Bug 441233 Missing focus events in Thunderbird account wizard dialog r=surkov.alexander
[wine-gecko.git] / dom / src / base / nsGlobalWindow.h
blobe16e1bd097f17734ae04c16784810e3be5cc3fd1
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
14 * License.
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.
23 * Contributor(s):
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___
46 // Local Includes
47 // Helper Classes
48 #include "nsCOMPtr.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"
56 // Interfaces Needed
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 "nsIDOMNSLocation.h"
69 #include "nsIDOMWindowInternal.h"
70 #include "nsIInterfaceRequestor.h"
71 #include "nsIInterfaceRequestorUtils.h"
72 #include "nsIDOMJSWindow.h"
73 #include "nsIDOMChromeWindow.h"
74 #include "nsIScriptGlobalObject.h"
75 #include "nsIScriptContext.h"
76 #include "nsIScriptObjectPrincipal.h"
77 #include "nsIScriptTimeoutHandler.h"
78 #include "nsITimer.h"
79 #include "nsIWebBrowserChrome.h"
80 #include "nsPIDOMWindow.h"
81 #include "nsIDOMModalContentWindow.h"
82 #include "nsIScriptSecurityManager.h"
83 #include "nsIEventListenerManager.h"
84 #include "nsIDOMDocument.h"
85 #include "nsIDOMCrypto.h"
86 #include "nsIDOMPkcs11.h"
87 #include "nsIPrincipal.h"
88 #include "nsPluginArray.h"
89 #include "nsMimeTypeArray.h"
90 #include "nsIXPCScriptable.h"
91 #include "nsPoint.h"
92 #include "nsSize.h"
93 #include "mozFlushType.h"
94 #include "prclist.h"
95 #include "nsIDOMStorage.h"
96 #include "nsIDOMStorageList.h"
97 #include "nsIDOMStorageWindow.h"
98 #include "nsIDOMOfflineResourceList.h"
99 #include "nsPIDOMEventTarget.h"
100 #include "nsIArray.h"
102 #define DEFAULT_HOME_PAGE "www.mozilla.org"
103 #define PREF_BROWSER_STARTUP_HOMEPAGE "browser.startup.homepage"
105 class nsIDOMBarProp;
106 class nsIDocument;
107 class nsIContent;
108 class nsPresContext;
109 class nsIDOMEvent;
110 class nsIScrollableView;
111 class nsIControllers;
113 class nsBarProp;
114 class nsLocation;
115 class nsNavigator;
116 class nsScreen;
117 class nsHistory;
118 class nsIDocShellLoadInfo;
119 class WindowStateHolder;
120 class nsGlobalWindowObserver;
121 class nsGlobalWindow;
122 #ifdef OJI
123 class nsDummyJavaPluginOwner;
124 #endif
125 class PostMessageEvent;
127 class nsDOMOfflineResourceList;
128 class nsDOMOfflineLoadStatusList;
130 // permissible values for CheckOpenAllow
131 enum OpenAllowValue {
132 allowNot = 0, // the window opening is denied
133 allowNoAbuse, // allowed: not a popup
134 allowWhitelisted // allowed: it's whitelisted or popup blocking is disabled
137 extern nsresult
138 NS_CreateJSTimeoutHandler(nsGlobalWindow *aWindow,
139 PRBool *aIsInterval,
140 PRInt32 *aInterval,
141 nsIScriptTimeoutHandler **aRet);
144 * Timeout struct that holds information about each script
145 * timeout. Holds a strong reference to an nsIScriptTimeoutHandler, which
146 * abstracts the language specific cruft.
148 struct nsTimeout : PRCList
150 nsTimeout();
151 ~nsTimeout();
153 nsrefcnt Release();
154 nsrefcnt AddRef();
156 nsTimeout* Next() {
157 // Note: might not actually return an nsTimeout. Use IsTimeout to check.
158 return static_cast<nsTimeout*>(PR_NEXT_LINK(this));
161 nsTimeout* Prev() {
162 // Note: might not actually return an nsTimeout. Use IsTimeout to check.
163 return static_cast<nsTimeout*>(PR_PREV_LINK(this));
166 // Window for which this timeout fires
167 nsRefPtr<nsGlobalWindow> mWindow;
169 // The actual timer object
170 nsCOMPtr<nsITimer> mTimer;
172 // True if the timeout was cleared
173 PRPackedBool mCleared;
175 // True if this is one of the timeouts that are currently running
176 PRPackedBool mRunning;
178 // Returned as value of setTimeout()
179 PRUint32 mPublicId;
181 // Non-zero interval in milliseconds if repetitive timeout
182 PRUint32 mInterval;
184 // Nominal time (in microseconds since the epoch) to run this
185 // timeout
186 PRTime mWhen;
188 // Principal with which to execute
189 nsCOMPtr<nsIPrincipal> mPrincipal;
191 // stack depth at which timeout is firing
192 PRUint32 mFiringDepth;
194 // The popup state at timeout creation time if not created from
195 // another timeout
196 PopupControlState mPopupState;
198 // The language-specific information about the callback.
199 nsCOMPtr<nsIScriptTimeoutHandler> mScriptHandler;
201 private:
202 // reference count for shared usage
203 PRInt32 mRefCnt;
206 //*****************************************************************************
207 // nsGlobalWindow: Global Object for Scripting
208 //*****************************************************************************
209 // Beware that all scriptable interfaces implemented by
210 // nsGlobalWindow will be reachable from JS, if you make this class
211 // implement new interfaces you better know what you're
212 // doing. Security wise this is very sensitive code. --
213 // jst@netscape.com
215 // nsGlobalWindow inherits PRCList for maintaining a list of all inner
216 // windows still in memory for any given outer window. This list is
217 // needed to ensure that mOuterWindow doesn't end up dangling. The
218 // nature of PRCList means that the window itself is always in the
219 // list, and an outer window's list will also contain all inner window
220 // objects that are still in memory (and in reality all inner window
221 // object's lists also contain its outer and all other inner windows
222 // belonging to the same outer window, but that's an unimportant
223 // side effect of inheriting PRCList).
225 class nsGlobalWindow : public nsPIDOMWindow,
226 public nsIScriptGlobalObject,
227 public nsIDOMJSWindow,
228 public nsIScriptObjectPrincipal,
229 public nsIDOMEventTarget,
230 public nsPIDOMEventTarget,
231 public nsIDOM3EventTarget,
232 public nsIDOMNSEventTarget,
233 public nsIDOMViewCSS,
234 public nsIDOMStorageWindow,
235 public nsSupportsWeakReference,
236 public nsIInterfaceRequestor,
237 public PRCListStr
239 public:
240 // public methods
241 nsPIDOMWindow* GetPrivateParent();
242 // callback for close event
243 void ReallyCloseWindow();
245 // nsISupports
246 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
248 // nsIScriptGlobalObject
249 virtual nsIScriptContext *GetContext();
250 virtual JSObject *GetGlobalJSObject();
252 virtual nsresult EnsureScriptEnvironment(PRUint32 aLangID);
254 virtual nsIScriptContext *GetScriptContext(PRUint32 lang);
255 virtual void *GetScriptGlobal(PRUint32 lang);
257 // Set a new script language context for this global. The native global
258 // for the context is created by the context's GetNativeGlobal() method.
259 virtual nsresult SetScriptContext(PRUint32 lang, nsIScriptContext *aContext);
261 virtual void OnFinalize(PRUint32 aLangID, void *aScriptGlobal);
262 virtual void SetScriptsEnabled(PRBool aEnabled, PRBool aFireTimeouts);
263 virtual nsresult SetNewArguments(nsIArray *aArguments);
265 // nsIScriptObjectPrincipal
266 virtual nsIPrincipal* GetPrincipal();
268 // nsIDOMWindow
269 NS_DECL_NSIDOMWINDOW
271 // nsIDOMWindow2
272 NS_DECL_NSIDOMWINDOW2
274 // nsIDOMWindowInternal
275 NS_DECL_NSIDOMWINDOWINTERNAL
277 // nsIDOMJSWindow
278 NS_DECL_NSIDOMJSWINDOW
280 // nsIDOMEventTarget
281 NS_DECL_NSIDOMEVENTTARGET
283 // nsIDOM3EventTarget
284 NS_DECL_NSIDOM3EVENTTARGET
286 // nsIDOMNSEventTarget
287 NS_DECL_NSIDOMNSEVENTTARGET
289 // nsPIDOMWindow
290 virtual NS_HIDDEN_(nsPIDOMWindow*) GetPrivateRoot();
291 virtual NS_HIDDEN_(nsresult) Activate();
292 virtual NS_HIDDEN_(nsresult) Deactivate();
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
308 return mIsFrozen;
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,
330 const nsIID& aIID);
331 virtual NS_HIDDEN_(nsresult) RemoveEventListenerByIID(nsIDOMEventListener *aListener,
332 const nsIID& aIID);
333 virtual NS_HIDDEN_(nsresult) GetSystemEventGroup(nsIDOMEventGroup** aGroup);
335 virtual NS_HIDDEN_(void) SetDocShell(nsIDocShell* aDocShell);
336 virtual NS_HIDDEN_(nsresult) SetNewDocument(nsIDocument *aDocument,
337 nsISupports *aState,
338 PRBool aClearScopeHint);
339 virtual NS_HIDDEN_(void) SetOpenerWindow(nsIDOMWindowInternal *aOpener,
340 PRBool aOriginalOpener);
341 virtual NS_HIDDEN_(void) EnsureSizeUpToDate();
343 virtual NS_HIDDEN_(void) EnterModalState();
344 virtual NS_HIDDEN_(void) LeaveModalState();
346 // nsIDOMViewCSS
347 NS_DECL_NSIDOMVIEWCSS
349 // nsIDOMAbstractView
350 NS_DECL_NSIDOMABSTRACTVIEW
352 // nsIDOMStorageWindow
353 NS_DECL_NSIDOMSTORAGEWINDOW
355 // nsIInterfaceRequestor
356 NS_DECL_NSIINTERFACEREQUESTOR
358 // Object Management
359 nsGlobalWindow(nsGlobalWindow *aOuterWindow);
361 static nsGlobalWindow *FromWrapper(nsIXPConnectWrappedNative *wrapper)
363 // Make sure this matches the casts we do in QueryInterface().
364 return (nsGlobalWindow *)(nsIScriptGlobalObject *)wrapper->Native();
367 nsIScriptContext *GetContextInternal()
369 if (mOuterWindow) {
370 return GetOuterWindowInternal()->mContext;
373 return mContext;
376 nsIScriptContext *GetScriptContextInternal(PRUint32 aLangID)
378 NS_ASSERTION(NS_STID_VALID(aLangID), "Invalid language");
379 if (mOuterWindow) {
380 return GetOuterWindowInternal()->mScriptContexts[NS_STID_INDEX(aLangID)];
383 return mScriptContexts[NS_STID_INDEX(aLangID)];
386 nsGlobalWindow *GetOuterWindowInternal()
388 return static_cast<nsGlobalWindow *>(GetOuterWindow());
391 nsGlobalWindow *GetCurrentInnerWindowInternal()
393 return static_cast<nsGlobalWindow *>(mInnerWindow);
396 nsGlobalWindow *EnsureInnerWindowInternal()
398 return static_cast<nsGlobalWindow *>(EnsureInnerWindow());
401 PRBool IsCreatingInnerWindow() const
403 return mCreatingInnerWindow;
406 PRBool IsChromeWindow() const
408 return mIsChrome;
411 nsresult Observe(nsISupports* aSubject, const char* aTopic,
412 const PRUnichar* aData);
414 static void ShutDown();
415 static void CleanupCachedXBLHandlers(nsGlobalWindow* aWindow);
416 static PRBool IsCallerChrome();
417 static void CloseBlockScriptTerminationFunc(nsISupports *aRef);
419 static void RunPendingTimeoutsRecursive(nsGlobalWindow *aTopWindow,
420 nsGlobalWindow *aWindow);
422 friend class WindowStateHolder;
424 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(nsGlobalWindow,
425 nsIScriptGlobalObject)
427 void InitJavaProperties();
429 virtual NS_HIDDEN_(void*)
430 GetCachedXBLPrototypeHandler(nsXBLPrototypeHandler* aKey);
432 virtual NS_HIDDEN_(void)
433 CacheXBLPrototypeHandler(nsXBLPrototypeHandler* aKey,
434 nsScriptObjectHolder& aHandler);
437 protected:
438 // Object Management
439 virtual ~nsGlobalWindow();
440 void CleanUp();
441 void ClearControllers();
443 void FreeInnerObjects(PRBool aClearScope);
444 nsGlobalWindow *CallerInnerWindow();
446 nsresult SetNewDocument(nsIDocument *aDocument,
447 nsISupports *aState,
448 PRBool aClearScopeHint,
449 PRBool aIsInternalCall);
451 // Get the parent, returns null if this is a toplevel window
452 nsIDOMWindowInternal *GetParentInternal();
454 // popup tracking
455 PRBool IsPopupSpamWindow()
457 if (IsInnerWindow() && !mOuterWindow) {
458 return PR_FALSE;
461 return GetOuterWindowInternal()->mIsPopupSpam;
464 void SetPopupSpamWindow(PRBool aPopup)
466 if (IsInnerWindow() && !mOuterWindow) {
467 NS_ERROR("SetPopupSpamWindow() called on inner window w/o an outer!");
469 return;
472 GetOuterWindowInternal()->mIsPopupSpam = aPopup;
475 // Window Control Functions
477 * @param aURL the URL to load in the new window
478 * @param aName the name to use for the new window
479 * @param aOptions the window options to use for the new window
480 * @param aDialog true when called from variants of OpenDialog. If this is
481 * true, this method will skip popup blocking checks. The
482 * aDialog argument is passed on to the window watcher.
483 * @param aCalledNoScript true when called via the [noscript] open()
484 * and openDialog() methods. When this is true, we do
485 * NOT want to use the JS stack for things like caller
486 * determination.
487 * @param aDoJSFixups true when this is the content-accessible JS version of
488 * window opening. When true, popups do not cause us to
489 * throw, we save the caller's principal in the new window
490 * for later consumption, and we make sure that there is a
491 * document in the newly-opened window. Note that this
492 * last will only be done if the newly-opened window is
493 * non-chrome.
494 * @param argv The arguments to pass to the new window. The first
495 * three args, if present, will be aURL, aName, and aOptions. So
496 * this param only matters if there are more than 3 arguments.
497 * @param argc The number of arguments in argv.
498 * @param aExtraArgument Another way to pass arguments in. This is mutually
499 * exclusive with the argv/argc approach.
500 * @param aJSCallerContext The calling script's context. This must be nsnull
501 * when aCalledNoScript is true.
502 * @param aReturn [out] The window that was opened, if any.
504 * @note that the boolean args are const because the function shouldn't be
505 * messing with them. That also makes it easier for the compiler to sort out
506 * its build warning stuff.
508 NS_HIDDEN_(nsresult) OpenInternal(const nsAString& aUrl,
509 const nsAString& aName,
510 const nsAString& aOptions,
511 PRBool aDialog,
512 PRBool aContentModal,
513 PRBool aCalledNoScript,
514 PRBool aDoJSFixups,
515 nsIArray *argv,
516 nsISupports *aExtraArgument,
517 nsIPrincipal *aCalleePrincipal,
518 JSContext *aJSCallerContext,
519 nsIDOMWindow **aReturn);
521 static void CloseWindow(nsISupports* aWindow);
522 static void ClearWindowScope(nsISupports* aWindow);
524 // Timeout Functions
525 // Language agnostic timeout function (all args passed)
526 nsresult SetTimeoutOrInterval(nsIScriptTimeoutHandler *aHandler,
527 PRInt32 interval,
528 PRBool aIsInterval, PRInt32 *aReturn);
529 nsresult ClearTimeoutOrInterval(PRInt32 aTimerID);
531 // JS specific timeout functions (JS args grabbed from context).
532 nsresult SetTimeoutOrInterval(PRBool aIsInterval, PRInt32* aReturn);
533 nsresult ClearTimeoutOrInterval();
535 // The timeout implementation functions.
536 void RunTimeout(nsTimeout *aTimeout);
538 void ClearAllTimeouts();
539 // Insert aTimeout into the list, before all timeouts that would
540 // fire after it, but no earlier than mTimeoutInsertionPoint, if any.
541 void InsertTimeoutIntoList(nsTimeout *aTimeout);
542 static void TimerCallback(nsITimer *aTimer, void *aClosure);
544 // Helper Functions
545 nsresult GetTreeOwner(nsIDocShellTreeOwner** aTreeOwner);
546 nsresult GetTreeOwner(nsIBaseWindow** aTreeOwner);
547 nsresult GetWebBrowserChrome(nsIWebBrowserChrome** aBrowserChrome);
548 // GetScrollInfo does not flush. Callers should do it themselves as needed,
549 // depending on which info they actually want off the scrollable view.
550 nsresult GetScrollInfo(nsIScrollableView** aScrollableView);
551 nsresult SecurityCheckURL(const char *aURL);
552 nsresult BuildURIfromBase(const char *aURL,
553 nsIURI **aBuiltURI,
554 PRBool *aFreeSecurityPass, JSContext **aCXused);
555 PopupControlState CheckForAbusePoint();
556 OpenAllowValue CheckOpenAllow(PopupControlState aAbuseLevel);
557 void FireAbuseEvents(PRBool aBlocked, PRBool aWindow,
558 const nsAString &aPopupURL,
559 const nsAString &aPopupWindowName,
560 const nsAString &aPopupWindowFeatures);
561 void FireOfflineStatusEvent();
563 void FlushPendingNotifications(mozFlushType aType);
564 void EnsureReflowFlushAndPaint();
565 nsresult CheckSecurityWidthAndHeight(PRInt32* width, PRInt32* height);
566 nsresult CheckSecurityLeftAndTop(PRInt32* left, PRInt32* top);
567 static PRBool CanSetProperty(const char *aPrefName);
569 static void MakeScriptDialogTitle(nsAString &aOutTitle);
571 static PRBool CanMoveResizeWindows();
573 // Helper for window.find()
574 nsresult FindInternal(const nsAString& aStr, PRBool caseSensitive,
575 PRBool backwards, PRBool wrapAround, PRBool wholeWord,
576 PRBool searchInFrames, PRBool showDialog,
577 PRBool *aReturn);
579 nsresult ConvertCharset(const nsAString& aStr, char** aDest);
581 PRBool GetBlurSuppression();
583 // If aDoFlush is true, we'll flush our own layout; otherwise we'll try to
584 // just flush our parent and only flush ourselves if we think we need to.
585 nsresult GetScrollXY(PRInt32* aScrollX, PRInt32* aScrollY,
586 PRBool aDoFlush);
587 nsresult GetScrollMaxXY(PRInt32* aScrollMaxX, PRInt32* aScrollMaxY);
589 nsresult GetOuterSize(nsIntSize* aSizeCSSPixels);
590 nsresult SetOuterSize(PRInt32 aLengthCSSPixels, PRBool aIsWidth);
592 PRBool IsFrame()
594 return GetParentInternal() != nsnull;
597 PRBool DispatchCustomEvent(const char *aEventName);
599 // If aLookForCallerOnJSStack is true, this method will look at the JS stack
600 // to determine who the caller is. If it's false, it'll use |this| as the
601 // caller.
602 PRBool WindowExists(const nsAString& aName, PRBool aLookForCallerOnJSStack);
604 already_AddRefed<nsIWidget> GetMainWidget();
606 void SuspendTimeouts();
608 void Freeze()
610 NS_ASSERTION(!IsFrozen(), "Double-freezing?");
611 mIsFrozen = PR_TRUE;
614 void Thaw()
616 mIsFrozen = PR_FALSE;
619 PRBool IsInModalState();
621 nsTimeout* FirstTimeout() {
622 // Note: might not actually return an nsTimeout. Use IsTimeout to check.
623 return static_cast<nsTimeout*>(PR_LIST_HEAD(&mTimeouts));
626 nsTimeout* LastTimeout() {
627 // Note: might not actually return an nsTimeout. Use IsTimeout to check.
628 return static_cast<nsTimeout*>(PR_LIST_TAIL(&mTimeouts));
631 PRBool IsTimeout(PRCList* aList) {
632 return aList != &mTimeouts;
635 static void NotifyDOMWindowDestroyed(nsGlobalWindow* aWindow);
637 // When adding new member variables, be careful not to create cycles
638 // through JavaScript. If there is any chance that a member variable
639 // could own objects that are implemented in JavaScript, then those
640 // objects will keep the global object (this object) alive. To prevent
641 // these cycles, ownership of such members must be released in
642 // |CleanUp| and |SetDocShell|.
644 // This member is also used on both inner and outer windows, but
645 // for slightly different purposes. On inner windows it means the
646 // inner window is held onto by session history and should not
647 // change. On outer windows it means that the window is in a state
648 // where we don't want to force creation of a new inner window since
649 // we're in the middle of doing just that.
650 PRPackedBool mIsFrozen : 1;
652 // True if the Java properties have been initialized on this
653 // window. Only used on inner windows.
654 PRPackedBool mDidInitJavaProperties : 1;
656 // These members are only used on outer window objects. Make sure
657 // you never set any of these on an inner object!
658 PRPackedBool mFullScreen : 1;
659 PRPackedBool mIsClosed : 1;
660 PRPackedBool mInClose : 1;
661 // mHavePendingClose means we've got a termination function set to
662 // close us when the JS stops executing or that we have a close
663 // event posted. If this is set, just ignore window.close() calls.
664 PRPackedBool mHavePendingClose : 1;
665 PRPackedBool mHadOriginalOpener : 1;
666 PRPackedBool mIsPopupSpam : 1;
668 // Indicates whether scripts are allowed to close this window.
669 PRPackedBool mBlockScriptedClosingFlag : 1;
671 // Track what sorts of events we need to fire when thawed
672 PRPackedBool mFireOfflineStatusChangeEventOnThaw : 1;
674 // Indicates whether we're in the middle of creating an initializing
675 // a new inner window object.
676 PRPackedBool mCreatingInnerWindow : 1;
678 // Fast way to tell if this is a chrome window (without having to QI).
679 PRPackedBool mIsChrome : 1;
681 nsCOMPtr<nsIScriptContext> mContext;
682 nsWeakPtr mOpener;
683 nsCOMPtr<nsIControllers> mControllers;
684 nsCOMPtr<nsIArray> mArguments;
685 nsCOMPtr<nsIArray> mArgumentsLast;
686 nsRefPtr<nsNavigator> mNavigator;
687 nsRefPtr<nsScreen> mScreen;
688 nsRefPtr<nsHistory> mHistory;
689 nsRefPtr<nsDOMWindowList> mFrames;
690 nsRefPtr<nsBarProp> mMenubar;
691 nsRefPtr<nsBarProp> mToolbar;
692 nsRefPtr<nsBarProp> mLocationbar;
693 nsRefPtr<nsBarProp> mPersonalbar;
694 nsRefPtr<nsBarProp> mStatusbar;
695 nsRefPtr<nsBarProp> mScrollbars;
696 nsCOMPtr<nsIWeakReference> mWindowUtils;
697 nsRefPtr<nsLocation> mLocation;
698 nsString mStatus;
699 nsString mDefaultStatus;
700 // index 0->language_id 1, so index MAX-1 == language_id MAX
701 nsCOMPtr<nsIScriptContext> mScriptContexts[NS_STID_ARRAY_UBOUND];
702 void * mScriptGlobals[NS_STID_ARRAY_UBOUND];
703 nsGlobalWindowObserver* mObserver;
705 nsCOMPtr<nsIDOMCrypto> mCrypto;
706 nsCOMPtr<nsIDOMPkcs11> mPkcs11;
709 nsCOMPtr<nsIDOMStorageList> gGlobalStorageList;
711 nsCOMPtr<nsISupports> mInnerWindowHolders[NS_STID_ARRAY_UBOUND];
712 nsCOMPtr<nsIPrincipal> mOpenerScriptPrincipal; // strong; used to determine
713 // whether to clear scope
715 // These member variable are used only on inner windows.
716 nsCOMPtr<nsIEventListenerManager> mListenerManager;
717 PRCList mTimeouts;
718 // If mTimeoutInsertionPoint is non-null, insertions should happen after it.
719 nsTimeout* mTimeoutInsertionPoint;
720 PRUint32 mTimeoutPublicIdCounter;
721 PRUint32 mTimeoutFiringDepth;
722 nsCOMPtr<nsIDOMStorage> mSessionStorage;
724 #ifdef OJI
725 nsRefPtr<nsDummyJavaPluginOwner> mDummyJavaPluginOwner;
726 #endif
728 // These member variables are used on both inner and the outer windows.
729 nsCOMPtr<nsIPrincipal> mDocumentPrincipal;
730 nsCOMPtr<nsIDocument> mDoc; // For fast access to principals
731 JSObject* mJSObject;
733 nsDataHashtable<nsStringHashKey, PRBool> *mPendingStorageEvents;
735 #ifdef DEBUG
736 PRBool mSetOpenerWindowCalled;
737 PRUint32 mSerial;
738 nsCOMPtr<nsIURI> mLastOpenedURI;
739 #endif
741 nsCOMPtr<nsIDOMOfflineResourceList> mApplicationCache;
743 nsDataHashtable<nsVoidPtrHashKey, void*> mCachedXBLPrototypeHandlers;
745 friend class nsDOMScriptableHelper;
746 friend class nsDOMWindowUtils;
747 friend class PostMessageEvent;
748 static nsIFactory *sComputedDOMStyleFactory;
752 * nsGlobalChromeWindow inherits from nsGlobalWindow. It is the global
753 * object created for a Chrome Window only.
755 class nsGlobalChromeWindow : public nsGlobalWindow,
756 public nsIDOMChromeWindow
758 public:
759 // nsISupports
760 NS_DECL_ISUPPORTS_INHERITED
762 // nsIDOMChromeWindow interface
763 NS_DECL_NSIDOMCHROMEWINDOW
765 nsGlobalChromeWindow(nsGlobalWindow *aOuterWindow)
766 : nsGlobalWindow(aOuterWindow)
768 mIsChrome = PR_TRUE;
771 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED_NO_UNLINK(nsGlobalChromeWindow,
772 nsGlobalWindow)
774 protected:
775 nsCOMPtr<nsIBrowserDOMWindow> mBrowserDOMWindow;
779 * nsGlobalModalWindow inherits from nsGlobalWindow. It is the global
780 * object created for a modal content windows only (i.e. not modal
781 * chrome dialogs).
783 class nsGlobalModalWindow : public nsGlobalWindow,
784 public nsIDOMModalContentWindow
786 public:
787 nsGlobalModalWindow(nsGlobalWindow *aOuterWindow)
788 : nsGlobalWindow(aOuterWindow)
790 mIsModalContentWindow = PR_TRUE;
793 NS_DECL_ISUPPORTS_INHERITED
794 NS_DECL_NSIDOMMODALCONTENTWINDOW
796 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsGlobalModalWindow, nsGlobalWindow)
798 protected:
799 nsCOMPtr<nsIVariant> mReturnValue;
803 //*****************************************************************************
804 // nsNavigator: Script "navigator" object
805 //*****************************************************************************
807 class nsNavigator : public nsIDOMNavigator,
808 public nsIDOMJSNavigator,
809 public nsIDOMClientInformation
811 public:
812 nsNavigator(nsIDocShell *aDocShell);
813 virtual ~nsNavigator();
815 NS_DECL_ISUPPORTS
816 NS_DECL_NSIDOMNAVIGATOR
817 NS_DECL_NSIDOMJSNAVIGATOR
818 NS_DECL_NSIDOMCLIENTINFORMATION
820 void SetDocShell(nsIDocShell *aDocShell);
821 nsIDocShell *GetDocShell()
823 return mDocShell;
826 void LoadingNewDocument();
827 nsresult RefreshMIMEArray();
829 protected:
830 nsRefPtr<nsMimeTypeArray> mMimeTypes;
831 nsRefPtr<nsPluginArray> mPlugins;
832 nsIDocShell* mDocShell; // weak reference
834 static jsval sPrefInternal_id;
837 class nsIURI;
839 //*****************************************************************************
840 // nsLocation: Script "location" object
841 //*****************************************************************************
843 class nsLocation : public nsIDOMLocation,
844 public nsIDOMNSLocation
846 public:
847 nsLocation(nsIDocShell *aDocShell);
848 virtual ~nsLocation();
850 NS_DECL_ISUPPORTS
852 void SetDocShell(nsIDocShell *aDocShell);
853 nsIDocShell *GetDocShell();
855 // nsIDOMLocation
856 NS_DECL_NSIDOMLOCATION
858 // nsIDOMNSLocation
859 NS_DECL_NSIDOMNSLOCATION
861 protected:
862 // In the case of jar: uris, we sometimes want the place the jar was
863 // fetched from as the URI instead of the jar: uri itself. Pass in
864 // PR_TRUE for aGetInnermostURI when that's the case.
865 nsresult GetURI(nsIURI** aURL, PRBool aGetInnermostURI = PR_FALSE);
866 nsresult GetWritableURI(nsIURI** aURL);
867 nsresult SetURI(nsIURI* aURL, PRBool aReplace = PR_FALSE);
868 nsresult SetHrefWithBase(const nsAString& aHref, nsIURI* aBase,
869 PRBool aReplace);
870 nsresult SetHrefWithContext(JSContext* cx, const nsAString& aHref,
871 PRBool aReplace);
873 nsresult GetSourceBaseURL(JSContext* cx, nsIURI** sourceURL);
874 nsresult GetSourceDocument(JSContext* cx, nsIDocument** aDocument);
876 nsresult CheckURL(nsIURI *url, nsIDocShellLoadInfo** aLoadInfo);
877 nsresult FindUsableBaseURI(nsIURI * aBaseURI, nsIDocShell * aParent, nsIURI ** aUsableURI);
879 nsWeakPtr mDocShell;
882 /* factory function */
883 nsresult
884 NS_NewScriptGlobalObject(PRBool aIsChrome, PRBool aIsModalContentWindow,
885 nsIScriptGlobalObject **aResult);
887 #endif /* nsGlobalWindow_h___ */