Diff for /chimera/MyBrowserView.mm between versions 1.16 and 1.34

version 1.16, 2002/02/11 07:22:13 version 1.34, 2002/04/20 00:44:56
Line 1 Line 1
/*/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 *  MyBrowserView.mm/* ***** BEGIN LICENSE BLOCK *****
 */ * Version: NPL 1.1/GPL 2.0/LGPL 2.1
  * The contents of this file are subject to the Netscape Public License
  * Version 1.1 (the "License"); you may not use this file except in
  * compliance with the License. You may obtain a copy of the License at
  * http://www.mozilla.org/NPL/
  * Software distributed under the License is distributed on an "AS IS" basis,
  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  * for the specific language governing rights and limitations under the
  * License.
  * The Original Code is mozilla.org code.
  * The Initial Developer of the Original Code is 
  * Netscape Communications Corporation.
  * Portions created by the Initial Developer are Copyright (C) 2002
  * the Initial Developer. All Rights Reserved.
  * Contributor(s):
  * Alternatively, the contents of this file may be used under the terms of
  * either the GNU General Public License Version 2 or later (the "GPL"), or 
  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  * in which case the provisions of the GPL or the LGPL are applicable instead
  * of those above. If you wish to allow use of your version of this file only
  * under the terms of either the GPL or the LGPL, and not to allow others to
  * use your version of this file under the terms of the NPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the NPL, the GPL or the LGPL.
  * ***** END LICENSE BLOCK ***** */
 #import "MyBrowserView.h"  #import "MyBrowserView.h"
   #import "BrowserWindowController.h"
 #include "nsCOMPtr.h"  #include "nsCOMPtr.h"
 #include "nsIServiceManager.h"  #include "nsIServiceManager.h"
 #include "nsIIOService.h"  #include "nsIIOService.h"
   #include "ContentClickListener.h"
   #include "nsIDOMWindow.h"
   #include "nsIChromeEventHandler.h"
   #include "nsPIDOMWindow.h"
   #include "nsIDOMEventReceiver.h"
   #include "nsIPrefBranch.h"
   #include "nsIPrefService.h"
   #include "nsCocoaBrowserService.h"
 #define DOCUMENT_DONE_STRING @"Document: Done"  #define DOCUMENT_DONE_STRING @"Document: Done"
 #define LOADING_STRING @"Loading..."  #define LOADING_STRING @"Loading..."
Line 17  static const char* ioServiceContractID = Line 59  static const char* ioServiceContractID =
 -(void)windowClosed  -(void)windowClosed
 {  {
    // Break the cycle.  // Break the cycle.
    [browserView setContainer: nil];  [browserView destroyWebBrowser];
    [browserView removeListener: self];  [browserView setContainer: nil];
    [browserView destroyWebBrowser];  [browserView removeListener: self];
 }  }
 -(void)dealloc  -(void)dealloc
 {  {
    printf("My browser view died.\n");  printf("My browser view died.\n");
    [[NSNotificationCenter defaultCenter] removeObserver: self];  [[NSNotificationCenter defaultCenter] removeObserver: self];
   [defaultStatus release];    [defaultStatus release];
    [loadingStatus release];  [loadingStatus release];
        [super dealloc];  [super dealloc];
 }  }
 - (IBAction)load:(id)sender  - (IBAction)load:(id)sender
