1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=2 sw=2 et tw=80: */
3 /* ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
16 * The Original Code is mozilla.org code.
18 * The Initial Developer of the Original Code is
19 * Netscape Communications Corporation.
20 * Portions created by the Initial Developer are Copyright (C) 1998
21 * the Initial Developer. All Rights Reserved.
24 * Travis Bogard <travis@netscape.com>
25 * Dan Rosen <dr@netscape.com>
26 * Vidur Apparao <vidur@netscape.com>
27 * Johnny Stenback <jst@netscape.com>
29 * Alternatively, the contents of this file may be used under the terms of
30 * either of the GNU General Public License Version 2 or later (the "GPL"),
31 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
32 * in which case the provisions of the GPL or the LGPL are applicable instead
33 * of those above. If you wish to allow use of your version of this file only
34 * under the terms of either the GPL or the LGPL, and not to allow others to
35 * use your version of this file under the terms of the MPL, indicate your
36 * decision by deleting the provisions above and replace them with the notice
37 * and other provisions required by the GPL or the LGPL. If you do not delete
38 * the provisions above, a recipient may use your version of this file under
39 * the terms of any one of the MPL, the GPL or the LGPL.
41 * ***** END LICENSE BLOCK ***** */
43 #ifndef nsGlobalWindow_h___
44 #define nsGlobalWindow_h___
49 #include "nsAutoPtr.h"
50 #include "nsWeakReference.h"
51 #include "nsHashtable.h"
52 #include "nsDataHashtable.h"
53 #include "nsCycleCollectionParticipant.h"
54 #include "nsDOMScriptObjectHolder.h"
57 #include "nsDOMWindowList.h"
58 #include "nsIBaseWindow.h"
59 #include "nsIBrowserDOMWindow.h"
60 #include "nsIDocShellTreeOwner.h"
61 #include "nsIDocShellTreeItem.h"
62 #include "nsIDOMClientInformation.h"
63 #include "nsIDOMViewCSS.h"
64 #include "nsIDOMEventTarget.h"
65 #include "nsIDOM3EventTarget.h"
66 #include "nsIDOMNSEventTarget.h"
67 #include "nsIDOMNavigator.h"
68 #include "nsIDOMNavigatorGeolocation.h"
69 #include "nsIDOMLocation.h"
70 #include "nsIDOMWindowInternal.h"
71 #include "nsIInterfaceRequestor.h"
72 #include "nsIInterfaceRequestorUtils.h"
73 #include "nsIDOMJSWindow.h"
74 #include "nsIDOMChromeWindow.h"
75 #include "nsIScriptGlobalObject.h"
76 #include "nsIScriptContext.h"
77 #include "nsIScriptObjectPrincipal.h"
78 #include "nsIScriptTimeoutHandler.h"
80 #include "nsIWebBrowserChrome.h"
81 #include "nsPIDOMWindow.h"
82 #include "nsIDOMModalContentWindow.h"
83 #include "nsIScriptSecurityManager.h"
84 #include "nsIEventListenerManager.h"
85 #include "nsIDOMDocument.h"
86 #include "nsIDOMCrypto.h"
87 #include "nsIDOMPkcs11.h"
88 #include "nsIPrincipal.h"
89 #include "nsPluginArray.h"
90 #include "nsMimeTypeArray.h"
91 #include "nsIXPCScriptable.h"
94 #include "mozFlushType.h"
96 #include "nsIDOMStorage.h"
97 #include "nsIDOMStorageList.h"
98 #include "nsIDOMStorageWindow.h"
99 #include "nsIDOMOfflineResourceList.h"
100 #include "nsPIDOMEventTarget.h"
101 #include "nsIArray.h"
103 #define DEFAULT_HOME_PAGE "www.mozilla.org"
104 #define PREF_BROWSER_STARTUP_HOMEPAGE "browser.startup.homepage"
111 class nsIScrollableView
;
112 class nsIControllers
;
119 class nsIDocShellLoadInfo
;
120 class WindowStateHolder
;
121 class nsGlobalWindowObserver
;
122 class nsGlobalWindow
;
123 class nsDummyJavaPluginOwner
;
124 class PostMessageEvent
;
126 class nsDOMOfflineResourceList
;
129 // permissible values for CheckOpenAllow
130 enum OpenAllowValue
{
131 allowNot
= 0, // the window opening is denied
132 allowNoAbuse
, // allowed: not a popup
133 allowWhitelisted
// allowed: it's whitelisted or popup blocking is disabled
137 NS_CreateJSTimeoutHandler(nsGlobalWindow
*aWindow
,
140 nsIScriptTimeoutHandler
**aRet
);
143 * Timeout struct that holds information about each script
144 * timeout. Holds a strong reference to an nsIScriptTimeoutHandler, which
145 * abstracts the language specific cruft.
147 struct nsTimeout
: PRCList
156 // Note: might not actually return an nsTimeout. Use IsTimeout to check.
157 return static_cast<nsTimeout
*>(PR_NEXT_LINK(this));
161 // Note: might not actually return an nsTimeout. Use IsTimeout to check.
162 return static_cast<nsTimeout
*>(PR_PREV_LINK(this));
165 // Window for which this timeout fires
166 nsRefPtr
<nsGlobalWindow
> mWindow
;
168 // The actual timer object
169 nsCOMPtr
<nsITimer
> mTimer
;
171 // True if the timeout was cleared
172 PRPackedBool mCleared
;
174 // True if this is one of the timeouts that are currently running
175 PRPackedBool mRunning
;
177 // Returned as value of setTimeout()
180 // Non-zero interval in milliseconds if repetitive timeout
183 // Nominal time (in microseconds since the epoch) to run this
187 // Principal with which to execute
188 nsCOMPtr
<nsIPrincipal
> mPrincipal
;
190 // stack depth at which timeout is firing
191 PRUint32 mFiringDepth
;
193 // The popup state at timeout creation time if not created from
195 PopupControlState mPopupState
;
197 // The language-specific information about the callback.
198 nsCOMPtr
<nsIScriptTimeoutHandler
> mScriptHandler
;
201 // reference count for shared usage
205 //*****************************************************************************
206 // nsGlobalWindow: Global Object for Scripting
207 //*****************************************************************************
208 // Beware that all scriptable interfaces implemented by
209 // nsGlobalWindow will be reachable from JS, if you make this class
210 // implement new interfaces you better know what you're
211 // doing. Security wise this is very sensitive code. --
214 // nsGlobalWindow inherits PRCList for maintaining a list of all inner
215 // windows still in memory for any given outer window. This list is
216 // needed to ensure that mOuterWindow doesn't end up dangling. The
217 // nature of PRCList means that the window itself is always in the
218 // list, and an outer window's list will also contain all inner window
219 // objects that are still in memory (and in reality all inner window
220 // object's lists also contain its outer and all other inner windows
221 // belonging to the same outer window, but that's an unimportant
222 // side effect of inheriting PRCList).
224 class nsGlobalWindow
: public nsPIDOMWindow
,
225 public nsIScriptGlobalObject
,
226 public nsIDOMJSWindow
,
227 public nsIScriptObjectPrincipal
,
228 public nsIDOMEventTarget
,
229 public nsPIDOMEventTarget
,
230 public nsIDOM3EventTarget
,
231 public nsIDOMNSEventTarget
,
232 public nsIDOMViewCSS
,
233 public nsIDOMStorageWindow
,
234 public nsSupportsWeakReference
,
235 public nsIInterfaceRequestor
,
240 nsPIDOMWindow
* GetPrivateParent();
241 // callback for close event
242 void ReallyCloseWindow();
245 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
247 // nsIScriptGlobalObject
248 virtual nsIScriptContext
*GetContext();
249 virtual JSObject
*GetGlobalJSObject();
251 virtual nsresult
EnsureScriptEnvironment(PRUint32 aLangID
);
253 virtual nsIScriptContext
*GetScriptContext(PRUint32 lang
);
254 virtual void *GetScriptGlobal(PRUint32 lang
);
256 // Set a new script language context for this global. The native global
257 // for the context is created by the context's GetNativeGlobal() method.
258 virtual nsresult
SetScriptContext(PRUint32 lang
, nsIScriptContext
*aContext
);
260 virtual void OnFinalize(PRUint32 aLangID
, void *aScriptGlobal
);
261 virtual void SetScriptsEnabled(PRBool aEnabled
, PRBool aFireTimeouts
);
262 virtual nsresult
SetNewArguments(nsIArray
*aArguments
);
264 // nsIScriptObjectPrincipal
265 virtual nsIPrincipal
* GetPrincipal();
271 NS_DECL_NSIDOMWINDOW2
273 // nsIDOMWindowInternal
274 NS_DECL_NSIDOMWINDOWINTERNAL
277 NS_DECL_NSIDOMJSWINDOW
280 NS_DECL_NSIDOMEVENTTARGET
282 // nsIDOM3EventTarget
283 NS_DECL_NSIDOM3EVENTTARGET
285 // nsIDOMNSEventTarget
286 NS_DECL_NSIDOMNSEVENTTARGET
289 virtual NS_HIDDEN_(nsPIDOMWindow
*) GetPrivateRoot();
290 virtual NS_HIDDEN_(nsresult
) Activate();
291 virtual NS_HIDDEN_(nsresult
) Deactivate();
292 virtual NS_HIDDEN_(void) SetChromeEventHandler(nsPIDOMEventTarget
* aChromeEventHandler
);
293 virtual NS_HIDDEN_(nsIFocusController
*) GetRootFocusController();
295 virtual NS_HIDDEN_(void) SetOpenerScriptPrincipal(nsIPrincipal
* aPrincipal
);
296 virtual NS_HIDDEN_(nsIPrincipal
*) GetOpenerScriptPrincipal();
298 virtual NS_HIDDEN_(PopupControlState
) PushPopupControlState(PopupControlState state
, PRBool aForce
) const;
299 virtual NS_HIDDEN_(void) PopPopupControlState(PopupControlState state
) const;
300 virtual NS_HIDDEN_(PopupControlState
) GetPopupControlState() const;
302 virtual NS_HIDDEN_(nsresult
) SaveWindowState(nsISupports
**aState
);
303 virtual NS_HIDDEN_(nsresult
) RestoreWindowState(nsISupports
*aState
);
304 virtual NS_HIDDEN_(nsresult
) ResumeTimeouts();
305 virtual NS_HIDDEN_(nsresult
) FireDelayedDOMEvents();
306 virtual NS_HIDDEN_(PRBool
) IsFrozen() const
311 virtual NS_HIDDEN_(PRBool
) WouldReuseInnerWindow(nsIDocument
*aNewDocument
);
313 virtual NS_HIDDEN_(nsPIDOMEventTarget
*) GetTargetForDOMEvent()
315 return static_cast<nsPIDOMEventTarget
*>(GetOuterWindowInternal());
317 virtual NS_HIDDEN_(nsPIDOMEventTarget
*) GetTargetForEventTargetChain()
319 return static_cast<nsPIDOMEventTarget
*>(GetCurrentInnerWindowInternal());
321 virtual NS_HIDDEN_(nsresult
) PreHandleEvent(nsEventChainPreVisitor
& aVisitor
);
322 virtual NS_HIDDEN_(nsresult
) PostHandleEvent(nsEventChainPostVisitor
& aVisitor
);
323 virtual NS_HIDDEN_(nsresult
) DispatchDOMEvent(nsEvent
* aEvent
,
324 nsIDOMEvent
* aDOMEvent
,
325 nsPresContext
* aPresContext
,
326 nsEventStatus
* aEventStatus
);
327 virtual NS_HIDDEN_(nsresult
) GetListenerManager(PRBool aCreateIfNotFound
,
328 nsIEventListenerManager
** aResult
);
329 virtual NS_HIDDEN_(nsresult
) AddEventListenerByIID(nsIDOMEventListener
*aListener
,
331 virtual NS_HIDDEN_(nsresult
) RemoveEventListenerByIID(nsIDOMEventListener
*aListener
,
333 virtual NS_HIDDEN_(nsresult
) GetSystemEventGroup(nsIDOMEventGroup
** aGroup
);
334 virtual NS_HIDDEN_(nsresult
) GetContextForEventHandlers(nsIScriptContext
** aContext
);
336 virtual NS_HIDDEN_(void) SetDocShell(nsIDocShell
* aDocShell
);
337 virtual NS_HIDDEN_(nsresult
) SetNewDocument(nsIDocument
*aDocument
,
339 PRBool aClearScopeHint
);
340 virtual NS_HIDDEN_(void) SetOpenerWindow(nsIDOMWindowInternal
*aOpener
,
341 PRBool aOriginalOpener
);
342 virtual NS_HIDDEN_(void) EnsureSizeUpToDate();
344 virtual NS_HIDDEN_(void) EnterModalState();
345 virtual NS_HIDDEN_(void) LeaveModalState();
348 NS_DECL_NSIDOMVIEWCSS
350 // nsIDOMAbstractView
351 NS_DECL_NSIDOMABSTRACTVIEW
353 // nsIDOMStorageWindow
354 NS_DECL_NSIDOMSTORAGEWINDOW
356 // nsIInterfaceRequestor
357 NS_DECL_NSIINTERFACEREQUESTOR
360 nsGlobalWindow(nsGlobalWindow
*aOuterWindow
);
362 static nsGlobalWindow
*FromWrapper(nsIXPConnectWrappedNative
*wrapper
)
364 // Make sure this matches the casts we do in QueryInterface().
365 return (nsGlobalWindow
*)(nsIScriptGlobalObject
*)wrapper
->Native();
368 nsIScriptContext
*GetContextInternal()
371 return GetOuterWindowInternal()->mContext
;
377 nsIScriptContext
*GetScriptContextInternal(PRUint32 aLangID
)
379 NS_ASSERTION(NS_STID_VALID(aLangID
), "Invalid language");
381 return GetOuterWindowInternal()->mScriptContexts
[NS_STID_INDEX(aLangID
)];
384 return mScriptContexts
[NS_STID_INDEX(aLangID
)];
387 nsGlobalWindow
*GetOuterWindowInternal()
389 return static_cast<nsGlobalWindow
*>(GetOuterWindow());
392 nsGlobalWindow
*GetCurrentInnerWindowInternal()
394 return static_cast<nsGlobalWindow
*>(mInnerWindow
);
397 nsGlobalWindow
*EnsureInnerWindowInternal()
399 return static_cast<nsGlobalWindow
*>(EnsureInnerWindow());
402 PRBool
IsCreatingInnerWindow() const
404 return mCreatingInnerWindow
;
407 PRBool
IsChromeWindow() const
412 nsresult
Observe(nsISupports
* aSubject
, const char* aTopic
,
413 const PRUnichar
* aData
);
415 static void ShutDown();
416 static void CleanupCachedXBLHandlers(nsGlobalWindow
* aWindow
);
417 static PRBool
IsCallerChrome();
418 static void CloseBlockScriptTerminationFunc(nsISupports
*aRef
);
420 static void RunPendingTimeoutsRecursive(nsGlobalWindow
*aTopWindow
,
421 nsGlobalWindow
*aWindow
);
423 friend class WindowStateHolder
;
425 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(nsGlobalWindow
,
426 nsIScriptGlobalObject
)
428 void InitJavaProperties();
430 virtual NS_HIDDEN_(void*)
431 GetCachedXBLPrototypeHandler(nsXBLPrototypeHandler
* aKey
);
433 virtual NS_HIDDEN_(void)
434 CacheXBLPrototypeHandler(nsXBLPrototypeHandler
* aKey
,
435 nsScriptObjectHolder
& aHandler
);
437 static PRBool
DOMWindowDumpEnabled();
441 virtual ~nsGlobalWindow();
443 void ClearControllers();
445 void FreeInnerObjects(PRBool aClearScope
);
446 nsGlobalWindow
*CallerInnerWindow();
448 nsresult
SetNewDocument(nsIDocument
*aDocument
,
450 PRBool aClearScopeHint
,
451 PRBool aIsInternalCall
);
453 // Get the parent, returns null if this is a toplevel window
454 nsIDOMWindowInternal
*GetParentInternal();
457 PRBool
IsPopupSpamWindow()
459 if (IsInnerWindow() && !mOuterWindow
) {
463 return GetOuterWindowInternal()->mIsPopupSpam
;
466 void SetPopupSpamWindow(PRBool aPopup
)
468 if (IsInnerWindow() && !mOuterWindow
) {
469 NS_ERROR("SetPopupSpamWindow() called on inner window w/o an outer!");
474 GetOuterWindowInternal()->mIsPopupSpam
= aPopup
;
477 // Window Control Functions
479 * @param aURL the URL to load in the new window
480 * @param aName the name to use for the new window
481 * @param aOptions the window options to use for the new window
482 * @param aDialog true when called from variants of OpenDialog. If this is
483 * true, this method will skip popup blocking checks. The
484 * aDialog argument is passed on to the window watcher.
485 * @param aCalledNoScript true when called via the [noscript] open()
486 * and openDialog() methods. When this is true, we do
487 * NOT want to use the JS stack for things like caller
489 * @param aDoJSFixups true when this is the content-accessible JS version of
490 * window opening. When true, popups do not cause us to
491 * throw, we save the caller's principal in the new window
492 * for later consumption, and we make sure that there is a
493 * document in the newly-opened window. Note that this
494 * last will only be done if the newly-opened window is
496 * @param argv The arguments to pass to the new window. The first
497 * three args, if present, will be aURL, aName, and aOptions. So
498 * this param only matters if there are more than 3 arguments.
499 * @param argc The number of arguments in argv.
500 * @param aExtraArgument Another way to pass arguments in. This is mutually
501 * exclusive with the argv/argc approach.
502 * @param aJSCallerContext The calling script's context. This must be nsnull
503 * when aCalledNoScript is true.
504 * @param aReturn [out] The window that was opened, if any.
506 * @note that the boolean args are const because the function shouldn't be
507 * messing with them. That also makes it easier for the compiler to sort out
508 * its build warning stuff.
510 NS_HIDDEN_(nsresult
) OpenInternal(const nsAString
& aUrl
,
511 const nsAString
& aName
,
512 const nsAString
& aOptions
,
514 PRBool aContentModal
,
515 PRBool aCalledNoScript
,
518 nsISupports
*aExtraArgument
,
519 nsIPrincipal
*aCalleePrincipal
,
520 JSContext
*aJSCallerContext
,
521 nsIDOMWindow
**aReturn
);
523 static void CloseWindow(nsISupports
* aWindow
);
524 static void ClearWindowScope(nsISupports
* aWindow
);
527 // Language agnostic timeout function (all args passed)
528 nsresult
SetTimeoutOrInterval(nsIScriptTimeoutHandler
*aHandler
,
530 PRBool aIsInterval
, PRInt32
*aReturn
);
531 nsresult
ClearTimeoutOrInterval(PRInt32 aTimerID
);
533 // JS specific timeout functions (JS args grabbed from context).
534 nsresult
SetTimeoutOrInterval(PRBool aIsInterval
, PRInt32
* aReturn
);
535 nsresult
ClearTimeoutOrInterval();
537 // The timeout implementation functions.
538 void RunTimeout(nsTimeout
*aTimeout
);
540 void ClearAllTimeouts();
541 // Insert aTimeout into the list, before all timeouts that would
542 // fire after it, but no earlier than mTimeoutInsertionPoint, if any.
543 void InsertTimeoutIntoList(nsTimeout
*aTimeout
);
544 static void TimerCallback(nsITimer
*aTimer
, void *aClosure
);
547 nsresult
GetTreeOwner(nsIDocShellTreeOwner
** aTreeOwner
);
548 nsresult
GetTreeOwner(nsIBaseWindow
** aTreeOwner
);
549 nsresult
GetWebBrowserChrome(nsIWebBrowserChrome
** aBrowserChrome
);
550 // GetScrollInfo does not flush. Callers should do it themselves as needed,
551 // depending on which info they actually want off the scrollable view.
552 nsresult
GetScrollInfo(nsIScrollableView
** aScrollableView
);
553 nsresult
SecurityCheckURL(const char *aURL
);
554 nsresult
BuildURIfromBase(const char *aURL
,
556 PRBool
*aFreeSecurityPass
, JSContext
**aCXused
);
557 PopupControlState
CheckForAbusePoint();
558 OpenAllowValue
CheckOpenAllow(PopupControlState aAbuseLevel
);
559 void FireAbuseEvents(PRBool aBlocked
, PRBool aWindow
,
560 const nsAString
&aPopupURL
,
561 const nsAString
&aPopupWindowName
,
562 const nsAString
&aPopupWindowFeatures
);
563 void FireOfflineStatusEvent();
565 void FlushPendingNotifications(mozFlushType aType
);
566 void EnsureReflowFlushAndPaint();
567 nsresult
CheckSecurityWidthAndHeight(PRInt32
* width
, PRInt32
* height
);
568 nsresult
CheckSecurityLeftAndTop(PRInt32
* left
, PRInt32
* top
);
569 static PRBool
CanSetProperty(const char *aPrefName
);
571 static void MakeScriptDialogTitle(nsAString
&aOutTitle
);
573 static PRBool
CanMoveResizeWindows();
575 PRBool
GetBlurSuppression();
577 // If aDoFlush is true, we'll flush our own layout; otherwise we'll try to
578 // just flush our parent and only flush ourselves if we think we need to.
579 nsresult
GetScrollXY(PRInt32
* aScrollX
, PRInt32
* aScrollY
,
581 nsresult
GetScrollMaxXY(PRInt32
* aScrollMaxX
, PRInt32
* aScrollMaxY
);
583 nsresult
GetOuterSize(nsIntSize
* aSizeCSSPixels
);
584 nsresult
SetOuterSize(PRInt32 aLengthCSSPixels
, PRBool aIsWidth
);
588 return GetParentInternal() != nsnull
;
591 PRBool
DispatchCustomEvent(const char *aEventName
);
593 // If aLookForCallerOnJSStack is true, this method will look at the JS stack
594 // to determine who the caller is. If it's false, it'll use |this| as the
596 PRBool
WindowExists(const nsAString
& aName
, PRBool aLookForCallerOnJSStack
);
598 already_AddRefed
<nsIWidget
> GetMainWidget();
600 void SuspendTimeouts();
604 NS_ASSERTION(!IsFrozen(), "Double-freezing?");
610 mIsFrozen
= PR_FALSE
;
613 PRBool
IsInModalState();
615 nsTimeout
* FirstTimeout() {
616 // Note: might not actually return an nsTimeout. Use IsTimeout to check.
617 return static_cast<nsTimeout
*>(PR_LIST_HEAD(&mTimeouts
));
620 nsTimeout
* LastTimeout() {
621 // Note: might not actually return an nsTimeout. Use IsTimeout to check.
622 return static_cast<nsTimeout
*>(PR_LIST_TAIL(&mTimeouts
));
625 PRBool
IsTimeout(PRCList
* aList
) {
626 return aList
!= &mTimeouts
;
629 static void NotifyDOMWindowDestroyed(nsGlobalWindow
* aWindow
);
631 // When adding new member variables, be careful not to create cycles
632 // through JavaScript. If there is any chance that a member variable
633 // could own objects that are implemented in JavaScript, then those
634 // objects will keep the global object (this object) alive. To prevent
635 // these cycles, ownership of such members must be released in
636 // |CleanUp| and |SetDocShell|.
638 // This member is also used on both inner and outer windows, but
639 // for slightly different purposes. On inner windows it means the
640 // inner window is held onto by session history and should not
641 // change. On outer windows it means that the window is in a state
642 // where we don't want to force creation of a new inner window since
643 // we're in the middle of doing just that.
644 PRPackedBool mIsFrozen
: 1;
646 // True if the Java properties have been initialized on this
647 // window. Only used on inner windows.
648 PRPackedBool mDidInitJavaProperties
: 1;
650 // These members are only used on outer window objects. Make sure
651 // you never set any of these on an inner object!
652 PRPackedBool mFullScreen
: 1;
653 PRPackedBool mIsClosed
: 1;
654 PRPackedBool mInClose
: 1;
655 // mHavePendingClose means we've got a termination function set to
656 // close us when the JS stops executing or that we have a close
657 // event posted. If this is set, just ignore window.close() calls.
658 PRPackedBool mHavePendingClose
: 1;
659 PRPackedBool mHadOriginalOpener
: 1;
660 PRPackedBool mIsPopupSpam
: 1;
662 // Indicates whether scripts are allowed to close this window.
663 PRPackedBool mBlockScriptedClosingFlag
: 1;
665 // Track what sorts of events we need to fire when thawed
666 PRPackedBool mFireOfflineStatusChangeEventOnThaw
: 1;
668 // Indicates whether we're in the middle of creating an initializing
669 // a new inner window object.
670 PRPackedBool mCreatingInnerWindow
: 1;
672 // Fast way to tell if this is a chrome window (without having to QI).
673 PRPackedBool mIsChrome
: 1;
675 nsCOMPtr
<nsIScriptContext
> mContext
;
677 nsCOMPtr
<nsIControllers
> mControllers
;
678 nsCOMPtr
<nsIArray
> mArguments
;
679 nsCOMPtr
<nsIArray
> mArgumentsLast
;
680 nsRefPtr
<nsNavigator
> mNavigator
;
681 nsRefPtr
<nsScreen
> mScreen
;
682 nsRefPtr
<nsHistory
> mHistory
;
683 nsRefPtr
<nsDOMWindowList
> mFrames
;
684 nsRefPtr
<nsBarProp
> mMenubar
;
685 nsRefPtr
<nsBarProp
> mToolbar
;
686 nsRefPtr
<nsBarProp
> mLocationbar
;
687 nsRefPtr
<nsBarProp
> mPersonalbar
;
688 nsRefPtr
<nsBarProp
> mStatusbar
;
689 nsRefPtr
<nsBarProp
> mScrollbars
;
690 nsCOMPtr
<nsIWeakReference
> mWindowUtils
;
691 nsRefPtr
<nsLocation
> mLocation
;
693 nsString mDefaultStatus
;
694 // index 0->language_id 1, so index MAX-1 == language_id MAX
695 nsCOMPtr
<nsIScriptContext
> mScriptContexts
[NS_STID_ARRAY_UBOUND
];
696 void * mScriptGlobals
[NS_STID_ARRAY_UBOUND
];
697 nsGlobalWindowObserver
* mObserver
;
699 nsCOMPtr
<nsIDOMCrypto
> mCrypto
;
700 nsCOMPtr
<nsIDOMPkcs11
> mPkcs11
;
703 nsCOMPtr
<nsIDOMStorageList
> gGlobalStorageList
;
705 nsCOMPtr
<nsISupports
> mInnerWindowHolders
[NS_STID_ARRAY_UBOUND
];
706 nsCOMPtr
<nsIPrincipal
> mOpenerScriptPrincipal
; // strong; used to determine
707 // whether to clear scope
709 // These member variable are used only on inner windows.
710 nsCOMPtr
<nsIEventListenerManager
> mListenerManager
;
712 // If mTimeoutInsertionPoint is non-null, insertions should happen after it.
713 nsTimeout
* mTimeoutInsertionPoint
;
714 PRUint32 mTimeoutPublicIdCounter
;
715 PRUint32 mTimeoutFiringDepth
;
716 nsCOMPtr
<nsIDOMStorage
> mSessionStorage
;
718 // Holder of the dummy java plugin, used to expose window.java and
720 nsRefPtr
<nsDummyJavaPluginOwner
> mDummyJavaPluginOwner
;
722 // These member variables are used on both inner and the outer windows.
723 nsCOMPtr
<nsIPrincipal
> mDocumentPrincipal
;
724 nsCOMPtr
<nsIDocument
> mDoc
; // For fast access to principals
727 nsDataHashtable
<nsStringHashKey
, PRBool
> *mPendingStorageEvents
;
730 PRBool mSetOpenerWindowCalled
;
732 nsCOMPtr
<nsIURI
> mLastOpenedURI
;
735 nsCOMPtr
<nsIDOMOfflineResourceList
> mApplicationCache
;
737 nsDataHashtable
<nsVoidPtrHashKey
, void*> mCachedXBLPrototypeHandlers
;
739 friend class nsDOMScriptableHelper
;
740 friend class nsDOMWindowUtils
;
741 friend class PostMessageEvent
;
742 static nsIFactory
*sComputedDOMStyleFactory
;
746 * nsGlobalChromeWindow inherits from nsGlobalWindow. It is the global
747 * object created for a Chrome Window only.
749 class nsGlobalChromeWindow
: public nsGlobalWindow
,
750 public nsIDOMChromeWindow
754 NS_DECL_ISUPPORTS_INHERITED
756 // nsIDOMChromeWindow interface
757 NS_DECL_NSIDOMCHROMEWINDOW
759 nsGlobalChromeWindow(nsGlobalWindow
*aOuterWindow
)
760 : nsGlobalWindow(aOuterWindow
)
765 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED_NO_UNLINK(nsGlobalChromeWindow
,
769 nsCOMPtr
<nsIBrowserDOMWindow
> mBrowserDOMWindow
;
773 * nsGlobalModalWindow inherits from nsGlobalWindow. It is the global
774 * object created for a modal content windows only (i.e. not modal
777 class nsGlobalModalWindow
: public nsGlobalWindow
,
778 public nsIDOMModalContentWindow
781 nsGlobalModalWindow(nsGlobalWindow
*aOuterWindow
)
782 : nsGlobalWindow(aOuterWindow
)
784 mIsModalContentWindow
= PR_TRUE
;
787 NS_DECL_ISUPPORTS_INHERITED
788 NS_DECL_NSIDOMMODALCONTENTWINDOW
790 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsGlobalModalWindow
, nsGlobalWindow
)
793 nsCOMPtr
<nsIVariant
> mReturnValue
;
797 //*****************************************************************************
798 // nsNavigator: Script "navigator" object
799 //*****************************************************************************
801 class nsNavigator
: public nsIDOMNavigator
,
802 public nsIDOMJSNavigator
,
803 public nsIDOMClientInformation
,
804 public nsIDOMNavigatorGeolocation
807 nsNavigator(nsIDocShell
*aDocShell
);
808 virtual ~nsNavigator();
811 NS_DECL_NSIDOMNAVIGATOR
812 NS_DECL_NSIDOMJSNAVIGATOR
813 NS_DECL_NSIDOMCLIENTINFORMATION
814 NS_DECL_NSIDOMNAVIGATORGEOLOCATION
816 void SetDocShell(nsIDocShell
*aDocShell
);
817 nsIDocShell
*GetDocShell()
822 void LoadingNewDocument();
823 nsresult
RefreshMIMEArray();
826 nsRefPtr
<nsMimeTypeArray
> mMimeTypes
;
827 nsRefPtr
<nsPluginArray
> mPlugins
;
828 nsRefPtr
<nsGeolocation
> mGeolocation
;
829 nsIDocShell
* mDocShell
; // weak reference
831 static jsval sPrefInternal_id
;
836 //*****************************************************************************
837 // nsLocation: Script "location" object
838 //*****************************************************************************
840 class nsLocation
: public nsIDOMLocation
843 nsLocation(nsIDocShell
*aDocShell
);
844 virtual ~nsLocation();
848 void SetDocShell(nsIDocShell
*aDocShell
);
849 nsIDocShell
*GetDocShell();
852 NS_DECL_NSIDOMLOCATION
855 // In the case of jar: uris, we sometimes want the place the jar was
856 // fetched from as the URI instead of the jar: uri itself. Pass in
857 // PR_TRUE for aGetInnermostURI when that's the case.
858 nsresult
GetURI(nsIURI
** aURL
, PRBool aGetInnermostURI
= PR_FALSE
);
859 nsresult
GetWritableURI(nsIURI
** aURL
);
860 nsresult
SetURI(nsIURI
* aURL
, PRBool aReplace
= PR_FALSE
);
861 nsresult
SetHrefWithBase(const nsAString
& aHref
, nsIURI
* aBase
,
863 nsresult
SetHrefWithContext(JSContext
* cx
, const nsAString
& aHref
,
866 nsresult
GetSourceBaseURL(JSContext
* cx
, nsIURI
** sourceURL
);
867 nsresult
GetSourceDocument(JSContext
* cx
, nsIDocument
** aDocument
);
869 nsresult
CheckURL(nsIURI
*url
, nsIDocShellLoadInfo
** aLoadInfo
);
870 nsresult
FindUsableBaseURI(nsIURI
* aBaseURI
, nsIDocShell
* aParent
, nsIURI
** aUsableURI
);
875 /* factory function */
877 NS_NewScriptGlobalObject(PRBool aIsChrome
, PRBool aIsModalContentWindow
,
878 nsIScriptGlobalObject
**aResult
);
880 #endif /* nsGlobalWindow_h___ */