1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* ***** BEGIN LICENSE BLOCK *****
3
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
5
* The contents of this file are subject to the Netscape Public License
6
* Version 1.1 (the "License"); you may not use this file except in
7
* compliance with the License. You may obtain a copy of the License at
8
* http://www.mozilla.org/NPL/
10
* Software distributed under the License is distributed on an "AS IS" basis,
11
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12
* for the specific language governing rights and limitations under the
15
* The Original Code is mozilla.org code.
17
* The Initial Developer of the Original Code is
18
* Netscape Communications Corporation.
19
* Portions created by the Initial Developer are Copyright (C) 1998
20
* the Initial Developer. All Rights Reserved.
23
* Travis Bogard <travis@netscape.com>
24
* Dan Rosen <dr@netscape.com>
25
* Vidur Apparao <vidur@netscape.com>
26
* Johnny Stenback <jst@netscape.com>
29
* Alternatively, the contents of this file may be used under the terms of
30
* either the GNU General Public License Version 2 or later (the "GPL"), or
31
* 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 NPL, 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 NPL, 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"
54
#include "nsDOMWindowList.h"
55
#include "nsIBaseWindow.h"
56
#include "nsIBrowserDOMWindow.h"
57
#include "nsIChromeEventHandler.h"
58
#include "nsIControllers.h"
59
#include "nsIObserver.h"
60
#include "nsIDocShellTreeOwner.h"
61
#include "nsIDocShellTreeItem.h"
62
#include "nsIDOMViewCSS.h"
63
#include "nsIDOMEventReceiver.h"
64
#include "nsIDOM3EventTarget.h"
65
#include "nsIDOMNavigator.h"
66
#include "nsIDOMNSLocation.h"
67
#include "nsIDOMWindowInternal.h"
68
#include "nsIInterfaceRequestor.h"
69
#include "nsIInterfaceRequestorUtils.h"
70
#include "nsIDOMJSWindow.h"
71
#include "nsIDOMChromeWindow.h"
72
#include "nsIScriptGlobalObject.h"
73
#include "nsIScriptObjectPrincipal.h"
75
#include "nsIWebBrowserChrome.h"
76
#include "nsPIDOMWindow.h"
77
#include "nsIScriptSecurityManager.h"
78
#include "nsIEventListenerManager.h"
79
#include "nsIDOMDocument.h"
80
#include "nsIDOMCrypto.h"
81
#include "nsIDOMPkcs11.h"
82
#include "nsIPrincipal.h"
83
#include "nsPluginArray.h"
84
#include "nsMimeTypeArray.h"
85
#include "nsIXPCScriptable.h"
89
#define DEFAULT_HOME_PAGE "www.mozilla.org"
90
#define PREF_BROWSER_STARTUP_HOMEPAGE "browser.startup.homepage"
97
class nsIScrollableView;
99
typedef struct nsTimeoutImpl nsTimeoutImpl;
106
class nsIDocShellLoadInfo;
108
//*****************************************************************************
109
// GlobalWindowImpl: Global Object for Scripting
110
//*****************************************************************************
111
// Beware that all scriptable interfaces implemented by
112
// GlobalWindowImpl will be reachable from JS, if you make this class
113
// implement new interfaces you better know what you're
114
// doing. Security wise this is very sensitive code. --
118
class GlobalWindowImpl : public nsIScriptGlobalObject,
119
public nsIDOMWindowInternal,
120
public nsIDOMJSWindow,
121
public nsIScriptObjectPrincipal,
122
public nsIDOMEventReceiver,
123
public nsIDOM3EventTarget,
124
public nsPIDOMWindow,
125
public nsIDOMViewCSS,
126
public nsSupportsWeakReference,
127
public nsIInterfaceRequestor
133
// nsIScriptGlobalObject
134
virtual void SetContext(nsIScriptContext *aContext);
135
virtual nsIScriptContext *GetContext();
136
virtual nsresult SetNewDocument(nsIDOMDocument *aDocument,
137
PRBool aRemoveEventListeners,
138
PRBool aClearScopeHint);
139
virtual void SetDocShell(nsIDocShell* aDocShell);
140
virtual nsIDocShell *GetDocShell();
141
virtual void SetOpenerWindow(nsIDOMWindowInternal *aOpener);
142
virtual void SetGlobalObjectOwner(nsIScriptGlobalObjectOwner* aOwner);
143
virtual nsIScriptGlobalObjectOwner *GetGlobalObjectOwner();
144
virtual nsresult HandleDOMEvent(nsIPresContext* aPresContext,
145
nsEvent* aEvent, nsIDOMEvent** aDOMEvent,
147
nsEventStatus* aEventStatus);
148
virtual JSObject *GetGlobalJSObject();
149
virtual void OnFinalize(JSObject *aJSObject);
150
virtual void SetScriptsEnabled(PRBool aEnabled, PRBool aFireTimeouts);
152
// nsIScriptObjectPrincipal
153
NS_IMETHOD GetPrincipalObsolete(nsIPrincipalObsolete **prin);
154
NS_IMETHOD GetPrincipal(nsIPrincipal **prin);
160
NS_DECL_NSIDOMWINDOW2
162
// nsIDOMWindowInternal
163
NS_DECL_NSIDOMWINDOWINTERNAL
166
NS_DECL_NSIDOMJSWINDOW
169
NS_DECL_NSIDOMEVENTTARGET
171
// nsIDOM3EventTarget
172
NS_DECL_NSIDOM3EVENTTARGET
174
// nsIDOMEventReceiver
175
NS_IMETHOD AddEventListenerByIID(nsIDOMEventListener *aListener,
177
NS_IMETHOD RemoveEventListenerByIID(nsIDOMEventListener *aListener,
179
NS_IMETHOD GetListenerManager(nsIEventListenerManager** aInstancePtrResult);
180
NS_IMETHOD HandleEvent(nsIDOMEvent *aEvent);
181
NS_IMETHOD GetSystemEventGroup(nsIDOMEventGroup** aGroup);
184
NS_IMETHOD GetPrivateParent(nsPIDOMWindow** aResult);
185
NS_IMETHOD GetPrivateRoot(nsIDOMWindowInternal** aResult);
186
NS_IMETHOD GetObjectProperty(const PRUnichar* aProperty,
187
nsISupports** aObject);
188
NS_IMETHOD Activate();
189
NS_IMETHOD Deactivate();
190
NS_IMETHOD GetChromeEventHandler(nsIChromeEventHandler** aHandler);
191
NS_IMETHOD HasMutationListeners(PRUint32 aMutationEventType,
193
NS_IMETHOD SetMutationListeners(PRUint32 aEventType);
194
NS_IMETHOD GetRootFocusController(nsIFocusController** aResult);
195
NS_IMETHOD GetExtantDocument(nsIDOMDocument** aDocument);
197
NS_IMETHOD ReallyCloseWindow();
198
NS_IMETHOD IsLoadingOrRunningTimeout(PRBool* aResult);
199
NS_IMETHOD IsPopupSpamWindow(PRBool *aResult);
200
NS_IMETHOD SetPopupSpamWindow(PRBool aPopup);
202
NS_IMETHOD GetFrameElementInternal(nsIDOMElement** aFrameElement);
203
NS_IMETHOD SetFrameElementInternal(nsIDOMElement* aFrameElement);
204
NS_IMETHOD SetOpenerScriptURL(nsIURI* aURI);
206
virtual NS_HIDDEN_(PopupControlState) PushPopupControlState(PopupControlState state) const;
207
virtual NS_HIDDEN_(void) PopPopupControlState(PopupControlState state) const;
208
virtual NS_HIDDEN_(PopupControlState) GetPopupControlState() const;
209
virtual NS_HIDDEN_(OpenAllowValue) GetOpenAllow(const nsAString &aName);
210
virtual NS_HIDDEN_(PRBool) IsHandlingResizeEvent() const;
213
NS_DECL_NSIDOMVIEWCSS
215
// nsIDOMAbstractView
216
NS_DECL_NSIDOMABSTRACTVIEW
218
// nsIInterfaceRequestor
219
NS_DECL_NSIINTERFACEREQUESTOR
224
static void ShutDown();
225
static PRBool IsCallerChrome();
229
virtual ~GlobalWindowImpl();
231
void ClearControllers();
233
// Get the parent, returns null if this is a toplevel window
234
nsIDOMWindowInternal *GetParentInternal();
236
// Window Control Functions
237
NS_IMETHOD OpenInternal(const nsAString& aUrl,
238
const nsAString& aName,
239
const nsAString& aOptions,
240
PRBool aDialog, jsval *argv, PRUint32 argc,
241
nsISupports *aExtraArgument, nsIDOMWindow **aReturn);
242
static void CloseWindow(nsISupports* aWindow);
245
nsresult SetTimeoutOrInterval(PRBool aIsInterval, PRInt32* aReturn);
246
void RunTimeout(nsTimeoutImpl *aTimeout);
247
nsresult ClearTimeoutOrInterval();
248
void ClearAllTimeouts();
249
void InsertTimeoutIntoList(nsTimeoutImpl **aInsertionPoint,
250
nsTimeoutImpl *aTimeout);
251
static void TimerCallback(nsITimer *aTimer, void *aClosure);
254
nsresult GetTreeOwner(nsIDocShellTreeOwner** aTreeOwner);
255
nsresult GetTreeOwner(nsIBaseWindow** aTreeOwner);
256
nsresult GetWebBrowserChrome(nsIWebBrowserChrome** aBrowserChrome);
257
nsresult GetScrollInfo(nsIScrollableView** aScrollableView, float* aP2T,
259
nsresult SecurityCheckURL(const char *aURL);
260
nsresult BuildURIfromBase(const char *aURL,
262
PRBool *aFreeSecurityPass, JSContext **aCXused);
263
PopupControlState CheckForAbusePoint();
264
OpenAllowValue CheckOpenAllow(PopupControlState aAbuseLevel,
265
const nsAString &aName);
266
void FireAbuseEvents(PRBool aBlocked, PRBool aWindow,
267
const nsAString &aPopupURL,
268
const nsAString &aPopupWindowFeatures);
270
void FlushPendingNotifications(PRBool aFlushReflows);
271
void EnsureReflowFlushAndPaint();
272
nsresult CheckSecurityWidthAndHeight(PRInt32* width, PRInt32* height);
273
nsresult CheckSecurityLeftAndTop(PRInt32* left, PRInt32* top);
274
static nsresult CheckSecurityIsChromeCaller(PRBool *isChrome);
275
static PRBool CanSetProperty(const char *aPrefName);
277
void MakeScriptDialogTitle(const nsAString &aInTitle, nsAString &aOutTitle);
279
// Helper for window.find()
280
nsresult FindInternal(const nsAString& aStr, PRBool caseSensitive,
281
PRBool backwards, PRBool wrapAround, PRBool wholeWord,
282
PRBool searchInFrames, PRBool showDialog,
285
nsresult ConvertCharset(const nsAString& aStr, char** aDest);
287
PRBool GetBlurSuppression();
289
nsresult GetScrollXY(PRInt32* aScrollX, PRInt32* aScrollY);
290
nsresult GetScrollMaxXY(PRInt32* aScrollMaxX, PRInt32* aScrollMaxY);
294
return GetParentInternal() != nsnull;
297
PRBool DispatchCustomEvent(const char *aEventName);
299
// When adding new member variables, be careful not to create cycles
300
// through JavaScript. If there is any chance that a member variable
301
// could own objects that are implemented in JavaScript, then those
302
// objects will keep the global object (this object) alive. To prevent
303
// these cycles, ownership of such members must be released in
304
// |CleanUp| and |SetDocShell|.
305
nsCOMPtr<nsIScriptContext> mContext;
306
nsCOMPtr<nsIDOMDocument> mDocument;
307
nsCOMPtr<nsIDOMWindowInternal> mOpener;
308
nsCOMPtr<nsIControllers> mControllers;
309
nsCOMPtr<nsIEventListenerManager> mListenerManager;
311
nsRefPtr<NavigatorImpl> mNavigator;
312
nsRefPtr<ScreenImpl> mScreen;
313
nsRefPtr<HistoryImpl> mHistory;
314
nsRefPtr<nsDOMWindowList> mFrames;
315
nsRefPtr<LocationImpl> mLocation;
316
nsRefPtr<BarPropImpl> mMenubar;
317
nsRefPtr<BarPropImpl> mToolbar;
318
nsRefPtr<BarPropImpl> mLocationbar;
319
nsRefPtr<BarPropImpl> mPersonalbar;
320
nsRefPtr<BarPropImpl> mStatusbar;
321
nsRefPtr<BarPropImpl> mScrollbars;
322
nsCOMPtr<nsIWeakReference> mWindowUtils;
323
nsCOMPtr<nsIBrowserDOMWindow> mBrowserDOMWindow; // held for DOMWindowUtils
324
nsTimeoutImpl* mTimeouts;
325
nsTimeoutImpl** mTimeoutInsertionPoint;
326
nsTimeoutImpl* mRunningTimeout;
327
PRUint32 mTimeoutPublicIdCounter;
328
PRUint32 mTimeoutFiringDepth;
329
PRPackedBool mFirstDocumentLoad;
330
PRPackedBool mIsScopeClear;
331
PRPackedBool mIsDocumentLoaded; // true between onload and onunload events
332
PRPackedBool mFullScreen;
333
PRPackedBool mIsClosed;
334
PRPackedBool mOpenerWasCleared;
335
PRPackedBool mIsPopupSpam;
336
PRPackedBool mIsHandlingResizeEvent;
338
nsString mDefaultStatus;
340
nsIScriptGlobalObjectOwner* mGlobalObjectOwner; // Weak Reference
341
nsIDocShell* mDocShell; // Weak Reference
342
nsEvent* mCurrentEvent;
343
PRUint32 mMutationBits;
344
nsCOMPtr<nsIChromeEventHandler> mChromeEventHandler; // [Strong] We break it when we get torn down.
345
nsCOMPtr<nsIDOMCrypto> mCrypto;
346
nsCOMPtr<nsIDOMPkcs11> mPkcs11;
347
nsCOMPtr<nsIPrincipal> mDocumentPrincipal;
348
nsCOMPtr<nsIURI> mOpenerScriptURL; // Used to determine whether to clear scope
350
// XXX We need mNavigatorHolder because we make two SetNewDocument()
351
// calls when transitioning from page to page. This keeps a reference
352
// to the JSObject holder for the navigator object in between
353
// SetNewDocument() calls so that the JSObject doesn't get garbage
354
// collected in between these calls.
355
// See bug 163645 for more on why we need this and bug 209607 for info
356
// on how we can remove the need for this.
357
nsCOMPtr<nsIXPConnectJSObjectHolder> mNavigatorHolder;
359
nsIDOMElement* mFrameElement; // WEAK
361
friend class nsDOMScriptableHelper;
362
friend class nsDOMWindowUtils;
363
static nsIXPConnect *sXPConnect;
364
static nsIScriptSecurityManager *sSecMan;
365
static nsIFactory *sComputedDOMStyleFactory;
369
* nsGlobalChromeWindow inherits from GlobalWindowImpl. It is the global
370
* object created for a Chrome Window only.
372
class nsGlobalChromeWindow : public GlobalWindowImpl,
373
public nsIDOMChromeWindow
377
NS_DECL_ISUPPORTS_INHERITED
379
// nsIDOMChromeWindow interface
380
NS_DECL_NSIDOMCHROMEWINDOW
383
nsresult GetMainWidget(nsIWidget** aMainWidget);
389
* Timeout struct that holds information about each JavaScript
398
extern PRInt32 gTimeoutCnt;
404
memset(this, 0, sizeof(*this));
406
MOZ_COUNT_CTOR(nsTimeoutImpl);
413
extern PRInt32 gTimeoutCnt;
419
MOZ_COUNT_DTOR(nsTimeoutImpl);
422
void Release(nsIScriptContext* aContext);
425
// Window for which this timeout fires
426
GlobalWindowImpl *mWindow;
428
// The JS expression to evaluate or function to call, if !mExpr
432
// The actual timer object
433
nsCOMPtr<nsITimer> mTimer;
435
// Function actual arguments and argument count
439
// True if the timeout was cleared
440
PRPackedBool mCleared;
442
// True if this is one of the timeouts that are currently running
443
PRPackedBool mRunning;
445
// Returned as value of setTimeout()
448
// Non-zero if repetitive timeout
451
// Nominal time to run this timeout
454
// Principal with which to execute
455
nsCOMPtr<nsIPrincipal> mPrincipal;
457
// filename, line number and JS language version string of the
458
// caller of setTimeout()
461
const char *mVersion;
463
// stack depth at which timeout is firing
464
PRUint32 mFiringDepth;
466
// Pointer to the next timeout in the linked list of scheduled
468
nsTimeoutImpl *mNext;
470
// The popup state at timeout creation time if not created from
472
PopupControlState mPopupState;
475
// reference count for shared usage
479
//*****************************************************************************
480
// NavigatorImpl: Script "navigator" object
481
//*****************************************************************************
483
class NavigatorImpl : public nsIDOMNavigator,
484
public nsIDOMJSNavigator
487
NavigatorImpl(nsIDocShell *aDocShell);
488
virtual ~NavigatorImpl();
491
NS_DECL_NSIDOMNAVIGATOR
492
NS_DECL_NSIDOMJSNAVIGATOR
494
void SetDocShell(nsIDocShell *aDocShell);
495
void LoadingNewDocument();
496
nsresult RefreshMIMEArray();
499
nsRefPtr<MimeTypeArrayImpl> mMimeTypes;
500
nsRefPtr<PluginArrayImpl> mPlugins;
501
nsIDocShell* mDocShell; // weak reference
503
static jsval sPrefInternal_id;
508
//*****************************************************************************
509
// LocationImpl: Script "location" object
510
//*****************************************************************************
512
class LocationImpl : public nsIDOMLocation,
513
public nsIDOMNSLocation
516
LocationImpl(nsIDocShell *aDocShell);
517
virtual ~LocationImpl();
521
void SetDocShell(nsIDocShell *aDocShell);
524
NS_DECL_NSIDOMLOCATION
527
NS_DECL_NSIDOMNSLOCATION
530
// In the case of jar: uris, we sometimes want the place the jar was
531
// fetched from as the URI instead of the jar: uri itself. Pass in
532
// PR_TRUE for aGetInnermostURI when that's the case.
533
nsresult GetURI(nsIURI** aURL, PRBool aGetInnermostURI = PR_FALSE);
534
nsresult GetWritableURI(nsIURI** aURL);
535
nsresult SetURI(nsIURI* aURL);
536
nsresult SetHrefWithBase(const nsAString& aHref, nsIURI* aBase,
538
nsresult SetHrefWithContext(JSContext* cx, const nsAString& aHref,
541
nsresult GetSourceURL(JSContext* cx, nsIURI** sourceURL);
542
nsresult GetSourceBaseURL(JSContext* cx, nsIURI** sourceURL);
543
nsresult GetSourceDocument(JSContext* cx, nsIDocument** aDocument);
545
nsresult CheckURL(nsIURI *url, nsIDocShellLoadInfo** aLoadInfo);
546
nsresult FindUsableBaseURI(nsIURI * aBaseURI, nsIDocShell * aParent, nsIURI ** aUsableURI);
548
nsIDocShell *mDocShell; // Weak Reference
551
/* factory function */
552
nsresult NS_NewScriptGlobalObject(PRBool aIsChrome,
553
nsIScriptGlobalObject **aResult);
555
#endif /* nsGlobalWindow_h___ */