Backed out changeset 9d8b4c0b99ed (bug 1945683) for causing btime failures. CLOSED...
[gecko.git] / dom / base / nsGlobalWindowInner.h
blob416f295f264404fbedf73978148b18f0b1b36ae5
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"
14 // Local Includes
15 // Helper Classes
16 #include "mozilla/WeakPtr.h"
17 #include "nsCOMPtr.h"
18 #include "nsWeakReference.h"
19 #include "nsTHashMap.h"
20 #include "nsCycleCollectionParticipant.h"
22 // Interfaces Needed
23 #include "nsIBrowserDOMWindow.h"
24 #include "nsIInterfaceRequestor.h"
25 #include "nsIScriptGlobalObject.h"
26 #include "nsIScriptObjectPrincipal.h"
27 #include "mozilla/EventListenerManager.h"
28 #include "nsIPrincipal.h"
29 #include "nsSize.h"
30 #include "mozilla/FlushType.h"
31 #include "prclist.h"
32 #include "mozilla/dom/BindingDeclarations.h"
33 #include "mozilla/dom/ChromeMessageBroadcaster.h"
34 #include "mozilla/dom/DebuggerNotificationManager.h"
35 #include "mozilla/dom/GamepadHandle.h"
36 #include "mozilla/dom/Location.h"
37 #include "mozilla/dom/Promise.h"
38 #include "mozilla/dom/StorageEvent.h"
39 #include "mozilla/CallState.h"
40 #include "mozilla/Attributes.h"
41 #include "mozilla/LinkedList.h"
42 #include "mozilla/StorageAccess.h"
43 #include "mozilla/TimeStamp.h"
44 #include "nsWrapperCacheInlines.h"
45 #include "mozilla/dom/EventTarget.h"
46 #include "mozilla/dom/WindowBinding.h"
47 #include "mozilla/dom/WindowProxyHolder.h"
48 #include "Units.h"
49 #include "nsCheapSets.h"
50 #include "mozilla/dom/ImageBitmapBinding.h"
51 #include "mozilla/dom/ImageBitmapSource.h"
52 #include "mozilla/UniquePtr.h"
53 #include "nsThreadUtils.h"
54 #include "mozilla/MozPromise.h"
56 class nsIArray;
57 class nsIBaseWindow;
58 class nsIContent;
59 class nsICookieJarSettings;
60 class nsICSSDeclaration;
61 class nsIDocShellTreeOwner;
62 class nsIDOMWindowUtils;
63 class nsIControllers;
64 class nsIScriptContext;
65 class nsIScriptTimeoutHandler;
66 class nsIBrowserChild;
67 class nsIPrintSettings;
68 class nsITimeoutHandler;
69 class nsIWebBrowserChrome;
70 class nsIWebProgressListener;
71 class mozIDOMWindowProxy;
73 class nsScreen;
74 class nsHistory;
75 class nsGlobalWindowObserver;
76 class nsGlobalWindowOuter;
77 class nsDOMWindowUtils;
78 class nsIUserIdleService;
79 struct nsRect;
80 class nsWindowRoot;
81 class nsWindowSizes;
83 class IdleRequestExecutor;
85 class PromiseDocumentFlushedResolver;
87 namespace mozilla {
88 class AbstractThread;
89 class ScrollContainerFrame;
90 class ErrorResult;
92 namespace glean {
93 class Glean;
94 class GleanPings;
95 } // namespace glean
97 namespace hal {
98 enum class ScreenOrientation : uint32_t;
101 namespace dom {
102 class BarProp;
103 class BrowsingContext;
104 struct ChannelPixelLayout;
105 class Credential;
106 class ClientSource;
107 class Console;
108 class CookieStore;
109 class Crypto;
110 class CustomElementRegistry;
111 class DataTransfer;
112 class DocGroup;
113 class External;
114 class FunctionOrTrustedScriptOrString;
115 class Gamepad;
116 class ContentMediaController;
117 enum class ImageBitmapFormat : uint8_t;
118 class IdleRequest;
119 class IdleRequestCallback;
120 class InstallTriggerImpl;
121 class IntlUtils;
122 class MediaQueryList;
123 class Navigation;
124 class OwningExternalOrWindowProxy;
125 class Promise;
126 class PostMessageEvent;
127 struct RequestInit;
128 class RequestOrUTF8String;
129 class SharedWorker;
130 class Selection;
131 struct SizeToContentConstraints;
132 class WebTaskScheduler;
133 class WebTaskSchedulerMainThread;
134 class SpeechSynthesis;
135 class Timeout;
136 class TrustedTypePolicyFactory;
137 class VisualViewport;
138 class VRDisplay;
139 enum class VRDisplayEventReason : uint8_t;
140 class VREventObserver;
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 const JSClass OuterWindowProxyClass;
152 //*****************************************************************************
153 // nsGlobalWindowInner: Global Object for Scripting
154 //*****************************************************************************
156 // nsGlobalWindowInner inherits PRCList for maintaining a list of all inner
157 // windows still in memory for any given outer window. This list is needed to
158 // ensure that mOuterWindow doesn't end up dangling. The nature of PRCList means
159 // that the window itself is always in the list, and an outer window's list will
160 // also contain all inner window objects that are still in memory (and in
161 // reality all inner window object's lists also contain its outer and all other
162 // inner windows belonging to the same outer window, but that's an unimportant
163 // side effect of inheriting PRCList).
165 class nsGlobalWindowInner final : public mozilla::dom::EventTarget,
166 public nsPIDOMWindowInner,
167 private nsIDOMWindow,
168 public nsIScriptGlobalObject,
169 public nsIScriptObjectPrincipal,
170 public nsSupportsWeakReference,
171 public nsIInterfaceRequestor,
172 public PRCListStr {
173 public:
174 using RemoteProxy = mozilla::dom::BrowsingContext;
176 using TimeStamp = mozilla::TimeStamp;
177 using TimeDuration = mozilla::TimeDuration;
179 using InnerWindowByIdTable =
180 nsTHashMap<nsUint64HashKey, nsGlobalWindowInner*>;
182 static void AssertIsOnMainThread()
183 #ifdef DEBUG
185 #else
188 #endif
190 bool IsInnerWindow() const final { return true; } // Overriding EventTarget
192 static nsGlobalWindowInner* Cast(nsPIDOMWindowInner* aPIWin) {
193 return static_cast<nsGlobalWindowInner*>(aPIWin);
195 static const nsGlobalWindowInner* Cast(const nsPIDOMWindowInner* aPIWin) {
196 return static_cast<const nsGlobalWindowInner*>(aPIWin);
198 static nsGlobalWindowInner* Cast(mozIDOMWindow* aWin) {
199 return Cast(nsPIDOMWindowInner::From(aWin));
202 static nsGlobalWindowInner* GetInnerWindowWithId(uint64_t aInnerWindowID) {
203 AssertIsOnMainThread();
205 if (!sInnerWindowsById) {
206 return nullptr;
209 nsGlobalWindowInner* innerWindow = sInnerWindowsById->Get(aInnerWindowID);
210 return innerWindow;
213 static InnerWindowByIdTable* GetWindowsTable() {
214 AssertIsOnMainThread();
216 return sInnerWindowsById;
219 static nsGlobalWindowInner* FromSupports(nsISupports* supports) {
220 // Make sure this matches the casts we do in QueryInterface().
221 return (nsGlobalWindowInner*)(mozilla::dom::EventTarget*)supports;
224 static already_AddRefed<nsGlobalWindowInner> Create(
225 nsGlobalWindowOuter* aOuter, bool aIsChrome,
226 mozilla::dom::WindowGlobalChild* aActor);
228 // nsISupports
229 NS_DECL_ISUPPORTS_INHERITED
230 NS_IMETHOD_(void) DeleteCycleCollectable() override;
232 // nsWrapperCache
233 virtual JSObject* WrapObject(JSContext* cx,
234 JS::Handle<JSObject*> aGivenProto) override {
235 return GetWrapper();
238 // nsIGlobalObject
239 bool ShouldResistFingerprinting(RFPTarget aTarget) const final;
240 mozilla::OriginTrials Trials() const final;
241 mozilla::dom::FontFaceSet* GetFonts() final;
243 JSObject* GetGlobalJSObject() final { return GetWrapper(); }
244 JSObject* GetGlobalJSObjectPreserveColor() const final {
245 return GetWrapperPreserveColor();
247 // The HasJSGlobal on nsIGlobalObject ends up having to do a virtual
248 // call to GetGlobalJSObjectPreserveColor(), because when it's
249 // making the call it doesn't know it's doing it on an
250 // nsGlobalWindowInner. Add a version here that can be entirely
251 // non-virtual.
252 bool HasJSGlobal() const { return GetGlobalJSObjectPreserveColor(); }
254 mozilla::Result<mozilla::ipc::PrincipalInfo, nsresult> GetStorageKey()
255 override;
257 mozilla::dom::StorageManager* GetStorageManager() override;
259 bool IsEligibleForMessaging() override;
261 void ReportToConsole(uint32_t aErrorFlags, const nsCString& aCategory,
262 nsContentUtils::PropertiesFile aFile,
263 const nsCString& aMessageName,
264 const nsTArray<nsString>& aParams,
265 const mozilla::SourceLocation& aLocation) override;
267 void TraceGlobalJSObject(JSTracer* aTrc);
269 virtual nsresult EnsureScriptEnvironment() override;
271 virtual nsIScriptContext* GetScriptContext() override;
273 virtual bool IsBlackForCC(bool aTracingNeeded = true) override;
275 // nsIScriptObjectPrincipal
276 virtual nsIPrincipal* GetPrincipal() override;
278 virtual nsIPrincipal* GetEffectiveCookiePrincipal() override;
280 virtual nsIPrincipal* GetEffectiveStoragePrincipal() override;
282 virtual nsIPrincipal* PartitionedPrincipal() override;
284 mozilla::dom::TimeoutManager* GetTimeoutManager() override;
286 bool IsRunningTimeout() override;
288 // nsIDOMWindow
289 NS_DECL_NSIDOMWINDOW
291 void CaptureEvents();
292 void ReleaseEvents();
293 void Dump(const nsAString& aStr);
294 void SetResizable(bool aResizable) const;
296 virtual mozilla::EventListenerManager* GetExistingListenerManager()
297 const override;
299 virtual mozilla::EventListenerManager* GetOrCreateListenerManager() override;
301 mozilla::Maybe<mozilla::dom::EventCallbackDebuggerNotificationType>
302 GetDebuggerNotificationType() const override;
304 bool ComputeDefaultWantsUntrusted(mozilla::ErrorResult& aRv) final;
306 virtual nsPIDOMWindowOuter* GetOwnerGlobalForBindingsInternal() override;
308 virtual nsIGlobalObject* GetOwnerGlobal() const override;
310 EventTarget* GetTargetForDOMEvent() override;
312 using mozilla::dom::EventTarget::DispatchEvent;
313 // TODO: Convert this to MOZ_CAN_RUN_SCRIPT (bug 1415230)
314 MOZ_CAN_RUN_SCRIPT_BOUNDARY bool DispatchEvent(
315 mozilla::dom::Event& aEvent, mozilla::dom::CallerType aCallerType,
316 mozilla::ErrorResult& aRv) override;
318 void GetEventTargetParent(mozilla::EventChainPreVisitor& aVisitor) override;
320 // TODO: Convert this to MOZ_CAN_RUN_SCRIPT (bug 1415230)
321 MOZ_CAN_RUN_SCRIPT_BOUNDARY nsresult
322 PostHandleEvent(mozilla::EventChainPostVisitor& aVisitor) override;
324 void Suspend(bool aIncludeSubWindows = true);
325 void Resume(bool aIncludeSubWindows = true);
326 virtual bool IsSuspended() const override;
328 // Calling Freeze() on a window will automatically Suspend() it. In
329 // addition, the window and its children (if aIncludeSubWindows is true) are
330 // further treated as no longer suitable for interaction with the user. For
331 // example, it may be marked non-visible, cannot be focused, etc. All worker
332 // threads are also frozen bringing them to a complete stop. A window can
333 // have Freeze() called multiple times and will only thaw after a matching
334 // number of Thaw() calls.
335 void Freeze(bool aIncludeSubWindows = true);
336 void Thaw(bool aIncludeSubWindows = true);
337 virtual bool IsFrozen() const override;
338 virtual bool HasActiveIndexedDBDatabases() override;
339 virtual bool HasActivePeerConnections() override;
340 virtual bool HasOpenWebSockets() const override;
341 void SyncStateFromParentWindow();
343 // Called on the current inner window of a browsing context when its
344 // background state changes according to selected tab or visibility of the
345 // browser window. Used with Suspend()/Resume() or Freeze()/Thaw() because
346 // background state may change while the inner window is not current.
347 void UpdateBackgroundState();
349 mozilla::dom::DebuggerNotificationManager*
350 GetOrCreateDebuggerNotificationManager() override;
352 mozilla::dom::DebuggerNotificationManager*
353 GetExistingDebuggerNotificationManager() override;
355 nsIURI* GetBaseURI() const final;
357 mozilla::Maybe<mozilla::dom::ClientInfo> GetClientInfo() const override;
358 mozilla::Maybe<mozilla::dom::ClientState> GetClientState() const final;
359 mozilla::Maybe<mozilla::dom::ServiceWorkerDescriptor> GetController()
360 const override;
362 void SetCsp(nsIContentSecurityPolicy* aCsp);
363 void SetPreloadCsp(nsIContentSecurityPolicy* aPreloadCsp);
364 nsIContentSecurityPolicy* GetCsp();
366 virtual already_AddRefed<mozilla::dom::ServiceWorkerContainer>
367 GetServiceWorkerContainer() override;
369 virtual RefPtr<mozilla::dom::ServiceWorker> GetOrCreateServiceWorker(
370 const mozilla::dom::ServiceWorkerDescriptor& aDescriptor) override;
372 RefPtr<mozilla::dom::ServiceWorkerRegistration> GetServiceWorkerRegistration(
373 const mozilla::dom::ServiceWorkerRegistrationDescriptor& aDescriptor)
374 const override;
376 RefPtr<mozilla::dom::ServiceWorkerRegistration>
377 GetOrCreateServiceWorkerRegistration(
378 const mozilla::dom::ServiceWorkerRegistrationDescriptor& aDescriptor)
379 override;
381 mozilla::StorageAccess GetStorageAccess() final;
383 nsICookieJarSettings* GetCookieJarSettings() final;
385 void NoteCalledRegisterForServiceWorkerScope(const nsACString& aScope);
387 void NoteDOMContentLoaded();
389 virtual nsresult FireDelayedDOMEvents(bool aIncludeSubWindows) override;
391 virtual void MaybeUpdateTouchState() override;
393 // Inner windows only.
394 void RefreshRealmPrincipal();
395 void RefreshReduceTimerPrecisionCallerType();
397 // For accessing protected field mFullscreen
398 friend class FullscreenTransitionTask;
400 // Inner windows only.
401 virtual void SetHasGamepadEventListener(bool aHasGamepad = true) override;
402 void NotifyHasXRSession();
403 bool HasUsedVR() const;
404 bool IsVRContentDetected() const;
405 bool IsVRContentPresenting() const;
406 void RequestXRPermission();
407 void OnXRPermissionRequestAllow();
408 void OnXRPermissionRequestCancel();
410 using EventTarget::EventListenerAdded;
411 virtual void EventListenerAdded(nsAtom* aType) override;
412 using EventTarget::EventListenerRemoved;
413 virtual void EventListenerRemoved(nsAtom* aType) override;
415 // nsIInterfaceRequestor
416 NS_DECL_NSIINTERFACEREQUESTOR
418 // WebIDL interface.
419 mozilla::dom::Nullable<mozilla::dom::WindowProxyHolder> IndexedGetter(
420 uint32_t aIndex);
422 static bool IsPrivilegedChromeWindow(JSContext*, JSObject* aObj);
424 static bool DeviceSensorsEnabled(JSContext*, JSObject*);
426 static bool CachesEnabled(JSContext* aCx, JSObject*);
428 // WebIDL permission Func for whether Glean APIs are permitted.
429 static bool IsGleanNeeded(JSContext*, JSObject*);
431 bool DoResolve(
432 JSContext* aCx, JS::Handle<JSObject*> aObj, JS::Handle<jsid> aId,
433 JS::MutableHandle<mozilla::Maybe<JS::PropertyDescriptor>> aDesc);
434 // The return value is whether DoResolve might end up resolving the given id.
435 // If in doubt, return true.
436 static bool MayResolve(jsid aId);
438 void GetOwnPropertyNames(JSContext* aCx, JS::MutableHandleVector<jsid> aNames,
439 bool aEnumerableOnly, mozilla::ErrorResult& aRv);
441 nsPIDOMWindowOuter* GetInProcessScriptableTop() override;
442 inline nsGlobalWindowOuter* GetInProcessTopInternal();
444 inline nsGlobalWindowOuter* GetInProcessScriptableTopInternal();
446 already_AddRefed<mozilla::dom::BrowsingContext> GetChildWindow(
447 const nsAString& aName);
449 inline nsIBrowserChild* GetBrowserChild() { return mBrowserChild.get(); }
451 nsIScriptContext* GetContextInternal();
453 nsGlobalWindowOuter* GetOuterWindowInternal() const;
455 bool IsChromeWindow() const { return mIsChrome; }
457 // GetScrollContainerFrame does not flush. Callers should do it themselves as
458 // needed, depending on which info they actually want off the scroll container
459 // frame.
460 mozilla::ScrollContainerFrame* GetScrollContainerFrame();
462 nsresult Observe(nsISupports* aSubject, const char* aTopic,
463 const char16_t* aData);
465 void ObserveStorageNotification(mozilla::dom::StorageEvent* aEvent,
466 const char16_t* aStorageType,
467 bool aPrivateBrowsing);
469 static void Init();
470 static void ShutDown();
471 static bool IsCallerChrome();
473 friend class WindowStateHolder;
475 NS_DECL_CYCLE_COLLECTION_SKIPPABLE_SCRIPT_HOLDER_CLASS_AMBIGUOUS(
476 nsGlobalWindowInner, mozilla::dom::EventTarget)
478 #ifdef DEBUG
479 // Call Unlink on this window. This may cause bad things to happen, so use
480 // with caution.
481 void RiskyUnlink();
482 #endif
484 virtual bool TakeFocus(bool aFocus, uint32_t aFocusMethod) override;
485 MOZ_CAN_RUN_SCRIPT_BOUNDARY virtual void SetReadyForFocus() override;
486 MOZ_CAN_RUN_SCRIPT_BOUNDARY virtual void PageHidden(
487 bool aIsEnteringBFCache) override;
488 virtual nsresult DispatchAsyncHashchange(nsIURI* aOldURI,
489 nsIURI* aNewURI) override;
490 virtual nsresult DispatchSyncPopState() override;
492 // Inner windows only.
493 virtual void EnableDeviceSensor(uint32_t aType) override;
494 virtual void DisableDeviceSensor(uint32_t aType) override;
496 #if defined(MOZ_WIDGET_ANDROID)
497 virtual void EnableOrientationChangeListener() override;
498 virtual void DisableOrientationChangeListener() override;
499 #endif
501 void AddSizeOfIncludingThis(nsWindowSizes& aWindowSizes) const;
503 void CollectDOMSizesForDataDocuments(nsWindowSizes&) const;
504 void RegisterDataDocumentForMemoryReporting(Document*);
505 void UnregisterDataDocumentForMemoryReporting(Document*);
507 enum SlowScriptResponse {
508 ContinueSlowScript = 0,
509 ContinueSlowScriptAndKeepNotifying,
510 AlwaysContinueSlowScript,
511 KillSlowScript,
512 KillScriptGlobal
514 SlowScriptResponse ShowSlowScriptDialog(JSContext* aCx,
515 const nsString& aAddonId,
516 const double aDuration);
518 // Inner windows only.
519 void AddGamepad(mozilla::dom::GamepadHandle aHandle,
520 mozilla::dom::Gamepad* aGamepad);
521 void RemoveGamepad(mozilla::dom::GamepadHandle aHandle);
522 void GetGamepads(nsTArray<RefPtr<mozilla::dom::Gamepad>>& aGamepads);
523 already_AddRefed<mozilla::dom::Promise> RequestAllGamepads(
524 mozilla::ErrorResult& aRv);
525 already_AddRefed<mozilla::dom::Gamepad> GetGamepad(
526 mozilla::dom::GamepadHandle aHandle);
527 void SetHasSeenGamepadInput(bool aHasSeen);
528 bool HasSeenGamepadInput();
529 void SyncGamepadState();
530 void StopGamepadHaptics();
532 // Inner windows only.
533 // Enable/disable updates for gamepad input.
534 void EnableGamepadUpdates();
535 void DisableGamepadUpdates();
537 // Inner windows only.
538 // Enable/disable updates for VR
539 void EnableVRUpdates();
540 void DisableVRUpdates();
541 // Reset telemetry data when switching windows.
542 // aUpdate, true for accumulating the result to the histogram.
543 // false for only resetting the timestamp.
544 void ResetVRTelemetry(bool aUpdate);
546 void StartVRActivity();
547 void StopVRActivity();
549 // Update the VR displays for this window
550 bool UpdateVRDisplays(nsTArray<RefPtr<mozilla::dom::VRDisplay>>& aDisplays);
552 // Inner windows only.
553 // Called to inform that the set of active VR displays has changed.
554 void NotifyActiveVRDisplaysChanged();
555 void NotifyDetectXRRuntimesCompleted();
556 void NotifyPresentationGenerationChanged(uint32_t aDisplayID);
558 void DispatchVRDisplayActivate(uint32_t aDisplayID,
559 mozilla::dom::VRDisplayEventReason aReason);
560 void DispatchVRDisplayDeactivate(uint32_t aDisplayID,
561 mozilla::dom::VRDisplayEventReason aReason);
562 void DispatchVRDisplayConnect(uint32_t aDisplayID);
563 void DispatchVRDisplayDisconnect(uint32_t aDisplayID);
564 void DispatchVRDisplayPresentChange(uint32_t aDisplayID);
566 #define EVENT(name_, id_, type_, struct_) \
567 mozilla::dom::EventHandlerNonNull* GetOn##name_() { \
568 mozilla::EventListenerManager* elm = GetExistingListenerManager(); \
569 return elm ? elm->GetEventHandler(nsGkAtoms::on##name_) : nullptr; \
571 void SetOn##name_(mozilla::dom::EventHandlerNonNull* handler) { \
572 mozilla::EventListenerManager* elm = GetOrCreateListenerManager(); \
573 if (elm) { \
574 elm->SetEventHandler(nsGkAtoms::on##name_, handler); \
577 #define ERROR_EVENT(name_, id_, type_, struct_) \
578 mozilla::dom::OnErrorEventHandlerNonNull* GetOn##name_() { \
579 mozilla::EventListenerManager* elm = GetExistingListenerManager(); \
580 return elm ? elm->GetOnErrorEventHandler() : nullptr; \
582 void SetOn##name_(mozilla::dom::OnErrorEventHandlerNonNull* handler) { \
583 mozilla::EventListenerManager* elm = GetOrCreateListenerManager(); \
584 if (elm) { \
585 elm->SetEventHandler(handler); \
588 #define BEFOREUNLOAD_EVENT(name_, id_, type_, struct_) \
589 mozilla::dom::OnBeforeUnloadEventHandlerNonNull* GetOn##name_() { \
590 mozilla::EventListenerManager* elm = GetExistingListenerManager(); \
591 return elm ? elm->GetOnBeforeUnloadEventHandler() : nullptr; \
593 void SetOn##name_( \
594 mozilla::dom::OnBeforeUnloadEventHandlerNonNull* handler) { \
595 mozilla::EventListenerManager* elm = GetOrCreateListenerManager(); \
596 if (elm) { \
597 elm->SetEventHandler(handler); \
600 #define WINDOW_ONLY_EVENT EVENT
601 #define TOUCH_EVENT EVENT
602 #include "mozilla/EventNameList.h"
603 #undef TOUCH_EVENT
604 #undef WINDOW_ONLY_EVENT
605 #undef BEFOREUNLOAD_EVENT
606 #undef ERROR_EVENT
607 #undef EVENT
609 nsISupports* GetParentObject() { return nullptr; }
611 static JSObject* CreateNamedPropertiesObject(JSContext* aCx,
612 JS::Handle<JSObject*> aProto);
614 mozilla::dom::WindowProxyHolder Window();
615 mozilla::dom::WindowProxyHolder Self() { return Window(); }
616 Document* GetDocument() { return GetDoc(); }
617 void GetName(nsAString& aName, mozilla::ErrorResult& aError);
618 void SetName(const nsAString& aName, mozilla::ErrorResult& aError);
619 mozilla::dom::Location* Location() override;
620 nsHistory* GetHistory(mozilla::ErrorResult& aError);
621 mozilla::dom::Navigation* Navigation();
622 mozilla::dom::CustomElementRegistry* CustomElements() override;
623 mozilla::dom::CustomElementRegistry* GetExistingCustomElements();
624 mozilla::dom::BarProp* GetLocationbar(mozilla::ErrorResult& aError);
625 mozilla::dom::BarProp* GetMenubar(mozilla::ErrorResult& aError);
626 mozilla::dom::BarProp* GetPersonalbar(mozilla::ErrorResult& aError);
627 mozilla::dom::BarProp* GetScrollbars(mozilla::ErrorResult& aError);
628 mozilla::dom::BarProp* GetStatusbar(mozilla::ErrorResult& aError);
629 mozilla::dom::BarProp* GetToolbar(mozilla::ErrorResult& aError);
630 void GetStatus(nsAString& aStatus, mozilla::ErrorResult& aError);
631 void SetStatus(const nsAString& aStatus, mozilla::ErrorResult& aError);
632 void Close(mozilla::dom::CallerType aCallerType,
633 mozilla::ErrorResult& aError);
634 nsresult Close() override;
635 bool GetClosed(mozilla::ErrorResult& aError);
636 void Stop(mozilla::ErrorResult& aError);
637 void Focus(mozilla::dom::CallerType aCallerType,
638 mozilla::ErrorResult& aError);
639 nsresult Focus(mozilla::dom::CallerType aCallerType) override;
640 void Blur(mozilla::dom::CallerType aCallerType, mozilla::ErrorResult& aError);
641 mozilla::dom::WindowProxyHolder GetFrames(mozilla::ErrorResult& aError);
642 uint32_t Length();
643 mozilla::dom::Nullable<mozilla::dom::WindowProxyHolder> GetTop(
644 mozilla::ErrorResult& aError);
646 protected:
647 explicit nsGlobalWindowInner(nsGlobalWindowOuter* aOuterWindow,
648 mozilla::dom::WindowGlobalChild* aActor);
649 // Initializes the mWasOffline member variable
650 void InitWasOffline();
652 public:
653 mozilla::dom::Nullable<mozilla::dom::WindowProxyHolder> GetOpenerWindow(
654 mozilla::ErrorResult& aError);
655 void GetOpener(JSContext* aCx, JS::MutableHandle<JS::Value> aRetval,
656 mozilla::ErrorResult& aError);
657 void SetOpener(JSContext* aCx, JS::Handle<JS::Value> aOpener,
658 mozilla::ErrorResult& aError);
659 void GetEvent(mozilla::dom::OwningEventOrUndefined& aRetval);
660 mozilla::dom::Nullable<mozilla::dom::WindowProxyHolder> GetParent(
661 mozilla::ErrorResult& aError);
662 nsPIDOMWindowOuter* GetInProcessScriptableParent() override;
663 mozilla::dom::Element* GetFrameElement(nsIPrincipal& aSubjectPrincipal,
664 mozilla::ErrorResult& aError);
665 mozilla::dom::Nullable<mozilla::dom::WindowProxyHolder> Open(
666 const nsAString& aUrl, const nsAString& aName, const nsAString& aOptions,
667 mozilla::ErrorResult& aError);
668 int16_t Orientation(mozilla::dom::CallerType aCallerType);
670 already_AddRefed<mozilla::dom::Console> GetConsole(JSContext* aCx,
671 mozilla::ErrorResult& aRv);
673 already_AddRefed<mozilla::dom::CookieStore> CookieStore();
675 // https://w3c.github.io/webappsec-secure-contexts/#dom-window-issecurecontext
676 bool IsSecureContext() const;
678 mozilla::dom::External* External();
680 mozilla::dom::Worklet* GetPaintWorklet(mozilla::ErrorResult& aRv);
682 void GetRegionalPrefsLocales(nsTArray<nsString>& aLocales);
684 void GetWebExposedLocales(nsTArray<nsString>& aLocales);
686 mozilla::dom::IntlUtils* GetIntlUtils(mozilla::ErrorResult& aRv);
688 void StoreSharedWorker(mozilla::dom::SharedWorker* aSharedWorker);
690 void ForgetSharedWorker(mozilla::dom::SharedWorker* aSharedWorker);
692 public:
693 void Alert(nsIPrincipal& aSubjectPrincipal, mozilla::ErrorResult& aError);
694 void Alert(const nsAString& aMessage, nsIPrincipal& aSubjectPrincipal,
695 mozilla::ErrorResult& aError);
696 bool Confirm(const nsAString& aMessage, nsIPrincipal& aSubjectPrincipal,
697 mozilla::ErrorResult& aError);
698 void Prompt(const nsAString& aMessage, const nsAString& aInitial,
699 nsAString& aReturn, nsIPrincipal& aSubjectPrincipal,
700 mozilla::ErrorResult& aError);
701 already_AddRefed<mozilla::dom::cache::CacheStorage> GetCaches(
702 mozilla::ErrorResult& aRv);
703 already_AddRefed<mozilla::dom::Promise> Fetch(
704 const mozilla::dom::RequestOrUTF8String& aInput,
705 const mozilla::dom::RequestInit& aInit,
706 mozilla::dom::CallerType aCallerType, mozilla::ErrorResult& aRv);
707 MOZ_CAN_RUN_SCRIPT void Print(mozilla::ErrorResult& aError);
708 MOZ_CAN_RUN_SCRIPT mozilla::dom::Nullable<mozilla::dom::WindowProxyHolder>
709 PrintPreview(nsIPrintSettings*, nsIWebProgressListener*, nsIDocShell*,
710 mozilla::ErrorResult&);
711 void PostMessageMoz(JSContext* aCx, JS::Handle<JS::Value> aMessage,
712 const nsAString& aTargetOrigin,
713 const mozilla::dom::Sequence<JSObject*>& aTransfer,
714 nsIPrincipal& aSubjectPrincipal,
715 mozilla::ErrorResult& aError);
716 void PostMessageMoz(JSContext* aCx, JS::Handle<JS::Value> aMessage,
717 const mozilla::dom::WindowPostMessageOptions& aOptions,
718 nsIPrincipal& aSubjectPrincipal,
719 mozilla::ErrorResult& aError);
721 MOZ_CAN_RUN_SCRIPT
722 int32_t SetTimeout(
723 JSContext* aCx,
724 const mozilla::dom::FunctionOrTrustedScriptOrString& aHandler,
725 int32_t aTimeout, const mozilla::dom::Sequence<JS::Value>& /* unused */,
726 mozilla::ErrorResult& aError);
728 MOZ_CAN_RUN_SCRIPT
729 void ClearTimeout(int32_t aHandle);
731 MOZ_CAN_RUN_SCRIPT
732 int32_t SetInterval(
733 JSContext* aCx,
734 const mozilla::dom::FunctionOrTrustedScriptOrString& aHandler,
735 const int32_t aTimeout,
736 const mozilla::dom::Sequence<JS::Value>& /* unused */,
737 mozilla::ErrorResult& aError);
739 MOZ_CAN_RUN_SCRIPT
740 void ClearInterval(int32_t aHandle);
741 void GetOrigin(nsAString& aOrigin);
743 MOZ_CAN_RUN_SCRIPT
744 void ReportError(JSContext* aCx, JS::Handle<JS::Value> aError,
745 mozilla::dom::CallerType aCallerType,
746 mozilla::ErrorResult& aRv);
748 void Atob(const nsAString& aAsciiBase64String, nsAString& aBinaryData,
749 mozilla::ErrorResult& aError);
750 void Btoa(const nsAString& aBinaryData, nsAString& aAsciiBase64String,
751 mozilla::ErrorResult& aError);
753 void MaybeNotifyStorageKeyUsed();
755 mozilla::dom::Storage* GetSessionStorage(mozilla::ErrorResult& aError);
756 mozilla::dom::Storage* GetLocalStorage(mozilla::ErrorResult& aError);
757 mozilla::dom::Selection* GetSelection(mozilla::ErrorResult& aError);
758 mozilla::dom::IDBFactory* GetIndexedDB(JSContext* aCx,
759 mozilla::ErrorResult& aError);
760 already_AddRefed<nsICSSDeclaration> GetComputedStyle(
761 mozilla::dom::Element& aElt, const nsAString& aPseudoElt,
762 mozilla::ErrorResult& aError) override;
763 mozilla::dom::VisualViewport* VisualViewport();
764 already_AddRefed<mozilla::dom::MediaQueryList> MatchMedia(
765 const nsACString& aQuery, mozilla::dom::CallerType aCallerType,
766 mozilla::ErrorResult& aError);
767 nsScreen* Screen();
768 void MoveTo(int32_t aXPos, int32_t aYPos,
769 mozilla::dom::CallerType aCallerType,
770 mozilla::ErrorResult& aError);
771 void MoveBy(int32_t aXDif, int32_t aYDif,
772 mozilla::dom::CallerType aCallerType,
773 mozilla::ErrorResult& aError);
774 void ResizeTo(int32_t aWidth, int32_t aHeight,
775 mozilla::dom::CallerType aCallerType,
776 mozilla::ErrorResult& aError);
777 void ResizeBy(int32_t aWidthDif, int32_t aHeightDif,
778 mozilla::dom::CallerType aCallerType,
779 mozilla::ErrorResult& aError);
780 void Scroll(double aXScroll, double aYScroll) {
781 ScrollTo(aXScroll, aYScroll);
783 void Scroll(const mozilla::dom::ScrollToOptions& aOptions) {
784 ScrollTo(aOptions);
786 void ScrollTo(double aXScroll, double aYScroll);
787 void ScrollTo(const mozilla::dom::ScrollToOptions& aOptions);
788 void ScrollBy(double aXScrollDif, double aYScrollDif);
789 void ScrollBy(const mozilla::dom::ScrollToOptions& aOptions);
790 void ScrollByLines(int32_t numLines,
791 const mozilla::dom::ScrollOptions& aOptions);
792 void ScrollByPages(int32_t numPages,
793 const mozilla::dom::ScrollOptions& aOptions);
794 void MozScrollSnap();
795 double GetScrollX(mozilla::ErrorResult& aError);
796 double GetPageXOffset(mozilla::ErrorResult& aError) {
797 return GetScrollX(aError);
799 double GetScrollY(mozilla::ErrorResult& aError);
800 double GetPageYOffset(mozilla::ErrorResult& aError) {
801 return GetScrollY(aError);
804 int32_t GetScreenLeft(mozilla::dom::CallerType aCallerType,
805 mozilla::ErrorResult& aError) {
806 return GetScreenX(aCallerType, aError);
809 double ScreenEdgeSlopX() const;
810 double ScreenEdgeSlopY() const;
812 int32_t GetScreenTop(mozilla::dom::CallerType aCallerType,
813 mozilla::ErrorResult& aError) {
814 return GetScreenY(aCallerType, aError);
817 void GetScreenX(JSContext* aCx, JS::MutableHandle<JS::Value> aValue,
818 mozilla::dom::CallerType aCallerType,
819 mozilla::ErrorResult& aError);
820 void GetScreenY(JSContext* aCx, JS::MutableHandle<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 GetOuterHeight(JSContext* aCx, JS::MutableHandle<JS::Value> aValue,
827 mozilla::dom::CallerType aCallerType,
828 mozilla::ErrorResult& aError);
830 MOZ_CAN_RUN_SCRIPT
831 uint32_t RequestAnimationFrame(mozilla::dom::FrameRequestCallback& aCallback,
832 mozilla::ErrorResult& aError);
834 MOZ_CAN_RUN_SCRIPT
835 void CancelAnimationFrame(uint32_t aHandle, mozilla::ErrorResult& aError);
837 uint32_t RequestIdleCallback(JSContext* aCx,
838 mozilla::dom::IdleRequestCallback& aCallback,
839 const mozilla::dom::IdleRequestOptions& aOptions,
840 mozilla::ErrorResult& aError);
841 void CancelIdleCallback(uint32_t aHandle);
843 #ifdef MOZ_WEBSPEECH
844 mozilla::dom::SpeechSynthesis* GetSpeechSynthesis(
845 mozilla::ErrorResult& aError);
846 bool HasActiveSpeechSynthesis();
847 #endif
849 mozilla::glean::Glean* Glean();
850 mozilla::glean::GleanPings* GleanPings();
852 already_AddRefed<nsICSSDeclaration> GetDefaultComputedStyle(
853 mozilla::dom::Element& aElt, const nsAString& aPseudoElt,
854 mozilla::ErrorResult& aError);
855 void SizeToContent(const mozilla::dom::SizeToContentConstraints&,
856 mozilla::ErrorResult&);
857 mozilla::dom::Crypto* GetCrypto(mozilla::ErrorResult& aError);
858 nsIControllers* GetControllers(mozilla::ErrorResult& aError);
859 nsresult GetControllers(nsIControllers** aControllers) override;
860 mozilla::dom::Element* GetRealFrameElement(mozilla::ErrorResult& aError);
861 float GetMozInnerScreenX(mozilla::dom::CallerType aCallerType,
862 mozilla::ErrorResult& aError);
863 float GetMozInnerScreenY(mozilla::dom::CallerType aCallerType,
864 mozilla::ErrorResult& aError);
865 double GetDevicePixelRatio(mozilla::dom::CallerType aCallerType,
866 mozilla::ErrorResult& aError);
867 double GetDesktopToDeviceScale(mozilla::ErrorResult& aError);
868 int32_t GetScrollMinX(mozilla::ErrorResult& aError);
869 int32_t GetScrollMinY(mozilla::ErrorResult& aError);
870 int32_t GetScrollMaxX(mozilla::ErrorResult& aError);
871 int32_t GetScrollMaxY(mozilla::ErrorResult& aError);
872 bool GetFullScreen(mozilla::ErrorResult& aError);
873 bool GetFullScreen() override;
874 void SetFullScreen(bool aFullscreen, mozilla::ErrorResult& aError);
875 bool Find(const nsAString& aString, bool aCaseSensitive, bool aBackwards,
876 bool aWrapAround, bool aWholeWord, bool aSearchInFrames,
877 bool aShowDialog, mozilla::ErrorResult& aError);
879 bool DidFireDocElemInserted() const { return mDidFireDocElemInserted; }
880 void SetDidFireDocElemInserted() { mDidFireDocElemInserted = true; }
882 mozilla::dom::Nullable<mozilla::dom::WindowProxyHolder> OpenDialog(
883 JSContext* aCx, const nsAString& aUrl, const nsAString& aName,
884 const nsAString& aOptions,
885 const mozilla::dom::Sequence<JS::Value>& aExtraArgument,
886 mozilla::ErrorResult& aError);
887 void UpdateCommands(const nsAString& anAction);
889 void GetContent(JSContext* aCx, JS::MutableHandle<JSObject*> aRetval,
890 mozilla::dom::CallerType aCallerType,
891 mozilla::ErrorResult& aError);
893 already_AddRefed<mozilla::dom::Promise> CreateImageBitmap(
894 const mozilla::dom::ImageBitmapSource& aImage,
895 const mozilla::dom::ImageBitmapOptions& aOptions,
896 mozilla::ErrorResult& aRv);
898 already_AddRefed<mozilla::dom::Promise> CreateImageBitmap(
899 const mozilla::dom::ImageBitmapSource& aImage, int32_t aSx, int32_t aSy,
900 int32_t aSw, int32_t aSh,
901 const mozilla::dom::ImageBitmapOptions& aOptions,
902 mozilla::ErrorResult& aRv);
904 void StructuredClone(JSContext* aCx, JS::Handle<JS::Value> aValue,
905 const mozilla::dom::StructuredSerializeOptions& aOptions,
906 JS::MutableHandle<JS::Value> aRetval,
907 mozilla::ErrorResult& aError);
909 // ChromeWindow bits. Do NOT call these unless your window is in
910 // fact chrome.
911 uint16_t WindowState();
912 bool IsFullyOccluded();
913 nsIBrowserDOMWindow* GetBrowserDOMWindow(mozilla::ErrorResult& aError);
914 void SetBrowserDOMWindow(nsIBrowserDOMWindow* aBrowserWindow,
915 mozilla::ErrorResult& aError);
916 void GetAttention(mozilla::ErrorResult& aError);
917 void GetAttentionWithCycleCount(int32_t aCycleCount,
918 mozilla::ErrorResult& aError);
919 void SetCursor(const nsACString& aCursor, mozilla::ErrorResult& aError);
920 void Maximize();
921 void Minimize();
922 void Restore();
923 void GetWorkspaceID(nsAString& workspaceID);
924 void MoveToWorkspace(const nsAString& workspaceID);
925 void NotifyDefaultButtonLoaded(mozilla::dom::Element& aDefaultButton,
926 mozilla::ErrorResult& aError);
927 mozilla::dom::ChromeMessageBroadcaster* MessageManager();
928 mozilla::dom::ChromeMessageBroadcaster* GetGroupMessageManager(
929 const nsAString& aGroup);
931 already_AddRefed<mozilla::dom::Promise> PromiseDocumentFlushed(
932 mozilla::dom::PromiseDocumentFlushedCallback& aCallback,
933 mozilla::ErrorResult& aError);
935 void GetInterface(JSContext* aCx, JS::Handle<JS::Value> aIID,
936 JS::MutableHandle<JS::Value> aRetval,
937 mozilla::ErrorResult& aError);
939 already_AddRefed<nsWindowRoot> GetWindowRoot(mozilla::ErrorResult& aError);
941 bool ShouldReportForServiceWorkerScope(const nsAString& aScope);
943 mozilla::dom::InstallTriggerImpl* GetInstallTrigger();
945 nsIDOMWindowUtils* GetWindowUtils(mozilla::ErrorResult& aRv);
947 void UpdateTopInnerWindow();
949 virtual bool IsInSyncOperation() override;
951 // Early during inner window creation, `IsSharedMemoryAllowedInternal`
952 // is called before the `mDoc` field has been initialized in order to
953 // determine whether to expose the `SharedArrayBuffer` constructor on the
954 // JS global. We still want to consider the document's principal to see if
955 // it is a privileged extension which should be exposed to
956 // `SharedArrayBuffer`, however the inner window doesn't know the document's
957 // principal yet. `aPrincipalOverride` is used in that situation to provide
958 // the principal for the to-be-loaded document.
959 bool IsSharedMemoryAllowed() const override {
960 return IsSharedMemoryAllowedInternal(
961 const_cast<nsGlobalWindowInner*>(this)->GetPrincipal());
964 bool IsSharedMemoryAllowedInternal(nsIPrincipal* aPrincipal = nullptr) const;
966 // https://whatpr.org/html/4734/structured-data.html#cross-origin-isolated
967 bool CrossOriginIsolated() const override;
969 mozilla::dom::WebTaskScheduler* Scheduler();
971 protected:
972 // Web IDL helpers
974 // Redefine the property called aPropName on this window object to be a value
975 // property with the value aValue, much like we would do for a [Replaceable]
976 // property in IDL.
977 void RedefineProperty(JSContext* aCx, const char* aPropName,
978 JS::Handle<JS::Value> aValue,
979 mozilla::ErrorResult& aError);
981 nsresult GetInnerWidth(double* aWidth) override;
982 nsresult GetInnerHeight(double* aHeight) override;
984 public:
985 double GetInnerWidth(mozilla::ErrorResult& aError);
986 double GetInnerHeight(mozilla::ErrorResult& aError);
987 int32_t GetScreenX(mozilla::dom::CallerType aCallerType,
988 mozilla::ErrorResult& aError);
989 int32_t GetScreenY(mozilla::dom::CallerType aCallerType,
990 mozilla::ErrorResult& aError);
991 int32_t GetOuterWidth(mozilla::dom::CallerType aCallerType,
992 mozilla::ErrorResult& aError);
993 int32_t GetOuterHeight(mozilla::dom::CallerType aCallerType,
994 mozilla::ErrorResult& aError);
996 protected:
997 friend class HashchangeCallback;
998 friend class mozilla::dom::BarProp;
1000 // Object Management
1001 virtual ~nsGlobalWindowInner();
1003 void FreeInnerObjects();
1005 // Initialize state that depends on the document. By this point, mDoc should
1006 // be set correctly and have us set as its script global object.
1007 void InitDocumentDependentState(JSContext* aCx);
1009 nsresult EnsureClientSource();
1010 nsresult ExecutionReady();
1012 // Inner windows only.
1013 nsresult DefineArgumentsProperty(nsIArray* aArguments);
1015 // Get the parent, returns null if this is a toplevel window
1016 nsPIDOMWindowOuter* GetInProcessParentInternal();
1018 private:
1019 template <typename Method, typename... Args>
1020 mozilla::CallState CallOnInProcessDescendantsInternal(
1021 mozilla::dom::BrowsingContext* aBrowsingContext, bool aChildOnly,
1022 Method aMethod, Args&&... aArgs);
1024 // Call the given method on the immediate children of this window. The
1025 // CallState returned by the last child method invocation is returned or
1026 // CallState::Continue if the method returns void.
1027 template <typename Method, typename... Args>
1028 mozilla::CallState CallOnInProcessChildren(Method aMethod, Args&&... aArgs) {
1029 MOZ_ASSERT(IsCurrentInnerWindow());
1030 return CallOnInProcessDescendantsInternal(GetBrowsingContext(), true,
1031 aMethod, aArgs...);
1034 // Call the given method on the descendant of this window. The CallState
1035 // returned by the last descendant method invocation is returned or
1036 // CallState::Continue if the method returns void.
1037 template <typename Method, typename... Args>
1038 mozilla::CallState CallOnInProcessDescendants(Method aMethod,
1039 Args&&... aArgs) {
1040 MOZ_ASSERT(IsCurrentInnerWindow());
1041 return CallOnInProcessDescendantsInternal(GetBrowsingContext(), false,
1042 aMethod, aArgs...);
1045 // Helper to convert a void returning child method into an implicit
1046 // CallState::Continue value.
1047 template <typename Return, typename Method, typename... Args>
1048 typename std::enable_if<std::is_void<Return>::value, mozilla::CallState>::type
1049 CallDescendant(nsGlobalWindowInner* aWindow, Method aMethod,
1050 Args&&... aArgs) {
1051 (aWindow->*aMethod)(aArgs...);
1052 return mozilla::CallState::Continue;
1055 // Helper that passes through the CallState value from a child method.
1056 template <typename Return, typename Method, typename... Args>
1057 typename std::enable_if<std::is_same<Return, mozilla::CallState>::value,
1058 mozilla::CallState>::type
1059 CallDescendant(nsGlobalWindowInner* aWindow, Method aMethod,
1060 Args&&... aArgs) {
1061 return (aWindow->*aMethod)(aArgs...);
1064 void FreezeInternal(bool aIncludeSubWindows);
1065 void ThawInternal(bool aIncludeSubWindows);
1067 mozilla::CallState ShouldReportForServiceWorkerScopeInternal(
1068 const nsACString& aScope, bool* aResultOut);
1070 public:
1071 // Timeout Functions
1072 // |interval| is in milliseconds.
1073 MOZ_CAN_RUN_SCRIPT
1074 int32_t SetTimeoutOrInterval(
1075 JSContext* aCx,
1076 const mozilla::dom::FunctionOrTrustedScriptOrString& aHandler,
1077 int32_t aTimeout, const mozilla::dom::Sequence<JS::Value>& aArguments,
1078 bool aIsInterval, mozilla::ErrorResult& aError);
1080 // Return true if |aTimeout| was cleared while its handler ran.
1081 MOZ_CAN_RUN_SCRIPT
1082 bool RunTimeoutHandler(mozilla::dom::Timeout* aTimeout) override;
1084 // Helper Functions
1085 already_AddRefed<nsIDocShellTreeOwner> GetTreeOwner();
1086 already_AddRefed<nsIWebBrowserChrome> GetWebBrowserChrome();
1087 bool IsPrivateBrowsing();
1089 void FireOfflineStatusEventIfChanged();
1091 public:
1092 // Inner windows only.
1093 nsresult FireHashchange(const nsAString& aOldURL, const nsAString& aNewURL);
1095 void FlushPendingNotifications(mozilla::FlushType aType);
1097 void ScrollTo(const mozilla::CSSIntPoint& aScroll,
1098 const mozilla::dom::ScrollOptions& aOptions);
1100 already_AddRefed<nsIWidget> GetMainWidget();
1101 nsIWidget* GetNearestWidget() const;
1103 bool IsInModalState();
1105 void SetFocusedElement(mozilla::dom::Element* aElement,
1106 uint32_t aFocusMethod = 0,
1107 bool aNeedsFocus = false) override;
1109 uint32_t GetFocusMethod() override;
1111 bool ShouldShowFocusRing() override;
1113 // Inner windows only.
1114 void UpdateCanvasFocus(bool aFocusChanged, nsIContent* aNewContent);
1116 public:
1117 virtual already_AddRefed<nsPIWindowRoot> GetTopWindowRoot() override;
1119 // Get the toplevel principal, returns null if this is a toplevel window.
1120 nsIPrincipal* GetTopLevelAntiTrackingPrincipal();
1122 // Get the client principal, returns null if the clientSource is not
1123 // available.
1124 nsIPrincipal* GetClientPrincipal();
1126 // Whether the chrome window is currently in a full screen transition. This
1127 // flag is updated from FullscreenTransitionTask.
1128 bool IsInFullScreenTransition();
1130 // This method is called if this window loads a 3rd party tracking resource
1131 // and the storage is just been changed. The window can reset the partitioned
1132 // storage objects and switch to the first party cookie jar.
1133 RefPtr<mozilla::GenericPromise> StorageAccessPermissionChanged(bool aGranted);
1135 protected:
1136 void NotifyWindowIDDestroyed(const char* aTopic);
1138 virtual void UpdateParentTarget() override;
1140 // Clear the document-dependent slots on our JS wrapper. Inner windows only.
1141 void ClearDocumentDependentSlots(JSContext* aCx);
1143 // Inner windows only.
1144 already_AddRefed<mozilla::dom::StorageEvent> CloneStorageEvent(
1145 const nsAString& aType, const RefPtr<mozilla::dom::StorageEvent>& aEvent,
1146 mozilla::ErrorResult& aRv);
1148 protected:
1149 already_AddRefed<nsICSSDeclaration> GetComputedStyleHelper(
1150 mozilla::dom::Element& aElt, const nsAString& aPseudoElt,
1151 bool aDefaultStylesOnly, mozilla::ErrorResult& aError);
1153 nsGlobalWindowInner* InnerForSetTimeoutOrInterval(
1154 mozilla::ErrorResult& aError);
1156 void PostMessageMoz(JSContext* aCx, JS::Handle<JS::Value> aMessage,
1157 const nsAString& aTargetOrigin,
1158 JS::Handle<JS::Value> aTransfer,
1159 nsIPrincipal& aSubjectPrincipal,
1160 mozilla::ErrorResult& aError);
1162 private:
1163 // Fire the JS engine's onNewGlobalObject hook. Only used on inner windows.
1164 void FireOnNewGlobalObject();
1166 // Helper for resolving the components shim.
1167 bool ResolveComponentsShim(
1168 JSContext* aCx, JS::Handle<JSObject*> aObj,
1169 JS::MutableHandle<mozilla::Maybe<JS::PropertyDescriptor>> aDesc);
1171 // nsPIDOMWindow{Inner,Outer} should be able to see these helper methods.
1172 friend class nsPIDOMWindowInner;
1173 friend class nsPIDOMWindowOuter;
1175 bool IsBackgroundInternal() const override;
1176 bool IsPlayingAudio() override;
1178 // NOTE: Chrome Only
1179 void DisconnectAndClearGroupMessageManagers() {
1180 MOZ_RELEASE_ASSERT(IsChromeWindow());
1181 for (const auto& entry : mChromeFields.mGroupMessageManagers) {
1182 mozilla::dom::ChromeMessageBroadcaster* mm = entry.GetWeak();
1183 if (mm) {
1184 mm->Disconnect();
1187 mChromeFields.mGroupMessageManagers.Clear();
1190 // Call mDocumentFlushedResolvers items, and perform MicroTask checkpoint
1191 // after that.
1193 // If aUntilExhaustion is true, then we call resolvers that get added as a
1194 // result synchronously, otherwise we wait until the next refresh driver tick.
1195 void CallDocumentFlushedResolvers(bool aUntilExhaustion);
1197 // Called after a refresh driver tick. See documentation of
1198 // CallDocumentFlushedResolvers for the meaning of aUntilExhaustion.
1200 // Returns whether we need to keep observing the refresh driver or not.
1201 bool MaybeCallDocumentFlushedResolvers(bool aUntilExhaustion);
1203 // Try to fire the "load" event on our content embedder if we're an iframe.
1204 MOZ_CAN_RUN_SCRIPT void FireFrameLoadEvent();
1206 void UpdateAutoplayPermission();
1207 void UpdateShortcutsPermission();
1208 void UpdatePopupPermission();
1210 void UpdatePermissions();
1212 public:
1213 static uint32_t GetShortcutsPermission(nsIPrincipal* aPrincipal);
1215 // Dispatch a runnable related to the global.
1216 nsresult Dispatch(already_AddRefed<nsIRunnable>&& aRunnable) const final;
1217 nsISerialEventTarget* SerialEventTarget() const final;
1219 void DisableIdleCallbackRequests();
1220 uint32_t LastIdleRequestHandle() const {
1221 return mIdleRequestCallbackCounter - 1;
1223 MOZ_CAN_RUN_SCRIPT
1224 void RunIdleRequest(mozilla::dom::IdleRequest* aRequest,
1225 DOMHighResTimeStamp aDeadline, bool aDidTimeout);
1226 MOZ_CAN_RUN_SCRIPT
1227 void ExecuteIdleRequest(TimeStamp aDeadline);
1228 void ScheduleIdleRequestDispatch();
1229 void SuspendIdleRequests();
1230 void ResumeIdleRequests();
1232 using IdleRequests = mozilla::LinkedList<RefPtr<mozilla::dom::IdleRequest>>;
1233 void RemoveIdleCallback(mozilla::dom::IdleRequest* aRequest);
1235 void SetActiveLoadingState(bool aIsLoading) override;
1237 // Hint to the JS engine whether we are currently loading.
1238 void HintIsLoading(bool aIsLoading);
1240 mozilla::dom::ContentMediaController* GetContentMediaController();
1242 bool TryOpenExternalProtocolIframe() {
1243 if (mHasOpenedExternalProtocolFrame) {
1244 return false;
1246 mHasOpenedExternalProtocolFrame = true;
1247 return true;
1250 nsTArray<uint32_t>& GetScrollMarks() { return mScrollMarks; }
1251 bool GetScrollMarksOnHScrollbar() const { return mScrollMarksOnHScrollbar; }
1252 void SetScrollMarks(const nsTArray<uint32_t>& aScrollMarks,
1253 bool aOnHScrollbar);
1255 // Don't use this value directly, call StorageAccess::StorageAllowedForWindow
1256 // instead.
1257 mozilla::Maybe<mozilla::StorageAccess> GetStorageAllowedCache(
1258 uint32_t& aRejectedReason) {
1259 if (mStorageAllowedCache.isSome()) {
1260 aRejectedReason = mStorageAllowedReasonCache;
1262 return mStorageAllowedCache;
1264 void SetStorageAllowedCache(const mozilla::StorageAccess& storageAllowed,
1265 uint32_t aRejectedReason) {
1266 mStorageAllowedCache = Some(storageAllowed);
1267 mStorageAllowedReasonCache = aRejectedReason;
1269 void ClearStorageAllowedCache() {
1270 mStorageAllowedCache = mozilla::Nothing();
1271 mStorageAllowedReasonCache = 0;
1274 virtual JS::loader::ModuleLoaderBase* GetModuleLoader(
1275 JSContext* aCx) override;
1277 mozilla::dom::TrustedTypePolicyFactory* TrustedTypes();
1279 void SetCurrentPasteDataTransfer(mozilla::dom::DataTransfer* aDataTransfer);
1280 mozilla::dom::DataTransfer* GetCurrentPasteDataTransfer() const;
1282 private:
1283 RefPtr<mozilla::dom::ContentMediaController> mContentMediaController;
1285 RefPtr<mozilla::dom::WebTaskSchedulerMainThread> mWebTaskScheduler;
1287 RefPtr<mozilla::dom::TrustedTypePolicyFactory> mTrustedTypePolicyFactory;
1289 protected:
1290 // Whether we need to care about orientation changes.
1291 bool mHasOrientationChangeListeners : 1;
1293 // Window offline status. Checked to see if we need to fire offline event
1294 bool mWasOffline : 1;
1296 // Represents whether the inner window's page has had a slow script notice.
1297 // Only used by inner windows; will always be false for outer windows.
1298 // This is used to implement Telemetry measures such as
1299 // SLOW_SCRIPT_PAGE_COUNT.
1300 bool mHasHadSlowScript : 1;
1302 // Fast way to tell if this is a chrome window (without having to QI).
1303 bool mIsChrome : 1;
1305 // Hack to indicate whether a chrome window needs its message manager
1306 // to be disconnected, since clean up code is shared in the global
1307 // window superclass.
1308 bool mCleanMessageManager : 1;
1310 // Indicates that the current document has never received a document focus
1311 // event.
1312 bool mNeedsFocus : 1;
1313 bool mHasFocus : 1;
1315 // true if tab navigation has occurred for this window. Focus rings
1316 // should be displayed.
1317 bool mFocusByKeyOccurred : 1;
1319 // True if we have notified document-element-inserted observers for this
1320 // document.
1321 bool mDidFireDocElemInserted : 1;
1323 // Indicates whether this window wants gamepad input events
1324 bool mHasGamepad : 1;
1326 // Indicates whether this window has content that has an XR session
1327 // An XR session results in enumeration and activation of XR devices.
1328 bool mHasXRSession : 1;
1330 // Indicates whether this window wants VRDisplayActivate events
1331 bool mHasVRDisplayActivateEvents : 1;
1333 // Indicates that a request for XR runtime detection has been
1334 // requested, but has not yet been resolved
1335 bool mXRRuntimeDetectionInFlight : 1;
1337 // Indicates that an XR permission request has been requested
1338 // but has not yet been resolved.
1339 bool mXRPermissionRequestInFlight : 1;
1341 // Indicates that an XR permission request has been granted.
1342 // The page should not request permission multiple times.
1343 bool mXRPermissionGranted : 1;
1345 // True if this was the currently-active inner window for a BrowsingContext at
1346 // the time it was discarded.
1347 bool mWasCurrentInnerWindow : 1;
1348 void SetWasCurrentInnerWindow() { mWasCurrentInnerWindow = true; }
1349 bool WasCurrentInnerWindow() const override { return mWasCurrentInnerWindow; }
1351 bool mHasSeenGamepadInput : 1;
1353 // Whether we told the JS engine that we were in pageload.
1354 bool mHintedWasLoading : 1;
1356 // Whether this window has opened an external-protocol iframe without user
1357 // activation once already. Only relevant for top windows.
1358 bool mHasOpenedExternalProtocolFrame : 1;
1360 bool mScrollMarksOnHScrollbar : 1;
1362 nsCheapSet<nsUint32HashKey> mGamepadIndexSet;
1363 nsRefPtrHashtable<nsGenericHashKey<mozilla::dom::GamepadHandle>,
1364 mozilla::dom::Gamepad>
1365 mGamepads;
1367 RefPtr<nsScreen> mScreen;
1369 RefPtr<mozilla::dom::BarProp> mMenubar;
1370 RefPtr<mozilla::dom::BarProp> mToolbar;
1371 RefPtr<mozilla::dom::BarProp> mLocationbar;
1372 RefPtr<mozilla::dom::BarProp> mPersonalbar;
1373 RefPtr<mozilla::dom::BarProp> mStatusbar;
1374 RefPtr<mozilla::dom::BarProp> mScrollbars;
1376 RefPtr<nsGlobalWindowObserver> mObserver;
1377 RefPtr<mozilla::dom::Crypto> mCrypto;
1378 RefPtr<mozilla::dom::cache::CacheStorage> mCacheStorage;
1379 RefPtr<mozilla::dom::Console> mConsole;
1380 RefPtr<mozilla::dom::CookieStore> mCookieStore;
1381 RefPtr<mozilla::dom::Worklet> mPaintWorklet;
1382 RefPtr<mozilla::dom::External> mExternal;
1383 RefPtr<mozilla::dom::InstallTriggerImpl> mInstallTrigger;
1385 RefPtr<mozilla::dom::Storage> mLocalStorage;
1386 RefPtr<mozilla::dom::Storage> mSessionStorage;
1388 RefPtr<mozilla::EventListenerManager> mListenerManager;
1389 RefPtr<mozilla::dom::Location> mLocation;
1390 RefPtr<nsHistory> mHistory;
1391 RefPtr<mozilla::dom::Navigation> mNavigation;
1392 RefPtr<mozilla::dom::CustomElementRegistry> mCustomElements;
1394 nsTObserverArray<RefPtr<mozilla::dom::SharedWorker>> mSharedWorkers;
1396 RefPtr<mozilla::dom::VisualViewport> mVisualViewport;
1398 // The document's principals and CSP are only stored if
1399 // FreeInnerObjects has been called.
1400 nsCOMPtr<nsIPrincipal> mDocumentPrincipal;
1401 nsCOMPtr<nsIPrincipal> mDocumentCookiePrincipal;
1402 nsCOMPtr<nsIPrincipal> mDocumentStoragePrincipal;
1403 nsCOMPtr<nsIPrincipal> mDocumentPartitionedPrincipal;
1404 nsCOMPtr<nsIContentSecurityPolicy> mDocumentCsp;
1406 // Used to cache the result of StorageAccess::StorageAllowedForWindow.
1407 // Don't use this field directly, use StorageAccess::StorageAllowedForWindow
1408 // instead.
1409 mozilla::Maybe<mozilla::StorageAccess> mStorageAllowedCache;
1410 uint32_t mStorageAllowedReasonCache;
1412 // When window associated storage is accessed we need to notify the parent
1413 // process. This flag is used to ensure we only do it once per window
1414 // lifetime.
1415 bool hasNotifiedStorageKeyUsed{false};
1417 RefPtr<mozilla::dom::DebuggerNotificationManager>
1418 mDebuggerNotificationManager;
1420 // mBrowserChild is only ever populated in the content process.
1421 nsCOMPtr<nsIBrowserChild> mBrowserChild;
1423 uint32_t mSuspendDepth;
1424 uint32_t mFreezeDepth;
1426 #ifdef DEBUG
1427 uint32_t mSerial;
1428 #endif
1430 // the method that was used to focus mFocusedElement
1431 uint32_t mFocusMethod;
1433 // Only relevant if we're listening for orientation changes.
1434 int16_t mOrientationAngle = 0;
1436 // The current idle request callback handle
1437 uint32_t mIdleRequestCallbackCounter;
1438 IdleRequests mIdleRequestCallbacks;
1439 RefPtr<IdleRequestExecutor> mIdleRequestExecutor;
1441 #ifdef DEBUG
1442 nsCOMPtr<nsIURI> mLastOpenedURI;
1443 #endif
1445 RefPtr<mozilla::dom::IDBFactory> mIndexedDB;
1447 // This flag keeps track of whether this window is currently
1448 // observing refresh notifications from the refresh driver.
1449 bool mObservingRefresh;
1451 bool mIteratingDocumentFlushedResolvers;
1453 bool TryToObserveRefresh();
1455 nsTArray<uint32_t> mEnabledSensors;
1457 #ifdef MOZ_WEBSPEECH
1458 RefPtr<mozilla::dom::SpeechSynthesis> mSpeechSynthesis;
1459 #endif
1461 RefPtr<mozilla::glean::Glean> mGlean;
1462 RefPtr<mozilla::glean::GleanPings> mGleanPings;
1464 // This is the CC generation the last time we called CanSkip.
1465 uint32_t mCanSkipCCGeneration;
1467 // The VR Displays for this window
1468 nsTArray<RefPtr<mozilla::dom::VRDisplay>> mVRDisplays;
1470 RefPtr<mozilla::dom::VREventObserver> mVREventObserver;
1472 // The number of unload and beforeunload event listeners registered on this
1473 // window.
1474 uint64_t mUnloadOrBeforeUnloadListenerCount = 0;
1476 RefPtr<mozilla::dom::IntlUtils> mIntlUtils;
1478 mozilla::UniquePtr<mozilla::dom::ClientSource> mClientSource;
1480 nsTArray<mozilla::UniquePtr<PromiseDocumentFlushedResolver>>
1481 mDocumentFlushedResolvers;
1483 nsTArray<uint32_t> mScrollMarks;
1485 nsTArray<mozilla::WeakPtr<Document>> mDataDocumentsForMemoryReporting;
1487 static InnerWindowByIdTable* sInnerWindowsById;
1489 // Members in the mChromeFields member should only be used in chrome windows.
1490 // All accesses to this field should be guarded by a check of mIsChrome.
1491 struct ChromeFields {
1492 RefPtr<mozilla::dom::ChromeMessageBroadcaster> mMessageManager;
1493 nsRefPtrHashtable<nsStringHashKey, mozilla::dom::ChromeMessageBroadcaster>
1494 mGroupMessageManagers{1};
1495 } mChromeFields;
1497 // Cache the DataTransfer created for a paste event, this will be reset after
1498 // the event is dispatched.
1499 RefPtr<mozilla::dom::DataTransfer> mCurrentPasteDataTransfer;
1501 // These fields are used by the inner and outer windows to prevent
1502 // programatically moving the window while the mouse is down.
1503 static bool sMouseDown;
1504 static bool sDragServiceDisabled;
1506 friend class nsDOMWindowUtils;
1507 friend class mozilla::dom::PostMessageEvent;
1508 friend class mozilla::dom::TimeoutManager;
1509 friend class IdleRequestExecutor;
1510 friend class nsGlobalWindowOuter;
1513 inline nsISupports* ToSupports(nsGlobalWindowInner* p) {
1514 return static_cast<mozilla::dom::EventTarget*>(p);
1517 inline nsISupports* ToCanonicalSupports(nsGlobalWindowInner* p) {
1518 return static_cast<mozilla::dom::EventTarget*>(p);
1521 // XXX: EWW - This is an awful hack - let's not do this
1522 #include "nsGlobalWindowOuter.h"
1524 inline nsIGlobalObject* nsGlobalWindowInner::GetOwnerGlobal() const {
1525 return const_cast<nsGlobalWindowInner*>(this);
1528 inline nsGlobalWindowOuter* nsGlobalWindowInner::GetInProcessTopInternal() {
1529 nsGlobalWindowOuter* outer = GetOuterWindowInternal();
1530 nsCOMPtr<nsPIDOMWindowOuter> top = outer ? outer->GetInProcessTop() : nullptr;
1531 if (top) {
1532 return nsGlobalWindowOuter::Cast(top);
1534 return nullptr;
1537 inline nsGlobalWindowOuter*
1538 nsGlobalWindowInner::GetInProcessScriptableTopInternal() {
1539 nsPIDOMWindowOuter* top = GetInProcessScriptableTop();
1540 return nsGlobalWindowOuter::Cast(top);
1543 inline nsIScriptContext* nsGlobalWindowInner::GetContextInternal() {
1544 if (mOuterWindow) {
1545 return GetOuterWindowInternal()->mContext;
1548 return nullptr;
1551 inline nsGlobalWindowOuter* nsGlobalWindowInner::GetOuterWindowInternal()
1552 const {
1553 return nsGlobalWindowOuter::Cast(GetOuterWindow());
1556 #endif /* nsGlobalWindowInner_h___ */