Back to index

lightning-sunbird  0.9+nobinonly
nsGlobalWindow.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* vim: set ts=2 sw=2 et tw=80: */
00003 /* ***** BEGIN LICENSE BLOCK *****
00004  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00005  *
00006  * The contents of this file are subject to the Mozilla Public License Version
00007  * 1.1 (the "License"); you may not use this file except in compliance with
00008  * the License. You may obtain a copy of the License at
00009  * http://www.mozilla.org/MPL/
00010  *
00011  * Software distributed under the License is distributed on an "AS IS" basis,
00012  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013  * for the specific language governing rights and limitations under the
00014  * License.
00015  *
00016  * The Original Code is mozilla.org code.
00017  *
00018  * The Initial Developer of the Original Code is
00019  * Netscape Communications Corporation.
00020  * Portions created by the Initial Developer are Copyright (C) 1998
00021  * the Initial Developer. All Rights Reserved.
00022  *
00023  * Contributor(s):
00024  *   Travis Bogard <travis@netscape.com>
00025  *   Dan Rosen <dr@netscape.com>
00026  *   Vidur Apparao <vidur@netscape.com>
00027  *   Johnny Stenback <jst@netscape.com>
00028  *
00029  * Alternatively, the contents of this file may be used under the terms of
00030  * either of the GNU General Public License Version 2 or later (the "GPL"),
00031  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00032  * in which case the provisions of the GPL or the LGPL are applicable instead
00033  * of those above. If you wish to allow use of your version of this file only
00034  * under the terms of either the GPL or the LGPL, and not to allow others to
00035  * use your version of this file under the terms of the MPL, indicate your
00036  * decision by deleting the provisions above and replace them with the notice
00037  * and other provisions required by the GPL or the LGPL. If you do not delete
00038  * the provisions above, a recipient may use your version of this file under
00039  * the terms of any one of the MPL, the GPL or the LGPL.
00040  *
00041  * ***** END LICENSE BLOCK ***** */
00042 
00043 #ifndef nsGlobalWindow_h___
00044 #define nsGlobalWindow_h___
00045 
00046 // Local Includes
00047 // Helper Classes
00048 #include "nsCOMPtr.h"
00049 #include "nsAutoPtr.h"
00050 #include "nsWeakReference.h"
00051 #include "nsHashtable.h"
00052 #include "nsDataHashtable.h"
00053 
00054 // Interfaces Needed
00055 #include "nsDOMWindowList.h"
00056 #include "nsIBaseWindow.h"
00057 #include "nsIBrowserDOMWindow.h"
00058 #include "nsIChromeEventHandler.h"
00059 #include "nsIControllers.h"
00060 #include "nsIObserver.h"
00061 #include "nsIDocShellTreeOwner.h"
00062 #include "nsIDocShellTreeItem.h"
00063 #include "nsIDOMClientInformation.h"
00064 #include "nsIDOMViewCSS.h"
00065 #include "nsIDOMEventReceiver.h"
00066 #include "nsIDOM3EventTarget.h"
00067 #include "nsIDOMNSEventTarget.h"
00068 #include "nsIDOMNavigator.h"
00069 #include "nsIDOMNSLocation.h"
00070 #include "nsIDOMWindowInternal.h"
00071 #include "nsIInterfaceRequestor.h"
00072 #include "nsIInterfaceRequestorUtils.h"
00073 #include "nsIDOMJSWindow.h"
00074 #include "nsIDOMChromeWindow.h"
00075 #include "nsIScriptGlobalObject.h"
00076 #include "nsIScriptContext.h"
00077 #include "nsIScriptObjectPrincipal.h"
00078 #include "nsITimer.h"
00079 #include "nsIWebBrowserChrome.h"
00080 #include "nsPIDOMWindow.h"
00081 #include "nsIScriptSecurityManager.h"
00082 #include "nsIEventListenerManager.h"
00083 #include "nsIDOMDocument.h"
00084 #include "nsIDOMCrypto.h"
00085 #include "nsIDOMPkcs11.h"
00086 #include "nsIPrincipal.h"
00087 #include "nsPluginArray.h"
00088 #include "nsMimeTypeArray.h"
00089 #include "nsIXPCScriptable.h"
00090 #include "nsPoint.h"
00091 #include "nsSize.h"
00092 #include "mozFlushType.h"
00093 #include "prclist.h"
00094 #include "nsIObserver.h"
00095 #include "nsIDOMStorage.h"
00096 #include "nsIDOMStorageList.h"
00097 #include "nsIDOMStorageWindow.h"
00098 #include "nsIDOMGCParticipant.h"
00099 
00100 #define DEFAULT_HOME_PAGE "www.mozilla.org"
00101 #define PREF_BROWSER_STARTUP_HOMEPAGE "browser.startup.homepage"
00102 
00103 class nsIDOMBarProp;
00104 class nsIDocument;
00105 class nsIContent;
00106 class nsPresContext;
00107 class nsIDOMEvent;
00108 class nsIScrollableView;
00109 
00110 typedef struct nsTimeout nsTimeout;
00111 
00112 class nsBarProp;
00113 class nsLocation;
00114 class nsNavigator;
00115 class nsScreen;
00116 class nsHistory;
00117 class nsIDocShellLoadInfo;
00118 class WindowStateHolder;
00119 
00120 //*****************************************************************************
00121 // nsGlobalWindow: Global Object for Scripting
00122 //*****************************************************************************
00123 // Beware that all scriptable interfaces implemented by
00124 // nsGlobalWindow will be reachable from JS, if you make this class
00125 // implement new interfaces you better know what you're
00126 // doing. Security wise this is very sensitive code. --
00127 // jst@netscape.com
00128 
00129 // nsGlobalWindow inherits PRCList for maintaining a list of all inner
00130 // widows still in memory for any given outer window. This list is
00131 // needed to ensure that mOuterWindow doesn't end up dangling. The
00132 // nature of PRCList means that the window itself is always in the
00133 // list, and an outer window's list will also contain all inner window
00134 // objects that are still in memory (and in reality all inner window
00135 // object's lists also contain its outer and all other inner windows
00136 // belonging to the same outer window, but that's an unimportant
00137 // side effect of inheriting PRCList).
00138 
00139 class nsGlobalWindow : public nsPIDOMWindow_MOZILLA_1_8_BRANCH2,
00140                        public nsIScriptGlobalObject,
00141                        public nsIDOMJSWindow,
00142                        public nsIScriptObjectPrincipal,
00143                        public nsIDOMEventReceiver,
00144                        public nsIDOMGCParticipant,
00145                        public nsIDOM3EventTarget,
00146                        public nsIDOMNSEventTarget,
00147                        public nsIDOMViewCSS,
00148                        public nsIDOMStorageWindow,
00149                        public nsSupportsWeakReference,
00150                        public nsIInterfaceRequestor,
00151                        public nsIObserver,
00152                        public PRCListStr
00153 {
00154 public:
00155   // public methods
00156   nsPIDOMWindow* GetPrivateParent();
00157   // callback for close event
00158   void ReallyCloseWindow();
00159 
00160   // nsISupports
00161   NS_DECL_ISUPPORTS
00162 
00163   // nsIScriptGlobalObject
00164   virtual void SetContext(nsIScriptContext *aContext);
00165   virtual nsIScriptContext *GetContext();
00166   virtual nsresult SetNewDocument(nsIDOMDocument *aDocument,
00167                                   nsISupports *aState,
00168                                   PRBool aRemoveEventListeners,
00169                                   PRBool aClearScopeHint);
00170   virtual void SetDocShell(nsIDocShell* aDocShell);
00171   virtual nsIDocShell *GetDocShell();
00172   virtual void SetOpenerWindow(nsIDOMWindowInternal *aOpener);
00173   virtual void SetGlobalObjectOwner(nsIScriptGlobalObjectOwner* aOwner);
00174   virtual nsIScriptGlobalObjectOwner *GetGlobalObjectOwner();
00175   virtual nsresult HandleDOMEvent(nsPresContext* aPresContext,
00176                                   nsEvent* aEvent, nsIDOMEvent** aDOMEvent,
00177                                   PRUint32 aFlags,
00178                                   nsEventStatus* aEventStatus);
00179   virtual JSObject *GetGlobalJSObject();
00180   virtual void OnFinalize(JSObject *aJSObject);
00181   virtual void SetScriptsEnabled(PRBool aEnabled, PRBool aFireTimeouts);
00182   virtual nsresult SetNewArguments(PRUint32 aArgc, void* aArgv);
00183 
00184   // nsIScriptObjectPrincipal
00185   virtual nsIPrincipal* GetPrincipal();
00186 
00187   // nsIDOMWindow
00188   NS_DECL_NSIDOMWINDOW
00189 
00190   // nsIDOMWindow2
00191   NS_DECL_NSIDOMWINDOW2
00192 
00193   // nsIDOMWindowInternal
00194   NS_DECL_NSIDOMWINDOWINTERNAL
00195 
00196   // nsIDOMJSWindow
00197   NS_DECL_NSIDOMJSWINDOW
00198 
00199   // nsIDOMEventTarget
00200   NS_DECL_NSIDOMEVENTTARGET
00201 
00202   // nsIDOM3EventTarget
00203   NS_DECL_NSIDOM3EVENTTARGET
00204 
00205   // nsIDOMNSEventTarget
00206   NS_DECL_NSIDOMNSEVENTTARGET
00207 
00208   // nsIDOMEventReceiver
00209   NS_IMETHOD AddEventListenerByIID(nsIDOMEventListener *aListener,
00210                                    const nsIID& aIID);
00211   NS_IMETHOD RemoveEventListenerByIID(nsIDOMEventListener *aListener,
00212                                       const nsIID& aIID);
00213   NS_IMETHOD GetListenerManager(nsIEventListenerManager** aInstancePtrResult);
00214   NS_IMETHOD HandleEvent(nsIDOMEvent *aEvent);
00215   NS_IMETHOD GetSystemEventGroup(nsIDOMEventGroup** aGroup);
00216 
00217   // nsIDOMGCParticipant
00218   virtual nsIDOMGCParticipant* GetSCCIndex();
00219   virtual void AppendReachableList(nsCOMArray<nsIDOMGCParticipant>& aArray);
00220 
00221   // nsPIDOMWindow
00222   virtual NS_HIDDEN_(nsPIDOMWindow*) GetPrivateRoot();
00223   virtual NS_HIDDEN_(nsresult) GetObjectProperty(const PRUnichar* aProperty,
00224                                                  nsISupports** aObject);
00225   virtual NS_HIDDEN_(nsresult) Activate();
00226   virtual NS_HIDDEN_(nsresult) Deactivate();
00227   virtual NS_HIDDEN_(nsIFocusController*) GetRootFocusController();
00228 
00229   virtual NS_HIDDEN_(void) SetOpenerScriptURL(nsIURI* aURI);
00230 
00231   virtual NS_HIDDEN_(PopupControlState) PushPopupControlState(PopupControlState state, PRBool aForce) const;
00232   virtual NS_HIDDEN_(void) PopPopupControlState(PopupControlState state) const;
00233   virtual NS_HIDDEN_(PopupControlState) GetPopupControlState() const;
00234   virtual NS_HIDDEN_(OpenAllowValue) GetOpenAllow(const nsAString &aName);
00235 
00236   virtual NS_HIDDEN_(nsresult) SaveWindowState(nsISupports **aState);
00237   virtual NS_HIDDEN_(nsresult) RestoreWindowState(nsISupports *aState);
00238 
00239   virtual NS_HIDDEN_(PRBool) WouldReuseInnerWindow(nsIDocument *aNewDocument);
00240 
00241   // nsPIDOMWindow_MOZILLA_1_8_BRANCH
00242   virtual NS_HIDDEN_(void) SetOpenerWindow(nsIDOMWindowInternal *aOpener,
00243                                            PRBool aOriginalOpener);
00244 
00245   virtual NS_HIDDEN_(nsresult) FireDelayedDOMEvents();
00246 
00247   virtual NS_HIDDEN_(void) EnterModalState();
00248   virtual NS_HIDDEN_(void) LeaveModalState();
00249 
00250   // nsPIDOMWindow_MOZILLA_1_8_BRANCH2
00251   virtual NS_HIDDEN_(void) SetOpenerScriptPrincipal(nsIPrincipal* aPrincipal);
00252   virtual NS_HIDDEN_(nsIPrincipal*) GetOpenerScriptPrincipal();
00253   
00254   // nsIDOMViewCSS
00255   NS_DECL_NSIDOMVIEWCSS
00256 
00257   // nsIDOMAbstractView
00258   NS_DECL_NSIDOMABSTRACTVIEW
00259 
00260   // nsIDOMStorageWindow
00261   NS_DECL_NSIDOMSTORAGEWINDOW
00262 
00263   // nsIInterfaceRequestor
00264   NS_DECL_NSIINTERFACEREQUESTOR
00265 
00266   // nsIObserver
00267   NS_DECL_NSIOBSERVER
00268 
00269   // Object Management
00270   nsGlobalWindow(nsGlobalWindow *aOuterWindow);
00271 
00272   static nsGlobalWindow *FromWrapper(nsIXPConnectWrappedNative *wrapper)
00273   {
00274     // Make sure this matches the casts we do in QueryInterface().
00275     return (nsGlobalWindow *)(nsIScriptGlobalObject *)wrapper->Native();
00276   }
00277 
00278   nsIScriptContext *GetContextInternal()
00279   {
00280     if (mOuterWindow) {
00281       return GetOuterWindowInternal()->mContext;
00282     }
00283 
00284     return mContext;
00285   }
00286 
00287   nsGlobalWindow *GetOuterWindowInternal()
00288   {
00289     return NS_STATIC_CAST(nsGlobalWindow *, GetOuterWindow());
00290   }
00291 
00292   nsGlobalWindow *GetCurrentInnerWindowInternal()
00293   {
00294     return NS_STATIC_CAST(nsGlobalWindow *, mInnerWindow);
00295   }
00296 
00297   nsIDocShell *GetDocShellInternal()
00298   {
00299     if (mOuterWindow) {
00300       return GetOuterWindowInternal()->mDocShell;
00301     }
00302 
00303     return mDocShell;
00304   }
00305 
00306   PRBool IsFrozen() const
00307   {
00308     return mIsFrozen;
00309   }
00310 
00311   PRBool IsCreatingInnerWindow() const
00312   {
00313     return  mCreatingInnerWindow;
00314   }
00315 
00316   static void ShutDown();
00317   static PRBool IsCallerChrome();
00318 
00319   friend class WindowStateHolder;
00320 
00321 protected:
00322   // Object Management
00323   virtual ~nsGlobalWindow();
00324   void CleanUp();
00325   void ClearControllers();
00326 
00327   void FreeInnerObjects(JSContext *cx);
00328 
00329   nsresult SetNewDocument(nsIDOMDocument *aDocument,
00330                           nsISupports *aState,
00331                           PRBool aRemoveEventListeners,
00332                           PRBool aClearScopeHint,
00333                           PRBool aIsInternalCall);
00334 
00335   // Get the parent, returns null if this is a toplevel window
00336   nsIDOMWindowInternal *GetParentInternal();
00337 
00338   // popup tracking
00339   PRBool IsPopupSpamWindow()
00340   {
00341     if (IsInnerWindow() && !mOuterWindow) {
00342       return PR_FALSE;
00343     }
00344 
00345     return GetOuterWindowInternal()->mIsPopupSpam;
00346   }
00347 
00348   void SetPopupSpamWindow(PRBool aPopup)
00349   {
00350     if (IsInnerWindow() && !mOuterWindow) {
00351       NS_ERROR("SetPopupSpamWindow() called on inner window w/o an outer!");
00352 
00353       return;
00354     }
00355 
00356     GetOuterWindowInternal()->mIsPopupSpam = aPopup;
00357   }
00358 
00359   // Window Control Functions
00390   NS_HIDDEN_(nsresult) OpenInternal(const nsAString& aUrl,
00391                                     const nsAString& aName,
00392                                     const nsAString& aOptions,
00393                                     PRBool aDialog,
00394                                     PRBool aCalledNoScript,
00395                                     PRBool aDoJSFixups,
00396                                     jsval *argv, PRUint32 argc,
00397                                     nsISupports *aExtraArgument,
00398                                     nsIPrincipal *aCalleePrincipal,
00399                                     nsIDOMWindow **aReturn);
00400 
00401   static void CloseWindow(nsISupports* aWindow);
00402   static void ClearWindowScope(nsISupports* aWindow);
00403 
00404   // Timeout Functions
00405   nsresult SetTimeoutOrInterval(PRBool aIsInterval, PRInt32* aReturn);
00406   void RunTimeout(nsTimeout *aTimeout);
00407   nsresult ClearTimeoutOrInterval();
00408   void ClearAllTimeouts();
00409   void InsertTimeoutIntoList(nsTimeout **aInsertionPoint, nsTimeout *aTimeout);
00410   static void TimerCallback(nsITimer *aTimer, void *aClosure);
00411 
00412   // Helper Functions
00413   nsresult GetTreeOwner(nsIDocShellTreeOwner** aTreeOwner);
00414   nsresult GetTreeOwner(nsIBaseWindow** aTreeOwner);
00415   nsresult GetWebBrowserChrome(nsIWebBrowserChrome** aBrowserChrome);
00416   // GetScrollInfo does not flush.  Callers should do it themselves as needed,
00417   // depending on which info they actually want off the scrollable view.
00418   nsresult GetScrollInfo(nsIScrollableView** aScrollableView, float* aP2T,
00419                          float* aT2P);
00420   nsresult SecurityCheckURL(const char *aURL);
00421   nsresult BuildURIfromBase(const char *aURL,
00422                             nsIURI **aBuiltURI,
00423                             PRBool *aFreeSecurityPass, JSContext **aCXused);
00424   PopupControlState CheckForAbusePoint();
00425   OpenAllowValue CheckOpenAllow(PopupControlState aAbuseLevel);
00426   void     FireAbuseEvents(PRBool aBlocked, PRBool aWindow,
00427                            const nsAString &aPopupURL,
00428                            const nsAString &aPopupWindowFeatures);
00429 
00430   void FlushPendingNotifications(mozFlushType aType);
00431   void EnsureSizeUpToDate();
00432   void EnsureReflowFlushAndPaint();
00433   nsresult CheckSecurityWidthAndHeight(PRInt32* width, PRInt32* height);
00434   nsresult CheckSecurityLeftAndTop(PRInt32* left, PRInt32* top);
00435   static PRBool CanSetProperty(const char *aPrefName);
00436 
00437   static void MakeScriptDialogTitle(nsAString &aOutTitle);
00438 
00439   // Helper for window.find()
00440   nsresult FindInternal(const nsAString& aStr, PRBool caseSensitive,
00441                        PRBool backwards, PRBool wrapAround, PRBool wholeWord, 
00442                        PRBool searchInFrames, PRBool showDialog, 
00443                        PRBool *aReturn);
00444 
00445   nsresult ConvertCharset(const nsAString& aStr, char** aDest);
00446 
00447   PRBool   GetBlurSuppression();
00448 
00449   // If aDoFlush is true, we'll flush our own layout; otherwise we'll try to
00450   // just flush our parent and only flush ourselves if we think we need to.
00451   nsresult GetScrollXY(PRInt32* aScrollX, PRInt32* aScrollY,
00452                        PRBool aDoFlush);
00453   nsresult GetScrollMaxXY(PRInt32* aScrollMaxX, PRInt32* aScrollMaxY);
00454 
00455   PRBool IsFrame()
00456   {
00457     return GetParentInternal() != nsnull;
00458   }
00459 
00460   PRBool DispatchCustomEvent(const char *aEventName);
00461 
00462   // If aLookForCallerOnJSStack is true, this method will look at the JS stack
00463   // to determine who the caller is.  If it's false, it'll use |this| as the
00464   // caller.
00465   PRBool WindowExists(const nsAString& aName, PRBool aLookForCallerOnJSStack);
00466 
00467   already_AddRefed<nsIWidget> GetMainWidget();
00468 
00469   void SuspendTimeouts();
00470   virtual nsresult ResumeTimeouts();
00471 
00472   void Freeze()
00473   {
00474     NS_ASSERTION(!IsFrozen(), "Double-freezing?");
00475     mIsFrozen = PR_TRUE;
00476   }
00477 
00478   void Thaw()
00479   {
00480     mIsFrozen = PR_FALSE;
00481   }
00482 
00483   PRBool IsInModalState();
00484 
00485   // When adding new member variables, be careful not to create cycles
00486   // through JavaScript.  If there is any chance that a member variable
00487   // could own objects that are implemented in JavaScript, then those
00488   // objects will keep the global object (this object) alive.  To prevent
00489   // these cycles, ownership of such members must be released in
00490   // |CleanUp| and |SetDocShell|.
00491 
00492   // This member is also used on both inner and outer windows, but
00493   // for slightly different purposes. On inner windows it means the
00494   // inner window is held onto by session history and should not
00495   // change. On outer windows it means that the window is in a state
00496   // where we don't want to force creation of a new inner window since
00497   // we're in the middle of doing just that.
00498   PRPackedBool                  mIsFrozen : 1;
00499 
00500   // These members are only used on outer window objects. Make sure
00501   // you never set any of these on an inner object!
00502   PRPackedBool                  mFullScreen : 1;
00503   PRPackedBool                  mIsClosed : 1;
00504   PRPackedBool                  mInClose : 1;
00505   // mHavePendingClose means we've got a termination function set to
00506   // close us when the JS stops executing or that we have a close
00507   // event posted.  If this is set, just ignore window.close() calls.
00508   PRPackedBool                  mHavePendingClose : 1;
00509   PRPackedBool                  mHadOriginalOpener : 1;
00510   PRPackedBool                  mIsPopupSpam : 1;
00511 
00512   // Indicates whether we're in the middle of creating an initializing
00513   // a new inner window object.
00514   PRPackedBool                  mCreatingInnerWindow : 1;
00515 
00516   PRUint32                      mModalStateDepth;
00517 
00518   nsCOMPtr<nsIScriptContext>    mContext;
00519   nsCOMPtr<nsIDOMWindowInternal> mOpener;
00520   nsCOMPtr<nsIControllers>      mControllers;
00521   JSObject*                     mArguments;
00522   nsRefPtr<nsNavigator>         mNavigator;
00523   nsRefPtr<nsScreen>            mScreen;
00524   nsRefPtr<nsHistory>           mHistory;
00525   nsRefPtr<nsDOMWindowList>     mFrames;
00526   nsRefPtr<nsBarProp>           mMenubar;
00527   nsRefPtr<nsBarProp>           mToolbar;
00528   nsRefPtr<nsBarProp>           mLocationbar;
00529   nsRefPtr<nsBarProp>           mPersonalbar;
00530   nsRefPtr<nsBarProp>           mStatusbar;
00531   nsRefPtr<nsBarProp>           mScrollbars;
00532   nsCOMPtr<nsIWeakReference>    mWindowUtils;
00533   nsRefPtr<nsLocation>          mLocation;
00534   nsString                      mStatus;
00535   nsString                      mDefaultStatus;
00536 
00537   nsIScriptGlobalObjectOwner*   mGlobalObjectOwner; // Weak Reference
00538   nsIDocShell*                  mDocShell;  // Weak Reference
00539   nsCOMPtr<nsIDOMCrypto>        mCrypto;
00540   nsCOMPtr<nsIDOMPkcs11>        mPkcs11;
00541 
00542   nsCOMPtr<nsIDOMStorageList>   gGlobalStorageList;
00543 
00544   nsCOMPtr<nsIXPConnectJSObjectHolder> mInnerWindowHolder;
00545   nsCOMPtr<nsIPrincipal> mOpenerScriptPrincipal; // strong; used to determine
00546                                                  // whether to clear scope
00547 
00548   // These member variable are used only on inner windows.
00549   nsCOMPtr<nsIEventListenerManager> mListenerManager;
00550   nsTimeout*                    mTimeouts;
00551   nsTimeout**                   mTimeoutInsertionPoint;
00552   PRUint32                      mTimeoutPublicIdCounter;
00553   PRUint32                      mTimeoutFiringDepth;
00554   nsCOMPtr<nsIDOMStorage>       mSessionStorage;
00555 
00556   // These member variables are used on both inner and the outer windows.
00557   nsCOMPtr<nsIPrincipal> mDocumentPrincipal;
00558   JSObject* mJSObject;
00559 
00560   nsDataHashtable<nsStringHashKey, PRBool> *mPendingStorageEvents;
00561 
00562 #ifdef DEBUG
00563   PRBool mSetOpenerWindowCalled;
00564 #endif
00565 
00566   friend class nsDOMScriptableHelper;
00567   friend class nsDOMWindowUtils;
00568   static nsIScriptSecurityManager *sSecMan;
00569   static nsIFactory *sComputedDOMStyleFactory;
00570 };
00571 
00572 /*
00573  * nsGlobalChromeWindow inherits from nsGlobalWindow. It is the global
00574  * object created for a Chrome Window only.
00575  */
00576 class nsGlobalChromeWindow : public nsGlobalWindow,
00577                              public nsIDOMChromeWindow
00578 {
00579 public:
00580   // nsISupports
00581   NS_DECL_ISUPPORTS_INHERITED
00582 
00583   // nsIDOMChromeWindow interface
00584   NS_DECL_NSIDOMCHROMEWINDOW
00585 
00586   nsGlobalChromeWindow(nsGlobalWindow *aOuterWindow)
00587     : nsGlobalWindow(aOuterWindow)
00588   {
00589   }
00590 
00591 protected:
00592   nsCOMPtr<nsIBrowserDOMWindow> mBrowserDOMWindow;
00593 };
00594 
00595 /*
00596  * Timeout struct that holds information about each JavaScript
00597  * timeout.
00598  */
00599 struct nsTimeout
00600 {
00601   nsTimeout()
00602   {
00603 #ifdef DEBUG_jst
00604     {
00605       extern int gTimeoutCnt;
00606 
00607       ++gTimeoutCnt;
00608     }
00609 #endif
00610 
00611     memset(this, 0, sizeof(*this));
00612 
00613     MOZ_COUNT_CTOR(nsTimeout);
00614   }
00615 
00616   ~nsTimeout()
00617   {
00618 #ifdef DEBUG_jst
00619     {
00620       extern int gTimeoutCnt;
00621 
00622       --gTimeoutCnt;
00623     }
00624 #endif
00625 
00626     MOZ_COUNT_DTOR(nsTimeout);
00627   }
00628 
00629   void Release(nsIScriptContext* aContext);
00630   void AddRef();
00631 
00632   // Window for which this timeout fires
00633   nsGlobalWindow *mWindow;
00634 
00635   // The JS expression to evaluate or function to call, if !mExpr
00636   JSString *mExpr;
00637   JSObject *mFunObj;
00638 
00639   // The actual timer object
00640   nsCOMPtr<nsITimer> mTimer;
00641 
00642   // Function actual arguments and argument count
00643   jsval *mArgv;
00644   PRUint16 mArgc;
00645 
00646   // True if the timeout was cleared
00647   PRPackedBool mCleared;
00648 
00649   // True if this is one of the timeouts that are currently running
00650   PRPackedBool mRunning;
00651 
00652   // Returned as value of setTimeout()
00653   PRUint32 mPublicId;
00654 
00655   // Non-zero interval in milliseconds if repetitive timeout
00656   PRInt32 mInterval;
00657 
00658   // Nominal time (in microseconds since the epoch) to run this
00659   // timeout
00660   PRTime mWhen;
00661 
00662   // Principal with which to execute
00663   nsCOMPtr<nsIPrincipal> mPrincipal;
00664 
00665   // filename, line number and JS language version string of the
00666   // caller of setTimeout()
00667   char *mFileName;
00668   PRUint32 mLineNo;
00669   const char *mVersion;
00670 
00671   // stack depth at which timeout is firing
00672   PRUint32 mFiringDepth;
00673 
00674   // Pointer to the next timeout in the linked list of scheduled
00675   // timeouts
00676   nsTimeout *mNext;
00677 
00678   // The popup state at timeout creation time if not created from
00679   // another timeout
00680   PopupControlState mPopupState;
00681 
00682 private:
00683   // reference count for shared usage
00684   PRInt32 mRefCnt;
00685 };
00686 
00687 //*****************************************************************************
00688 // nsNavigator: Script "navigator" object
00689 //*****************************************************************************
00690 
00691 class nsNavigator : public nsIDOMNavigator,
00692                     public nsIDOMNavigator_MOZILLA_1_8_BRANCH,
00693                     public nsIDOMJSNavigator,
00694                     public nsIDOMClientInformation
00695 {
00696 public:
00697   nsNavigator(nsIDocShell *aDocShell);
00698   virtual ~nsNavigator();
00699 
00700   NS_DECL_ISUPPORTS
00701   NS_DECL_NSIDOMNAVIGATOR
00702   NS_DECL_NSIDOMNAVIGATOR_MOZILLA_1_8_BRANCH
00703   NS_DECL_NSIDOMJSNAVIGATOR
00704   NS_DECL_NSIDOMCLIENTINFORMATION
00705   
00706   void SetDocShell(nsIDocShell *aDocShell);
00707   nsIDocShell *GetDocShell()
00708   {
00709     return mDocShell;
00710   }
00711 
00712   void LoadingNewDocument();
00713   nsresult RefreshMIMEArray();
00714 
00715 protected:
00716   nsRefPtr<nsMimeTypeArray> mMimeTypes;
00717   nsRefPtr<nsPluginArray> mPlugins;
00718   nsIDocShell* mDocShell; // weak reference
00719 
00720   static jsval       sPrefInternal_id;
00721 };
00722 
00723 class nsIURI;
00724 
00725 //*****************************************************************************
00726 // nsLocation: Script "location" object
00727 //*****************************************************************************
00728 
00729 class nsLocation : public nsIDOMLocation,
00730                    public nsIDOMNSLocation
00731 {
00732 public:
00733   nsLocation(nsIDocShell *aDocShell);
00734   virtual ~nsLocation();
00735 
00736   NS_DECL_ISUPPORTS
00737 
00738   void SetDocShell(nsIDocShell *aDocShell);
00739   nsIDocShell *GetDocShell();
00740 
00741   // nsIDOMLocation
00742   NS_DECL_NSIDOMLOCATION
00743 
00744   // nsIDOMNSLocation
00745   NS_DECL_NSIDOMNSLOCATION
00746 
00747 protected:
00748   // In the case of jar: uris, we sometimes want the place the jar was
00749   // fetched from as the URI instead of the jar: uri itself.  Pass in
00750   // PR_TRUE for aGetInnermostURI when that's the case.
00751   nsresult GetURI(nsIURI** aURL, PRBool aGetInnermostURI = PR_FALSE);
00752   nsresult GetWritableURI(nsIURI** aURL);
00753   nsresult SetURI(nsIURI* aURL, PRBool aReplace = PR_FALSE);
00754   nsresult SetHrefWithBase(const nsAString& aHref, nsIURI* aBase,
00755                            PRBool aReplace);
00756   nsresult SetHrefWithContext(JSContext* cx, const nsAString& aHref,
00757                               PRBool aReplace);
00758 
00759   nsresult GetSourceBaseURL(JSContext* cx, nsIURI** sourceURL);
00760   nsresult GetSourceDocument(JSContext* cx, nsIDocument** aDocument);
00761 
00762   nsresult CheckURL(nsIURI *url, nsIDocShellLoadInfo** aLoadInfo);
00763   nsresult FindUsableBaseURI(nsIURI * aBaseURI, nsIDocShell * aParent, nsIURI ** aUsableURI);
00764 
00765   nsWeakPtr mDocShell;
00766 };
00767 
00768 /* factory function */
00769 nsresult NS_NewScriptGlobalObject(PRBool aIsChrome,
00770                                   nsIScriptGlobalObject **aResult);
00771 
00772 #endif /* nsGlobalWindow_h___ */