Line data Source code
1 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 : /* This Source Code Form is subject to the terms of the Mozilla Public
4 : * License, v. 2.0. If a copy of the MPL was not distributed with this
5 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 :
7 : #ifndef nsGlobalWindow_h___
8 : #define nsGlobalWindow_h___
9 :
10 : #include "nsPIDOMWindow.h"
11 :
12 : #include "nsTHashtable.h"
13 : #include "nsHashKeys.h"
14 : #include "nsRefPtrHashtable.h"
15 : #include "nsInterfaceHashtable.h"
16 :
17 : // Local Includes
18 : // Helper Classes
19 : #include "nsCOMPtr.h"
20 : #include "nsAutoPtr.h"
21 : #include "nsWeakReference.h"
22 : #include "nsDataHashtable.h"
23 : #include "nsJSThingHashtable.h"
24 : #include "nsCycleCollectionParticipant.h"
25 :
26 : // Interfaces Needed
27 : #include "nsIBrowserDOMWindow.h"
28 : #include "nsIDOMEventTarget.h"
29 : #include "nsIInterfaceRequestor.h"
30 : #include "nsIDOMChromeWindow.h"
31 : #include "nsIScriptGlobalObject.h"
32 : #include "nsIScriptObjectPrincipal.h"
33 : #include "nsITimer.h"
34 : #include "nsIDOMModalContentWindow.h"
35 : #include "mozilla/EventListenerManager.h"
36 : #include "nsIPrincipal.h"
37 : #include "nsSize.h"
38 : #include "mozilla/FlushType.h"
39 : #include "prclist.h"
40 : #include "mozilla/dom/BindingDeclarations.h"
41 : #include "mozilla/dom/StorageEvent.h"
42 : #include "mozilla/dom/StorageEventBinding.h"
43 : #include "mozilla/dom/UnionTypes.h"
44 : #include "mozilla/ErrorResult.h"
45 : #include "nsFrameMessageManager.h"
46 : #include "mozilla/Attributes.h"
47 : #include "mozilla/GuardObjects.h"
48 : #include "mozilla/LinkedList.h"
49 : #include "mozilla/TimeStamp.h"
50 : #include "nsWrapperCacheInlines.h"
51 : #include "nsIIdleObserver.h"
52 : #include "nsIDocument.h"
53 : #include "mozilla/dom/EventTarget.h"
54 : #include "mozilla/dom/WindowBinding.h"
55 : #include "Units.h"
56 : #include "nsComponentManagerUtils.h"
57 : #include "nsSize.h"
58 : #include "nsCheapSets.h"
59 : #include "mozilla/dom/ImageBitmapSource.h"
60 : #include "mozilla/UniquePtr.h"
61 :
62 : #define DEFAULT_HOME_PAGE "www.mozilla.org"
63 : #define PREF_BROWSER_STARTUP_HOMEPAGE "browser.startup.homepage"
64 :
65 : // Amount of time allowed between alert/prompt/confirm before enabling
66 : // the stop dialog checkbox.
67 : #define DEFAULT_SUCCESSIVE_DIALOG_TIME_LIMIT 3 // 3 sec
68 :
69 : // Maximum number of successive dialogs before we prompt users to disable
70 : // dialogs for this window.
71 : #define MAX_SUCCESSIVE_DIALOG_COUNT 5
72 :
73 : // Idle fuzz time upper limit
74 : #define MAX_IDLE_FUZZ_TIME_MS 90000
75 :
76 : // Min idle notification time in seconds.
77 : #define MIN_IDLE_NOTIFICATION_TIME_S 1
78 :
79 : class nsIArray;
80 : class nsIBaseWindow;
81 : class nsIContent;
82 : class nsICSSDeclaration;
83 : class nsIDocShellTreeOwner;
84 : class nsIDOMOfflineResourceList;
85 : class nsIScrollableFrame;
86 : class nsIControllers;
87 : class nsIJSID;
88 : class nsIScriptContext;
89 : class nsIScriptTimeoutHandler;
90 : class nsITabChild;
91 : class nsITimeoutHandler;
92 : class nsIWebBrowserChrome;
93 : class mozIDOMWindowProxy;
94 :
95 : class nsDOMWindowList;
96 : class nsScreen;
97 : class nsHistory;
98 : class nsGlobalWindowObserver;
99 : class nsGlobalWindow;
100 : class nsDOMWindowUtils;
101 : class nsIIdleService;
102 : struct nsRect;
103 :
104 : class nsWindowSizes;
105 :
106 : class IdleRequestExecutor;
107 :
108 : namespace mozilla {
109 : class AbstractThread;
110 : class DOMEventTargetHelper;
111 : class ThrottledEventQueue;
112 : namespace dom {
113 : class BarProp;
114 : struct ChannelPixelLayout;
115 : class Console;
116 : class Crypto;
117 : class CustomElementRegistry;
118 : class DocGroup;
119 : class External;
120 : class Function;
121 : class Gamepad;
122 : enum class ImageBitmapFormat : uint8_t;
123 : class IdleRequest;
124 : class IdleRequestCallback;
125 : class IncrementalRunnable;
126 : #ifdef ENABLE_INTL_API
127 : class IntlUtils;
128 : #endif
129 : class Location;
130 : class MediaQueryList;
131 : class MozSelfSupport;
132 : class Navigator;
133 : class OwningExternalOrWindowProxy;
134 : class Promise;
135 : class PostMessageEvent;
136 : struct RequestInit;
137 : class RequestOrUSVString;
138 : class Selection;
139 : class SpeechSynthesis;
140 : class TabGroup;
141 : class Timeout;
142 : class U2F;
143 : class VRDisplay;
144 : enum class VRDisplayEventReason : uint8_t;
145 : class VREventObserver;
146 : class WakeLock;
147 : #if defined(MOZ_WIDGET_ANDROID) || defined(MOZ_WIDGET_GONK)
148 : class WindowOrientationObserver;
149 : #endif
150 : class Worklet;
151 : namespace cache {
152 : class CacheStorage;
153 : } // namespace cache
154 : class IDBFactory;
155 : } // namespace dom
156 : } // namespace mozilla
157 :
158 : extern already_AddRefed<nsIScriptTimeoutHandler>
159 : NS_CreateJSTimeoutHandler(JSContext* aCx, nsGlobalWindow *aWindow,
160 : mozilla::dom::Function& aFunction,
161 : const mozilla::dom::Sequence<JS::Value>& aArguments,
162 : mozilla::ErrorResult& aError);
163 :
164 : extern already_AddRefed<nsIScriptTimeoutHandler>
165 : NS_CreateJSTimeoutHandler(JSContext* aCx, nsGlobalWindow *aWindow,
166 : const nsAString& aExpression,
167 : mozilla::ErrorResult& aError);
168 :
169 : extern const js::Class OuterWindowProxyClass;
170 :
171 : struct IdleObserverHolder
172 : {
173 : nsCOMPtr<nsIIdleObserver> mIdleObserver;
174 : uint32_t mTimeInS;
175 : bool mPrevNotificationIdle;
176 :
177 0 : IdleObserverHolder()
178 0 : : mTimeInS(0), mPrevNotificationIdle(false)
179 : {
180 0 : MOZ_COUNT_CTOR(IdleObserverHolder);
181 0 : }
182 :
183 0 : IdleObserverHolder(const IdleObserverHolder& aOther)
184 0 : : mIdleObserver(aOther.mIdleObserver), mTimeInS(aOther.mTimeInS),
185 0 : mPrevNotificationIdle(aOther.mPrevNotificationIdle)
186 : {
187 0 : MOZ_COUNT_CTOR(IdleObserverHolder);
188 0 : }
189 :
190 : bool operator==(const IdleObserverHolder& aOther) const {
191 : return
192 : mIdleObserver == aOther.mIdleObserver &&
193 : mTimeInS == aOther.mTimeInS;
194 : }
195 :
196 0 : ~IdleObserverHolder()
197 0 : {
198 0 : MOZ_COUNT_DTOR(IdleObserverHolder);
199 0 : }
200 : };
201 :
202 : // Helper class to manage modal dialog arguments and all their quirks.
203 : //
204 : // Given our clunky embedding APIs, modal dialog arguments need to be passed
205 : // as an nsISupports parameter to WindowWatcher, get stuck inside an array of
206 : // length 1, and then passed back to the newly-created dialog.
207 : //
208 : // However, we need to track both the caller-passed value as well as the
209 : // caller's, so that we can do an origin check (even for primitives) when the
210 : // value is accessed. This class encapsulates that magic.
211 : //
212 : // We also use the same machinery for |returnValue|, which needs similar origin
213 : // checks.
214 : class DialogValueHolder final : public nsISupports
215 : {
216 : public:
217 : NS_DECL_CYCLE_COLLECTING_ISUPPORTS
218 2 : NS_DECL_CYCLE_COLLECTION_CLASS(DialogValueHolder)
219 :
220 0 : DialogValueHolder(nsIPrincipal* aSubject, nsIVariant* aValue)
221 0 : : mOrigin(aSubject)
222 0 : , mValue(aValue) {}
223 : nsresult Get(nsIPrincipal* aSubject, nsIVariant** aResult);
224 : void Get(JSContext* aCx, JS::Handle<JSObject*> aScope, nsIPrincipal* aSubject,
225 : JS::MutableHandle<JS::Value> aResult, mozilla::ErrorResult& aError);
226 : private:
227 0 : virtual ~DialogValueHolder() {}
228 :
229 : nsCOMPtr<nsIPrincipal> mOrigin;
230 : nsCOMPtr<nsIVariant> mValue;
231 : };
232 :
233 : //*****************************************************************************
234 : // nsGlobalWindow: Global Object for Scripting
235 : //*****************************************************************************
236 : // Beware that all scriptable interfaces implemented by
237 : // nsGlobalWindow will be reachable from JS, if you make this class
238 : // implement new interfaces you better know what you're
239 : // doing. Security wise this is very sensitive code. --
240 : // jst@netscape.com
241 :
242 : // nsGlobalWindow inherits PRCList for maintaining a list of all inner
243 : // windows still in memory for any given outer window. This list is
244 : // needed to ensure that mOuterWindow doesn't end up dangling. The
245 : // nature of PRCList means that the window itself is always in the
246 : // list, and an outer window's list will also contain all inner window
247 : // objects that are still in memory (and in reality all inner window
248 : // object's lists also contain its outer and all other inner windows
249 : // belonging to the same outer window, but that's an unimportant
250 : // side effect of inheriting PRCList).
251 :
252 : // NB: Currently nsPIDOMWindowInner and nsPIDOMWindowOuter are identical classes
253 : // with identical member variables and identical vtables, that only differ in
254 : // type name. nsGlobalWindow doesn't want to doubly inherit (and have two
255 : // copies of everything), and it also doesn't want to privilege one over
256 : // the other by making it possible to convert types through the C++ type system
257 : // instead of our accessor methods (AsInner and AsOuter) that do dynamic
258 : // checking. So we inherit from nsPIDOMWindow<nsISupports>, which is also
259 : // identical to both nsPIDOMWindowInner and nsPIDOMWindowOuter, but not
260 : // convertible to either.
261 :
262 : class nsGlobalWindow : public mozilla::dom::EventTarget,
263 : public nsPIDOMWindow<nsISupports>,
264 : private nsIDOMWindowInternal,
265 : public nsIScriptGlobalObject,
266 : public nsIScriptObjectPrincipal,
267 : public nsSupportsWeakReference,
268 : public nsIInterfaceRequestor,
269 : public PRCListStr
270 : {
271 : public:
272 : typedef mozilla::TimeStamp TimeStamp;
273 : typedef mozilla::TimeDuration TimeDuration;
274 : typedef nsDataHashtable<nsUint64HashKey, nsGlobalWindow*> WindowByIdTable;
275 :
276 : static void
277 : AssertIsOnMainThread()
278 : #ifdef DEBUG
279 : ;
280 : #else
281 : { }
282 : #endif
283 :
284 358 : static nsGlobalWindow* Cast(nsPIDOMWindowInner* aPIWin) {
285 358 : return static_cast<nsGlobalWindow*>(
286 358 : reinterpret_cast<nsPIDOMWindow<nsISupports>*>(aPIWin));
287 : }
288 0 : static const nsGlobalWindow* Cast(const nsPIDOMWindowInner* aPIWin) {
289 0 : return static_cast<const nsGlobalWindow*>(
290 0 : reinterpret_cast<const nsPIDOMWindow<nsISupports>*>(aPIWin));
291 : }
292 0 : static nsGlobalWindow* Cast(mozIDOMWindow* aWin) {
293 0 : return Cast(nsPIDOMWindowInner::From(aWin));
294 : }
295 2267 : static nsGlobalWindow* Cast(nsPIDOMWindowOuter* aPIWin) {
296 2267 : return static_cast<nsGlobalWindow*>(
297 2267 : reinterpret_cast<nsPIDOMWindow<nsISupports>*>(aPIWin));
298 : }
299 0 : static const nsGlobalWindow* Cast(const nsPIDOMWindowOuter* aPIWin) {
300 0 : return static_cast<const nsGlobalWindow*>(
301 0 : reinterpret_cast<const nsPIDOMWindow<nsISupports>*>(aPIWin));
302 : }
303 0 : static nsGlobalWindow* Cast(mozIDOMWindowProxy* aWin) {
304 0 : return Cast(nsPIDOMWindowOuter::From(aWin));
305 : }
306 :
307 : // public methods
308 : nsPIDOMWindowOuter* GetPrivateParent();
309 :
310 : // callback for close event
311 : void ReallyCloseWindow();
312 :
313 : // nsISupports
314 : NS_DECL_CYCLE_COLLECTING_ISUPPORTS
315 :
316 : // nsWrapperCache
317 2 : virtual JSObject *WrapObject(JSContext *cx, JS::Handle<JSObject*> aGivenProto) override
318 : {
319 2 : return IsInnerWindow() || AsOuter()->EnsureInnerWindow() ? GetWrapper() : nullptr;
320 : }
321 :
322 : // nsIGlobalJSObjectHolder
323 : virtual JSObject* GetGlobalJSObject() override;
324 :
325 : // nsIScriptGlobalObject
326 9604 : JSObject *FastGetGlobalJSObject() const
327 : {
328 9604 : return GetWrapperPreserveColor();
329 : }
330 :
331 : void TraceGlobalJSObject(JSTracer* aTrc);
332 :
333 : virtual nsresult EnsureScriptEnvironment() override;
334 :
335 : virtual nsIScriptContext *GetScriptContext() override;
336 :
337 : void PoisonOuterWindowProxy(JSObject *aObject);
338 :
339 : virtual bool IsBlackForCC(bool aTracingNeeded = true) override;
340 :
341 : // nsIScriptObjectPrincipal
342 : virtual nsIPrincipal* GetPrincipal() override;
343 :
344 : // nsIDOMWindow
345 : NS_DECL_NSIDOMWINDOW
346 :
347 : nsresult
348 : OpenJS(const nsAString& aUrl, const nsAString& aName,
349 : const nsAString& aOptions, nsPIDOMWindowOuter **_retval);
350 : void CaptureEvents();
351 : void ReleaseEvents();
352 : void Dump(const nsAString& aStr);
353 : void SetResizable(bool aResizable) const;
354 :
355 : // nsIDOMEventTarget
356 : NS_DECL_NSIDOMEVENTTARGET
357 :
358 : virtual mozilla::EventListenerManager*
359 : GetExistingListenerManager() const override;
360 :
361 : virtual mozilla::EventListenerManager*
362 : GetOrCreateListenerManager() override;
363 :
364 : using mozilla::dom::EventTarget::RemoveEventListener;
365 : virtual void AddEventListener(const nsAString& aType,
366 : mozilla::dom::EventListener* aListener,
367 : const mozilla::dom::AddEventListenerOptionsOrBoolean& aOptions,
368 : const mozilla::dom::Nullable<bool>& aWantsUntrusted,
369 : mozilla::ErrorResult& aRv) override;
370 : virtual nsPIDOMWindowOuter* GetOwnerGlobalForBindings() override;
371 :
372 0 : virtual nsIGlobalObject* GetOwnerGlobal() const override
373 : {
374 0 : if (IsOuterWindow()) {
375 0 : return GetCurrentInnerWindowInternal();
376 : }
377 :
378 0 : return const_cast<nsGlobalWindow*>(this);
379 : }
380 :
381 : // nsPIDOMWindow
382 : virtual nsPIDOMWindowOuter* GetPrivateRoot() override;
383 :
384 : // Outer windows only.
385 : virtual void ActivateOrDeactivate(bool aActivate) override;
386 : virtual void SetActive(bool aActive) override;
387 : virtual bool IsTopLevelWindowActive() override;
388 : virtual void SetIsBackground(bool aIsBackground) override;
389 : virtual void SetChromeEventHandler(mozilla::dom::EventTarget* aChromeEventHandler) override;
390 :
391 : // Outer windows only.
392 : virtual void SetInitialPrincipalToSubject() override;
393 :
394 : virtual PopupControlState PushPopupControlState(PopupControlState state, bool aForce) const override;
395 : virtual void PopPopupControlState(PopupControlState state) const override;
396 : virtual PopupControlState GetPopupControlState() const override;
397 :
398 : virtual already_AddRefed<nsISupports> SaveWindowState() override;
399 : virtual nsresult RestoreWindowState(nsISupports *aState) override;
400 :
401 : void Suspend();
402 : void Resume();
403 : virtual bool IsSuspended() const override;
404 : void Freeze();
405 : void Thaw();
406 : virtual bool IsFrozen() const override;
407 : void SyncStateFromParentWindow();
408 :
409 : virtual nsresult FireDelayedDOMEvents() override;
410 :
411 : // Outer windows only.
412 : virtual bool WouldReuseInnerWindow(nsIDocument* aNewDocument) override;
413 :
414 : virtual void SetDocShell(nsIDocShell* aDocShell) override;
415 : virtual void DetachFromDocShell() override;
416 : virtual nsresult SetNewDocument(nsIDocument *aDocument,
417 : nsISupports *aState,
418 : bool aForceReuseInnerWindow) override;
419 :
420 : // Outer windows only.
421 : void DispatchDOMWindowCreated();
422 :
423 : virtual void SetOpenerWindow(nsPIDOMWindowOuter* aOpener,
424 : bool aOriginalOpener) override;
425 :
426 : // Outer windows only.
427 : virtual void EnsureSizeAndPositionUpToDate() override;
428 :
429 : virtual void EnterModalState() override;
430 : virtual void LeaveModalState() override;
431 :
432 : // Outer windows only.
433 : virtual bool CanClose() override;
434 : virtual void ForceClose() override;
435 :
436 : virtual void MaybeUpdateTouchState() override;
437 :
438 : // Outer windows only.
439 : virtual bool DispatchCustomEvent(const nsAString& aEventName) override;
440 : bool DispatchResizeEvent(const mozilla::CSSIntSize& aSize);
441 :
442 : // Inner windows only.
443 : void RefreshCompartmentPrincipal();
444 :
445 : // For accessing protected field mFullScreen
446 : friend class FullscreenTransitionTask;
447 :
448 : // Outer windows only.
449 : virtual nsresult SetFullscreenInternal(
450 : FullscreenReason aReason, bool aIsFullscreen) override final;
451 : virtual void FinishFullscreenChange(bool aIsFullscreen) override final;
452 : bool SetWidgetFullscreen(FullscreenReason aReason, bool aIsFullscreen,
453 : nsIWidget* aWidget, nsIScreen* aScreen);
454 : bool FullScreen() const;
455 :
456 : // Inner windows only.
457 : virtual void SetHasGamepadEventListener(bool aHasGamepad = true) override;
458 : void NotifyVREventListenerAdded();
459 : bool HasUsedVR() const;
460 : bool IsVRContentDetected() const;
461 : bool IsVRContentPresenting() const;
462 :
463 : using EventTarget::EventListenerAdded;
464 : virtual void EventListenerAdded(nsIAtom* aType) override;
465 : using EventTarget::EventListenerRemoved;
466 : virtual void EventListenerRemoved(nsIAtom* aType) override;
467 :
468 : // nsIInterfaceRequestor
469 : NS_DECL_NSIINTERFACEREQUESTOR
470 :
471 : // WebIDL interface.
472 : already_AddRefed<nsPIDOMWindowOuter> IndexedGetterOuter(uint32_t aIndex);
473 : already_AddRefed<nsPIDOMWindowOuter> IndexedGetter(uint32_t aIndex);
474 :
475 : static bool IsPrivilegedChromeWindow(JSContext* /* unused */, JSObject* aObj);
476 :
477 : static bool IsShowModalDialogEnabled(JSContext* /* unused */ = nullptr,
478 : JSObject* /* unused */ = nullptr);
479 :
480 : static bool IsRequestIdleCallbackEnabled(JSContext* aCx, JSObject* /* unused */);
481 :
482 : bool DoResolve(JSContext* aCx, JS::Handle<JSObject*> aObj,
483 : JS::Handle<jsid> aId,
484 : JS::MutableHandle<JS::PropertyDescriptor> aDesc);
485 : // The return value is whether DoResolve might end up resolving the given id.
486 : // If in doubt, return true.
487 : static bool MayResolve(jsid aId);
488 :
489 : void GetOwnPropertyNames(JSContext* aCx, JS::AutoIdVector& aNames,
490 : bool aEnumerableOnly, mozilla::ErrorResult& aRv);
491 :
492 : // Object Management
493 : static already_AddRefed<nsGlobalWindow> Create(nsGlobalWindow *aOuterWindow);
494 :
495 4 : static nsGlobalWindow *FromSupports(nsISupports *supports)
496 : {
497 : // Make sure this matches the casts we do in QueryInterface().
498 4 : return (nsGlobalWindow *)(mozilla::dom::EventTarget *)supports;
499 : }
500 : static nsGlobalWindow *FromWrapper(nsIXPConnectWrappedNative *wrapper)
501 : {
502 : return FromSupports(wrapper->Native());
503 : }
504 : already_AddRefed<nsPIDOMWindowOuter> GetTop() override;
505 : nsPIDOMWindowOuter* GetScriptableTop() override;
506 7 : inline nsGlobalWindow *GetTopInternal()
507 : {
508 7 : nsGlobalWindow* outer = IsOuterWindow() ? this : GetOuterWindowInternal();
509 14 : nsCOMPtr<nsPIDOMWindowOuter> top = outer ? outer->GetTop() : nullptr;
510 7 : if (top) {
511 7 : return nsGlobalWindow::Cast(top);
512 : }
513 0 : return nullptr;
514 : }
515 :
516 31 : inline nsGlobalWindow* GetScriptableTopInternal()
517 : {
518 31 : nsPIDOMWindowOuter* top = GetScriptableTop();
519 31 : return nsGlobalWindow::Cast(top);
520 : }
521 :
522 : nsPIDOMWindowOuter* GetChildWindow(const nsAString& aName);
523 :
524 : // These return true if we've reached the state in this top level window
525 : // where we ask the user if further dialogs should be blocked.
526 : //
527 : // DialogsAreBeingAbused must be called on the scriptable top inner window.
528 : //
529 : // ShouldPromptToBlockDialogs is implemented in terms of
530 : // DialogsAreBeingAbused, and will get the scriptable top inner window
531 : // automatically.
532 : // Outer windows only.
533 : bool ShouldPromptToBlockDialogs();
534 : // Inner windows only.
535 : bool DialogsAreBeingAbused();
536 :
537 : // These functions are used for controlling and determining whether dialogs
538 : // (alert, prompt, confirm) are currently allowed in this window. If you want
539 : // to temporarily disable dialogs, please use TemporarilyDisableDialogs, not
540 : // EnableDialogs/DisableDialogs, because correctly determining whether to
541 : // re-enable dialogs is actually quite difficult.
542 : void EnableDialogs();
543 : void DisableDialogs();
544 : // Outer windows only.
545 : bool AreDialogsEnabled();
546 :
547 : class MOZ_RAII TemporarilyDisableDialogs
548 : {
549 : public:
550 : // Takes an inner _or_ outer window.
551 : explicit TemporarilyDisableDialogs(nsGlobalWindow* aWindow
552 : MOZ_GUARD_OBJECT_NOTIFIER_PARAM);
553 : ~TemporarilyDisableDialogs();
554 :
555 : private:
556 : MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
557 :
558 : // Always an inner window; this is the window whose dialog state we messed
559 : // with. We just want to keep it alive, because we plan to poke at its
560 : // members in our destructor.
561 : RefPtr<nsGlobalWindow> mTopWindow;
562 : // This is not a AutoRestore<bool> because that would require careful
563 : // member destructor ordering, which is a bit fragile. This way we can
564 : // explicitly restore things before we drop our ref to mTopWindow.
565 : bool mSavedDialogsEnabled;
566 : };
567 : friend class TemporarilyDisableDialogs;
568 :
569 29 : nsIScriptContext *GetContextInternal()
570 : {
571 29 : if (mOuterWindow) {
572 29 : return GetOuterWindowInternal()->mContext;
573 : }
574 :
575 0 : return mContext;
576 : }
577 :
578 1842 : nsGlobalWindow *GetOuterWindowInternal()
579 : {
580 1842 : return nsGlobalWindow::Cast(GetOuterWindow());
581 : }
582 :
583 313 : nsGlobalWindow* GetCurrentInnerWindowInternal() const
584 : {
585 313 : MOZ_ASSERT(IsOuterWindow());
586 313 : return nsGlobalWindow::Cast(mInnerWindow);
587 : }
588 :
589 : nsGlobalWindow* EnsureInnerWindowInternal()
590 : {
591 : return nsGlobalWindow::Cast(AsOuter()->EnsureInnerWindow());
592 : }
593 :
594 : bool IsCreatingInnerWindow() const
595 : {
596 : return mCreatingInnerWindow;
597 : }
598 :
599 154 : bool IsChromeWindow() const
600 : {
601 154 : return mIsChrome;
602 : }
603 :
604 : using nsPIDOMWindow::IsModalContentWindow;
605 : static bool IsModalContentWindow(JSContext* aCx, JSObject* aGlobal);
606 :
607 : // GetScrollFrame does not flush. Callers should do it themselves as needed,
608 : // depending on which info they actually want off the scrollable frame.
609 : nsIScrollableFrame *GetScrollFrame();
610 :
611 : nsresult Observe(nsISupports* aSubject, const char* aTopic,
612 : const char16_t* aData);
613 :
614 : void ObserveStorageNotification(mozilla::dom::StorageEvent* aEvent,
615 : const char16_t* aStorageType,
616 : bool aPrivateBrowsing);
617 :
618 : // Outer windows only.
619 : void UnblockScriptedClosing();
620 :
621 : static void Init();
622 : static void ShutDown();
623 : static void CleanupCachedXBLHandlers(nsGlobalWindow* aWindow);
624 : static bool IsCallerChrome();
625 :
626 : friend class WindowStateHolder;
627 :
628 39561 : NS_DECL_CYCLE_COLLECTION_SKIPPABLE_SCRIPT_HOLDER_CLASS_AMBIGUOUS(nsGlobalWindow,
629 : nsIDOMEventTarget)
630 :
631 : #ifdef DEBUG
632 : // Call Unlink on this window. This may cause bad things to happen, so use
633 : // with caution.
634 : void RiskyUnlink();
635 : #endif
636 :
637 : virtual JSObject*
638 : GetCachedXBLPrototypeHandler(nsXBLPrototypeHandler* aKey) override;
639 :
640 : virtual void
641 : CacheXBLPrototypeHandler(nsXBLPrototypeHandler* aKey,
642 : JS::Handle<JSObject*> aHandler) override;
643 :
644 : virtual bool TakeFocus(bool aFocus, uint32_t aFocusMethod) override;
645 : virtual void SetReadyForFocus() override;
646 : virtual void PageHidden() override;
647 : virtual nsresult DispatchAsyncHashchange(nsIURI *aOldURI, nsIURI *aNewURI) override;
648 : virtual nsresult DispatchSyncPopState() override;
649 :
650 : // Inner windows only.
651 : virtual void EnableDeviceSensor(uint32_t aType) override;
652 : virtual void DisableDeviceSensor(uint32_t aType) override;
653 :
654 : #if defined(MOZ_WIDGET_ANDROID) || defined(MOZ_WIDGET_GONK)
655 : virtual void EnableOrientationChangeListener() override;
656 : virtual void DisableOrientationChangeListener() override;
657 : #endif
658 :
659 : virtual void EnableTimeChangeNotifications() override;
660 : virtual void DisableTimeChangeNotifications() override;
661 :
662 : #ifdef MOZ_B2G
663 : // Inner windows only.
664 : virtual void EnableNetworkEvent(mozilla::EventMessage aEventMessage) override;
665 : virtual void DisableNetworkEvent(
666 : mozilla::EventMessage aEventMessage) override;
667 : #endif // MOZ_B2G
668 :
669 : virtual nsresult SetArguments(nsIArray* aArguments) override;
670 :
671 : void MaybeForgiveSpamCount();
672 2 : bool IsClosedOrClosing() {
673 4 : return (mIsClosed ||
674 4 : mInClose ||
675 6 : mHavePendingClose ||
676 4 : mCleanedUp);
677 : }
678 :
679 : bool
680 0 : HadOriginalOpener() const
681 : {
682 0 : MOZ_ASSERT(IsOuterWindow());
683 0 : return mHadOriginalOpener;
684 : }
685 :
686 : bool
687 0 : IsTopLevelWindow()
688 : {
689 0 : MOZ_ASSERT(IsOuterWindow());
690 0 : nsPIDOMWindowOuter* parentWindow = GetScriptableTop();
691 0 : return parentWindow == this->AsOuter();
692 : }
693 :
694 : virtual void
695 : FirePopupBlockedEvent(nsIDocument* aDoc,
696 : nsIURI* aPopupURI,
697 : const nsAString& aPopupWindowName,
698 : const nsAString& aPopupWindowFeatures) override;
699 :
700 0 : virtual uint32_t GetSerial() override {
701 0 : return mSerial;
702 : }
703 :
704 1147 : static nsGlobalWindow* GetOuterWindowWithId(uint64_t aWindowID) {
705 1147 : AssertIsOnMainThread();
706 :
707 1147 : if (!sWindowsById) {
708 0 : return nullptr;
709 : }
710 :
711 1147 : nsGlobalWindow* outerWindow = sWindowsById->Get(aWindowID);
712 1147 : return outerWindow && !outerWindow->IsInnerWindow() ? outerWindow : nullptr;
713 : }
714 :
715 0 : static nsGlobalWindow* GetInnerWindowWithId(uint64_t aInnerWindowID) {
716 0 : AssertIsOnMainThread();
717 :
718 0 : if (!sWindowsById) {
719 0 : return nullptr;
720 : }
721 :
722 0 : nsGlobalWindow* innerWindow = sWindowsById->Get(aInnerWindowID);
723 0 : return innerWindow && innerWindow->IsInnerWindow() ? innerWindow : nullptr;
724 : }
725 :
726 1 : static WindowByIdTable* GetWindowsTable() {
727 1 : AssertIsOnMainThread();
728 :
729 1 : return sWindowsById;
730 : }
731 :
732 : void AddSizeOfIncludingThis(nsWindowSizes* aWindowSizes) const;
733 :
734 : // Inner windows only.
735 : void AddEventTargetObject(mozilla::DOMEventTargetHelper* aObject);
736 : void RemoveEventTargetObject(mozilla::DOMEventTargetHelper* aObject);
737 :
738 : void NotifyIdleObserver(IdleObserverHolder* aIdleObserverHolder,
739 : bool aCallOnidle);
740 : nsresult HandleIdleActiveEvent();
741 : bool ContainsIdleObserver(nsIIdleObserver* aIdleObserver, uint32_t timeInS);
742 : void HandleIdleObserverCallback();
743 :
744 0 : void AllowScriptsToClose()
745 : {
746 0 : mAllowScriptsToClose = true;
747 0 : }
748 :
749 : enum SlowScriptResponse {
750 : ContinueSlowScript = 0,
751 : ContinueSlowScriptAndKeepNotifying,
752 : AlwaysContinueSlowScript,
753 : KillSlowScript
754 : };
755 : SlowScriptResponse ShowSlowScriptDialog();
756 :
757 : // Inner windows only.
758 : void AddGamepad(uint32_t aIndex, mozilla::dom::Gamepad* aGamepad);
759 : void RemoveGamepad(uint32_t aIndex);
760 : void GetGamepads(nsTArray<RefPtr<mozilla::dom::Gamepad> >& aGamepads);
761 : already_AddRefed<mozilla::dom::Gamepad> GetGamepad(uint32_t aIndex);
762 : void SetHasSeenGamepadInput(bool aHasSeen);
763 : bool HasSeenGamepadInput();
764 : void SyncGamepadState();
765 : void StopGamepadHaptics();
766 :
767 : // Inner windows only.
768 : // Enable/disable updates for gamepad input.
769 : void EnableGamepadUpdates();
770 : void DisableGamepadUpdates();
771 :
772 : // Inner windows only.
773 : // Enable/disable updates for VR
774 : void EnableVRUpdates();
775 : void DisableVRUpdates();
776 :
777 : // Update the VR displays for this window
778 : bool UpdateVRDisplays(nsTArray<RefPtr<mozilla::dom::VRDisplay>>& aDisplays);
779 :
780 : // Inner windows only.
781 : // Called to inform that the set of active VR displays has changed.
782 : void NotifyActiveVRDisplaysChanged();
783 :
784 : // Outer windows only.
785 : uint32_t GetAutoActivateVRDisplayID();
786 : // Outer windows only.
787 : void SetAutoActivateVRDisplayID(uint32_t aAutoActivateVRDisplayID);
788 :
789 : void DispatchVRDisplayActivate(uint32_t aDisplayID,
790 : mozilla::dom::VRDisplayEventReason aReason);
791 : void DispatchVRDisplayDeactivate(uint32_t aDisplayID,
792 : mozilla::dom::VRDisplayEventReason aReason);
793 : void DispatchVRDisplayConnect(uint32_t aDisplayID);
794 : void DispatchVRDisplayDisconnect(uint32_t aDisplayID);
795 : void DispatchVRDisplayPresentChange(uint32_t aDisplayID);
796 :
797 : #define EVENT(name_, id_, type_, struct_) \
798 : mozilla::dom::EventHandlerNonNull* GetOn##name_() \
799 : { \
800 : mozilla::EventListenerManager* elm = GetExistingListenerManager(); \
801 : return elm ? elm->GetEventHandler(nsGkAtoms::on##name_, EmptyString()) \
802 : : nullptr; \
803 : } \
804 : void SetOn##name_(mozilla::dom::EventHandlerNonNull* handler) \
805 : { \
806 : mozilla::EventListenerManager* elm = GetOrCreateListenerManager(); \
807 : if (elm) { \
808 : elm->SetEventHandler(nsGkAtoms::on##name_, EmptyString(), handler); \
809 : } \
810 : }
811 : #define ERROR_EVENT(name_, id_, type_, struct_) \
812 : mozilla::dom::OnErrorEventHandlerNonNull* GetOn##name_() \
813 : { \
814 : mozilla::EventListenerManager* elm = GetExistingListenerManager(); \
815 : return elm ? elm->GetOnErrorEventHandler() : nullptr; \
816 : } \
817 : void SetOn##name_(mozilla::dom::OnErrorEventHandlerNonNull* handler) \
818 : { \
819 : mozilla::EventListenerManager* elm = GetOrCreateListenerManager(); \
820 : if (elm) { \
821 : elm->SetEventHandler(handler); \
822 : } \
823 : }
824 : #define BEFOREUNLOAD_EVENT(name_, id_, type_, struct_) \
825 : mozilla::dom::OnBeforeUnloadEventHandlerNonNull* GetOn##name_() \
826 : { \
827 : mozilla::EventListenerManager* elm = GetExistingListenerManager(); \
828 : return elm ? elm->GetOnBeforeUnloadEventHandler() : nullptr; \
829 : } \
830 : void SetOn##name_(mozilla::dom::OnBeforeUnloadEventHandlerNonNull* handler) \
831 : { \
832 : mozilla::EventListenerManager* elm = GetOrCreateListenerManager(); \
833 : if (elm) { \
834 : elm->SetEventHandler(handler); \
835 : } \
836 : }
837 : #define WINDOW_ONLY_EVENT EVENT
838 : #define TOUCH_EVENT EVENT
839 : #include "mozilla/EventNameList.h"
840 : #undef TOUCH_EVENT
841 : #undef WINDOW_ONLY_EVENT
842 : #undef BEFOREUNLOAD_EVENT
843 : #undef ERROR_EVENT
844 : #undef EVENT
845 :
846 0 : nsISupports* GetParentObject()
847 : {
848 0 : return nullptr;
849 : }
850 :
851 : static JSObject*
852 : CreateNamedPropertiesObject(JSContext *aCx, JS::Handle<JSObject*> aProto);
853 :
854 : nsGlobalWindow* Window();
855 : nsGlobalWindow* Self();
856 15 : nsIDocument* GetDocument()
857 : {
858 15 : return GetDoc();
859 : }
860 : void GetNameOuter(nsAString& aName);
861 : void GetName(nsAString& aName, mozilla::ErrorResult& aError);
862 : void SetNameOuter(const nsAString& aName, mozilla::ErrorResult& aError);
863 : void SetName(const nsAString& aName, mozilla::ErrorResult& aError);
864 : mozilla::dom::Location* GetLocation() override;
865 : nsHistory* GetHistory(mozilla::ErrorResult& aError);
866 : mozilla::dom::CustomElementRegistry* CustomElements() override;
867 : mozilla::dom::BarProp* GetLocationbar(mozilla::ErrorResult& aError);
868 : mozilla::dom::BarProp* GetMenubar(mozilla::ErrorResult& aError);
869 : mozilla::dom::BarProp* GetPersonalbar(mozilla::ErrorResult& aError);
870 : mozilla::dom::BarProp* GetScrollbars(mozilla::ErrorResult& aError);
871 : mozilla::dom::BarProp* GetStatusbar(mozilla::ErrorResult& aError);
872 : mozilla::dom::BarProp* GetToolbar(mozilla::ErrorResult& aError);
873 : void GetStatusOuter(nsAString& aStatus);
874 : void GetStatus(nsAString& aStatus, mozilla::ErrorResult& aError);
875 : void SetStatusOuter(const nsAString& aStatus);
876 : void SetStatus(const nsAString& aStatus, mozilla::ErrorResult& aError);
877 : void CloseOuter(bool aTrustedCaller);
878 : void Close(mozilla::ErrorResult& aError);
879 : nsresult Close() override;
880 : bool GetClosedOuter();
881 : bool GetClosed(mozilla::ErrorResult& aError);
882 : bool Closed() override;
883 : void StopOuter(mozilla::ErrorResult& aError);
884 : void Stop(mozilla::ErrorResult& aError);
885 : void FocusOuter(mozilla::ErrorResult& aError);
886 : void Focus(mozilla::ErrorResult& aError);
887 : nsresult Focus() override;
888 : void BlurOuter();
889 : void Blur(mozilla::ErrorResult& aError);
890 : already_AddRefed<nsPIDOMWindowOuter> GetFramesOuter();
891 : already_AddRefed<nsIDOMWindowCollection> GetFrames() override;
892 : already_AddRefed<nsPIDOMWindowOuter> GetFrames(mozilla::ErrorResult& aError);
893 : uint32_t Length();
894 : already_AddRefed<nsPIDOMWindowOuter> GetTopOuter();
895 : already_AddRefed<nsPIDOMWindowOuter> GetTop(mozilla::ErrorResult& aError);
896 :
897 : nsresult GetPrompter(nsIPrompt** aPrompt) override;
898 : protected:
899 : explicit nsGlobalWindow(nsGlobalWindow *aOuterWindow);
900 : nsPIDOMWindowOuter* GetOpenerWindowOuter();
901 : // Initializes the mWasOffline member variable
902 : void InitWasOffline();
903 : public:
904 : nsPIDOMWindowOuter*
905 : GetSanitizedOpener(nsPIDOMWindowOuter* aOpener);
906 :
907 : nsPIDOMWindowOuter* GetOpenerWindow(mozilla::ErrorResult& aError);
908 : void GetOpener(JSContext* aCx, JS::MutableHandle<JS::Value> aRetval,
909 : mozilla::ErrorResult& aError);
910 : already_AddRefed<nsPIDOMWindowOuter> GetOpener() override;
911 : void SetOpener(JSContext* aCx, JS::Handle<JS::Value> aOpener,
912 : mozilla::ErrorResult& aError);
913 : already_AddRefed<nsPIDOMWindowOuter> GetParentOuter();
914 : already_AddRefed<nsPIDOMWindowOuter> GetParent(mozilla::ErrorResult& aError);
915 : already_AddRefed<nsPIDOMWindowOuter> GetParent() override;
916 : nsPIDOMWindowOuter* GetScriptableParent() override;
917 : nsPIDOMWindowOuter* GetScriptableParentOrNull() override;
918 : mozilla::dom::Element*
919 : GetFrameElementOuter(nsIPrincipal& aSubjectPrincipal);
920 : mozilla::dom::Element*
921 : GetFrameElement(nsIPrincipal& aSubjectPrincipal,
922 : mozilla::ErrorResult& aError);
923 : already_AddRefed<nsIDOMElement> GetFrameElement() override;
924 : already_AddRefed<nsPIDOMWindowOuter>
925 : OpenOuter(const nsAString& aUrl,
926 : const nsAString& aName,
927 : const nsAString& aOptions,
928 : mozilla::ErrorResult& aError);
929 : already_AddRefed<nsPIDOMWindowOuter>
930 : Open(const nsAString& aUrl,
931 : const nsAString& aName,
932 : const nsAString& aOptions,
933 : mozilla::ErrorResult& aError);
934 : nsresult Open(const nsAString& aUrl, const nsAString& aName,
935 : const nsAString& aOptions,
936 : nsIDocShellLoadInfo* aLoadInfo,
937 : bool aForceNoOpener,
938 : nsPIDOMWindowOuter **_retval) override;
939 : mozilla::dom::Navigator* Navigator();
940 : nsIDOMNavigator* GetNavigator() override;
941 : nsIDOMOfflineResourceList* GetApplicationCache(mozilla::ErrorResult& aError);
942 : already_AddRefed<nsIDOMOfflineResourceList> GetApplicationCache() override;
943 :
944 : #if defined(MOZ_WIDGET_ANDROID) || defined(MOZ_WIDGET_GONK)
945 : int16_t Orientation(mozilla::dom::CallerType aCallerType) const;
946 : #endif
947 :
948 : mozilla::dom::Console* GetConsole(mozilla::ErrorResult& aRv);
949 :
950 : // https://w3c.github.io/webappsec-secure-contexts/#dom-window-issecurecontext
951 : bool IsSecureContext() const;
952 : bool IsSecureContextIfOpenerIgnored() const;
953 :
954 : void GetSidebar(mozilla::dom::OwningExternalOrWindowProxy& aResult,
955 : mozilla::ErrorResult& aRv);
956 : already_AddRefed<mozilla::dom::External> GetExternal(mozilla::ErrorResult& aRv);
957 :
958 : // Exposed only for testing
959 : static bool
960 : TokenizeDialogOptions(nsAString& aToken, nsAString::const_iterator& aIter,
961 : nsAString::const_iterator aEnd);
962 : static void
963 : ConvertDialogOptions(const nsAString& aOptions, nsAString& aResult);
964 :
965 : mozilla::dom::Worklet*
966 : GetAudioWorklet(mozilla::ErrorResult& aRv);
967 :
968 : mozilla::dom::Worklet*
969 : GetPaintWorklet(mozilla::ErrorResult& aRv);
970 :
971 : void
972 : GetAppLocalesAsBCP47(nsTArray<nsString>& aLocales);
973 :
974 : #ifdef ENABLE_INTL_API
975 : mozilla::dom::IntlUtils*
976 : GetIntlUtils(mozilla::ErrorResult& aRv);
977 : #endif
978 :
979 : protected:
980 : bool AlertOrConfirm(bool aAlert, const nsAString& aMessage,
981 : nsIPrincipal& aSubjectPrincipal,
982 : mozilla::ErrorResult& aError);
983 :
984 : public:
985 : void Alert(nsIPrincipal& aSubjectPrincipal,
986 : mozilla::ErrorResult& aError);
987 : void AlertOuter(const nsAString& aMessage,
988 : nsIPrincipal& aSubjectPrincipal,
989 : mozilla::ErrorResult& aError);
990 : void Alert(const nsAString& aMessage,
991 : nsIPrincipal& aSubjectPrincipal,
992 : mozilla::ErrorResult& aError);
993 : bool ConfirmOuter(const nsAString& aMessage,
994 : nsIPrincipal& aSubjectPrincipal,
995 : mozilla::ErrorResult& aError);
996 : bool Confirm(const nsAString& aMessage,
997 : nsIPrincipal& aSubjectPrincipal,
998 : mozilla::ErrorResult& aError);
999 : void PromptOuter(const nsAString& aMessage, const nsAString& aInitial,
1000 : nsAString& aReturn,
1001 : nsIPrincipal& aSubjectPrincipal,
1002 : mozilla::ErrorResult& aError);
1003 : void Prompt(const nsAString& aMessage, const nsAString& aInitial,
1004 : nsAString& aReturn,
1005 : nsIPrincipal& aSubjectPrincipal,
1006 : mozilla::ErrorResult& aError);
1007 : already_AddRefed<mozilla::dom::cache::CacheStorage> GetCaches(mozilla::ErrorResult& aRv);
1008 : already_AddRefed<mozilla::dom::Promise> Fetch(const mozilla::dom::RequestOrUSVString& aInput,
1009 : const mozilla::dom::RequestInit& aInit,
1010 : mozilla::dom::CallerType aCallerType,
1011 : mozilla::ErrorResult& aRv);
1012 : void PrintOuter(mozilla::ErrorResult& aError);
1013 : void Print(mozilla::ErrorResult& aError);
1014 : void ShowModalDialog(JSContext* aCx, const nsAString& aUrl,
1015 : JS::Handle<JS::Value> aArgument,
1016 : const nsAString& aOptions,
1017 : JS::MutableHandle<JS::Value> aRetval,
1018 : nsIPrincipal& aSubjectPrincipal,
1019 : mozilla::ErrorResult& aError);
1020 : void PostMessageMoz(JSContext* aCx, JS::Handle<JS::Value> aMessage,
1021 : const nsAString& aTargetOrigin,
1022 : const mozilla::dom::Sequence<JSObject*>& aTransfer,
1023 : nsIPrincipal& aSubjectPrincipal,
1024 : mozilla::ErrorResult& aError);
1025 : int32_t SetTimeout(JSContext* aCx, mozilla::dom::Function& aFunction,
1026 : int32_t aTimeout,
1027 : const mozilla::dom::Sequence<JS::Value>& aArguments,
1028 : mozilla::ErrorResult& aError);
1029 : int32_t SetTimeout(JSContext* aCx, const nsAString& aHandler,
1030 : int32_t aTimeout,
1031 : const mozilla::dom::Sequence<JS::Value>& /* unused */,
1032 : mozilla::ErrorResult& aError);
1033 : void ClearTimeout(int32_t aHandle);
1034 : int32_t SetInterval(JSContext* aCx, mozilla::dom::Function& aFunction,
1035 : const mozilla::dom::Optional<int32_t>& aTimeout,
1036 : const mozilla::dom::Sequence<JS::Value>& aArguments,
1037 : mozilla::ErrorResult& aError);
1038 : int32_t SetInterval(JSContext* aCx, const nsAString& aHandler,
1039 : const mozilla::dom::Optional<int32_t>& aTimeout,
1040 : const mozilla::dom::Sequence<JS::Value>& /* unused */,
1041 : mozilla::ErrorResult& aError);
1042 : void ClearInterval(int32_t aHandle);
1043 : void GetOrigin(nsAString& aOrigin);
1044 : void Atob(const nsAString& aAsciiBase64String, nsAString& aBinaryData,
1045 : mozilla::ErrorResult& aError);
1046 : void Btoa(const nsAString& aBinaryData, nsAString& aAsciiBase64String,
1047 : mozilla::ErrorResult& aError);
1048 : mozilla::dom::Storage* GetSessionStorage(mozilla::ErrorResult& aError);
1049 : mozilla::dom::Storage*
1050 : GetLocalStorage(mozilla::ErrorResult& aError);
1051 : mozilla::dom::Selection* GetSelectionOuter();
1052 : mozilla::dom::Selection* GetSelection(mozilla::ErrorResult& aError);
1053 : already_AddRefed<nsISelection> GetSelection() override;
1054 : mozilla::dom::IDBFactory* GetIndexedDB(mozilla::ErrorResult& aError);
1055 : already_AddRefed<nsICSSDeclaration>
1056 : GetComputedStyle(mozilla::dom::Element& aElt, const nsAString& aPseudoElt,
1057 : mozilla::ErrorResult& aError) override;
1058 : already_AddRefed<mozilla::dom::MediaQueryList> MatchMediaOuter(const nsAString& aQuery);
1059 : already_AddRefed<mozilla::dom::MediaQueryList> MatchMedia(const nsAString& aQuery,
1060 : mozilla::ErrorResult& aError);
1061 : nsScreen* GetScreen(mozilla::ErrorResult& aError);
1062 : nsIDOMScreen* GetScreen() override;
1063 : void MoveToOuter(int32_t aXPos, int32_t aYPos,
1064 : mozilla::dom::CallerType aCallerType,
1065 : mozilla::ErrorResult& aError);
1066 : void MoveTo(int32_t aXPos, int32_t aYPos,
1067 : mozilla::dom::CallerType aCallerType,
1068 : mozilla::ErrorResult& aError);
1069 : void MoveByOuter(int32_t aXDif, int32_t aYDif,
1070 : mozilla::dom::CallerType aCallerType,
1071 : mozilla::ErrorResult& aError);
1072 : void MoveBy(int32_t aXDif, int32_t aYDif,
1073 : mozilla::dom::CallerType aCallerType,
1074 : mozilla::ErrorResult& aError);
1075 : nsresult MoveBy(int32_t aXDif, int32_t aYDif) override;
1076 : void ResizeToOuter(int32_t aWidth, int32_t aHeight,
1077 : mozilla::dom::CallerType aCallerType,
1078 : mozilla::ErrorResult& aError);
1079 : void ResizeTo(int32_t aWidth, int32_t aHeight,
1080 : mozilla::dom::CallerType aCallerType,
1081 : mozilla::ErrorResult& aError);
1082 : void ResizeByOuter(int32_t aWidthDif, int32_t aHeightDif,
1083 : mozilla::dom::CallerType aCallerType,
1084 : mozilla::ErrorResult& aError);
1085 : void ResizeBy(int32_t aWidthDif, int32_t aHeightDif,
1086 : mozilla::dom::CallerType aCallerType,
1087 : mozilla::ErrorResult& aError);
1088 : void Scroll(double aXScroll, double aYScroll);
1089 : void Scroll(const mozilla::dom::ScrollToOptions& aOptions);
1090 : void ScrollTo(double aXScroll, double aYScroll);
1091 : void ScrollTo(const mozilla::dom::ScrollToOptions& aOptions);
1092 : void ScrollBy(double aXScrollDif, double aYScrollDif);
1093 : void ScrollBy(const mozilla::dom::ScrollToOptions& aOptions);
1094 : void ScrollByLines(int32_t numLines,
1095 : const mozilla::dom::ScrollOptions& aOptions);
1096 : void ScrollByPages(int32_t numPages,
1097 : const mozilla::dom::ScrollOptions& aOptions);
1098 : void MozScrollSnap();
1099 : void GetInnerWidth(JSContext* aCx, JS::MutableHandle<JS::Value> aValue,
1100 : mozilla::dom::CallerType aCallerType,
1101 : mozilla::ErrorResult& aError);
1102 : void SetInnerWidth(JSContext* aCx, JS::Handle<JS::Value> aValue,
1103 : mozilla::dom::CallerType aCallerType,
1104 : mozilla::ErrorResult& aError);
1105 : void GetInnerHeight(JSContext* aCx, JS::MutableHandle<JS::Value> aValue,
1106 : mozilla::dom::CallerType aCallerType,
1107 : mozilla::ErrorResult& aError);
1108 : void SetInnerHeight(JSContext* aCx, JS::Handle<JS::Value> aValue,
1109 : mozilla::dom::CallerType aCallerType,
1110 : mozilla::ErrorResult& aError);
1111 : double GetScrollXOuter();
1112 : double GetScrollX(mozilla::ErrorResult& aError);
1113 0 : double GetPageXOffset(mozilla::ErrorResult& aError)
1114 : {
1115 0 : return GetScrollX(aError);
1116 : }
1117 : double GetScrollYOuter();
1118 : double GetScrollY(mozilla::ErrorResult& aError);
1119 0 : double GetPageYOffset(mozilla::ErrorResult& aError)
1120 : {
1121 0 : return GetScrollY(aError);
1122 : }
1123 : void GetScreenX(JSContext* aCx, JS::MutableHandle<JS::Value> aValue,
1124 : mozilla::dom::CallerType aCallerType,
1125 : mozilla::ErrorResult& aError);
1126 : void SetScreenX(JSContext* aCx, JS::Handle<JS::Value> aValue,
1127 : mozilla::dom::CallerType aCallerType,
1128 : mozilla::ErrorResult& aError);
1129 : void GetScreenY(JSContext* aCx, JS::MutableHandle<JS::Value> aValue,
1130 : mozilla::dom::CallerType aCallerType,
1131 : mozilla::ErrorResult& aError);
1132 : void SetScreenY(JSContext* aCx, JS::Handle<JS::Value> aValue,
1133 : mozilla::dom::CallerType aCallerType,
1134 : mozilla::ErrorResult& aError);
1135 : void GetOuterWidth(JSContext* aCx, JS::MutableHandle<JS::Value> aValue,
1136 : mozilla::dom::CallerType aCallerType,
1137 : mozilla::ErrorResult& aError);
1138 : void SetOuterWidth(JSContext* aCx, JS::Handle<JS::Value> aValue,
1139 : mozilla::dom::CallerType aCallerType,
1140 : mozilla::ErrorResult& aError);
1141 : void GetOuterHeight(JSContext* aCx, JS::MutableHandle<JS::Value> aValue,
1142 : mozilla::dom::CallerType aCallerType,
1143 : mozilla::ErrorResult& aError);
1144 : void SetOuterHeight(JSContext* aCx, JS::Handle<JS::Value> aValue,
1145 : mozilla::dom::CallerType aCallerType,
1146 : mozilla::ErrorResult& aError);
1147 : int32_t RequestAnimationFrame(mozilla::dom::FrameRequestCallback& aCallback,
1148 : mozilla::ErrorResult& aError);
1149 : void CancelAnimationFrame(int32_t aHandle, mozilla::ErrorResult& aError);
1150 :
1151 : uint32_t RequestIdleCallback(JSContext* aCx,
1152 : mozilla::dom::IdleRequestCallback& aCallback,
1153 : const mozilla::dom::IdleRequestOptions& aOptions,
1154 : mozilla::ErrorResult& aError);
1155 : void CancelIdleCallback(uint32_t aHandle);
1156 :
1157 : #ifdef MOZ_WEBSPEECH
1158 : mozilla::dom::SpeechSynthesis*
1159 : GetSpeechSynthesis(mozilla::ErrorResult& aError);
1160 : bool HasActiveSpeechSynthesis();
1161 : #endif
1162 : already_AddRefed<nsICSSDeclaration>
1163 : GetDefaultComputedStyle(mozilla::dom::Element& aElt,
1164 : const nsAString& aPseudoElt,
1165 : mozilla::ErrorResult& aError);
1166 : void SizeToContentOuter(mozilla::dom::CallerType aCallerType,
1167 : mozilla::ErrorResult& aError);
1168 : void SizeToContent(mozilla::dom::CallerType aCallerType,
1169 : mozilla::ErrorResult& aError);
1170 : mozilla::dom::Crypto* GetCrypto(mozilla::ErrorResult& aError);
1171 : mozilla::dom::U2F* GetU2f(mozilla::ErrorResult& aError);
1172 : nsIControllers* GetControllersOuter(mozilla::ErrorResult& aError);
1173 : nsIControllers* GetControllers(mozilla::ErrorResult& aError);
1174 : nsresult GetControllers(nsIControllers** aControllers) override;
1175 : mozilla::dom::Element* GetRealFrameElementOuter();
1176 : mozilla::dom::Element* GetRealFrameElement(mozilla::ErrorResult& aError);
1177 : float GetMozInnerScreenXOuter(mozilla::dom::CallerType aCallerType);
1178 : float GetMozInnerScreenX(mozilla::dom::CallerType aCallerType,
1179 : mozilla::ErrorResult& aError);
1180 : float GetMozInnerScreenYOuter(mozilla::dom::CallerType aCallerType);
1181 : float GetMozInnerScreenY(mozilla::dom::CallerType aCallerType,
1182 : mozilla::ErrorResult& aError);
1183 : float GetDevicePixelRatioOuter(mozilla::dom::CallerType aCallerType);
1184 : float GetDevicePixelRatio(mozilla::dom::CallerType aCallerType,
1185 : mozilla::ErrorResult& aError);
1186 : int32_t GetScrollMinX(mozilla::ErrorResult& aError);
1187 : int32_t GetScrollMinY(mozilla::ErrorResult& aError);
1188 : int32_t GetScrollMaxX(mozilla::ErrorResult& aError);
1189 : int32_t GetScrollMaxY(mozilla::ErrorResult& aError);
1190 : bool GetFullScreenOuter();
1191 : bool GetFullScreen(mozilla::ErrorResult& aError);
1192 : bool GetFullScreen() override;
1193 : void SetFullScreenOuter(bool aFullScreen, mozilla::ErrorResult& aError);
1194 : void SetFullScreen(bool aFullScreen, mozilla::ErrorResult& aError);
1195 : nsresult SetFullScreen(bool aFullScreen) override;
1196 : void BackOuter(mozilla::ErrorResult& aError);
1197 : void Back(mozilla::ErrorResult& aError);
1198 : void ForwardOuter(mozilla::ErrorResult& aError);
1199 : void Forward(mozilla::ErrorResult& aError);
1200 : void HomeOuter(nsIPrincipal& aSubjectPrincipal, mozilla::ErrorResult& aError);
1201 : void Home(nsIPrincipal& aSubjectPrincipal, mozilla::ErrorResult& aError);
1202 : bool FindOuter(const nsAString& aString, bool aCaseSensitive, bool aBackwards,
1203 : bool aWrapAround, bool aWholeWord, bool aSearchInFrames,
1204 : bool aShowDialog, mozilla::ErrorResult& aError);
1205 : bool Find(const nsAString& aString, bool aCaseSensitive, bool aBackwards,
1206 : bool aWrapAround, bool aWholeWord, bool aSearchInFrames,
1207 : bool aShowDialog, mozilla::ErrorResult& aError);
1208 : uint64_t GetMozPaintCountOuter();
1209 : uint64_t GetMozPaintCount(mozilla::ErrorResult& aError);
1210 :
1211 : bool ShouldResistFingerprinting();
1212 :
1213 : mozilla::dom::MozSelfSupport* GetMozSelfSupport(mozilla::ErrorResult& aError);
1214 :
1215 : already_AddRefed<nsPIDOMWindowOuter>
1216 : OpenDialogOuter(JSContext* aCx,
1217 : const nsAString& aUrl,
1218 : const nsAString& aName,
1219 : const nsAString& aOptions,
1220 : const mozilla::dom::Sequence<JS::Value>& aExtraArgument,
1221 : mozilla::ErrorResult& aError);
1222 : already_AddRefed<nsPIDOMWindowOuter>
1223 : OpenDialog(JSContext* aCx,
1224 : const nsAString& aUrl,
1225 : const nsAString& aName,
1226 : const nsAString& aOptions,
1227 : const mozilla::dom::Sequence<JS::Value>& aExtraArgument,
1228 : mozilla::ErrorResult& aError);
1229 : nsresult OpenDialog(const nsAString& aUrl, const nsAString& aName,
1230 : const nsAString& aOptions,
1231 : nsISupports* aExtraArgument,
1232 : nsPIDOMWindowOuter** _retval) override;
1233 : nsresult UpdateCommands(const nsAString& anAction, nsISelection* aSel, int16_t aReason) override;
1234 :
1235 : already_AddRefed<nsPIDOMWindowOuter>
1236 : GetContentInternal(mozilla::ErrorResult& aError,
1237 : mozilla::dom::CallerType aCallerType);
1238 : void GetContentOuter(JSContext* aCx,
1239 : JS::MutableHandle<JSObject*> aRetval,
1240 : mozilla::dom::CallerType aCallerType,
1241 : mozilla::ErrorResult& aError);
1242 : void GetContent(JSContext* aCx,
1243 : JS::MutableHandle<JSObject*> aRetval,
1244 : mozilla::dom::CallerType aCallerType,
1245 : mozilla::ErrorResult& aError);
1246 0 : already_AddRefed<nsPIDOMWindowOuter> GetContent()
1247 : {
1248 0 : MOZ_ASSERT(IsOuterWindow());
1249 0 : mozilla::IgnoredErrorResult ignored;
1250 : nsCOMPtr<nsPIDOMWindowOuter> win =
1251 0 : GetContentInternal(ignored, mozilla::dom::CallerType::System);
1252 0 : return win.forget();
1253 : }
1254 :
1255 0 : void Get_content(JSContext* aCx,
1256 : JS::MutableHandle<JSObject*> aRetval,
1257 : mozilla::dom::SystemCallerGuarantee aCallerType,
1258 : mozilla::ErrorResult& aError)
1259 : {
1260 0 : if (mDoc) {
1261 0 : mDoc->WarnOnceAbout(nsIDocument::eWindow_Content);
1262 : }
1263 0 : GetContent(aCx, aRetval, aCallerType, aError);
1264 0 : }
1265 :
1266 : already_AddRefed<mozilla::dom::Promise>
1267 : CreateImageBitmap(JSContext* aCx,
1268 : const mozilla::dom::ImageBitmapSource& aImage,
1269 : mozilla::ErrorResult& aRv);
1270 :
1271 : already_AddRefed<mozilla::dom::Promise>
1272 : CreateImageBitmap(JSContext* aCx,
1273 : const mozilla::dom::ImageBitmapSource& aImage,
1274 : int32_t aSx, int32_t aSy, int32_t aSw, int32_t aSh,
1275 : mozilla::ErrorResult& aRv);
1276 :
1277 : already_AddRefed<mozilla::dom::Promise>
1278 : CreateImageBitmap(JSContext* aCx,
1279 : const mozilla::dom::ImageBitmapSource& aImage,
1280 : int32_t aOffset, int32_t aLength,
1281 : mozilla::dom::ImageBitmapFormat aFormat,
1282 : const mozilla::dom::Sequence<mozilla::dom::ChannelPixelLayout>& aLayout,
1283 : mozilla::ErrorResult& aRv);
1284 :
1285 :
1286 : // ChromeWindow bits. Do NOT call these unless your window is in
1287 : // fact an nsGlobalChromeWindow.
1288 : uint16_t WindowState();
1289 : bool IsFullyOccluded();
1290 : nsIBrowserDOMWindow* GetBrowserDOMWindowOuter();
1291 : nsIBrowserDOMWindow* GetBrowserDOMWindow(mozilla::ErrorResult& aError);
1292 : void SetBrowserDOMWindowOuter(nsIBrowserDOMWindow* aBrowserWindow);
1293 : void SetBrowserDOMWindow(nsIBrowserDOMWindow* aBrowserWindow,
1294 : mozilla::ErrorResult& aError);
1295 : void GetAttention(mozilla::ErrorResult& aError);
1296 : void GetAttentionWithCycleCount(int32_t aCycleCount,
1297 : mozilla::ErrorResult& aError);
1298 : void SetCursorOuter(const nsAString& aCursor, mozilla::ErrorResult& aError);
1299 : void SetCursor(const nsAString& aCursor, mozilla::ErrorResult& aError);
1300 : void Maximize();
1301 : void Minimize();
1302 : void Restore();
1303 : void NotifyDefaultButtonLoaded(mozilla::dom::Element& aDefaultButton,
1304 : mozilla::ErrorResult& aError);
1305 : nsIMessageBroadcaster* GetMessageManager(mozilla::ErrorResult& aError);
1306 : nsIMessageBroadcaster* GetGroupMessageManager(const nsAString& aGroup,
1307 : mozilla::ErrorResult& aError);
1308 : void BeginWindowMove(mozilla::dom::Event& aMouseDownEvent,
1309 : mozilla::dom::Element* aPanel,
1310 : mozilla::ErrorResult& aError);
1311 :
1312 : void GetDialogArgumentsOuter(JSContext* aCx, JS::MutableHandle<JS::Value> aRetval,
1313 : nsIPrincipal& aSubjectPrincipal,
1314 : mozilla::ErrorResult& aError);
1315 : void GetDialogArguments(JSContext* aCx, JS::MutableHandle<JS::Value> aRetval,
1316 : nsIPrincipal& aSubjectPrincipal,
1317 : mozilla::ErrorResult& aError);
1318 : void GetReturnValueOuter(JSContext* aCx, JS::MutableHandle<JS::Value> aReturnValue,
1319 : nsIPrincipal& aSubjectPrincipal,
1320 : mozilla::ErrorResult& aError);
1321 : void GetReturnValue(JSContext* aCx, JS::MutableHandle<JS::Value> aReturnValue,
1322 : nsIPrincipal& aSubjectPrincipal,
1323 : mozilla::ErrorResult& aError);
1324 : void SetReturnValueOuter(JSContext* aCx, JS::Handle<JS::Value> aReturnValue,
1325 : nsIPrincipal& aSubjectPrincipal,
1326 : mozilla::ErrorResult& aError);
1327 : void SetReturnValue(JSContext* aCx, JS::Handle<JS::Value> aReturnValue,
1328 : nsIPrincipal& aSubjectPrincipal,
1329 : mozilla::ErrorResult& aError);
1330 :
1331 : void GetInterface(JSContext* aCx, nsIJSID* aIID,
1332 : JS::MutableHandle<JS::Value> aRetval,
1333 : mozilla::ErrorResult& aError);
1334 :
1335 : already_AddRefed<nsWindowRoot> GetWindowRootOuter();
1336 : already_AddRefed<nsWindowRoot> GetWindowRoot(mozilla::ErrorResult& aError);
1337 :
1338 : mozilla::dom::Performance* GetPerformance();
1339 :
1340 : protected:
1341 : // Web IDL helpers
1342 :
1343 : // Redefine the property called aPropName on this window object to be a value
1344 : // property with the value aValue, much like we would do for a [Replaceable]
1345 : // property in IDL.
1346 : void RedefineProperty(JSContext* aCx, const char* aPropName,
1347 : JS::Handle<JS::Value> aValue,
1348 : mozilla::ErrorResult& aError);
1349 :
1350 : // Implementation guts for our writable IDL attributes that are really
1351 : // supposed to be readonly replaceable.
1352 : typedef int32_t
1353 : (nsGlobalWindow::*WindowCoordGetter)(mozilla::dom::CallerType aCallerType,
1354 : mozilla::ErrorResult&);
1355 : typedef void
1356 : (nsGlobalWindow::*WindowCoordSetter)(int32_t,
1357 : mozilla::dom::CallerType aCallerType,
1358 : mozilla::ErrorResult&);
1359 : void GetReplaceableWindowCoord(JSContext* aCx, WindowCoordGetter aGetter,
1360 : JS::MutableHandle<JS::Value> aRetval,
1361 : mozilla::dom::CallerType aCallerType,
1362 : mozilla::ErrorResult& aError);
1363 : void SetReplaceableWindowCoord(JSContext* aCx, WindowCoordSetter aSetter,
1364 : JS::Handle<JS::Value> aValue,
1365 : const char* aPropName,
1366 : mozilla::dom::CallerType aCallerType,
1367 : mozilla::ErrorResult& aError);
1368 : // And the implementations of WindowCoordGetter/WindowCoordSetter.
1369 : public:
1370 : int32_t GetInnerWidthOuter(mozilla::ErrorResult& aError);
1371 : protected:
1372 : int32_t GetInnerWidth(mozilla::dom::CallerType aCallerType,
1373 : mozilla::ErrorResult& aError);
1374 : nsresult GetInnerWidth(int32_t* aWidth) override;
1375 : void SetInnerWidthOuter(int32_t aInnerWidth,
1376 : mozilla::dom::CallerType aCallerType,
1377 : mozilla::ErrorResult& aError);
1378 : void SetInnerWidth(int32_t aInnerWidth,
1379 : mozilla::dom::CallerType aCallerType,
1380 : mozilla::ErrorResult& aError);
1381 : public:
1382 : int32_t GetInnerHeightOuter(mozilla::ErrorResult& aError);
1383 : protected:
1384 : int32_t GetInnerHeight(mozilla::dom::CallerType aCallerType,
1385 : mozilla::ErrorResult& aError);
1386 : nsresult GetInnerHeight(int32_t* aHeight) override;
1387 : void SetInnerHeightOuter(int32_t aInnerHeight,
1388 : mozilla::dom::CallerType aCallerType,
1389 : mozilla::ErrorResult& aError);
1390 : void SetInnerHeight(int32_t aInnerHeight,
1391 : mozilla::dom::CallerType aCallerType,
1392 : mozilla::ErrorResult& aError);
1393 : int32_t GetScreenXOuter(mozilla::dom::CallerType aCallerType,
1394 : mozilla::ErrorResult& aError);
1395 : int32_t GetScreenX(mozilla::dom::CallerType aCallerType,
1396 : mozilla::ErrorResult& aError);
1397 : void SetScreenXOuter(int32_t aScreenX,
1398 : mozilla::dom::CallerType aCallerType,
1399 : mozilla::ErrorResult& aError);
1400 : void SetScreenX(int32_t aScreenX,
1401 : mozilla::dom::CallerType aCallerType,
1402 : mozilla::ErrorResult& aError);
1403 : int32_t GetScreenYOuter(mozilla::dom::CallerType aCallerType,
1404 : mozilla::ErrorResult& aError);
1405 : int32_t GetScreenY(mozilla::dom::CallerType aCallerType,
1406 : mozilla::ErrorResult& aError);
1407 : void SetScreenYOuter(int32_t aScreenY,
1408 : mozilla::dom::CallerType aCallerType,
1409 : mozilla::ErrorResult& aError);
1410 : void SetScreenY(int32_t aScreenY,
1411 : mozilla::dom::CallerType aCallerType,
1412 : mozilla::ErrorResult& aError);
1413 : int32_t GetOuterWidthOuter(mozilla::dom::CallerType aCallerType,
1414 : mozilla::ErrorResult& aError);
1415 : int32_t GetOuterWidth(mozilla::dom::CallerType aCallerType,
1416 : mozilla::ErrorResult& aError);
1417 : void SetOuterWidthOuter(int32_t aOuterWidth,
1418 : mozilla::dom::CallerType aCallerType,
1419 : mozilla::ErrorResult& aError);
1420 : void SetOuterWidth(int32_t aOuterWidth,
1421 : mozilla::dom::CallerType aCallerType,
1422 : mozilla::ErrorResult& aError);
1423 : int32_t GetOuterHeightOuter(mozilla::dom::CallerType aCallerType,
1424 : mozilla::ErrorResult& aError);
1425 : int32_t GetOuterHeight(mozilla::dom::CallerType aCallerType,
1426 : mozilla::ErrorResult& aError);
1427 : void SetOuterHeightOuter(int32_t aOuterHeight,
1428 : mozilla::dom::CallerType aCallerType,
1429 : mozilla::ErrorResult& aError);
1430 : void SetOuterHeight(int32_t aOuterHeight,
1431 : mozilla::dom::CallerType aCallerType,
1432 : mozilla::ErrorResult& aError);
1433 :
1434 : // Array of idle observers that are notified of idle events.
1435 : nsTObserverArray<IdleObserverHolder> mIdleObservers;
1436 :
1437 : // Idle timer used for function callbacks to notify idle observers.
1438 : nsCOMPtr<nsITimer> mIdleTimer;
1439 :
1440 : // Idle fuzz time added to idle timer callbacks.
1441 : uint32_t mIdleFuzzFactor;
1442 :
1443 : // Index in mArrayIdleObservers
1444 : // Next idle observer to notify user idle status
1445 : int32_t mIdleCallbackIndex;
1446 :
1447 : // If false then the topic is "active"
1448 : // If true then the topic is "idle"
1449 : bool mCurrentlyIdle;
1450 :
1451 : // Set to true when a fuzz time needs to be applied
1452 : // to active notifications to the idle observer.
1453 : bool mAddActiveEventFuzzTime;
1454 :
1455 : nsCOMPtr <nsIIdleService> mIdleService;
1456 :
1457 : RefPtr<mozilla::dom::WakeLock> mWakeLock;
1458 :
1459 : static bool sIdleObserversAPIFuzzTimeDisabled;
1460 :
1461 : friend class HashchangeCallback;
1462 : friend class mozilla::dom::BarProp;
1463 :
1464 : // Object Management
1465 : virtual ~nsGlobalWindow();
1466 : void DropOuterWindowDocs();
1467 : void CleanUp();
1468 : void ClearControllers();
1469 : // Outer windows only.
1470 : void FinalClose();
1471 :
1472 0 : inline void MaybeClearInnerWindow(nsGlobalWindow* aExpectedInner)
1473 : {
1474 0 : if(mInnerWindow == aExpectedInner->AsInner()) {
1475 0 : mInnerWindow = nullptr;
1476 : }
1477 0 : }
1478 :
1479 : void FreeInnerObjects();
1480 : nsGlobalWindow *CallerInnerWindow();
1481 :
1482 : // Only to be called on an inner window.
1483 : // aDocument must not be null.
1484 : void InnerSetNewDocument(JSContext* aCx, nsIDocument* aDocument);
1485 :
1486 : // Inner windows only.
1487 : nsresult DefineArgumentsProperty(nsIArray *aArguments);
1488 :
1489 : // Get the parent, returns null if this is a toplevel window
1490 : nsPIDOMWindowOuter* GetParentInternal();
1491 :
1492 : public:
1493 : // popup tracking
1494 1 : bool IsPopupSpamWindow()
1495 : {
1496 1 : if (IsInnerWindow() && !mOuterWindow) {
1497 0 : return false;
1498 : }
1499 :
1500 1 : return GetOuterWindowInternal()->mIsPopupSpam;
1501 : }
1502 :
1503 : // Outer windows only.
1504 : void SetIsPopupSpamWindow(bool aIsPopupSpam);
1505 :
1506 : protected:
1507 : // Window Control Functions
1508 :
1509 : // Outer windows only.
1510 : virtual nsresult
1511 : OpenNoNavigate(const nsAString& aUrl,
1512 : const nsAString& aName,
1513 : const nsAString& aOptions,
1514 : nsPIDOMWindowOuter** _retval) override;
1515 :
1516 : private:
1517 : /**
1518 : * @param aUrl the URL we intend to load into the window. If aNavigate is
1519 : * true, we'll actually load this URL into the window. Otherwise,
1520 : * aUrl is advisory; OpenInternal will not load the URL into the
1521 : * new window.
1522 : *
1523 : * @param aName the name to use for the new window
1524 : *
1525 : * @param aOptions the window options to use for the new window
1526 : *
1527 : * @param aDialog true when called from variants of OpenDialog. If this is
1528 : * true, this method will skip popup blocking checks. The aDialog
1529 : * argument is passed on to the window watcher.
1530 : *
1531 : * @param aCalledNoScript true when called via the [noscript] open()
1532 : * and openDialog() methods. When this is true, we do NOT want to use
1533 : * the JS stack for things like caller determination.
1534 : *
1535 : * @param aDoJSFixups true when this is the content-accessible JS version of
1536 : * window opening. When true, popups do not cause us to throw, we save
1537 : * the caller's principal in the new window for later consumption, and
1538 : * we make sure that there is a document in the newly-opened window.
1539 : * Note that this last will only be done if the newly-opened window is
1540 : * non-chrome.
1541 : *
1542 : * @param aNavigate true if we should navigate to the provided URL, false
1543 : * otherwise. When aNavigate is false, we also skip our can-load
1544 : * security check, on the assumption that whoever *actually* loads this
1545 : * page will do their own security check.
1546 : *
1547 : * @param argv The arguments to pass to the new window. The first
1548 : * three args, if present, will be aUrl, aName, and aOptions. So this
1549 : * param only matters if there are more than 3 arguments.
1550 : *
1551 : * @param aExtraArgument Another way to pass arguments in. This is mutually
1552 : * exclusive with the argv approach.
1553 : *
1554 : * @param aLoadInfo to be passed on along to the windowwatcher.
1555 : *
1556 : * @param aForceNoOpener if true, will act as if "noopener" were passed in
1557 : * aOptions, but without affecting any other window
1558 : * features.
1559 : *
1560 : * @param aReturn [out] The window that was opened, if any. Will be null if
1561 : * aForceNoOpener is true of if aOptions contains
1562 : * "noopener".
1563 : *
1564 : * Outer windows only.
1565 : */
1566 : nsresult OpenInternal(const nsAString& aUrl,
1567 : const nsAString& aName,
1568 : const nsAString& aOptions,
1569 : bool aDialog,
1570 : bool aContentModal,
1571 : bool aCalledNoScript,
1572 : bool aDoJSFixups,
1573 : bool aNavigate,
1574 : nsIArray *argv,
1575 : nsISupports *aExtraArgument,
1576 : nsIDocShellLoadInfo* aLoadInfo,
1577 : bool aForceNoOpener,
1578 : nsPIDOMWindowOuter **aReturn);
1579 :
1580 : template<typename Method>
1581 : void CallOnChildren(Method aMethod);
1582 :
1583 : void FreezeInternal();
1584 : void ThawInternal();
1585 :
1586 : public:
1587 : // Timeout Functions
1588 : // |interval| is in milliseconds.
1589 : int32_t SetTimeoutOrInterval(JSContext* aCx,
1590 : mozilla::dom::Function& aFunction,
1591 : int32_t aTimeout,
1592 : const mozilla::dom::Sequence<JS::Value>& aArguments,
1593 : bool aIsInterval, mozilla::ErrorResult& aError);
1594 : int32_t SetTimeoutOrInterval(JSContext* aCx, const nsAString& aHandler,
1595 : int32_t aTimeout, bool aIsInterval,
1596 : mozilla::ErrorResult& aError);
1597 :
1598 : // Return true if |aTimeout| was cleared while its handler ran.
1599 : bool RunTimeoutHandler(mozilla::dom::Timeout* aTimeout, nsIScriptContext* aScx);
1600 :
1601 : // Helper Functions
1602 : already_AddRefed<nsIDocShellTreeOwner> GetTreeOwner();
1603 : already_AddRefed<nsIBaseWindow> GetTreeOwnerWindow();
1604 : already_AddRefed<nsIWebBrowserChrome> GetWebBrowserChrome();
1605 : nsresult SecurityCheckURL(const char *aURL);
1606 : bool IsPrivateBrowsing();
1607 :
1608 : bool PopupWhitelisted();
1609 : PopupControlState RevisePopupAbuseLevel(PopupControlState);
1610 : void FireAbuseEvents(const nsAString &aPopupURL,
1611 : const nsAString &aPopupWindowName,
1612 : const nsAString &aPopupWindowFeatures);
1613 : void FireOfflineStatusEventIfChanged();
1614 :
1615 : bool GetIsPrerendered();
1616 :
1617 : private:
1618 : void ReportLargeAllocStatus();
1619 :
1620 : public:
1621 : // Inner windows only.
1622 : nsresult ScheduleNextIdleObserverCallback();
1623 : uint32_t GetFuzzTimeMS();
1624 : nsresult ScheduleActiveTimerCallback();
1625 : uint32_t FindInsertionIndex(IdleObserverHolder* aIdleObserver);
1626 : virtual nsresult RegisterIdleObserver(nsIIdleObserver* aIdleObserverPtr) override;
1627 : nsresult FindIndexOfElementToRemove(nsIIdleObserver* aIdleObserver,
1628 : int32_t* aRemoveElementIndex);
1629 : virtual nsresult UnregisterIdleObserver(nsIIdleObserver* aIdleObserverPtr) override;
1630 :
1631 : // Inner windows only.
1632 : nsresult FireHashchange(const nsAString &aOldURL, const nsAString &aNewURL);
1633 :
1634 : void FlushPendingNotifications(mozilla::FlushType aType);
1635 :
1636 : // Outer windows only.
1637 : void EnsureReflowFlushAndPaint();
1638 : void CheckSecurityWidthAndHeight(int32_t* width, int32_t* height,
1639 : mozilla::dom::CallerType aCallerType);
1640 : void CheckSecurityLeftAndTop(int32_t* left, int32_t* top,
1641 : mozilla::dom::CallerType aCallerType);
1642 :
1643 : // Outer windows only.
1644 : // Arguments to this function should have values in app units
1645 : void SetCSSViewportWidthAndHeight(nscoord width, nscoord height);
1646 : // Arguments to this function should have values in device pixels
1647 : nsresult SetDocShellWidthAndHeight(int32_t width, int32_t height);
1648 :
1649 : static bool CanSetProperty(const char *aPrefName);
1650 :
1651 : static void MakeScriptDialogTitle(nsAString& aOutTitle,
1652 : nsIPrincipal* aSubjectPrincipal);
1653 :
1654 : // Outer windows only.
1655 : bool CanMoveResizeWindows(mozilla::dom::CallerType aCallerType);
1656 :
1657 : // If aDoFlush is true, we'll flush our own layout; otherwise we'll try to
1658 : // just flush our parent and only flush ourselves if we think we need to.
1659 : // Outer windows only.
1660 : mozilla::CSSPoint GetScrollXY(bool aDoFlush);
1661 :
1662 : int32_t GetScrollBoundaryOuter(mozilla::Side aSide);
1663 :
1664 : // Outer windows only.
1665 : nsresult GetInnerSize(mozilla::CSSIntSize& aSize);
1666 : nsIntSize GetOuterSize(mozilla::dom::CallerType aCallerType,
1667 : mozilla::ErrorResult& aError);
1668 : void SetOuterSize(int32_t aLengthCSSPixels, bool aIsWidth,
1669 : mozilla::dom::CallerType aCallerType,
1670 : mozilla::ErrorResult& aError);
1671 : nsRect GetInnerScreenRect();
1672 :
1673 : void ScrollTo(const mozilla::CSSIntPoint& aScroll,
1674 : const mozilla::dom::ScrollOptions& aOptions);
1675 :
1676 5 : bool IsFrame()
1677 : {
1678 5 : return GetParentInternal() != nullptr;
1679 : }
1680 :
1681 : // Outer windows only.
1682 : // If aLookForCallerOnJSStack is true, this method will look at the JS stack
1683 : // to determine who the caller is. If it's false, it'll use |this| as the
1684 : // caller.
1685 : bool WindowExists(const nsAString& aName, bool aForceNoOpener,
1686 : bool aLookForCallerOnJSStack);
1687 :
1688 : already_AddRefed<nsIWidget> GetMainWidget();
1689 : nsIWidget* GetNearestWidget() const;
1690 :
1691 : bool IsInModalState();
1692 :
1693 : // Convenience functions for the many methods that need to scale
1694 : // from device to CSS pixels or vice versa. Note: if a presentation
1695 : // context is not available, they will assume a 1:1 ratio.
1696 : int32_t DevToCSSIntPixels(int32_t px);
1697 : int32_t CSSToDevIntPixels(int32_t px);
1698 : nsIntSize DevToCSSIntPixels(nsIntSize px);
1699 : nsIntSize CSSToDevIntPixels(nsIntSize px);
1700 :
1701 : virtual void SetFocusedNode(nsIContent* aNode,
1702 : uint32_t aFocusMethod = 0,
1703 : bool aNeedsFocus = false) override;
1704 :
1705 : virtual uint32_t GetFocusMethod() override;
1706 :
1707 : virtual bool ShouldShowFocusRing() override;
1708 :
1709 : virtual void SetKeyboardIndicators(UIStateChangeType aShowAccelerators,
1710 : UIStateChangeType aShowFocusRings) override;
1711 :
1712 : // Inner windows only.
1713 : void UpdateCanvasFocus(bool aFocusChanged, nsIContent* aNewContent);
1714 :
1715 : public:
1716 : virtual already_AddRefed<nsPIWindowRoot> GetTopWindowRoot() override;
1717 :
1718 : protected:
1719 : static void NotifyDOMWindowDestroyed(nsGlobalWindow* aWindow);
1720 : void NotifyWindowIDDestroyed(const char* aTopic);
1721 :
1722 : static void NotifyDOMWindowFrozen(nsGlobalWindow* aWindow);
1723 : static void NotifyDOMWindowThawed(nsGlobalWindow* aWindow);
1724 :
1725 : void ClearStatus();
1726 :
1727 : virtual void UpdateParentTarget() override;
1728 :
1729 : void InitializeShowFocusRings();
1730 :
1731 : // Clear the document-dependent slots on our JS wrapper. Inner windows only.
1732 : void ClearDocumentDependentSlots(JSContext* aCx);
1733 :
1734 : // Inner windows only.
1735 : already_AddRefed<mozilla::dom::StorageEvent>
1736 : CloneStorageEvent(const nsAString& aType,
1737 : const RefPtr<mozilla::dom::StorageEvent>& aEvent,
1738 : mozilla::ErrorResult& aRv);
1739 :
1740 : public:
1741 : // Outer windows only.
1742 : nsDOMWindowList* GetWindowList();
1743 :
1744 : protected:
1745 : // Helper for getComputedStyle and getDefaultComputedStyle
1746 : already_AddRefed<nsICSSDeclaration>
1747 : GetComputedStyleHelperOuter(mozilla::dom::Element& aElt,
1748 : const nsAString& aPseudoElt,
1749 : bool aDefaultStylesOnly);
1750 : already_AddRefed<nsICSSDeclaration>
1751 : GetComputedStyleHelper(mozilla::dom::Element& aElt,
1752 : const nsAString& aPseudoElt,
1753 : bool aDefaultStylesOnly,
1754 : mozilla::ErrorResult& aError);
1755 : nsresult GetComputedStyleHelper(nsIDOMElement* aElt,
1756 : const nsAString& aPseudoElt,
1757 : bool aDefaultStylesOnly,
1758 : nsIDOMCSSStyleDeclaration** aReturn);
1759 :
1760 : // Outer windows only.
1761 : void PreloadLocalStorage();
1762 :
1763 : // Returns CSS pixels based on primary screen. Outer windows only.
1764 : mozilla::CSSIntPoint GetScreenXY(mozilla::dom::CallerType aCallerType,
1765 : mozilla::ErrorResult& aError);
1766 :
1767 : nsGlobalWindow* InnerForSetTimeoutOrInterval(mozilla::ErrorResult& aError);
1768 :
1769 : void PostMessageMozOuter(JSContext* aCx, JS::Handle<JS::Value> aMessage,
1770 : const nsAString& aTargetOrigin,
1771 : JS::Handle<JS::Value> aTransfer,
1772 : nsIPrincipal& aSubjectPrincipal,
1773 : mozilla::ErrorResult& aError);
1774 : void PostMessageMoz(JSContext* aCx, JS::Handle<JS::Value> aMessage,
1775 : const nsAString& aTargetOrigin,
1776 : JS::Handle<JS::Value> aTransfer,
1777 : nsIPrincipal& aSubjectPrincipal,
1778 : mozilla::ErrorResult& aError);
1779 :
1780 : already_AddRefed<nsIVariant>
1781 : ShowModalDialogOuter(const nsAString& aUrl, nsIVariant* aArgument,
1782 : const nsAString& aOptions,
1783 : nsIPrincipal& aSubjectPrincipal,
1784 : mozilla::ErrorResult& aError);
1785 :
1786 : already_AddRefed<nsIVariant>
1787 : ShowModalDialog(const nsAString& aUrl, nsIVariant* aArgument,
1788 : const nsAString& aOptions,
1789 : nsIPrincipal& aSubjectPrincipal,
1790 : mozilla::ErrorResult& aError);
1791 :
1792 : // Ask the user if further dialogs should be blocked, if dialogs are currently
1793 : // being abused. This is used in the cases where we have no modifiable UI to
1794 : // show, in that case we show a separate dialog to ask this question.
1795 : bool ConfirmDialogIfNeeded();
1796 :
1797 : // Helper called after moving/resizing, to update docShell's presContext
1798 : // if we have caused a resolution change by moving across monitors.
1799 : void CheckForDPIChange();
1800 :
1801 : private:
1802 : // Fire the JS engine's onNewGlobalObject hook. Only used on inner windows.
1803 : void FireOnNewGlobalObject();
1804 :
1805 : void DisconnectEventTargetObjects();
1806 :
1807 :
1808 : enum class SecureContextFlags {
1809 : eDefault,
1810 : eIgnoreOpener
1811 : };
1812 : // Called only on outer windows to compute the value that will be returned by
1813 : // IsSecureContext() for the inner window that corresponds to aDocument.
1814 : bool ComputeIsSecureContext(nsIDocument* aDocument,
1815 : SecureContextFlags aFlags =
1816 : SecureContextFlags::eDefault);
1817 :
1818 : // nsPIDOMWindow<T> should be able to see these helper methods.
1819 : friend class nsPIDOMWindow<mozIDOMWindowProxy>;
1820 : friend class nsPIDOMWindow<mozIDOMWindow>;
1821 : friend class nsPIDOMWindow<nsISupports>;
1822 :
1823 : mozilla::dom::TabGroup* TabGroupInner();
1824 : mozilla::dom::TabGroup* TabGroupOuter();
1825 :
1826 : bool IsBackgroundInternal() const;
1827 :
1828 : void SetIsBackgroundInternal(bool aIsBackground);
1829 :
1830 : public:
1831 : // Dispatch a runnable related to the global.
1832 : virtual nsresult Dispatch(const char* aName,
1833 : mozilla::TaskCategory aCategory,
1834 : already_AddRefed<nsIRunnable>&& aRunnable) override;
1835 :
1836 : virtual nsISerialEventTarget*
1837 : EventTargetFor(mozilla::TaskCategory aCategory) const override;
1838 :
1839 : virtual mozilla::AbstractThread*
1840 : AbstractMainThreadFor(mozilla::TaskCategory aCategory) override;
1841 :
1842 : void DisableIdleCallbackRequests();
1843 1 : uint32_t LastIdleRequestHandle() const { return mIdleRequestCallbackCounter - 1; }
1844 : nsresult RunIdleRequest(mozilla::dom::IdleRequest* aRequest,
1845 : DOMHighResTimeStamp aDeadline, bool aDidTimeout);
1846 : nsresult ExecuteIdleRequest(TimeStamp aDeadline);
1847 : void ScheduleIdleRequestDispatch();
1848 : void SuspendIdleRequests();
1849 : void ResumeIdleRequests();
1850 :
1851 : typedef mozilla::LinkedList<mozilla::dom::IdleRequest> IdleRequests;
1852 : void InsertIdleCallback(mozilla::dom::IdleRequest* aRequest);
1853 :
1854 : void RemoveIdleCallback(mozilla::dom::IdleRequest* aRequest);
1855 :
1856 : protected:
1857 : // These members are only used on outer window objects. Make sure
1858 : // you never set any of these on an inner object!
1859 : bool mFullScreen : 1;
1860 : bool mFullscreenMode : 1;
1861 : bool mIsClosed : 1;
1862 : bool mInClose : 1;
1863 : // mHavePendingClose means we've got a termination function set to
1864 : // close us when the JS stops executing or that we have a close
1865 : // event posted. If this is set, just ignore window.close() calls.
1866 : bool mHavePendingClose : 1;
1867 : bool mHadOriginalOpener : 1;
1868 : bool mOriginalOpenerWasSecureContext : 1;
1869 : bool mIsSecureContextIfOpenerIgnored : 1;
1870 : bool mIsPopupSpam : 1;
1871 :
1872 : // Indicates whether scripts are allowed to close this window.
1873 : bool mBlockScriptedClosingFlag : 1;
1874 :
1875 : // Window offline status. Checked to see if we need to fire offline event
1876 : bool mWasOffline : 1;
1877 :
1878 : // Represents whether the inner window's page has had a slow script notice.
1879 : // Only used by inner windows; will always be false for outer windows.
1880 : // This is used to implement Telemetry measures such as SLOW_SCRIPT_PAGE_COUNT.
1881 : bool mHasHadSlowScript : 1;
1882 :
1883 : // Track what sorts of events we need to fire when thawed
1884 : bool mNotifyIdleObserversIdleOnThaw : 1;
1885 : bool mNotifyIdleObserversActiveOnThaw : 1;
1886 :
1887 : // Indicates whether we're in the middle of creating an initializing
1888 : // a new inner window object.
1889 : bool mCreatingInnerWindow : 1;
1890 :
1891 : // Fast way to tell if this is a chrome window (without having to QI).
1892 : bool mIsChrome : 1;
1893 :
1894 : // Hack to indicate whether a chrome window needs its message manager
1895 : // to be disconnected, since clean up code is shared in the global
1896 : // window superclass.
1897 : bool mCleanMessageManager : 1;
1898 :
1899 : // Indicates that the current document has never received a document focus
1900 : // event.
1901 : bool mNeedsFocus : 1;
1902 : bool mHasFocus : 1;
1903 :
1904 : // when true, show focus rings for the current focused content only.
1905 : // This will be reset when another element is focused
1906 : bool mShowFocusRingForContent : 1;
1907 :
1908 : // true if tab navigation has occurred for this window. Focus rings
1909 : // should be displayed.
1910 : bool mFocusByKeyOccurred : 1;
1911 :
1912 : // Inner windows only.
1913 : // Indicates whether this window wants gamepad input events
1914 : bool mHasGamepad : 1;
1915 :
1916 : // Inner windows only.
1917 : // Indicates whether this window wants VR events
1918 : bool mHasVREvents : 1;
1919 :
1920 : // Inner windows only.
1921 : // Indicates whether this window wants VRDisplayActivate events
1922 : bool mHasVRDisplayActivateEvents : 1;
1923 : nsCheapSet<nsUint32HashKey> mGamepadIndexSet;
1924 : nsRefPtrHashtable<nsUint32HashKey, mozilla::dom::Gamepad> mGamepads;
1925 : bool mHasSeenGamepadInput;
1926 :
1927 : // whether we've sent the destroy notification for our window id
1928 : bool mNotifiedIDDestroyed : 1;
1929 : // whether scripts may close the window,
1930 : // even if "dom.allow_scripts_to_close_windows" is false.
1931 : bool mAllowScriptsToClose : 1;
1932 :
1933 : bool mTopLevelOuterContentWindow : 1;
1934 :
1935 : nsCOMPtr<nsIScriptContext> mContext;
1936 : nsWeakPtr mOpener;
1937 : nsCOMPtr<nsIControllers> mControllers;
1938 :
1939 : // For |window.arguments|, via |openDialog|.
1940 : nsCOMPtr<nsIArray> mArguments;
1941 :
1942 : // For |window.dialogArguments|, via |showModalDialog|.
1943 : RefPtr<DialogValueHolder> mDialogArguments;
1944 :
1945 : // Only used in the outer.
1946 : RefPtr<DialogValueHolder> mReturnValue;
1947 :
1948 : RefPtr<mozilla::dom::Navigator> mNavigator;
1949 : RefPtr<nsScreen> mScreen;
1950 : RefPtr<nsDOMWindowList> mFrames;
1951 : // All BarProps are inner window only.
1952 : RefPtr<mozilla::dom::BarProp> mMenubar;
1953 : RefPtr<mozilla::dom::BarProp> mToolbar;
1954 : RefPtr<mozilla::dom::BarProp> mLocationbar;
1955 : RefPtr<mozilla::dom::BarProp> mPersonalbar;
1956 : RefPtr<mozilla::dom::BarProp> mStatusbar;
1957 : RefPtr<mozilla::dom::BarProp> mScrollbars;
1958 : RefPtr<nsDOMWindowUtils> mWindowUtils;
1959 : nsString mStatus;
1960 : nsString mDefaultStatus;
1961 : RefPtr<nsGlobalWindowObserver> mObserver; // Inner windows only.
1962 : RefPtr<mozilla::dom::Crypto> mCrypto;
1963 : RefPtr<mozilla::dom::U2F> mU2F;
1964 : RefPtr<mozilla::dom::cache::CacheStorage> mCacheStorage;
1965 : RefPtr<mozilla::dom::Console> mConsole;
1966 : RefPtr<mozilla::dom::Worklet> mAudioWorklet;
1967 : RefPtr<mozilla::dom::Worklet> mPaintWorklet;
1968 : // We need to store an nsISupports pointer to this object because the
1969 : // mozilla::dom::External class doesn't exist on b2g and using the type
1970 : // forward declared here means that ~nsGlobalWindow wouldn't compile because
1971 : // it wouldn't see the ~External function's declaration.
1972 : nsCOMPtr<nsISupports> mExternal;
1973 :
1974 : RefPtr<mozilla::dom::MozSelfSupport> mMozSelfSupport;
1975 :
1976 : RefPtr<mozilla::dom::Storage> mLocalStorage;
1977 : RefPtr<mozilla::dom::Storage> mSessionStorage;
1978 :
1979 : // These member variable are used only on inner windows.
1980 : RefPtr<mozilla::EventListenerManager> mListenerManager;
1981 : RefPtr<mozilla::dom::Location> mLocation;
1982 : RefPtr<nsHistory> mHistory;
1983 : RefPtr<mozilla::dom::CustomElementRegistry> mCustomElements;
1984 :
1985 : // These member variables are used on both inner and the outer windows.
1986 : nsCOMPtr<nsIPrincipal> mDocumentPrincipal;
1987 : // mTabChild is only ever populated in the content process.
1988 : nsCOMPtr<nsITabChild> mTabChild;
1989 :
1990 : uint32_t mSuspendDepth;
1991 : uint32_t mFreezeDepth;
1992 :
1993 : // the method that was used to focus mFocusedNode
1994 : uint32_t mFocusMethod;
1995 :
1996 : uint32_t mSerial;
1997 :
1998 : // The current idle request callback handle
1999 : uint32_t mIdleRequestCallbackCounter;
2000 : IdleRequests mIdleRequestCallbacks;
2001 : RefPtr<IdleRequestExecutor> mIdleRequestExecutor;
2002 :
2003 : #ifdef DEBUG
2004 : bool mSetOpenerWindowCalled;
2005 : nsCOMPtr<nsIURI> mLastOpenedURI;
2006 : #endif
2007 :
2008 : #ifdef MOZ_B2G
2009 : bool mNetworkUploadObserverEnabled;
2010 : bool mNetworkDownloadObserverEnabled;
2011 : #endif // MOZ_B2G
2012 :
2013 : bool mCleanedUp;
2014 :
2015 : nsCOMPtr<nsIDOMOfflineResourceList> mApplicationCache;
2016 :
2017 : using XBLPrototypeHandlerTable = nsJSThingHashtable<nsPtrHashKey<nsXBLPrototypeHandler>, JSObject*>;
2018 : nsAutoPtr<XBLPrototypeHandlerTable> mCachedXBLPrototypeHandlers;
2019 :
2020 : // mSuspendedDoc is only set on outer windows. It's useful when we get matched
2021 : // EnterModalState/LeaveModalState calls, in which case the outer window is
2022 : // responsible for unsuspending events on the document. If we don't (for
2023 : // example, if the outer window is closed before the LeaveModalState call),
2024 : // then the inner window whose mDoc is our mSuspendedDoc is responsible for
2025 : // unsuspending it.
2026 : nsCOMPtr<nsIDocument> mSuspendedDoc;
2027 :
2028 : RefPtr<mozilla::dom::IDBFactory> mIndexedDB;
2029 :
2030 : // This counts the number of windows that have been opened in rapid succession
2031 : // (i.e. within dom.successive_dialog_time_limit of each other). It is reset
2032 : // to 0 once a dialog is opened after dom.successive_dialog_time_limit seconds
2033 : // have elapsed without any other dialogs.
2034 : uint32_t mDialogAbuseCount;
2035 :
2036 : // This holds the time when the last modal dialog was shown. If more than
2037 : // MAX_DIALOG_LIMIT dialogs are shown within the time span defined by
2038 : // dom.successive_dialog_time_limit, we show a checkbox or confirmation prompt
2039 : // to allow disabling of further dialogs from this window.
2040 : TimeStamp mLastDialogQuitTime;
2041 :
2042 : // This flag keeps track of whether dialogs are
2043 : // currently enabled on this window.
2044 : bool mAreDialogsEnabled;
2045 :
2046 : nsTHashtable<nsPtrHashKey<mozilla::DOMEventTargetHelper> > mEventTargetObjects;
2047 :
2048 : nsTArray<uint32_t> mEnabledSensors;
2049 :
2050 : #if defined(MOZ_WIDGET_ANDROID) || defined(MOZ_WIDGET_GONK)
2051 : nsAutoPtr<mozilla::dom::WindowOrientationObserver> mOrientationChangeObserver;
2052 : #endif
2053 :
2054 : #ifdef MOZ_WEBSPEECH
2055 : // mSpeechSynthesis is only used on inner windows.
2056 : RefPtr<mozilla::dom::SpeechSynthesis> mSpeechSynthesis;
2057 : #endif
2058 :
2059 : #ifdef DEBUG
2060 : // This member is used in the debug only assertions in TabGroup()
2061 : // to catch cyclic parent/opener trees and not overflow the stack.
2062 : bool mIsValidatingTabGroup;
2063 : #endif
2064 :
2065 : // This is the CC generation the last time we called CanSkip.
2066 : uint32_t mCanSkipCCGeneration;
2067 :
2068 : // The VR Displays for this window
2069 : nsTArray<RefPtr<mozilla::dom::VRDisplay>> mVRDisplays;
2070 :
2071 : RefPtr<mozilla::dom::VREventObserver> mVREventObserver;
2072 :
2073 : // When non-zero, the document should receive a vrdisplayactivate event
2074 : // after loading. The value is the ID of the VRDisplay that content should
2075 : // begin presentation on.
2076 : uint32_t mAutoActivateVRDisplayID; // Outer windows only
2077 : int64_t mBeforeUnloadListenerCount; // Inner windows only
2078 :
2079 : #ifdef ENABLE_INTL_API
2080 : RefPtr<mozilla::dom::IntlUtils> mIntlUtils;
2081 : #endif
2082 :
2083 : friend class nsDOMScriptableHelper;
2084 : friend class nsDOMWindowUtils;
2085 : friend class mozilla::dom::PostMessageEvent;
2086 : friend class DesktopNotification;
2087 : friend class mozilla::dom::TimeoutManager;
2088 : friend class IdleRequestExecutor;
2089 :
2090 : static WindowByIdTable* sWindowsById;
2091 : static bool sWarnedAboutWindowInternal;
2092 : };
2093 :
2094 : inline nsISupports*
2095 22 : ToSupports(nsGlobalWindow *p)
2096 : {
2097 22 : return static_cast<nsIDOMEventTarget*>(p);
2098 : }
2099 :
2100 : inline nsISupports*
2101 24 : ToCanonicalSupports(nsGlobalWindow *p)
2102 : {
2103 24 : return static_cast<nsIDOMEventTarget*>(p);
2104 : }
2105 :
2106 : /*
2107 : * nsGlobalChromeWindow inherits from nsGlobalWindow. It is the global
2108 : * object created for a Chrome Window only.
2109 : */
2110 : class nsGlobalChromeWindow : public nsGlobalWindow,
2111 : public nsIDOMChromeWindow
2112 : {
2113 : public:
2114 : // nsISupports
2115 : NS_DECL_ISUPPORTS_INHERITED
2116 :
2117 : // nsIDOMChromeWindow interface
2118 : NS_DECL_NSIDOMCHROMEWINDOW
2119 :
2120 : static already_AddRefed<nsGlobalChromeWindow> Create(nsGlobalWindow *aOuterWindow);
2121 :
2122 0 : void DisconnectAndClearGroupMessageManagers()
2123 : {
2124 0 : for (auto iter = mGroupMessageManagers.Iter(); !iter.Done(); iter.Next()) {
2125 0 : nsIMessageBroadcaster* mm = iter.UserData();
2126 0 : if (mm) {
2127 0 : static_cast<nsFrameMessageManager*>(mm)->Disconnect();
2128 : }
2129 : }
2130 0 : mGroupMessageManagers.Clear();
2131 0 : }
2132 :
2133 : protected:
2134 7 : explicit nsGlobalChromeWindow(nsGlobalWindow *aOuterWindow)
2135 7 : : nsGlobalWindow(aOuterWindow),
2136 7 : mGroupMessageManagers(1)
2137 : {
2138 7 : mIsChrome = true;
2139 7 : mCleanMessageManager = true;
2140 7 : }
2141 :
2142 0 : ~nsGlobalChromeWindow()
2143 0 : {
2144 0 : MOZ_ASSERT(mCleanMessageManager,
2145 : "chrome windows may always disconnect the msg manager");
2146 :
2147 0 : DisconnectAndClearGroupMessageManagers();
2148 :
2149 0 : if (mMessageManager) {
2150 : static_cast<nsFrameMessageManager *>(
2151 0 : mMessageManager.get())->Disconnect();
2152 : }
2153 :
2154 0 : mCleanMessageManager = false;
2155 0 : }
2156 :
2157 : public:
2158 19 : NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsGlobalChromeWindow,
2159 : nsGlobalWindow)
2160 :
2161 : using nsGlobalWindow::GetBrowserDOMWindow;
2162 : using nsGlobalWindow::SetBrowserDOMWindow;
2163 : using nsGlobalWindow::GetAttention;
2164 : using nsGlobalWindow::GetAttentionWithCycleCount;
2165 : using nsGlobalWindow::SetCursor;
2166 : using nsGlobalWindow::Maximize;
2167 : using nsGlobalWindow::Minimize;
2168 : using nsGlobalWindow::Restore;
2169 : using nsGlobalWindow::NotifyDefaultButtonLoaded;
2170 : using nsGlobalWindow::GetMessageManager;
2171 : using nsGlobalWindow::GetGroupMessageManager;
2172 : using nsGlobalWindow::BeginWindowMove;
2173 :
2174 : nsCOMPtr<nsIBrowserDOMWindow> mBrowserDOMWindow;
2175 : nsCOMPtr<nsIMessageBroadcaster> mMessageManager;
2176 : nsInterfaceHashtable<nsStringHashKey, nsIMessageBroadcaster> mGroupMessageManagers;
2177 : // A weak pointer to the nsPresShell that we are doing fullscreen for.
2178 : // The pointer being set indicates we've set the IsInFullscreenChange
2179 : // flag on this pres shell.
2180 : nsWeakPtr mFullscreenPresShell;
2181 : nsCOMPtr<mozIDOMWindowProxy> mOpenerForInitialContentBrowser;
2182 : };
2183 :
2184 : /*
2185 : * nsGlobalModalWindow inherits from nsGlobalWindow. It is the global
2186 : * object created for a modal content windows only (i.e. not modal
2187 : * chrome dialogs).
2188 : */
2189 : class nsGlobalModalWindow : public nsGlobalWindow,
2190 : public nsIDOMModalContentWindow
2191 : {
2192 : public:
2193 : NS_DECL_ISUPPORTS_INHERITED
2194 : NS_DECL_NSIDOMMODALCONTENTWINDOW
2195 :
2196 : static already_AddRefed<nsGlobalModalWindow> Create(nsGlobalWindow *aOuterWindow);
2197 :
2198 : protected:
2199 0 : explicit nsGlobalModalWindow(nsGlobalWindow *aOuterWindow)
2200 0 : : nsGlobalWindow(aOuterWindow)
2201 : {
2202 0 : mIsModalContentWindow = true;
2203 0 : }
2204 :
2205 0 : ~nsGlobalModalWindow() {}
2206 : };
2207 :
2208 : /* factory function */
2209 : inline already_AddRefed<nsGlobalWindow>
2210 5 : NS_NewScriptGlobalObject(bool aIsChrome, bool aIsModalContentWindow)
2211 : {
2212 10 : RefPtr<nsGlobalWindow> global;
2213 :
2214 5 : if (aIsChrome) {
2215 3 : global = nsGlobalChromeWindow::Create(nullptr);
2216 2 : } else if (aIsModalContentWindow) {
2217 0 : global = nsGlobalModalWindow::Create(nullptr);
2218 : } else {
2219 2 : global = nsGlobalWindow::Create(nullptr);
2220 : }
2221 :
2222 10 : return global.forget();
2223 : }
2224 :
2225 : #endif /* nsGlobalWindow_h___ */
|