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 nsPIDOMWindow_h__
8 #define nsPIDOMWindow_h__
10 #include "nsIDOMWindow.h"
11 #include "mozIDOMWindow.h"
16 #include "mozilla/dom/EventTarget.h"
17 #include "mozilla/EventForwards.h"
18 #include "mozilla/Maybe.h"
19 #include "js/TypeDecls.h"
20 #include "nsRefPtrHashtable.h"
21 #include "nsILoadInfo.h"
23 // Only fired for inner windows.
24 #define DOM_WINDOW_DESTROYED_TOPIC "dom-window-destroyed"
25 #define DOM_WINDOW_FROZEN_TOPIC "dom-window-frozen"
26 #define DOM_WINDOW_THAWED_TOPIC "dom-window-thawed"
28 class nsGlobalWindowInner
;
29 class nsGlobalWindowOuter
;
34 class nsIContentSecurityPolicy
;
35 class nsICSSDeclaration
;
37 class nsIDocShellTreeOwner
;
38 class nsDocShellLoadState
;
41 class nsIScriptTimeoutHandler
;
42 class nsISerialEventTarget
;
44 class nsIWebBrowserChrome
;
45 class nsPIDOMWindowInner
;
46 class nsPIDOMWindowOuter
;
49 using SuspendTypes
= uint32_t;
51 namespace mozilla::dom
{
53 class BrowsingContext
;
54 class BrowsingContextGroup
;
57 class ContentFrameMessageManager
;
68 class ServiceWorkerDescriptor
;
72 class WindowGlobalChild
;
73 class CustomElementRegistry
;
74 enum class CallerType
: uint32_t;
75 } // namespace mozilla::dom
77 enum class FullscreenReason
{
78 // Toggling the fullscreen mode requires trusted context.
80 // Fullscreen API is the API provided to untrusted content.
82 // This reason can only be used with exiting fullscreen.
83 // It is otherwise identical to eForFullscreenAPI except it would
84 // suppress the fullscreen transition.
85 ForForceExitFullscreen
88 // Must be kept in sync with xpcom/rust/xpcom/src/interfaces/nonidl.rs
89 #define NS_PIDOMWINDOWINNER_IID \
91 0x775dabc9, 0x8f43, 0x4277, { \
92 0x9a, 0xdb, 0xf1, 0x99, 0x0d, 0x77, 0xcf, 0xfb \
96 // Must be kept in sync with xpcom/rust/xpcom/src/interfaces/nonidl.rs
97 #define NS_PIDOMWINDOWOUTER_IID \
99 0x769693d4, 0xb009, 0x4fe2, { \
100 0xaf, 0x18, 0x7d, 0xc8, 0xdf, 0x74, 0x96, 0xdf \
104 class nsPIDOMWindowInner
: public mozIDOMWindow
{
106 using Document
= mozilla::dom::Document
;
107 friend nsGlobalWindowInner
;
108 friend nsGlobalWindowOuter
;
110 nsPIDOMWindowInner(nsPIDOMWindowOuter
* aOuterWindow
,
111 mozilla::dom::WindowGlobalChild
* aActor
);
113 ~nsPIDOMWindowInner();
116 NS_DECLARE_STATIC_IID_ACCESSOR(NS_PIDOMWINDOWINNER_IID
)
118 nsIGlobalObject
* AsGlobal();
119 const nsIGlobalObject
* AsGlobal() const;
121 nsPIDOMWindowOuter
* GetOuterWindow() const { return mOuterWindow
; }
123 static nsPIDOMWindowInner
* From(mozIDOMWindow
* aFrom
) {
124 return static_cast<nsPIDOMWindowInner
*>(aFrom
);
127 NS_IMPL_FROMEVENTTARGET_HELPER_WITH_GETTER(nsPIDOMWindowInner
,
130 // Returns true if this object is the currently-active inner window for its
132 bool IsCurrentInnerWindow() const;
134 // Returns true if the document of this window is the active document. This
135 // is identical to IsCurrentInnerWindow() now that document.open() no longer
136 // creates new inner windows for the document it is called on.
137 inline bool HasActiveDocument() const;
139 // Return true if this object is the currently-active inner window for its
140 // BrowsingContext and any container document is also fully active.
141 // For https://html.spec.whatwg.org/multipage/browsers.html#fully-active
142 bool IsFullyActive() const;
144 // Returns true if this window is the same as mTopInnerWindow
145 inline bool IsTopInnerWindow() const;
147 // Returns true if this was the current window for its BrowsingContext when it
149 virtual bool WasCurrentInnerWindow() const = 0;
151 // Check whether a document is currently loading (really checks if the
152 // load event has completed). May not be reset to false on errors.
153 inline bool IsLoading() const;
154 inline bool IsHandlingResizeEvent() const;
156 // Note: not related to IsLoading. Set to false if there's an error, etc.
157 virtual void SetActiveLoadingState(bool aIsActiveLoading
) = 0;
159 bool AddAudioContext(mozilla::dom::AudioContext
* aAudioContext
);
160 void RemoveAudioContext(mozilla::dom::AudioContext
* aAudioContext
);
161 void MuteAudioContexts();
162 void UnmuteAudioContexts();
164 void SetAudioCapture(bool aCapture
);
167 * Associate this inner window with a MediaKeys instance.
169 void AddMediaKeysInstance(mozilla::dom::MediaKeys
* aMediaKeysInstance
);
172 * Remove an association between this inner window and a MediaKeys instance.
174 void RemoveMediaKeysInstance(mozilla::dom::MediaKeys
* aMediaKeysInstance
);
177 * Return if any MediaKeys instances are associated with this window.
179 bool HasActiveMediaKeysInstance();
181 mozilla::dom::Performance
* GetPerformance();
183 void QueuePerformanceNavigationTiming();
185 bool HasMutationListeners(uint32_t aMutationEventType
) const {
187 NS_ERROR("HasMutationListeners() called on orphan inner window!");
192 return (mMutationBits
& aMutationEventType
) != 0;
195 void SetMutationListeners(uint32_t aType
) {
197 NS_ERROR("HasMutationListeners() called on orphan inner window!");
202 mMutationBits
|= aType
;
206 * Call this to check whether some node (this window, its document,
207 * or content in that document) has a mouseenter/leave event listener.
209 bool HasMouseEnterLeaveEventListeners() const {
210 return mMayHaveMouseEnterLeaveEventListener
;
214 * Call this to indicate that some node (this window, its document,
215 * or content in that document) has a mouseenter/leave event listener.
217 void SetHasMouseEnterLeaveEventListeners() {
218 mMayHaveMouseEnterLeaveEventListener
= true;
222 * Call this to check whether some node (this window, its document,
223 * or content in that document) has a Pointerenter/leave event listener.
225 bool HasPointerEnterLeaveEventListeners() const {
226 return mMayHavePointerEnterLeaveEventListener
;
230 * Call this to indicate that some node (this window, its document,
231 * or content in that document) has a Pointerenter/leave event listener.
233 void SetHasPointerEnterLeaveEventListeners() {
234 mMayHavePointerEnterLeaveEventListener
= true;
238 * Call this to check whether some node (this window, its document,
239 * or content in that document) has a transition* event listeners.
241 bool HasTransitionEventListeners() { return mMayHaveTransitionEventListener
; }
244 * Call this to indicate that some node (this window, its document,
245 * or content in that document) has a transition* event listener.
247 void SetHasTransitionEventListeners() {
248 mMayHaveTransitionEventListener
= true;
252 * Call this to check whether some node (this window, its document,
253 * or content in that document) has a beforeinput event listener.
254 * Returing false may be wrong if some nodes have come from another document
255 * with `Document.adoptNode`.
257 bool HasBeforeInputEventListenersForTelemetry() const {
258 return mMayHaveBeforeInputEventListenerForTelemetry
;
262 * Call this to indicate that some node (this window, its document,
263 * or content in that document) has a beforeinput event listener.
265 void SetHasBeforeInputEventListenersForTelemetry() {
266 mMayHaveBeforeInputEventListenerForTelemetry
= true;
270 * Call this to check whether some node (The document, or content in the
271 * document) has been observed by web apps with a mutation observer.
272 * (i.e., `MutationObserver.observe()` called by chrome script and addon's
273 * script does not make this returns true).
274 * Returing false may be wrong if some nodes have come from another document
275 * with `Document.adoptNode`.
277 bool MutationObserverHasObservedNodeForTelemetry() const {
278 return mMutationObserverHasObservedNodeForTelemetry
;
282 * Call this to indicate that some node (The document, or content in the
283 * document) is observed by web apps with a mutation observer.
285 void SetMutationObserverHasObservedNodeForTelemetry() {
286 mMutationObserverHasObservedNodeForTelemetry
= true;
289 // Sets the event for window.event. Does NOT take ownership, so
290 // the caller is responsible for clearing the event before the
291 // event gets deallocated. Pass nullptr to set window.event to
292 // undefined. Returns the previous value.
293 mozilla::dom::Event
* SetEvent(mozilla::dom::Event
* aEvent
) {
294 mozilla::dom::Event
* old
= mEvent
;
300 * Check whether this window is a secure context.
302 bool IsSecureContext() const;
303 bool IsSecureContextIfOpenerIgnored() const;
305 // Calling suspend should prevent any asynchronous tasks from
306 // executing javascript for this window. This means setTimeout,
307 // requestAnimationFrame, and events should not be fired. Suspending
308 // a window maybe also suspends its children. Workers may
309 // continue to perform computations in the background. A window
310 // can have Suspend() called multiple times and will only resume after
311 // a matching number of Resume() calls.
312 void Suspend(bool aIncludeSubWindows
= true);
313 void Resume(bool aIncludeSubWindows
= true);
315 // Whether or not this window was suspended by the BrowserContextGroup
316 bool GetWasSuspendedByGroup() const { return mWasSuspendedByGroup
; }
317 void SetWasSuspendedByGroup(bool aSuspended
) {
318 mWasSuspendedByGroup
= aSuspended
;
321 // Apply the parent window's suspend, freeze, and modal state to the current
323 void SyncStateFromParentWindow();
326 * Increment active peer connection count.
328 void AddPeerConnection();
331 * Decrement active peer connection count.
333 void RemovePeerConnection();
336 * Check whether the active peer connection count is non-zero.
338 bool HasActivePeerConnections();
340 bool IsPlayingAudio();
342 bool IsDocumentLoaded() const;
344 mozilla::dom::TimeoutManager
& TimeoutManager();
346 bool IsRunningTimeout();
348 // To cache top inner-window if available after constructed for tab-wised
349 // indexedDB counters.
350 void TryToCacheTopInnerWindow();
352 // Increase/Decrease the number of active IndexedDB databases for the
353 // decision making of timeout-throttling.
354 void UpdateActiveIndexedDBDatabaseCount(int32_t aDelta
);
356 // Return true if there is any active IndexedDB databases which could block
357 // timeout-throttling.
358 bool HasActiveIndexedDBDatabases();
360 // Increase/Decrease the number of open WebSockets.
361 void UpdateWebSocketCount(int32_t aDelta
);
363 // Return true if there are any open WebSockets that could block
364 // timeout-throttling.
365 bool HasOpenWebSockets() const;
367 mozilla::Maybe
<mozilla::dom::ClientInfo
> GetClientInfo() const;
368 mozilla::Maybe
<mozilla::dom::ClientState
> GetClientState() const;
369 mozilla::Maybe
<mozilla::dom::ServiceWorkerDescriptor
> GetController() const;
371 void SetCsp(nsIContentSecurityPolicy
* aCsp
);
372 void SetPreloadCsp(nsIContentSecurityPolicy
* aPreloadCsp
);
373 nsIContentSecurityPolicy
* GetCsp();
375 void NoteCalledRegisterForServiceWorkerScope(const nsACString
& aScope
);
377 void NoteDOMContentLoaded();
379 virtual mozilla::dom::CustomElementRegistry
* CustomElements() = 0;
381 // XXX: This is called on inner windows
382 virtual nsPIDOMWindowOuter
* GetInProcessScriptableTop() = 0;
383 virtual nsPIDOMWindowOuter
* GetInProcessScriptableParent() = 0;
384 virtual already_AddRefed
<nsPIWindowRoot
> GetTopWindowRoot() = 0;
386 mozilla::dom::EventTarget
* GetChromeEventHandler() const {
387 return mChromeEventHandler
;
390 mozilla::dom::EventTarget
* GetParentTarget() {
391 if (!mParentTarget
) {
392 UpdateParentTarget();
394 return mParentTarget
;
397 virtual void MaybeUpdateTouchState() {}
399 Document
* GetExtantDoc() const { return mDoc
; }
400 nsIURI
* GetDocumentURI() const;
401 nsIURI
* GetDocBaseURI() const;
410 mozilla::dom::WindowContext
* GetWindowContext() const;
411 mozilla::dom::WindowGlobalChild
* GetWindowGlobalChild() const {
412 return mWindowGlobalChild
;
415 // Removes this inner window from the BFCache, if it is cached, and returns
417 bool RemoveFromBFCacheSync();
419 // Determine if the window is suspended or frozen. Outer windows
420 // will forward this call to the inner window for convenience. If
421 // there is no inner window then the outer window is considered
422 // suspended and frozen by default.
423 virtual bool IsSuspended() const = 0;
424 virtual bool IsFrozen() const = 0;
426 // Fire any DOM notification events related to things that happened while
427 // the window was frozen.
428 virtual nsresult
FireDelayedDOMEvents(bool aIncludeSubWindows
) = 0;
431 * Get the docshell in this window.
433 inline nsIDocShell
* GetDocShell() const;
436 * Get the browsing context in this window.
438 inline mozilla::dom::BrowsingContext
* GetBrowsingContext() const;
441 * Get the browsing context group this window belongs to.
443 mozilla::dom::BrowsingContextGroup
* GetBrowsingContextGroup() const;
446 * Call this to indicate that some node (this window, its document,
447 * or content in that document) has a DOMActivate event listener.
449 void SetHasDOMActivateEventListeners() {
450 mMayHaveDOMActivateEventListeners
= true;
454 * Call this to check whether some node (this window, its document,
455 * or content in that document) has a DOMActivate event listener.
457 bool HasDOMActivateEventListeners() const {
458 return mMayHaveDOMActivateEventListeners
;
462 * Call this to indicate that some node (this window, its document,
463 * or content in that document) has a paint event listener.
465 void SetHasPaintEventListeners() { mMayHavePaintEventListener
= true; }
468 * Call this to check whether some node (this window, its document,
469 * or content in that document) has a paint event listener.
471 bool HasPaintEventListeners() { return mMayHavePaintEventListener
; }
474 * Call this to indicate that some node (this window, its document,
475 * or content in that document) has a touch event listener.
477 void SetHasTouchEventListeners() {
478 if (!mMayHaveTouchEventListener
) {
479 mMayHaveTouchEventListener
= true;
480 MaybeUpdateTouchState();
485 * Call this to indicate that some node (this window, its document,
486 * or content in that document) has a selectionchange event listener.
488 void SetHasSelectionChangeEventListeners() {
489 mMayHaveSelectionChangeEventListener
= true;
493 * Call this to check whether some node (this window, its document,
494 * or content in that document) has a selectionchange event listener.
496 bool HasSelectionChangeEventListeners() const {
497 return mMayHaveSelectionChangeEventListener
;
501 * Call this to indicate that some node (this window, its document,
502 * or content in that document) has a select event listener of form controls.
504 void SetHasFormSelectEventListeners() {
505 mMayHaveFormSelectEventListener
= true;
509 * Call this to check whether some node (this window, its document,
510 * or content in that document) has a select event listener of form controls.
512 bool HasFormSelectEventListeners() const {
513 return mMayHaveFormSelectEventListener
;
517 * Get and set the currently focused element within the document. If
518 * aNeedsFocus is true, then set mNeedsFocus to true to indicate that a
519 * document focus event is needed.
521 * DO NOT CALL EITHER OF THESE METHODS DIRECTLY. USE THE FOCUS MANAGER
524 mozilla::dom::Element
* GetFocusedElement() const {
525 return mFocusedElement
.get();
528 virtual void SetFocusedElement(mozilla::dom::Element
* aElement
,
529 uint32_t aFocusMethod
= 0,
530 bool aNeedsFocus
= false) = 0;
532 bool UnknownFocusMethodShouldShowOutline() const {
533 return mUnknownFocusMethodShouldShowOutline
;
537 * Retrieves the method that was used to focus the current node.
539 virtual uint32_t GetFocusMethod() = 0;
542 * Tells the window that it now has focus or has lost focus, based on the
543 * state of aFocus. If this method returns true, then the document loaded
544 * in the window has never received a focus event and expects to receive
545 * one. If false is returned, the document has received a focus event before
546 * and should only receive one if the window is being focused.
548 * aFocusMethod may be set to one of the focus method constants in
549 * nsIFocusManager to indicate how focus was set.
551 virtual bool TakeFocus(bool aFocus
, uint32_t aFocusMethod
) = 0;
554 * Indicates that the window may now accept a document focus event. This
555 * should be called once a document has been loaded into the window.
557 virtual void SetReadyForFocus() = 0;
560 * Whether the focused content within the window should show a focus ring.
562 virtual bool ShouldShowFocusRing() = 0;
565 * Indicates that the page in the window has been hidden. This is used to
566 * reset the focus state.
568 virtual void PageHidden() = 0;
571 * Instructs this window to asynchronously dispatch a hashchange event. This
572 * method must be called on an inner window.
574 virtual nsresult
DispatchAsyncHashchange(nsIURI
* aOldURI
,
575 nsIURI
* aNewURI
) = 0;
578 * Instructs this window to synchronously dispatch a popState event.
580 virtual nsresult
DispatchSyncPopState() = 0;
583 * Tell this window that it should listen for sensor changes of the given
586 virtual void EnableDeviceSensor(uint32_t aType
) = 0;
589 * Tell this window that it should remove itself from sensor change
592 virtual void DisableDeviceSensor(uint32_t aType
) = 0;
594 #if defined(MOZ_WIDGET_ANDROID)
595 virtual void EnableOrientationChangeListener() = 0;
596 virtual void DisableOrientationChangeListener() = 0;
600 * Tell this window that there is an observer for gamepad input
602 * Inner windows only.
604 virtual void SetHasGamepadEventListener(bool aHasGamepad
= true) = 0;
607 * Return the window id of this window
609 uint64_t WindowID() const { return mWindowID
; }
612 void MarkUncollectableForCCGeneration(uint32_t aGeneration
) {
613 mMarkedCCGeneration
= aGeneration
;
616 uint32_t GetMarkedCCGeneration() { return mMarkedCCGeneration
; }
618 mozilla::dom::Navigator
* Navigator();
619 mozilla::dom::MediaDevices
* GetExtantMediaDevices() const;
620 virtual mozilla::dom::Location
* Location() = 0;
622 virtual nsresult
GetControllers(nsIControllers
** aControllers
) = 0;
624 virtual nsresult
GetInnerWidth(double* aWidth
) = 0;
625 virtual nsresult
GetInnerHeight(double* aHeight
) = 0;
627 virtual already_AddRefed
<nsICSSDeclaration
> GetComputedStyle(
628 mozilla::dom::Element
& aElt
, const nsAString
& aPseudoElt
,
629 mozilla::ErrorResult
& aError
) = 0;
631 virtual bool GetFullScreen() = 0;
633 virtual nsresult
Focus(mozilla::dom::CallerType aCallerType
) = 0;
634 virtual nsresult
Close() = 0;
636 mozilla::dom::DocGroup
* GetDocGroup() const;
638 void SaveStorageAccessPermissionGranted();
639 void SaveStorageAccessPermissionRevoked();
641 bool UsingStorageAccess();
643 uint32_t UpdateLockCount(bool aIncrement
) {
644 MOZ_ASSERT_IF(!aIncrement
, mLockCount
> 0);
645 mLockCount
+= aIncrement
? 1 : -1;
648 bool HasActiveLocks() { return mLockCount
> 0; }
650 uint32_t UpdateWebTransportCount(bool aIncrement
) {
651 MOZ_ASSERT_IF(!aIncrement
, mWebTransportCount
> 0);
652 mWebTransportCount
+= aIncrement
? 1 : -1;
653 return mWebTransportCount
;
655 bool HasActiveWebTransports() { return mWebTransportCount
> 0; }
658 void CreatePerformanceObjectIfNeeded();
660 // Lazily instantiate an about:blank document if necessary, and if
661 // we have what it takes to do so.
662 void MaybeCreateDoc();
664 void SetChromeEventHandlerInternal(
665 mozilla::dom::EventTarget
* aChromeEventHandler
) {
666 mChromeEventHandler
= aChromeEventHandler
;
667 // mParentTarget will be set when the next event is dispatched.
668 mParentTarget
= nullptr;
671 virtual void UpdateParentTarget() = 0;
673 // These two variables are special in that they're set to the same
674 // value on both the outer window and the current inner window. Make
675 // sure you keep them in sync!
676 nsCOMPtr
<mozilla::dom::EventTarget
> mChromeEventHandler
; // strong
677 RefPtr
<Document
> mDoc
;
678 // Cache the URI when mDoc is cleared.
679 nsCOMPtr
<nsIURI
> mDocumentURI
; // strong
680 nsCOMPtr
<nsIURI
> mDocBaseURI
; // strong
682 nsCOMPtr
<mozilla::dom::EventTarget
> mParentTarget
; // strong
684 RefPtr
<mozilla::dom::Performance
> mPerformance
;
685 mozilla::UniquePtr
<mozilla::dom::TimeoutManager
> mTimeoutManager
;
687 RefPtr
<mozilla::dom::Navigator
> mNavigator
;
689 // These variables are only used on inner windows.
690 uint32_t mMutationBits
;
692 uint32_t mActivePeerConnections
= 0;
694 bool mIsDocumentLoaded
;
695 bool mIsHandlingResizeEvent
;
696 bool mMayHaveDOMActivateEventListeners
;
697 bool mMayHavePaintEventListener
;
698 bool mMayHaveTouchEventListener
;
699 bool mMayHaveSelectionChangeEventListener
;
700 bool mMayHaveFormSelectEventListener
;
701 bool mMayHaveMouseEnterLeaveEventListener
;
702 bool mMayHavePointerEnterLeaveEventListener
;
703 bool mMayHaveTransitionEventListener
;
704 // Only used for telemetry probes. This may be wrong if some nodes have
705 // come from another document with `Document.adoptNode`.
706 bool mMayHaveBeforeInputEventListenerForTelemetry
;
707 bool mMutationObserverHasObservedNodeForTelemetry
;
709 // Our inner window's outer window.
710 nsCOMPtr
<nsPIDOMWindowOuter
> mOuterWindow
;
712 // The element within the document that is currently focused when this
714 RefPtr
<mozilla::dom::Element
> mFocusedElement
;
716 // The AudioContexts created for the current document, if any.
717 nsTArray
<mozilla::dom::AudioContext
*> mAudioContexts
; // Weak
719 // Instances of MediaKeys created in this inner window. Storing these allows
720 // us to shutdown MediaKeys when an inner windows is destroyed. We can also
721 // use the presence of MediaKeys to assess if a window has EME activity.
722 nsTArray
<mozilla::dom::MediaKeys
*> mMediaKeysInstances
; // Weak
724 RefPtr
<mozilla::dom::BrowsingContext
> mBrowsingContext
;
726 // A unique (as long as our 64-bit counter doesn't roll over) id for
730 // Set to true once we've sent the (chrome|content)-document-global-created
732 bool mHasNotifiedGlobalCreated
;
734 // Whether when focused via an "unknown" focus method, we should show outlines
735 // by default or not. The initial value of this is true (so as to show
736 // outlines for stuff like html autofocus, or initial programmatic focus
737 // without any other user interaction).
738 bool mUnknownFocusMethodShouldShowOutline
= true;
740 uint32_t mMarkedCCGeneration
;
742 // mTopInnerWindow is used for tab-wise check by timeout throttling. It could
744 nsCOMPtr
<nsPIDOMWindowInner
> mTopInnerWindow
;
746 // The evidence that we have tried to cache mTopInnerWindow only once from
747 // SetNewDocument(). Note: We need this extra flag because mTopInnerWindow
748 // could be null and we don't want it to be set multiple times.
749 bool mHasTriedToCacheTopInnerWindow
;
751 // The number of active IndexedDB databases.
752 uint32_t mNumOfIndexedDBDatabases
;
754 // The number of open WebSockets.
755 uint32_t mNumOfOpenWebSockets
;
757 // The event dispatch code sets and unsets this while keeping
758 // the event object alive.
759 mozilla::dom::Event
* mEvent
;
761 // The WindowGlobalChild actor for this window.
763 // This will be non-null during the full lifetime of the window, initialized
764 // during SetNewDocument, and cleared during FreeInnerObjects.
765 RefPtr
<mozilla::dom::WindowGlobalChild
> mWindowGlobalChild
;
767 bool mWasSuspendedByGroup
;
770 * Count of the number of active LockRequest objects, including ones from
773 uint32_t mLockCount
= 0;
775 * Count of the number of active WebTransport objects, including ones from
778 uint32_t mWebTransportCount
= 0;
781 NS_DEFINE_STATIC_IID_ACCESSOR(nsPIDOMWindowInner
, NS_PIDOMWINDOWINNER_IID
)
783 class nsPIDOMWindowOuter
: public mozIDOMWindowProxy
{
785 using Document
= mozilla::dom::Document
;
787 explicit nsPIDOMWindowOuter(uint64_t aWindowID
);
789 ~nsPIDOMWindowOuter();
791 void NotifyResumingDelayedMedia();
794 NS_DECLARE_STATIC_IID_ACCESSOR(NS_PIDOMWINDOWOUTER_IID
)
796 NS_IMPL_FROMEVENTTARGET_HELPER_WITH_GETTER(nsPIDOMWindowOuter
,
799 static nsPIDOMWindowOuter
* From(mozIDOMWindowProxy
* aFrom
) {
800 return static_cast<nsPIDOMWindowOuter
*>(aFrom
);
803 // Given an inner window, return its outer if the inner is the current inner.
804 // Otherwise (argument null or not an inner or not current) return null.
805 static nsPIDOMWindowOuter
* GetFromCurrentInner(nsPIDOMWindowInner
* aInner
);
807 // Check whether a document is currently loading
808 inline bool IsLoading() const;
809 inline bool IsHandlingResizeEvent() const;
811 nsPIDOMWindowInner
* GetCurrentInnerWindow() const { return mInnerWindow
; }
813 nsPIDOMWindowInner
* EnsureInnerWindow() {
814 // GetDoc forces inner window creation if there isn't one already
816 return GetCurrentInnerWindow();
819 bool IsRootOuterWindow() { return mIsRootOuterWindow
; }
821 // Internal getter/setter for the frame element, this version of the
822 // getter crosses chrome boundaries whereas the public scriptable
823 // one doesn't for security reasons.
824 mozilla::dom::Element
* GetFrameElementInternal() const;
825 void SetFrameElementInternal(mozilla::dom::Element
* aFrameElement
);
827 bool IsBackground() { return mIsBackground
; }
830 bool GetAudioMuted() const;
832 // No longer to delay media from starting for this window.
833 void ActivateMediaComponents();
834 bool ShouldDelayMediaFromStart() const;
836 void RefreshMediaElementsVolume();
838 virtual nsPIDOMWindowOuter
* GetPrivateRoot() = 0;
841 * |top| gets the root of the window hierarchy.
843 * This function does not cross chrome-content boundaries, so if this
844 * window's parent is of a different type, |top| will return this window.
846 * When script reads the top property, we run GetInProcessScriptableTop,
847 * which will not cross an <iframe mozbrowser> boundary.
849 * In contrast, C++ calls to GetTop are forwarded to GetRealTop, which
850 * ignores <iframe mozbrowser> boundaries.
853 virtual already_AddRefed
<nsPIDOMWindowOuter
>
854 GetInProcessTop() = 0; // Outer only
855 virtual already_AddRefed
<nsPIDOMWindowOuter
> GetInProcessParent() = 0;
856 virtual nsPIDOMWindowOuter
* GetInProcessScriptableTop() = 0;
857 virtual nsPIDOMWindowOuter
* GetInProcessScriptableParent() = 0;
858 virtual already_AddRefed
<nsPIWindowRoot
> GetTopWindowRoot() = 0;
861 * Behaves identically to GetInProcessScriptableParent except that it
862 * returns null if GetInProcessScriptableParent would return this window.
864 virtual nsPIDOMWindowOuter
* GetInProcessScriptableParentOrNull() = 0;
866 virtual void SetIsBackground(bool aIsBackground
) = 0;
868 mozilla::dom::EventTarget
* GetChromeEventHandler() const {
869 return mChromeEventHandler
;
872 virtual void SetChromeEventHandler(
873 mozilla::dom::EventTarget
* aChromeEventHandler
) = 0;
875 mozilla::dom::EventTarget
* GetParentTarget() {
876 if (!mParentTarget
) {
877 UpdateParentTarget();
879 return mParentTarget
;
882 mozilla::dom::ContentFrameMessageManager
* GetMessageManager() {
883 // We maintain our mMessageManager state alongside mParentTarget.
884 if (!mParentTarget
) {
885 UpdateParentTarget();
887 return mMessageManager
;
890 Document
* GetExtantDoc() const { return mDoc
; }
891 nsIURI
* GetDocumentURI() const;
900 // Set the window up with an about:blank document with the given principal and
901 // potentially a CSP and a COEP.
902 virtual void SetInitialPrincipal(
903 nsIPrincipal
* aNewWindowPrincipal
, nsIContentSecurityPolicy
* aCSP
,
904 const mozilla::Maybe
<nsILoadInfo::CrossOriginEmbedderPolicy
>& aCoep
) = 0;
906 // Returns an object containing the window's state. This also suspends
907 // all running timeouts in the window.
908 virtual already_AddRefed
<nsISupports
> SaveWindowState() = 0;
910 // Restore the window state from aState.
911 virtual nsresult
RestoreWindowState(nsISupports
* aState
) = 0;
913 // Determine if the window is suspended or frozen. Outer windows
914 // will forward this call to the inner window for convenience. If
915 // there is no inner window then the outer window is considered
916 // suspended and frozen by default.
917 virtual bool IsSuspended() const = 0;
918 virtual bool IsFrozen() const = 0;
920 // Fire any DOM notification events related to things that happened while
921 // the window was frozen.
922 virtual nsresult
FireDelayedDOMEvents(bool aIncludeSubWindows
) = 0;
925 * Get the docshell in this window.
927 inline nsIDocShell
* GetDocShell() const;
930 * Get the browsing context in this window.
932 inline mozilla::dom::BrowsingContext
* GetBrowsingContext() const;
935 * Get the browsing context group this window belongs to.
937 mozilla::dom::BrowsingContextGroup
* GetBrowsingContextGroup() const;
940 * Set a new document in the window. Calling this method will in most cases
941 * create a new inner window. This may be called with a pointer to the current
942 * document, in that case the document remains unchanged, but a new inner
943 * window will be created.
945 * aDocument must not be null.
947 virtual nsresult
SetNewDocument(
948 Document
* aDocument
, nsISupports
* aState
, bool aForceReuseInnerWindow
,
949 mozilla::dom::WindowGlobalChild
* aActor
= nullptr) = 0;
952 * Ensure the size and position of this window are up-to-date by doing
953 * a layout flush in the parent (which will in turn, do a layout flush
954 * in its parent, etc.).
956 virtual void EnsureSizeAndPositionUpToDate() = 0;
959 * Suppresses/unsuppresses user initiated event handling in window's document
960 * and all in-process descendant documents.
962 virtual void SuppressEventHandling() = 0;
963 virtual void UnsuppressEventHandling() = 0;
966 * Callback for notifying a window about a modal dialog being
967 * opened/closed with the window as a parent.
969 * If any script can run between the enter and leave modal states, and the
970 * window isn't top, the LeaveModalState() should be called on the window
971 * returned by EnterModalState().
973 virtual nsPIDOMWindowOuter
* EnterModalState() = 0;
974 virtual void LeaveModalState() = 0;
976 virtual bool CanClose() = 0;
977 virtual void ForceClose() = 0;
980 * Moves the top-level window into fullscreen mode if aIsFullScreen is true,
981 * otherwise exits fullscreen.
983 virtual nsresult
SetFullscreenInternal(FullscreenReason aReason
,
984 bool aIsFullscreen
) = 0;
985 virtual void FullscreenWillChange(bool aIsFullscreen
) = 0;
987 * This function should be called when the fullscreen state is flipped.
988 * If no widget is involved the fullscreen change, this method is called
989 * by SetFullscreenInternal, otherwise, it is called when the widget
990 * finishes its change to or from fullscreen.
992 * @param aIsFullscreen indicates whether the widget is in fullscreen.
994 virtual void FinishFullscreenChange(bool aIsFullscreen
) = 0;
996 virtual void ForceFullScreenInWidget() = 0;
998 virtual void MacFullscreenMenubarOverlapChanged(
999 mozilla::DesktopCoord aOverlapAmount
) = 0;
1001 // XXX: These focus methods all forward to the inner, could we change
1002 // consumers to call these on the inner directly?
1005 * Get and set the currently focused element within the document. If
1006 * aNeedsFocus is true, then set mNeedsFocus to true to indicate that a
1007 * document focus event is needed.
1009 * DO NOT CALL EITHER OF THESE METHODS DIRECTLY. USE THE FOCUS MANAGER
1012 inline mozilla::dom::Element
* GetFocusedElement() const;
1014 virtual void SetFocusedElement(mozilla::dom::Element
* aElement
,
1015 uint32_t aFocusMethod
= 0,
1016 bool aNeedsFocus
= false) = 0;
1018 * Get whether a focused element focused by unknown reasons (like script
1019 * focus) should match the :focus-visible pseudo-class.
1021 bool UnknownFocusMethodShouldShowOutline() const;
1024 * Retrieves the method that was used to focus the current node.
1026 virtual uint32_t GetFocusMethod() = 0;
1029 * Tells the window that it now has focus or has lost focus, based on the
1030 * state of aFocus. If this method returns true, then the document loaded
1031 * in the window has never received a focus event and expects to receive
1032 * one. If false is returned, the document has received a focus event before
1033 * and should only receive one if the window is being focused.
1035 * aFocusMethod may be set to one of the focus method constants in
1036 * nsIFocusManager to indicate how focus was set.
1038 virtual bool TakeFocus(bool aFocus
, uint32_t aFocusMethod
) = 0;
1041 * Indicates that the window may now accept a document focus event. This
1042 * should be called once a document has been loaded into the window.
1044 virtual void SetReadyForFocus() = 0;
1047 * Whether the focused content within the window should show a focus ring.
1049 virtual bool ShouldShowFocusRing() = 0;
1052 * Indicates that the page in the window has been hidden. This is used to
1053 * reset the focus state.
1055 virtual void PageHidden() = 0;
1058 * Return the window id of this window
1060 uint64_t WindowID() const { return mWindowID
; }
1063 * Dispatch a custom event with name aEventName targeted at this window.
1064 * Returns whether the default action should be performed.
1066 * Outer windows only.
1068 virtual bool DispatchCustomEvent(
1069 const nsAString
& aEventName
,
1070 mozilla::ChromeOnlyDispatch aChromeOnlyDispatch
=
1071 mozilla::ChromeOnlyDispatch::eNo
) = 0;
1074 * Like nsIDOMWindow::Open, except that we don't navigate to the given URL.
1076 * Outer windows only.
1078 virtual nsresult
OpenNoNavigate(const nsAString
& aUrl
, const nsAString
& aName
,
1079 const nsAString
& aOptions
,
1080 mozilla::dom::BrowsingContext
** _retval
) = 0;
1083 * Fire a popup blocked event on the document.
1085 virtual void FirePopupBlockedEvent(Document
* aDoc
, nsIURI
* aPopupURI
,
1086 const nsAString
& aPopupWindowName
,
1087 const nsAString
& aPopupWindowFeatures
) = 0;
1090 void MarkUncollectableForCCGeneration(uint32_t aGeneration
) {
1091 mMarkedCCGeneration
= aGeneration
;
1094 uint32_t GetMarkedCCGeneration() { return mMarkedCCGeneration
; }
1096 // XXX(nika): These feel like they should be inner window only, but they're
1097 // called on the outer window.
1098 virtual mozilla::dom::Navigator
* GetNavigator() = 0;
1099 virtual mozilla::dom::Location
* GetLocation() = 0;
1101 virtual nsresult
GetPrompter(nsIPrompt
** aPrompt
) = 0;
1102 virtual nsresult
GetControllers(nsIControllers
** aControllers
) = 0;
1103 virtual already_AddRefed
<mozilla::dom::Selection
> GetSelection() = 0;
1104 virtual mozilla::dom::Nullable
<mozilla::dom::WindowProxyHolder
>
1107 // aLoadState will be passed on through to the windowwatcher.
1108 // aForceNoOpener will act just like a "noopener" feature in aOptions except
1109 // will not affect any other window features.
1110 virtual nsresult
Open(const nsAString
& aUrl
, const nsAString
& aName
,
1111 const nsAString
& aOptions
,
1112 nsDocShellLoadState
* aLoadState
, bool aForceNoOpener
,
1113 mozilla::dom::BrowsingContext
** _retval
) = 0;
1114 virtual nsresult
OpenDialog(const nsAString
& aUrl
, const nsAString
& aName
,
1115 const nsAString
& aOptions
,
1116 nsISupports
* aExtraArgument
,
1117 mozilla::dom::BrowsingContext
** _retval
) = 0;
1119 virtual nsresult
GetInnerWidth(double* aWidth
) = 0;
1120 virtual nsresult
GetInnerHeight(double* aHeight
) = 0;
1122 virtual mozilla::dom::Element
* GetFrameElement() = 0;
1124 virtual bool Closed() = 0;
1125 virtual bool GetFullScreen() = 0;
1126 virtual nsresult
SetFullScreen(bool aFullscreen
) = 0;
1128 virtual nsresult
Focus(mozilla::dom::CallerType aCallerType
) = 0;
1129 virtual nsresult
Close() = 0;
1131 virtual nsresult
MoveBy(int32_t aXDif
, int32_t aYDif
) = 0;
1133 virtual void UpdateCommands(const nsAString
& anAction
) = 0;
1135 mozilla::dom::DocGroup
* GetDocGroup() const;
1137 already_AddRefed
<nsIDocShellTreeOwner
> GetTreeOwner();
1138 already_AddRefed
<nsIBaseWindow
> GetTreeOwnerWindow();
1139 already_AddRefed
<nsIWebBrowserChrome
> GetWebBrowserChrome();
1142 // Lazily instantiate an about:blank document if necessary, and if
1143 // we have what it takes to do so.
1144 void MaybeCreateDoc();
1146 void SetChromeEventHandlerInternal(
1147 mozilla::dom::EventTarget
* aChromeEventHandler
);
1149 virtual void UpdateParentTarget() = 0;
1151 // These two variables are special in that they're set to the same
1152 // value on both the outer window and the current inner window. Make
1153 // sure you keep them in sync!
1154 nsCOMPtr
<mozilla::dom::EventTarget
> mChromeEventHandler
; // strong
1155 RefPtr
<Document
> mDoc
;
1156 // Cache the URI when mDoc is cleared.
1157 nsCOMPtr
<nsIURI
> mDocumentURI
; // strong
1159 nsCOMPtr
<mozilla::dom::EventTarget
> mParentTarget
; // strong
1160 RefPtr
<mozilla::dom::ContentFrameMessageManager
> mMessageManager
; // strong
1162 nsCOMPtr
<mozilla::dom::Element
> mFrameElement
;
1164 // These references are used by nsGlobalWindow.
1165 nsCOMPtr
<nsIDocShell
> mDocShell
;
1166 RefPtr
<mozilla::dom::BrowsingContext
> mBrowsingContext
;
1168 uint32_t mModalStateDepth
;
1170 uint32_t mSuppressEventHandlingDepth
;
1172 // Tracks whether our docshell is active. If it is, mIsBackground
1173 // is false. Too bad we have so many different concepts of
1177 bool mIsRootOuterWindow
;
1179 // And these are the references between inner and outer windows.
1180 nsPIDOMWindowInner
* MOZ_NON_OWNING_REF mInnerWindow
;
1182 // A unique (as long as our 64-bit counter doesn't roll over) id for
1186 uint32_t mMarkedCCGeneration
;
1189 NS_DEFINE_STATIC_IID_ACCESSOR(nsPIDOMWindowOuter
, NS_PIDOMWINDOWOUTER_IID
)
1191 #include "nsPIDOMWindowInlines.h"
1193 #endif // nsPIDOMWindow_h__