Line 48  static const char* ioServiceContractID = Line 90  static const char* ioServiceContractID =
     progressSuper = nil;      progressSuper = nil;
     mIsPrimary = NO;      mIsPrimary = NO;
     [[NSNotificationCenter defaultCenter] removeObserver:self];      [[NSNotificationCenter defaultCenter] removeObserver:self];
       [browserView setActive: NO];
   -(id)initWithTab:(id)aTab andWindow: (NSWindow*)aWindow
     mTab = aTab;
     mWindow = aWindow;
     return [self initWithFrame: NSZeroRect];
 }  }
 - (id)initWithFrame:(NSRect)frameRect  - (id)initWithFrame:(NSRect)frameRect
 {  {
    [super initWithFrame: frameRect];    if ( (self = [super initWithFrame: frameRect]) ) {
     browserView = [[[NSBrowserView alloc] initWithFrame:[self bounds]] autorelease];        browserView = [[[NSBrowserView alloc] initWithFrame:[self bounds] andWindow: [self getNativeWindow]] autorelease];
    [self addSubview:browserView];        [self addSubview:browserView];
    [browserView setContainer:self];        [browserView setContainer:self];
    [browserView addListener:self];        [browserView addListener:self];
    mIsBusy = NO;        mIsBusy = NO;
         mListenersAttached = NO;
     return self;      return self;
 }  }
-(void)makePrimaryBrowserView: (NSTabViewItem*)tab urlbar: (id)aUrlbar status: (id)aStatus-(void)setTab: (NSTabViewItem*)tab
    progress: (id)aProgress windowController: aWindowController 
 {  {
   mTab = tab;    mTab = tab;
   -(void)makePrimaryBrowserView: (id)aUrlbar status: (id)aStatus
       progress: (id)aProgress windowController: aWindowController
   urlbar = aUrlbar;    urlbar = aUrlbar;
   status = aStatus;    status = aStatus;
   progress = aProgress;    progress = aProgress;
   progressSuper = [aProgress superview];    progressSuper = [aProgress superview];
   mWindowController = aWindowController;    mWindowController = aWindowController;
  if (!mIsBusy) {  if (!mIsBusy)
    [progress retain]; 
     [progress removeFromSuperview];      [progress removeFromSuperview];
   defaultStatus = NULL;    defaultStatus = NULL;
   loadingStatus = DOCUMENT_DONE_STRING;    loadingStatus = DOCUMENT_DONE_STRING;
   [status setStringValue:loadingStatus];    [status setStringValue:loadingStatus];
   mIsPrimary = YES;    mIsPrimary = YES;
   if ([[self window] isKeyWindow])
     [browserView setActive: YES];
   nsCOMPtr<nsIIOService> ioService(do_GetService(ioServiceContractID));    nsCOMPtr<nsIIOService> ioService(do_GetService(ioServiceContractID));
   if (!ioService)    if (!ioService)
     return;      return;
Line 94  static const char* ioServiceContractID = Line 152  static const char* ioServiceContractID =
         selector:@selector(offlineModeChanged:)          selector:@selector(offlineModeChanged:)
         name:@"offlineModeChanged"          name:@"offlineModeChanged"
         object:nil];          object:nil];
     // Update the URL bar.
     [mWindowController updateLocationFields:[self getCurrentURLSpec]];
     if (mWindowController && !mListenersAttached) {
       mListenersAttached = YES;
       // We need to hook up our click and context menu listeners.
       ContentClickListener* clickListener = new ContentClickListener(mWindowController);
       if (!clickListener)
       nsCOMPtr<nsIDOMWindow> contentWindow = getter_AddRefs([[self getBrowserView] getContentWindow]);
       nsCOMPtr<nsPIDOMWindow> piWindow(do_QueryInterface(contentWindow));
       nsCOMPtr<nsIChromeEventHandler> chromeHandler;
       nsCOMPtr<nsIDOMEventReceiver> rec(do_QueryInterface(chromeHandler));
       rec->AddEventListenerByIID(clickListener, NS_GET_IID(nsIDOMMouseListener));
     return [browserView getCurrentURLSpec];
 }  }
 - (void)awakeFromNib   - (void)awakeFromNib 
Line 120  static const char* ioServiceContractID = Line 202  static const char* ioServiceContractID =
   }    }
   [progressSuper addSubview:progress];    [progressSuper addSubview:progress];
   [progress release];  
   [progress setIndeterminate:YES];    [progress setIndeterminate:YES];
   [progress startAnimation:self];    [progress startAnimation:self];
