Bug 1750871 - run mochitest-remote on fission everywhere. r=releng-reviewers,aki
[gecko.git] / dom / base / nsGlobalWindowInner.h
blob89218aef259beaacbd1cba53e16b1cddff81500f
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/. */
7 #ifndef nsGlobalWindowInner_h___
8 #define nsGlobalWindowInner_h___
10 #include "nsPIDOMWindow.h"
12 #include "nsHashKeys.h"
13 #include "nsRefPtrHashtable.h"
14 #include "nsInterfaceHashtable.h"
16 // Local Includes
17 // Helper Classes
18 #include "nsCOMPtr.h"
19 #include "nsWeakReference.h"
20 #include "nsTHashMap.h"
21 #include "nsCycleCollectionParticipant.h"
23 // Interfaces Needed
24 #include "nsIBrowserDOMWindow.h"
25 #include "nsIInterfaceRequestor.h"
26 #include "nsIDOMChromeWindow.h"
27 #include "nsIScriptGlobalObject.h"
28 #include "nsIScriptObjectPrincipal.h"
29 #include "mozilla/EventListenerManager.h"
30 #include "nsIPrincipal.h"
31 #include "nsSize.h"
32 #include "mozilla/FlushType.h"
33 #include "prclist.h"
34 #include "mozilla/dom/BindingDeclarations.h"
35 #include "mozilla/dom/ChromeMessageBroadcaster.h"
36 #include "mozilla/dom/DebuggerNotificationManager.h"
37 #include "mozilla/dom/GamepadHandle.h"
38 #include "mozilla/dom/Location.h"
39 #include "mozilla/dom/NavigatorBinding.h"
40 #include "mozilla/dom/StorageEvent.h"
41 #include "mozilla/dom/StorageEventBinding.h"
42 #include "mozilla/dom/UnionTypes.h"
43 #include "mozilla/CallState.h"
44 #include "mozilla/Attributes.h"
45 #include "mozilla/LinkedList.h"
46 #include "mozilla/OwningNonNull.h"
47 #include "mozilla/StorageAccess.h"
48 #include "mozilla/TimeStamp.h"
49 #include "nsWrapperCacheInlines.h"
50 #include "mozilla/dom/EventTarget.h"
51 #include "mozilla/dom/WindowBinding.h"
52 #include "mozilla/dom/WindowProxyHolder.h"
53 #include "mozilla/glean/bindings/Glean.h"
54 #include "mozilla/glean/bindings/GleanPings.h"
55 #include "Units.h"
56 #include "nsComponentManagerUtils.h"
57 #include "nsSize.h"
58 #include "nsCheapSets.h"
59 #include "mozilla/dom/ImageBitmapBinding.h"
60 #include "mozilla/dom/ImageBitmapSource.h"
61 #include "mozilla/UniquePtr.h"
62 #include "nsRefreshObservers.h"
63 #include "nsThreadUtils.h"
65 class nsIArray;
66 class nsIBaseWindow;
67 class nsIContent;
68 class nsICSSDeclaration;
69 class nsIDocShellTreeOwner;
70 class nsIDOMWindowUtils;
71 class nsDOMOfflineResourceList;
72 class nsIScrollableFrame;
73 class nsIControllers;
74 class nsIScriptContext;
75 class nsIScriptTimeoutHandler;
76 class nsIBrowserChild;
77 class nsIPrintSettings;
78 class nsITimeoutHandler;
79 class nsIWebBrowserChrome;
80 class nsIWebProgressListener;
81 class mozIDOMWindowProxy;
83 class nsScreen;
84 class nsHistory;
85 class nsGlobalWindowObserver;
86 class nsGlobalWindowOuter;
87 class nsDOMWindowUtils;
88 class nsIUserIdleService;
89 struct nsRect;
91 class nsWindowSizes;
93 class IdleRequestExecutor;
95 class DialogValueHolder;
97 class PromiseDocumentFlushedResolver;
99 namespace mozilla {
100 class AbstractThread;
101 class ErrorResult;
103 namespace dom {
104 class BarProp;
105 class BrowsingContext;
106 struct ChannelPixelLayout;
107 class ClientSource;
108 class Console;
109 class Crypto;
110 class CustomElementRegistry;
111 class DocGroup;
112 class External;
113 class Function;
114 class Gamepad;
115 class ContentMediaController;
116 enum class ImageBitmapFormat : uint8_t;
117 class IdleRequest;
118 class IdleRequestCallback;
119 class IncrementalRunnable;
120 class InstallTriggerImpl;
121 class IntlUtils;
122 class MediaQueryList;
123 class OwningExternalOrWindowProxy;
124 class Promise;
125 class PostMessageEvent;
126 struct RequestInit;
127 class RequestOrUSVString;
128 class SharedWorker;
129 class Selection;
130 class SpeechSynthesis;
131 class Timeout;
132 class U2F;
133 class VisualViewport;
134 class VRDisplay;
135 enum class VRDisplayEventReason : uint8_t;
136 class VREventObserver;
137 class WakeLock;
138 #if defined(MOZ_WIDGET_ANDROID)
139 class WindowOrientationObserver;
140 #endif
141 struct WindowPostMessageOptions;
142 class Worklet;
143 namespace cache {
144 class CacheStorage;
145 } // namespace cache
146 class IDBFactory;
147 } // namespace dom
148 } // namespace mozilla
150 extern already_AddRefed<nsIScriptTimeoutHandler> NS_CreateJSTimeoutHandler(
151 JSContext* aCx, nsGlobalWindowInner* aWindow,
152 mozilla::dom::Function& aFunction,
153 const mozilla::dom::Sequence<JS::Value>& aArguments,
154 mozilla::ErrorResult& aError);
156 extern already_AddRefed<nsIScriptTimeoutHandler> NS_CreateJSTimeoutHandler(
157 JSContext* aCx, nsGlobalWindowInner* aWindow, const nsAString& aExpression,
158 mozilla::ErrorResult& aError);
160 extern const JSClass OuterWindowProxyClass;
162 //*****************************************************************************
163 // nsGlobalWindowInner: Global Object for Scripting
164 //*****************************************************************************
166 // nsGlobalWindowInner inherits PRCList for maintaining a list of all inner
167 // windows still in memory for any given outer window. This list is needed to
168 // ensure that mOuterWindow doesn't end up dangling. The nature of PRCList means
169 // that the window itself is always in the list, and an outer window's list will
170 // also contain all inner window objects that are still in memory (and in
171 // reality all inner window object's lists also contain its outer and all other
172 // inner windows belonging to the same outer window, but that's an unimportant
173 // side effect of inheriting PRCList).
175 class nsGlobalWindowInner final : public mozilla::dom::EventTarget,
176 public nsPIDOMWindowInner,
177 private nsIDOMWindow
178 // NOTE: This interface is private, as it's only
179 // implemented on chrome windows.
181 private nsIDOMChromeWindow,
182 public nsIScriptGlobalObject,
183 public nsIScriptObjectPrincipal,
184 public nsSupportsWeakReference,
185 public nsIInterfaceRequestor,
186 public PRCListStr {
187 public:
188 using RemoteProxy = mozilla::dom::BrowsingContext;
190 using TimeStamp = mozilla::TimeStamp;
191 using TimeDuration = mozilla::TimeDuration;
193 using InnerWindowByIdTable =
194 nsTHashMap<nsUint64HashKey, nsGlobalWindowInner*>;
196 static void AssertIsOnMainThread()
197 #ifdef DEBUG
199 #else
202 #endif
204 bool IsInnerWindow() const final { return true; } // Overriding EventTarget
206 static nsGlobalWindowInner* Cast(nsPIDOMWindowInner* aPIWin) {
207 return static_cast<nsGlobalWindowInner*>(aPIWin);
209 static const nsGlobalWindowInner* Cast(const nsPIDOMWindowInner* aPIWin) {
210 return static_cast<const nsGlobalWindowInner*>(aPIWin);
212 static nsGlobalWindowInner* Cast(mozIDOMWindow* aWin) {
213 return Cast(nsPIDOMWindowInner::From(aWin));
216 static nsGlobalWindowInner* GetInnerWindowWithId(uint64_t aInnerWindowID) {
217 AssertIsOnMainThread();
219 if (!sInnerWindowsById) {
220 return nullptr;
223 nsGlobalWindowInner* innerWindow = sInnerWindowsById->Get(aInnerWindowID);
224 return innerWindow;
227 static InnerWindowByIdTable* GetWindowsTable() {
228 AssertIsOnMainThread();
230 return sInnerWindowsById;
233 static nsGlobalWindowInner* FromSupports(nsISupports* supports) {
234 // Make sure this matches the casts we do in QueryInterface().
235 return (nsGlobalWindowInner*)(mozilla::dom::EventTarget*)supports;
238 static already_AddRefed<nsGlobalWindowInner> Create(
239 nsGlobalWindowOuter* aOuter, bool aIsChrome,
240 mozilla::dom::WindowGlobalChild* aActor);
242 // nsISupports
243 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
245 // nsWrapperCache
246 virtual JSObject* WrapObject(JSContext* cx,
247 JS::Handle<JSObject*> aGivenProto) override {
248 return GetWrapper();
251 // nsIGlobalObject
252 bool ShouldResistFingerprinting() const final;
253 uint32_t GetPrincipalHashValue() const final;
255 JSObject* GetGlobalJSObject() final { return GetWrapper(); }
256 JSObject* GetGlobalJSObjectPreserveColor() const final {
257 return GetWrapperPreserveColor();
259 // The HasJSGlobal on nsIGlobalObject ends up having to do a virtual
260 // call to GetGlobalJSObjectPreserveColor(), because when it's
261 // making the call it doesn't know it's doing it on an
262 // nsGlobalWindowInner. Add a version here that can be entirely
263 // non-virtual.
264 bool HasJSGlobal() const { return GetGlobalJSObjectPreserveColor(); }
266 void TraceGlobalJSObject(JSTracer* aTrc);
268 virtual nsresult EnsureScriptEnvironment() override;
270 virtual nsIScriptContext* GetScriptContext() override;
272 virtual bool IsBlackForCC(bool aTracingNeeded = true) override;
274 // nsIScriptObjectPrincipal
275 virtual nsIPrincipal* GetPrincipal() override;
277 virtual nsIPrincipal* GetEffectiveStoragePrincipal() override;
279 virtual nsIPrincipal* PartitionedPrincipal() override;
281 // nsIDOMWindow
282 NS_DECL_NSIDOMWINDOW
284 // nsIDOMChromeWindow (only implemented on chrome windows)
285 NS_DECL_NSIDOMCHROMEWINDOW
287 void CaptureEvents();
288 void ReleaseEvents();
289 void Dump(const nsAString& aStr);
290 void SetResizable(bool aResizable) const;
292 virtual mozilla::EventListenerManager* GetExistingListenerManager()
293 const override;
295 virtual mozilla::EventListenerManager* GetOrCreateListenerManager() override;
297 mozilla::Maybe<mozilla::dom::EventCallbackDebuggerNotificationType>
298 GetDebuggerNotificationType() const override;
300 bool ComputeDefaultWantsUntrusted(mozilla::ErrorResult& aRv) final;
302 virtual nsPIDOMWindowOuter* GetOwnerGlobalForBindingsInternal() override;
304 virtual nsIGlobalObject* GetOwnerGlobal() const override;
306 EventTarget* GetTargetForDOMEvent() override;
308 using mozilla::dom::EventTarget::DispatchEvent;
309 // TODO: Convert this to MOZ_CAN_RUN_SCRIPT (bug 1415230)
310 MOZ_CAN_RUN_SCRIPT_BOUNDARY bool DispatchEvent(
311 mozilla::dom::Event& aEvent, mozilla::dom::CallerType aCallerType,
312 mozilla::ErrorResult& aRv) override;
314 void GetEventTargetParent(mozilla::EventChainPreVisitor& aVisitor) override;
316 // TODO: Convert this to MOZ_CAN_RUN_SCRIPT (bug 1415230)
317 MOZ_CAN_RUN_SCRIPT_BOUNDARY nsresult
318 PostHandleEvent(mozilla::EventChainPostVisitor& aVisitor) override;
320 void Suspend(bool aIncludeSubWindows = true);
321 void Resume(bool aIncludeSubWindows = true);
322 virtual bool IsSuspended() const override;
324 // Calling Freeze() on a window will automatically Suspend() it. In
325 // addition, the window and its children (if aIncludeSubWindows is true) are
326 // further treated as no longer suitable for interaction with the user. For
327 // example, it may be marked non-visible, cannot be focused, etc. All worker
328 // threads are also frozen bringing them to a complete stop. A window can
329 // have Freeze() called multiple times and will only thaw after a matching
330 // number of Thaw() calls.
331 void Freeze(bool aIncludeSubWindows = true);
332 void Thaw(bool aIncludeSubWindows = true);
333 virtual bool IsFrozen() const override;
334 void SyncStateFromParentWindow();
336 // Called on the current inner window of a browsing context when its
337 // background state changes according to selected tab or visibility of the
338 // browser window. Used with Suspend()/Resume() or Freeze()/Thaw() because
339 // background state may change while the inner window is not current.
340 void UpdateBackgroundState();
342 mozilla::dom::DebuggerNotificationManager*
343 GetOrCreateDebuggerNotificationManager() override;
345 mozilla::dom::DebuggerNotificationManager*
346 GetExistingDebuggerNotificationManager() override;
348 mozilla::Maybe<mozilla::dom::ClientInfo> GetClientInfo() const override;
349 mozilla::Maybe<mozilla::dom::ClientState> GetClientState() const;
350 mozilla::Maybe<mozilla::dom::ServiceWorkerDescriptor> GetController()
351 const override;
353 void SetCsp(nsIContentSecurityPolicy* aCsp);
354 void SetPreloadCsp(nsIContentSecurityPolicy* aPreloadCsp);
355 nsIContentSecurityPolicy* GetCsp();
357 virtual RefPtr<mozilla::dom::ServiceWorker> GetOrCreateServiceWorker(
358 const mozilla::dom::ServiceWorkerDescriptor& aDescriptor) override;
360 RefPtr<mozilla::dom::ServiceWorkerRegistration> GetServiceWorkerRegistration(
361 const mozilla::dom::ServiceWorkerRegistrationDescriptor& aDescriptor)
362 const override;
364 RefPtr<mozilla::dom::ServiceWorkerRegistration>
365 GetOrCreateServiceWorkerRegistration(
366 const mozilla::dom::ServiceWorkerRegistrationDescriptor& aDescriptor)
367 override;
369 mozilla::StorageAccess GetStorageAccess() final;
371 void NoteCalledRegisterForServiceWorkerScope(const nsACString& aScope);
373 void NoteDOMContentLoaded();
375 virtual nsresult FireDelayedDOMEvents(bool aIncludeSubWindows) override;
377 virtual void MaybeUpdateTouchState() override;
379 // Inner windows only.
380 void RefreshRealmPrincipal();
382 // For accessing protected field mFullscreen
383 friend class FullscreenTransitionTask;
385 // Inner windows only.
386 virtual void SetHasGamepadEventListener(bool aHasGamepad = true) override;
387 void NotifyHasXRSession();
388 bool HasUsedVR() const;
389 bool IsVRContentDetected() const;
390 bool IsVRContentPresenting() const;
391 void RequestXRPermission();
392 void OnXRPermissionRequestAllow();
393 void OnXRPermissionRequestCancel();
395 using EventTarget::EventListenerAdded;
396 virtual void EventListenerAdded(nsAtom* aType) override;
397 using EventTarget::EventListenerRemoved;
398 virtual void EventListenerRemoved(nsAtom* aType) override;
400 // nsIInterfaceRequestor
401 NS_DECL_NSIINTERFACEREQUESTOR
403 // WebIDL interface.
404 mozilla::dom::Nullable<mozilla::dom::WindowProxyHolder> IndexedGetter(
405 uint32_t aIndex);
407 static bool IsPrivilegedChromeWindow(JSContext*, JSObject* aObj);
409 static bool IsRequestIdleCallbackEnabled(JSContext* aCx, JSObject*);
411 static bool DeviceSensorsEnabled(JSContext*, JSObject*);
413 static bool ContentPropertyEnabled(JSContext* aCx, JSObject*);
415 bool DoResolve(
416 JSContext* aCx, JS::Handle<JSObject*> aObj, JS::Handle<jsid> aId,
417 JS::MutableHandle<mozilla::Maybe<JS::PropertyDescriptor>> aDesc);
418 // The return value is whether DoResolve might end up resolving the given id.
419 // If in doubt, return true.
420 static bool MayResolve(jsid aId);
422 void GetOwnPropertyNames(JSContext* aCx, JS::MutableHandleVector<jsid> aNames,
423 bool aEnumerableOnly, mozilla::ErrorResult& aRv);
425 nsPIDOMWindowOuter* GetInProcessScriptableTop() override;
426 inline nsGlobalWindowOuter* GetInProcessTopInternal();
428 inline nsGlobalWindowOuter* GetInProcessScriptableTopInternal();
430 already_AddRefed<mozilla::dom::BrowsingContext> GetChildWindow(
431 const nsAString& aName);
433 inline nsIBrowserChild* GetBrowserChild() { return mBrowserChild.get(); }
435 nsIScriptContext* GetContextInternal();
437 nsGlobalWindowOuter* GetOuterWindowInternal() const;
439 bool IsChromeWindow() const { return mIsChrome; }
441 // GetScrollFrame does not flush. Callers should do it themselves as needed,
442 // depending on which info they actually want off the scrollable frame.
443 nsIScrollableFrame* GetScrollFrame();
445 nsresult Observe(nsISupports* aSubject, const char* aTopic,
446 const char16_t* aData);
448 void ObserveStorageNotification(mozilla::dom::StorageEvent* aEvent,
449 const char16_t* aStorageType,
450 bool aPrivateBrowsing);
452 static void Init();
453 static void ShutDown();
454 static bool IsCallerChrome();
456 friend class WindowStateHolder;
458 NS_DECL_CYCLE_COLLECTION_SKIPPABLE_SCRIPT_HOLDER_CLASS_AMBIGUOUS(
459 nsGlobalWindowInner, mozilla::dom::EventTarget)
461 #ifdef DEBUG
462 // Call Unlink on this window. This may cause bad things to happen, so use
463 // with caution.
464 void RiskyUnlink();
465 #endif
467 virtual bool TakeFocus(bool aFocus, uint32_t aFocusMethod) override;
468 virtual void SetReadyForFocus() override;
469 virtual void PageHidden() override;
470 virtual nsresult DispatchAsyncHashchange(nsIURI* aOldURI,
471 nsIURI* aNewURI) override;
472 virtual nsresult DispatchSyncPopState() override;
474 // Inner windows only.
475 virtual void EnableDeviceSensor(uint32_t aType) override;
476 virtual void DisableDeviceSensor(uint32_t aType) override;
478 #if defined(MOZ_WIDGET_ANDROID)
479 virtual void EnableOrientationChangeListener() override;
480 virtual void DisableOrientationChangeListener() override;
481 #endif
483 void AddSizeOfIncludingThis(nsWindowSizes& aWindowSizes) const;
485 void CollectDOMSizesForDataDocuments(nsWindowSizes&) const;
486 void RegisterDataDocumentForMemoryReporting(Document*);
487 void UnregisterDataDocumentForMemoryReporting(Document*);
489 enum SlowScriptResponse {
490 ContinueSlowScript = 0,
491 ContinueSlowScriptAndKeepNotifying,
492 AlwaysContinueSlowScript,
493 KillSlowScript,
494 KillScriptGlobal
496 SlowScriptResponse ShowSlowScriptDialog(JSContext* aCx,
497 const nsString& aAddonId,
498 const double aDuration);
500 // Inner windows only.
501 void AddGamepad(mozilla::dom::GamepadHandle aHandle,
502 mozilla::dom::Gamepad* aGamepad);
503 void RemoveGamepad(mozilla::dom::GamepadHandle aHandle);
504 void GetGamepads(nsTArray<RefPtr<mozilla::dom::Gamepad>>& aGamepads);
505 already_AddRefed<mozilla::dom::Gamepad> GetGamepad(
506 mozilla::dom::GamepadHandle aHandle);
507 void SetHasSeenGamepadInput(bool aHasSeen);
508 bool HasSeenGamepadInput();
509 void SyncGamepadState();
510 void StopGamepadHaptics();
512 // Inner windows only.
513 // Enable/disable updates for gamepad input.
514 void EnableGamepadUpdates();
515 void DisableGamepadUpdates();
517 // Inner windows only.
518 // Enable/disable updates for VR
519 void EnableVRUpdates();
520 void DisableVRUpdates();
521 // Reset telemetry data when switching windows.
522 // aUpdate, true for accumulating the result to the histogram.
523 // false for only resetting the timestamp.
524 void ResetVRTelemetry(bool aUpdate);
526 void StartVRActivity();
527 void StopVRActivity();
529 // Update the VR displays for this window
530 bool UpdateVRDisplays(nsTArray<RefPtr<mozilla::dom::VRDisplay>>& aDisplays);
532 // Inner windows only.
533 // Called to inform that the set of active VR displays has changed.
534 void NotifyActiveVRDisplaysChanged();
535 void NotifyDetectXRRuntimesCompleted();
536 void NotifyPresentationGenerationChanged(uint32_t aDisplayID);
538 void DispatchVRDisplayActivate(uint32_t aDisplayID,
539 mozilla::dom::VRDisplayEventReason aReason);
540 void DispatchVRDisplayDeactivate(uint32_t aDisplayID,
541 mozilla::dom::VRDisplayEventReason aReason);
542 void DispatchVRDisplayConnect(uint32_t aDisplayID);
543 void DispatchVRDisplayDisconnect(uint32_t aDisplayID);
544 void DispatchVRDisplayPresentChange(uint32_t aDisplayID);
546 #define EVENT(name_, id_, type_, struct_) \
547 mozilla::dom::EventHandlerNonNull* GetOn##name_() { \
548 mozilla::EventListenerManager* elm = GetExistingListenerManager(); \
549 return elm ? elm->GetEventHandler(nsGkAtoms::on##name_) : nullptr; \
551 void SetOn##name_(mozilla::dom::EventHandlerNonNull* handler) { \
552 mozilla::EventListenerManager* elm = GetOrCreateListenerManager(); \
553 if (elm) { \
554 elm->SetEventHandler(nsGkAtoms::on##name_, handler); \
557 #define ERROR_EVENT(name_, id_, type_, struct_) \
558 mozilla::dom::OnErrorEventHandlerNonNull* GetOn##name_() { \
559 mozilla::EventListenerManager* elm = GetExistingListenerManager(); \
560 return elm ? elm->GetOnErrorEventHandler() : nullptr; \
562 void SetOn##name_(mozilla::dom::OnErrorEventHandlerNonNull* handler) { \
563 mozilla::EventListenerManager* elm = GetOrCreateListenerManager(); \
564 if (elm) { \
565 elm->SetEventHandler(handler); \
568 #define BEFOREUNLOAD_EVENT(name_, id_, type_, struct_) \
569 mozilla::dom::OnBeforeUnloadEventHandlerNonNull* GetOn##name_() { \
570 mozilla::EventListenerManager* elm = GetExistingListenerManager(); \
571 return elm ? elm->GetOnBeforeUnloadEventHandler() : nullptr; \
573 void SetOn##name_( \
574 mozilla::dom::OnBeforeUnloadEventHandlerNonNull* handler) { \
575 mozilla::EventListenerManager* elm = GetOrCreateListenerManager(); \
576 if (elm) { \
577 elm->SetEventHandler(handler); \
580 #define WINDOW_ONLY_EVENT EVENT
581 #define TOUCH_EVENT EVENT
582 #include "mozilla/EventNameList.h"
583 #undef TOUCH_EVENT
584 #undef WINDOW_ONLY_EVENT
585 #undef BEFOREUNLOAD_EVENT
586 #undef ERROR_EVENT
587 #undef EVENT
589 nsISupports* GetParentObject() { return nullptr; }
591 static JSObject* CreateNamedPropertiesObject(JSContext* aCx,
592 JS::Handle<JSObject*> aProto);
594 mozilla::dom::WindowProxyHolder Window();
595 mozilla::dom::WindowProxyHolder Self() { return Window(); }
596 Document* GetDocument() { return GetDoc(); }
597 void GetName(nsAString& aName, mozilla::ErrorResult& aError);
598 void SetName(const nsAString& aName, mozilla::ErrorResult& aError);
599 mozilla::dom::Location* Location() override;
600 nsHistory* GetHistory(mozilla::ErrorResult& aError);
601 mozilla::dom::CustomElementRegistry* CustomElements() override;
602 mozilla::dom::CustomElementRegistry* GetExistingCustomElements();
603 mozilla::dom::BarProp* GetLocationbar(mozilla::ErrorResult& aError);
604 mozilla::dom::BarProp* GetMenubar(mozilla::ErrorResult& aError);
605 mozilla::dom::BarProp* GetPersonalbar(mozilla::ErrorResult& aError);
606 mozilla::dom::BarProp* GetScrollbars(mozilla::ErrorResult& aError);
607 mozilla::dom::BarProp* GetStatusbar(mozilla::ErrorResult& aError);
608 mozilla::dom::BarProp* GetToolbar(mozilla::ErrorResult& aError);
609 void GetStatus(nsAString& aStatus, mozilla::ErrorResult& aError);
610 void SetStatus(const nsAString& aStatus, mozilla::ErrorResult& aError);
611 void Close(mozilla::dom::CallerType aCallerType,
612 mozilla::ErrorResult& aError);
613 nsresult Close() override;
614 bool GetClosed(mozilla::ErrorResult& aError);
615 void Stop(mozilla::ErrorResult& aError);
616 void Focus(mozilla::dom::CallerType aCallerType,
617 mozilla::ErrorResult& aError);
618 nsresult Focus(mozilla::dom::CallerType aCallerType) override;
619 void Blur(mozilla::dom::CallerType aCallerType, mozilla::ErrorResult& aError);
620 mozilla::dom::WindowProxyHolder GetFrames(mozilla::ErrorResult& aError);
621 uint32_t Length();
622 mozilla::dom::Nullable<mozilla::dom::WindowProxyHolder> GetTop(
623 mozilla::ErrorResult& aError);
625 protected:
626 explicit nsGlobalWindowInner(nsGlobalWindowOuter* aOuterWindow,
627 mozilla::dom::WindowGlobalChild* aActor);
628 // Initializes the mWasOffline member variable
629 void InitWasOffline();
631 public:
632 mozilla::dom::Nullable<mozilla::dom::WindowProxyHolder> GetOpenerWindow(
633 mozilla::ErrorResult& aError);
634 void GetOpener(JSContext* aCx, JS::MutableHandle<JS::Value> aRetval,
635 mozilla::ErrorResult& aError);
636 void SetOpener(JSContext* aCx, JS::Handle<JS::Value> aOpener,
637 mozilla::ErrorResult& aError);
638 void GetEvent(JSContext* aCx, JS::MutableHandle<JS::Value> aRetval);
639 mozilla::dom::Nullable<mozilla::dom::WindowProxyHolder> GetParent(
640 mozilla::ErrorResult& aError);
641 nsPIDOMWindowOuter* GetInProcessScriptableParent() override;
642 mozilla::dom::Element* GetFrameElement(nsIPrincipal& aSubjectPrincipal,
643 mozilla::ErrorResult& aError);
644 mozilla::dom::Nullable<mozilla::dom::WindowProxyHolder> Open(
645 const nsAString& aUrl, const nsAString& aName, const nsAString& aOptions,
646 mozilla::ErrorResult& aError);
647 nsDOMOfflineResourceList* GetApplicationCache(mozilla::ErrorResult& aError);
648 nsDOMOfflineResourceList* GetApplicationCache() override;
650 #if defined(MOZ_WIDGET_ANDROID)
651 int16_t Orientation(mozilla::dom::CallerType aCallerType) const;
652 #endif
654 already_AddRefed<mozilla::dom::Console> GetConsole(JSContext* aCx,
655 mozilla::ErrorResult& aRv);
657 // https://w3c.github.io/webappsec-secure-contexts/#dom-window-issecurecontext
658 bool IsSecureContext() const;
660 void GetSidebar(mozilla::dom::OwningExternalOrWindowProxy& aResult,
661 mozilla::ErrorResult& aRv);
662 mozilla::dom::External* GetExternal(mozilla::ErrorResult& aRv);
664 mozilla::dom::Worklet* GetPaintWorklet(mozilla::ErrorResult& aRv);
666 void GetRegionalPrefsLocales(nsTArray<nsString>& aLocales);
668 void GetWebExposedLocales(nsTArray<nsString>& aLocales);
670 mozilla::dom::IntlUtils* GetIntlUtils(mozilla::ErrorResult& aRv);
672 void StoreSharedWorker(mozilla::dom::SharedWorker* aSharedWorker);
674 void ForgetSharedWorker(mozilla::dom::SharedWorker* aSharedWorker);
676 public:
677 void Alert(nsIPrincipal& aSubjectPrincipal, mozilla::ErrorResult& aError);
678 void Alert(const nsAString& aMessage, nsIPrincipal& aSubjectPrincipal,
679 mozilla::ErrorResult& aError);
680 bool Confirm(const nsAString& aMessage, nsIPrincipal& aSubjectPrincipal,
681 mozilla::ErrorResult& aError);
682 void Prompt(const nsAString& aMessage, const nsAString& aInitial,
683 nsAString& aReturn, nsIPrincipal& aSubjectPrincipal,
684 mozilla::ErrorResult& aError);
685 already_AddRefed<mozilla::dom::cache::CacheStorage> GetCaches(
686 mozilla::ErrorResult& aRv);
687 already_AddRefed<mozilla::dom::Promise> Fetch(
688 const mozilla::dom::RequestOrUSVString& aInput,
689 const mozilla::dom::RequestInit& aInit,
690 mozilla::dom::CallerType aCallerType, mozilla::ErrorResult& aRv);
691 void Print(mozilla::ErrorResult& aError);
692 mozilla::dom::Nullable<mozilla::dom::WindowProxyHolder> PrintPreview(
693 nsIPrintSettings*, nsIWebProgressListener*, nsIDocShell*,
694 mozilla::ErrorResult&);
695 void PostMessageMoz(JSContext* aCx, JS::Handle<JS::Value> aMessage,
696 const nsAString& aTargetOrigin,
697 const mozilla::dom::Sequence<JSObject*>& aTransfer,
698 nsIPrincipal& aSubjectPrincipal,
699 mozilla::ErrorResult& aError);
700 void PostMessageMoz(JSContext* aCx, JS::Handle<JS::Value> aMessage,
701 const mozilla::dom::WindowPostMessageOptions& aOptions,
702 nsIPrincipal& aSubjectPrincipal,
703 mozilla::ErrorResult& aError);
705 MOZ_CAN_RUN_SCRIPT
706 int32_t SetTimeout(JSContext* aCx, mozilla::dom::Function& aFunction,
707 int32_t aTimeout,
708 const mozilla::dom::Sequence<JS::Value>& aArguments,
709 mozilla::ErrorResult& aError);
711 MOZ_CAN_RUN_SCRIPT
712 int32_t SetTimeout(JSContext* aCx, const nsAString& aHandler,
713 int32_t aTimeout,
714 const mozilla::dom::Sequence<JS::Value>& /* unused */,
715 mozilla::ErrorResult& aError);
717 MOZ_CAN_RUN_SCRIPT
718 void ClearTimeout(int32_t aHandle);
720 MOZ_CAN_RUN_SCRIPT
721 int32_t SetInterval(JSContext* aCx, mozilla::dom::Function& aFunction,
722 const int32_t aTimeout,
723 const mozilla::dom::Sequence<JS::Value>& aArguments,
724 mozilla::ErrorResult& aError);
726 MOZ_CAN_RUN_SCRIPT
727 int32_t SetInterval(JSContext* aCx, const nsAString& aHandler,
728 const int32_t aTimeout,
729 const mozilla::dom::Sequence<JS::Value>& /* unused */,
730 mozilla::ErrorResult& aError);
732 MOZ_CAN_RUN_SCRIPT
733 void ClearInterval(int32_t aHandle);
734 void GetOrigin(nsAString& aOrigin);
736 MOZ_CAN_RUN_SCRIPT
737 void ReportError(JSContext* aCx, JS::Handle<JS::Value> aError,
738 mozilla::dom::CallerType aCallerType,
739 mozilla::ErrorResult& aRv);
741 void Atob(const nsAString& aAsciiBase64String, nsAString& aBinaryData,
742 mozilla::ErrorResult& aError);
743 void Btoa(const nsAString& aBinaryData, nsAString& aAsciiBase64String,
744 mozilla::ErrorResult& aError);
745 mozilla::dom::Storage* GetSessionStorage(mozilla::ErrorResult& aError);
746 mozilla::dom::Storage* GetLocalStorage(mozilla::ErrorResult& aError);
747 mozilla::dom::Selection* GetSelection(mozilla::ErrorResult& aError);
748 mozilla::dom::IDBFactory* GetIndexedDB(mozilla::ErrorResult& aError);
749 already_AddRefed<nsICSSDeclaration> GetComputedStyle(
750 mozilla::dom::Element& aElt, const nsAString& aPseudoElt,
751 mozilla::ErrorResult& aError) override;
752 mozilla::dom::VisualViewport* VisualViewport();
753 already_AddRefed<mozilla::dom::MediaQueryList> MatchMedia(
754 const nsACString& aQuery, mozilla::dom::CallerType aCallerType,
755 mozilla::ErrorResult& aError);
756 nsScreen* GetScreen(mozilla::ErrorResult& aError);
757 void MoveTo(int32_t aXPos, int32_t aYPos,
758 mozilla::dom::CallerType aCallerType,
759 mozilla::ErrorResult& aError);
760 void MoveBy(int32_t aXDif, int32_t aYDif,
761 mozilla::dom::CallerType aCallerType,
762 mozilla::ErrorResult& aError);
763 void ResizeTo(int32_t aWidth, int32_t aHeight,
764 mozilla::dom::CallerType aCallerType,
765 mozilla::ErrorResult& aError);
766 void ResizeBy(int32_t aWidthDif, int32_t aHeightDif,
767 mozilla::dom::CallerType aCallerType,
768 mozilla::ErrorResult& aError);
769 void Scroll(double aXScroll, double aYScroll);
770 void Scroll(const mozilla::dom::ScrollToOptions& aOptions);
771 void ScrollTo(double aXScroll, double aYScroll);
772 void ScrollTo(const mozilla::dom::ScrollToOptions& aOptions);
773 void ScrollBy(double aXScrollDif, double aYScrollDif);
774 void ScrollBy(const mozilla::dom::ScrollToOptions& aOptions);
775 void ScrollByLines(int32_t numLines,
776 const mozilla::dom::ScrollOptions& aOptions);
777 void ScrollByPages(int32_t numPages,
778 const mozilla::dom::ScrollOptions& aOptions);
779 void MozScrollSnap();
780 void GetInnerWidth(JSContext* aCx, JS::MutableHandle<JS::Value> aValue,
781 mozilla::dom::CallerType aCallerType,
782 mozilla::ErrorResult& aError);
783 void SetInnerWidth(JSContext* aCx, JS::Handle<JS::Value> aValue,
784 mozilla::dom::CallerType aCallerType,
785 mozilla::ErrorResult& aError);
786 void GetInnerHeight(JSContext* aCx, JS::MutableHandle<JS::Value> aValue,
787 mozilla::dom::CallerType aCallerType,
788 mozilla::ErrorResult& aError);
789 void SetInnerHeight(JSContext* aCx, JS::Handle<JS::Value> aValue,
790 mozilla::dom::CallerType aCallerType,
791 mozilla::ErrorResult& aError);
792 double GetScrollX(mozilla::ErrorResult& aError);
793 double GetPageXOffset(mozilla::ErrorResult& aError) {
794 return GetScrollX(aError);
796 double GetScrollY(mozilla::ErrorResult& aError);
797 double GetPageYOffset(mozilla::ErrorResult& aError) {
798 return GetScrollY(aError);
801 int32_t GetScreenLeft(mozilla::dom::CallerType aCallerType,
802 mozilla::ErrorResult& aError) {
803 return GetScreenX(aCallerType, aError);
806 int32_t GetScreenTop(mozilla::dom::CallerType aCallerType,
807 mozilla::ErrorResult& aError) {
808 return GetScreenY(aCallerType, aError);
811 void GetScreenX(JSContext* aCx, JS::MutableHandle<JS::Value> aValue,
812 mozilla::dom::CallerType aCallerType,
813 mozilla::ErrorResult& aError);
814 void SetScreenX(JSContext* aCx, JS::Handle<JS::Value> aValue,
815 mozilla::dom::CallerType aCallerType,
816 mozilla::ErrorResult& aError);
817 void GetScreenY(JSContext* aCx, JS::MutableHandle<JS::Value> aValue,
818 mozilla::dom::CallerType aCallerType,
819 mozilla::ErrorResult& aError);
820 void SetScreenY(JSContext* aCx, JS::Handle<JS::Value> aValue,
821 mozilla::dom::CallerType aCallerType,
822 mozilla::ErrorResult& aError);
823 void GetOuterWidth(JSContext* aCx, JS::MutableHandle<JS::Value> aValue,
824 mozilla::dom::CallerType aCallerType,
825 mozilla::ErrorResult& aError);
826 void SetOuterWidth(JSContext* aCx, JS::Handle<JS::Value> aValue,
827 mozilla::dom::CallerType aCallerType,
828 mozilla::ErrorResult& aError);
829 void GetOuterHeight(JSContext* aCx, JS::MutableHandle<JS::Value> aValue,
830 mozilla::dom::CallerType aCallerType,
831 mozilla::ErrorResult& aError);
832 void SetOuterHeight(JSContext* aCx, JS::Handle<JS::Value> aValue,
833 mozilla::dom::CallerType aCallerType,
834 mozilla::ErrorResult& aError);
836 MOZ_CAN_RUN_SCRIPT
837 int32_t RequestAnimationFrame(mozilla::dom::FrameRequestCallback& aCallback,
838 mozilla::ErrorResult& aError);
840 MOZ_CAN_RUN_SCRIPT
841 void CancelAnimationFrame(int32_t aHandle, mozilla::ErrorResult& aError);
843 uint32_t RequestIdleCallback(JSContext* aCx,
844 mozilla::dom::IdleRequestCallback& aCallback,
845 const mozilla::dom::IdleRequestOptions& aOptions,
846 mozilla::ErrorResult& aError);
847 void CancelIdleCallback(uint32_t aHandle);
849 #ifdef MOZ_WEBSPEECH
850 mozilla::dom::SpeechSynthesis* GetSpeechSynthesis(
851 mozilla::ErrorResult& aError);
852 bool HasActiveSpeechSynthesis();
853 #endif
855 mozilla::glean::Glean* Glean();
856 mozilla::glean::GleanPings* GleanPings();
858 already_AddRefed<nsICSSDeclaration> GetDefaultComputedStyle(
859 mozilla::dom::Element& aElt, const nsAString& aPseudoElt,
860 mozilla::ErrorResult& aError);
861 void SizeToContent(mozilla::dom::CallerType aCallerType,
862 mozilla::ErrorResult& aError);
863 mozilla::dom::Crypto* GetCrypto(mozilla::ErrorResult& aError);
864 mozilla::dom::U2F* GetU2f(mozilla::ErrorResult& aError);
865 nsIControllers* GetControllers(mozilla::ErrorResult& aError);
866 nsresult GetControllers(nsIControllers** aControllers) override;
867 mozilla::dom::Element* GetRealFrameElement(mozilla::ErrorResult& aError);
868 float GetMozInnerScreenX(mozilla::dom::CallerType aCallerType,
869 mozilla::ErrorResult& aError);
870 float GetMozInnerScreenY(mozilla::dom::CallerType aCallerType,
871 mozilla::ErrorResult& aError);
872 double GetDevicePixelRatio(mozilla::dom::CallerType aCallerType,
873 mozilla::ErrorResult& aError);
874 int32_t GetScrollMinX(mozilla::ErrorResult& aError);
875 int32_t GetScrollMinY(mozilla::ErrorResult& aError);
876 int32_t GetScrollMaxX(mozilla::ErrorResult& aError);
877 int32_t GetScrollMaxY(mozilla::ErrorResult& aError);
878 bool GetFullScreen(mozilla::ErrorResult& aError);
879 bool GetFullScreen() override;
880 void SetFullScreen(bool aFullscreen, mozilla::ErrorResult& aError);
881 bool Find(const nsAString& aString, bool aCaseSensitive, bool aBackwards,
882 bool aWrapAround, bool aWholeWord, bool aSearchInFrames,
883 bool aShowDialog, mozilla::ErrorResult& aError);
884 uint64_t GetMozPaintCount(mozilla::ErrorResult& aError);
886 bool DidFireDocElemInserted() const { return mDidFireDocElemInserted; }
887 void SetDidFireDocElemInserted() { mDidFireDocElemInserted = true; }
889 mozilla::dom::Nullable<mozilla::dom::WindowProxyHolder> OpenDialog(
890 JSContext* aCx, const nsAString& aUrl, const nsAString& aName,
891 const nsAString& aOptions,
892 const mozilla::dom::Sequence<JS::Value>& aExtraArgument,
893 mozilla::ErrorResult& aError);
894 void UpdateCommands(const nsAString& anAction, mozilla::dom::Selection* aSel,
895 int16_t aReason);
897 void GetContent(JSContext* aCx, JS::MutableHandle<JSObject*> aRetval,
898 mozilla::dom::CallerType aCallerType,
899 mozilla::ErrorResult& aError);
901 already_AddRefed<mozilla::dom::Promise> CreateImageBitmap(
902 const mozilla::dom::ImageBitmapSource& aImage,
903 const mozilla::dom::ImageBitmapOptions& aOptions,
904 mozilla::ErrorResult& aRv);
906 already_AddRefed<mozilla::dom::Promise> CreateImageBitmap(
907 const mozilla::dom::ImageBitmapSource& aImage, int32_t aSx, int32_t aSy,
908 int32_t aSw, int32_t aSh,
909 const mozilla::dom::ImageBitmapOptions& aOptions,
910 mozilla::ErrorResult& aRv);
912 void StructuredClone(JSContext* aCx, JS::Handle<JS::Value> aValue,
913 const mozilla::dom::StructuredSerializeOptions& aOptions,
914 JS::MutableHandle<JS::Value> aRetval,
915 mozilla::ErrorResult& aError);
917 // ChromeWindow bits. Do NOT call these unless your window is in
918 // fact chrome.
919 uint16_t WindowState();
920 bool IsFullyOccluded();
921 nsIBrowserDOMWindow* GetBrowserDOMWindow(mozilla::ErrorResult& aError);
922 void SetBrowserDOMWindow(nsIBrowserDOMWindow* aBrowserWindow,
923 mozilla::ErrorResult& aError);
924 void GetAttention(mozilla::ErrorResult& aError);
925 void GetAttentionWithCycleCount(int32_t aCycleCount,
926 mozilla::ErrorResult& aError);
927 void SetCursor(const nsACString& aCursor, mozilla::ErrorResult& aError);
928 void Maximize();
929 void Minimize();
930 void Restore();
931 void GetWorkspaceID(nsAString& workspaceID);
932 void MoveToWorkspace(const nsAString& workspaceID);
933 void NotifyDefaultButtonLoaded(mozilla::dom::Element& aDefaultButton,
934 mozilla::ErrorResult& aError);
935 mozilla::dom::ChromeMessageBroadcaster* MessageManager();
936 mozilla::dom::ChromeMessageBroadcaster* GetGroupMessageManager(
937 const nsAString& aGroup);
939 already_AddRefed<mozilla::dom::Promise> PromiseDocumentFlushed(
940 mozilla::dom::PromiseDocumentFlushedCallback& aCallback,
941 mozilla::ErrorResult& aError);
943 void GetReturnValueOuter(JSContext* aCx,
944 JS::MutableHandle<JS::Value> aReturnValue,
945 nsIPrincipal& aSubjectPrincipal,
946 mozilla::ErrorResult& aError);
947 void GetReturnValue(JSContext* aCx, JS::MutableHandle<JS::Value> aReturnValue,
948 nsIPrincipal& aSubjectPrincipal,
949 mozilla::ErrorResult& aError);
950 void SetReturnValueOuter(JSContext* aCx, JS::Handle<JS::Value> aReturnValue,
951 nsIPrincipal& aSubjectPrincipal,
952 mozilla::ErrorResult& aError);
953 void SetReturnValue(JSContext* aCx, JS::Handle<JS::Value> aReturnValue,
954 nsIPrincipal& aSubjectPrincipal,
955 mozilla::ErrorResult& aError);
957 void GetInterface(JSContext* aCx, JS::Handle<JS::Value> aIID,
958 JS::MutableHandle<JS::Value> aRetval,
959 mozilla::ErrorResult& aError);
961 already_AddRefed<nsWindowRoot> GetWindowRoot(mozilla::ErrorResult& aError);
963 bool ShouldReportForServiceWorkerScope(const nsAString& aScope);
965 mozilla::dom::InstallTriggerImpl* GetInstallTrigger();
967 nsIDOMWindowUtils* GetWindowUtils(mozilla::ErrorResult& aRv);
969 void UpdateTopInnerWindow();
971 virtual bool IsInSyncOperation() override;
973 // Early during inner window creation, `IsSharedMemoryAllowedInternal`
974 // is called before the `mDoc` field has been initialized in order to
975 // determine whether to expose the `SharedArrayBuffer` constructor on the
976 // JS global. We still want to consider the document's principal to see if
977 // it is a privileged extension which should be exposed to
978 // `SharedArrayBuffer`, however the inner window doesn't know the document's
979 // principal yet. `aPrincipalOverride` is used in that situation to provide
980 // the principal for the to-be-loaded document.
981 bool IsSharedMemoryAllowed() const override {
982 return IsSharedMemoryAllowedInternal(
983 const_cast<nsGlobalWindowInner*>(this)->GetPrincipal());
986 bool IsSharedMemoryAllowedInternal(nsIPrincipal* aPrincipal = nullptr) const;
988 // https://whatpr.org/html/4734/structured-data.html#cross-origin-isolated
989 bool CrossOriginIsolated() const override;
991 protected:
992 // Web IDL helpers
994 // Redefine the property called aPropName on this window object to be a value
995 // property with the value aValue, much like we would do for a [Replaceable]
996 // property in IDL.
997 void RedefineProperty(JSContext* aCx, const char* aPropName,
998 JS::Handle<JS::Value> aValue,
999 mozilla::ErrorResult& aError);
1001 // Implementation guts for our writable IDL attributes that are really
1002 // supposed to be readonly replaceable.
1003 template <typename T>
1004 using WindowCoordGetter = T (nsGlobalWindowInner::*)(
1005 mozilla::dom::CallerType aCallerType, mozilla::ErrorResult&);
1006 template <typename T>
1007 using WindowCoordSetter = void (nsGlobalWindowInner::*)(
1008 T, mozilla::dom::CallerType aCallerType, mozilla::ErrorResult&);
1010 template <typename T>
1011 void GetReplaceableWindowCoord(JSContext* aCx, WindowCoordGetter<T> aGetter,
1012 JS::MutableHandle<JS::Value> aRetval,
1013 mozilla::dom::CallerType aCallerType,
1014 mozilla::ErrorResult& aError);
1016 template <typename T>
1017 void SetReplaceableWindowCoord(JSContext* aCx, WindowCoordSetter<T> aSetter,
1018 JS::Handle<JS::Value> aValue,
1019 const char* aPropName,
1020 mozilla::dom::CallerType aCallerType,
1021 mozilla::ErrorResult& aError);
1022 // And the implementations of WindowCoordGetter/WindowCoordSetter.
1023 protected:
1024 double GetInnerWidth(mozilla::dom::CallerType aCallerType,
1025 mozilla::ErrorResult& aError);
1026 nsresult GetInnerWidth(double* aWidth) override;
1027 void SetInnerWidth(double aInnerWidth, mozilla::dom::CallerType aCallerType,
1028 mozilla::ErrorResult& aError);
1029 double GetInnerHeight(mozilla::dom::CallerType aCallerType,
1030 mozilla::ErrorResult& aError);
1031 nsresult GetInnerHeight(double* aHeight) override;
1032 void SetInnerHeight(double aInnerHeight, mozilla::dom::CallerType aCallerType,
1033 mozilla::ErrorResult& aError);
1034 int32_t GetScreenX(mozilla::dom::CallerType aCallerType,
1035 mozilla::ErrorResult& aError);
1036 void SetScreenX(int32_t aScreenX, mozilla::dom::CallerType aCallerType,
1037 mozilla::ErrorResult& aError);
1038 int32_t GetScreenY(mozilla::dom::CallerType aCallerType,
1039 mozilla::ErrorResult& aError);
1040 void SetScreenY(int32_t aScreenY, mozilla::dom::CallerType aCallerType,
1041 mozilla::ErrorResult& aError);
1042 int32_t GetOuterWidth(mozilla::dom::CallerType aCallerType,
1043 mozilla::ErrorResult& aError);
1044 void SetOuterWidth(int32_t aOuterWidth, mozilla::dom::CallerType aCallerType,
1045 mozilla::ErrorResult& aError);
1046 int32_t GetOuterHeight(mozilla::dom::CallerType aCallerType,
1047 mozilla::ErrorResult& aError);
1048 void SetOuterHeight(int32_t aOuterHeight,
1049 mozilla::dom::CallerType aCallerType,
1050 mozilla::ErrorResult& aError);
1052 RefPtr<mozilla::dom::WakeLock> mWakeLock;
1054 friend class HashchangeCallback;
1055 friend class mozilla::dom::BarProp;
1057 // Object Management
1058 virtual ~nsGlobalWindowInner();
1060 void FreeInnerObjects();
1062 // Initialize state that depends on the document. By this point, mDoc should
1063 // be set correctly and have us set as its script global object.
1064 void InitDocumentDependentState(JSContext* aCx);
1066 nsresult EnsureClientSource();
1067 nsresult ExecutionReady();
1069 // Inner windows only.
1070 nsresult DefineArgumentsProperty(nsIArray* aArguments);
1072 // Get the parent, returns null if this is a toplevel window
1073 nsPIDOMWindowOuter* GetInProcessParentInternal();
1075 private:
1076 template <typename Method, typename... Args>
1077 mozilla::CallState CallOnInProcessDescendantsInternal(
1078 mozilla::dom::BrowsingContext* aBrowsingContext, bool aChildOnly,
1079 Method aMethod, Args&&... aArgs);
1081 // Call the given method on the immediate children of this window. The
1082 // CallState returned by the last child method invocation is returned or
1083 // CallState::Continue if the method returns void.
1084 template <typename Method, typename... Args>
1085 mozilla::CallState CallOnInProcessChildren(Method aMethod, Args&&... aArgs) {
1086 MOZ_ASSERT(IsCurrentInnerWindow());
1087 return CallOnInProcessDescendantsInternal(GetBrowsingContext(), true,
1088 aMethod, aArgs...);
1091 // Call the given method on the descendant of this window. The CallState
1092 // returned by the last descendant method invocation is returned or
1093 // CallState::Continue if the method returns void.
1094 template <typename Method, typename... Args>
1095 mozilla::CallState CallOnInProcessDescendants(Method aMethod,
1096 Args&&... aArgs) {
1097 MOZ_ASSERT(IsCurrentInnerWindow());
1098 return CallOnInProcessDescendantsInternal(GetBrowsingContext(), false,
1099 aMethod, aArgs...);
1102 // Helper to convert a void returning child method into an implicit
1103 // CallState::Continue value.
1104 template <typename Return, typename Method, typename... Args>
1105 typename std::enable_if<std::is_void<Return>::value, mozilla::CallState>::type
1106 CallDescendant(nsGlobalWindowInner* aWindow, Method aMethod,
1107 Args&&... aArgs) {
1108 (aWindow->*aMethod)(aArgs...);
1109 return mozilla::CallState::Continue;
1112 // Helper that passes through the CallState value from a child method.
1113 template <typename Return, typename Method, typename... Args>
1114 typename std::enable_if<std::is_same<Return, mozilla::CallState>::value,
1115 mozilla::CallState>::type
1116 CallDescendant(nsGlobalWindowInner* aWindow, Method aMethod,
1117 Args&&... aArgs) {
1118 return (aWindow->*aMethod)(aArgs...);
1121 void FreezeInternal(bool aIncludeSubWindows);
1122 void ThawInternal(bool aIncludeSubWindows);
1124 mozilla::CallState ShouldReportForServiceWorkerScopeInternal(
1125 const nsACString& aScope, bool* aResultOut);
1127 public:
1128 // Timeout Functions
1129 // |interval| is in milliseconds.
1130 MOZ_CAN_RUN_SCRIPT
1131 int32_t SetTimeoutOrInterval(
1132 JSContext* aCx, mozilla::dom::Function& aFunction, int32_t aTimeout,
1133 const mozilla::dom::Sequence<JS::Value>& aArguments, bool aIsInterval,
1134 mozilla::ErrorResult& aError);
1136 MOZ_CAN_RUN_SCRIPT
1137 int32_t SetTimeoutOrInterval(JSContext* aCx, const nsAString& aHandler,
1138 int32_t aTimeout, bool aIsInterval,
1139 mozilla::ErrorResult& aError);
1141 // Return true if |aTimeout| was cleared while its handler ran.
1142 MOZ_CAN_RUN_SCRIPT
1143 bool RunTimeoutHandler(mozilla::dom::Timeout* aTimeout,
1144 nsIScriptContext* aScx);
1146 // Helper Functions
1147 already_AddRefed<nsIDocShellTreeOwner> GetTreeOwner();
1148 already_AddRefed<nsIWebBrowserChrome> GetWebBrowserChrome();
1149 bool IsPrivateBrowsing();
1151 void FireOfflineStatusEventIfChanged();
1153 public:
1154 // Inner windows only.
1155 nsresult FireHashchange(const nsAString& aOldURL, const nsAString& aNewURL);
1157 void FlushPendingNotifications(mozilla::FlushType aType);
1159 void ScrollTo(const mozilla::CSSIntPoint& aScroll,
1160 const mozilla::dom::ScrollOptions& aOptions);
1162 already_AddRefed<nsIWidget> GetMainWidget();
1163 nsIWidget* GetNearestWidget() const;
1165 bool IsInModalState();
1167 void SetFocusedElement(mozilla::dom::Element* aElement,
1168 uint32_t aFocusMethod = 0,
1169 bool aNeedsFocus = false) override;
1171 uint32_t GetFocusMethod() override;
1173 bool ShouldShowFocusRing() override;
1175 // Inner windows only.
1176 void UpdateCanvasFocus(bool aFocusChanged, nsIContent* aNewContent);
1178 public:
1179 virtual already_AddRefed<nsPIWindowRoot> GetTopWindowRoot() override;
1181 // Get the toplevel principal, returns null if this is a toplevel window.
1182 nsIPrincipal* GetTopLevelAntiTrackingPrincipal();
1184 // Get the client principal, returns null if the clientSource is not
1185 // available.
1186 nsIPrincipal* GetClientPrincipal();
1188 // This method is called if this window loads a 3rd party tracking resource
1189 // and the storage is just been granted. The window can reset the partitioned
1190 // storage objects and switch to the first party cookie jar.
1191 void StorageAccessPermissionGranted();
1193 protected:
1194 static void NotifyDOMWindowDestroyed(nsGlobalWindowInner* aWindow);
1195 void NotifyWindowIDDestroyed(const char* aTopic);
1197 static void NotifyDOMWindowFrozen(nsGlobalWindowInner* aWindow);
1198 static void NotifyDOMWindowThawed(nsGlobalWindowInner* aWindow);
1200 virtual void UpdateParentTarget() override;
1202 void InitializeShowFocusRings();
1204 // Clear the document-dependent slots on our JS wrapper. Inner windows only.
1205 void ClearDocumentDependentSlots(JSContext* aCx);
1207 // Inner windows only.
1208 already_AddRefed<mozilla::dom::StorageEvent> CloneStorageEvent(
1209 const nsAString& aType, const RefPtr<mozilla::dom::StorageEvent>& aEvent,
1210 mozilla::ErrorResult& aRv);
1212 protected:
1213 already_AddRefed<nsICSSDeclaration> GetComputedStyleHelper(
1214 mozilla::dom::Element& aElt, const nsAString& aPseudoElt,
1215 bool aDefaultStylesOnly, mozilla::ErrorResult& aError);
1217 nsGlobalWindowInner* InnerForSetTimeoutOrInterval(
1218 mozilla::ErrorResult& aError);
1220 void PostMessageMoz(JSContext* aCx, JS::Handle<JS::Value> aMessage,
1221 const nsAString& aTargetOrigin,
1222 JS::Handle<JS::Value> aTransfer,
1223 nsIPrincipal& aSubjectPrincipal,
1224 mozilla::ErrorResult& aError);
1226 private:
1227 // Fire the JS engine's onNewGlobalObject hook. Only used on inner windows.
1228 void FireOnNewGlobalObject();
1230 // Helper for resolving the components shim.
1231 bool ResolveComponentsShim(
1232 JSContext* aCx, JS::Handle<JSObject*> aObj,
1233 JS::MutableHandle<mozilla::Maybe<JS::PropertyDescriptor>> aDesc);
1235 // nsPIDOMWindow{Inner,Outer} should be able to see these helper methods.
1236 friend class nsPIDOMWindowInner;
1237 friend class nsPIDOMWindowOuter;
1239 bool IsBackgroundInternal() const;
1241 // NOTE: Chrome Only
1242 void DisconnectAndClearGroupMessageManagers() {
1243 MOZ_RELEASE_ASSERT(IsChromeWindow());
1244 for (const auto& entry : mChromeFields.mGroupMessageManagers) {
1245 mozilla::dom::ChromeMessageBroadcaster* mm = entry.GetWeak();
1246 if (mm) {
1247 mm->Disconnect();
1250 mChromeFields.mGroupMessageManagers.Clear();
1253 // Call mDocumentFlushedResolvers items, and perform MicroTask checkpoint
1254 // after that.
1256 // If aUntilExhaustion is true, then we call resolvers that get added as a
1257 // result synchronously, otherwise we wait until the next refresh driver tick.
1258 void CallDocumentFlushedResolvers(bool aUntilExhaustion);
1260 // Called after a refresh driver tick. See documentation of
1261 // CallDocumentFlushedResolvers for the meaning of aUntilExhaustion.
1263 // Returns whether we need to keep observing the refresh driver or not.
1264 bool MaybeCallDocumentFlushedResolvers(bool aUntilExhaustion);
1266 // Try to fire the "load" event on our content embedder if we're an iframe.
1267 MOZ_CAN_RUN_SCRIPT void FireFrameLoadEvent();
1269 void UpdateAutoplayPermission();
1270 void UpdateShortcutsPermission();
1271 void UpdatePopupPermission();
1273 void UpdatePermissions();
1275 public:
1276 static uint32_t GetShortcutsPermission(nsIPrincipal* aPrincipal);
1278 // Dispatch a runnable related to the global.
1279 virtual nsresult Dispatch(mozilla::TaskCategory aCategory,
1280 already_AddRefed<nsIRunnable>&& aRunnable) override;
1282 virtual nsISerialEventTarget* EventTargetFor(
1283 mozilla::TaskCategory aCategory) const override;
1285 virtual mozilla::AbstractThread* AbstractMainThreadFor(
1286 mozilla::TaskCategory aCategory) override;
1288 void DisableIdleCallbackRequests();
1289 uint32_t LastIdleRequestHandle() const {
1290 return mIdleRequestCallbackCounter - 1;
1292 MOZ_CAN_RUN_SCRIPT
1293 void RunIdleRequest(mozilla::dom::IdleRequest* aRequest,
1294 DOMHighResTimeStamp aDeadline, bool aDidTimeout);
1295 MOZ_CAN_RUN_SCRIPT
1296 void ExecuteIdleRequest(TimeStamp aDeadline);
1297 void ScheduleIdleRequestDispatch();
1298 void SuspendIdleRequests();
1299 void ResumeIdleRequests();
1301 using IdleRequests = mozilla::LinkedList<RefPtr<mozilla::dom::IdleRequest>>;
1302 void RemoveIdleCallback(mozilla::dom::IdleRequest* aRequest);
1304 void SetActiveLoadingState(bool aIsLoading) override;
1306 // Hint to the JS engine whether we are currently loading.
1307 void HintIsLoading(bool aIsLoading);
1309 mozilla::dom::ContentMediaController* GetContentMediaController();
1311 bool TryOpenExternalProtocolIframe() {
1312 if (mHasOpenedExternalProtocolFrame) {
1313 return false;
1315 mHasOpenedExternalProtocolFrame = true;
1316 return true;
1319 nsTArray<uint32_t>& GetScrollMarks() { return mScrollMarks; }
1320 void SetScrollMarks(const nsTArray<uint32_t>& aScrollMarks);
1322 // Don't use this value directly, call StorageAccess::StorageAllowedForWindow
1323 // instead.
1324 mozilla::Maybe<mozilla::StorageAccess> GetStorageAllowedCache(
1325 uint32_t& aRejectedReason) {
1326 if (mStorageAllowedCache.isSome()) {
1327 aRejectedReason = mStorageAllowedReasonCache;
1329 return mStorageAllowedCache;
1331 void SetStorageAllowedCache(const mozilla::StorageAccess& storageAllowed,
1332 uint32_t aRejectedReason) {
1333 mStorageAllowedCache = Some(storageAllowed);
1334 mStorageAllowedReasonCache = aRejectedReason;
1336 void ClearStorageAllowedCache() {
1337 mStorageAllowedCache = mozilla::Nothing();
1338 mStorageAllowedReasonCache = 0;
1341 private:
1342 RefPtr<mozilla::dom::ContentMediaController> mContentMediaController;
1344 protected:
1345 // Window offline status. Checked to see if we need to fire offline event
1346 bool mWasOffline : 1;
1348 // Represents whether the inner window's page has had a slow script notice.
1349 // Only used by inner windows; will always be false for outer windows.
1350 // This is used to implement Telemetry measures such as
1351 // SLOW_SCRIPT_PAGE_COUNT.
1352 bool mHasHadSlowScript : 1;
1354 // Fast way to tell if this is a chrome window (without having to QI).
1355 bool mIsChrome : 1;
1357 // Hack to indicate whether a chrome window needs its message manager
1358 // to be disconnected, since clean up code is shared in the global
1359 // window superclass.
1360 bool mCleanMessageManager : 1;
1362 // Indicates that the current document has never received a document focus
1363 // event.
1364 bool mNeedsFocus : 1;
1365 bool mHasFocus : 1;
1367 // true if tab navigation has occurred for this window. Focus rings
1368 // should be displayed.
1369 bool mFocusByKeyOccurred : 1;
1371 // True if we have notified document-element-inserted observers for this
1372 // document.
1373 bool mDidFireDocElemInserted : 1;
1375 // Indicates whether this window wants gamepad input events
1376 bool mHasGamepad : 1;
1378 // Indicates whether this window has content that has an XR session
1379 // An XR session results in enumeration and activation of XR devices.
1380 bool mHasXRSession : 1;
1382 // Indicates whether this window wants VRDisplayActivate events
1383 bool mHasVRDisplayActivateEvents : 1;
1385 // Indicates that a request for XR runtime detection has been
1386 // requested, but has not yet been resolved
1387 bool mXRRuntimeDetectionInFlight : 1;
1389 // Indicates that an XR permission request has been requested
1390 // but has not yet been resolved.
1391 bool mXRPermissionRequestInFlight : 1;
1393 // Indicates that an XR permission request has been granted.
1394 // The page should not request permission multiple times.
1395 bool mXRPermissionGranted : 1;
1397 // True if this was the currently-active inner window for a BrowsingContext at
1398 // the time it was discarded.
1399 bool mWasCurrentInnerWindow : 1;
1400 void SetWasCurrentInnerWindow() { mWasCurrentInnerWindow = true; }
1401 bool WasCurrentInnerWindow() const override { return mWasCurrentInnerWindow; }
1403 bool mHasSeenGamepadInput : 1;
1405 // Whether we told the JS engine that we were in pageload.
1406 bool mHintedWasLoading : 1;
1408 // Whether this window has opened an external-protocol iframe without user
1409 // activation once already. Only relevant for top windows.
1410 bool mHasOpenedExternalProtocolFrame : 1;
1412 nsCheapSet<nsUint32HashKey> mGamepadIndexSet;
1413 nsRefPtrHashtable<nsGenericHashKey<mozilla::dom::GamepadHandle>,
1414 mozilla::dom::Gamepad>
1415 mGamepads;
1417 RefPtr<nsScreen> mScreen;
1419 RefPtr<mozilla::dom::BarProp> mMenubar;
1420 RefPtr<mozilla::dom::BarProp> mToolbar;
1421 RefPtr<mozilla::dom::BarProp> mLocationbar;
1422 RefPtr<mozilla::dom::BarProp> mPersonalbar;
1423 RefPtr<mozilla::dom::BarProp> mStatusbar;
1424 RefPtr<mozilla::dom::BarProp> mScrollbars;
1426 RefPtr<nsGlobalWindowObserver> mObserver;
1427 RefPtr<mozilla::dom::Crypto> mCrypto;
1428 RefPtr<mozilla::dom::U2F> mU2F;
1429 RefPtr<mozilla::dom::cache::CacheStorage> mCacheStorage;
1430 RefPtr<mozilla::dom::Console> mConsole;
1431 RefPtr<mozilla::dom::Worklet> mPaintWorklet;
1432 RefPtr<mozilla::dom::External> mExternal;
1433 RefPtr<mozilla::dom::InstallTriggerImpl> mInstallTrigger;
1435 RefPtr<mozilla::dom::Storage> mLocalStorage;
1436 RefPtr<mozilla::dom::Storage> mSessionStorage;
1438 RefPtr<mozilla::EventListenerManager> mListenerManager;
1439 RefPtr<mozilla::dom::Location> mLocation;
1440 RefPtr<nsHistory> mHistory;
1441 RefPtr<mozilla::dom::CustomElementRegistry> mCustomElements;
1443 nsTObserverArray<RefPtr<mozilla::dom::SharedWorker>> mSharedWorkers;
1445 RefPtr<mozilla::dom::VisualViewport> mVisualViewport;
1447 // The document's principals and CSP are only stored if
1448 // FreeInnerObjects has been called.
1449 nsCOMPtr<nsIPrincipal> mDocumentPrincipal;
1450 nsCOMPtr<nsIPrincipal> mDocumentStoragePrincipal;
1451 nsCOMPtr<nsIPrincipal> mDocumentPartitionedPrincipal;
1452 nsCOMPtr<nsIContentSecurityPolicy> mDocumentCsp;
1454 // Used to cache the result of StorageAccess::StorageAllowedForWindow.
1455 // Don't use this field directly, use StorageAccess::StorageAllowedForWindow
1456 // instead.
1457 mozilla::Maybe<mozilla::StorageAccess> mStorageAllowedCache;
1458 uint32_t mStorageAllowedReasonCache;
1460 RefPtr<mozilla::dom::DebuggerNotificationManager>
1461 mDebuggerNotificationManager;
1463 // mBrowserChild is only ever populated in the content process.
1464 nsCOMPtr<nsIBrowserChild> mBrowserChild;
1466 uint32_t mSuspendDepth;
1467 uint32_t mFreezeDepth;
1469 #ifdef DEBUG
1470 uint32_t mSerial;
1471 #endif
1473 // the method that was used to focus mFocusedElement
1474 uint32_t mFocusMethod;
1476 // The current idle request callback handle
1477 uint32_t mIdleRequestCallbackCounter;
1478 IdleRequests mIdleRequestCallbacks;
1479 RefPtr<IdleRequestExecutor> mIdleRequestExecutor;
1481 #ifdef DEBUG
1482 nsCOMPtr<nsIURI> mLastOpenedURI;
1483 #endif
1485 RefPtr<nsDOMOfflineResourceList> mApplicationCache;
1487 RefPtr<mozilla::dom::IDBFactory> mIndexedDB;
1489 // This flag keeps track of whether this window is currently
1490 // observing refresh notifications from the refresh driver.
1491 bool mObservingRefresh;
1493 bool mIteratingDocumentFlushedResolvers;
1495 bool TryToObserveRefresh();
1497 nsTArray<uint32_t> mEnabledSensors;
1499 #if defined(MOZ_WIDGET_ANDROID)
1500 mozilla::UniquePtr<mozilla::dom::WindowOrientationObserver>
1501 mOrientationChangeObserver;
1502 #endif
1504 #ifdef MOZ_WEBSPEECH
1505 RefPtr<mozilla::dom::SpeechSynthesis> mSpeechSynthesis;
1506 #endif
1508 RefPtr<mozilla::glean::Glean> mGlean;
1509 RefPtr<mozilla::glean::GleanPings> mGleanPings;
1511 // This is the CC generation the last time we called CanSkip.
1512 uint32_t mCanSkipCCGeneration;
1514 // The VR Displays for this window
1515 nsTArray<RefPtr<mozilla::dom::VRDisplay>> mVRDisplays;
1517 RefPtr<mozilla::dom::VREventObserver> mVREventObserver;
1519 // The number of unload and beforeunload even listeners registered on this
1520 // window.
1521 uint64_t mUnloadOrBeforeUnloadListenerCount = 0;
1523 RefPtr<mozilla::dom::IntlUtils> mIntlUtils;
1525 mozilla::UniquePtr<mozilla::dom::ClientSource> mClientSource;
1527 nsTArray<mozilla::UniquePtr<PromiseDocumentFlushedResolver>>
1528 mDocumentFlushedResolvers;
1530 nsTArray<uint32_t> mScrollMarks;
1532 nsTArray<nsWeakPtr> mDataDocumentsForMemoryReporting;
1534 static InnerWindowByIdTable* sInnerWindowsById;
1536 // Members in the mChromeFields member should only be used in chrome windows.
1537 // All accesses to this field should be guarded by a check of mIsChrome.
1538 struct ChromeFields {
1539 RefPtr<mozilla::dom::ChromeMessageBroadcaster> mMessageManager;
1540 nsRefPtrHashtable<nsStringHashKey, mozilla::dom::ChromeMessageBroadcaster>
1541 mGroupMessageManagers{1};
1542 } mChromeFields;
1544 // These fields are used by the inner and outer windows to prevent
1545 // programatically moving the window while the mouse is down.
1546 static bool sMouseDown;
1547 static bool sDragServiceDisabled;
1549 friend class nsDOMScriptableHelper;
1550 friend class nsDOMWindowUtils;
1551 friend class mozilla::dom::PostMessageEvent;
1552 friend class DesktopNotification;
1553 friend class mozilla::dom::TimeoutManager;
1554 friend class IdleRequestExecutor;
1555 friend class nsGlobalWindowOuter;
1558 inline nsISupports* ToSupports(nsGlobalWindowInner* p) {
1559 return static_cast<mozilla::dom::EventTarget*>(p);
1562 inline nsISupports* ToCanonicalSupports(nsGlobalWindowInner* p) {
1563 return static_cast<mozilla::dom::EventTarget*>(p);
1566 // XXX: EWW - This is an awful hack - let's not do this
1567 #include "nsGlobalWindowOuter.h"
1569 inline nsIGlobalObject* nsGlobalWindowInner::GetOwnerGlobal() const {
1570 return const_cast<nsGlobalWindowInner*>(this);
1573 inline nsGlobalWindowOuter* nsGlobalWindowInner::GetInProcessTopInternal() {
1574 nsGlobalWindowOuter* outer = GetOuterWindowInternal();
1575 nsCOMPtr<nsPIDOMWindowOuter> top = outer ? outer->GetInProcessTop() : nullptr;
1576 if (top) {
1577 return nsGlobalWindowOuter::Cast(top);
1579 return nullptr;
1582 inline nsGlobalWindowOuter*
1583 nsGlobalWindowInner::GetInProcessScriptableTopInternal() {
1584 nsPIDOMWindowOuter* top = GetInProcessScriptableTop();
1585 return nsGlobalWindowOuter::Cast(top);
1588 inline nsIScriptContext* nsGlobalWindowInner::GetContextInternal() {
1589 if (mOuterWindow) {
1590 return GetOuterWindowInternal()->mContext;
1593 return nullptr;
1596 inline nsGlobalWindowOuter* nsGlobalWindowInner::GetOuterWindowInternal()
1597 const {
1598 return nsGlobalWindowOuter::Cast(GetOuterWindow());
1601 #endif /* nsGlobalWindowInner_h___ */