1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/base/nsGlobalWindow.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,1703 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim: set ts=2 sw=2 et tw=80: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#ifndef nsGlobalWindow_h___ 1.11 +#define nsGlobalWindow_h___ 1.12 + 1.13 +#include "nsPIDOMWindow.h" 1.14 + 1.15 +#include "nsTHashtable.h" 1.16 +#include "nsHashKeys.h" 1.17 +#include "nsRefPtrHashtable.h" 1.18 + 1.19 +// Local Includes 1.20 +// Helper Classes 1.21 +#include "nsCOMPtr.h" 1.22 +#include "nsAutoPtr.h" 1.23 +#include "nsWeakReference.h" 1.24 +#include "nsDataHashtable.h" 1.25 +#include "nsJSThingHashtable.h" 1.26 +#include "nsCycleCollectionParticipant.h" 1.27 + 1.28 +// Interfaces Needed 1.29 +#include "nsIBrowserDOMWindow.h" 1.30 +#include "nsIDOMEventTarget.h" 1.31 +#include "nsIInterfaceRequestor.h" 1.32 +#include "nsIDOMJSWindow.h" 1.33 +#include "nsIDOMChromeWindow.h" 1.34 +#include "nsIScriptGlobalObject.h" 1.35 +#include "nsIScriptObjectPrincipal.h" 1.36 +#include "nsITimer.h" 1.37 +#include "nsIDOMModalContentWindow.h" 1.38 +#include "mozilla/EventListenerManager.h" 1.39 +#include "nsIPrincipal.h" 1.40 +#include "nsSize.h" 1.41 +#include "mozFlushType.h" 1.42 +#include "prclist.h" 1.43 +#include "nsIDOMStorageEvent.h" 1.44 +#include "nsFrameMessageManager.h" 1.45 +#include "mozilla/LinkedList.h" 1.46 +#include "mozilla/TimeStamp.h" 1.47 +#include "nsIInlineEventHandlers.h" 1.48 +#include "nsWrapperCacheInlines.h" 1.49 +#include "nsIIdleObserver.h" 1.50 +#include "nsIDocument.h" 1.51 +#include "nsIDOMTouchEvent.h" 1.52 +#include "mozilla/dom/EventTarget.h" 1.53 +#include "Units.h" 1.54 +#include "nsComponentManagerUtils.h" 1.55 + 1.56 +#ifdef MOZ_B2G 1.57 +#include "nsIDOMWindowB2G.h" 1.58 +#endif // MOZ_B2G 1.59 + 1.60 +#ifdef MOZ_WEBSPEECH 1.61 +#include "nsISpeechSynthesisGetter.h" 1.62 +#endif // MOZ_WEBSPEECH 1.63 + 1.64 +#define DEFAULT_HOME_PAGE "www.mozilla.org" 1.65 +#define PREF_BROWSER_STARTUP_HOMEPAGE "browser.startup.homepage" 1.66 + 1.67 +// Amount of time allowed between alert/prompt/confirm before enabling 1.68 +// the stop dialog checkbox. 1.69 +#define DEFAULT_SUCCESSIVE_DIALOG_TIME_LIMIT 3 // 3 sec 1.70 + 1.71 +// Maximum number of successive dialogs before we prompt users to disable 1.72 +// dialogs for this window. 1.73 +#define MAX_SUCCESSIVE_DIALOG_COUNT 5 1.74 + 1.75 +// Idle fuzz time upper limit 1.76 +#define MAX_IDLE_FUZZ_TIME_MS 90000 1.77 + 1.78 +// Min idle notification time in seconds. 1.79 +#define MIN_IDLE_NOTIFICATION_TIME_S 1 1.80 + 1.81 +class nsIArray; 1.82 +class nsIBaseWindow; 1.83 +class nsIContent; 1.84 +class nsICSSDeclaration; 1.85 +class nsIDocShellTreeOwner; 1.86 +class nsIDOMCrypto; 1.87 +class nsIDOMOfflineResourceList; 1.88 +class nsIScrollableFrame; 1.89 +class nsIControllers; 1.90 +class nsIJSID; 1.91 +class nsIScriptContext; 1.92 +class nsIScriptTimeoutHandler; 1.93 +class nsIWebBrowserChrome; 1.94 + 1.95 +class nsDOMWindowList; 1.96 +class nsLocation; 1.97 +class nsScreen; 1.98 +class nsHistory; 1.99 +class nsGlobalWindowObserver; 1.100 +class nsGlobalWindow; 1.101 +class nsDOMWindowUtils; 1.102 +class nsIIdleService; 1.103 +struct nsIntSize; 1.104 +struct nsRect; 1.105 + 1.106 +class nsWindowSizes; 1.107 + 1.108 +namespace mozilla { 1.109 +class DOMEventTargetHelper; 1.110 +namespace dom { 1.111 +class BarProp; 1.112 +class Console; 1.113 +class External; 1.114 +class Function; 1.115 +class Gamepad; 1.116 +class MediaQueryList; 1.117 +class Navigator; 1.118 +class OwningExternalOrWindowProxy; 1.119 +class Selection; 1.120 +class SpeechSynthesis; 1.121 +class WakeLock; 1.122 +namespace indexedDB { 1.123 +class IDBFactory; 1.124 +} // namespace indexedDB 1.125 +} // namespace dom 1.126 +} // namespace mozilla 1.127 + 1.128 +extern nsresult 1.129 +NS_CreateJSTimeoutHandler(nsGlobalWindow *aWindow, 1.130 + bool *aIsInterval, 1.131 + int32_t *aInterval, 1.132 + nsIScriptTimeoutHandler **aRet); 1.133 + 1.134 +extern already_AddRefed<nsIScriptTimeoutHandler> 1.135 +NS_CreateJSTimeoutHandler(nsGlobalWindow *aWindow, 1.136 + mozilla::dom::Function& aFunction, 1.137 + const mozilla::dom::Sequence<JS::Value>& aArguments, 1.138 + mozilla::ErrorResult& aError); 1.139 + 1.140 +extern already_AddRefed<nsIScriptTimeoutHandler> 1.141 +NS_CreateJSTimeoutHandler(JSContext* aCx, nsGlobalWindow *aWindow, 1.142 + const nsAString& aExpression, 1.143 + mozilla::ErrorResult& aError); 1.144 + 1.145 +/* 1.146 + * Timeout struct that holds information about each script 1.147 + * timeout. Holds a strong reference to an nsIScriptTimeoutHandler, which 1.148 + * abstracts the language specific cruft. 1.149 + */ 1.150 +struct nsTimeout : mozilla::LinkedListElement<nsTimeout> 1.151 +{ 1.152 + nsTimeout(); 1.153 + ~nsTimeout(); 1.154 + 1.155 + NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(nsTimeout) 1.156 + NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(nsTimeout) 1.157 + 1.158 + nsresult InitTimer(nsTimerCallbackFunc aFunc, uint32_t aDelay) 1.159 + { 1.160 + return mTimer->InitWithFuncCallback(aFunc, this, aDelay, 1.161 + nsITimer::TYPE_ONE_SHOT); 1.162 + } 1.163 + 1.164 + bool HasRefCntOne(); 1.165 + 1.166 + // Window for which this timeout fires 1.167 + nsRefPtr<nsGlobalWindow> mWindow; 1.168 + 1.169 + // The actual timer object 1.170 + nsCOMPtr<nsITimer> mTimer; 1.171 + 1.172 + // True if the timeout was cleared 1.173 + bool mCleared; 1.174 + 1.175 + // True if this is one of the timeouts that are currently running 1.176 + bool mRunning; 1.177 + 1.178 + // True if this is a repeating/interval timer 1.179 + bool mIsInterval; 1.180 + 1.181 + // Returned as value of setTimeout() 1.182 + uint32_t mPublicId; 1.183 + 1.184 + // Interval in milliseconds 1.185 + uint32_t mInterval; 1.186 + 1.187 + // mWhen and mTimeRemaining can't be in a union, sadly, because they 1.188 + // have constructors. 1.189 + // Nominal time to run this timeout. Use only when timeouts are not 1.190 + // suspended. 1.191 + mozilla::TimeStamp mWhen; 1.192 + // Remaining time to wait. Used only when timeouts are suspended. 1.193 + mozilla::TimeDuration mTimeRemaining; 1.194 + 1.195 + // Principal with which to execute 1.196 + nsCOMPtr<nsIPrincipal> mPrincipal; 1.197 + 1.198 + // stack depth at which timeout is firing 1.199 + uint32_t mFiringDepth; 1.200 + 1.201 + // 1.202 + uint32_t mNestingLevel; 1.203 + 1.204 + // The popup state at timeout creation time if not created from 1.205 + // another timeout 1.206 + PopupControlState mPopupState; 1.207 + 1.208 + // The language-specific information about the callback. 1.209 + nsCOMPtr<nsIScriptTimeoutHandler> mScriptHandler; 1.210 +}; 1.211 + 1.212 +struct IdleObserverHolder 1.213 +{ 1.214 + nsCOMPtr<nsIIdleObserver> mIdleObserver; 1.215 + uint32_t mTimeInS; 1.216 + bool mPrevNotificationIdle; 1.217 + 1.218 + IdleObserverHolder() 1.219 + : mTimeInS(0), mPrevNotificationIdle(false) 1.220 + { 1.221 + MOZ_COUNT_CTOR(IdleObserverHolder); 1.222 + } 1.223 + 1.224 + IdleObserverHolder(const IdleObserverHolder& aOther) 1.225 + : mIdleObserver(aOther.mIdleObserver), mTimeInS(aOther.mTimeInS), 1.226 + mPrevNotificationIdle(aOther.mPrevNotificationIdle) 1.227 + { 1.228 + MOZ_COUNT_CTOR(IdleObserverHolder); 1.229 + } 1.230 + 1.231 + bool operator==(const IdleObserverHolder& aOther) const { 1.232 + return 1.233 + mIdleObserver == aOther.mIdleObserver && 1.234 + mTimeInS == aOther.mTimeInS; 1.235 + } 1.236 + 1.237 + ~IdleObserverHolder() 1.238 + { 1.239 + MOZ_COUNT_DTOR(IdleObserverHolder); 1.240 + } 1.241 +}; 1.242 + 1.243 +static inline already_AddRefed<nsIVariant> 1.244 +CreateVoidVariant() 1.245 +{ 1.246 + nsCOMPtr<nsIWritableVariant> writable = 1.247 + do_CreateInstance(NS_VARIANT_CONTRACTID); 1.248 + writable->SetAsVoid(); 1.249 + return writable.forget(); 1.250 +} 1.251 + 1.252 +// Helper class to manage modal dialog arguments and all their quirks. 1.253 +// 1.254 +// Given our clunky embedding APIs, modal dialog arguments need to be passed 1.255 +// as an nsISupports parameter to WindowWatcher, get stuck inside an array of 1.256 +// length 1, and then passed back to the newly-created dialog. 1.257 +// 1.258 +// However, we need to track both the caller-passed value as well as the 1.259 +// caller's, so that we can do an origin check (even for primitives) when the 1.260 +// value is accessed. This class encapsulates that magic. 1.261 +// 1.262 +// We also use the same machinery for |returnValue|, which needs similar origin 1.263 +// checks. 1.264 +class DialogValueHolder : public nsISupports 1.265 +{ 1.266 +public: 1.267 + NS_DECL_CYCLE_COLLECTING_ISUPPORTS 1.268 + NS_DECL_CYCLE_COLLECTION_CLASS(DialogValueHolder) 1.269 + 1.270 + DialogValueHolder(nsIPrincipal* aSubject, nsIVariant* aValue) 1.271 + : mOrigin(aSubject) 1.272 + , mValue(aValue) {} 1.273 + nsresult Get(nsIPrincipal* aSubject, nsIVariant** aResult) 1.274 + { 1.275 + nsCOMPtr<nsIVariant> result; 1.276 + if (aSubject->SubsumesConsideringDomain(mOrigin)) { 1.277 + result = mValue; 1.278 + } else { 1.279 + result = CreateVoidVariant(); 1.280 + } 1.281 + result.forget(aResult); 1.282 + return NS_OK; 1.283 + } 1.284 + void Get(JSContext* aCx, JS::Handle<JSObject*> aScope, nsIPrincipal* aSubject, 1.285 + JS::MutableHandle<JS::Value> aResult, mozilla::ErrorResult& aError) 1.286 + { 1.287 + if (aSubject->Subsumes(mOrigin)) { 1.288 + aError = nsContentUtils::XPConnect()->VariantToJS(aCx, aScope, 1.289 + mValue, aResult); 1.290 + } else { 1.291 + aResult.setUndefined(); 1.292 + } 1.293 + } 1.294 + virtual ~DialogValueHolder() {} 1.295 +private: 1.296 + nsCOMPtr<nsIPrincipal> mOrigin; 1.297 + nsCOMPtr<nsIVariant> mValue; 1.298 +}; 1.299 + 1.300 +//***************************************************************************** 1.301 +// nsGlobalWindow: Global Object for Scripting 1.302 +//***************************************************************************** 1.303 +// Beware that all scriptable interfaces implemented by 1.304 +// nsGlobalWindow will be reachable from JS, if you make this class 1.305 +// implement new interfaces you better know what you're 1.306 +// doing. Security wise this is very sensitive code. -- 1.307 +// jst@netscape.com 1.308 + 1.309 +// nsGlobalWindow inherits PRCList for maintaining a list of all inner 1.310 +// windows still in memory for any given outer window. This list is 1.311 +// needed to ensure that mOuterWindow doesn't end up dangling. The 1.312 +// nature of PRCList means that the window itself is always in the 1.313 +// list, and an outer window's list will also contain all inner window 1.314 +// objects that are still in memory (and in reality all inner window 1.315 +// object's lists also contain its outer and all other inner windows 1.316 +// belonging to the same outer window, but that's an unimportant 1.317 +// side effect of inheriting PRCList). 1.318 + 1.319 +class nsGlobalWindow : public mozilla::dom::EventTarget, 1.320 + public nsPIDOMWindow, 1.321 + public nsIScriptGlobalObject, 1.322 + public nsIScriptObjectPrincipal, 1.323 + public nsIDOMJSWindow, 1.324 + public nsSupportsWeakReference, 1.325 + public nsIInterfaceRequestor, 1.326 + public PRCListStr, 1.327 + public nsIDOMWindowPerformance, 1.328 + public nsITouchEventReceiver, 1.329 + public nsIInlineEventHandlers 1.330 +#ifdef MOZ_B2G 1.331 + , public nsIDOMWindowB2G 1.332 +#endif // MOZ_B2G 1.333 +#ifdef MOZ_WEBSPEECH 1.334 + , public nsISpeechSynthesisGetter 1.335 +#endif // MOZ_WEBSPEECH 1.336 +{ 1.337 +public: 1.338 + typedef mozilla::TimeStamp TimeStamp; 1.339 + typedef mozilla::TimeDuration TimeDuration; 1.340 + typedef nsDataHashtable<nsUint64HashKey, nsGlobalWindow*> WindowByIdTable; 1.341 + 1.342 + // public methods 1.343 + nsPIDOMWindow* GetPrivateParent(); 1.344 + // callback for close event 1.345 + void ReallyCloseWindow(); 1.346 + 1.347 + // nsISupports 1.348 + NS_DECL_CYCLE_COLLECTING_ISUPPORTS 1.349 + 1.350 + // nsWrapperCache 1.351 + virtual JSObject *WrapObject(JSContext *cx) MOZ_OVERRIDE 1.352 + { 1.353 + NS_ASSERTION(IsOuterWindow(), 1.354 + "Inner window supports nsWrapperCache, fix WrapObject!"); 1.355 + return EnsureInnerWindow() ? GetWrapper() : nullptr; 1.356 + } 1.357 + 1.358 + // nsIGlobalJSObjectHolder 1.359 + virtual JSObject *GetGlobalJSObject(); 1.360 + 1.361 + // nsIScriptGlobalObject 1.362 + JSObject *FastGetGlobalJSObject() const 1.363 + { 1.364 + return GetWrapperPreserveColor(); 1.365 + } 1.366 + 1.367 + void TraceGlobalJSObject(JSTracer* aTrc); 1.368 + 1.369 + virtual nsresult EnsureScriptEnvironment(); 1.370 + 1.371 + virtual nsIScriptContext *GetScriptContext(); 1.372 + 1.373 + void PoisonOuterWindowProxy(JSObject *aObject); 1.374 + 1.375 + virtual bool IsBlackForCC(bool aTracingNeeded = true); 1.376 + 1.377 + static JSObject* OuterObject(JSContext* aCx, JS::Handle<JSObject*> aObj); 1.378 + 1.379 + // nsIScriptObjectPrincipal 1.380 + virtual nsIPrincipal* GetPrincipal(); 1.381 + 1.382 + // nsIDOMWindow 1.383 + NS_DECL_NSIDOMWINDOW 1.384 + 1.385 +#ifdef MOZ_B2G 1.386 + // nsIDOMWindowB2G 1.387 + NS_DECL_NSIDOMWINDOWB2G 1.388 +#endif // MOZ_B2G 1.389 + 1.390 +#ifdef MOZ_WEBSPEECH 1.391 + // nsISpeechSynthesisGetter 1.392 + NS_DECL_NSISPEECHSYNTHESISGETTER 1.393 +#endif // MOZ_WEBSPEECH 1.394 + 1.395 + // nsIDOMWindowPerformance 1.396 + NS_DECL_NSIDOMWINDOWPERFORMANCE 1.397 + 1.398 + // nsIDOMJSWindow 1.399 + NS_DECL_NSIDOMJSWINDOW 1.400 + 1.401 + // nsIDOMEventTarget 1.402 + NS_DECL_NSIDOMEVENTTARGET 1.403 + 1.404 + virtual mozilla::EventListenerManager* 1.405 + GetExistingListenerManager() const MOZ_OVERRIDE; 1.406 + 1.407 + virtual mozilla::EventListenerManager* 1.408 + GetOrCreateListenerManager() MOZ_OVERRIDE; 1.409 + 1.410 + using mozilla::dom::EventTarget::RemoveEventListener; 1.411 + virtual void AddEventListener(const nsAString& aType, 1.412 + mozilla::dom::EventListener* aListener, 1.413 + bool aUseCapture, 1.414 + const mozilla::dom::Nullable<bool>& aWantsUntrusted, 1.415 + mozilla::ErrorResult& aRv) MOZ_OVERRIDE; 1.416 + virtual nsIDOMWindow* GetOwnerGlobal() MOZ_OVERRIDE 1.417 + { 1.418 + if (IsOuterWindow()) { 1.419 + return this; 1.420 + } 1.421 + 1.422 + return GetOuterFromCurrentInner(this); 1.423 + } 1.424 + 1.425 + // nsITouchEventReceiver 1.426 + NS_DECL_NSITOUCHEVENTRECEIVER 1.427 + 1.428 + // nsIInlineEventHandlers 1.429 + NS_DECL_NSIINLINEEVENTHANDLERS 1.430 + 1.431 + // nsPIDOMWindow 1.432 + virtual NS_HIDDEN_(nsPIDOMWindow*) GetPrivateRoot(); 1.433 + 1.434 + // Outer windows only. 1.435 + virtual NS_HIDDEN_(void) ActivateOrDeactivate(bool aActivate); 1.436 + virtual NS_HIDDEN_(void) SetActive(bool aActive); 1.437 + virtual NS_HIDDEN_(void) SetIsBackground(bool aIsBackground); 1.438 + virtual NS_HIDDEN_(void) SetChromeEventHandler(mozilla::dom::EventTarget* aChromeEventHandler); 1.439 + 1.440 + virtual NS_HIDDEN_(void) SetInitialPrincipalToSubject(); 1.441 + 1.442 + virtual NS_HIDDEN_(PopupControlState) PushPopupControlState(PopupControlState state, bool aForce) const; 1.443 + virtual NS_HIDDEN_(void) PopPopupControlState(PopupControlState state) const; 1.444 + virtual NS_HIDDEN_(PopupControlState) GetPopupControlState() const; 1.445 + 1.446 + virtual already_AddRefed<nsISupports> SaveWindowState(); 1.447 + virtual NS_HIDDEN_(nsresult) RestoreWindowState(nsISupports *aState); 1.448 + virtual NS_HIDDEN_(void) SuspendTimeouts(uint32_t aIncrease = 1, 1.449 + bool aFreezeChildren = true); 1.450 + virtual NS_HIDDEN_(nsresult) ResumeTimeouts(bool aThawChildren = true); 1.451 + virtual NS_HIDDEN_(uint32_t) TimeoutSuspendCount(); 1.452 + virtual NS_HIDDEN_(nsresult) FireDelayedDOMEvents(); 1.453 + virtual NS_HIDDEN_(bool) IsFrozen() const 1.454 + { 1.455 + return mIsFrozen; 1.456 + } 1.457 + virtual NS_HIDDEN_(bool) IsRunningTimeout() { return mTimeoutFiringDepth > 0; } 1.458 + 1.459 + virtual NS_HIDDEN_(bool) WouldReuseInnerWindow(nsIDocument *aNewDocument); 1.460 + 1.461 + virtual NS_HIDDEN_(void) SetDocShell(nsIDocShell* aDocShell); 1.462 + virtual void DetachFromDocShell(); 1.463 + virtual NS_HIDDEN_(nsresult) SetNewDocument(nsIDocument *aDocument, 1.464 + nsISupports *aState, 1.465 + bool aForceReuseInnerWindow); 1.466 + void DispatchDOMWindowCreated(); 1.467 + virtual NS_HIDDEN_(void) SetOpenerWindow(nsIDOMWindow* aOpener, 1.468 + bool aOriginalOpener); 1.469 + 1.470 + // Outer windows only. 1.471 + virtual NS_HIDDEN_(void) EnsureSizeUpToDate(); 1.472 + 1.473 + virtual NS_HIDDEN_(void) EnterModalState(); 1.474 + virtual NS_HIDDEN_(void) LeaveModalState(); 1.475 + 1.476 + virtual NS_HIDDEN_(bool) CanClose(); 1.477 + virtual NS_HIDDEN_(nsresult) ForceClose(); 1.478 + 1.479 + virtual NS_HIDDEN_(void) MaybeUpdateTouchState(); 1.480 + virtual NS_HIDDEN_(void) UpdateTouchState(); 1.481 + virtual NS_HIDDEN_(bool) DispatchCustomEvent(const char *aEventName); 1.482 + virtual NS_HIDDEN_(bool) DispatchResizeEvent(const nsIntSize& aSize); 1.483 + virtual NS_HIDDEN_(void) RefreshCompartmentPrincipal(); 1.484 + virtual NS_HIDDEN_(nsresult) SetFullScreenInternal(bool aIsFullScreen, bool aRequireTrust); 1.485 + 1.486 + virtual NS_HIDDEN_(void) SetHasGamepadEventListener(bool aHasGamepad = true); 1.487 + 1.488 + // nsIInterfaceRequestor 1.489 + NS_DECL_NSIINTERFACEREQUESTOR 1.490 + 1.491 + // WebIDL interface. 1.492 + already_AddRefed<nsIDOMWindow> IndexedGetter(uint32_t aIndex, bool& aFound); 1.493 + 1.494 + void GetSupportedNames(nsTArray<nsString>& aNames); 1.495 + 1.496 + static bool IsChromeWindow(JSContext* /* unused */, JSObject* aObj); 1.497 + 1.498 + bool IsChrome() const; 1.499 + 1.500 + bool DoNewResolve(JSContext* aCx, JS::Handle<JSObject*> aObj, 1.501 + JS::Handle<jsid> aId, 1.502 + JS::MutableHandle<JSPropertyDescriptor> aDesc); 1.503 + 1.504 + void GetOwnPropertyNames(JSContext* aCx, nsTArray<nsString>& aNames, 1.505 + mozilla::ErrorResult& aRv); 1.506 + 1.507 + // Object Management 1.508 + nsGlobalWindow(nsGlobalWindow *aOuterWindow); 1.509 + 1.510 + static nsGlobalWindow *FromSupports(nsISupports *supports) 1.511 + { 1.512 + // Make sure this matches the casts we do in QueryInterface(). 1.513 + return (nsGlobalWindow *)(mozilla::dom::EventTarget *)supports; 1.514 + } 1.515 + static nsGlobalWindow *FromWrapper(nsIXPConnectWrappedNative *wrapper) 1.516 + { 1.517 + return FromSupports(wrapper->Native()); 1.518 + } 1.519 + 1.520 + /** 1.521 + * Wrap nsIDOMWindow::GetTop so we can overload the inline GetTop() 1.522 + * implementation below. (nsIDOMWindow::GetTop simply calls 1.523 + * nsIDOMWindow::GetRealTop().) 1.524 + */ 1.525 + nsresult GetTop(nsIDOMWindow **aWindow) 1.526 + { 1.527 + return nsIDOMWindow::GetTop(aWindow); 1.528 + } 1.529 + 1.530 + inline nsGlobalWindow *GetTop() 1.531 + { 1.532 + nsCOMPtr<nsIDOMWindow> top; 1.533 + GetTop(getter_AddRefs(top)); 1.534 + if (top) 1.535 + return static_cast<nsGlobalWindow *>(top.get()); 1.536 + return nullptr; 1.537 + } 1.538 + 1.539 + inline nsGlobalWindow* GetScriptableTop() 1.540 + { 1.541 + nsCOMPtr<nsIDOMWindow> top; 1.542 + GetScriptableTop(getter_AddRefs(top)); 1.543 + return static_cast<nsGlobalWindow *>(top.get()); 1.544 + } 1.545 + 1.546 + already_AddRefed<nsIDOMWindow> GetChildWindow(const nsAString& aName); 1.547 + 1.548 + // These return true if we've reached the state in this top level window 1.549 + // where we ask the user if further dialogs should be blocked. 1.550 + // 1.551 + // DialogsAreBeingAbused must be called on the scriptable top inner window. 1.552 + // 1.553 + // ShouldPromptToBlockDialogs is implemented in terms of 1.554 + // DialogsAreBeingAbused, and will get the scriptable top inner window 1.555 + // automatically. 1.556 + // Outer windows only. 1.557 + bool ShouldPromptToBlockDialogs(); 1.558 + // Inner windows only. 1.559 + bool DialogsAreBeingAbused(); 1.560 + 1.561 + // These functions are used for controlling and determining whether dialogs 1.562 + // (alert, prompt, confirm) are currently allowed in this window. 1.563 + void EnableDialogs(); 1.564 + void DisableDialogs(); 1.565 + bool AreDialogsEnabled(); 1.566 + 1.567 + nsIScriptContext *GetContextInternal() 1.568 + { 1.569 + if (mOuterWindow) { 1.570 + return GetOuterWindowInternal()->mContext; 1.571 + } 1.572 + 1.573 + return mContext; 1.574 + } 1.575 + 1.576 + nsGlobalWindow *GetOuterWindowInternal() 1.577 + { 1.578 + return static_cast<nsGlobalWindow *>(GetOuterWindow()); 1.579 + } 1.580 + 1.581 + nsGlobalWindow *GetCurrentInnerWindowInternal() const 1.582 + { 1.583 + return static_cast<nsGlobalWindow *>(mInnerWindow); 1.584 + } 1.585 + 1.586 + nsGlobalWindow *EnsureInnerWindowInternal() 1.587 + { 1.588 + return static_cast<nsGlobalWindow *>(EnsureInnerWindow()); 1.589 + } 1.590 + 1.591 + bool IsCreatingInnerWindow() const 1.592 + { 1.593 + return mCreatingInnerWindow; 1.594 + } 1.595 + 1.596 + bool IsChromeWindow() const 1.597 + { 1.598 + return mIsChrome; 1.599 + } 1.600 + 1.601 + using nsPIDOMWindow::IsModalContentWindow; 1.602 + static bool IsModalContentWindow(JSContext* aCx, JSObject* aGlobal); 1.603 + 1.604 + // GetScrollFrame does not flush. Callers should do it themselves as needed, 1.605 + // depending on which info they actually want off the scrollable frame. 1.606 + nsIScrollableFrame *GetScrollFrame(); 1.607 + 1.608 + nsresult Observe(nsISupports* aSubject, const char* aTopic, 1.609 + const char16_t* aData); 1.610 + 1.611 + // Outer windows only. 1.612 + void UnblockScriptedClosing(); 1.613 + 1.614 + static void Init(); 1.615 + static void ShutDown(); 1.616 + static void CleanupCachedXBLHandlers(nsGlobalWindow* aWindow); 1.617 + static bool IsCallerChrome(); 1.618 + 1.619 + static void RunPendingTimeoutsRecursive(nsGlobalWindow *aTopWindow, 1.620 + nsGlobalWindow *aWindow); 1.621 + 1.622 + friend class WindowStateHolder; 1.623 + 1.624 + NS_DECL_CYCLE_COLLECTION_SKIPPABLE_SCRIPT_HOLDER_CLASS_AMBIGUOUS(nsGlobalWindow, 1.625 + nsIDOMEventTarget) 1.626 + 1.627 +#ifdef DEBUG 1.628 + // Call Unlink on this window. This may cause bad things to happen, so use 1.629 + // with caution. 1.630 + void RiskyUnlink(); 1.631 +#endif 1.632 + 1.633 + virtual NS_HIDDEN_(JSObject*) 1.634 + GetCachedXBLPrototypeHandler(nsXBLPrototypeHandler* aKey); 1.635 + 1.636 + virtual NS_HIDDEN_(void) 1.637 + CacheXBLPrototypeHandler(nsXBLPrototypeHandler* aKey, 1.638 + JS::Handle<JSObject*> aHandler); 1.639 + 1.640 + virtual bool TakeFocus(bool aFocus, uint32_t aFocusMethod); 1.641 + virtual void SetReadyForFocus(); 1.642 + virtual void PageHidden(); 1.643 + virtual nsresult DispatchAsyncHashchange(nsIURI *aOldURI, nsIURI *aNewURI); 1.644 + virtual nsresult DispatchSyncPopState(); 1.645 + 1.646 + // Inner windows only. 1.647 + virtual void EnableDeviceSensor(uint32_t aType); 1.648 + virtual void DisableDeviceSensor(uint32_t aType); 1.649 + 1.650 + virtual void EnableTimeChangeNotifications(); 1.651 + virtual void DisableTimeChangeNotifications(); 1.652 + 1.653 +#ifdef MOZ_B2G 1.654 + // Inner windows only. 1.655 + virtual void EnableNetworkEvent(uint32_t aType); 1.656 + virtual void DisableNetworkEvent(uint32_t aType); 1.657 +#endif // MOZ_B2G 1.658 + 1.659 + virtual nsresult SetArguments(nsIArray *aArguments); 1.660 + 1.661 + void MaybeForgiveSpamCount(); 1.662 + bool IsClosedOrClosing() { 1.663 + return (mIsClosed || 1.664 + mInClose || 1.665 + mHavePendingClose || 1.666 + mCleanedUp); 1.667 + } 1.668 + 1.669 + static void FirePopupBlockedEvent(nsIDocument* aDoc, 1.670 + nsIDOMWindow *aRequestingWindow, nsIURI *aPopupURI, 1.671 + const nsAString &aPopupWindowName, 1.672 + const nsAString &aPopupWindowFeatures); 1.673 + 1.674 + virtual uint32_t GetSerial() { 1.675 + return mSerial; 1.676 + } 1.677 + 1.678 + static nsGlobalWindow* GetOuterWindowWithId(uint64_t aWindowID) { 1.679 + if (!sWindowsById) { 1.680 + return nullptr; 1.681 + } 1.682 + 1.683 + nsGlobalWindow* outerWindow = sWindowsById->Get(aWindowID); 1.684 + return outerWindow && !outerWindow->IsInnerWindow() ? outerWindow : nullptr; 1.685 + } 1.686 + 1.687 + static nsGlobalWindow* GetInnerWindowWithId(uint64_t aInnerWindowID) { 1.688 + if (!sWindowsById) { 1.689 + return nullptr; 1.690 + } 1.691 + 1.692 + nsGlobalWindow* innerWindow = sWindowsById->Get(aInnerWindowID); 1.693 + return innerWindow && innerWindow->IsInnerWindow() ? innerWindow : nullptr; 1.694 + } 1.695 + 1.696 + static WindowByIdTable* GetWindowsTable() { 1.697 + return sWindowsById; 1.698 + } 1.699 + 1.700 + void AddSizeOfIncludingThis(nsWindowSizes* aWindowSizes) const; 1.701 + 1.702 + void UnmarkGrayTimers(); 1.703 + 1.704 + void AddEventTargetObject(mozilla::DOMEventTargetHelper* aObject); 1.705 + void RemoveEventTargetObject(mozilla::DOMEventTargetHelper* aObject); 1.706 + 1.707 + void NotifyIdleObserver(IdleObserverHolder* aIdleObserverHolder, 1.708 + bool aCallOnidle); 1.709 + nsresult HandleIdleActiveEvent(); 1.710 + bool ContainsIdleObserver(nsIIdleObserver* aIdleObserver, uint32_t timeInS); 1.711 + void HandleIdleObserverCallback(); 1.712 + 1.713 + void AllowScriptsToClose() 1.714 + { 1.715 + mAllowScriptsToClose = true; 1.716 + } 1.717 + 1.718 + enum SlowScriptResponse { 1.719 + ContinueSlowScript = 0, 1.720 + AlwaysContinueSlowScript, 1.721 + KillSlowScript 1.722 + }; 1.723 + SlowScriptResponse ShowSlowScriptDialog(); 1.724 + 1.725 +#ifdef MOZ_GAMEPAD 1.726 + void AddGamepad(uint32_t aIndex, mozilla::dom::Gamepad* aGamepad); 1.727 + void RemoveGamepad(uint32_t aIndex); 1.728 + void GetGamepads(nsTArray<nsRefPtr<mozilla::dom::Gamepad> >& aGamepads); 1.729 + already_AddRefed<mozilla::dom::Gamepad> GetGamepad(uint32_t aIndex); 1.730 + void SetHasSeenGamepadInput(bool aHasSeen); 1.731 + bool HasSeenGamepadInput(); 1.732 + void SyncGamepadState(); 1.733 + static PLDHashOperator EnumGamepadsForSync(const uint32_t& aKey, 1.734 + mozilla::dom::Gamepad* aData, 1.735 + void* aUserArg); 1.736 + static PLDHashOperator EnumGamepadsForGet(const uint32_t& aKey, 1.737 + mozilla::dom::Gamepad* aData, 1.738 + void* aUserArg); 1.739 +#endif 1.740 + 1.741 + // Enable/disable updates for gamepad input. 1.742 + void EnableGamepadUpdates(); 1.743 + void DisableGamepadUpdates(); 1.744 + 1.745 + 1.746 +#define EVENT(name_, id_, type_, struct_) \ 1.747 + mozilla::dom::EventHandlerNonNull* GetOn##name_() \ 1.748 + { \ 1.749 + mozilla::EventListenerManager* elm = GetExistingListenerManager(); \ 1.750 + return elm ? elm->GetEventHandler(nsGkAtoms::on##name_, EmptyString()) \ 1.751 + : nullptr; \ 1.752 + } \ 1.753 + void SetOn##name_(mozilla::dom::EventHandlerNonNull* handler) \ 1.754 + { \ 1.755 + mozilla::EventListenerManager* elm = GetOrCreateListenerManager(); \ 1.756 + if (elm) { \ 1.757 + elm->SetEventHandler(nsGkAtoms::on##name_, EmptyString(), handler); \ 1.758 + } \ 1.759 + } 1.760 +#define ERROR_EVENT(name_, id_, type_, struct_) \ 1.761 + mozilla::dom::OnErrorEventHandlerNonNull* GetOn##name_() \ 1.762 + { \ 1.763 + mozilla::EventListenerManager* elm = GetExistingListenerManager(); \ 1.764 + return elm ? elm->GetOnErrorEventHandler() : nullptr; \ 1.765 + } \ 1.766 + void SetOn##name_(mozilla::dom::OnErrorEventHandlerNonNull* handler) \ 1.767 + { \ 1.768 + mozilla::EventListenerManager* elm = GetOrCreateListenerManager(); \ 1.769 + if (elm) { \ 1.770 + elm->SetEventHandler(handler); \ 1.771 + } \ 1.772 + } 1.773 +#define BEFOREUNLOAD_EVENT(name_, id_, type_, struct_) \ 1.774 + mozilla::dom::OnBeforeUnloadEventHandlerNonNull* GetOn##name_() \ 1.775 + { \ 1.776 + mozilla::EventListenerManager* elm = GetExistingListenerManager(); \ 1.777 + return elm ? elm->GetOnBeforeUnloadEventHandler() : nullptr; \ 1.778 + } \ 1.779 + void SetOn##name_(mozilla::dom::OnBeforeUnloadEventHandlerNonNull* handler) \ 1.780 + { \ 1.781 + mozilla::EventListenerManager* elm = GetOrCreateListenerManager(); \ 1.782 + if (elm) { \ 1.783 + elm->SetEventHandler(handler); \ 1.784 + } \ 1.785 + } 1.786 +#define WINDOW_ONLY_EVENT EVENT 1.787 +#define TOUCH_EVENT EVENT 1.788 +#include "mozilla/EventNameList.h" 1.789 +#undef TOUCH_EVENT 1.790 +#undef WINDOW_ONLY_EVENT 1.791 +#undef BEFOREUNLOAD_EVENT 1.792 +#undef ERROR_EVENT 1.793 +#undef EVENT 1.794 + 1.795 + nsISupports* GetParentObject() 1.796 + { 1.797 + return nullptr; 1.798 + } 1.799 + 1.800 + static bool WindowOnWebIDL(JSContext* /* unused */, JSObject* aObj); 1.801 + 1.802 + nsIDOMWindow* GetWindow(mozilla::ErrorResult& aError); 1.803 + nsIDOMWindow* GetSelf(mozilla::ErrorResult& aError); 1.804 + nsIDocument* GetDocument() 1.805 + { 1.806 + return GetDoc(); 1.807 + } 1.808 + void GetName(nsAString& aName, mozilla::ErrorResult& aError); 1.809 + void SetName(const nsAString& aName, mozilla::ErrorResult& aError); 1.810 + nsIDOMLocation* GetLocation(mozilla::ErrorResult& aError); 1.811 + nsHistory* GetHistory(mozilla::ErrorResult& aError); 1.812 + mozilla::dom::BarProp* GetLocationbar(mozilla::ErrorResult& aError); 1.813 + mozilla::dom::BarProp* GetMenubar(mozilla::ErrorResult& aError); 1.814 + mozilla::dom::BarProp* GetPersonalbar(mozilla::ErrorResult& aError); 1.815 + mozilla::dom::BarProp* GetScrollbars(mozilla::ErrorResult& aError); 1.816 + mozilla::dom::BarProp* GetStatusbar(mozilla::ErrorResult& aError); 1.817 + mozilla::dom::BarProp* GetToolbar(mozilla::ErrorResult& aError); 1.818 + void GetStatus(nsAString& aStatus, mozilla::ErrorResult& aError); 1.819 + void SetStatus(const nsAString& aStatus, mozilla::ErrorResult& aError); 1.820 + void Close(mozilla::ErrorResult& aError); 1.821 + bool GetClosed(mozilla::ErrorResult& aError); 1.822 + void Stop(mozilla::ErrorResult& aError); 1.823 + void Focus(mozilla::ErrorResult& aError); 1.824 + void Blur(mozilla::ErrorResult& aError); 1.825 + already_AddRefed<nsIDOMWindow> GetFrames(mozilla::ErrorResult& aError); 1.826 + uint32_t Length(); 1.827 + already_AddRefed<nsIDOMWindow> GetTop(mozilla::ErrorResult& aError) 1.828 + { 1.829 + nsCOMPtr<nsIDOMWindow> top; 1.830 + aError = GetScriptableTop(getter_AddRefs(top)); 1.831 + return top.forget(); 1.832 + } 1.833 +protected: 1.834 + nsIDOMWindow* GetOpenerWindow(mozilla::ErrorResult& aError); 1.835 +public: 1.836 + void GetOpener(JSContext* aCx, JS::MutableHandle<JS::Value> aRetval, 1.837 + mozilla::ErrorResult& aError); 1.838 + void SetOpener(JSContext* aCx, JS::Handle<JS::Value> aOpener, 1.839 + mozilla::ErrorResult& aError); 1.840 + using nsIDOMWindow::GetParent; 1.841 + already_AddRefed<nsIDOMWindow> GetParent(mozilla::ErrorResult& aError); 1.842 + mozilla::dom::Element* GetFrameElement(mozilla::ErrorResult& aError); 1.843 + already_AddRefed<nsIDOMWindow> Open(const nsAString& aUrl, 1.844 + const nsAString& aName, 1.845 + const nsAString& aOptions, 1.846 + mozilla::ErrorResult& aError); 1.847 + mozilla::dom::Navigator* GetNavigator(mozilla::ErrorResult& aError); 1.848 + nsIDOMOfflineResourceList* GetApplicationCache(mozilla::ErrorResult& aError); 1.849 + 1.850 + mozilla::dom::Console* GetConsole(mozilla::ErrorResult& aRv); 1.851 + 1.852 + void GetSidebar(mozilla::dom::OwningExternalOrWindowProxy& aResult, 1.853 + mozilla::ErrorResult& aRv); 1.854 + already_AddRefed<mozilla::dom::External> GetExternal(mozilla::ErrorResult& aRv); 1.855 + 1.856 +protected: 1.857 + bool AlertOrConfirm(bool aAlert, const nsAString& aMessage, 1.858 + mozilla::ErrorResult& aError); 1.859 + 1.860 +public: 1.861 + void Alert(const nsAString& aMessage, mozilla::ErrorResult& aError); 1.862 + bool Confirm(const nsAString& aMessage, mozilla::ErrorResult& aError); 1.863 + void Prompt(const nsAString& aMessage, const nsAString& aInitial, 1.864 + nsAString& aReturn, mozilla::ErrorResult& aError); 1.865 + void Print(mozilla::ErrorResult& aError); 1.866 + void ShowModalDialog(JSContext* aCx, const nsAString& aUrl, 1.867 + JS::Handle<JS::Value> aArgument, 1.868 + const nsAString& aOptions, 1.869 + JS::MutableHandle<JS::Value> aRetval, 1.870 + mozilla::ErrorResult& aError); 1.871 + void PostMessageMoz(JSContext* aCx, JS::Handle<JS::Value> aMessage, 1.872 + const nsAString& aTargetOrigin, 1.873 + const mozilla::dom::Optional<mozilla::dom::Sequence<JS::Value > >& aTransfer, 1.874 + mozilla::ErrorResult& aError); 1.875 + int32_t SetTimeout(JSContext* aCx, mozilla::dom::Function& aFunction, 1.876 + int32_t aTimeout, 1.877 + const mozilla::dom::Sequence<JS::Value>& aArguments, 1.878 + mozilla::ErrorResult& aError); 1.879 + int32_t SetTimeout(JSContext* aCx, const nsAString& aHandler, 1.880 + int32_t aTimeout, 1.881 + const mozilla::dom::Sequence<JS::Value>& /* unused */, 1.882 + mozilla::ErrorResult& aError); 1.883 + void ClearTimeout(int32_t aHandle, mozilla::ErrorResult& aError); 1.884 + int32_t SetInterval(JSContext* aCx, mozilla::dom::Function& aFunction, 1.885 + const mozilla::dom::Optional<int32_t>& aTimeout, 1.886 + const mozilla::dom::Sequence<JS::Value>& aArguments, 1.887 + mozilla::ErrorResult& aError); 1.888 + int32_t SetInterval(JSContext* aCx, const nsAString& aHandler, 1.889 + const mozilla::dom::Optional<int32_t>& aTimeout, 1.890 + const mozilla::dom::Sequence<JS::Value>& /* unused */, 1.891 + mozilla::ErrorResult& aError); 1.892 + void ClearInterval(int32_t aHandle, mozilla::ErrorResult& aError); 1.893 + void Atob(const nsAString& aAsciiBase64String, nsAString& aBinaryData, 1.894 + mozilla::ErrorResult& aError); 1.895 + void Btoa(const nsAString& aBinaryData, nsAString& aAsciiBase64String, 1.896 + mozilla::ErrorResult& aError); 1.897 + nsIDOMStorage* GetSessionStorage(mozilla::ErrorResult& aError); 1.898 + nsIDOMStorage* GetLocalStorage(mozilla::ErrorResult& aError); 1.899 + mozilla::dom::Selection* GetSelection(mozilla::ErrorResult& aError); 1.900 + mozilla::dom::indexedDB::IDBFactory* GetIndexedDB(mozilla::ErrorResult& aError); 1.901 + already_AddRefed<nsICSSDeclaration> 1.902 + GetComputedStyle(mozilla::dom::Element& aElt, const nsAString& aPseudoElt, 1.903 + mozilla::ErrorResult& aError); 1.904 + already_AddRefed<mozilla::dom::MediaQueryList> MatchMedia(const nsAString& aQuery, 1.905 + mozilla::ErrorResult& aError); 1.906 + nsScreen* GetScreen(mozilla::ErrorResult& aError); 1.907 + void MoveTo(int32_t aXPos, int32_t aYPos, mozilla::ErrorResult& aError); 1.908 + void MoveBy(int32_t aXDif, int32_t aYDif, mozilla::ErrorResult& aError); 1.909 + void ResizeTo(int32_t aWidth, int32_t aHeight, 1.910 + mozilla::ErrorResult& aError); 1.911 + void ResizeBy(int32_t aWidthDif, int32_t aHeightDif, 1.912 + mozilla::ErrorResult& aError); 1.913 + int32_t GetInnerWidth(mozilla::ErrorResult& aError); 1.914 + void SetInnerWidth(int32_t aInnerWidth, mozilla::ErrorResult& aError); 1.915 + int32_t GetInnerHeight(mozilla::ErrorResult& aError); 1.916 + void SetInnerHeight(int32_t aInnerHeight, mozilla::ErrorResult& aError); 1.917 + int32_t GetScrollX(mozilla::ErrorResult& aError); 1.918 + int32_t GetPageXOffset(mozilla::ErrorResult& aError) 1.919 + { 1.920 + return GetScrollX(aError); 1.921 + } 1.922 + int32_t GetScrollY(mozilla::ErrorResult& aError); 1.923 + int32_t GetPageYOffset(mozilla::ErrorResult& aError) 1.924 + { 1.925 + return GetScrollY(aError); 1.926 + } 1.927 + int32_t GetScreenX(mozilla::ErrorResult& aError); 1.928 + void SetScreenX(int32_t aScreenX, mozilla::ErrorResult& aError); 1.929 + int32_t GetScreenY(mozilla::ErrorResult& aError); 1.930 + void SetScreenY(int32_t aScreenY, mozilla::ErrorResult& aError); 1.931 + int32_t GetOuterWidth(mozilla::ErrorResult& aError); 1.932 + void SetOuterWidth(int32_t aOuterWidth, mozilla::ErrorResult& aError); 1.933 + int32_t GetOuterHeight(mozilla::ErrorResult& aError); 1.934 + void SetOuterHeight(int32_t aOuterHeight, mozilla::ErrorResult& aError); 1.935 + int32_t RequestAnimationFrame(mozilla::dom::FrameRequestCallback& aCallback, 1.936 + mozilla::ErrorResult& aError); 1.937 + void CancelAnimationFrame(int32_t aHandle, mozilla::ErrorResult& aError); 1.938 + nsPerformance* GetPerformance(mozilla::ErrorResult& aError); 1.939 + nsresult GetFirstPartyIsolationURI(nsIURI** aFirstPartyIsolationURI); 1.940 + 1.941 +#ifdef MOZ_WEBSPEECH 1.942 + mozilla::dom::SpeechSynthesis* 1.943 + GetSpeechSynthesis(mozilla::ErrorResult& aError); 1.944 +#endif 1.945 + already_AddRefed<nsICSSDeclaration> 1.946 + GetDefaultComputedStyle(mozilla::dom::Element& aElt, 1.947 + const nsAString& aPseudoElt, 1.948 + mozilla::ErrorResult& aError); 1.949 + mozilla::dom::indexedDB::IDBFactory* 1.950 + GetMozIndexedDB(mozilla::ErrorResult& aError) 1.951 + { 1.952 + return GetIndexedDB(aError); 1.953 + } 1.954 + int32_t MozRequestAnimationFrame(nsIFrameRequestCallback* aRequestCallback, 1.955 + mozilla::ErrorResult& aError); 1.956 + void MozCancelAnimationFrame(int32_t aHandle, mozilla::ErrorResult& aError) 1.957 + { 1.958 + return CancelAnimationFrame(aHandle, aError); 1.959 + } 1.960 + void MozCancelRequestAnimationFrame(int32_t aHandle, 1.961 + mozilla::ErrorResult& aError) 1.962 + { 1.963 + return CancelAnimationFrame(aHandle, aError); 1.964 + } 1.965 + int64_t GetMozAnimationStartTime(mozilla::ErrorResult& aError); 1.966 + void SizeToContent(mozilla::ErrorResult& aError); 1.967 + nsIDOMCrypto* GetCrypto(mozilla::ErrorResult& aError); 1.968 + nsIControllers* GetControllers(mozilla::ErrorResult& aError); 1.969 + float GetMozInnerScreenX(mozilla::ErrorResult& aError); 1.970 + float GetMozInnerScreenY(mozilla::ErrorResult& aError); 1.971 + float GetDevicePixelRatio(mozilla::ErrorResult& aError); 1.972 + int32_t GetScrollMaxX(mozilla::ErrorResult& aError); 1.973 + int32_t GetScrollMaxY(mozilla::ErrorResult& aError); 1.974 + bool GetFullScreen(mozilla::ErrorResult& aError); 1.975 + void SetFullScreen(bool aFullScreen, mozilla::ErrorResult& aError); 1.976 + void Back(mozilla::ErrorResult& aError); 1.977 + void Forward(mozilla::ErrorResult& aError); 1.978 + void Home(mozilla::ErrorResult& aError); 1.979 + bool Find(const nsAString& aString, bool aCaseSensitive, bool aBackwards, 1.980 + bool aWrapAround, bool aWholeWord, bool aSearchInFrames, 1.981 + bool aShowDialog, mozilla::ErrorResult& aError); 1.982 + uint64_t GetMozPaintCount(mozilla::ErrorResult& aError); 1.983 + already_AddRefed<nsIDOMWindow> OpenDialog(JSContext* aCx, 1.984 + const nsAString& aUrl, 1.985 + const nsAString& aName, 1.986 + const nsAString& aOptions, 1.987 + const mozilla::dom::Sequence<JS::Value>& aExtraArgument, 1.988 + mozilla::ErrorResult& aError); 1.989 + void GetContent(JSContext* aCx, 1.990 + JS::MutableHandle<JSObject*> aRetval, 1.991 + mozilla::ErrorResult& aError); 1.992 + void Get_content(JSContext* aCx, 1.993 + JS::MutableHandle<JSObject*> aRetval, 1.994 + mozilla::ErrorResult& aError) 1.995 + { 1.996 + if (mDoc) { 1.997 + mDoc->WarnOnceAbout(nsIDocument::eWindow_Content); 1.998 + } 1.999 + GetContent(aCx, aRetval, aError); 1.1000 + } 1.1001 + 1.1002 + // ChromeWindow bits. Do NOT call these unless your window is in 1.1003 + // fact an nsGlobalChromeWindow. 1.1004 + uint16_t WindowState(); 1.1005 + nsIBrowserDOMWindow* GetBrowserDOMWindow(mozilla::ErrorResult& aError); 1.1006 + void SetBrowserDOMWindow(nsIBrowserDOMWindow* aBrowserWindow, 1.1007 + mozilla::ErrorResult& aError); 1.1008 + void GetAttention(mozilla::ErrorResult& aError); 1.1009 + void GetAttentionWithCycleCount(int32_t aCycleCount, 1.1010 + mozilla::ErrorResult& aError); 1.1011 + void SetCursor(const nsAString& aCursor, mozilla::ErrorResult& aError); 1.1012 + void Maximize(mozilla::ErrorResult& aError); 1.1013 + void Minimize(mozilla::ErrorResult& aError); 1.1014 + void Restore(mozilla::ErrorResult& aError); 1.1015 + void NotifyDefaultButtonLoaded(mozilla::dom::Element& aDefaultButton, 1.1016 + mozilla::ErrorResult& aError); 1.1017 + nsIMessageBroadcaster* GetMessageManager(mozilla::ErrorResult& aError); 1.1018 + void BeginWindowMove(mozilla::dom::Event& aMouseDownEvent, 1.1019 + mozilla::dom::Element* aPanel, 1.1020 + mozilla::ErrorResult& aError); 1.1021 + 1.1022 + void GetDialogArguments(JSContext* aCx, JS::MutableHandle<JS::Value> aRetval, 1.1023 + mozilla::ErrorResult& aError); 1.1024 + void GetReturnValue(JSContext* aCx, JS::MutableHandle<JS::Value> aReturnValue, 1.1025 + mozilla::ErrorResult& aError); 1.1026 + void SetReturnValue(JSContext* aCx, JS::Handle<JS::Value> aReturnValue, 1.1027 + mozilla::ErrorResult& aError); 1.1028 + 1.1029 + void GetInterface(JSContext* aCx, nsIJSID* aIID, 1.1030 + JS::MutableHandle<JS::Value> aRetval, 1.1031 + mozilla::ErrorResult& aError); 1.1032 + 1.1033 +protected: 1.1034 + // Array of idle observers that are notified of idle events. 1.1035 + nsTObserverArray<IdleObserverHolder> mIdleObservers; 1.1036 + 1.1037 + // Idle timer used for function callbacks to notify idle observers. 1.1038 + nsCOMPtr<nsITimer> mIdleTimer; 1.1039 + 1.1040 + // Idle fuzz time added to idle timer callbacks. 1.1041 + uint32_t mIdleFuzzFactor; 1.1042 + 1.1043 + // Index in mArrayIdleObservers 1.1044 + // Next idle observer to notify user idle status 1.1045 + int32_t mIdleCallbackIndex; 1.1046 + 1.1047 + // If false then the topic is "active" 1.1048 + // If true then the topic is "idle" 1.1049 + bool mCurrentlyIdle; 1.1050 + 1.1051 + // Set to true when a fuzz time needs to be applied 1.1052 + // to active notifications to the idle observer. 1.1053 + bool mAddActiveEventFuzzTime; 1.1054 + 1.1055 + nsCOMPtr <nsIIdleService> mIdleService; 1.1056 + 1.1057 + nsRefPtr<mozilla::dom::WakeLock> mWakeLock; 1.1058 + 1.1059 + static bool sIdleObserversAPIFuzzTimeDisabled; 1.1060 + 1.1061 + friend class HashchangeCallback; 1.1062 + friend class mozilla::dom::BarProp; 1.1063 + 1.1064 + // Object Management 1.1065 + virtual ~nsGlobalWindow(); 1.1066 + void DropOuterWindowDocs(); 1.1067 + void CleanUp(); 1.1068 + void ClearControllers(); 1.1069 + nsresult FinalClose(); 1.1070 + 1.1071 + inline void MaybeClearInnerWindow(nsGlobalWindow* aExpectedInner) 1.1072 + { 1.1073 + if(mInnerWindow == aExpectedInner) { 1.1074 + mInnerWindow = nullptr; 1.1075 + } 1.1076 + } 1.1077 + 1.1078 + void FreeInnerObjects(); 1.1079 + JSObject *CallerGlobal(); 1.1080 + nsGlobalWindow *CallerInnerWindow(); 1.1081 + 1.1082 + // Only to be called on an inner window. 1.1083 + // aDocument must not be null. 1.1084 + void InnerSetNewDocument(JSContext* aCx, nsIDocument* aDocument); 1.1085 + 1.1086 + nsresult DefineArgumentsProperty(nsIArray *aArguments); 1.1087 + 1.1088 + // Get the parent, returns null if this is a toplevel window 1.1089 + nsIDOMWindow* GetParentInternal(); 1.1090 + 1.1091 + // popup tracking 1.1092 + bool IsPopupSpamWindow() 1.1093 + { 1.1094 + if (IsInnerWindow() && !mOuterWindow) { 1.1095 + return false; 1.1096 + } 1.1097 + 1.1098 + return GetOuterWindowInternal()->mIsPopupSpam; 1.1099 + } 1.1100 + 1.1101 + void SetPopupSpamWindow(bool aPopup) 1.1102 + { 1.1103 + if (IsInnerWindow() && !mOuterWindow) { 1.1104 + NS_ERROR("SetPopupSpamWindow() called on inner window w/o an outer!"); 1.1105 + 1.1106 + return; 1.1107 + } 1.1108 + 1.1109 + GetOuterWindowInternal()->mIsPopupSpam = aPopup; 1.1110 + } 1.1111 + 1.1112 + // Window Control Functions 1.1113 + 1.1114 + virtual nsresult 1.1115 + OpenNoNavigate(const nsAString& aUrl, 1.1116 + const nsAString& aName, 1.1117 + const nsAString& aOptions, 1.1118 + nsIDOMWindow **_retval); 1.1119 + 1.1120 + /** 1.1121 + * @param aUrl the URL we intend to load into the window. If aNavigate is 1.1122 + * true, we'll actually load this URL into the window. Otherwise, 1.1123 + * aUrl is advisory; OpenInternal will not load the URL into the 1.1124 + * new window. 1.1125 + * 1.1126 + * @param aName the name to use for the new window 1.1127 + * 1.1128 + * @param aOptions the window options to use for the new window 1.1129 + * 1.1130 + * @param aDialog true when called from variants of OpenDialog. If this is 1.1131 + * true, this method will skip popup blocking checks. The aDialog 1.1132 + * argument is passed on to the window watcher. 1.1133 + * 1.1134 + * @param aCalledNoScript true when called via the [noscript] open() 1.1135 + * and openDialog() methods. When this is true, we do NOT want to use 1.1136 + * the JS stack for things like caller determination. 1.1137 + * 1.1138 + * @param aDoJSFixups true when this is the content-accessible JS version of 1.1139 + * window opening. When true, popups do not cause us to throw, we save 1.1140 + * the caller's principal in the new window for later consumption, and 1.1141 + * we make sure that there is a document in the newly-opened window. 1.1142 + * Note that this last will only be done if the newly-opened window is 1.1143 + * non-chrome. 1.1144 + * 1.1145 + * @param aNavigate true if we should navigate to the provided URL, false 1.1146 + * otherwise. When aNavigate is false, we also skip our can-load 1.1147 + * security check, on the assumption that whoever *actually* loads this 1.1148 + * page will do their own security check. 1.1149 + * 1.1150 + * @param argv The arguments to pass to the new window. The first 1.1151 + * three args, if present, will be aUrl, aName, and aOptions. So this 1.1152 + * param only matters if there are more than 3 arguments. 1.1153 + * 1.1154 + * @param argc The number of arguments in argv. 1.1155 + * 1.1156 + * @param aExtraArgument Another way to pass arguments in. This is mutually 1.1157 + * exclusive with the argv/argc approach. 1.1158 + * 1.1159 + * @param aJSCallerContext The calling script's context. This must be null 1.1160 + * when aCalledNoScript is true. 1.1161 + * 1.1162 + * @param aReturn [out] The window that was opened, if any. 1.1163 + */ 1.1164 + NS_HIDDEN_(nsresult) OpenInternal(const nsAString& aUrl, 1.1165 + const nsAString& aName, 1.1166 + const nsAString& aOptions, 1.1167 + bool aDialog, 1.1168 + bool aContentModal, 1.1169 + bool aCalledNoScript, 1.1170 + bool aDoJSFixups, 1.1171 + bool aNavigate, 1.1172 + nsIArray *argv, 1.1173 + nsISupports *aExtraArgument, 1.1174 + nsIPrincipal *aCalleePrincipal, 1.1175 + JSContext *aJSCallerContext, 1.1176 + nsIDOMWindow **aReturn); 1.1177 + 1.1178 + // Timeout Functions 1.1179 + // Language agnostic timeout function (all args passed). 1.1180 + // |interval| is in milliseconds. 1.1181 + nsresult SetTimeoutOrInterval(nsIScriptTimeoutHandler *aHandler, 1.1182 + int32_t interval, 1.1183 + bool aIsInterval, int32_t *aReturn); 1.1184 + int32_t SetTimeoutOrInterval(mozilla::dom::Function& aFunction, 1.1185 + int32_t aTimeout, 1.1186 + const mozilla::dom::Sequence<JS::Value>& aArguments, 1.1187 + bool aIsInterval, mozilla::ErrorResult& aError); 1.1188 + int32_t SetTimeoutOrInterval(JSContext* aCx, const nsAString& aHandler, 1.1189 + int32_t aTimeout, bool aIsInterval, 1.1190 + mozilla::ErrorResult& aError); 1.1191 + void ClearTimeoutOrInterval(int32_t aTimerID, 1.1192 + mozilla::ErrorResult& aError); 1.1193 + nsresult ClearTimeoutOrInterval(int32_t aTimerID) 1.1194 + { 1.1195 + mozilla::ErrorResult rv; 1.1196 + ClearTimeoutOrInterval(aTimerID, rv); 1.1197 + return rv.ErrorCode(); 1.1198 + } 1.1199 + 1.1200 + // JS specific timeout functions (JS args grabbed from context). 1.1201 + nsresult SetTimeoutOrInterval(bool aIsInterval, int32_t* aReturn); 1.1202 + nsresult ResetTimersForNonBackgroundWindow(); 1.1203 + 1.1204 + // The timeout implementation functions. 1.1205 + void RunTimeout(nsTimeout *aTimeout); 1.1206 + void RunTimeout() { RunTimeout(nullptr); } 1.1207 + // Return true if |aTimeout| was cleared while its handler ran. 1.1208 + bool RunTimeoutHandler(nsTimeout* aTimeout, nsIScriptContext* aScx); 1.1209 + // Return true if |aTimeout| needs to be reinserted into the timeout list. 1.1210 + bool RescheduleTimeout(nsTimeout* aTimeout, const TimeStamp& now, 1.1211 + bool aRunningPendingTimeouts); 1.1212 + 1.1213 + void ClearAllTimeouts(); 1.1214 + // Insert aTimeout into the list, before all timeouts that would 1.1215 + // fire after it, but no earlier than mTimeoutInsertionPoint, if any. 1.1216 + void InsertTimeoutIntoList(nsTimeout *aTimeout); 1.1217 + static void TimerCallback(nsITimer *aTimer, void *aClosure); 1.1218 + 1.1219 + // Helper Functions 1.1220 + already_AddRefed<nsIDocShellTreeOwner> GetTreeOwner(); 1.1221 + already_AddRefed<nsIBaseWindow> GetTreeOwnerWindow(); 1.1222 + already_AddRefed<nsIWebBrowserChrome> GetWebBrowserChrome(); 1.1223 + nsresult SecurityCheckURL(const char *aURL); 1.1224 + 1.1225 + bool PopupWhitelisted(); 1.1226 + PopupControlState RevisePopupAbuseLevel(PopupControlState); 1.1227 + void FireAbuseEvents(bool aBlocked, bool aWindow, 1.1228 + const nsAString &aPopupURL, 1.1229 + const nsAString &aPopupWindowName, 1.1230 + const nsAString &aPopupWindowFeatures); 1.1231 + void FireOfflineStatusEvent(); 1.1232 + 1.1233 + // Inner windows only. 1.1234 + nsresult ScheduleNextIdleObserverCallback(); 1.1235 + uint32_t GetFuzzTimeMS(); 1.1236 + nsresult ScheduleActiveTimerCallback(); 1.1237 + uint32_t FindInsertionIndex(IdleObserverHolder* aIdleObserver); 1.1238 + virtual nsresult RegisterIdleObserver(nsIIdleObserver* aIdleObserverPtr); 1.1239 + nsresult FindIndexOfElementToRemove(nsIIdleObserver* aIdleObserver, 1.1240 + int32_t* aRemoveElementIndex); 1.1241 + virtual nsresult UnregisterIdleObserver(nsIIdleObserver* aIdleObserverPtr); 1.1242 + 1.1243 + // Inner windows only. 1.1244 + nsresult FireHashchange(const nsAString &aOldURL, const nsAString &aNewURL); 1.1245 + 1.1246 + void FlushPendingNotifications(mozFlushType aType); 1.1247 + 1.1248 + // Outer windows only. 1.1249 + void EnsureReflowFlushAndPaint(); 1.1250 + void CheckSecurityWidthAndHeight(int32_t* width, int32_t* height); 1.1251 + void CheckSecurityLeftAndTop(int32_t* left, int32_t* top); 1.1252 + 1.1253 + // Outer windows only. 1.1254 + // Arguments to this function should have values in app units 1.1255 + void SetCSSViewportWidthAndHeight(nscoord width, nscoord height); 1.1256 + // Arguments to this function should have values in device pixels 1.1257 + nsresult SetDocShellWidthAndHeight(int32_t width, int32_t height); 1.1258 + 1.1259 + static bool CanSetProperty(const char *aPrefName); 1.1260 + 1.1261 + static void MakeScriptDialogTitle(nsAString &aOutTitle); 1.1262 + 1.1263 + // Outer windows only. 1.1264 + bool CanMoveResizeWindows(); 1.1265 + 1.1266 + // If aDoFlush is true, we'll flush our own layout; otherwise we'll try to 1.1267 + // just flush our parent and only flush ourselves if we think we need to. 1.1268 + mozilla::CSSIntPoint GetScrollXY(bool aDoFlush, mozilla::ErrorResult& aError); 1.1269 + nsresult GetScrollXY(int32_t* aScrollX, int32_t* aScrollY, bool aDoFlush); 1.1270 + void GetScrollMaxXY(int32_t* aScrollMaxX, int32_t* aScrollMaxY, 1.1271 + mozilla::ErrorResult& aError); 1.1272 + 1.1273 + // Outer windows only. 1.1274 + nsresult GetInnerSize(mozilla::CSSIntSize& aSize); 1.1275 + nsIntSize GetOuterSize(mozilla::ErrorResult& aError); 1.1276 + void SetOuterSize(int32_t aLengthCSSPixels, bool aIsWidth, 1.1277 + mozilla::ErrorResult& aError); 1.1278 + nsRect GetInnerScreenRect(); 1.1279 + 1.1280 + void ScrollTo(const mozilla::CSSIntPoint& aScroll); 1.1281 + 1.1282 + bool IsFrame() 1.1283 + { 1.1284 + return GetParentInternal() != nullptr; 1.1285 + } 1.1286 + 1.1287 + // Outer windows only. 1.1288 + // If aLookForCallerOnJSStack is true, this method will look at the JS stack 1.1289 + // to determine who the caller is. If it's false, it'll use |this| as the 1.1290 + // caller. 1.1291 + bool WindowExists(const nsAString& aName, bool aLookForCallerOnJSStack); 1.1292 + 1.1293 + already_AddRefed<nsIWidget> GetMainWidget(); 1.1294 + nsIWidget* GetNearestWidget(); 1.1295 + 1.1296 + void Freeze() 1.1297 + { 1.1298 + NS_ASSERTION(!IsFrozen(), "Double-freezing?"); 1.1299 + mIsFrozen = true; 1.1300 + NotifyDOMWindowFrozen(this); 1.1301 + } 1.1302 + 1.1303 + void Thaw() 1.1304 + { 1.1305 + mIsFrozen = false; 1.1306 + NotifyDOMWindowThawed(this); 1.1307 + } 1.1308 + 1.1309 + bool IsInModalState(); 1.1310 + 1.1311 + // Convenience functions for the many methods that need to scale 1.1312 + // from device to CSS pixels or vice versa. Note: if a presentation 1.1313 + // context is not available, they will assume a 1:1 ratio. 1.1314 + int32_t DevToCSSIntPixels(int32_t px); 1.1315 + int32_t CSSToDevIntPixels(int32_t px); 1.1316 + nsIntSize DevToCSSIntPixels(nsIntSize px); 1.1317 + nsIntSize CSSToDevIntPixels(nsIntSize px); 1.1318 + 1.1319 + virtual void SetFocusedNode(nsIContent* aNode, 1.1320 + uint32_t aFocusMethod = 0, 1.1321 + bool aNeedsFocus = false); 1.1322 + 1.1323 + virtual uint32_t GetFocusMethod(); 1.1324 + 1.1325 + virtual bool ShouldShowFocusRing(); 1.1326 + 1.1327 + virtual void SetKeyboardIndicators(UIStateChangeType aShowAccelerators, 1.1328 + UIStateChangeType aShowFocusRings); 1.1329 + virtual void GetKeyboardIndicators(bool* aShowAccelerators, 1.1330 + bool* aShowFocusRings); 1.1331 + 1.1332 + // Inner windows only. 1.1333 + void UpdateCanvasFocus(bool aFocusChanged, nsIContent* aNewContent); 1.1334 + 1.1335 +public: 1.1336 + virtual already_AddRefed<nsPIWindowRoot> GetTopWindowRoot() MOZ_OVERRIDE; 1.1337 + 1.1338 +protected: 1.1339 + static void NotifyDOMWindowDestroyed(nsGlobalWindow* aWindow); 1.1340 + void NotifyWindowIDDestroyed(const char* aTopic); 1.1341 + 1.1342 + static void NotifyDOMWindowFrozen(nsGlobalWindow* aWindow); 1.1343 + static void NotifyDOMWindowThawed(nsGlobalWindow* aWindow); 1.1344 + 1.1345 + void ClearStatus(); 1.1346 + 1.1347 + virtual void UpdateParentTarget(); 1.1348 + 1.1349 + inline int32_t DOMMinTimeoutValue() const; 1.1350 + 1.1351 + nsresult CloneStorageEvent(const nsAString& aType, 1.1352 + nsCOMPtr<nsIDOMStorageEvent>& aEvent); 1.1353 + 1.1354 + // Outer windows only. 1.1355 + nsDOMWindowList* GetWindowList(); 1.1356 + 1.1357 + // Helper for getComputedStyle and getDefaultComputedStyle 1.1358 + already_AddRefed<nsICSSDeclaration> 1.1359 + GetComputedStyleHelper(mozilla::dom::Element& aElt, 1.1360 + const nsAString& aPseudoElt, 1.1361 + bool aDefaultStylesOnly, 1.1362 + mozilla::ErrorResult& aError); 1.1363 + nsresult GetComputedStyleHelper(nsIDOMElement* aElt, 1.1364 + const nsAString& aPseudoElt, 1.1365 + bool aDefaultStylesOnly, 1.1366 + nsIDOMCSSStyleDeclaration** aReturn); 1.1367 + 1.1368 + void PreloadLocalStorage(); 1.1369 + 1.1370 + // Returns device pixels. Outer windows only. 1.1371 + nsIntPoint GetScreenXY(mozilla::ErrorResult& aError); 1.1372 + 1.1373 + int32_t RequestAnimationFrame(const nsIDocument::FrameRequestCallbackHolder& aCallback, 1.1374 + mozilla::ErrorResult& aError); 1.1375 + 1.1376 + nsGlobalWindow* InnerForSetTimeoutOrInterval(mozilla::ErrorResult& aError); 1.1377 + 1.1378 + mozilla::dom::Element* GetRealFrameElement(mozilla::ErrorResult& aError); 1.1379 + 1.1380 + void PostMessageMoz(JSContext* aCx, JS::Handle<JS::Value> aMessage, 1.1381 + const nsAString& aTargetOrigin, 1.1382 + JS::Handle<JS::Value> aTransfer, 1.1383 + mozilla::ErrorResult& aError); 1.1384 + 1.1385 + already_AddRefed<nsIVariant> 1.1386 + ShowModalDialog(const nsAString& aUrl, nsIVariant* aArgument, 1.1387 + const nsAString& aOptions, mozilla::ErrorResult& aError); 1.1388 + 1.1389 + already_AddRefed<nsIDOMWindow> 1.1390 + GetContentInternal(mozilla::ErrorResult& aError); 1.1391 + 1.1392 + // Ask the user if further dialogs should be blocked, if dialogs are currently 1.1393 + // being abused. This is used in the cases where we have no modifiable UI to 1.1394 + // show, in that case we show a separate dialog to ask this question. 1.1395 + bool ConfirmDialogIfNeeded(); 1.1396 + 1.1397 + // When adding new member variables, be careful not to create cycles 1.1398 + // through JavaScript. If there is any chance that a member variable 1.1399 + // could own objects that are implemented in JavaScript, then those 1.1400 + // objects will keep the global object (this object) alive. To prevent 1.1401 + // these cycles, ownership of such members must be released in 1.1402 + // |CleanUp| and |DetachFromDocShell|. 1.1403 + 1.1404 + // This member is also used on both inner and outer windows, but 1.1405 + // for slightly different purposes. On inner windows it means the 1.1406 + // inner window is held onto by session history and should not 1.1407 + // change. On outer windows it means that the window is in a state 1.1408 + // where we don't want to force creation of a new inner window since 1.1409 + // we're in the middle of doing just that. 1.1410 + bool mIsFrozen : 1; 1.1411 + 1.1412 + // These members are only used on outer window objects. Make sure 1.1413 + // you never set any of these on an inner object! 1.1414 + bool mFullScreen : 1; 1.1415 + bool mIsClosed : 1; 1.1416 + bool mInClose : 1; 1.1417 + // mHavePendingClose means we've got a termination function set to 1.1418 + // close us when the JS stops executing or that we have a close 1.1419 + // event posted. If this is set, just ignore window.close() calls. 1.1420 + bool mHavePendingClose : 1; 1.1421 + bool mHadOriginalOpener : 1; 1.1422 + bool mIsPopupSpam : 1; 1.1423 + 1.1424 + // Indicates whether scripts are allowed to close this window. 1.1425 + bool mBlockScriptedClosingFlag : 1; 1.1426 + 1.1427 + // Track what sorts of events we need to fire when thawed 1.1428 + bool mFireOfflineStatusChangeEventOnThaw : 1; 1.1429 + bool mNotifyIdleObserversIdleOnThaw : 1; 1.1430 + bool mNotifyIdleObserversActiveOnThaw : 1; 1.1431 + 1.1432 + // Indicates whether we're in the middle of creating an initializing 1.1433 + // a new inner window object. 1.1434 + bool mCreatingInnerWindow : 1; 1.1435 + 1.1436 + // Fast way to tell if this is a chrome window (without having to QI). 1.1437 + bool mIsChrome : 1; 1.1438 + 1.1439 + // Hack to indicate whether a chrome window needs its message manager 1.1440 + // to be disconnected, since clean up code is shared in the global 1.1441 + // window superclass. 1.1442 + bool mCleanMessageManager : 1; 1.1443 + 1.1444 + // Indicates that the current document has never received a document focus 1.1445 + // event. 1.1446 + bool mNeedsFocus : 1; 1.1447 + bool mHasFocus : 1; 1.1448 + 1.1449 + // whether to show keyboard accelerators 1.1450 + bool mShowAccelerators : 1; 1.1451 + 1.1452 + // whether to show focus rings 1.1453 + bool mShowFocusRings : 1; 1.1454 + 1.1455 + // when true, show focus rings for the current focused content only. 1.1456 + // This will be reset when another element is focused 1.1457 + bool mShowFocusRingForContent : 1; 1.1458 + 1.1459 + // true if tab navigation has occurred for this window. Focus rings 1.1460 + // should be displayed. 1.1461 + bool mFocusByKeyOccurred : 1; 1.1462 + 1.1463 + // Ensure that a call to ResumeTimeouts() after FreeInnerObjects() does nothing. 1.1464 + // This member is only used by inner windows. 1.1465 + bool mInnerObjectsFreed : 1; 1.1466 + 1.1467 + // Indicates whether this window wants gamepad input events 1.1468 + bool mHasGamepad : 1; 1.1469 +#ifdef MOZ_GAMEPAD 1.1470 + nsRefPtrHashtable<nsUint32HashKey, mozilla::dom::Gamepad> mGamepads; 1.1471 + bool mHasSeenGamepadInput; 1.1472 +#endif 1.1473 + 1.1474 + // whether we've sent the destroy notification for our window id 1.1475 + bool mNotifiedIDDestroyed : 1; 1.1476 + // whether scripts may close the window, 1.1477 + // even if "dom.allow_scripts_to_close_windows" is false. 1.1478 + bool mAllowScriptsToClose : 1; 1.1479 + 1.1480 + nsCOMPtr<nsIScriptContext> mContext; 1.1481 + nsWeakPtr mOpener; 1.1482 + nsCOMPtr<nsIControllers> mControllers; 1.1483 + 1.1484 + // For |window.arguments|, via |openDialog|. 1.1485 + nsCOMPtr<nsIArray> mArguments; 1.1486 + 1.1487 + // For |window.dialogArguments|, via |showModalDialog|. 1.1488 + nsRefPtr<DialogValueHolder> mDialogArguments; 1.1489 + 1.1490 + // Only used in the outer. 1.1491 + nsRefPtr<DialogValueHolder> mReturnValue; 1.1492 + 1.1493 + nsRefPtr<mozilla::dom::Navigator> mNavigator; 1.1494 + nsRefPtr<nsScreen> mScreen; 1.1495 + nsRefPtr<nsDOMWindowList> mFrames; 1.1496 + nsRefPtr<mozilla::dom::BarProp> mMenubar; 1.1497 + nsRefPtr<mozilla::dom::BarProp> mToolbar; 1.1498 + nsRefPtr<mozilla::dom::BarProp> mLocationbar; 1.1499 + nsRefPtr<mozilla::dom::BarProp> mPersonalbar; 1.1500 + nsRefPtr<mozilla::dom::BarProp> mStatusbar; 1.1501 + nsRefPtr<mozilla::dom::BarProp> mScrollbars; 1.1502 + nsRefPtr<nsDOMWindowUtils> mWindowUtils; 1.1503 + nsString mStatus; 1.1504 + nsString mDefaultStatus; 1.1505 + nsGlobalWindowObserver* mObserver; // Inner windows only. 1.1506 + nsCOMPtr<nsIDOMCrypto> mCrypto; 1.1507 + nsRefPtr<mozilla::dom::Console> mConsole; 1.1508 + // We need to store an nsISupports pointer to this object because the 1.1509 + // mozilla::dom::External class doesn't exist on b2g and using the type 1.1510 + // forward declared here means that ~nsGlobalWindow wouldn't compile because 1.1511 + // it wouldn't see the ~External function's declaration. 1.1512 + nsCOMPtr<nsISupports> mExternal; 1.1513 + 1.1514 + nsCOMPtr<nsIDOMStorage> mLocalStorage; 1.1515 + nsCOMPtr<nsIDOMStorage> mSessionStorage; 1.1516 + 1.1517 + // These member variable are used only on inner windows. 1.1518 + nsRefPtr<mozilla::EventListenerManager> mListenerManager; 1.1519 + // mTimeouts is generally sorted by mWhen, unless mTimeoutInsertionPoint is 1.1520 + // non-null. In that case, the dummy timeout pointed to by 1.1521 + // mTimeoutInsertionPoint may have a later mWhen than some of the timeouts 1.1522 + // that come after it. 1.1523 + mozilla::LinkedList<nsTimeout> mTimeouts; 1.1524 + // If mTimeoutInsertionPoint is non-null, insertions should happen after it. 1.1525 + // This is a dummy timeout at the moment; if that ever changes, the logic in 1.1526 + // ResetTimersForNonBackgroundWindow needs to change. 1.1527 + nsTimeout* mTimeoutInsertionPoint; 1.1528 + uint32_t mTimeoutPublicIdCounter; 1.1529 + uint32_t mTimeoutFiringDepth; 1.1530 + nsRefPtr<nsLocation> mLocation; 1.1531 + nsRefPtr<nsHistory> mHistory; 1.1532 + 1.1533 + // These member variables are used on both inner and the outer windows. 1.1534 + nsCOMPtr<nsIPrincipal> mDocumentPrincipal; 1.1535 + 1.1536 + typedef nsCOMArray<nsIDOMStorageEvent> nsDOMStorageEventArray; 1.1537 + nsDOMStorageEventArray mPendingStorageEvents; 1.1538 + 1.1539 + uint32_t mTimeoutsSuspendDepth; 1.1540 + 1.1541 + // the method that was used to focus mFocusedNode 1.1542 + uint32_t mFocusMethod; 1.1543 + 1.1544 + uint32_t mSerial; 1.1545 + 1.1546 +#ifdef DEBUG 1.1547 + bool mSetOpenerWindowCalled; 1.1548 + nsCOMPtr<nsIURI> mLastOpenedURI; 1.1549 +#endif 1.1550 + 1.1551 +#ifdef MOZ_B2G 1.1552 + bool mNetworkUploadObserverEnabled; 1.1553 + bool mNetworkDownloadObserverEnabled; 1.1554 +#endif // MOZ_B2G 1.1555 + 1.1556 + bool mCleanedUp; 1.1557 + 1.1558 + nsCOMPtr<nsIDOMOfflineResourceList> mApplicationCache; 1.1559 + 1.1560 + nsAutoPtr<nsJSThingHashtable<nsPtrHashKey<nsXBLPrototypeHandler>, JSObject*> > mCachedXBLPrototypeHandlers; 1.1561 + 1.1562 + // mSuspendedDoc is only set on outer windows. It's useful when we get matched 1.1563 + // EnterModalState/LeaveModalState calls, in which case the outer window is 1.1564 + // responsible for unsuspending events on the document. If we don't (for 1.1565 + // example, if the outer window is closed before the LeaveModalState call), 1.1566 + // then the inner window whose mDoc is our mSuspendedDoc is responsible for 1.1567 + // unsuspending it. 1.1568 + nsCOMPtr<nsIDocument> mSuspendedDoc; 1.1569 + 1.1570 + nsRefPtr<mozilla::dom::indexedDB::IDBFactory> mIndexedDB; 1.1571 + 1.1572 + // This counts the number of windows that have been opened in rapid succession 1.1573 + // (i.e. within dom.successive_dialog_time_limit of each other). It is reset 1.1574 + // to 0 once a dialog is opened after dom.successive_dialog_time_limit seconds 1.1575 + // have elapsed without any other dialogs. 1.1576 + uint32_t mDialogAbuseCount; 1.1577 + 1.1578 + // This holds the time when the last modal dialog was shown. If more than 1.1579 + // MAX_DIALOG_LIMIT dialogs are shown within the time span defined by 1.1580 + // dom.successive_dialog_time_limit, we show a checkbox or confirmation prompt 1.1581 + // to allow disabling of further dialogs from this window. 1.1582 + TimeStamp mLastDialogQuitTime; 1.1583 + 1.1584 + // This flag keeps track of whether dialogs are 1.1585 + // currently enabled on this window. 1.1586 + bool mAreDialogsEnabled; 1.1587 + 1.1588 + nsTHashtable<nsPtrHashKey<mozilla::DOMEventTargetHelper> > mEventTargetObjects; 1.1589 + 1.1590 + nsTArray<uint32_t> mEnabledSensors; 1.1591 + 1.1592 +#ifdef MOZ_WEBSPEECH 1.1593 + // mSpeechSynthesis is only used on inner windows. 1.1594 + nsRefPtr<mozilla::dom::SpeechSynthesis> mSpeechSynthesis; 1.1595 +#endif 1.1596 + 1.1597 + friend class nsDOMScriptableHelper; 1.1598 + friend class nsDOMWindowUtils; 1.1599 + friend class PostMessageEvent; 1.1600 + friend class DesktopNotification; 1.1601 + 1.1602 + static WindowByIdTable* sWindowsById; 1.1603 + static bool sWarnedAboutWindowInternal; 1.1604 +}; 1.1605 + 1.1606 +inline nsISupports* 1.1607 +ToSupports(nsGlobalWindow *p) 1.1608 +{ 1.1609 + return static_cast<nsIDOMEventTarget*>(p); 1.1610 +} 1.1611 + 1.1612 +inline nsISupports* 1.1613 +ToCanonicalSupports(nsGlobalWindow *p) 1.1614 +{ 1.1615 + return static_cast<nsIDOMEventTarget*>(p); 1.1616 +} 1.1617 + 1.1618 +/* 1.1619 + * nsGlobalChromeWindow inherits from nsGlobalWindow. It is the global 1.1620 + * object created for a Chrome Window only. 1.1621 + */ 1.1622 +class nsGlobalChromeWindow : public nsGlobalWindow, 1.1623 + public nsIDOMChromeWindow 1.1624 +{ 1.1625 +public: 1.1626 + // nsISupports 1.1627 + NS_DECL_ISUPPORTS_INHERITED 1.1628 + 1.1629 + // nsIDOMChromeWindow interface 1.1630 + NS_DECL_NSIDOMCHROMEWINDOW 1.1631 + 1.1632 + nsGlobalChromeWindow(nsGlobalWindow *aOuterWindow) 1.1633 + : nsGlobalWindow(aOuterWindow) 1.1634 + { 1.1635 + mIsChrome = true; 1.1636 + mCleanMessageManager = true; 1.1637 + } 1.1638 + 1.1639 + ~nsGlobalChromeWindow() 1.1640 + { 1.1641 + NS_ABORT_IF_FALSE(mCleanMessageManager, 1.1642 + "chrome windows may always disconnect the msg manager"); 1.1643 + if (mMessageManager) { 1.1644 + static_cast<nsFrameMessageManager *>( 1.1645 + mMessageManager.get())->Disconnect(); 1.1646 + } 1.1647 + 1.1648 + mCleanMessageManager = false; 1.1649 + } 1.1650 + 1.1651 + NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsGlobalChromeWindow, 1.1652 + nsGlobalWindow) 1.1653 + 1.1654 + using nsGlobalWindow::GetBrowserDOMWindow; 1.1655 + using nsGlobalWindow::SetBrowserDOMWindow; 1.1656 + using nsGlobalWindow::GetAttention; 1.1657 + using nsGlobalWindow::GetAttentionWithCycleCount; 1.1658 + using nsGlobalWindow::SetCursor; 1.1659 + using nsGlobalWindow::Maximize; 1.1660 + using nsGlobalWindow::Minimize; 1.1661 + using nsGlobalWindow::Restore; 1.1662 + using nsGlobalWindow::NotifyDefaultButtonLoaded; 1.1663 + using nsGlobalWindow::GetMessageManager; 1.1664 + using nsGlobalWindow::BeginWindowMove; 1.1665 + 1.1666 + nsCOMPtr<nsIBrowserDOMWindow> mBrowserDOMWindow; 1.1667 + nsCOMPtr<nsIMessageBroadcaster> mMessageManager; 1.1668 +}; 1.1669 + 1.1670 +/* 1.1671 + * nsGlobalModalWindow inherits from nsGlobalWindow. It is the global 1.1672 + * object created for a modal content windows only (i.e. not modal 1.1673 + * chrome dialogs). 1.1674 + */ 1.1675 +class nsGlobalModalWindow : public nsGlobalWindow, 1.1676 + public nsIDOMModalContentWindow 1.1677 +{ 1.1678 +public: 1.1679 + nsGlobalModalWindow(nsGlobalWindow *aOuterWindow) 1.1680 + : nsGlobalWindow(aOuterWindow) 1.1681 + { 1.1682 + mIsModalContentWindow = true; 1.1683 + } 1.1684 + 1.1685 + NS_DECL_ISUPPORTS_INHERITED 1.1686 + NS_DECL_NSIDOMMODALCONTENTWINDOW 1.1687 +}; 1.1688 + 1.1689 +/* factory function */ 1.1690 +inline already_AddRefed<nsGlobalWindow> 1.1691 +NS_NewScriptGlobalObject(bool aIsChrome, bool aIsModalContentWindow) 1.1692 +{ 1.1693 + nsRefPtr<nsGlobalWindow> global; 1.1694 + 1.1695 + if (aIsChrome) { 1.1696 + global = new nsGlobalChromeWindow(nullptr); 1.1697 + } else if (aIsModalContentWindow) { 1.1698 + global = new nsGlobalModalWindow(nullptr); 1.1699 + } else { 1.1700 + global = new nsGlobalWindow(nullptr); 1.1701 + } 1.1702 + 1.1703 + return global.forget(); 1.1704 +} 1.1705 + 1.1706 +#endif /* nsGlobalWindow_h___ */