Line 132  static const char* ioServiceContractID = Line 213  static const char* ioServiceContractID =
   if (mWindowController)    if (mWindowController)
     [mWindowController updateToolbarItems];      [mWindowController updateToolbarItems];
     else {
       printf("background load.\n");
 }  }
 - (void)onLoadingCompleted:(BOOL)succeeded  - (void)onLoadingCompleted:(BOOL)succeeded
 {  {
   [progress setIndeterminate:YES];    [progress setIndeterminate:YES];
   [progress stopAnimation:self];    [progress stopAnimation:self];
   [progress retain];  
   [progress removeFromSuperview];    [progress removeFromSuperview];
   loadingStatus = DOCUMENT_DONE_STRING;    loadingStatus = DOCUMENT_DONE_STRING;
Line 209  static const char* ioServiceContractID = Line 292  static const char* ioServiceContractID =
 - (void)setTitle:(NSString *)title  - (void)setTitle:(NSString *)title
 {  {
     if (!mWindowController)  
         return; // Sidebar panels can't affect the window title.  
     // We must be the primary content area.      // We must be the primary content area.
    if (mIsPrimary) {    if (mIsPrimary && mWindowController) {
         if (mOffline) {          if (mOffline) {
             NSString* newTitle;              NSString* newTitle;
             if (title && ![title isEqualToString:@""])              if (title && ![title isEqualToString:@""])
Line 237  static const char* ioServiceContractID = Line 317  static const char* ioServiceContractID =
         [mTab setLabel:@"Untitled"];          [mTab setLabel:@"Untitled"];
 }  }
   // Called when a context menu should be shown.
   - (void)onShowContextMenu:(int)flags domEvent:(nsIDOMEvent*)aEvent domNode:(nsIDOMNode*)aNode
     [mWindowController onShowContextMenu: flags domEvent: aEvent domNode: aNode];
     return [mWindowController getContextMenu];
     NSWindow* window = [self window];
     if (window)
       return window;
     if (mWindow)
       return mWindow;
     return nil;
 - (void)offlineModeChanged: (NSNotification*)aNotification  - (void)offlineModeChanged: (NSNotification*)aNotification
 {  {
     nsCOMPtr<nsIIOService> ioService(do_GetService(ioServiceContractID));      nsCOMPtr<nsIIOService> ioService(do_GetService(ioServiceContractID));
Line 269  static const char* ioServiceContractID = Line 372  static const char* ioServiceContractID =
   [[self window] setFrame:frame display:YES];    [[self window] setFrame:frame display:YES];
 }  }
- (NSBrowserView*)createBrowserWindow:(unsigned int)mask#define NS_POPUP_BLOCK @"This Web site is attempting to open an unrequested popup window.  Navigator can \
{automatically prevent Web sites from opening popup advertisements.  Click OK to prevent all \
  // XXX not implemented unrequested popups (including this one) from opening."
  return NULL;
 - (NSBrowserView*)createBrowserWindow:(unsigned int)aMask
   nsCOMPtr<nsIPrefBranch> pref(do_GetService("@mozilla.org/preferences-service;1"));
   if (!pref)
     return NS_OK; // Something bad happened if we can't get prefs.
   PRBool showBlocker;
   pref->GetBoolPref("browser.popups.showPopupBlocker", &showBlocker);
   if (showBlocker) {
     nsCOMPtr<nsIDOMWindow> domWindow = getter_AddRefs([browserView getContentWindow]);
     nsCOMPtr<nsPIDOMWindow> piWindow(do_QueryInterface(domWindow));
     PRBool isUnrequested;
     if (isUnrequested) {
       // A popup is being opened while the page is currently loading.  Offer to block the
       // popup.
       nsAlertController* controller = nsCocoaBrowserService::GetAlertController();
       BOOL confirm = [controller confirm: [self window] title: @"Unrequested Popup Detected"
                                 text: NS_POPUP_BLOCK];
       // This is a one-time dialog.
       pref->SetBoolPref("browser.popups.showPopupBlocker", PR_FALSE);
       if (confirm) {
         pref->SetBoolPref("dom.disable_open_during_load", PR_TRUE);
         pref->SetIntPref("dom.disable_open_click_delay", 1000);
       nsCOMPtr<nsIPrefService> prefService(do_QueryInterface(pref));
       if (confirm)
         return nil;
   BrowserWindowController* controller = [[BrowserWindowController alloc] initWithWindowNibName: @"BrowserWindow"];
   [controller setChromeMask: aMask];
   [controller disableAutosave]; // The Web page opened this window, so we don't ever use its settings.
   [controller enterModalSession];
   [[[controller getMyBrowserView] getBrowserView] setActive: YES];
   return [[controller getMyBrowserView] getBrowserView];
 }  }
 - (NSBrowserView*)getBrowserView  - (NSBrowserView*)getBrowserView

Removed from v.1.16  
changed lines
  Added in v.1.34

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>