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 nsGlobalWindowOuter_h___
8 #define nsGlobalWindowOuter_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 "nsWeakReference.h"
21 #include "nsTHashMap.h"
22 #include "nsCycleCollectionParticipant.h"
23 
24 // Interfaces Needed
25 #include "nsIBrowserDOMWindow.h"
26 #include "nsIInterfaceRequestor.h"
27 #include "nsIDOMChromeWindow.h"
28 #include "nsIScriptGlobalObject.h"
29 #include "nsIScriptObjectPrincipal.h"
30 #include "mozilla/EventListenerManager.h"
31 #include "nsIPrincipal.h"
32 #include "nsSize.h"
33 #include "mozilla/FlushType.h"
34 #include "prclist.h"
35 #include "mozilla/dom/BindingDeclarations.h"
36 #include "mozilla/dom/ChromeMessageBroadcaster.h"
37 #include "mozilla/dom/PopupBlocker.h"
38 #include "mozilla/dom/StorageEvent.h"
39 #include "mozilla/dom/StorageEventBinding.h"
40 #include "mozilla/dom/UnionTypes.h"
41 #include "mozilla/Attributes.h"
42 #include "mozilla/LinkedList.h"
43 #include "nsWrapperCacheInlines.h"
44 #include "mozilla/dom/EventTarget.h"
45 #include "mozilla/dom/WindowBinding.h"
46 #include "Units.h"
47 #include "nsComponentManagerUtils.h"
48 #include "nsSize.h"
49 #include "nsCheapSets.h"
50 #include "mozilla/dom/ImageBitmapSource.h"
51 #include "mozilla/UniquePtr.h"
52 #include "mozilla/dom/BrowsingContext.h"
53 #include "X11UndefineNone.h"
54 
55 class nsDocShell;
56 class nsIArray;
57 class nsIBaseWindow;
58 class nsIContent;
59 class nsICSSDeclaration;
60 class nsIDocShellTreeOwner;
61 class nsIDOMWindowUtils;
62 class nsIScrollableFrame;
63 class nsIControllers;
64 class nsIPrintSettings;
65 class nsIScriptContext;
66 class nsIScriptTimeoutHandler;
67 class nsIBrowserChild;
68 class nsITimeoutHandler;
69 class nsIWebBrowserChrome;
70 class nsIWebProgressListener;
71 class mozIDOMWindowProxy;
72 
73 class nsDocShellLoadState;
74 class nsScreen;
75 class nsHistory;
76 class nsGlobalWindowObserver;
77 class nsGlobalWindowInner;
78 class nsDOMWindowUtils;
79 struct nsRect;
80 
81 class nsWindowSizes;
82 
83 namespace mozilla {
84 class AbstractThread;
85 class DOMEventTargetHelper;
86 class ErrorResult;
87 class ThrottledEventQueue;
88 namespace dom {
89 class BarProp;
90 struct ChannelPixelLayout;
91 class Console;
92 class Crypto;
93 class CustomElementRegistry;
94 class DocGroup;
95 class Document;
96 class External;
97 class Function;
98 class Gamepad;
99 enum class ImageBitmapFormat : uint8_t;
100 class IncrementalRunnable;
101 class IntlUtils;
102 class Location;
103 class MediaQueryList;
104 class Navigator;
105 class OwningExternalOrWindowProxy;
106 class Promise;
107 class PostMessageData;
108 class PostMessageEvent;
109 class PrintPreviewResultInfo;
110 struct RequestInit;
111 class RequestOrUSVString;
112 class Selection;
113 class SpeechSynthesis;
114 class Timeout;
115 class U2F;
116 class VRDisplay;
117 enum class VRDisplayEventReason : uint8_t;
118 class VREventObserver;
119 class WakeLock;
120 #if defined(MOZ_WIDGET_ANDROID)
121 class WindowOrientationObserver;
122 #endif
123 class Worklet;
124 namespace cache {
125 class CacheStorage;
126 }  // namespace cache
127 class IDBFactory;
128 }  // namespace dom
129 }  // namespace mozilla
130 
131 extern already_AddRefed<nsIScriptTimeoutHandler> NS_CreateJSTimeoutHandler(
132     JSContext* aCx, nsGlobalWindowInner* aWindow,
133     mozilla::dom::Function& aFunction,
134     const mozilla::dom::Sequence<JS::Value>& aArguments,
135     mozilla::ErrorResult& aError);
136 
137 extern already_AddRefed<nsIScriptTimeoutHandler> NS_CreateJSTimeoutHandler(
138     JSContext* aCx, nsGlobalWindowInner* aWindow, const nsAString& aExpression,
139     mozilla::ErrorResult& aError);
140 
141 extern const JSClass OuterWindowProxyClass;
142 
143 //*****************************************************************************
144 // nsGlobalWindowOuter
145 //*****************************************************************************
146 
147 // nsGlobalWindowOuter inherits PRCList for maintaining a list of all inner
148 // windows still in memory for any given outer window. This list is needed to
149 // ensure that mOuterWindow doesn't end up dangling. The nature of PRCList means
150 // that the window itself is always in the list, and an outer window's list will
151 // also contain all inner window objects that are still in memory (and in
152 // reality all inner window object's lists also contain its outer and all other
153 // inner windows belonging to the same outer window, but that's an unimportant
154 // side effect of inheriting PRCList).
155 
156 class nsGlobalWindowOuter final : public mozilla::dom::EventTarget,
157                                   public nsPIDOMWindowOuter,
158                                   private nsIDOMWindow
159     // NOTE: This interface is private, as it's only
160     // implemented on chrome windows.
161     ,
162                                   private nsIDOMChromeWindow,
163                                   public nsIScriptGlobalObject,
164                                   public nsIScriptObjectPrincipal,
165                                   public nsSupportsWeakReference,
166                                   public nsIInterfaceRequestor,
167                                   public PRCListStr {
168  public:
169   typedef nsTHashMap<nsUint64HashKey, nsGlobalWindowOuter*>
170       OuterWindowByIdTable;
171 
172   using PrintPreviewResolver =
173       std::function<void(const mozilla::dom::PrintPreviewResultInfo&)>;
174 
175   static void AssertIsOnMainThread()
176 #ifdef DEBUG
177       ;
178 #else
179   {
180   }
181 #endif
182 
Cast(nsPIDOMWindowOuter * aPIWin)183   static nsGlobalWindowOuter* Cast(nsPIDOMWindowOuter* aPIWin) {
184     return static_cast<nsGlobalWindowOuter*>(aPIWin);
185   }
Cast(const nsPIDOMWindowOuter * aPIWin)186   static const nsGlobalWindowOuter* Cast(const nsPIDOMWindowOuter* aPIWin) {
187     return static_cast<const nsGlobalWindowOuter*>(aPIWin);
188   }
Cast(mozIDOMWindowProxy * aWin)189   static nsGlobalWindowOuter* Cast(mozIDOMWindowProxy* aWin) {
190     return Cast(nsPIDOMWindowOuter::From(aWin));
191   }
192 
GetOuterWindowWithId(uint64_t aWindowID)193   static nsGlobalWindowOuter* GetOuterWindowWithId(uint64_t aWindowID) {
194     AssertIsOnMainThread();
195 
196     if (!sOuterWindowsById) {
197       return nullptr;
198     }
199 
200     nsGlobalWindowOuter* outerWindow = sOuterWindowsById->Get(aWindowID);
201     return outerWindow;
202   }
203 
GetWindowsTable()204   static OuterWindowByIdTable* GetWindowsTable() {
205     AssertIsOnMainThread();
206 
207     return sOuterWindowsById;
208   }
209 
FromSupports(nsISupports * supports)210   static nsGlobalWindowOuter* FromSupports(nsISupports* supports) {
211     // Make sure this matches the casts we do in QueryInterface().
212     return (nsGlobalWindowOuter*)(mozilla::dom::EventTarget*)supports;
213   }
214 
215   static already_AddRefed<nsGlobalWindowOuter> Create(nsDocShell* aDocShell,
216                                                       bool aIsChrome);
217 
218   // public methods
219   nsPIDOMWindowOuter* GetPrivateParent();
220 
221   // callback for close event
222   void ReallyCloseWindow();
223 
224   // nsISupports
225   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
226 
227   // nsWrapperCache
WrapObject(JSContext * cx,JS::Handle<JSObject * > aGivenProto)228   virtual JSObject* WrapObject(JSContext* cx,
229                                JS::Handle<JSObject*> aGivenProto) override {
230     return EnsureInnerWindow() ? GetWrapper() : nullptr;
231   }
232 
233   // nsIGlobalJSObjectHolder
GetGlobalJSObject()234   JSObject* GetGlobalJSObject() final { return GetWrapper(); }
GetGlobalJSObjectPreserveColor()235   JSObject* GetGlobalJSObjectPreserveColor() const final {
236     return GetWrapperPreserveColor();
237   }
238 
239   virtual nsresult EnsureScriptEnvironment() override;
240 
241   virtual nsIScriptContext* GetScriptContext() override;
242 
243   void PoisonOuterWindowProxy(JSObject* aObject);
244 
245   virtual bool IsBlackForCC(bool aTracingNeeded = true) override;
246 
247   // nsIScriptObjectPrincipal
248   virtual nsIPrincipal* GetPrincipal() override;
249 
250   virtual nsIPrincipal* GetEffectiveStoragePrincipal() override;
251 
252   virtual nsIPrincipal* PartitionedPrincipal() override;
253 
254   // nsIDOMWindow
255   NS_DECL_NSIDOMWINDOW
256 
257   // nsIDOMChromeWindow (only implemented on chrome windows)
258   NS_DECL_NSIDOMCHROMEWINDOW
259 
260   mozilla::dom::ChromeMessageBroadcaster* GetMessageManager();
261   mozilla::dom::ChromeMessageBroadcaster* GetGroupMessageManager(
262       const nsAString& aGroup);
263 
264   nsresult OpenJS(const nsAString& aUrl, const nsAString& aName,
265                   const nsAString& aOptions,
266                   mozilla::dom::BrowsingContext** _retval);
267 
268   virtual mozilla::EventListenerManager* GetExistingListenerManager()
269       const override;
270 
271   virtual mozilla::EventListenerManager* GetOrCreateListenerManager() override;
272 
273   bool ComputeDefaultWantsUntrusted(mozilla::ErrorResult& aRv) final;
274 
275   virtual nsPIDOMWindowOuter* GetOwnerGlobalForBindingsInternal() override;
276 
277   virtual nsIGlobalObject* GetOwnerGlobal() const override;
278 
279   EventTarget* GetTargetForEventTargetChain() override;
280 
281   using mozilla::dom::EventTarget::DispatchEvent;
282   bool DispatchEvent(mozilla::dom::Event& aEvent,
283                      mozilla::dom::CallerType aCallerType,
284                      mozilla::ErrorResult& aRv) override;
285 
286   void GetEventTargetParent(mozilla::EventChainPreVisitor& aVisitor) override;
287 
288   nsresult PostHandleEvent(mozilla::EventChainPostVisitor& aVisitor) override;
289 
290   // nsPIDOMWindow
291   virtual nsPIDOMWindowOuter* GetPrivateRoot() override;
292 
293   // Outer windows only.
294   virtual void SetIsBackground(bool aIsBackground) override;
295   virtual void SetChromeEventHandler(
296       mozilla::dom::EventTarget* aChromeEventHandler) override;
297 
298   // Outer windows only.
299   virtual void SetInitialPrincipalToSubject(
300       nsIContentSecurityPolicy* aCSP,
301       const mozilla::Maybe<nsILoadInfo::CrossOriginEmbedderPolicy>& aCoep)
302       override;
303 
304   virtual already_AddRefed<nsISupports> SaveWindowState() override;
305   MOZ_CAN_RUN_SCRIPT_BOUNDARY virtual nsresult RestoreWindowState(
306       nsISupports* aState) override;
307 
308   virtual bool IsSuspended() const override;
309   virtual bool IsFrozen() const override;
310 
311   virtual nsresult FireDelayedDOMEvents(bool aIncludeSubWindows) override;
312 
313   // Outer windows only.
314   bool WouldReuseInnerWindow(Document* aNewDocument);
315 
316   void DetachFromDocShell(bool aIsBeingDiscarded);
317 
318   virtual nsresult SetNewDocument(
319       Document* aDocument, nsISupports* aState, bool aForceReuseInnerWindow,
320       mozilla::dom::WindowGlobalChild* aActor = nullptr) override;
321 
322   // Outer windows only.
323   static void PrepareForProcessChange(JSObject* aProxy);
324 
325   // Outer windows only.
326   void DispatchDOMWindowCreated();
327 
328   // Outer windows only.
329   virtual void EnsureSizeAndPositionUpToDate() override;
330 
331   MOZ_CAN_RUN_SCRIPT_BOUNDARY virtual nsGlobalWindowOuter* EnterModalState()
332       override;
333   virtual void LeaveModalState() override;
334 
335   // Outer windows only.
336   virtual bool CanClose() override;
337   virtual void ForceClose() override;
338 
339   // Outer windows only.
340   virtual bool DispatchCustomEvent(
341       const nsAString& aEventName,
342       mozilla::ChromeOnlyDispatch aChromeOnlyDispatch) override;
343   bool DispatchResizeEvent(const mozilla::CSSIntSize& aSize);
344 
345   // For accessing protected field mFullscreen
346   friend class FullscreenTransitionTask;
347 
348   // Outer windows only.
349   nsresult SetFullscreenInternal(FullscreenReason aReason,
350                                  bool aIsFullscreen) final;
351   void FullscreenWillChange(bool aIsFullscreen) final;
352   void FinishFullscreenChange(bool aIsFullscreen) final;
353   void ForceFullScreenInWidget() final;
354   void MacFullscreenMenubarOverlapChanged(
355       mozilla::DesktopCoord aOverlapAmount) final;
356   bool SetWidgetFullscreen(FullscreenReason aReason, bool aIsFullscreen,
357                            nsIWidget* aWidget, nsIScreen* aScreen);
358   bool Fullscreen() const;
359 
360   // nsIInterfaceRequestor
361   NS_DECL_NSIINTERFACEREQUESTOR
362 
363   mozilla::dom::Nullable<mozilla::dom::WindowProxyHolder> IndexedGetterOuter(
364       uint32_t aIndex);
365 
366   already_AddRefed<nsPIDOMWindowOuter> GetInProcessTop() override;
367   // Similar to GetInProcessTop() except that it stops at content frames that
368   // an extension has permission to access.  This is used by the third-party
369   // util service in order to determine the top window for a channel which is
370   // used in third-partiness checks.
371   already_AddRefed<nsPIDOMWindowOuter>
372   GetTopExcludingExtensionAccessibleContentFrames(nsIURI* aURIBeingLoaded);
373   nsPIDOMWindowOuter* GetInProcessScriptableTop() override;
374   inline nsGlobalWindowOuter* GetInProcessTopInternal();
375 
376   inline nsGlobalWindowOuter* GetInProcessScriptableTopInternal();
377 
378   already_AddRefed<mozilla::dom::BrowsingContext> GetChildWindow(
379       const nsAString& aName);
380 
381   // These return true if we've reached the state in this top level window
382   // where we ask the user if further dialogs should be blocked.
383   //
384   // DialogsAreBeingAbused must be called on the scriptable top inner window.
385   //
386   // ShouldPromptToBlockDialogs is implemented in terms of
387   // DialogsAreBeingAbused, and will get the scriptable top inner window
388   // automatically.
389   // Outer windows only.
390   bool ShouldPromptToBlockDialogs();
391 
392   // These functions are used for controlling and determining whether dialogs
393   // (alert, prompt, confirm) are currently allowed in this window.  If you want
394   // to temporarily disable dialogs, please use TemporarilyDisableDialogs, not
395   // EnableDialogs/DisableDialogs, because correctly determining whether to
396   // re-enable dialogs is actually quite difficult.
397   void EnableDialogs();
398   void DisableDialogs();
399   // Outer windows only.
400   bool AreDialogsEnabled();
401 
402   class MOZ_RAII TemporarilyDisableDialogs {
403    public:
404     explicit TemporarilyDisableDialogs(nsGlobalWindowOuter* aWindow);
405     ~TemporarilyDisableDialogs();
406 
407    private:
408     // Always an inner window; this is the window whose dialog state we messed
409     // with.  We just want to keep it alive, because we plan to poke at its
410     // members in our destructor.
411     RefPtr<nsGlobalWindowInner> mTopWindow;
412     // This is not a AutoRestore<bool> because that would require careful
413     // member destructor ordering, which is a bit fragile.  This way we can
414     // explicitly restore things before we drop our ref to mTopWindow.
415     bool mSavedDialogsEnabled;
416   };
417   friend class TemporarilyDisableDialogs;
418 
419   nsIScriptContext* GetContextInternal();
420 
421   nsGlobalWindowInner* GetCurrentInnerWindowInternal() const;
422 
423   nsGlobalWindowInner* EnsureInnerWindowInternal();
424 
IsCreatingInnerWindow()425   bool IsCreatingInnerWindow() const { return mCreatingInnerWindow; }
426 
IsChromeWindow()427   bool IsChromeWindow() const { return mIsChrome; }
428 
429   // GetScrollFrame does not flush.  Callers should do it themselves as needed,
430   // depending on which info they actually want off the scrollable frame.
431   nsIScrollableFrame* GetScrollFrame();
432 
433   // Outer windows only.
434   void UnblockScriptedClosing();
435 
436   static void Init();
437   static void ShutDown();
438   static bool IsCallerChrome();
439 
440   friend class WindowStateHolder;
441 
442   NS_DECL_CYCLE_COLLECTION_SKIPPABLE_SCRIPT_HOLDER_CLASS_AMBIGUOUS(
443       nsGlobalWindowOuter, mozilla::dom::EventTarget)
444 
445   virtual bool TakeFocus(bool aFocus, uint32_t aFocusMethod) override;
446   virtual void SetReadyForFocus() override;
447   virtual void PageHidden() override;
448 
449   /**
450    * Set a arguments for this window. This will be set on the window
451    * right away (if there's an existing document) and it will also be
452    * installed on the window when the next document is loaded.
453    *
454    * This function passes |arguments| back from nsWindowWatcher to
455    * nsGlobalWindow.
456    */
457   nsresult SetArguments(nsIArray* aArguments);
458 
IsClosedOrClosing()459   bool IsClosedOrClosing() {
460     return (mIsClosed || mInClose || mHavePendingClose || mCleanedUp);
461   }
462 
IsCleanedUp()463   bool IsCleanedUp() const { return mCleanedUp; }
464 
465   virtual void FirePopupBlockedEvent(
466       Document* aDoc, nsIURI* aPopupURI, const nsAString& aPopupWindowName,
467       const nsAString& aPopupWindowFeatures) override;
468 
469   void AddSizeOfIncludingThis(nsWindowSizes& aWindowSizes) const;
470 
AllowScriptsToClose()471   void AllowScriptsToClose() { mAllowScriptsToClose = true; }
472 
473   // Outer windows only.
474   uint32_t GetAutoActivateVRDisplayID();
475   // Outer windows only.
476   void SetAutoActivateVRDisplayID(uint32_t aAutoActivateVRDisplayID);
477 
478 #define EVENT(name_, id_, type_, struct_)                              \
479   mozilla::dom::EventHandlerNonNull* GetOn##name_() {                  \
480     mozilla::EventListenerManager* elm = GetExistingListenerManager(); \
481     return elm ? elm->GetEventHandler(nsGkAtoms::on##name_) : nullptr; \
482   }                                                                    \
483   void SetOn##name_(mozilla::dom::EventHandlerNonNull* handler) {      \
484     mozilla::EventListenerManager* elm = GetOrCreateListenerManager(); \
485     if (elm) {                                                         \
486       elm->SetEventHandler(nsGkAtoms::on##name_, handler);             \
487     }                                                                  \
488   }
489 #define ERROR_EVENT(name_, id_, type_, struct_)                          \
490   mozilla::dom::OnErrorEventHandlerNonNull* GetOn##name_() {             \
491     mozilla::EventListenerManager* elm = GetExistingListenerManager();   \
492     return elm ? elm->GetOnErrorEventHandler() : nullptr;                \
493   }                                                                      \
494   void SetOn##name_(mozilla::dom::OnErrorEventHandlerNonNull* handler) { \
495     mozilla::EventListenerManager* elm = GetOrCreateListenerManager();   \
496     if (elm) {                                                           \
497       elm->SetEventHandler(handler);                                     \
498     }                                                                    \
499   }
500 #define BEFOREUNLOAD_EVENT(name_, id_, type_, struct_)                 \
501   mozilla::dom::OnBeforeUnloadEventHandlerNonNull* GetOn##name_() {    \
502     mozilla::EventListenerManager* elm = GetExistingListenerManager(); \
503     return elm ? elm->GetOnBeforeUnloadEventHandler() : nullptr;       \
504   }                                                                    \
505   void SetOn##name_(                                                   \
506       mozilla::dom::OnBeforeUnloadEventHandlerNonNull* handler) {      \
507     mozilla::EventListenerManager* elm = GetOrCreateListenerManager(); \
508     if (elm) {                                                         \
509       elm->SetEventHandler(handler);                                   \
510     }                                                                  \
511   }
512 #define WINDOW_ONLY_EVENT EVENT
513 #define TOUCH_EVENT EVENT
514 #include "mozilla/EventNameList.h"
515 #undef TOUCH_EVENT
516 #undef WINDOW_ONLY_EVENT
517 #undef BEFOREUNLOAD_EVENT
518 #undef ERROR_EVENT
519 #undef EVENT
520 
GetParentObject()521   nsISupports* GetParentObject() { return nullptr; }
522 
GetDocument()523   Document* GetDocument() { return GetDoc(); }
524   void GetNameOuter(nsAString& aName);
525   void SetNameOuter(const nsAString& aName, mozilla::ErrorResult& aError);
526   mozilla::dom::Location* GetLocation() override;
527   void GetStatusOuter(nsAString& aStatus);
528   void SetStatusOuter(const nsAString& aStatus);
529   void CloseOuter(bool aTrustedCaller);
530   nsresult Close() override;
531   bool GetClosedOuter();
532   bool Closed() override;
533   void StopOuter(mozilla::ErrorResult& aError);
534   void FocusOuter(mozilla::dom::CallerType aCallerType, bool aFromOtherProcess,
535                   uint64_t aActionId);
536   nsresult Focus(mozilla::dom::CallerType aCallerType) override;
537   void BlurOuter(mozilla::dom::CallerType aCallerType);
538   mozilla::dom::WindowProxyHolder GetFramesOuter();
539   uint32_t Length();
540   mozilla::dom::Nullable<mozilla::dom::WindowProxyHolder> GetTopOuter();
541 
542   nsresult GetPrompter(nsIPrompt** aPrompt) override;
543 
544  protected:
545   mozilla::dom::Nullable<mozilla::dom::WindowProxyHolder>
546   GetOpenerWindowOuter();
547   // Initializes the mWasOffline member variable
548   void InitWasOffline();
549 
550  public:
551   nsPIDOMWindowOuter* GetSameProcessOpener();
552   already_AddRefed<mozilla::dom::BrowsingContext> GetOpenerBrowsingContext();
553   mozilla::dom::Nullable<mozilla::dom::WindowProxyHolder> GetOpener() override;
554   mozilla::dom::Nullable<mozilla::dom::WindowProxyHolder> GetParentOuter();
555   already_AddRefed<nsPIDOMWindowOuter> GetInProcessParent() override;
556   nsPIDOMWindowOuter* GetInProcessScriptableParent() override;
557   nsPIDOMWindowOuter* GetInProcessScriptableParentOrNull() override;
558   mozilla::dom::Element* GetFrameElement(nsIPrincipal& aSubjectPrincipal);
559   mozilla::dom::Element* GetFrameElement() override;
560   mozilla::dom::Nullable<mozilla::dom::WindowProxyHolder> OpenOuter(
561       const nsAString& aUrl, const nsAString& aName, const nsAString& aOptions,
562       mozilla::ErrorResult& aError);
563   nsresult Open(const nsAString& aUrl, const nsAString& aName,
564                 const nsAString& aOptions, nsDocShellLoadState* aLoadState,
565                 bool aForceNoOpener,
566                 mozilla::dom::BrowsingContext** _retval) override;
567   mozilla::dom::Navigator* GetNavigator() override;
568 
569 #if defined(MOZ_WIDGET_ANDROID)
570   int16_t Orientation(mozilla::dom::CallerType aCallerType) const;
571 #endif
572 
573  protected:
574   bool AlertOrConfirm(bool aAlert, const nsAString& aMessage,
575                       nsIPrincipal& aSubjectPrincipal,
576                       mozilla::ErrorResult& aError);
577 
578  public:
579   void AlertOuter(const nsAString& aMessage, nsIPrincipal& aSubjectPrincipal,
580                   mozilla::ErrorResult& aError);
581   bool ConfirmOuter(const nsAString& aMessage, nsIPrincipal& aSubjectPrincipal,
582                     mozilla::ErrorResult& aError);
583   void PromptOuter(const nsAString& aMessage, const nsAString& aInitial,
584                    nsAString& aReturn, nsIPrincipal& aSubjectPrincipal,
585                    mozilla::ErrorResult& aError);
586 
587   void PrintOuter(mozilla::ErrorResult& aError);
588 
589   enum class IsPreview : bool { No, Yes };
590   enum class IsForWindowDotPrint : bool { No, Yes };
591   mozilla::dom::Nullable<mozilla::dom::WindowProxyHolder> Print(
592       nsIPrintSettings*, nsIWebProgressListener*, nsIDocShell*, IsPreview,
593       IsForWindowDotPrint, PrintPreviewResolver&&, mozilla::ErrorResult&);
594   mozilla::dom::Selection* GetSelectionOuter();
595   already_AddRefed<mozilla::dom::Selection> GetSelection() override;
596   nsScreen* GetScreen();
597   void MoveToOuter(int32_t aXPos, int32_t aYPos,
598                    mozilla::dom::CallerType aCallerType,
599                    mozilla::ErrorResult& aError);
600   void MoveByOuter(int32_t aXDif, int32_t aYDif,
601                    mozilla::dom::CallerType aCallerType,
602                    mozilla::ErrorResult& aError);
603   nsresult MoveBy(int32_t aXDif, int32_t aYDif) override;
604   void ResizeToOuter(int32_t aWidth, int32_t aHeight,
605                      mozilla::dom::CallerType aCallerType,
606                      mozilla::ErrorResult& aError);
607   void ResizeByOuter(int32_t aWidthDif, int32_t aHeightDif,
608                      mozilla::dom::CallerType aCallerType,
609                      mozilla::ErrorResult& aError);
610   double GetScrollXOuter();
611   double GetScrollYOuter();
612 
613   MOZ_CAN_RUN_SCRIPT_BOUNDARY
614   void SizeToContentOuter(mozilla::dom::CallerType aCallerType,
615                           mozilla::ErrorResult& aError);
616   nsIControllers* GetControllersOuter(mozilla::ErrorResult& aError);
617   nsresult GetControllers(nsIControllers** aControllers) override;
618   float GetMozInnerScreenXOuter(mozilla::dom::CallerType aCallerType);
619   float GetMozInnerScreenYOuter(mozilla::dom::CallerType aCallerType);
620   double GetDevicePixelRatioOuter(mozilla::dom::CallerType aCallerType);
621   bool GetFullscreenOuter();
622   bool GetFullScreen() override;
623   void SetFullscreenOuter(bool aFullscreen, mozilla::ErrorResult& aError);
624   nsresult SetFullScreen(bool aFullscreen) override;
625   bool FindOuter(const nsAString& aString, bool aCaseSensitive, bool aBackwards,
626                  bool aWrapAround, bool aWholeWord, bool aSearchInFrames,
627                  bool aShowDialog, mozilla::ErrorResult& aError);
628   uint64_t GetMozPaintCountOuter();
629 
630   bool ShouldResistFingerprinting();
631 
632   mozilla::dom::Nullable<mozilla::dom::WindowProxyHolder> OpenDialogOuter(
633       JSContext* aCx, const nsAString& aUrl, const nsAString& aName,
634       const nsAString& aOptions,
635       const mozilla::dom::Sequence<JS::Value>& aExtraArgument,
636       mozilla::ErrorResult& aError);
637   nsresult OpenDialog(const nsAString& aUrl, const nsAString& aName,
638                       const nsAString& aOptions, nsISupports* aExtraArgument,
639                       mozilla::dom::BrowsingContext** _retval) override;
640   void UpdateCommands(const nsAString& anAction, mozilla::dom::Selection* aSel,
641                       int16_t aReason) override;
642 
643   already_AddRefed<mozilla::dom::BrowsingContext> GetContentInternal(
644       mozilla::dom::CallerType aCallerType, mozilla::ErrorResult& aError);
645   void GetContentOuter(JSContext* aCx, JS::MutableHandle<JSObject*> aRetval,
646                        mozilla::dom::CallerType aCallerType,
647                        mozilla::ErrorResult& aError);
648 
649   // ChromeWindow bits.  Do NOT call these unless your window is in
650   // fact chrome.
651   nsIBrowserDOMWindow* GetBrowserDOMWindowOuter();
652   void SetBrowserDOMWindowOuter(nsIBrowserDOMWindow* aBrowserWindow);
653   void SetCursorOuter(const nsACString& aCursor, mozilla::ErrorResult& aError);
654 
655   void GetReturnValueOuter(JSContext* aCx,
656                            JS::MutableHandle<JS::Value> aReturnValue,
657                            nsIPrincipal& aSubjectPrincipal,
658                            mozilla::ErrorResult& aError);
659   void GetReturnValue(JSContext* aCx, JS::MutableHandle<JS::Value> aReturnValue,
660                       nsIPrincipal& aSubjectPrincipal,
661                       mozilla::ErrorResult& aError);
662   void SetReturnValueOuter(JSContext* aCx, JS::Handle<JS::Value> aReturnValue,
663                            nsIPrincipal& aSubjectPrincipal,
664                            mozilla::ErrorResult& aError);
665   void SetReturnValue(JSContext* aCx, JS::Handle<JS::Value> aReturnValue,
666                       nsIPrincipal& aSubjectPrincipal,
667                       mozilla::ErrorResult& aError);
668 
669   already_AddRefed<nsWindowRoot> GetWindowRootOuter();
670 
671   nsIDOMWindowUtils* WindowUtils();
672 
673   virtual bool IsInSyncOperation() override;
674 
ParentWindowChanged()675   void ParentWindowChanged() {
676     // Reset our storage access permission flag when we get reparented.
677     mStorageAccessPermissionGranted = false;
678   }
679 
680  public:
681   double GetInnerWidthOuter(mozilla::ErrorResult& aError);
682 
683  protected:
684   nsresult GetInnerWidth(double* aWidth) override;
685   void SetInnerWidthOuter(double aInnerWidth,
686                           mozilla::dom::CallerType aCallerType,
687                           mozilla::ErrorResult& aError);
688 
689  public:
690   double GetInnerHeightOuter(mozilla::ErrorResult& aError);
691 
692  protected:
693   nsresult GetInnerHeight(double* aHeight) override;
694   void SetInnerHeightOuter(double aInnerHeight,
695                            mozilla::dom::CallerType aCallerType,
696                            mozilla::ErrorResult& aError);
697   int32_t GetScreenXOuter(mozilla::dom::CallerType aCallerType,
698                           mozilla::ErrorResult& aError);
699   void SetScreenXOuter(int32_t aScreenX, mozilla::dom::CallerType aCallerType,
700                        mozilla::ErrorResult& aError);
701   int32_t GetScreenYOuter(mozilla::dom::CallerType aCallerType,
702                           mozilla::ErrorResult& aError);
703   void SetScreenYOuter(int32_t aScreenY, mozilla::dom::CallerType aCallerType,
704                        mozilla::ErrorResult& aError);
705   int32_t GetOuterWidthOuter(mozilla::dom::CallerType aCallerType,
706                              mozilla::ErrorResult& aError);
707   void SetOuterWidthOuter(int32_t aOuterWidth,
708                           mozilla::dom::CallerType aCallerType,
709                           mozilla::ErrorResult& aError);
710   int32_t GetOuterHeightOuter(mozilla::dom::CallerType aCallerType,
711                               mozilla::ErrorResult& aError);
712   void SetOuterHeightOuter(int32_t aOuterHeight,
713                            mozilla::dom::CallerType aCallerType,
714                            mozilla::ErrorResult& aError);
715 
716   friend class HashchangeCallback;
717   friend class mozilla::dom::BarProp;
718 
719   // Object Management
720   virtual ~nsGlobalWindowOuter();
721   void DropOuterWindowDocs();
722   void CleanUp();
723   void ClearControllers();
724   // Outer windows only.
725   void FinalClose();
726 
727   inline void MaybeClearInnerWindow(nsGlobalWindowInner* aExpectedInner);
728 
729   // Get the parent, returns null if this is a toplevel window
730   nsPIDOMWindowOuter* GetInProcessParentInternal();
731 
732  protected:
733   // Window Control Functions
734 
735   // Outer windows only.
736   virtual nsresult OpenNoNavigate(
737       const nsAString& aUrl, const nsAString& aName, const nsAString& aOptions,
738       mozilla::dom::BrowsingContext** _retval) override;
739 
740  private:
741   explicit nsGlobalWindowOuter(uint64_t aWindowID);
742 
743   enum class PrintKind : uint8_t { None, InternalPrint, WindowDotPrint };
744 
745   /**
746    * @param aUrl the URL we intend to load into the window.  If aNavigate is
747    *        true, we'll actually load this URL into the window. Otherwise,
748    *        aUrl is advisory; OpenInternal will not load the URL into the
749    *        new window.
750    *
751    * @param aName the name to use for the new window
752    *
753    * @param aOptions the window options to use for the new window
754    *
755    * @param aDialog true when called from variants of OpenDialog.  If this is
756    *        true, this method will skip popup blocking checks.  The aDialog
757    *        argument is passed on to the window watcher.
758    *
759    * @param aCalledNoScript true when called via the [noscript] open()
760    *        and openDialog() methods.  When this is true, we do NOT want to use
761    *        the JS stack for things like caller determination.
762    *
763    * @param aDoJSFixups true when this is the content-accessible JS version of
764    *        window opening.  When true, popups do not cause us to throw, we save
765    *        the caller's principal in the new window for later consumption, and
766    *        we make sure that there is a document in the newly-opened window.
767    *        Note that this last will only be done if the newly-opened window is
768    *        non-chrome.
769    *
770    * @param aNavigate true if we should navigate to the provided URL, false
771    *        otherwise.  When aNavigate is false, we also skip our can-load
772    *        security check, on the assumption that whoever *actually* loads this
773    *        page will do their own security check.
774    *
775    * @param argv The arguments to pass to the new window.  The first
776    *        three args, if present, will be aUrl, aName, and aOptions.  So this
777    *        param only matters if there are more than 3 arguments.
778    *
779    * @param aExtraArgument Another way to pass arguments in.  This is mutually
780    *        exclusive with the argv approach.
781    *
782    * @param aLoadState to be passed on along to the windowwatcher.
783    *
784    * @param aForceNoOpener if true, will act as if "noopener" were passed in
785    *                       aOptions, but without affecting any other window
786    *                       features.
787    *
788    * @param aPrintKind     Whether this is a browser created for printing, and
789    *                       if so for which kind of print.
790    *
791    * @param aReturn [out] The window that was opened, if any.  Will be null if
792    *                      aForceNoOpener is true of if aOptions contains
793    *                      "noopener".
794    *
795    * Outer windows only.
796    */
797   nsresult OpenInternal(const nsAString& aUrl, const nsAString& aName,
798                         const nsAString& aOptions, bool aDialog,
799                         bool aContentModal, bool aCalledNoScript,
800                         bool aDoJSFixups, bool aNavigate, nsIArray* argv,
801                         nsISupports* aExtraArgument,
802                         nsDocShellLoadState* aLoadState, bool aForceNoOpener,
803                         PrintKind aPrintKind,
804                         mozilla::dom::BrowsingContext** aReturn);
805 
806  public:
807   nsresult SecurityCheckURL(const char* aURL, nsIURI** aURI);
808 
809   mozilla::dom::PopupBlocker::PopupControlState RevisePopupAbuseLevel(
810       mozilla::dom::PopupBlocker::PopupControlState aState);
811   void FireAbuseEvents(const nsAString& aPopupURL,
812                        const nsAString& aPopupWindowName,
813                        const nsAString& aPopupWindowFeatures);
814 
815   void FlushPendingNotifications(mozilla::FlushType aType);
816 
817   // Outer windows only.
818   void EnsureReflowFlushAndPaint();
819   void CheckSecurityWidthAndHeight(int32_t* width, int32_t* height,
820                                    mozilla::dom::CallerType aCallerType);
821   void CheckSecurityLeftAndTop(int32_t* left, int32_t* top,
822                                mozilla::dom::CallerType aCallerType);
823 
824   // Outer windows only.
825   // Arguments to this function should have values in app units
826   void SetCSSViewportWidthAndHeight(nscoord width, nscoord height);
827   // Arguments to this function should have values in device pixels
828   MOZ_CAN_RUN_SCRIPT_BOUNDARY
829   nsresult SetDocShellWidthAndHeight(int32_t width, int32_t height);
830 
831   static bool CanSetProperty(const char* aPrefName);
832 
833   static void MakeMessageWithPrincipal(nsAString& aOutMessage,
834                                        nsIPrincipal* aSubjectPrincipal,
835                                        bool aUseHostPort,
836                                        const char* aNullMessage,
837                                        const char* aContentMessage,
838                                        const char* aFallbackMessage);
839 
840   // Outer windows only.
841   MOZ_CAN_RUN_SCRIPT_BOUNDARY
842   bool CanMoveResizeWindows(mozilla::dom::CallerType aCallerType);
843 
844   // If aDoFlush is true, we'll flush our own layout; otherwise we'll try to
845   // just flush our parent and only flush ourselves if we think we need to.
846   // Outer windows only.
847   mozilla::CSSPoint GetScrollXY(bool aDoFlush);
848 
849   int32_t GetScrollBoundaryOuter(mozilla::Side aSide);
850 
851   // Outer windows only.
852   nsresult GetInnerSize(mozilla::CSSSize& aSize);
853   nsIntSize GetOuterSize(mozilla::dom::CallerType aCallerType,
854                          mozilla::ErrorResult& aError);
855   void SetOuterSize(int32_t aLengthCSSPixels, bool aIsWidth,
856                     mozilla::dom::CallerType aCallerType,
857                     mozilla::ErrorResult& aError);
858   nsRect GetInnerScreenRect();
859   static mozilla::Maybe<mozilla::CSSIntSize> GetRDMDeviceSize(
860       const Document& aDocument);
861 
862   // Outer windows only.
863   // If aLookForCallerOnJSStack is true, this method will look at the JS stack
864   // to determine who the caller is.  If it's false, it'll use |this| as the
865   // caller.
866   bool WindowExists(const nsAString& aName, bool aForceNoOpener,
867                     bool aLookForCallerOnJSStack);
868 
869   already_AddRefed<nsIWidget> GetMainWidget();
870   nsIWidget* GetNearestWidget() const;
871 
872   bool IsInModalState();
873 
IsStorageAccessPermissionGranted()874   bool IsStorageAccessPermissionGranted() const {
875     return mStorageAccessPermissionGranted;
876   }
SetStorageAccessPermissionGranted(bool aStorageAccessPermissionGranted)877   void SetStorageAccessPermissionGranted(bool aStorageAccessPermissionGranted) {
878     mStorageAccessPermissionGranted = aStorageAccessPermissionGranted;
879   }
880 
881   // Convenience functions for the many methods that need to scale
882   // from device to CSS pixels.  This computes it with cached scale in
883   // PresContext which may be not recent information of the widget.
884   // Note: if PresContext is not available, they will assume a 1:1 ratio.
885   int32_t DevToCSSIntPixels(int32_t px);
886   nsIntSize DevToCSSIntPixels(nsIntSize px);
887 
888   // Convenience functions for the methods which call methods of nsIBaseWindow
889   // because it takes/returns device pixels.  Unfortunately, mPresContext may
890   // have older scale value for the corresponding widget.  Therefore, these
891   // helper methods convert between CSS pixels and device pixels with aWindow.
892   int32_t DevToCSSIntPixelsForBaseWindow(int32_t aDevicePixels,
893                                          nsIBaseWindow* aWindow);
894   nsIntSize DevToCSSIntPixelsForBaseWindow(nsIntSize aDeviceSize,
895                                            nsIBaseWindow* aWindow);
896   int32_t CSSToDevIntPixelsForBaseWindow(int32_t aCSSPixels,
897                                          nsIBaseWindow* aWindow);
898   nsIntSize CSSToDevIntPixelsForBaseWindow(nsIntSize aCSSSize,
899                                            nsIBaseWindow* aWindow);
900 
901   void SetFocusedElement(mozilla::dom::Element* aElement,
902                          uint32_t aFocusMethod = 0,
903                          bool aNeedsFocus = false) override;
904 
905   uint32_t GetFocusMethod() override;
906 
907   bool ShouldShowFocusRing() override;
908 
909   void SetKeyboardIndicators(UIStateChangeType aShowFocusRings) override;
910 
911  public:
912   already_AddRefed<nsPIWindowRoot> GetTopWindowRoot() override;
913 
914  protected:
915   void NotifyWindowIDDestroyed(const char* aTopic);
916 
917   void ClearStatus();
918 
919   void UpdateParentTarget() override;
920 
921   void InitializeShowFocusRings();
922 
923  protected:
924   // Helper for getComputedStyle and getDefaultComputedStyle
925   already_AddRefed<nsICSSDeclaration> GetComputedStyleHelperOuter(
926       mozilla::dom::Element& aElt, const nsAString& aPseudoElt,
927       bool aDefaultStylesOnly);
928 
929   // Outer windows only.
930   void PreloadLocalStorage();
931 
932   // Returns CSS pixels based on primary screen.  Outer windows only.
933   mozilla::CSSIntPoint GetScreenXY(mozilla::dom::CallerType aCallerType,
934                                    mozilla::ErrorResult& aError);
935 
936   void PostMessageMozOuter(JSContext* aCx, JS::Handle<JS::Value> aMessage,
937                            const nsAString& aTargetOrigin,
938                            JS::Handle<JS::Value> aTransfer,
939                            nsIPrincipal& aSubjectPrincipal,
940                            mozilla::ErrorResult& aError);
941 
942  public:
943   /**
944    * Compute the principal to use for checking against the target principal in a
945    * postMessage call.
946    *
947    * @param aTargetOrigin The value passed as the targetOrigin argument to the
948    * postMessage call.
949    *
950    * @param aTargetOriginURI The origin of the URI contained in aTargetOrigin
951    * (see GatherPostMessageData).
952    *
953    * @param aCallerPrincipal The principal of the incumbent global of the
954    * postMessage call (see GatherPostMessageData).
955    *
956    * @param aSubjectPrincipal The subject principal for the postMessage call.
957    *
958    * @param aProvidedPrincipal [out] The principal to use for checking against
959    * the target's principal.
960    *
961    * @return Whether the postMessage call should continue or return now.
962    */
963   bool GetPrincipalForPostMessage(const nsAString& aTargetOrigin,
964                                   nsIURI* aTargetOriginURI,
965                                   nsIPrincipal* aCallerPrincipal,
966                                   nsIPrincipal& aSubjectPrincipal,
967                                   nsIPrincipal** aProvidedPrincipal);
968 
969  private:
970   /**
971    * Gather the necessary data from the caller for a postMessage call.
972    *
973    * @param aCx The JSContext.
974    *
975    * @param aTargetOrigin The value passed as the targetOrigin argument to the
976    * postMessage call.
977    *
978    * @param aSource [out] The browsing context for the incumbent global.
979    *
980    * @param aOrigin [out] The value to use for the origin property of the
981    * MessageEvent object.
982    *
983    * @param aTargetOriginURI [out] The origin of the URI contained in
984    * aTargetOrigin, null if aTargetOrigin is "/" or "*".
985    *
986    * @param aCallerPrincipal [out] The principal of the incumbent global of the
987    *                               postMessage call.
988    *
989    * @param aCallerInnerWindow [out] Inner window of the caller of
990    * postMessage, or null if the incumbent global is not a Window.
991    *
992    * @param aCallerURI [out] The URI of the document of the incumbent
993    * global if it's a Window, null otherwise.
994    *
995    * @param aCallerAgentCluterId [out] If a non-nullptr is passed, it would
996    * return the caller's agent cluster id.
997    *
998    * @param aScriptLocation [out] If we do not have a caller's URI, then
999    * use script location as a sourcename for creating an error object.
1000    *
1001    * @param aError [out] The error, if any.
1002    *
1003    * @return Whether the postMessage call should continue or return now.
1004    */
1005   static bool GatherPostMessageData(
1006       JSContext* aCx, const nsAString& aTargetOrigin,
1007       mozilla::dom::BrowsingContext** aSource, nsAString& aOrigin,
1008       nsIURI** aTargetOriginURI, nsIPrincipal** aCallerPrincipal,
1009       nsGlobalWindowInner** aCallerInnerWindow, nsIURI** aCallerURI,
1010       mozilla::Maybe<nsID>* aCallerAgentClusterId, nsACString* aScriptLocation,
1011       mozilla::ErrorResult& aError);
1012 
1013   // Ask the user if further dialogs should be blocked, if dialogs are currently
1014   // being abused. This is used in the cases where we have no modifiable UI to
1015   // show, in that case we show a separate dialog to ask this question.
1016   bool ConfirmDialogIfNeeded();
1017 
1018   // Helper called after moving/resizing, to update docShell's presContext
1019   // if we have caused a resolution change by moving across monitors.
1020   void CheckForDPIChange();
1021 
1022  private:
1023   enum class SecureContextFlags { eDefault, eIgnoreOpener };
1024   // Called only on outer windows to compute the value that will be returned by
1025   // IsSecureContext() for the inner window that corresponds to aDocument.
1026   bool ComputeIsSecureContext(
1027       Document* aDocument,
1028       SecureContextFlags aFlags = SecureContextFlags::eDefault);
1029 
1030   void SetDocShell(nsDocShell* aDocShell);
1031 
1032   // nsPIDOMWindow{Inner,Outer} should be able to see these helper methods.
1033   friend class nsPIDOMWindowInner;
1034   friend class nsPIDOMWindowOuter;
1035 
1036   void SetIsBackgroundInternal(bool aIsBackground);
1037 
1038   nsresult GetInterfaceInternal(const nsIID& aIID, void** aSink);
1039 
1040   void MaybeAllowStorageForOpenedWindow(nsIURI* aURI);
1041 
1042   bool IsOnlyTopLevelDocumentInSHistory();
1043 
1044   void MaybeResetWindowName(Document* aNewDocument);
1045 
1046  public:
DelayedPrintUntilAfterLoad()1047   bool DelayedPrintUntilAfterLoad() const {
1048     return mDelayedPrintUntilAfterLoad;
1049   }
1050 
DelayedCloseForPrinting()1051   bool DelayedCloseForPrinting() const { return mDelayedCloseForPrinting; }
1052 
StopDelayingPrintingUntilAfterLoad()1053   void StopDelayingPrintingUntilAfterLoad() {
1054     mShouldDelayPrintUntilAfterLoad = false;
1055   }
1056 
1057   // Dispatch a runnable related to the global.
1058   virtual nsresult Dispatch(mozilla::TaskCategory aCategory,
1059                             already_AddRefed<nsIRunnable>&& aRunnable) override;
1060 
1061   virtual nsISerialEventTarget* EventTargetFor(
1062       mozilla::TaskCategory aCategory) const override;
1063 
1064   virtual mozilla::AbstractThread* AbstractMainThreadFor(
1065       mozilla::TaskCategory aCategory) override;
1066 
1067  protected:
1068   bool mFullscreen : 1;
1069   bool mFullscreenMode : 1;
1070   bool mForceFullScreenInWidget : 1;
1071   bool mIsClosed : 1;
1072   bool mInClose : 1;
1073   // mHavePendingClose means we've got a termination function set to
1074   // close us when the JS stops executing or that we have a close
1075   // event posted.  If this is set, just ignore window.close() calls.
1076   bool mHavePendingClose : 1;
1077 
1078   // Indicates whether scripts are allowed to close this window.
1079   bool mBlockScriptedClosingFlag : 1;
1080 
1081   // Window offline status. Checked to see if we need to fire offline event
1082   bool mWasOffline : 1;
1083 
1084   // Indicates whether we're in the middle of creating an initializing
1085   // a new inner window object.
1086   bool mCreatingInnerWindow : 1;
1087 
1088   // Fast way to tell if this is a chrome window (without having to QI).
1089   bool mIsChrome : 1;
1090 
1091   // whether scripts may close the window,
1092   // even if "dom.allow_scripts_to_close_windows" is false.
1093   bool mAllowScriptsToClose : 1;
1094 
1095   bool mTopLevelOuterContentWindow : 1;
1096 
1097   // whether storage access has been granted to this frame.
1098   bool mStorageAccessPermissionGranted : 1;
1099 
1100   // Whether we've delayed a print until after load.
1101   bool mDelayedPrintUntilAfterLoad : 1;
1102   // Whether we've delayed a close() operation because there was a pending
1103   // print() operation.
1104   bool mDelayedCloseForPrinting : 1;
1105   // Whether we should delay printing until after load.
1106   bool mShouldDelayPrintUntilAfterLoad : 1;
1107 
1108   nsCOMPtr<nsIScriptContext> mContext;
1109   nsCOMPtr<nsIControllers> mControllers;
1110 
1111   // For |window.arguments|, via |openDialog|.
1112   nsCOMPtr<nsIArray> mArguments;
1113 
1114   RefPtr<nsDOMWindowUtils> mWindowUtils;
1115   nsString mStatus;
1116 
1117   RefPtr<mozilla::dom::Storage> mLocalStorage;
1118 
1119   nsCOMPtr<nsIPrincipal> mDocumentPrincipal;
1120   nsCOMPtr<nsIPrincipal> mDocumentStoragePrincipal;
1121   nsCOMPtr<nsIPrincipal> mDocumentPartitionedPrincipal;
1122 
1123 #ifdef DEBUG
1124   uint32_t mSerial;
1125 
1126   bool mSetOpenerWindowCalled;
1127   nsCOMPtr<nsIURI> mLastOpenedURI;
1128 #endif
1129 
1130   bool mCleanedUp;
1131 
1132   // It's useful when we get matched EnterModalState/LeaveModalState calls, in
1133   // which case the outer window is responsible for unsuspending events on the
1134   // document. If we don't (for example, if the outer window is closed before
1135   // the LeaveModalState call), then the inner window whose mDoc is our
1136   // mSuspendedDoc is responsible for unsuspending it.
1137   RefPtr<Document> mSuspendedDoc;
1138 
1139   // This is the CC generation the last time we called CanSkip.
1140   uint32_t mCanSkipCCGeneration;
1141 
1142   // When non-zero, the document should receive a vrdisplayactivate event
1143   // after loading.  The value is the ID of the VRDisplay that content should
1144   // begin presentation on.
1145   uint32_t mAutoActivateVRDisplayID;
1146 
1147   static OuterWindowByIdTable* sOuterWindowsById;
1148 
1149   // Members in the mChromeFields member should only be used in chrome windows.
1150   // All accesses to this field should be guarded by a check of mIsChrome.
1151   struct ChromeFields {
1152     nsCOMPtr<nsIBrowserDOMWindow> mBrowserDOMWindow;
1153     // A weak pointer to the PresShell that we are doing fullscreen for.
1154     // The pointer being set indicates we've set the IsInFullscreenChange
1155     // flag on this pres shell.
1156     nsWeakPtr mFullscreenPresShell;
1157   } mChromeFields;
1158 
1159   friend class nsDOMScriptableHelper;
1160   friend class nsDOMWindowUtils;
1161   friend class mozilla::dom::BrowsingContext;
1162   friend class mozilla::dom::PostMessageEvent;
1163   friend class DesktopNotification;
1164   friend class mozilla::dom::TimeoutManager;
1165   friend class nsGlobalWindowInner;
1166 };
1167 
1168 // XXX: EWW - This is an awful hack - let's not do this
1169 #include "nsGlobalWindowInner.h"
1170 
ToSupports(nsGlobalWindowOuter * p)1171 inline nsISupports* ToSupports(nsGlobalWindowOuter* p) {
1172   return static_cast<mozilla::dom::EventTarget*>(p);
1173 }
1174 
ToCanonicalSupports(nsGlobalWindowOuter * p)1175 inline nsISupports* ToCanonicalSupports(nsGlobalWindowOuter* p) {
1176   return static_cast<mozilla::dom::EventTarget*>(p);
1177 }
1178 
GetOwnerGlobal()1179 inline nsIGlobalObject* nsGlobalWindowOuter::GetOwnerGlobal() const {
1180   return GetCurrentInnerWindowInternal();
1181 }
1182 
GetInProcessTopInternal()1183 inline nsGlobalWindowOuter* nsGlobalWindowOuter::GetInProcessTopInternal() {
1184   nsCOMPtr<nsPIDOMWindowOuter> top = GetInProcessTop();
1185   if (top) {
1186     return nsGlobalWindowOuter::Cast(top);
1187   }
1188   return nullptr;
1189 }
1190 
1191 inline nsGlobalWindowOuter*
GetInProcessScriptableTopInternal()1192 nsGlobalWindowOuter::GetInProcessScriptableTopInternal() {
1193   nsPIDOMWindowOuter* top = GetInProcessScriptableTop();
1194   return nsGlobalWindowOuter::Cast(top);
1195 }
1196 
GetContextInternal()1197 inline nsIScriptContext* nsGlobalWindowOuter::GetContextInternal() {
1198   return mContext;
1199 }
1200 
GetCurrentInnerWindowInternal()1201 inline nsGlobalWindowInner* nsGlobalWindowOuter::GetCurrentInnerWindowInternal()
1202     const {
1203   return nsGlobalWindowInner::Cast(mInnerWindow);
1204 }
1205 
EnsureInnerWindowInternal()1206 inline nsGlobalWindowInner* nsGlobalWindowOuter::EnsureInnerWindowInternal() {
1207   return nsGlobalWindowInner::Cast(EnsureInnerWindow());
1208 }
1209 
MaybeClearInnerWindow(nsGlobalWindowInner * aExpectedInner)1210 inline void nsGlobalWindowOuter::MaybeClearInnerWindow(
1211     nsGlobalWindowInner* aExpectedInner) {
1212   if (mInnerWindow == aExpectedInner) {
1213     mInnerWindow = nullptr;
1214   }
1215 }
1216 
1217 #endif /* nsGlobalWindowOuter_h___ */
1218