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"
16 #include "mozilla/WeakPtr.h"
18 #include "nsWeakReference.h"
19 #include "nsTHashMap.h"
20 #include "nsCycleCollectionParticipant.h"
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"
30 #include "mozilla/FlushType.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/StorageEvent.h"
38 #include "mozilla/CallState.h"
39 #include "mozilla/Attributes.h"
40 #include "mozilla/LinkedList.h"
41 #include "mozilla/StorageAccess.h"
42 #include "mozilla/TimeStamp.h"
43 #include "nsWrapperCacheInlines.h"
44 #include "mozilla/dom/EventTarget.h"
45 #include "mozilla/dom/WindowBinding.h"
46 #include "mozilla/dom/WindowProxyHolder.h"
48 #include "nsCheapSets.h"
49 #include "mozilla/dom/ImageBitmapBinding.h"
50 #include "mozilla/dom/ImageBitmapSource.h"
51 #include "mozilla/UniquePtr.h"
52 #include "nsThreadUtils.h"
57 class nsICSSDeclaration
;
58 class nsIDocShellTreeOwner
;
59 class nsIDOMWindowUtils
;
60 class nsIScrollableFrame
;
62 class nsIScriptContext
;
63 class nsIScriptTimeoutHandler
;
64 class nsIBrowserChild
;
65 class nsIPrintSettings
;
66 class nsITimeoutHandler
;
67 class nsIWebBrowserChrome
;
68 class nsIWebProgressListener
;
69 class mozIDOMWindowProxy
;
73 class nsGlobalWindowObserver
;
74 class nsGlobalWindowOuter
;
75 class nsDOMWindowUtils
;
76 class nsIUserIdleService
;
81 class IdleRequestExecutor
;
83 class PromiseDocumentFlushedResolver
;
95 enum class ScreenOrientation
: uint32_t;
100 class BrowsingContext
;
101 struct ChannelPixelLayout
;
105 class CustomElementRegistry
;
110 class ContentMediaController
;
111 enum class ImageBitmapFormat
: uint8_t;
113 class IdleRequestCallback
;
114 class InstallTriggerImpl
;
116 class MediaQueryList
;
117 class OwningExternalOrWindowProxy
;
119 class PostMessageEvent
;
121 class RequestOrUSVString
;
124 struct SizeToContentConstraints
;
125 class WebTaskScheduler
;
126 class WebTaskSchedulerMainThread
;
127 class SpeechSynthesis
;
129 class VisualViewport
;
131 enum class VRDisplayEventReason
: uint8_t;
132 class VREventObserver
;
133 struct WindowPostMessageOptions
;
140 } // namespace mozilla
142 extern const JSClass OuterWindowProxyClass
;
144 //*****************************************************************************
145 // nsGlobalWindowInner: Global Object for Scripting
146 //*****************************************************************************
148 // nsGlobalWindowInner inherits PRCList for maintaining a list of all inner
149 // windows still in memory for any given outer window. This list is needed to
150 // ensure that mOuterWindow doesn't end up dangling. The nature of PRCList means
151 // that the window itself is always in the list, and an outer window's list will
152 // also contain all inner window objects that are still in memory (and in
153 // reality all inner window object's lists also contain its outer and all other
154 // inner windows belonging to the same outer window, but that's an unimportant
155 // side effect of inheriting PRCList).
157 class nsGlobalWindowInner final
: public mozilla::dom::EventTarget
,
158 public nsPIDOMWindowInner
,
159 private nsIDOMWindow
,
160 public nsIScriptGlobalObject
,
161 public nsIScriptObjectPrincipal
,
162 public nsSupportsWeakReference
,
163 public nsIInterfaceRequestor
,
166 using RemoteProxy
= mozilla::dom::BrowsingContext
;
168 using TimeStamp
= mozilla::TimeStamp
;
169 using TimeDuration
= mozilla::TimeDuration
;
171 using InnerWindowByIdTable
=
172 nsTHashMap
<nsUint64HashKey
, nsGlobalWindowInner
*>;
174 static void AssertIsOnMainThread()
182 bool IsInnerWindow() const final
{ return true; } // Overriding EventTarget
184 static nsGlobalWindowInner
* Cast(nsPIDOMWindowInner
* aPIWin
) {
185 return static_cast<nsGlobalWindowInner
*>(aPIWin
);
187 static const nsGlobalWindowInner
* Cast(const nsPIDOMWindowInner
* aPIWin
) {
188 return static_cast<const nsGlobalWindowInner
*>(aPIWin
);
190 static nsGlobalWindowInner
* Cast(mozIDOMWindow
* aWin
) {
191 return Cast(nsPIDOMWindowInner::From(aWin
));
194 static nsGlobalWindowInner
* GetInnerWindowWithId(uint64_t aInnerWindowID
) {
195 AssertIsOnMainThread();
197 if (!sInnerWindowsById
) {
201 nsGlobalWindowInner
* innerWindow
= sInnerWindowsById
->Get(aInnerWindowID
);
205 static InnerWindowByIdTable
* GetWindowsTable() {
206 AssertIsOnMainThread();
208 return sInnerWindowsById
;
211 static nsGlobalWindowInner
* FromSupports(nsISupports
* supports
) {
212 // Make sure this matches the casts we do in QueryInterface().
213 return (nsGlobalWindowInner
*)(mozilla::dom::EventTarget
*)supports
;
216 static already_AddRefed
<nsGlobalWindowInner
> Create(
217 nsGlobalWindowOuter
* aOuter
, bool aIsChrome
,
218 mozilla::dom::WindowGlobalChild
* aActor
);
221 NS_DECL_ISUPPORTS_INHERITED
222 NS_IMETHOD_(void) DeleteCycleCollectable() override
;
225 virtual JSObject
* WrapObject(JSContext
* cx
,
226 JS::Handle
<JSObject
*> aGivenProto
) override
{
231 bool ShouldResistFingerprinting(RFPTarget aTarget
) const final
;
232 mozilla::OriginTrials
Trials() const final
;
233 mozilla::dom::FontFaceSet
* GetFonts() final
;
235 JSObject
* GetGlobalJSObject() final
{ return GetWrapper(); }
236 JSObject
* GetGlobalJSObjectPreserveColor() const final
{
237 return GetWrapperPreserveColor();
239 // The HasJSGlobal on nsIGlobalObject ends up having to do a virtual
240 // call to GetGlobalJSObjectPreserveColor(), because when it's
241 // making the call it doesn't know it's doing it on an
242 // nsGlobalWindowInner. Add a version here that can be entirely
244 bool HasJSGlobal() const { return GetGlobalJSObjectPreserveColor(); }
246 mozilla::Result
<mozilla::ipc::PrincipalInfo
, nsresult
> GetStorageKey()
249 mozilla::dom::StorageManager
* GetStorageManager() override
;
251 bool IsEligibleForMessaging() override
;
253 void TraceGlobalJSObject(JSTracer
* aTrc
);
255 virtual nsresult
EnsureScriptEnvironment() override
;
257 virtual nsIScriptContext
* GetScriptContext() override
;
259 virtual bool IsBlackForCC(bool aTracingNeeded
= true) override
;
261 // nsIScriptObjectPrincipal
262 virtual nsIPrincipal
* GetPrincipal() override
;
264 virtual nsIPrincipal
* GetEffectiveCookiePrincipal() override
;
266 virtual nsIPrincipal
* GetEffectiveStoragePrincipal() override
;
268 virtual nsIPrincipal
* PartitionedPrincipal() override
;
273 void CaptureEvents();
274 void ReleaseEvents();
275 void Dump(const nsAString
& aStr
);
276 void SetResizable(bool aResizable
) const;
278 virtual mozilla::EventListenerManager
* GetExistingListenerManager()
281 virtual mozilla::EventListenerManager
* GetOrCreateListenerManager() override
;
283 mozilla::Maybe
<mozilla::dom::EventCallbackDebuggerNotificationType
>
284 GetDebuggerNotificationType() const override
;
286 bool ComputeDefaultWantsUntrusted(mozilla::ErrorResult
& aRv
) final
;
288 virtual nsPIDOMWindowOuter
* GetOwnerGlobalForBindingsInternal() override
;
290 virtual nsIGlobalObject
* GetOwnerGlobal() const override
;
292 EventTarget
* GetTargetForDOMEvent() override
;
294 using mozilla::dom::EventTarget::DispatchEvent
;
295 // TODO: Convert this to MOZ_CAN_RUN_SCRIPT (bug 1415230)
296 MOZ_CAN_RUN_SCRIPT_BOUNDARY
bool DispatchEvent(
297 mozilla::dom::Event
& aEvent
, mozilla::dom::CallerType aCallerType
,
298 mozilla::ErrorResult
& aRv
) override
;
300 void GetEventTargetParent(mozilla::EventChainPreVisitor
& aVisitor
) override
;
302 // TODO: Convert this to MOZ_CAN_RUN_SCRIPT (bug 1415230)
303 MOZ_CAN_RUN_SCRIPT_BOUNDARY nsresult
304 PostHandleEvent(mozilla::EventChainPostVisitor
& aVisitor
) override
;
306 void Suspend(bool aIncludeSubWindows
= true);
307 void Resume(bool aIncludeSubWindows
= true);
308 virtual bool IsSuspended() const override
;
310 // Calling Freeze() on a window will automatically Suspend() it. In
311 // addition, the window and its children (if aIncludeSubWindows is true) are
312 // further treated as no longer suitable for interaction with the user. For
313 // example, it may be marked non-visible, cannot be focused, etc. All worker
314 // threads are also frozen bringing them to a complete stop. A window can
315 // have Freeze() called multiple times and will only thaw after a matching
316 // number of Thaw() calls.
317 void Freeze(bool aIncludeSubWindows
= true);
318 void Thaw(bool aIncludeSubWindows
= true);
319 virtual bool IsFrozen() const override
;
320 void SyncStateFromParentWindow();
322 // Called on the current inner window of a browsing context when its
323 // background state changes according to selected tab or visibility of the
324 // browser window. Used with Suspend()/Resume() or Freeze()/Thaw() because
325 // background state may change while the inner window is not current.
326 void UpdateBackgroundState();
328 mozilla::dom::DebuggerNotificationManager
*
329 GetOrCreateDebuggerNotificationManager() override
;
331 mozilla::dom::DebuggerNotificationManager
*
332 GetExistingDebuggerNotificationManager() override
;
334 mozilla::Maybe
<mozilla::dom::ClientInfo
> GetClientInfo() const override
;
335 mozilla::Maybe
<mozilla::dom::ClientState
> GetClientState() const;
336 mozilla::Maybe
<mozilla::dom::ServiceWorkerDescriptor
> GetController()
339 void SetCsp(nsIContentSecurityPolicy
* aCsp
);
340 void SetPreloadCsp(nsIContentSecurityPolicy
* aPreloadCsp
);
341 nsIContentSecurityPolicy
* GetCsp();
343 virtual RefPtr
<mozilla::dom::ServiceWorker
> GetOrCreateServiceWorker(
344 const mozilla::dom::ServiceWorkerDescriptor
& aDescriptor
) override
;
346 RefPtr
<mozilla::dom::ServiceWorkerRegistration
> GetServiceWorkerRegistration(
347 const mozilla::dom::ServiceWorkerRegistrationDescriptor
& aDescriptor
)
350 RefPtr
<mozilla::dom::ServiceWorkerRegistration
>
351 GetOrCreateServiceWorkerRegistration(
352 const mozilla::dom::ServiceWorkerRegistrationDescriptor
& aDescriptor
)
355 mozilla::StorageAccess
GetStorageAccess() final
;
357 void NoteCalledRegisterForServiceWorkerScope(const nsACString
& aScope
);
359 void NoteDOMContentLoaded();
361 virtual nsresult
FireDelayedDOMEvents(bool aIncludeSubWindows
) override
;
363 virtual void MaybeUpdateTouchState() override
;
365 // Inner windows only.
366 void RefreshRealmPrincipal();
367 void RefreshReduceTimerPrecisionCallerType();
369 // For accessing protected field mFullscreen
370 friend class FullscreenTransitionTask
;
372 // Inner windows only.
373 virtual void SetHasGamepadEventListener(bool aHasGamepad
= true) override
;
374 void NotifyHasXRSession();
375 bool HasUsedVR() const;
376 bool IsVRContentDetected() const;
377 bool IsVRContentPresenting() const;
378 void RequestXRPermission();
379 void OnXRPermissionRequestAllow();
380 void OnXRPermissionRequestCancel();
382 using EventTarget::EventListenerAdded
;
383 virtual void EventListenerAdded(nsAtom
* aType
) override
;
384 using EventTarget::EventListenerRemoved
;
385 virtual void EventListenerRemoved(nsAtom
* aType
) override
;
387 // nsIInterfaceRequestor
388 NS_DECL_NSIINTERFACEREQUESTOR
391 mozilla::dom::Nullable
<mozilla::dom::WindowProxyHolder
> IndexedGetter(
394 static bool IsPrivilegedChromeWindow(JSContext
*, JSObject
* aObj
);
396 static bool DeviceSensorsEnabled(JSContext
*, JSObject
*);
398 static bool CachesEnabled(JSContext
* aCx
, JSObject
*);
400 static bool IsSizeToContentEnabled(JSContext
*, JSObject
*);
402 // WebIDL permission Func for whether Glean APIs are permitted.
403 static bool IsGleanNeeded(JSContext
*, JSObject
*);
406 JSContext
* aCx
, JS::Handle
<JSObject
*> aObj
, JS::Handle
<jsid
> aId
,
407 JS::MutableHandle
<mozilla::Maybe
<JS::PropertyDescriptor
>> aDesc
);
408 // The return value is whether DoResolve might end up resolving the given id.
409 // If in doubt, return true.
410 static bool MayResolve(jsid aId
);
412 void GetOwnPropertyNames(JSContext
* aCx
, JS::MutableHandleVector
<jsid
> aNames
,
413 bool aEnumerableOnly
, mozilla::ErrorResult
& aRv
);
415 nsPIDOMWindowOuter
* GetInProcessScriptableTop() override
;
416 inline nsGlobalWindowOuter
* GetInProcessTopInternal();
418 inline nsGlobalWindowOuter
* GetInProcessScriptableTopInternal();
420 already_AddRefed
<mozilla::dom::BrowsingContext
> GetChildWindow(
421 const nsAString
& aName
);
423 inline nsIBrowserChild
* GetBrowserChild() { return mBrowserChild
.get(); }
425 nsIScriptContext
* GetContextInternal();
427 nsGlobalWindowOuter
* GetOuterWindowInternal() const;
429 bool IsChromeWindow() const { return mIsChrome
; }
431 // GetScrollFrame does not flush. Callers should do it themselves as needed,
432 // depending on which info they actually want off the scrollable frame.
433 nsIScrollableFrame
* GetScrollFrame();
435 nsresult
Observe(nsISupports
* aSubject
, const char* aTopic
,
436 const char16_t
* aData
);
438 void ObserveStorageNotification(mozilla::dom::StorageEvent
* aEvent
,
439 const char16_t
* aStorageType
,
440 bool aPrivateBrowsing
);
443 static void ShutDown();
444 static bool IsCallerChrome();
446 friend class WindowStateHolder
;
448 NS_DECL_CYCLE_COLLECTION_SKIPPABLE_SCRIPT_HOLDER_CLASS_AMBIGUOUS(
449 nsGlobalWindowInner
, mozilla::dom::EventTarget
)
452 // Call Unlink on this window. This may cause bad things to happen, so use
457 virtual bool TakeFocus(bool aFocus
, uint32_t aFocusMethod
) override
;
458 MOZ_CAN_RUN_SCRIPT_BOUNDARY
virtual void SetReadyForFocus() override
;
459 MOZ_CAN_RUN_SCRIPT_BOUNDARY
virtual void PageHidden() override
;
460 virtual nsresult
DispatchAsyncHashchange(nsIURI
* aOldURI
,
461 nsIURI
* aNewURI
) override
;
462 virtual nsresult
DispatchSyncPopState() override
;
464 // Inner windows only.
465 virtual void EnableDeviceSensor(uint32_t aType
) override
;
466 virtual void DisableDeviceSensor(uint32_t aType
) override
;
468 #if defined(MOZ_WIDGET_ANDROID)
469 virtual void EnableOrientationChangeListener() override
;
470 virtual void DisableOrientationChangeListener() override
;
473 void AddSizeOfIncludingThis(nsWindowSizes
& aWindowSizes
) const;
475 void CollectDOMSizesForDataDocuments(nsWindowSizes
&) const;
476 void RegisterDataDocumentForMemoryReporting(Document
*);
477 void UnregisterDataDocumentForMemoryReporting(Document
*);
479 enum SlowScriptResponse
{
480 ContinueSlowScript
= 0,
481 ContinueSlowScriptAndKeepNotifying
,
482 AlwaysContinueSlowScript
,
486 SlowScriptResponse
ShowSlowScriptDialog(JSContext
* aCx
,
487 const nsString
& aAddonId
,
488 const double aDuration
);
490 // Inner windows only.
491 void AddGamepad(mozilla::dom::GamepadHandle aHandle
,
492 mozilla::dom::Gamepad
* aGamepad
);
493 void RemoveGamepad(mozilla::dom::GamepadHandle aHandle
);
494 void GetGamepads(nsTArray
<RefPtr
<mozilla::dom::Gamepad
>>& aGamepads
);
495 already_AddRefed
<mozilla::dom::Gamepad
> GetGamepad(
496 mozilla::dom::GamepadHandle aHandle
);
497 void SetHasSeenGamepadInput(bool aHasSeen
);
498 bool HasSeenGamepadInput();
499 void SyncGamepadState();
500 void StopGamepadHaptics();
502 // Inner windows only.
503 // Enable/disable updates for gamepad input.
504 void EnableGamepadUpdates();
505 void DisableGamepadUpdates();
507 // Inner windows only.
508 // Enable/disable updates for VR
509 void EnableVRUpdates();
510 void DisableVRUpdates();
511 // Reset telemetry data when switching windows.
512 // aUpdate, true for accumulating the result to the histogram.
513 // false for only resetting the timestamp.
514 void ResetVRTelemetry(bool aUpdate
);
516 void StartVRActivity();
517 void StopVRActivity();
519 // Update the VR displays for this window
520 bool UpdateVRDisplays(nsTArray
<RefPtr
<mozilla::dom::VRDisplay
>>& aDisplays
);
522 // Inner windows only.
523 // Called to inform that the set of active VR displays has changed.
524 void NotifyActiveVRDisplaysChanged();
525 void NotifyDetectXRRuntimesCompleted();
526 void NotifyPresentationGenerationChanged(uint32_t aDisplayID
);
528 void DispatchVRDisplayActivate(uint32_t aDisplayID
,
529 mozilla::dom::VRDisplayEventReason aReason
);
530 void DispatchVRDisplayDeactivate(uint32_t aDisplayID
,
531 mozilla::dom::VRDisplayEventReason aReason
);
532 void DispatchVRDisplayConnect(uint32_t aDisplayID
);
533 void DispatchVRDisplayDisconnect(uint32_t aDisplayID
);
534 void DispatchVRDisplayPresentChange(uint32_t aDisplayID
);
536 #define EVENT(name_, id_, type_, struct_) \
537 mozilla::dom::EventHandlerNonNull* GetOn##name_() { \
538 mozilla::EventListenerManager* elm = GetExistingListenerManager(); \
539 return elm ? elm->GetEventHandler(nsGkAtoms::on##name_) : nullptr; \
541 void SetOn##name_(mozilla::dom::EventHandlerNonNull* handler) { \
542 mozilla::EventListenerManager* elm = GetOrCreateListenerManager(); \
544 elm->SetEventHandler(nsGkAtoms::on##name_, handler); \
547 #define ERROR_EVENT(name_, id_, type_, struct_) \
548 mozilla::dom::OnErrorEventHandlerNonNull* GetOn##name_() { \
549 mozilla::EventListenerManager* elm = GetExistingListenerManager(); \
550 return elm ? elm->GetOnErrorEventHandler() : nullptr; \
552 void SetOn##name_(mozilla::dom::OnErrorEventHandlerNonNull* handler) { \
553 mozilla::EventListenerManager* elm = GetOrCreateListenerManager(); \
555 elm->SetEventHandler(handler); \
558 #define BEFOREUNLOAD_EVENT(name_, id_, type_, struct_) \
559 mozilla::dom::OnBeforeUnloadEventHandlerNonNull* GetOn##name_() { \
560 mozilla::EventListenerManager* elm = GetExistingListenerManager(); \
561 return elm ? elm->GetOnBeforeUnloadEventHandler() : nullptr; \
564 mozilla::dom::OnBeforeUnloadEventHandlerNonNull* handler) { \
565 mozilla::EventListenerManager* elm = GetOrCreateListenerManager(); \
567 elm->SetEventHandler(handler); \
570 #define WINDOW_ONLY_EVENT EVENT
571 #define TOUCH_EVENT EVENT
572 #include "mozilla/EventNameList.h"
574 #undef WINDOW_ONLY_EVENT
575 #undef BEFOREUNLOAD_EVENT
579 nsISupports
* GetParentObject() { return nullptr; }
581 static JSObject
* CreateNamedPropertiesObject(JSContext
* aCx
,
582 JS::Handle
<JSObject
*> aProto
);
584 mozilla::dom::WindowProxyHolder
Window();
585 mozilla::dom::WindowProxyHolder
Self() { return Window(); }
586 Document
* GetDocument() { return GetDoc(); }
587 void GetName(nsAString
& aName
, mozilla::ErrorResult
& aError
);
588 void SetName(const nsAString
& aName
, mozilla::ErrorResult
& aError
);
589 mozilla::dom::Location
* Location() override
;
590 nsHistory
* GetHistory(mozilla::ErrorResult
& aError
);
591 mozilla::dom::CustomElementRegistry
* CustomElements() override
;
592 mozilla::dom::CustomElementRegistry
* GetExistingCustomElements();
593 mozilla::dom::BarProp
* GetLocationbar(mozilla::ErrorResult
& aError
);
594 mozilla::dom::BarProp
* GetMenubar(mozilla::ErrorResult
& aError
);
595 mozilla::dom::BarProp
* GetPersonalbar(mozilla::ErrorResult
& aError
);
596 mozilla::dom::BarProp
* GetScrollbars(mozilla::ErrorResult
& aError
);
597 mozilla::dom::BarProp
* GetStatusbar(mozilla::ErrorResult
& aError
);
598 mozilla::dom::BarProp
* GetToolbar(mozilla::ErrorResult
& aError
);
599 void GetStatus(nsAString
& aStatus
, mozilla::ErrorResult
& aError
);
600 void SetStatus(const nsAString
& aStatus
, mozilla::ErrorResult
& aError
);
601 void Close(mozilla::dom::CallerType aCallerType
,
602 mozilla::ErrorResult
& aError
);
603 nsresult
Close() override
;
604 bool GetClosed(mozilla::ErrorResult
& aError
);
605 void Stop(mozilla::ErrorResult
& aError
);
606 void Focus(mozilla::dom::CallerType aCallerType
,
607 mozilla::ErrorResult
& aError
);
608 nsresult
Focus(mozilla::dom::CallerType aCallerType
) override
;
609 void Blur(mozilla::dom::CallerType aCallerType
, mozilla::ErrorResult
& aError
);
610 mozilla::dom::WindowProxyHolder
GetFrames(mozilla::ErrorResult
& aError
);
612 mozilla::dom::Nullable
<mozilla::dom::WindowProxyHolder
> GetTop(
613 mozilla::ErrorResult
& aError
);
616 explicit nsGlobalWindowInner(nsGlobalWindowOuter
* aOuterWindow
,
617 mozilla::dom::WindowGlobalChild
* aActor
);
618 // Initializes the mWasOffline member variable
619 void InitWasOffline();
622 mozilla::dom::Nullable
<mozilla::dom::WindowProxyHolder
> GetOpenerWindow(
623 mozilla::ErrorResult
& aError
);
624 void GetOpener(JSContext
* aCx
, JS::MutableHandle
<JS::Value
> aRetval
,
625 mozilla::ErrorResult
& aError
);
626 void SetOpener(JSContext
* aCx
, JS::Handle
<JS::Value
> aOpener
,
627 mozilla::ErrorResult
& aError
);
628 void GetEvent(mozilla::dom::OwningEventOrUndefined
& aRetval
);
629 mozilla::dom::Nullable
<mozilla::dom::WindowProxyHolder
> GetParent(
630 mozilla::ErrorResult
& aError
);
631 nsPIDOMWindowOuter
* GetInProcessScriptableParent() override
;
632 mozilla::dom::Element
* GetFrameElement(nsIPrincipal
& aSubjectPrincipal
,
633 mozilla::ErrorResult
& aError
);
634 mozilla::dom::Nullable
<mozilla::dom::WindowProxyHolder
> Open(
635 const nsAString
& aUrl
, const nsAString
& aName
, const nsAString
& aOptions
,
636 mozilla::ErrorResult
& aError
);
637 int16_t Orientation(mozilla::dom::CallerType aCallerType
);
639 already_AddRefed
<mozilla::dom::Console
> GetConsole(JSContext
* aCx
,
640 mozilla::ErrorResult
& aRv
);
642 // https://w3c.github.io/webappsec-secure-contexts/#dom-window-issecurecontext
643 bool IsSecureContext() const;
645 mozilla::dom::External
* External();
647 mozilla::dom::Worklet
* GetPaintWorklet(mozilla::ErrorResult
& aRv
);
649 void GetRegionalPrefsLocales(nsTArray
<nsString
>& aLocales
);
651 void GetWebExposedLocales(nsTArray
<nsString
>& aLocales
);
653 mozilla::dom::IntlUtils
* GetIntlUtils(mozilla::ErrorResult
& aRv
);
655 void StoreSharedWorker(mozilla::dom::SharedWorker
* aSharedWorker
);
657 void ForgetSharedWorker(mozilla::dom::SharedWorker
* aSharedWorker
);
660 void Alert(nsIPrincipal
& aSubjectPrincipal
, mozilla::ErrorResult
& aError
);
661 void Alert(const nsAString
& aMessage
, nsIPrincipal
& aSubjectPrincipal
,
662 mozilla::ErrorResult
& aError
);
663 bool Confirm(const nsAString
& aMessage
, nsIPrincipal
& aSubjectPrincipal
,
664 mozilla::ErrorResult
& aError
);
665 void Prompt(const nsAString
& aMessage
, const nsAString
& aInitial
,
666 nsAString
& aReturn
, nsIPrincipal
& aSubjectPrincipal
,
667 mozilla::ErrorResult
& aError
);
668 already_AddRefed
<mozilla::dom::cache::CacheStorage
> GetCaches(
669 mozilla::ErrorResult
& aRv
);
670 already_AddRefed
<mozilla::dom::Promise
> Fetch(
671 const mozilla::dom::RequestOrUSVString
& aInput
,
672 const mozilla::dom::RequestInit
& aInit
,
673 mozilla::dom::CallerType aCallerType
, mozilla::ErrorResult
& aRv
);
674 MOZ_CAN_RUN_SCRIPT
void Print(mozilla::ErrorResult
& aError
);
675 MOZ_CAN_RUN_SCRIPT
mozilla::dom::Nullable
<mozilla::dom::WindowProxyHolder
>
676 PrintPreview(nsIPrintSettings
*, nsIWebProgressListener
*, nsIDocShell
*,
677 mozilla::ErrorResult
&);
678 void PostMessageMoz(JSContext
* aCx
, JS::Handle
<JS::Value
> aMessage
,
679 const nsAString
& aTargetOrigin
,
680 const mozilla::dom::Sequence
<JSObject
*>& aTransfer
,
681 nsIPrincipal
& aSubjectPrincipal
,
682 mozilla::ErrorResult
& aError
);
683 void PostMessageMoz(JSContext
* aCx
, JS::Handle
<JS::Value
> aMessage
,
684 const mozilla::dom::WindowPostMessageOptions
& aOptions
,
685 nsIPrincipal
& aSubjectPrincipal
,
686 mozilla::ErrorResult
& aError
);
689 int32_t SetTimeout(JSContext
* aCx
, mozilla::dom::Function
& aFunction
,
691 const mozilla::dom::Sequence
<JS::Value
>& aArguments
,
692 mozilla::ErrorResult
& aError
);
695 int32_t SetTimeout(JSContext
* aCx
, const nsAString
& aHandler
,
697 const mozilla::dom::Sequence
<JS::Value
>& /* unused */,
698 mozilla::ErrorResult
& aError
);
701 void ClearTimeout(int32_t aHandle
);
704 int32_t SetInterval(JSContext
* aCx
, mozilla::dom::Function
& aFunction
,
705 const int32_t aTimeout
,
706 const mozilla::dom::Sequence
<JS::Value
>& aArguments
,
707 mozilla::ErrorResult
& aError
);
710 int32_t SetInterval(JSContext
* aCx
, const nsAString
& aHandler
,
711 const int32_t aTimeout
,
712 const mozilla::dom::Sequence
<JS::Value
>& /* unused */,
713 mozilla::ErrorResult
& aError
);
716 void ClearInterval(int32_t aHandle
);
717 void GetOrigin(nsAString
& aOrigin
);
720 void ReportError(JSContext
* aCx
, JS::Handle
<JS::Value
> aError
,
721 mozilla::dom::CallerType aCallerType
,
722 mozilla::ErrorResult
& aRv
);
724 void Atob(const nsAString
& aAsciiBase64String
, nsAString
& aBinaryData
,
725 mozilla::ErrorResult
& aError
);
726 void Btoa(const nsAString
& aBinaryData
, nsAString
& aAsciiBase64String
,
727 mozilla::ErrorResult
& aError
);
728 mozilla::dom::Storage
* GetSessionStorage(mozilla::ErrorResult
& aError
);
729 mozilla::dom::Storage
* GetLocalStorage(mozilla::ErrorResult
& aError
);
730 mozilla::dom::Selection
* GetSelection(mozilla::ErrorResult
& aError
);
731 mozilla::dom::IDBFactory
* GetIndexedDB(JSContext
* aCx
,
732 mozilla::ErrorResult
& aError
);
733 already_AddRefed
<nsICSSDeclaration
> GetComputedStyle(
734 mozilla::dom::Element
& aElt
, const nsAString
& aPseudoElt
,
735 mozilla::ErrorResult
& aError
) override
;
736 mozilla::dom::VisualViewport
* VisualViewport();
737 already_AddRefed
<mozilla::dom::MediaQueryList
> MatchMedia(
738 const nsACString
& aQuery
, mozilla::dom::CallerType aCallerType
,
739 mozilla::ErrorResult
& aError
);
741 void MoveTo(int32_t aXPos
, int32_t aYPos
,
742 mozilla::dom::CallerType aCallerType
,
743 mozilla::ErrorResult
& aError
);
744 void MoveBy(int32_t aXDif
, int32_t aYDif
,
745 mozilla::dom::CallerType aCallerType
,
746 mozilla::ErrorResult
& aError
);
747 void ResizeTo(int32_t aWidth
, int32_t aHeight
,
748 mozilla::dom::CallerType aCallerType
,
749 mozilla::ErrorResult
& aError
);
750 void ResizeBy(int32_t aWidthDif
, int32_t aHeightDif
,
751 mozilla::dom::CallerType aCallerType
,
752 mozilla::ErrorResult
& aError
);
753 void Scroll(double aXScroll
, double aYScroll
);
754 void Scroll(const mozilla::dom::ScrollToOptions
& aOptions
);
755 void ScrollTo(double aXScroll
, double aYScroll
);
756 void ScrollTo(const mozilla::dom::ScrollToOptions
& aOptions
);
757 void ScrollBy(double aXScrollDif
, double aYScrollDif
);
758 void ScrollBy(const mozilla::dom::ScrollToOptions
& aOptions
);
759 void ScrollByLines(int32_t numLines
,
760 const mozilla::dom::ScrollOptions
& aOptions
);
761 void ScrollByPages(int32_t numPages
,
762 const mozilla::dom::ScrollOptions
& aOptions
);
763 void MozScrollSnap();
764 double GetScrollX(mozilla::ErrorResult
& aError
);
765 double GetPageXOffset(mozilla::ErrorResult
& aError
) {
766 return GetScrollX(aError
);
768 double GetScrollY(mozilla::ErrorResult
& aError
);
769 double GetPageYOffset(mozilla::ErrorResult
& aError
) {
770 return GetScrollY(aError
);
773 int32_t GetScreenLeft(mozilla::dom::CallerType aCallerType
,
774 mozilla::ErrorResult
& aError
) {
775 return GetScreenX(aCallerType
, aError
);
778 double ScreenEdgeSlopX() const;
779 double ScreenEdgeSlopY() const;
781 int32_t GetScreenTop(mozilla::dom::CallerType aCallerType
,
782 mozilla::ErrorResult
& aError
) {
783 return GetScreenY(aCallerType
, aError
);
786 void GetScreenX(JSContext
* aCx
, JS::MutableHandle
<JS::Value
> aValue
,
787 mozilla::dom::CallerType aCallerType
,
788 mozilla::ErrorResult
& aError
);
789 void GetScreenY(JSContext
* aCx
, JS::MutableHandle
<JS::Value
> aValue
,
790 mozilla::dom::CallerType aCallerType
,
791 mozilla::ErrorResult
& aError
);
792 void GetOuterWidth(JSContext
* aCx
, JS::MutableHandle
<JS::Value
> aValue
,
793 mozilla::dom::CallerType aCallerType
,
794 mozilla::ErrorResult
& aError
);
795 void GetOuterHeight(JSContext
* aCx
, JS::MutableHandle
<JS::Value
> aValue
,
796 mozilla::dom::CallerType aCallerType
,
797 mozilla::ErrorResult
& aError
);
800 int32_t RequestAnimationFrame(mozilla::dom::FrameRequestCallback
& aCallback
,
801 mozilla::ErrorResult
& aError
);
804 void CancelAnimationFrame(int32_t aHandle
, mozilla::ErrorResult
& aError
);
806 uint32_t RequestIdleCallback(JSContext
* aCx
,
807 mozilla::dom::IdleRequestCallback
& aCallback
,
808 const mozilla::dom::IdleRequestOptions
& aOptions
,
809 mozilla::ErrorResult
& aError
);
810 void CancelIdleCallback(uint32_t aHandle
);
813 mozilla::dom::SpeechSynthesis
* GetSpeechSynthesis(
814 mozilla::ErrorResult
& aError
);
815 bool HasActiveSpeechSynthesis();
818 mozilla::glean::Glean
* Glean();
819 mozilla::glean::GleanPings
* GleanPings();
821 already_AddRefed
<nsICSSDeclaration
> GetDefaultComputedStyle(
822 mozilla::dom::Element
& aElt
, const nsAString
& aPseudoElt
,
823 mozilla::ErrorResult
& aError
);
824 void SizeToContent(mozilla::dom::CallerType aCallerType
,
825 mozilla::ErrorResult
& aError
);
826 void SizeToContentConstrained(const mozilla::dom::SizeToContentConstraints
&,
827 mozilla::ErrorResult
&);
828 mozilla::dom::Crypto
* GetCrypto(mozilla::ErrorResult
& aError
);
829 nsIControllers
* GetControllers(mozilla::ErrorResult
& aError
);
830 nsresult
GetControllers(nsIControllers
** aControllers
) override
;
831 mozilla::dom::Element
* GetRealFrameElement(mozilla::ErrorResult
& aError
);
832 float GetMozInnerScreenX(mozilla::dom::CallerType aCallerType
,
833 mozilla::ErrorResult
& aError
);
834 float GetMozInnerScreenY(mozilla::dom::CallerType aCallerType
,
835 mozilla::ErrorResult
& aError
);
836 double GetDevicePixelRatio(mozilla::dom::CallerType aCallerType
,
837 mozilla::ErrorResult
& aError
);
838 double GetDesktopToDeviceScale(mozilla::ErrorResult
& aError
);
839 int32_t GetScrollMinX(mozilla::ErrorResult
& aError
);
840 int32_t GetScrollMinY(mozilla::ErrorResult
& aError
);
841 int32_t GetScrollMaxX(mozilla::ErrorResult
& aError
);
842 int32_t GetScrollMaxY(mozilla::ErrorResult
& aError
);
843 bool GetFullScreen(mozilla::ErrorResult
& aError
);
844 bool GetFullScreen() override
;
845 void SetFullScreen(bool aFullscreen
, mozilla::ErrorResult
& aError
);
846 bool Find(const nsAString
& aString
, bool aCaseSensitive
, bool aBackwards
,
847 bool aWrapAround
, bool aWholeWord
, bool aSearchInFrames
,
848 bool aShowDialog
, mozilla::ErrorResult
& aError
);
850 bool DidFireDocElemInserted() const { return mDidFireDocElemInserted
; }
851 void SetDidFireDocElemInserted() { mDidFireDocElemInserted
= true; }
853 mozilla::dom::Nullable
<mozilla::dom::WindowProxyHolder
> OpenDialog(
854 JSContext
* aCx
, const nsAString
& aUrl
, const nsAString
& aName
,
855 const nsAString
& aOptions
,
856 const mozilla::dom::Sequence
<JS::Value
>& aExtraArgument
,
857 mozilla::ErrorResult
& aError
);
858 void UpdateCommands(const nsAString
& anAction
);
860 void GetContent(JSContext
* aCx
, JS::MutableHandle
<JSObject
*> aRetval
,
861 mozilla::dom::CallerType aCallerType
,
862 mozilla::ErrorResult
& aError
);
864 already_AddRefed
<mozilla::dom::Promise
> CreateImageBitmap(
865 const mozilla::dom::ImageBitmapSource
& aImage
,
866 const mozilla::dom::ImageBitmapOptions
& aOptions
,
867 mozilla::ErrorResult
& aRv
);
869 already_AddRefed
<mozilla::dom::Promise
> CreateImageBitmap(
870 const mozilla::dom::ImageBitmapSource
& aImage
, int32_t aSx
, int32_t aSy
,
871 int32_t aSw
, int32_t aSh
,
872 const mozilla::dom::ImageBitmapOptions
& aOptions
,
873 mozilla::ErrorResult
& aRv
);
875 void StructuredClone(JSContext
* aCx
, JS::Handle
<JS::Value
> aValue
,
876 const mozilla::dom::StructuredSerializeOptions
& aOptions
,
877 JS::MutableHandle
<JS::Value
> aRetval
,
878 mozilla::ErrorResult
& aError
);
880 // ChromeWindow bits. Do NOT call these unless your window is in
882 uint16_t WindowState();
883 bool IsFullyOccluded();
884 nsIBrowserDOMWindow
* GetBrowserDOMWindow(mozilla::ErrorResult
& aError
);
885 void SetBrowserDOMWindow(nsIBrowserDOMWindow
* aBrowserWindow
,
886 mozilla::ErrorResult
& aError
);
887 void GetAttention(mozilla::ErrorResult
& aError
);
888 void GetAttentionWithCycleCount(int32_t aCycleCount
,
889 mozilla::ErrorResult
& aError
);
890 void SetCursor(const nsACString
& aCursor
, mozilla::ErrorResult
& aError
);
894 void GetWorkspaceID(nsAString
& workspaceID
);
895 void MoveToWorkspace(const nsAString
& workspaceID
);
896 void NotifyDefaultButtonLoaded(mozilla::dom::Element
& aDefaultButton
,
897 mozilla::ErrorResult
& aError
);
898 mozilla::dom::ChromeMessageBroadcaster
* MessageManager();
899 mozilla::dom::ChromeMessageBroadcaster
* GetGroupMessageManager(
900 const nsAString
& aGroup
);
902 already_AddRefed
<mozilla::dom::Promise
> PromiseDocumentFlushed(
903 mozilla::dom::PromiseDocumentFlushedCallback
& aCallback
,
904 mozilla::ErrorResult
& aError
);
906 void GetInterface(JSContext
* aCx
, JS::Handle
<JS::Value
> aIID
,
907 JS::MutableHandle
<JS::Value
> aRetval
,
908 mozilla::ErrorResult
& aError
);
910 already_AddRefed
<nsWindowRoot
> GetWindowRoot(mozilla::ErrorResult
& aError
);
912 bool ShouldReportForServiceWorkerScope(const nsAString
& aScope
);
914 mozilla::dom::InstallTriggerImpl
* GetInstallTrigger();
916 nsIDOMWindowUtils
* GetWindowUtils(mozilla::ErrorResult
& aRv
);
918 void UpdateTopInnerWindow();
920 virtual bool IsInSyncOperation() override
;
922 // Early during inner window creation, `IsSharedMemoryAllowedInternal`
923 // is called before the `mDoc` field has been initialized in order to
924 // determine whether to expose the `SharedArrayBuffer` constructor on the
925 // JS global. We still want to consider the document's principal to see if
926 // it is a privileged extension which should be exposed to
927 // `SharedArrayBuffer`, however the inner window doesn't know the document's
928 // principal yet. `aPrincipalOverride` is used in that situation to provide
929 // the principal for the to-be-loaded document.
930 bool IsSharedMemoryAllowed() const override
{
931 return IsSharedMemoryAllowedInternal(
932 const_cast<nsGlobalWindowInner
*>(this)->GetPrincipal());
935 bool IsSharedMemoryAllowedInternal(nsIPrincipal
* aPrincipal
= nullptr) const;
937 // https://whatpr.org/html/4734/structured-data.html#cross-origin-isolated
938 bool CrossOriginIsolated() const override
;
940 mozilla::dom::WebTaskScheduler
* Scheduler();
945 // Redefine the property called aPropName on this window object to be a value
946 // property with the value aValue, much like we would do for a [Replaceable]
948 void RedefineProperty(JSContext
* aCx
, const char* aPropName
,
949 JS::Handle
<JS::Value
> aValue
,
950 mozilla::ErrorResult
& aError
);
952 nsresult
GetInnerWidth(double* aWidth
) override
;
953 nsresult
GetInnerHeight(double* aHeight
) override
;
956 double GetInnerWidth(mozilla::ErrorResult
& aError
);
957 double GetInnerHeight(mozilla::ErrorResult
& aError
);
958 int32_t GetScreenX(mozilla::dom::CallerType aCallerType
,
959 mozilla::ErrorResult
& aError
);
960 int32_t GetScreenY(mozilla::dom::CallerType aCallerType
,
961 mozilla::ErrorResult
& aError
);
962 int32_t GetOuterWidth(mozilla::dom::CallerType aCallerType
,
963 mozilla::ErrorResult
& aError
);
964 int32_t GetOuterHeight(mozilla::dom::CallerType aCallerType
,
965 mozilla::ErrorResult
& aError
);
968 friend class HashchangeCallback
;
969 friend class mozilla::dom::BarProp
;
972 virtual ~nsGlobalWindowInner();
974 void FreeInnerObjects();
976 // Initialize state that depends on the document. By this point, mDoc should
977 // be set correctly and have us set as its script global object.
978 void InitDocumentDependentState(JSContext
* aCx
);
980 nsresult
EnsureClientSource();
981 nsresult
ExecutionReady();
983 // Inner windows only.
984 nsresult
DefineArgumentsProperty(nsIArray
* aArguments
);
986 // Get the parent, returns null if this is a toplevel window
987 nsPIDOMWindowOuter
* GetInProcessParentInternal();
990 template <typename Method
, typename
... Args
>
991 mozilla::CallState
CallOnInProcessDescendantsInternal(
992 mozilla::dom::BrowsingContext
* aBrowsingContext
, bool aChildOnly
,
993 Method aMethod
, Args
&&... aArgs
);
995 // Call the given method on the immediate children of this window. The
996 // CallState returned by the last child method invocation is returned or
997 // CallState::Continue if the method returns void.
998 template <typename Method
, typename
... Args
>
999 mozilla::CallState
CallOnInProcessChildren(Method aMethod
, Args
&&... aArgs
) {
1000 MOZ_ASSERT(IsCurrentInnerWindow());
1001 return CallOnInProcessDescendantsInternal(GetBrowsingContext(), true,
1005 // Call the given method on the descendant of this window. The CallState
1006 // returned by the last descendant method invocation is returned or
1007 // CallState::Continue if the method returns void.
1008 template <typename Method
, typename
... Args
>
1009 mozilla::CallState
CallOnInProcessDescendants(Method aMethod
,
1011 MOZ_ASSERT(IsCurrentInnerWindow());
1012 return CallOnInProcessDescendantsInternal(GetBrowsingContext(), false,
1016 // Helper to convert a void returning child method into an implicit
1017 // CallState::Continue value.
1018 template <typename Return
, typename Method
, typename
... Args
>
1019 typename
std::enable_if
<std::is_void
<Return
>::value
, mozilla::CallState
>::type
1020 CallDescendant(nsGlobalWindowInner
* aWindow
, Method aMethod
,
1022 (aWindow
->*aMethod
)(aArgs
...);
1023 return mozilla::CallState::Continue
;
1026 // Helper that passes through the CallState value from a child method.
1027 template <typename Return
, typename Method
, typename
... Args
>
1028 typename
std::enable_if
<std::is_same
<Return
, mozilla::CallState
>::value
,
1029 mozilla::CallState
>::type
1030 CallDescendant(nsGlobalWindowInner
* aWindow
, Method aMethod
,
1032 return (aWindow
->*aMethod
)(aArgs
...);
1035 void FreezeInternal(bool aIncludeSubWindows
);
1036 void ThawInternal(bool aIncludeSubWindows
);
1038 mozilla::CallState
ShouldReportForServiceWorkerScopeInternal(
1039 const nsACString
& aScope
, bool* aResultOut
);
1042 // Timeout Functions
1043 // |interval| is in milliseconds.
1045 int32_t SetTimeoutOrInterval(
1046 JSContext
* aCx
, mozilla::dom::Function
& aFunction
, int32_t aTimeout
,
1047 const mozilla::dom::Sequence
<JS::Value
>& aArguments
, bool aIsInterval
,
1048 mozilla::ErrorResult
& aError
);
1051 int32_t SetTimeoutOrInterval(JSContext
* aCx
, const nsAString
& aHandler
,
1052 int32_t aTimeout
, bool aIsInterval
,
1053 mozilla::ErrorResult
& aError
);
1055 // Return true if |aTimeout| was cleared while its handler ran.
1057 bool RunTimeoutHandler(mozilla::dom::Timeout
* aTimeout
,
1058 nsIScriptContext
* aScx
);
1061 already_AddRefed
<nsIDocShellTreeOwner
> GetTreeOwner();
1062 already_AddRefed
<nsIWebBrowserChrome
> GetWebBrowserChrome();
1063 bool IsPrivateBrowsing();
1065 void FireOfflineStatusEventIfChanged();
1068 // Inner windows only.
1069 nsresult
FireHashchange(const nsAString
& aOldURL
, const nsAString
& aNewURL
);
1071 void FlushPendingNotifications(mozilla::FlushType aType
);
1073 void ScrollTo(const mozilla::CSSIntPoint
& aScroll
,
1074 const mozilla::dom::ScrollOptions
& aOptions
);
1076 already_AddRefed
<nsIWidget
> GetMainWidget();
1077 nsIWidget
* GetNearestWidget() const;
1079 bool IsInModalState();
1081 void SetFocusedElement(mozilla::dom::Element
* aElement
,
1082 uint32_t aFocusMethod
= 0,
1083 bool aNeedsFocus
= false) override
;
1085 uint32_t GetFocusMethod() override
;
1087 bool ShouldShowFocusRing() override
;
1089 // Inner windows only.
1090 void UpdateCanvasFocus(bool aFocusChanged
, nsIContent
* aNewContent
);
1093 virtual already_AddRefed
<nsPIWindowRoot
> GetTopWindowRoot() override
;
1095 // Get the toplevel principal, returns null if this is a toplevel window.
1096 nsIPrincipal
* GetTopLevelAntiTrackingPrincipal();
1098 // Get the client principal, returns null if the clientSource is not
1100 nsIPrincipal
* GetClientPrincipal();
1102 // Whether the chrome window is currently in a full screen transition. This
1103 // flag is updated from FullscreenTransitionTask.
1104 bool IsInFullScreenTransition();
1106 // This method is called if this window loads a 3rd party tracking resource
1107 // and the storage is just been changed. The window can reset the partitioned
1108 // storage objects and switch to the first party cookie jar.
1109 void StorageAccessPermissionChanged();
1112 static void NotifyDOMWindowDestroyed(nsGlobalWindowInner
* aWindow
);
1113 void NotifyWindowIDDestroyed(const char* aTopic
);
1115 static void NotifyDOMWindowFrozen(nsGlobalWindowInner
* aWindow
);
1116 static void NotifyDOMWindowThawed(nsGlobalWindowInner
* aWindow
);
1118 virtual void UpdateParentTarget() override
;
1120 // Clear the document-dependent slots on our JS wrapper. Inner windows only.
1121 void ClearDocumentDependentSlots(JSContext
* aCx
);
1123 // Inner windows only.
1124 already_AddRefed
<mozilla::dom::StorageEvent
> CloneStorageEvent(
1125 const nsAString
& aType
, const RefPtr
<mozilla::dom::StorageEvent
>& aEvent
,
1126 mozilla::ErrorResult
& aRv
);
1129 already_AddRefed
<nsICSSDeclaration
> GetComputedStyleHelper(
1130 mozilla::dom::Element
& aElt
, const nsAString
& aPseudoElt
,
1131 bool aDefaultStylesOnly
, mozilla::ErrorResult
& aError
);
1133 nsGlobalWindowInner
* InnerForSetTimeoutOrInterval(
1134 mozilla::ErrorResult
& aError
);
1136 void PostMessageMoz(JSContext
* aCx
, JS::Handle
<JS::Value
> aMessage
,
1137 const nsAString
& aTargetOrigin
,
1138 JS::Handle
<JS::Value
> aTransfer
,
1139 nsIPrincipal
& aSubjectPrincipal
,
1140 mozilla::ErrorResult
& aError
);
1143 // Fire the JS engine's onNewGlobalObject hook. Only used on inner windows.
1144 void FireOnNewGlobalObject();
1146 // Helper for resolving the components shim.
1147 bool ResolveComponentsShim(
1148 JSContext
* aCx
, JS::Handle
<JSObject
*> aObj
,
1149 JS::MutableHandle
<mozilla::Maybe
<JS::PropertyDescriptor
>> aDesc
);
1151 // nsPIDOMWindow{Inner,Outer} should be able to see these helper methods.
1152 friend class nsPIDOMWindowInner
;
1153 friend class nsPIDOMWindowOuter
;
1155 bool IsBackgroundInternal() const;
1157 // NOTE: Chrome Only
1158 void DisconnectAndClearGroupMessageManagers() {
1159 MOZ_RELEASE_ASSERT(IsChromeWindow());
1160 for (const auto& entry
: mChromeFields
.mGroupMessageManagers
) {
1161 mozilla::dom::ChromeMessageBroadcaster
* mm
= entry
.GetWeak();
1166 mChromeFields
.mGroupMessageManagers
.Clear();
1169 // Call mDocumentFlushedResolvers items, and perform MicroTask checkpoint
1172 // If aUntilExhaustion is true, then we call resolvers that get added as a
1173 // result synchronously, otherwise we wait until the next refresh driver tick.
1174 void CallDocumentFlushedResolvers(bool aUntilExhaustion
);
1176 // Called after a refresh driver tick. See documentation of
1177 // CallDocumentFlushedResolvers for the meaning of aUntilExhaustion.
1179 // Returns whether we need to keep observing the refresh driver or not.
1180 bool MaybeCallDocumentFlushedResolvers(bool aUntilExhaustion
);
1182 // Try to fire the "load" event on our content embedder if we're an iframe.
1183 MOZ_CAN_RUN_SCRIPT
void FireFrameLoadEvent();
1185 void UpdateAutoplayPermission();
1186 void UpdateShortcutsPermission();
1187 void UpdatePopupPermission();
1189 void UpdatePermissions();
1192 static uint32_t GetShortcutsPermission(nsIPrincipal
* aPrincipal
);
1194 // Dispatch a runnable related to the global.
1195 nsresult
Dispatch(already_AddRefed
<nsIRunnable
>&& aRunnable
) const final
;
1196 nsISerialEventTarget
* SerialEventTarget() const final
;
1198 void DisableIdleCallbackRequests();
1199 uint32_t LastIdleRequestHandle() const {
1200 return mIdleRequestCallbackCounter
- 1;
1203 void RunIdleRequest(mozilla::dom::IdleRequest
* aRequest
,
1204 DOMHighResTimeStamp aDeadline
, bool aDidTimeout
);
1206 void ExecuteIdleRequest(TimeStamp aDeadline
);
1207 void ScheduleIdleRequestDispatch();
1208 void SuspendIdleRequests();
1209 void ResumeIdleRequests();
1211 using IdleRequests
= mozilla::LinkedList
<RefPtr
<mozilla::dom::IdleRequest
>>;
1212 void RemoveIdleCallback(mozilla::dom::IdleRequest
* aRequest
);
1214 void SetActiveLoadingState(bool aIsLoading
) override
;
1216 // Hint to the JS engine whether we are currently loading.
1217 void HintIsLoading(bool aIsLoading
);
1219 mozilla::dom::ContentMediaController
* GetContentMediaController();
1221 bool TryOpenExternalProtocolIframe() {
1222 if (mHasOpenedExternalProtocolFrame
) {
1225 mHasOpenedExternalProtocolFrame
= true;
1229 nsTArray
<uint32_t>& GetScrollMarks() { return mScrollMarks
; }
1230 bool GetScrollMarksOnHScrollbar() const { return mScrollMarksOnHScrollbar
; }
1231 void SetScrollMarks(const nsTArray
<uint32_t>& aScrollMarks
,
1232 bool aOnHScrollbar
);
1234 // Don't use this value directly, call StorageAccess::StorageAllowedForWindow
1236 mozilla::Maybe
<mozilla::StorageAccess
> GetStorageAllowedCache(
1237 uint32_t& aRejectedReason
) {
1238 if (mStorageAllowedCache
.isSome()) {
1239 aRejectedReason
= mStorageAllowedReasonCache
;
1241 return mStorageAllowedCache
;
1243 void SetStorageAllowedCache(const mozilla::StorageAccess
& storageAllowed
,
1244 uint32_t aRejectedReason
) {
1245 mStorageAllowedCache
= Some(storageAllowed
);
1246 mStorageAllowedReasonCache
= aRejectedReason
;
1248 void ClearStorageAllowedCache() {
1249 mStorageAllowedCache
= mozilla::Nothing();
1250 mStorageAllowedReasonCache
= 0;
1253 virtual JS::loader::ModuleLoaderBase
* GetModuleLoader(
1254 JSContext
* aCx
) override
;
1257 RefPtr
<mozilla::dom::ContentMediaController
> mContentMediaController
;
1259 RefPtr
<mozilla::dom::WebTaskSchedulerMainThread
> mWebTaskScheduler
;
1262 // Whether we need to care about orientation changes.
1263 bool mHasOrientationChangeListeners
: 1;
1265 // Window offline status. Checked to see if we need to fire offline event
1266 bool mWasOffline
: 1;
1268 // Represents whether the inner window's page has had a slow script notice.
1269 // Only used by inner windows; will always be false for outer windows.
1270 // This is used to implement Telemetry measures such as
1271 // SLOW_SCRIPT_PAGE_COUNT.
1272 bool mHasHadSlowScript
: 1;
1274 // Fast way to tell if this is a chrome window (without having to QI).
1277 // Hack to indicate whether a chrome window needs its message manager
1278 // to be disconnected, since clean up code is shared in the global
1279 // window superclass.
1280 bool mCleanMessageManager
: 1;
1282 // Indicates that the current document has never received a document focus
1284 bool mNeedsFocus
: 1;
1287 // true if tab navigation has occurred for this window. Focus rings
1288 // should be displayed.
1289 bool mFocusByKeyOccurred
: 1;
1291 // True if we have notified document-element-inserted observers for this
1293 bool mDidFireDocElemInserted
: 1;
1295 // Indicates whether this window wants gamepad input events
1296 bool mHasGamepad
: 1;
1298 // Indicates whether this window has content that has an XR session
1299 // An XR session results in enumeration and activation of XR devices.
1300 bool mHasXRSession
: 1;
1302 // Indicates whether this window wants VRDisplayActivate events
1303 bool mHasVRDisplayActivateEvents
: 1;
1305 // Indicates that a request for XR runtime detection has been
1306 // requested, but has not yet been resolved
1307 bool mXRRuntimeDetectionInFlight
: 1;
1309 // Indicates that an XR permission request has been requested
1310 // but has not yet been resolved.
1311 bool mXRPermissionRequestInFlight
: 1;
1313 // Indicates that an XR permission request has been granted.
1314 // The page should not request permission multiple times.
1315 bool mXRPermissionGranted
: 1;
1317 // True if this was the currently-active inner window for a BrowsingContext at
1318 // the time it was discarded.
1319 bool mWasCurrentInnerWindow
: 1;
1320 void SetWasCurrentInnerWindow() { mWasCurrentInnerWindow
= true; }
1321 bool WasCurrentInnerWindow() const override
{ return mWasCurrentInnerWindow
; }
1323 bool mHasSeenGamepadInput
: 1;
1325 // Whether we told the JS engine that we were in pageload.
1326 bool mHintedWasLoading
: 1;
1328 // Whether this window has opened an external-protocol iframe without user
1329 // activation once already. Only relevant for top windows.
1330 bool mHasOpenedExternalProtocolFrame
: 1;
1332 bool mScrollMarksOnHScrollbar
: 1;
1334 nsCheapSet
<nsUint32HashKey
> mGamepadIndexSet
;
1335 nsRefPtrHashtable
<nsGenericHashKey
<mozilla::dom::GamepadHandle
>,
1336 mozilla::dom::Gamepad
>
1339 RefPtr
<nsScreen
> mScreen
;
1341 RefPtr
<mozilla::dom::BarProp
> mMenubar
;
1342 RefPtr
<mozilla::dom::BarProp
> mToolbar
;
1343 RefPtr
<mozilla::dom::BarProp
> mLocationbar
;
1344 RefPtr
<mozilla::dom::BarProp
> mPersonalbar
;
1345 RefPtr
<mozilla::dom::BarProp
> mStatusbar
;
1346 RefPtr
<mozilla::dom::BarProp
> mScrollbars
;
1348 RefPtr
<nsGlobalWindowObserver
> mObserver
;
1349 RefPtr
<mozilla::dom::Crypto
> mCrypto
;
1350 RefPtr
<mozilla::dom::cache::CacheStorage
> mCacheStorage
;
1351 RefPtr
<mozilla::dom::Console
> mConsole
;
1352 RefPtr
<mozilla::dom::Worklet
> mPaintWorklet
;
1353 RefPtr
<mozilla::dom::External
> mExternal
;
1354 RefPtr
<mozilla::dom::InstallTriggerImpl
> mInstallTrigger
;
1356 RefPtr
<mozilla::dom::Storage
> mLocalStorage
;
1357 RefPtr
<mozilla::dom::Storage
> mSessionStorage
;
1359 RefPtr
<mozilla::EventListenerManager
> mListenerManager
;
1360 RefPtr
<mozilla::dom::Location
> mLocation
;
1361 RefPtr
<nsHistory
> mHistory
;
1362 RefPtr
<mozilla::dom::CustomElementRegistry
> mCustomElements
;
1364 nsTObserverArray
<RefPtr
<mozilla::dom::SharedWorker
>> mSharedWorkers
;
1366 RefPtr
<mozilla::dom::VisualViewport
> mVisualViewport
;
1368 // The document's principals and CSP are only stored if
1369 // FreeInnerObjects has been called.
1370 nsCOMPtr
<nsIPrincipal
> mDocumentPrincipal
;
1371 nsCOMPtr
<nsIPrincipal
> mDocumentCookiePrincipal
;
1372 nsCOMPtr
<nsIPrincipal
> mDocumentStoragePrincipal
;
1373 nsCOMPtr
<nsIPrincipal
> mDocumentPartitionedPrincipal
;
1374 nsCOMPtr
<nsIContentSecurityPolicy
> mDocumentCsp
;
1376 // Used to cache the result of StorageAccess::StorageAllowedForWindow.
1377 // Don't use this field directly, use StorageAccess::StorageAllowedForWindow
1379 mozilla::Maybe
<mozilla::StorageAccess
> mStorageAllowedCache
;
1380 uint32_t mStorageAllowedReasonCache
;
1382 RefPtr
<mozilla::dom::DebuggerNotificationManager
>
1383 mDebuggerNotificationManager
;
1385 // mBrowserChild is only ever populated in the content process.
1386 nsCOMPtr
<nsIBrowserChild
> mBrowserChild
;
1388 uint32_t mSuspendDepth
;
1389 uint32_t mFreezeDepth
;
1395 // the method that was used to focus mFocusedElement
1396 uint32_t mFocusMethod
;
1398 // Only relevant if we're listening for orientation changes.
1399 int16_t mOrientationAngle
= 0;
1401 // The current idle request callback handle
1402 uint32_t mIdleRequestCallbackCounter
;
1403 IdleRequests mIdleRequestCallbacks
;
1404 RefPtr
<IdleRequestExecutor
> mIdleRequestExecutor
;
1407 nsCOMPtr
<nsIURI
> mLastOpenedURI
;
1410 RefPtr
<mozilla::dom::IDBFactory
> mIndexedDB
;
1412 // This flag keeps track of whether this window is currently
1413 // observing refresh notifications from the refresh driver.
1414 bool mObservingRefresh
;
1416 bool mIteratingDocumentFlushedResolvers
;
1418 bool TryToObserveRefresh();
1420 nsTArray
<uint32_t> mEnabledSensors
;
1422 #ifdef MOZ_WEBSPEECH
1423 RefPtr
<mozilla::dom::SpeechSynthesis
> mSpeechSynthesis
;
1426 RefPtr
<mozilla::glean::Glean
> mGlean
;
1427 RefPtr
<mozilla::glean::GleanPings
> mGleanPings
;
1429 // This is the CC generation the last time we called CanSkip.
1430 uint32_t mCanSkipCCGeneration
;
1432 // The VR Displays for this window
1433 nsTArray
<RefPtr
<mozilla::dom::VRDisplay
>> mVRDisplays
;
1435 RefPtr
<mozilla::dom::VREventObserver
> mVREventObserver
;
1437 // The number of unload and beforeunload event listeners registered on this
1439 uint64_t mUnloadOrBeforeUnloadListenerCount
= 0;
1441 RefPtr
<mozilla::dom::IntlUtils
> mIntlUtils
;
1443 mozilla::UniquePtr
<mozilla::dom::ClientSource
> mClientSource
;
1445 nsTArray
<mozilla::UniquePtr
<PromiseDocumentFlushedResolver
>>
1446 mDocumentFlushedResolvers
;
1448 nsTArray
<uint32_t> mScrollMarks
;
1450 nsTArray
<mozilla::WeakPtr
<Document
>> mDataDocumentsForMemoryReporting
;
1452 static InnerWindowByIdTable
* sInnerWindowsById
;
1454 // Members in the mChromeFields member should only be used in chrome windows.
1455 // All accesses to this field should be guarded by a check of mIsChrome.
1456 struct ChromeFields
{
1457 RefPtr
<mozilla::dom::ChromeMessageBroadcaster
> mMessageManager
;
1458 nsRefPtrHashtable
<nsStringHashKey
, mozilla::dom::ChromeMessageBroadcaster
>
1459 mGroupMessageManagers
{1};
1462 // These fields are used by the inner and outer windows to prevent
1463 // programatically moving the window while the mouse is down.
1464 static bool sMouseDown
;
1465 static bool sDragServiceDisabled
;
1467 friend class nsDOMWindowUtils
;
1468 friend class mozilla::dom::PostMessageEvent
;
1469 friend class mozilla::dom::TimeoutManager
;
1470 friend class IdleRequestExecutor
;
1471 friend class nsGlobalWindowOuter
;
1474 inline nsISupports
* ToSupports(nsGlobalWindowInner
* p
) {
1475 return static_cast<mozilla::dom::EventTarget
*>(p
);
1478 inline nsISupports
* ToCanonicalSupports(nsGlobalWindowInner
* p
) {
1479 return static_cast<mozilla::dom::EventTarget
*>(p
);
1482 // XXX: EWW - This is an awful hack - let's not do this
1483 #include "nsGlobalWindowOuter.h"
1485 inline nsIGlobalObject
* nsGlobalWindowInner::GetOwnerGlobal() const {
1486 return const_cast<nsGlobalWindowInner
*>(this);
1489 inline nsGlobalWindowOuter
* nsGlobalWindowInner::GetInProcessTopInternal() {
1490 nsGlobalWindowOuter
* outer
= GetOuterWindowInternal();
1491 nsCOMPtr
<nsPIDOMWindowOuter
> top
= outer
? outer
->GetInProcessTop() : nullptr;
1493 return nsGlobalWindowOuter::Cast(top
);
1498 inline nsGlobalWindowOuter
*
1499 nsGlobalWindowInner::GetInProcessScriptableTopInternal() {
1500 nsPIDOMWindowOuter
* top
= GetInProcessScriptableTop();
1501 return nsGlobalWindowOuter::Cast(top
);
1504 inline nsIScriptContext
* nsGlobalWindowInner::GetContextInternal() {
1506 return GetOuterWindowInternal()->mContext
;
1512 inline nsGlobalWindowOuter
* nsGlobalWindowInner::GetOuterWindowInternal()
1514 return nsGlobalWindowOuter::Cast(GetOuterWindow());
1517 #endif /* nsGlobalWindowInner_h___ */