From 4ffa6418bbe733da6f1231f79847baf90af03d2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 1 Jul 2024 11:49:59 +0000 Subject: [PATCH] Bug 1904442 - Rename GlobalTeardownObserver::GetOwner to GetOwnerWindow. r=smaug,media-playback-reviewers,dom-storage-reviewers,aosmond,padenot,asuth Also HasOrHasHadOwner to HasOrHasHadOwnerWindow. Differential Revision: https://phabricator.services.mozilla.com/D214772 --- dom/animation/AnimationEventDispatcher.cpp | 9 ++-- dom/base/EventSource.cpp | 8 ++-- dom/base/GlobalTeardownObserver.cpp | 39 +++++++--------- dom/base/GlobalTeardownObserver.h | 9 ++-- dom/base/ScreenOrientation.cpp | 16 +++---- dom/base/VisualViewport.cpp | 5 ++- dom/base/nsContentUtils.cpp | 8 ++-- dom/base/nsDOMDataChannel.cpp | 2 +- dom/base/nsDOMDataChannel.h | 9 ++-- dom/base/nsGlobalWindowInner.cpp | 1 + dom/base/nsGlobalWindowInner.h | 2 +- dom/base/nsScreen.cpp | 13 +++--- dom/base/nsScreen.h | 2 +- dom/battery/BatteryManager.cpp | 3 +- dom/battery/BatteryManager.h | 9 ++-- dom/broadcastchannel/BroadcastChannel.cpp | 2 +- dom/events/Clipboard.cpp | 24 +++++----- dom/events/DOMEventTargetHelper.cpp | 17 ++++--- dom/events/DOMEventTargetHelper.h | 15 +++---- dom/events/EventListenerManager.cpp | 2 +- dom/html/HTMLMediaElement.cpp | 5 ++- dom/indexedDB/ActorsChild.cpp | 2 +- dom/indexedDB/IDBDatabase.cpp | 35 +++++++-------- dom/indexedDB/IDBFactory.cpp | 4 +- dom/media/CanvasCaptureMediaStream.cpp | 5 +-- dom/media/DOMMediaStream.cpp | 8 ++-- dom/media/MediaDevices.cpp | 17 +++---- dom/media/MediaRecorder.cpp | 14 +++--- dom/media/autoplay/AutoplayPolicy.cpp | 4 +- dom/media/imagecapture/ImageCapture.cpp | 18 ++------ dom/media/imagecapture/ImageCapture.h | 2 +- dom/media/mediasource/MediaSource.cpp | 18 ++++---- dom/media/mediasource/SourceBuffer.cpp | 7 +-- dom/media/webaudio/AudioContext.cpp | 41 ++++++++--------- dom/media/webaudio/AudioContext.h | 4 +- dom/media/webaudio/AudioDestinationNode.cpp | 21 ++++----- dom/media/webaudio/AudioProcessingEvent.cpp | 5 ++- dom/media/webaudio/AudioWorkletImpl.cpp | 5 +-- dom/media/webaudio/BiquadFilterNode.cpp | 5 ++- dom/media/webaudio/IIRFilterNode.cpp | 6 +-- dom/media/webaudio/MediaBufferDecoder.cpp | 12 ++--- .../MediaStreamAudioDestinationNode.cpp | 10 +++-- .../webaudio/MediaStreamAudioSourceNode.cpp | 5 ++- .../MediaStreamTrackAudioSourceNode.cpp | 7 +-- dom/media/webaudio/ScriptProcessorNode.cpp | 6 +-- .../OnlineSpeechRecognitionService.cpp | 12 +---- .../recognition/SpeechRecognition.cpp | 11 ++--- dom/media/webspeech/synth/SpeechSynthesis.cpp | 9 ++-- .../synth/SpeechSynthesisUtterance.cpp | 2 +- dom/media/webspeech/synth/nsSpeechTask.cpp | 3 +- .../webspeech/synth/nsSynthVoiceRegistry.cpp | 2 +- dom/media/webvtt/TextTrack.cpp | 13 +++--- dom/media/webvtt/TextTrackCue.cpp | 3 +- dom/media/webvtt/TextTrackList.cpp | 4 +- dom/messagechannel/MessagePort.cpp | 6 +-- dom/midi/MIDIAccess.cpp | 7 +-- dom/midi/MIDIInput.cpp | 5 ++- dom/midi/MIDIOutput.cpp | 10 +++-- dom/midi/MIDIPort.cpp | 19 +++----- dom/midi/MIDIPort.h | 2 +- dom/network/TCPServerSocket.cpp | 4 +- dom/network/TCPServerSocket.h | 6 +-- dom/network/UDPSocket.cpp | 29 ++++++------ dom/network/UDPSocket.h | 2 +- dom/notification/Notification.cpp | 22 ++++------ dom/notification/Notification.h | 5 +-- dom/payments/PaymentRequest.cpp | 13 +++--- dom/payments/PaymentRequestManager.cpp | 2 +- dom/payments/PaymentResponse.cpp | 16 +++---- dom/performance/Performance.cpp | 14 +++--- dom/performance/PerformanceMainThread.cpp | 7 ++- dom/permission/PermissionStatus.cpp | 5 ++- .../StorageAccessPermissionStatus.cpp | 5 ++- dom/serviceworkers/ServiceWorker.cpp | 2 +- dom/serviceworkers/ServiceWorkerContainer.cpp | 11 ++--- dom/vr/VRDisplay.cpp | 4 +- dom/vr/VRServiceTest.cpp | 4 +- dom/vr/XRSession.cpp | 5 +-- dom/vr/XRSystem.cpp | 9 ++-- dom/websocket/WebSocket.cpp | 22 +++++----- .../sharedworkers/SharedWorkerChild.cpp | 7 +-- dom/xhr/XMLHttpRequestEventTarget.h | 5 +-- dom/xhr/XMLHttpRequestMainThread.cpp | 44 ++++++++++--------- netwerk/cookie/CookieParser.cpp | 2 +- 84 files changed, 381 insertions(+), 433 deletions(-) diff --git a/dom/animation/AnimationEventDispatcher.cpp b/dom/animation/AnimationEventDispatcher.cpp index 0ec5686d8f96..1e61989c8e25 100644 --- a/dom/animation/AnimationEventDispatcher.cpp +++ b/dom/animation/AnimationEventDispatcher.cpp @@ -11,6 +11,7 @@ #include "nsRefreshDriver.h" #include "nsCSSProps.h" #include "mozilla/dom/AnimationEffect.h" +#include "nsGlobalWindowInner.h" using namespace mozilla; @@ -185,8 +186,8 @@ void AnimationEventInfo::MaybeAddMarker() const { DOM, MarkerOptions( MarkerTiming::Interval(startTime, mScheduledEventTimeStamp), - mAnimation->GetOwner() - ? MarkerInnerWindowId(mAnimation->GetOwner()->WindowID()) + mAnimation->GetOwnerWindow() + ? MarkerInnerWindowId(mAnimation->GetOwnerWindow()->WindowID()) : MarkerInnerWindowId::NoId()), CSSAnimationMarker, name, NS_ConvertUTF16toUTF8(target), properties, oncompositor); @@ -226,8 +227,8 @@ void AnimationEventInfo::MaybeAddMarker() const { mScheduledEventTimeStamp - TimeDuration::FromSeconds(data.mElapsedTime), mScheduledEventTimeStamp), - mAnimation->GetOwner() - ? MarkerInnerWindowId(mAnimation->GetOwner()->WindowID()) + mAnimation->GetOwnerWindow() + ? MarkerInnerWindowId(mAnimation->GetOwnerWindow()->WindowID()) : MarkerInnerWindowId::NoId()), CSSTransitionMarker, NS_ConvertUTF16toUTF8(target), property, onCompositor, message == eTransitionCancel); diff --git a/dom/base/EventSource.cpp b/dom/base/EventSource.cpp index 69bce082dfd0..84d50afb11ae 100644 --- a/dom/base/EventSource.cpp +++ b/dom/base/EventSource.cpp @@ -678,8 +678,8 @@ EventSourceImpl::Observe(nsISupports* aSubject, const char* aTopic, MOZ_ASSERT(mIsMainThread); { auto lock = mSharedData.Lock(); - if (!lock->mEventSource->GetOwner() || - window != lock->mEventSource->GetOwner()) { + if (!lock->mEventSource->GetOwnerWindow() || + window != lock->mEventSource->GetOwnerWindow()) { return NS_OK; } } @@ -961,8 +961,8 @@ EventSourceImpl::GetInterface(const nsIID& aIID, void** aResult) { rv = lock->mEventSource->CheckCurrentGlobalCorrectness(); NS_ENSURE_SUCCESS(rv, NS_ERROR_UNEXPECTED); - if (lock->mEventSource->GetOwner()) { - window = lock->mEventSource->GetOwner()->GetOuterWindow(); + if (nsGlobalWindowInner* win = lock->mEventSource->GetOwnerWindow()) { + window = win->GetOuterWindow(); } } diff --git a/dom/base/GlobalTeardownObserver.cpp b/dom/base/GlobalTeardownObserver.cpp index 9f9ac39b479e..6e01f51d2e06 100644 --- a/dom/base/GlobalTeardownObserver.cpp +++ b/dom/base/GlobalTeardownObserver.cpp @@ -5,7 +5,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "GlobalTeardownObserver.h" -#include "mozilla/Sprintf.h" +#include "nsGlobalWindowInner.h" #include "mozilla/dom/Document.h" namespace mozilla { @@ -29,41 +29,36 @@ void GlobalTeardownObserver::BindToOwner(nsIGlobalObject* aOwner) { if (aOwner) { mParentObject = aOwner; aOwner->AddGlobalTeardownObserver(this); - // Let's cache the result of this QI for fast access and off main thread - // usage - mOwnerWindow = - nsCOMPtr(do_QueryInterface(aOwner)).get(); - if (mOwnerWindow) { - mHasOrHasHadOwnerWindow = true; - } + const bool isWindow = !!aOwner->GetAsInnerWindow(); + MOZ_ASSERT_IF(!isWindow, !mHasOrHasHadOwnerWindow); + mHasOrHasHadOwnerWindow = isWindow; } } void GlobalTeardownObserver::DisconnectFromOwner() { if (mParentObject) { mParentObject->RemoveGlobalTeardownObserver(this); + mParentObject = nullptr; } - mOwnerWindow = nullptr; - mParentObject = nullptr; } nsresult GlobalTeardownObserver::CheckCurrentGlobalCorrectness() const { - NS_ENSURE_STATE(!mHasOrHasHadOwnerWindow || mOwnerWindow); + if (!mParentObject) { + if (NS_IsMainThread() && !HasOrHasHadOwnerWindow()) { + return NS_OK; + } + return NS_ERROR_FAILURE; + } // Main-thread. - if (mOwnerWindow && !mOwnerWindow->IsCurrentInnerWindow()) { - return NS_ERROR_FAILURE; + if (mHasOrHasHadOwnerWindow) { + auto* ownerWin = static_cast(mParentObject); + if (!ownerWin->IsCurrentInnerWindow()) { + return NS_ERROR_FAILURE; + } } - if (NS_IsMainThread()) { - return NS_OK; - } - - if (!mParentObject) { - return NS_ERROR_FAILURE; - } - - if (mParentObject->IsDying()) { + if (mParentObject->IsDying() && !NS_IsMainThread()) { return NS_ERROR_FAILURE; } diff --git a/dom/base/GlobalTeardownObserver.h b/dom/base/GlobalTeardownObserver.h index e6e3a562991a..db8a0bc0ddbf 100644 --- a/dom/base/GlobalTeardownObserver.h +++ b/dom/base/GlobalTeardownObserver.h @@ -8,15 +8,12 @@ #define DOM_BASE_GLOBALTEARDOWNOBSERVER_H_ #include "mozilla/Attributes.h" -#include "mozilla/dom/EventTarget.h" #include "mozilla/RefPtr.h" -#include "nsCycleCollectionParticipant.h" #include "nsID.h" #include "nsIGlobalObject.h" #include "nsIScriptGlobalObject.h" #include "nsISupports.h" #include "nsISupportsUtils.h" -#include "nsPIDOMWindow.h" #define NS_GLOBALTEARDOWNOBSERVER_IID \ { \ @@ -37,9 +34,9 @@ class GlobalTeardownObserver explicit GlobalTeardownObserver(nsIGlobalObject* aGlobalObject, bool aHasOrHasHadOwnerWindow = false); - nsPIDOMWindowInner* GetOwner() const { return mOwnerWindow; } + nsGlobalWindowInner* GetOwnerWindow() const { return mOwnerWindow; } nsIGlobalObject* GetOwnerGlobal() const { return mParentObject; } - bool HasOrHasHadOwner() { return mHasOrHasHadOwnerWindow; } + bool HasOrHasHadOwnerWindow() const { return mHasOrHasHadOwnerWindow; } void GetParentObject(nsIScriptGlobalObject** aParentObject) { if (mParentObject) { @@ -75,7 +72,7 @@ class GlobalTeardownObserver // mParentObject pre QI-ed and cached (inner window) // (it is needed for off main thread access) // It is obtained in BindToOwner and reset in DisconnectFromOwner. - nsPIDOMWindowInner* MOZ_NON_OWNING_REF mOwnerWindow = nullptr; + nsGlobalWindowInner* MOZ_NON_OWNING_REF mOwnerWindow = nullptr; bool mHasOrHasHadOwnerWindow = false; }; diff --git a/dom/base/ScreenOrientation.cpp b/dom/base/ScreenOrientation.cpp index d3ef3f6652d1..14f37bcb57d6 100644 --- a/dom/base/ScreenOrientation.cpp +++ b/dom/base/ScreenOrientation.cpp @@ -168,7 +168,7 @@ ScreenOrientation::LockOrientationTask::Run() { return NS_OK; } - nsCOMPtr owner = mScreenOrientation->GetOwner(); + nsCOMPtr owner = mScreenOrientation->GetOwnerWindow(); if (!owner || !owner->IsFullyActive()) { mPromise->MaybeRejectWithAbortError("The document is not fully active."); return NS_OK; @@ -441,7 +441,7 @@ already_AddRefed ScreenOrientation::LockInternal( // If document is not fully active, return a promise rejected with an // "InvalidStateError" DOMException. - nsCOMPtr owner = GetOwner(); + nsCOMPtr owner = GetOwnerWindow(); if (NS_WARN_IF(!owner)) { aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR); return nullptr; @@ -560,12 +560,12 @@ already_AddRefed ScreenOrientation::LockInternal( RefPtr ScreenOrientation::LockDeviceOrientation( hal::ScreenOrientation aOrientation, bool aIsFullscreen) { - if (!GetOwner()) { + if (!GetOwnerWindow()) { return GenericNonExclusivePromise::CreateAndReject(NS_ERROR_DOM_ABORT_ERR, __func__); } - nsCOMPtr target = GetOwner()->GetDoc(); + nsCOMPtr target = GetOwnerWindow()->GetDoc(); // We need to register a listener so we learn when we leave fullscreen // and when we will have to unlock the screen. // This needs to be done before LockScreenOrientation call to make sure @@ -608,13 +608,13 @@ void ScreenOrientation::UnlockDeviceOrientation() { } void ScreenOrientation::CleanupFullscreenListener() { - if (!mFullscreenListener || !GetOwner()) { + if (!mFullscreenListener || !GetOwnerWindow()) { mFullscreenListener = nullptr; return; } // Remove event listener in case of fullscreen lock. - if (nsCOMPtr target = GetOwner()->GetDoc()) { + if (nsCOMPtr target = GetOwnerWindow()->GetDoc()) { target->RemoveSystemEventListener(u"fullscreenchange"_ns, mFullscreenListener, /* useCapture */ true); @@ -675,7 +675,7 @@ uint16_t ScreenOrientation::GetAngle(CallerType aCallerType, ScreenOrientation::LockPermission ScreenOrientation::GetLockOrientationPermission(bool aCheckSandbox) const { - nsCOMPtr owner = GetOwner(); + nsCOMPtr owner = GetOwnerWindow(); if (!owner) { return LOCK_DENIED; } @@ -707,7 +707,7 @@ ScreenOrientation::GetLockOrientationPermission(bool aCheckSandbox) const { } Document* ScreenOrientation::GetResponsibleDocument() const { - nsCOMPtr owner = GetOwner(); + nsCOMPtr owner = GetOwnerWindow(); if (!owner) { return nullptr; } diff --git a/dom/base/VisualViewport.cpp b/dom/base/VisualViewport.cpp index 14751109fdbc..39dfb6ed88b1 100644 --- a/dom/base/VisualViewport.cpp +++ b/dom/base/VisualViewport.cpp @@ -11,6 +11,7 @@ #include "mozilla/ScrollContainerFrame.h" #include "mozilla/ToString.h" #include "nsIDocShell.h" +#include "nsGlobalWindowInner.h" #include "nsPresContext.h" #include "nsRefreshDriver.h" #include "DocumentInlines.h" @@ -49,7 +50,7 @@ void VisualViewport::GetEventTargetParent(EventChainPreVisitor& aVisitor) { // Only our special internal events are allowed to escape the // Visual Viewport and be dispatched further up the DOM tree. if (msg == eMozVisualScroll || msg == eMozVisualResize) { - if (nsPIDOMWindowInner* win = GetOwner()) { + if (nsPIDOMWindowInner* win = GetOwnerWindow()) { if (Document* doc = win->GetExtantDoc()) { parentTarget = doc; } @@ -136,7 +137,7 @@ double VisualViewport::OffsetTop() const { } Document* VisualViewport::GetDocument() const { - nsCOMPtr window = GetOwner(); + nsCOMPtr window = GetOwnerWindow(); if (!window) { return nullptr; } diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp index 27641ed09019..b592bc320379 100644 --- a/dom/base/nsContentUtils.cpp +++ b/dom/base/nsContentUtils.cpp @@ -9925,11 +9925,9 @@ nsIDocShell* nsContentUtils::GetDocShellForEventTarget(EventTarget* aTarget) { do_QueryInterface(node->OwnerDoc()->GetScriptHandlingObject(ignore)); } else if ((innerWindow = nsPIDOMWindowInner::FromEventTarget(aTarget))) { // Nothing else to do - } else { - nsCOMPtr helper = do_QueryInterface(aTarget); - if (helper) { - innerWindow = helper->GetOwner(); - } + } else if (nsCOMPtr helper = + do_QueryInterface(aTarget)) { + innerWindow = helper->GetOwnerWindow(); } if (innerWindow) { diff --git a/dom/base/nsDOMDataChannel.cpp b/dom/base/nsDOMDataChannel.cpp index 523a70ca6f42..5635f91f8c36 100644 --- a/dom/base/nsDOMDataChannel.cpp +++ b/dom/base/nsDOMDataChannel.cpp @@ -284,7 +284,7 @@ nsresult nsDOMDataChannel::DoOnMessageAvailable(const nsACString& aData, } AutoJSAPI jsapi; - if (NS_WARN_IF(!jsapi.Init(GetOwner()))) { + if (NS_WARN_IF(!jsapi.Init(GetOwnerWindow()))) { return NS_ERROR_FAILURE; } JSContext* cx = jsapi.cx(); diff --git a/dom/base/nsDOMDataChannel.h b/dom/base/nsDOMDataChannel.h index c717983c813e..05e3370599e2 100644 --- a/dom/base/nsDOMDataChannel.h +++ b/dom/base/nsDOMDataChannel.h @@ -36,14 +36,13 @@ class nsDOMDataChannel final : public mozilla::DOMEventTargetHelper, // EventTarget using EventTarget::EventListenerAdded; - virtual void EventListenerAdded(nsAtom* aType) override; + void EventListenerAdded(nsAtom* aType) override; using EventTarget::EventListenerRemoved; - virtual void EventListenerRemoved(nsAtom* aType) override; + void EventListenerRemoved(nsAtom* aType) override; - virtual JSObject* WrapObject(JSContext* aCx, - JS::Handle aGivenProto) override; - nsPIDOMWindowInner* GetParentObject() const { return GetOwner(); } + JSObject* WrapObject(JSContext*, JS::Handle aGivenProto) override; + nsIGlobalObject* GetParentObject() const { return GetOwnerGlobal(); } // WebIDL void GetLabel(nsAString& aLabel); diff --git a/dom/base/nsGlobalWindowInner.cpp b/dom/base/nsGlobalWindowInner.cpp index 4cd8e65390b6..3678ebc59c5f 100644 --- a/dom/base/nsGlobalWindowInner.cpp +++ b/dom/base/nsGlobalWindowInner.cpp @@ -98,6 +98,7 @@ #include "mozilla/dom/BindingUtils.h" #include "mozilla/dom/BrowserChild.h" #include "mozilla/dom/BrowsingContext.h" +#include "mozilla/dom/Credential.h" #include "mozilla/dom/CSPEvalChecker.h" #include "mozilla/dom/CallbackDebuggerNotification.h" #include "mozilla/dom/ChromeMessageBroadcaster.h" diff --git a/dom/base/nsGlobalWindowInner.h b/dom/base/nsGlobalWindowInner.h index 91259ca150ff..5c817d491da7 100644 --- a/dom/base/nsGlobalWindowInner.h +++ b/dom/base/nsGlobalWindowInner.h @@ -31,7 +31,6 @@ #include "prclist.h" #include "mozilla/dom/BindingDeclarations.h" #include "mozilla/dom/ChromeMessageBroadcaster.h" -#include "mozilla/dom/Credential.h" #include "mozilla/dom/DebuggerNotificationManager.h" #include "mozilla/dom/GamepadHandle.h" #include "mozilla/dom/Location.h" @@ -102,6 +101,7 @@ namespace dom { class BarProp; class BrowsingContext; struct ChannelPixelLayout; +class Credential; class ClientSource; class Console; class Crypto; diff --git a/dom/base/nsScreen.cpp b/dom/base/nsScreen.cpp index fc832fd2cfc8..4bd1e0c9648e 100644 --- a/dom/base/nsScreen.cpp +++ b/dom/base/nsScreen.cpp @@ -49,7 +49,7 @@ int32_t nsScreen::PixelDepth() { } nsPIDOMWindowOuter* nsScreen::GetOuter() const { - if (nsPIDOMWindowInner* inner = GetOwner()) { + if (nsPIDOMWindowInner* inner = GetOwnerWindow()) { return inner->GetOuterWindow(); } return nullptr; @@ -67,7 +67,7 @@ CSSIntRect nsScreen::GetRect() { // Here we manipulate the value of aRect to represent the screen size, // if in RDM. - if (nsPIDOMWindowInner* owner = GetOwner()) { + if (nsPIDOMWindowInner* owner = GetOwnerWindow()) { if (Document* doc = owner->GetExtantDoc()) { Maybe deviceSize = nsGlobalWindowOuter::GetRDMDeviceSize(*doc); @@ -96,7 +96,7 @@ CSSIntRect nsScreen::GetAvailRect() { // Here we manipulate the value of aRect to represent the screen size, // if in RDM. - if (nsPIDOMWindowInner* owner = GetOwner()) { + if (nsPIDOMWindowInner* owner = GetOwnerWindow()) { if (Document* doc = owner->GetExtantDoc()) { Maybe deviceSize = nsGlobalWindowOuter::GetRDMDeviceSize(*doc); @@ -166,7 +166,7 @@ JSObject* nsScreen::WrapObject(JSContext* aCx, } CSSIntRect nsScreen::GetWindowInnerRect() { - nsCOMPtr win = GetOwner(); + nsCOMPtr win = GetOwnerWindow(); if (!win) { return {}; } @@ -180,7 +180,6 @@ CSSIntRect nsScreen::GetWindowInnerRect() { } bool nsScreen::ShouldResistFingerprinting(RFPTarget aTarget) const { - nsCOMPtr owner = GetOwner(); - return owner && - nsGlobalWindowInner::Cast(owner)->ShouldResistFingerprinting(aTarget); + nsGlobalWindowInner* owner = GetOwnerWindow(); + return owner && owner->ShouldResistFingerprinting(aTarget); } diff --git a/dom/base/nsScreen.h b/dom/base/nsScreen.h index aa4158e94e81..c20e6e2cbe49 100644 --- a/dom/base/nsScreen.h +++ b/dom/base/nsScreen.h @@ -28,7 +28,7 @@ class nsScreen : public mozilla::DOMEventTargetHelper { NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsScreen, mozilla::DOMEventTargetHelper) - nsPIDOMWindowInner* GetParentObject() const { return GetOwner(); } + nsIGlobalObject* GetParentObject() const { return GetOwnerGlobal(); } nsPIDOMWindowOuter* GetOuter() const; diff --git a/dom/battery/BatteryManager.cpp b/dom/battery/BatteryManager.cpp index 0a56f12af138..a42ac3017d86 100644 --- a/dom/battery/BatteryManager.cpp +++ b/dom/battery/BatteryManager.cpp @@ -13,6 +13,7 @@ #include "mozilla/dom/BatteryManagerBinding.h" #include "mozilla/Preferences.h" #include "nsContentUtils.h" +#include "nsGlobalWindowInner.h" #include "mozilla/dom/Document.h" /** @@ -113,7 +114,7 @@ void BatteryManager::UpdateFromBatteryInfo( mLevel = aBatteryInfo.level(); // Round to the nearest ten percent for non-chrome. - Document* doc = GetOwner() ? GetOwner()->GetDoc() : nullptr; + Document* doc = GetOwnerWindow() ? GetOwnerWindow()->GetDoc() : nullptr; mCharging = aBatteryInfo.charging(); mRemainingTime = aBatteryInfo.remainingTime(); diff --git a/dom/battery/BatteryManager.h b/dom/battery/BatteryManager.h index c92df7e6622f..13f6dec52f79 100644 --- a/dom/battery/BatteryManager.h +++ b/dom/battery/BatteryManager.h @@ -18,8 +18,8 @@ class BatteryInformation; namespace dom::battery { -class BatteryManager : public DOMEventTargetHelper, - public hal::BatteryObserver { +class BatteryManager final : public DOMEventTargetHelper, + public hal::BatteryObserver { public: explicit BatteryManager(nsPIDOMWindowInner* aWindow); @@ -33,10 +33,9 @@ class BatteryManager : public DOMEventTargetHelper, * WebIDL Interface */ - nsPIDOMWindowInner* GetParentObject() const { return GetOwner(); } + nsIGlobalObject* GetParentObject() const { return GetOwnerGlobal(); } - virtual JSObject* WrapObject(JSContext* aCx, - JS::Handle aGivenProto) override; + JSObject* WrapObject(JSContext*, JS::Handle aGivenProto) override; bool Charging() const; diff --git a/dom/broadcastchannel/BroadcastChannel.cpp b/dom/broadcastchannel/BroadcastChannel.cpp index 366541d9112d..5df8903a3dd9 100644 --- a/dom/broadcastchannel/BroadcastChannel.cpp +++ b/dom/broadcastchannel/BroadcastChannel.cpp @@ -353,7 +353,7 @@ void BroadcastChannel::RemoveDocFromBFCache() { return; } - if (nsPIDOMWindowInner* window = GetOwner()) { + if (nsPIDOMWindowInner* window = GetOwnerWindow()) { window->RemoveFromBFCacheSync(); } } diff --git a/dom/events/Clipboard.cpp b/dom/events/Clipboard.cpp index e36639fc5deb..04a78f645d53 100644 --- a/dom/events/Clipboard.cpp +++ b/dom/events/Clipboard.cpp @@ -330,22 +330,17 @@ already_AddRefed Clipboard::ReadHelper(nsIPrincipal& aSubjectPrincipal, ReadRequestType aType, ErrorResult& aRv) { // Create a new promise - RefPtr p = dom::Promise::Create(GetOwnerGlobal(), aRv); - if (aRv.Failed() || !p) { + nsGlobalWindowInner* owner = GetOwnerWindow(); + RefPtr p = dom::Promise::Create(owner, aRv); + if (aRv.Failed()) { return nullptr; } - nsPIDOMWindowInner* owner = GetOwner(); - if (!owner) { - p->MaybeRejectWithUndefined(); - return p.forget(); - } - // If a "paste" clipboard event is actively being processed, we're // intentionally skipping permission/user-activation checks and giving the // webpage access to the clipboard. if (RefPtr dataTransfer = - nsGlobalWindowInner::Cast(owner)->GetCurrentPasteDataTransfer()) { + owner->GetCurrentPasteDataTransfer()) { // If there is valid nsIClipboardDataSnapshot, use it directly. if (nsCOMPtr clipboardDataSnapshot = dataTransfer->GetClipboardDataSnapshot()) { @@ -685,13 +680,13 @@ already_AddRefed Clipboard::Write( const Sequence>& aData, nsIPrincipal& aSubjectPrincipal, ErrorResult& aRv) { // Create a promise - RefPtr p = dom::Promise::Create(GetOwnerGlobal(), aRv); + RefPtr owner = GetOwnerWindow(); + RefPtr p = dom::Promise::Create(owner, aRv); if (aRv.Failed()) { return nullptr; } - RefPtr owner = GetOwner(); - Document* doc = owner ? owner->GetDoc() : nullptr; + Document* doc = owner->GetDoc(); if (!doc) { p->MaybeRejectWithUndefined(); return p.forget(); @@ -751,7 +746,7 @@ already_AddRefed Clipboard::Write( [owner, request, context, principal = RefPtr{&aSubjectPrincipal}]( const nsTArray& aEntries) { RefPtr dataTransfer = - new DataTransfer(owner, eCopy, + new DataTransfer(ToSupports(owner), eCopy, /* is external */ true, /* clipboard type */ -1); @@ -800,7 +795,8 @@ already_AddRefed Clipboard::WriteText(const nsAString& aData, nsTArray> sequence; RefPtr item = MakeRefPtr( - GetOwner(), PresentationStyle::Unspecified, std::move(items)); + ToSupports(GetOwnerWindow()), PresentationStyle::Unspecified, + std::move(items)); sequence.AppendElement(*item); return Write(std::move(sequence), aSubjectPrincipal, aRv); diff --git a/dom/events/DOMEventTargetHelper.cpp b/dom/events/DOMEventTargetHelper.cpp index 2604a5a47b4a..8e7e5b9a5010 100644 --- a/dom/events/DOMEventTargetHelper.cpp +++ b/dom/events/DOMEventTargetHelper.cpp @@ -12,6 +12,7 @@ #include "mozilla/EventDispatcher.h" #include "mozilla/EventListenerManager.h" #include "mozilla/Likely.h" +#include "nsGlobalWindowInner.h" #include "MainThreadUtils.h" namespace mozilla { @@ -24,8 +25,8 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(DOMEventTargetHelper) if (MOZ_UNLIKELY(cb.WantDebugInfo())) { char name[512]; nsAutoString uri; - if (tmp->GetOwner() && tmp->GetOwner()->GetExtantDoc()) { - Unused << tmp->GetOwner()->GetExtantDoc()->GetDocumentURI(uri); + if (tmp->GetOwnerWindow() && tmp->GetOwnerWindow()->GetExtantDoc()) { + Unused << tmp->GetOwnerWindow()->GetExtantDoc()->GetDocumentURI(uri); } nsXPCOMCycleCollectionParticipant* participant = nullptr; @@ -93,8 +94,9 @@ DOMEventTargetHelper::DOMEventTargetHelper(nsIGlobalObject* aGlobalObject) : GlobalTeardownObserver(aGlobalObject) {} DOMEventTargetHelper::DOMEventTargetHelper(DOMEventTargetHelper* aOther) - : GlobalTeardownObserver(aOther ? aOther->GetParentObject() : nullptr, - aOther ? aOther->HasOrHasHadOwner() : false) {} + : GlobalTeardownObserver( + aOther ? aOther->GetParentObject() : nullptr, + aOther ? aOther->HasOrHasHadOwnerWindow() : false) {} DOMEventTargetHelper::~DOMEventTargetHelper() { if (mListenerManager) { @@ -115,12 +117,15 @@ void DOMEventTargetHelper::DisconnectFromOwner() { MaybeDontKeepAlive(); } +nsPIDOMWindowOuter* DOMEventTargetHelper::GetOwnerGlobalForBindingsInternal() { + return nsPIDOMWindowOuter::GetFromCurrentInner(GetOwnerWindow()); +} + nsPIDOMWindowInner* DOMEventTargetHelper::GetWindowIfCurrent() const { if (NS_FAILED(CheckCurrentGlobalCorrectness())) { return nullptr; } - - return GetOwner(); + return GetOwnerWindow(); } Document* DOMEventTargetHelper::GetDocumentIfCurrent() const { diff --git a/dom/events/DOMEventTargetHelper.h b/dom/events/DOMEventTargetHelper.h index c972ebacd050..c38d4f8ad3aa 100644 --- a/dom/events/DOMEventTargetHelper.h +++ b/dom/events/DOMEventTargetHelper.h @@ -10,7 +10,6 @@ #include "mozilla/Attributes.h" #include "mozilla/dom/EventTarget.h" #include "mozilla/GlobalTeardownObserver.h" -#include "mozilla/LinkedList.h" #include "mozilla/RefPtr.h" #include "nsAtom.h" #include "nsCOMPtr.h" @@ -19,9 +18,7 @@ #include "nsGkAtoms.h" #include "nsID.h" #include "nsIGlobalObject.h" -#include "nsIScriptGlobalObject.h" #include "nsISupports.h" -#include "nsISupportsUtils.h" #include "nsPIDOMWindow.h" #include "nsStringFwd.h" #include "nsTArray.h" @@ -61,8 +58,8 @@ class DOMEventTargetHelper : public dom::EventTarget, NS_DECL_CYCLE_COLLECTION_SKIPPABLE_WRAPPERCACHE_CLASS_AMBIGUOUS( DOMEventTargetHelper, dom::EventTarget) - virtual EventListenerManager* GetExistingListenerManager() const override; - virtual EventListenerManager* GetOrCreateListenerManager() override; + EventListenerManager* GetExistingListenerManager() const override; + EventListenerManager* GetOrCreateListenerManager() override; bool ComputeDefaultWantsUntrusted(ErrorResult& aRv) override; @@ -102,9 +99,7 @@ class DOMEventTargetHelper : public dom::EventTarget, bool HasListenersFor(nsAtom* aTypeWithOn) const; - virtual nsPIDOMWindowOuter* GetOwnerGlobalForBindingsInternal() override { - return nsPIDOMWindowOuter::GetFromCurrentInner(GetOwner()); - } + nsPIDOMWindowOuter* GetOwnerGlobalForBindingsInternal() override; // Like GetOwner, but only returns non-null if the window being returned is // current (in the "current document" sense of the HTML spec). @@ -116,9 +111,9 @@ class DOMEventTargetHelper : public dom::EventTarget, void DisconnectFromOwner() override; using EventTarget::GetParentObject; - virtual void EventListenerAdded(nsAtom* aType) override; + void EventListenerAdded(nsAtom* aType) override; - virtual void EventListenerRemoved(nsAtom* aType) override; + void EventListenerRemoved(nsAtom* aType) override; // Dispatch a trusted, non-cancellable and non-bubbling event to |this|. nsresult DispatchTrustedEvent(const nsAString& aEventName); diff --git a/dom/events/EventListenerManager.cpp b/dom/events/EventListenerManager.cpp index 99aeb570f296..5f85345ec597 100644 --- a/dom/events/EventListenerManager.cpp +++ b/dom/events/EventListenerManager.cpp @@ -670,7 +670,7 @@ void EventListenerManager::ProcessApzAwareEventListenerAdd() { } if (!doc) { if (nsCOMPtr helper = do_QueryInterface(mTarget)) { - if (nsPIDOMWindowInner* window = helper->GetOwner()) { + if (nsPIDOMWindowInner* window = helper->GetOwnerWindow()) { doc = window->GetExtantDoc(); } } diff --git a/dom/html/HTMLMediaElement.cpp b/dom/html/HTMLMediaElement.cpp index 3a34bc3f6363..5b5bb1d235dd 100644 --- a/dom/html/HTMLMediaElement.cpp +++ b/dom/html/HTMLMediaElement.cpp @@ -103,6 +103,7 @@ #include "nsError.h" #include "nsGenericHTMLElement.h" #include "nsGkAtoms.h" +#include "nsGlobalWindowInner.h" #include "nsIAsyncVerifyRedirectCallback.h" #include "nsICachingChannel.h" #include "nsIClassOfService.h" @@ -3670,11 +3671,11 @@ void HTMLMediaElement::AddOutputTrackSourceToOutputStream( RefPtr domTrack; if (aSource->Track()->mType == MediaSegment::AUDIO) { domTrack = new AudioStreamTrack( - aOutputStream.mStream->GetOwner(), aSource->Track(), aSource, + aOutputStream.mStream->GetOwnerWindow(), aSource->Track(), aSource, MediaStreamTrackState::Live, aSource->Muted()); } else { domTrack = new VideoStreamTrack( - aOutputStream.mStream->GetOwner(), aSource->Track(), aSource, + aOutputStream.mStream->GetOwnerWindow(), aSource->Track(), aSource, MediaStreamTrackState::Live, aSource->Muted()); } diff --git a/dom/indexedDB/ActorsChild.cpp b/dom/indexedDB/ActorsChild.cpp index 1a122ea3c1b7..0bfe185b4f44 100644 --- a/dom/indexedDB/ActorsChild.cpp +++ b/dom/indexedDB/ActorsChild.cpp @@ -1242,7 +1242,7 @@ mozilla::ipc::IPCResult BackgroundDatabaseChild::RecvVersionChange( RefPtr kungFuDeathGrip = mDatabase; // Handle bfcache'd windows. - if (nsPIDOMWindowInner* owner = kungFuDeathGrip->GetOwner()) { + if (nsPIDOMWindowInner* owner = kungFuDeathGrip->GetOwnerWindow()) { // The database must be closed if the window is already frozen. bool shouldAbortAndClose = owner->IsFrozen(); diff --git a/dom/indexedDB/IDBDatabase.cpp b/dom/indexedDB/IDBDatabase.cpp index c1a70e94012e..7326289c22dc 100644 --- a/dom/indexedDB/IDBDatabase.cpp +++ b/dom/indexedDB/IDBDatabase.cpp @@ -50,6 +50,7 @@ #include "ProfilerHelpers.h" #include "ReportInternalError.h" #include "ScriptErrorHelper.h" +#include "nsGlobalWindowInner.h" #include "nsQueryObject.h" // Include this last to avoid path problems on Windows. @@ -187,28 +188,26 @@ RefPtr IDBDatabase::Create(IDBOpenDBRequest* aRequest, RefPtr db = new IDBDatabase(aRequest, aFactory.clonePtr(), aActor, std::move(aSpec)); - if (NS_IsMainThread()) { - nsCOMPtr window = aFactory->GetOwner(); - if (window) { - uint64_t windowId = window->WindowID(); + if (nsCOMPtr window = aFactory->GetOwnerWindow()) { + MOZ_ASSERT(NS_IsMainThread()); + uint64_t windowId = window->WindowID(); - RefPtr observer = new Observer(db, windowId); + RefPtr observer = new Observer(db, windowId); - nsCOMPtr obsSvc = GetObserverService(); - MOZ_ASSERT(obsSvc); + nsCOMPtr obsSvc = GetObserverService(); + MOZ_ASSERT(obsSvc); - // This topic must be successfully registered. - MOZ_ALWAYS_SUCCEEDS( - obsSvc->AddObserver(observer, kWindowObserverTopic, false)); + // This topic must be successfully registered. + MOZ_ALWAYS_SUCCEEDS( + obsSvc->AddObserver(observer, kWindowObserverTopic, false)); - // These topics are not crucial. - QM_WARNONLY_TRY(QM_TO_RESULT( - obsSvc->AddObserver(observer, kCycleCollectionObserverTopic, false))); - QM_WARNONLY_TRY(QM_TO_RESULT( - obsSvc->AddObserver(observer, kMemoryPressureObserverTopic, false))); + // These topics are not crucial. + QM_WARNONLY_TRY(QM_TO_RESULT( + obsSvc->AddObserver(observer, kCycleCollectionObserverTopic, false))); + QM_WARNONLY_TRY(QM_TO_RESULT( + obsSvc->AddObserver(observer, kMemoryPressureObserverTopic, false))); - db->mObserver = std::move(observer); - } + db->mObserver = std::move(observer); } db->IncreaseActiveDatabaseCount(); @@ -342,7 +341,7 @@ RefPtr IDBDatabase::ObjectStoreNames() const { } RefPtr IDBDatabase::GetOwnerDocument() const { - if (nsPIDOMWindowInner* window = GetOwner()) { + if (nsPIDOMWindowInner* window = GetOwnerWindow()) { return window->GetExtantDoc(); } return nullptr; diff --git a/dom/indexedDB/IDBFactory.cpp b/dom/indexedDB/IDBFactory.cpp index a02453a29a81..36ab99b59517 100644 --- a/dom/indexedDB/IDBFactory.cpp +++ b/dom/indexedDB/IDBFactory.cpp @@ -403,8 +403,8 @@ void IDBFactory::UpdateActiveDatabaseCount(int32_t aDelta) { (mActiveDatabaseCount + aDelta) < mActiveDatabaseCount); mActiveDatabaseCount += aDelta; - if (GetOwner()) { - GetOwner()->UpdateActiveIndexedDBDatabaseCount(aDelta); + if (nsGlobalWindowInner* win = GetOwnerWindow()) { + win->UpdateActiveIndexedDBDatabaseCount(aDelta); } } diff --git a/dom/media/CanvasCaptureMediaStream.cpp b/dom/media/CanvasCaptureMediaStream.cpp index 377243540c22..3fdb8c52d671 100644 --- a/dom/media/CanvasCaptureMediaStream.cpp +++ b/dom/media/CanvasCaptureMediaStream.cpp @@ -10,11 +10,10 @@ #include "MediaTrackGraph.h" #include "Tracing.h" #include "VideoSegment.h" -#include "gfxPlatform.h" -#include "mozilla/Atomics.h" #include "mozilla/dom/CanvasCaptureMediaStreamBinding.h" #include "mozilla/gfx/2D.h" #include "nsContentUtils.h" +#include "nsGlobalWindowInner.h" using namespace mozilla::layers; using namespace mozilla::gfx; @@ -172,7 +171,7 @@ void CanvasCaptureMediaStream::RequestFrame() { nsresult CanvasCaptureMediaStream::Init(const dom::Optional& aFPS, nsIPrincipal* aPrincipal) { MediaTrackGraph* graph = MediaTrackGraph::GetInstance( - MediaTrackGraph::SYSTEM_THREAD_DRIVER, GetOwner(), + MediaTrackGraph::SYSTEM_THREAD_DRIVER, GetOwnerWindow(), MediaTrackGraph::REQUEST_DEFAULT_SAMPLE_RATE, MediaTrackGraph::DEFAULT_OUTPUT_DEVICE); SourceMediaTrack* source = graph->CreateSourceTrack(MediaSegment::VIDEO); diff --git a/dom/media/DOMMediaStream.cpp b/dom/media/DOMMediaStream.cpp index 2c1e2ea51462..8eda8471ba5c 100644 --- a/dom/media/DOMMediaStream.cpp +++ b/dom/media/DOMMediaStream.cpp @@ -366,7 +366,7 @@ void DOMMediaStream::RemoveTrack(MediaStreamTrack& aTrack) { } already_AddRefed DOMMediaStream::Clone() { - auto newStream = MakeRefPtr(GetOwner()); + auto newStream = MakeRefPtr(GetOwnerWindow()); LOG(LogLevel::Info, ("DOMMediaStream %p created clone %p", this, newStream.get())); @@ -418,11 +418,11 @@ void DOMMediaStream::RemoveTrackInternal(MediaStreamTrack* aTrack) { } already_AddRefed DOMMediaStream::GetPrincipal() { - if (!GetOwner()) { + nsGlobalWindowInner* win = GetOwnerWindow(); + if (!win) { return nullptr; } - nsCOMPtr principal = - nsGlobalWindowInner::Cast(GetOwner())->GetPrincipal(); + nsCOMPtr principal = win->GetPrincipal(); for (const auto& t : mTracks) { if (t->Ended()) { continue; diff --git a/dom/media/MediaDevices.cpp b/dom/media/MediaDevices.cpp index b312fc1ec357..eb1efe98bdba 100644 --- a/dom/media/MediaDevices.cpp +++ b/dom/media/MediaDevices.cpp @@ -48,7 +48,8 @@ already_AddRefed MediaDevices::GetUserMedia( ErrorResult& aRv) { MOZ_ASSERT(NS_IsMainThread()); // Get the relevant global for the promise from the wrapper cache because - // DOMEventTargetHelper::GetOwner() returns null if the document is unloaded. + // DOMEventTargetHelper::GetOwnerWindow() returns null if the document is + // unloaded. // We know the wrapper exists because it is being used for |this| from JS. // See https://github.com/heycam/webidl/issues/932 for why the relevant // global is used instead of the current global. @@ -185,7 +186,7 @@ void MediaDevices::MaybeResumeDeviceExposure() { !mHaveUnprocessedDeviceListChange) { return; } - nsPIDOMWindowInner* window = GetOwner(); + nsPIDOMWindowInner* window = GetOwnerWindow(); if (!window || !window->IsFullyActive()) { return; } @@ -229,7 +230,7 @@ void MediaDevices::MaybeResumeDeviceExposure() { RefPtr MediaDevices::FilterExposedDevices( const MediaDeviceSet& aDevices) const { - nsPIDOMWindowInner* window = GetOwner(); + nsPIDOMWindowInner* window = GetOwnerWindow(); RefPtr exposed = new MediaDeviceSetRefCnt(); if (!window) { return exposed; // Promises will be left pending @@ -394,7 +395,7 @@ bool MediaDevices::ShouldQueueDeviceChange( void MediaDevices::ResumeEnumerateDevices( nsTArray>&& aPromises, RefPtr aExposedDevices) const { - nsCOMPtr window = GetOwner(); + nsCOMPtr window = GetOwnerWindow(); if (!window) { return; // Leave Promise pending after navigation by design. } @@ -421,7 +422,7 @@ void MediaDevices::ResumeEnumerateDevices( void MediaDevices::ResolveEnumerateDevicesPromise( Promise* aPromise, const LocalMediaDeviceSet& aDevices) const { - nsCOMPtr window = GetOwner(); + nsCOMPtr window = GetOwnerWindow(); auto windowId = window->WindowID(); nsTArray> infos; bool legacy = StaticPrefs::media_devices_enumerate_legacy_enabled(); @@ -659,7 +660,7 @@ RefPtr MediaDevices::GetSinkDevice( GetCurrentSerialEventTarget(), __func__, [self = RefPtr(this), this, aDeviceId](RefPtr aRawDevices) { - nsCOMPtr window = GetOwner(); + nsCOMPtr window = GetOwnerWindow(); if (!window) { return LocalDeviceSetPromise::CreateAndReject( new MediaMgrError(MediaMgrError::Name::AbortError), __func__); @@ -728,7 +729,7 @@ void MediaDevices::OnDeviceChange() { if (nsContentUtils::ShouldResistFingerprinting( "Guarding the more expensive RFP check with a simple one", RFPTarget::MediaDevices)) { - nsCOMPtr window = GetOwner(); + nsCOMPtr window = GetOwnerWindow(); auto* wrapper = GetWrapper(); if (!window && wrapper) { nsCOMPtr global = xpc::NativeGlobal(wrapper); @@ -757,7 +758,7 @@ void MediaDevices::SetupDeviceChangeListener() { return; } - nsPIDOMWindowInner* window = GetOwner(); + nsPIDOMWindowInner* window = GetOwnerWindow(); if (!window) { return; } diff --git a/dom/media/MediaRecorder.cpp b/dom/media/MediaRecorder.cpp index be3b97cc99a0..3a27d0e9fb18 100644 --- a/dom/media/MediaRecorder.cpp +++ b/dom/media/MediaRecorder.cpp @@ -34,6 +34,7 @@ #include "nsIScriptError.h" #include "nsMimeTypes.h" #include "nsProxyRelease.h" +#include "nsGlobalWindowInner.h" #include "nsServiceManagerUtils.h" #include "nsTArray.h" @@ -166,10 +167,10 @@ NS_IMPL_RELEASE_INHERITED(MediaRecorder, DOMEventTargetHelper) namespace { bool PrincipalSubsumes(MediaRecorder* aRecorder, nsIPrincipal* aPrincipal) { - if (!aRecorder->GetOwner()) { + if (!aRecorder->GetOwnerWindow()) { return false; } - nsCOMPtr doc = aRecorder->GetOwner()->GetExtantDoc(); + nsCOMPtr doc = aRecorder->GetOwnerWindow()->GetExtantDoc(); if (!doc) { return false; } @@ -197,8 +198,9 @@ bool MediaStreamTracksPrincipalSubsumes( bool AudioNodePrincipalSubsumes(MediaRecorder* aRecorder, AudioNode* aAudioNode) { MOZ_ASSERT(aAudioNode); - Document* doc = - aAudioNode->GetOwner() ? aAudioNode->GetOwner()->GetExtantDoc() : nullptr; + Document* doc = aAudioNode->GetOwnerWindow() + ? aAudioNode->GetOwnerWindow()->GetExtantDoc() + : nullptr; nsCOMPtr principal = doc ? doc->NodePrincipal() : nullptr; return PrincipalSubsumes(aRecorder, principal); } @@ -1192,7 +1194,7 @@ MediaRecorder::MediaRecorder(nsPIDOMWindowInner* aOwnerWindow) } void MediaRecorder::RegisterActivityObserver() { - if (nsPIDOMWindowInner* window = GetOwner()) { + if (nsPIDOMWindowInner* window = GetOwnerWindow()) { mDocument = window->GetExtantDoc(); if (mDocument) { mDocument->RegisterActivityObserver( @@ -1823,7 +1825,7 @@ void MediaRecorder::RemoveSession(Session* aSession) { } void MediaRecorder::NotifyOwnerDocumentActivityChanged() { - nsPIDOMWindowInner* window = GetOwner(); + nsPIDOMWindowInner* window = GetOwnerWindow(); NS_ENSURE_TRUE_VOID(window); Document* doc = window->GetExtantDoc(); NS_ENSURE_TRUE_VOID(doc); diff --git a/dom/media/autoplay/AutoplayPolicy.cpp b/dom/media/autoplay/AutoplayPolicy.cpp index fafa20477ed8..ec5b2c454d63 100644 --- a/dom/media/autoplay/AutoplayPolicy.cpp +++ b/dom/media/autoplay/AutoplayPolicy.cpp @@ -151,7 +151,7 @@ static bool IsMediaElementInaudible(const HTMLMediaElement& aElement) { static bool IsAudioContextAllowedToPlay(const AudioContext& aContext) { // Offline context won't directly output sound to audio devices. return aContext.IsOffline() || - IsWindowAllowedToPlayOverall(aContext.GetParentObject()); + IsWindowAllowedToPlayOverall(aContext.GetOwnerWindow()); } static bool IsEnableBlockingWebAudioByUserGesturePolicy() { @@ -297,7 +297,7 @@ bool AutoplayPolicy::IsAllowedToPlay(const AudioContext& aContext) { return true; } - nsPIDOMWindowInner* window = aContext.GetParentObject(); + nsPIDOMWindowInner* window = aContext.GetOwnerWindow(); uint32_t sitePermission = SiteAutoplayPerm(window); if (sitePermission == nsIPermissionManager::ALLOW_ACTION) { diff --git a/dom/media/imagecapture/ImageCapture.cpp b/dom/media/imagecapture/ImageCapture.cpp index d32c22d05436..2a0bea0e7732 100644 --- a/dom/media/imagecapture/ImageCapture.cpp +++ b/dom/media/imagecapture/ImageCapture.cpp @@ -16,6 +16,7 @@ #include "mozilla/dom/Document.h" #include "CaptureTask.h" #include "MediaEngineSource.h" +#include "nsGlobalWindowInner.h" namespace mozilla { @@ -189,23 +190,12 @@ nsresult ImageCapture::PostErrorEvent(uint16_t aErrorCode, nsresult aReason) { bool ImageCapture::CheckPrincipal() { MOZ_ASSERT(NS_IsMainThread()); - nsCOMPtr principal = mTrack->GetPrincipal(); - - if (!GetOwner()) { + if (!GetOwnerWindow()) { return false; } - nsCOMPtr doc = GetOwner()->GetExtantDoc(); - if (!doc || !principal) { - return false; - } - - bool subsumes; - if (NS_FAILED(doc->NodePrincipal()->Subsumes(principal, &subsumes))) { - return false; - } - - return subsumes; + nsCOMPtr doc = GetOwnerWindow()->GetExtantDoc(); + return doc && principal && doc->NodePrincipal()->Subsumes(principal); } } // namespace dom diff --git a/dom/media/imagecapture/ImageCapture.h b/dom/media/imagecapture/ImageCapture.h index 957a3ffcccd8..78487ae0e3a8 100644 --- a/dom/media/imagecapture/ImageCapture.h +++ b/dom/media/imagecapture/ImageCapture.h @@ -60,7 +60,7 @@ class ImageCapture final : public DOMEventTargetHelper { } // ImageCapture class members - nsPIDOMWindowInner* GetParentObject() { return GetOwner(); } + nsIGlobalObject* GetParentObject() const { return GetOwnerGlobal(); } static already_AddRefed Constructor(const GlobalObject& aGlobal, MediaStreamTrack& aTrack, diff --git a/dom/media/mediasource/MediaSource.cpp b/dom/media/mediasource/MediaSource.cpp index 8f4cd0c51421..9e989ea02181 100644 --- a/dom/media/mediasource/MediaSource.cpp +++ b/dom/media/mediasource/MediaSource.cpp @@ -14,13 +14,11 @@ #include "MediaContainerType.h" #include "MediaResult.h" #include "MediaSourceDemuxer.h" -#include "MediaSourceUtils.h" #include "SourceBuffer.h" #include "SourceBufferList.h" #include "mozilla/ErrorResult.h" #include "mozilla/FloatingPoint.h" #include "mozilla/Logging.h" -#include "mozilla/Sprintf.h" #include "mozilla/StaticPrefs_media.h" #include "mozilla/dom/BindingDeclarations.h" #include "mozilla/dom/HTMLMediaElement.h" @@ -32,7 +30,7 @@ #include "nsIScriptObjectPrincipal.h" #include "nsMimeTypes.h" #include "nsPIDOMWindow.h" -#include "nsServiceManagerUtils.h" +#include "nsGlobalWindowInner.h" #include "nsString.h" #include "nsThreadUtils.h" @@ -282,11 +280,11 @@ already_AddRefed MediaSource::AddSourceBuffer( MOZ_ASSERT(NS_IsMainThread()); DecoderDoctorDiagnostics diagnostics; IsTypeSupported(aType, &diagnostics, aRv); - RecordTypeForTelemetry(aType, GetOwner()); + RecordTypeForTelemetry(aType, GetOwnerWindow()); bool supported = !aRv.Failed(); diagnostics.StoreFormatDiagnostics( - GetOwner() ? GetOwner()->GetExtantDoc() : nullptr, aType, supported, - __func__); + GetOwnerWindow() ? GetOwnerWindow()->GetExtantDoc() : nullptr, aType, + supported, __func__); MSE_API("AddSourceBuffer(aType=%s)%s", NS_ConvertUTF16toUTF8(aType).get(), supported ? "" : " [not supported]"); if (!supported) { @@ -653,12 +651,12 @@ void MediaSource::DurationChange(double aNewDuration, ErrorResult& aRv) { already_AddRefed MediaSource::MozDebugReaderData(ErrorResult& aRv) { // Creating a JS promise - nsPIDOMWindowInner* win = GetOwner(); + nsGlobalWindowInner* win = GetOwnerWindow(); if (!win) { aRv.Throw(NS_ERROR_UNEXPECTED); return nullptr; } - RefPtr domPromise = Promise::Create(win->AsGlobal(), aRv); + RefPtr domPromise = Promise::Create(win, aRv); if (NS_WARN_IF(aRv.Failed())) { return nullptr; } @@ -677,7 +675,9 @@ already_AddRefed MediaSource::MozDebugReaderData(ErrorResult& aRv) { return domPromise.forget(); } -nsPIDOMWindowInner* MediaSource::GetParentObject() const { return GetOwner(); } +nsPIDOMWindowInner* MediaSource::GetParentObject() const { + return GetOwnerWindow(); +} JSObject* MediaSource::WrapObject(JSContext* aCx, JS::Handle aGivenProto) { diff --git a/dom/media/mediasource/SourceBuffer.cpp b/dom/media/mediasource/SourceBuffer.cpp index 504ec6a3b3a8..14a4d61d33e2 100644 --- a/dom/media/mediasource/SourceBuffer.cpp +++ b/dom/media/mediasource/SourceBuffer.cpp @@ -12,12 +12,12 @@ #include "MediaSourceUtils.h" #include "mozilla/ErrorResult.h" #include "mozilla/FloatingPoint.h" -#include "mozilla/Preferences.h" #include "mozilla/dom/MediaSourceBinding.h" #include "mozilla/dom/TimeRanges.h" #include "mozilla/dom/TypedArray.h" #include "nsError.h" #include "nsIRunnable.h" +#include "nsGlobalWindowInner.h" #include "nsThreadUtils.h" #include "mozilla/Logging.h" #include @@ -389,8 +389,9 @@ void SourceBuffer::ChangeType(const nsAString& aType, ErrorResult& aRv) { MediaSource::IsTypeSupported(aType, &diagnostics, aRv); bool supported = !aRv.Failed(); diagnostics.StoreFormatDiagnostics( - mMediaSource->GetOwner() ? mMediaSource->GetOwner()->GetExtantDoc() - : nullptr, + mMediaSource->GetOwnerWindow() + ? mMediaSource->GetOwnerWindow()->GetExtantDoc() + : nullptr, aType, supported, __func__); MSE_API("ChangeType(aType=%s)%s", NS_ConvertUTF16toUTF8(aType).get(), supported ? "" : " [not supported]"); diff --git a/dom/media/webaudio/AudioContext.cpp b/dom/media/webaudio/AudioContext.cpp index 2ef5fdd65bcb..66184b683b76 100644 --- a/dom/media/webaudio/AudioContext.cpp +++ b/dom/media/webaudio/AudioContext.cpp @@ -233,8 +233,7 @@ void AudioContext::StartBlockedAudioContextIfAllowed() { void AudioContext::DisconnectFromWindow() { MaybeClearPageAwakeRequest(); - nsPIDOMWindowInner* window = GetOwner(); - if (window) { + if (nsGlobalWindowInner* window = GetOwnerWindow()) { window->RemoveAudioContext(this); } } @@ -249,9 +248,8 @@ JSObject* AudioContext::WrapObject(JSContext* aCx, JS::Handle aGivenProto) { if (mIsOffline) { return OfflineAudioContext_Binding::Wrap(aCx, this, aGivenProto); - } else { - return AudioContext_Binding::Wrap(aCx, this, aGivenProto); } + return AudioContext_Binding::Wrap(aCx, this, aGivenProto); } static bool CheckFullyActive(nsPIDOMWindowInner* aWindow, ErrorResult& aRv) { @@ -374,7 +372,7 @@ already_AddRefed AudioContext::CreateBuffer( return nullptr; } - return AudioBuffer::Create(GetOwner(), aNumberOfChannels, aLength, + return AudioBuffer::Create(GetOwnerWindow(), aNumberOfChannels, aLength, aSampleRate, aRv); } @@ -591,8 +589,8 @@ void AudioContext::GetOutputTimestamp(AudioTimestamp& aTimeStamp) { // output latency. The resolution of CurrentTime() is already reduced. aTimeStamp.mContextTime.Construct( std::max(0.0, CurrentTime() - OutputLatency())); - nsPIDOMWindowInner* parent = GetParentObject(); - Performance* perf = parent ? parent->GetPerformance() : nullptr; + nsGlobalWindowInner* win = GetOwnerWindow(); + Performance* perf = win ? win->GetPerformance() : nullptr; if (perf) { // perf->Now() already has reduced resolution here, no need to do it again. aTimeStamp.mPerformanceTime.Construct( @@ -615,7 +613,8 @@ bool AudioContext::IsRunning() const { already_AddRefed AudioContext::CreatePromise(ErrorResult& aRv) { // Get the relevant global for the promise from the wrapper cache because - // DOMEventTargetHelper::GetOwner() returns null if the document is unloaded. + // DOMEventTargetHelper::GetOwnerWindow() returns null if the document is + // unloaded. // We know the wrapper exists because it is being used for |this| from JS. // See https://github.com/heycam/webidl/issues/932 for why the relevant // global is used instead of the current global. @@ -765,8 +764,8 @@ double AudioContext::CurrentTime() { } nsISerialEventTarget* AudioContext::GetMainThread() const { - if (nsPIDOMWindowInner* window = GetParentObject()) { - return window->AsGlobal()->SerialEventTarget(); + if (nsIGlobalObject* global = GetOwnerGlobal()) { + return global->SerialEventTarget(); } return GetCurrentSerialEventTarget(); } @@ -830,12 +829,12 @@ class OnStateChangeTask final : public Runnable { NS_IMETHODIMP Run() override { - nsPIDOMWindowInner* parent = mAudioContext->GetParentObject(); - if (!parent) { + nsGlobalWindowInner* win = mAudioContext->GetOwnerWindow(); + if (!win) { return NS_ERROR_FAILURE; } - Document* doc = parent->GetExtantDoc(); + Document* doc = win->GetExtantDoc(); if (!doc) { return NS_ERROR_FAILURE; } @@ -903,7 +902,7 @@ void AudioContext::OnStateChanged(void* aPromise, AudioContextState aNewState) { } BrowsingContext* AudioContext::GetTopLevelBrowsingContext() { - nsCOMPtr window = GetParentObject(); + nsGlobalWindowInner* window = GetOwnerWindow(); if (!window) { return nullptr; } @@ -1173,15 +1172,14 @@ void AudioContext::ReportBlocked() { return; } - RefPtr self = this; - RefPtr r = - NS_NewRunnableFunction("AudioContext::AutoplayBlocked", [self]() { - nsPIDOMWindowInner* parent = self->GetParentObject(); - if (!parent) { + RefPtr r = NS_NewRunnableFunction( + "AudioContext::AutoplayBlocked", [self = RefPtr{this}]() { + nsGlobalWindowInner* win = self->GetOwnerWindow(); + if (!win) { return; } - Document* doc = parent->GetExtantDoc(); + Document* doc = win->GetExtantDoc(); if (!doc) { return; } @@ -1365,8 +1363,7 @@ BasicWaveFormCache* AudioContext::GetBasicWaveFormCache() { void AudioContext::ReportToConsole(uint32_t aErrorFlags, const char* aMsg) const { MOZ_ASSERT(aMsg); - Document* doc = - GetParentObject() ? GetParentObject()->GetExtantDoc() : nullptr; + Document* doc = GetOwnerWindow() ? GetOwnerWindow()->GetExtantDoc() : nullptr; nsContentUtils::ReportToConsole(aErrorFlags, "Media"_ns, doc, nsContentUtils::eDOM_PROPERTIES, aMsg); } diff --git a/dom/media/webaudio/AudioContext.h b/dom/media/webaudio/AudioContext.h index 81a64a18bfd2..23d314b7fd77 100644 --- a/dom/media/webaudio/AudioContext.h +++ b/dom/media/webaudio/AudioContext.h @@ -147,11 +147,11 @@ class AudioContext final : public DOMEventTargetHelper, NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(AudioContext, DOMEventTargetHelper) MOZ_DEFINE_MALLOC_SIZE_OF(MallocSizeOf) - nsPIDOMWindowInner* GetParentObject() const { return GetOwner(); } + nsIGlobalObject* GetParentObject() const { return GetOwnerGlobal(); } nsISerialEventTarget* GetMainThread() const; - virtual void DisconnectFromOwner() override; + void DisconnectFromOwner() override; void OnWindowDestroy(); // idempotent diff --git a/dom/media/webaudio/AudioDestinationNode.cpp b/dom/media/webaudio/AudioDestinationNode.cpp index 1a9c3c0f7b13..77b4bfd6c63f 100644 --- a/dom/media/webaudio/AudioDestinationNode.cpp +++ b/dom/media/webaudio/AudioDestinationNode.cpp @@ -8,7 +8,6 @@ #include "AlignmentUtils.h" #include "AudibilityMonitor.h" -#include "AudioChannelService.h" #include "AudioContext.h" #include "AudioNodeEngine.h" #include "AudioNodeTrack.h" @@ -25,9 +24,7 @@ #include "mozilla/Telemetry.h" #include "mozilla/TelemetryHistogramEnums.h" #include "nsContentUtils.h" -#include "nsIInterfaceRequestorUtils.h" -#include "nsIScriptObjectPrincipal.h" -#include "nsServiceManagerUtils.h" +#include "nsGlobalWindowInner.h" #include "Tracing.h" extern mozilla::LazyLogModule gAudioChannelLog; @@ -152,8 +149,8 @@ class OfflineDestinationNodeEngine final : public AudioNodeEngine { // Create the input buffer ErrorResult rv; RefPtr renderedBuffer = - AudioBuffer::Create(aContext->GetOwner(), mNumberOfChannels, mLength, - mSampleRate, mBuffer.forget(), rv); + AudioBuffer::Create(aContext->GetOwnerWindow(), mNumberOfChannels, + mLength, mSampleRate, mBuffer.forget(), rv); if (rv.Failed()) { rv.SuppressException(); return nullptr; @@ -308,7 +305,7 @@ AudioDestinationNode::AudioDestinationNode(AudioContext* aContext, // GetParentObject can return nullptr here. This will end up creating another // MediaTrackGraph MediaTrackGraph* graph = MediaTrackGraph::GetInstance( - MediaTrackGraph::AUDIO_THREAD_DRIVER, aContext->GetParentObject(), + MediaTrackGraph::AUDIO_THREAD_DRIVER, aContext->GetOwnerWindow(), aContext->SampleRate(), MediaTrackGraph::DEFAULT_OUTPUT_DEVICE); AudioNodeEngine* engine = new DestinationNodeEngine(this); @@ -339,7 +336,7 @@ void AudioDestinationNode::CreateAndStartAudioChannelAgent() { MOZ_ASSERT(!mAudioChannelAgent); AudioChannelAgent* agent = new AudioChannelAgent(); - nsresult rv = agent->InitWithWeakCallback(GetOwner(), this); + nsresult rv = agent->InitWithWeakCallback(GetOwnerWindow(), this); if (NS_WARN_IF(NS_FAILED(rv))) { AUDIO_CHANNEL_LOG("Failed to init audio channel agent"); return; @@ -567,8 +564,7 @@ AudioDestinationNode::WindowAudioCaptureChanged(bool aCapture) { return NS_OK; } - nsCOMPtr ownerWindow = GetOwner(); - if (!ownerWindow) { + if (!GetOwnerWindow()) { return NS_OK; } @@ -591,7 +587,7 @@ bool AudioDestinationNode::IsCapturingAudio() const { void AudioDestinationNode::StartAudioCapturingTrack() { MOZ_ASSERT(!IsCapturingAudio()); - nsCOMPtr window = Context()->GetParentObject(); + nsGlobalWindowInner* window = Context()->GetOwnerWindow(); uint64_t id = window->WindowID(); mCaptureTrackPort = mTrack->Graph()->ConnectToCaptureTrack(id, mTrack); } @@ -609,7 +605,8 @@ void AudioDestinationNode::CreateAudioWakeLockIfNeeded() { NS_ENSURE_TRUE_VOID(pmService); ErrorResult rv; - mWakeLock = pmService->NewWakeLock(u"audio-playing"_ns, GetOwner(), rv); + mWakeLock = + pmService->NewWakeLock(u"audio-playing"_ns, GetOwnerWindow(), rv); } } diff --git a/dom/media/webaudio/AudioProcessingEvent.cpp b/dom/media/webaudio/AudioProcessingEvent.cpp index 7d9987db0739..beee4e98921a 100644 --- a/dom/media/webaudio/AudioProcessingEvent.cpp +++ b/dom/media/webaudio/AudioProcessingEvent.cpp @@ -8,6 +8,7 @@ #include "mozilla/dom/AudioProcessingEventBinding.h" #include "mozilla/dom/ScriptSettings.h" #include "AudioContext.h" +#include "nsGlobalWindowInner.h" namespace mozilla::dom { @@ -35,8 +36,8 @@ JSObject* AudioProcessingEvent::WrapObjectInternal( already_AddRefed AudioProcessingEvent::LazilyCreateBuffer( uint32_t aNumberOfChannels, ErrorResult& aRv) { RefPtr buffer = AudioBuffer::Create( - mNode->Context()->GetOwner(), aNumberOfChannels, mNode->BufferSize(), - mNode->Context()->SampleRate(), aRv); + mNode->Context()->GetOwnerWindow(), aNumberOfChannels, + mNode->BufferSize(), mNode->Context()->SampleRate(), aRv); MOZ_ASSERT(buffer || aRv.ErrorCodeIs(NS_ERROR_OUT_OF_MEMORY)); return buffer.forget(); } diff --git a/dom/media/webaudio/AudioWorkletImpl.cpp b/dom/media/webaudio/AudioWorkletImpl.cpp index 5eaa128c8a47..26c665bfc722 100644 --- a/dom/media/webaudio/AudioWorkletImpl.cpp +++ b/dom/media/webaudio/AudioWorkletImpl.cpp @@ -21,13 +21,12 @@ namespace mozilla { dom::AudioContext* aContext, ErrorResult& aRv) { MOZ_ASSERT(NS_IsMainThread()); - nsCOMPtr window = aContext->GetOwner(); + nsGlobalWindowInner* window = aContext->GetOwnerWindow(); if (NS_WARN_IF(!window)) { aRv.Throw(NS_ERROR_FAILURE); return nullptr; } - nsCOMPtr principal = - nsGlobalWindowInner::Cast(window)->GetPrincipal(); + nsIPrincipal* principal = window->GetPrincipal(); if (NS_WARN_IF(!principal)) { aRv.Throw(NS_ERROR_FAILURE); return nullptr; diff --git a/dom/media/webaudio/BiquadFilterNode.cpp b/dom/media/webaudio/BiquadFilterNode.cpp index 602dbf9cc16a..f2efdc1c94dc 100644 --- a/dom/media/webaudio/BiquadFilterNode.cpp +++ b/dom/media/webaudio/BiquadFilterNode.cpp @@ -17,6 +17,7 @@ #include "mozilla/ErrorResult.h" #include "AudioParamTimeline.h" #include "Tracing.h" +#include "nsGlobalWindowInner.h" namespace mozilla::dom { @@ -235,8 +236,8 @@ BiquadFilterNode::BiquadFilterNode(AudioContext* aContext) mGain = CreateAudioParam(BiquadFilterNodeEngine::GAIN, u"gain"_ns, 0.f); uint64_t windowID = 0; - if (aContext->GetParentObject()) { - windowID = aContext->GetParentObject()->WindowID(); + if (nsGlobalWindowInner* win = aContext->GetOwnerWindow()) { + windowID = win->WindowID(); } BiquadFilterNodeEngine* engine = new BiquadFilterNodeEngine(this, aContext->Destination(), windowID); diff --git a/dom/media/webaudio/IIRFilterNode.cpp b/dom/media/webaudio/IIRFilterNode.cpp index fe87744d4dea..77a8625d7954 100644 --- a/dom/media/webaudio/IIRFilterNode.cpp +++ b/dom/media/webaudio/IIRFilterNode.cpp @@ -11,8 +11,8 @@ #include "PlayingRefChangeHandler.h" #include "AlignmentUtils.h" #include "nsPrintfCString.h" +#include "nsGlobalWindowInner.h" -#include "nsGkAtoms.h" #include "Tracing.h" namespace mozilla::dom { @@ -151,8 +151,8 @@ IIRFilterNode::IIRFilterNode(AudioContext* aContext, elements[0] = 1.0; uint64_t windowID = 0; - if (aContext->GetParentObject()) { - windowID = aContext->GetParentObject()->WindowID(); + if (nsGlobalWindowInner* win = aContext->GetOwnerWindow()) { + windowID = win->WindowID(); } IIRFilterNodeEngine* engine = new IIRFilterNodeEngine( this, aContext->Destination(), mFeedforward, mFeedback, windowID); diff --git a/dom/media/webaudio/MediaBufferDecoder.cpp b/dom/media/webaudio/MediaBufferDecoder.cpp index 425c0639b58c..72df5006a8a9 100644 --- a/dom/media/webaudio/MediaBufferDecoder.cpp +++ b/dom/media/webaudio/MediaBufferDecoder.cpp @@ -24,19 +24,13 @@ #include "mozilla/AbstractThread.h" #include "mozilla/Logging.h" #include "mozilla/StaticPrefs_media.h" -#include "mozilla/Telemetry.h" #include "mozilla/dom/AudioContextBinding.h" #include "mozilla/dom/BaseAudioContextBinding.h" #include "mozilla/dom/DOMException.h" #include "mozilla/dom/Promise.h" -#include "mozilla/dom/ScriptSettings.h" -#include "nsComponentManagerUtils.h" #include "nsContentUtils.h" -#include "nsIScriptError.h" -#include "nsIScriptObjectPrincipal.h" +#include "nsGlobalWindowInner.h" #include "nsMimeTypes.h" -#include "nsPrintfCString.h" -#include "nsXPCOMCIDInternal.h" namespace mozilla { @@ -626,8 +620,8 @@ bool WebAudioDecodeJob::AllocateBuffer() { MOZ_ASSERT(NS_IsMainThread()); // Now create the AudioBuffer - mOutput = AudioBuffer::Create(mContext->GetOwner(), mContext->SampleRate(), - std::move(mBuffer)); + mOutput = AudioBuffer::Create(mContext->GetOwnerWindow(), + mContext->SampleRate(), std::move(mBuffer)); return mOutput != nullptr; } diff --git a/dom/media/webaudio/MediaStreamAudioDestinationNode.cpp b/dom/media/webaudio/MediaStreamAudioDestinationNode.cpp index 704adaa30451..614fbe049ab5 100644 --- a/dom/media/webaudio/MediaStreamAudioDestinationNode.cpp +++ b/dom/media/webaudio/MediaStreamAudioDestinationNode.cpp @@ -12,6 +12,7 @@ #include "AudioStreamTrack.h" #include "DOMMediaStream.h" #include "ForwardedInputTrack.h" +#include "nsGlobalWindowInner.h" namespace mozilla::dom { @@ -83,15 +84,15 @@ MediaStreamAudioDestinationNode::MediaStreamAudioDestinationNode( AudioContext* aContext) : AudioNode(aContext, 2, ChannelCountMode::Explicit, ChannelInterpretation::Speakers), - mDOMStream(MakeAndAddRef(GetOwner())) { + mDOMStream(MakeAndAddRef(GetOwnerWindow())) { // Ensure an audio track with the correct ID is exposed to JS. If we can't get // a principal here because the document is not available, pass in a null // principal. This happens in edge cases when the document is being unloaded // and it does not matter too much to have something working as long as it's // not dangerous. nsCOMPtr principal = nullptr; - if (aContext->GetParentObject()) { - Document* doc = aContext->GetParentObject()->GetExtantDoc(); + if (nsGlobalWindowInner* win = aContext->GetOwnerWindow()) { + Document* doc = win->GetExtantDoc(); principal = doc->NodePrincipal(); } mTrack = AudioNodeTrack::Create(aContext, new AudioNodeEngine(this), @@ -101,7 +102,8 @@ MediaStreamAudioDestinationNode::MediaStreamAudioDestinationNode( this, mTrack, aContext->Graph()->CreateForwardedInputTrack(MediaSegment::AUDIO), principal); - auto track = MakeRefPtr(GetOwner(), source->mTrack, source); + auto track = + MakeRefPtr(GetOwnerWindow(), source->mTrack, source); mDOMStream->AddTrackInternal(track); } diff --git a/dom/media/webaudio/MediaStreamAudioSourceNode.cpp b/dom/media/webaudio/MediaStreamAudioSourceNode.cpp index 4ade20d16d45..b6a1208a757b 100644 --- a/dom/media/webaudio/MediaStreamAudioSourceNode.cpp +++ b/dom/media/webaudio/MediaStreamAudioSourceNode.cpp @@ -13,6 +13,7 @@ #include "nsContentUtils.h" #include "nsIScriptError.h" #include "nsID.h" +#include "nsGlobalWindowInner.h" #include "Tracing.h" namespace mozilla::dom { @@ -102,7 +103,7 @@ void MediaStreamAudioSourceNode::AttachToTrack( } if (NS_WARN_IF(Context()->Graph() != aTrack->Graph())) { - nsCOMPtr pWindow = Context()->GetParentObject(); + nsGlobalWindowInner* pWindow = Context()->GetOwnerWindow(); Document* document = pWindow ? pWindow->GetExtantDoc() : nullptr; nsContentUtils::ReportToConsole(nsIScriptError::warningFlag, "Web Audio"_ns, document, nsContentUtils::eDOM_PROPERTIES, @@ -228,7 +229,7 @@ void MediaStreamAudioSourceNode::PrincipalChanged( bool subsumes = false; Document* doc = nullptr; - if (nsPIDOMWindowInner* parent = Context()->GetParentObject()) { + if (nsGlobalWindowInner* parent = Context()->GetOwnerWindow()) { doc = parent->GetExtantDoc(); if (doc) { nsIPrincipal* docPrincipal = doc->NodePrincipal(); diff --git a/dom/media/webaudio/MediaStreamTrackAudioSourceNode.cpp b/dom/media/webaudio/MediaStreamTrackAudioSourceNode.cpp index f3948a33ad9b..567b3e9fce3e 100644 --- a/dom/media/webaudio/MediaStreamTrackAudioSourceNode.cpp +++ b/dom/media/webaudio/MediaStreamTrackAudioSourceNode.cpp @@ -12,6 +12,7 @@ #include "mozilla/dom/Document.h" #include "nsContentUtils.h" #include "nsIScriptError.h" +#include "nsGlobalWindowInner.h" namespace mozilla::dom { @@ -50,7 +51,7 @@ MediaStreamTrackAudioSourceNode::Create( if (!aOptions.mMediaStreamTrack->Ended() && aAudioContext.Graph() != aOptions.mMediaStreamTrack->Graph()) { - nsCOMPtr pWindow = aAudioContext.GetParentObject(); + nsGlobalWindowInner* pWindow = aAudioContext.GetOwnerWindow(); Document* document = pWindow ? pWindow->GetExtantDoc() : nullptr; nsContentUtils::ReportToConsole(nsIScriptError::warningFlag, "Web Audio"_ns, document, nsContentUtils::eDOM_PROPERTIES, @@ -146,8 +147,8 @@ void MediaStreamTrackAudioSourceNode::PrincipalChanged( bool subsumes = false; Document* doc = nullptr; - if (nsPIDOMWindowInner* parent = Context()->GetParentObject()) { - doc = parent->GetExtantDoc(); + if (nsGlobalWindowInner* win = Context()->GetOwnerWindow()) { + doc = win->GetExtantDoc(); if (doc) { nsIPrincipal* docPrincipal = doc->NodePrincipal(); nsIPrincipal* trackPrincipal = aMediaStreamTrack->GetPrincipal(); diff --git a/dom/media/webaudio/ScriptProcessorNode.cpp b/dom/media/webaudio/ScriptProcessorNode.cpp index 1e645a2b428c..ec2300e786ea 100644 --- a/dom/media/webaudio/ScriptProcessorNode.cpp +++ b/dom/media/webaudio/ScriptProcessorNode.cpp @@ -11,10 +11,10 @@ #include "AudioNodeEngine.h" #include "AudioNodeTrack.h" #include "AudioProcessingEvent.h" -#include "WebAudioUtils.h" #include "mozilla/dom/ScriptSettings.h" #include "mozilla/Mutex.h" #include "mozilla/PodOperations.h" +#include "nsGlobalWindowInner.h" #include #include "Tracing.h" @@ -400,7 +400,7 @@ class ScriptProcessorNodeEngine final : public AudioNodeEngine { } AutoJSAPI jsapi; - if (NS_WARN_IF(!jsapi.Init(aNode->GetOwner()))) { + if (NS_WARN_IF(!jsapi.Init(aNode->GetOwnerWindow()))) { return; } JSContext* cx = jsapi.cx(); @@ -411,7 +411,7 @@ class ScriptProcessorNodeEngine final : public AudioNodeEngine { if (mInputBuffer) { ErrorResult rv; inputBuffer = AudioBuffer::Create( - context->GetOwner(), inputChannelCount, aNode->BufferSize(), + context->GetOwnerWindow(), inputChannelCount, aNode->BufferSize(), context->SampleRate(), mInputBuffer.forget(), rv); if (rv.Failed()) { rv.SuppressException(); diff --git a/dom/media/webspeech/recognition/OnlineSpeechRecognitionService.cpp b/dom/media/webspeech/recognition/OnlineSpeechRecognitionService.cpp index e68ccc417ecc..021aa567938f 100644 --- a/dom/media/webspeech/recognition/OnlineSpeechRecognitionService.cpp +++ b/dom/media/webspeech/recognition/OnlineSpeechRecognitionService.cpp @@ -5,22 +5,15 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "nsThreadUtils.h" -#include "nsXPCOMCIDInternal.h" #include "OnlineSpeechRecognitionService.h" -#include "nsIFile.h" #include "SpeechGrammar.h" #include "SpeechRecognition.h" #include "SpeechRecognitionAlternative.h" #include "SpeechRecognitionResult.h" #include "SpeechRecognitionResultList.h" -#include "nsIObserverService.h" #include "mozilla/dom/Document.h" #include "mozilla/Preferences.h" #include "mozilla/ScopeExit.h" -#include "mozilla/StaticPrefs_media.h" -#include "mozilla/Services.h" -#include "nsDirectoryServiceDefs.h" -#include "nsDirectoryServiceUtils.h" #include "nsNetUtil.h" #include "nsContentUtils.h" #include "nsIChannel.h" @@ -28,10 +21,9 @@ #include "nsIPrincipal.h" #include "nsIStreamListener.h" #include "nsIUploadChannel2.h" -#include "mozilla/dom/ClientIPCTypes.h" #include "nsStringStream.h" #include "nsIOutputStream.h" -#include "nsStreamUtils.h" +#include "nsGlobalWindowInner.h" #include "OpusTrackEncoder.h" #include "OggWriter.h" #include "nsIClassOfService.h" @@ -316,7 +308,7 @@ void OnlineSpeechRecognitionService::DoSTT() { nsIRequest::LOAD_NORMAL | nsIChannel::LOAD_BYPASS_SERVICE_WORKER; nsContentPolicyType contentPolicy = nsIContentPolicy::TYPE_OTHER; - nsPIDOMWindowInner* window = mRecognition->GetOwner(); + nsGlobalWindowInner* window = mRecognition->GetOwnerWindow(); if (NS_WARN_IF(!window)) { mRecognition->DispatchError( SpeechRecognition::EVENT_RECOGNITIONSERVICE_ERROR, diff --git a/dom/media/webspeech/recognition/SpeechRecognition.cpp b/dom/media/webspeech/recognition/SpeechRecognition.cpp index 44ad5fdd61e9..e06d76bf29af 100644 --- a/dom/media/webspeech/recognition/SpeechRecognition.cpp +++ b/dom/media/webspeech/recognition/SpeechRecognition.cpp @@ -38,6 +38,7 @@ #include "nsPIDOMWindow.h" #include "nsServiceManagerUtils.h" #include "nsQueryObject.h" +#include "nsGlobalWindowInner.h" #include "SpeechTrackListener.h" #include @@ -160,7 +161,7 @@ SpeechRecognition::SpeechRecognition(nsPIDOMWindowInner* aOwnerWindow) mEndpointer(kSAMPLE_RATE), mAudioSamplesPerChunk(mEndpointer.FrameSize()), mSpeechDetectionTimer(NS_NewTimer()), - mSpeechGrammarList(new SpeechGrammarList(GetOwner())), + mSpeechGrammarList(new SpeechGrammarList(GetOwnerGlobal())), mContinuous(false), mInterimResults(false), mMaxAlternatives(1) { @@ -830,7 +831,7 @@ void SpeechRecognition::Start(const Optional>& aStream, } } else { mTrackIsOwned = true; - nsPIDOMWindowInner* win = GetOwner(); + nsPIDOMWindowInner* win = GetOwnerWindow(); if (!win || !win->IsFullyActive()) { aRv.ThrowInvalidStateError("The document is not fully active."); return; @@ -885,7 +886,7 @@ void SpeechRecognition::Start(const Optional>& aStream, } bool SpeechRecognition::SetRecognitionService(ErrorResult& aRv) { - if (!GetOwner()) { + if (!GetOwnerWindow()) { aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR); return false; } @@ -896,7 +897,7 @@ bool SpeechRecognition::SetRecognitionService(ErrorResult& aRv) { if (!mLang.IsEmpty()) { lang = mLang; } else { - nsCOMPtr document = GetOwner()->GetExtantDoc(); + nsCOMPtr document = GetOwnerWindow()->GetExtantDoc(); if (!document) { aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR); return false; @@ -911,7 +912,7 @@ bool SpeechRecognition::SetRecognitionService(ErrorResult& aRv) { element->GetLang(lang); } - auto result = CreateSpeechRecognitionService(GetOwner(), this, lang); + auto result = CreateSpeechRecognitionService(GetOwnerWindow(), this, lang); if (result.isErr()) { switch (result.unwrapErr()) { diff --git a/dom/media/webspeech/synth/SpeechSynthesis.cpp b/dom/media/webspeech/synth/SpeechSynthesis.cpp index f26e36a3f4a7..02fe03232cd1 100644 --- a/dom/media/webspeech/synth/SpeechSynthesis.cpp +++ b/dom/media/webspeech/synth/SpeechSynthesis.cpp @@ -17,6 +17,7 @@ #include "nsSynthVoiceRegistry.h" #include "mozilla/dom/Document.h" #include "nsIDocShell.h" +#include "nsGlobalWindowInner.h" #undef LOG mozilla::LogModule* GetSpeechSynthLog() { @@ -146,7 +147,7 @@ void SpeechSynthesis::AdvanceQueue() { RefPtr utterance = mSpeechQueue.ElementAt(0); nsAutoString docLang; - nsCOMPtr window = GetOwner(); + nsCOMPtr window = GetOwnerWindow(); if (Document* doc = window ? window->GetExtantDoc() : nullptr) { if (Element* elm = doc->GetHtmlElement()) { elm->GetLang(docLang); @@ -223,7 +224,7 @@ void SpeechSynthesis::GetVoices( nsTArray >& aResult) { aResult.Clear(); uint32_t voiceCount = 0; - nsCOMPtr window = GetOwner(); + nsCOMPtr window = GetOwnerWindow(); nsCOMPtr docShell = window ? window->GetDocShell() : nullptr; if (nsContentUtils::ShouldResistFingerprinting(docShell, @@ -297,7 +298,7 @@ SpeechSynthesis::Observe(nsISupports* aSubject, const char* aTopic, } } else if (strcmp(aTopic, "synth-voices-changed") == 0) { LOG(LogLevel::Debug, ("SpeechSynthesis::onvoiceschanged")); - nsCOMPtr window = GetOwner(); + nsCOMPtr window = GetOwnerWindow(); nsCOMPtr docShell = window ? window->GetDocShell() : nullptr; if (!nsContentUtils::ShouldResistFingerprinting( @@ -311,7 +312,7 @@ SpeechSynthesis::Observe(nsISupports* aSubject, const char* aTopic, } else if (strcmp(aTopic, "synth-voices-error") == 0) { NS_WARNING("SpeechSynthesis::Observe: synth-voices-error"); LOG(LogLevel::Debug, ("SpeechSynthesis::onvoiceserror")); - nsCOMPtr window = GetOwner(); + nsCOMPtr window = GetOwnerWindow(); nsCOMPtr obs = services::GetObserverService(); if (obs) { diff --git a/dom/media/webspeech/synth/SpeechSynthesisUtterance.cpp b/dom/media/webspeech/synth/SpeechSynthesisUtterance.cpp index 4d8dcd5c12b5..4c812eeb66da 100644 --- a/dom/media/webspeech/synth/SpeechSynthesisUtterance.cpp +++ b/dom/media/webspeech/synth/SpeechSynthesisUtterance.cpp @@ -46,7 +46,7 @@ JSObject* SpeechSynthesisUtterance::WrapObject( } nsISupports* SpeechSynthesisUtterance::GetParentObject() const { - return GetOwner(); + return GetOwnerGlobal(); } already_AddRefed diff --git a/dom/media/webspeech/synth/nsSpeechTask.cpp b/dom/media/webspeech/synth/nsSpeechTask.cpp index b10217246600..0f637c29c926 100644 --- a/dom/media/webspeech/synth/nsSpeechTask.cpp +++ b/dom/media/webspeech/synth/nsSpeechTask.cpp @@ -11,6 +11,7 @@ #include "nsXULAppAPI.h" #include "SharedBuffer.h" #include "SpeechSynthesis.h" +#include "nsGlobalWindowInner.h" #undef LOG extern mozilla::LogModule* GetSpeechSynthLog(); @@ -335,7 +336,7 @@ void nsSpeechTask::CreateAudioChannelAgent() { } mAudioChannelAgent = new AudioChannelAgent(); - mAudioChannelAgent->InitWithWeakCallback(mUtterance->GetOwner(), this); + mAudioChannelAgent->InitWithWeakCallback(mUtterance->GetOwnerWindow(), this); nsresult rv = mAudioChannelAgent->NotifyStartedPlaying( AudioChannelService::AudibleState::eAudible); diff --git a/dom/media/webspeech/synth/nsSynthVoiceRegistry.cpp b/dom/media/webspeech/synth/nsSynthVoiceRegistry.cpp index 452c1744369e..e5a1353d6b19 100644 --- a/dom/media/webspeech/synth/nsSynthVoiceRegistry.cpp +++ b/dom/media/webspeech/synth/nsSynthVoiceRegistry.cpp @@ -640,7 +640,7 @@ already_AddRefed nsSynthVoiceRegistry::SpeakUtterance( float volume = aUtterance.Volume(); RefPtr service = AudioChannelService::GetOrCreate(); if (service) { - if (nsCOMPtr topWindow = aUtterance.GetOwner()) { + if (nsCOMPtr topWindow = aUtterance.GetOwnerWindow()) { // TODO : use audio channel agent, open new bug to fix it. AudioPlaybackConfig config = service->GetMediaConfig(topWindow->GetOuterWindow()); diff --git a/dom/media/webvtt/TextTrack.cpp b/dom/media/webvtt/TextTrack.cpp index 7a5b398d2d65..bb0d32b3fd62 100644 --- a/dom/media/webvtt/TextTrack.cpp +++ b/dom/media/webvtt/TextTrack.cpp @@ -81,7 +81,7 @@ TextTrack::TextTrack(nsPIDOMWindowInner* aOwnerWindow, TextTrack::~TextTrack() = default; void TextTrack::SetDefaultSettings() { - nsPIDOMWindowInner* ownerWindow = GetOwner(); + nsPIDOMWindowInner* ownerWindow = GetOwnerWindow(); mCueList = new TextTrackCueList(ownerWindow); mActiveCueList = new TextTrackCueList(ownerWindow); mCuePos = 0; @@ -246,14 +246,15 @@ void TextTrack::GetLanguage(nsAString& aLanguage) const { } void TextTrack::DispatchAsyncTrustedEvent(const nsString& aEventName) { - nsPIDOMWindowInner* win = GetOwner(); + nsGlobalWindowInner* win = GetOwnerWindow(); if (!win) { return; } - RefPtr self = this; - nsGlobalWindowInner::Cast(win)->Dispatch(NS_NewRunnableFunction( - "dom::TextTrack::DispatchAsyncTrustedEvent", - [self, aEventName]() { self->DispatchTrustedEvent(aEventName); })); + win->Dispatch( + NS_NewRunnableFunction("dom::TextTrack::DispatchAsyncTrustedEvent", + [self = RefPtr{this}, aEventName]() { + self->DispatchTrustedEvent(aEventName); + })); } bool TextTrack::IsLoaded() { diff --git a/dom/media/webvtt/TextTrackCue.cpp b/dom/media/webvtt/TextTrackCue.cpp index 7364d6083bc6..9eb1829fc859 100644 --- a/dom/media/webvtt/TextTrackCue.cpp +++ b/dom/media/webvtt/TextTrackCue.cpp @@ -12,6 +12,7 @@ #include "nsComponentManagerUtils.h" #include "mozilla/ClearOnShutdown.h" #include "mozilla/intl/Bidi.h" +#include "nsGlobalWindowInner.h" extern mozilla::LazyLogModule gTextTrackLog; @@ -94,7 +95,7 @@ TextTrackCue::~TextTrackCue() = default; * keep getting it from our window. */ nsresult TextTrackCue::StashDocument() { - nsPIDOMWindowInner* window = GetOwner(); + nsPIDOMWindowInner* window = GetOwnerWindow(); if (!window) { return NS_ERROR_NO_INTERFACE; } diff --git a/dom/media/webvtt/TextTrackList.cpp b/dom/media/webvtt/TextTrackList.cpp index 5d51ff48fecd..9edccdd7de85 100644 --- a/dom/media/webvtt/TextTrackList.cpp +++ b/dom/media/webvtt/TextTrackList.cpp @@ -69,7 +69,7 @@ already_AddRefed TextTrackList::AddTextTrack( TextTrackMode aMode, TextTrackReadyState aReadyState, TextTrackSource aTextTrackSource, const CompareTextTracks& aCompareTT) { RefPtr track = - new TextTrack(GetOwner(), this, aKind, aLabel, aLanguage, aMode, + new TextTrack(GetOwnerWindow(), this, aKind, aLabel, aLanguage, aMode, aReadyState, aTextTrackSource); AddTextTrack(track, aCompareTT); return track.forget(); @@ -121,7 +121,7 @@ nsresult TextTrackList::DispatchTrackEvent(Event* aEvent) { void TextTrackList::CreateAndDispatchChangeEvent() { MOZ_ASSERT(NS_IsMainThread()); - nsPIDOMWindowInner* win = GetOwner(); + nsPIDOMWindowInner* win = GetOwnerWindow(); if (!win) { return; } diff --git a/dom/messagechannel/MessagePort.cpp b/dom/messagechannel/MessagePort.cpp index 5c073114277d..100b5f56a08a 100644 --- a/dom/messagechannel/MessagePort.cpp +++ b/dom/messagechannel/MessagePort.cpp @@ -119,10 +119,8 @@ class PostMessageRunnable final : public CancelableRunnable { } // Create the event - nsCOMPtr eventTarget = - do_QueryInterface(mPort->GetOwner()); RefPtr event = - new MessageEvent(eventTarget, nullptr, nullptr); + new MessageEvent(mPort->GetOwnerWindow(), nullptr, nullptr); Sequence> ports; if (!mData->TakeTransferredPortsAsSequence(ports)) { @@ -813,7 +811,7 @@ void MessagePort::RemoveDocFromBFCache() { return; } - if (nsPIDOMWindowInner* window = GetOwner()) { + if (nsPIDOMWindowInner* window = GetOwnerWindow()) { window->RemoveFromBFCacheSync(); } } diff --git a/dom/midi/MIDIAccess.cpp b/dom/midi/MIDIAccess.cpp index fa8ae514c29b..6f629a7644e5 100644 --- a/dom/midi/MIDIAccess.cpp +++ b/dom/midi/MIDIAccess.cpp @@ -21,6 +21,7 @@ #include "mozilla/dom/PContent.h" #include "mozilla/dom/Document.h" #include "nsPIDOMWindow.h" +#include "nsGlobalWindowInner.h" #include "nsContentPermissionHelper.h" #include "nsISupportsImpl.h" // for MOZ_COUNT_CTOR, MOZ_COUNT_DTOR #include "ipc/IPCMessageUtils.h" @@ -150,7 +151,7 @@ void MIDIAccess::MaybeCreateMIDIPort(const MIDIPortInfo& aInfo, // We already have the port in our map. return; } - port = MIDIInput::Create(GetOwner(), this, aInfo, mSysexEnabled); + port = MIDIInput::Create(GetOwnerWindow(), this, aInfo, mSysexEnabled); if (NS_WARN_IF(!port)) { LOG("Couldn't create input port"); aRv.Throw(NS_ERROR_FAILURE); @@ -169,7 +170,7 @@ void MIDIAccess::MaybeCreateMIDIPort(const MIDIPortInfo& aInfo, // We already have the port in our map. return; } - port = MIDIOutput::Create(GetOwner(), this, aInfo, mSysexEnabled); + port = MIDIOutput::Create(GetOwnerWindow(), this, aInfo, mSysexEnabled); if (NS_WARN_IF(!port)) { LOG("Couldn't create output port"); aRv.Throw(NS_ERROR_FAILURE); @@ -205,7 +206,7 @@ void MIDIAccess::MaybeCreateMIDIPort(const MIDIPortInfo& aInfo, // request removal from MIDIAccess's maps. void MIDIAccess::Notify(const MIDIPortList& aEvent) { LOG("MIDIAcess::Notify"); - if (!GetOwner()) { + if (!GetOwnerWindow()) { // Do nothing if we've already been disconnected from the document. return; } diff --git a/dom/midi/MIDIInput.cpp b/dom/midi/MIDIInput.cpp index b9202ac57805..fa2ac7a78f73 100644 --- a/dom/midi/MIDIInput.cpp +++ b/dom/midi/MIDIInput.cpp @@ -10,6 +10,7 @@ #include "mozilla/dom/MIDIInputBinding.h" #include "mozilla/dom/MIDIMessageEvent.h" #include "mozilla/dom/MIDIMessageEventBinding.h" +#include "nsGlobalWindowInner.h" #include "MIDILog.h" @@ -38,11 +39,11 @@ JSObject* MIDIInput::WrapObject(JSContext* aCx, } void MIDIInput::Receive(const nsTArray& aMsgs) { - if (!GetOwner()) { + if (!GetOwnerWindow()) { return; // Ignore messages once we've been disconnected from the owner } - nsCOMPtr doc = GetOwner()->GetDoc(); + nsCOMPtr doc = GetOwnerWindow()->GetDoc(); if (!doc) { NS_WARNING("No document available to send MIDIMessageEvent to!"); return; diff --git a/dom/midi/MIDIOutput.cpp b/dom/midi/MIDIOutput.cpp index 3cdd7d308d5a..ff48ab0510b2 100644 --- a/dom/midi/MIDIOutput.cpp +++ b/dom/midi/MIDIOutput.cpp @@ -14,9 +14,9 @@ #include "mozilla/TimeStamp.h" #include "mozilla/dom/Document.h" #include "mozilla/dom/Performance.h" +#include "nsGlobalWindowInner.h" -using namespace mozilla; -using namespace mozilla::dom; +namespace mozilla::dom { MIDIOutput::MIDIOutput(nsPIDOMWindowInner* aWindow) : MIDIPort(aWindow) {} @@ -54,13 +54,13 @@ void MIDIOutput::Send(const Sequence& aData, // message ASAP. TimeStamp timestamp; if (aTimestamp.WasPassed() && aTimestamp.Value() != 0) { - nsCOMPtr doc = GetOwner()->GetDoc(); + nsCOMPtr doc = GetOwnerWindow()->GetDoc(); if (!doc) { aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR); return; } TimeDuration ts_diff = TimeDuration::FromMilliseconds(aTimestamp.Value()); - timestamp = GetOwner() + timestamp = GetOwnerWindow() ->GetPerformance() ->GetDOMTiming() ->GetNavigationStartTimeStamp() + @@ -100,3 +100,5 @@ void MIDIOutput::Clear() { } Port()->SendClear(); } + +} // namespace mozilla::dom diff --git a/dom/midi/MIDIPort.cpp b/dom/midi/MIDIPort.cpp index 94d7280c73d4..c7f26a520cc3 100644 --- a/dom/midi/MIDIPort.cpp +++ b/dom/midi/MIDIPort.cpp @@ -41,8 +41,7 @@ MIDIPort::MIDIPort(nsPIDOMWindowInner* aWindow) mKeepAlive(false) { MOZ_ASSERT(aWindow); - Document* aDoc = GetOwner()->GetExtantDoc(); - if (aDoc) { + if (Document* aDoc = aWindow->GetExtantDoc()) { aDoc->DisallowBFCaching(); } } @@ -158,13 +157,10 @@ bool MIDIPort::SysexEnabled() const { already_AddRefed MIDIPort::Open(ErrorResult& aError) { LOG("MIDIPort::Open"); MOZ_ASSERT(Port()); - RefPtr p; if (mOpeningPromise) { - p = mOpeningPromise; - return p.forget(); + return do_AddRef(mOpeningPromise); } - nsCOMPtr go = do_QueryInterface(GetOwner()); - p = Promise::Create(go, aError); + RefPtr p = Promise::Create(GetOwnerGlobal(), aError); if (aError.Failed()) { return nullptr; } @@ -176,13 +172,10 @@ already_AddRefed MIDIPort::Open(ErrorResult& aError) { already_AddRefed MIDIPort::Close(ErrorResult& aError) { LOG("MIDIPort::Close"); MOZ_ASSERT(Port()); - RefPtr p; if (mClosingPromise) { - p = mClosingPromise; - return p.forget(); + return do_AddRef(mClosingPromise); } - nsCOMPtr go = do_QueryInterface(GetOwner()); - p = Promise::Create(go, aError); + RefPtr p = Promise::Create(GetOwnerGlobal(), aError); if (aError.Failed()) { return nullptr; } @@ -199,7 +192,7 @@ void MIDIPort::Notify(const void_t& aVoid) { } void MIDIPort::FireStateChangeEvent() { - if (!GetOwner()) { + if (!GetOwnerWindow()) { return; // Ignore changes once we've been disconnected from the owner } diff --git a/dom/midi/MIDIPort.h b/dom/midi/MIDIPort.h index 76e039ab6556..a9966c2afb20 100644 --- a/dom/midi/MIDIPort.h +++ b/dom/midi/MIDIPort.h @@ -41,7 +41,7 @@ class MIDIPort : public DOMEventTargetHelper, virtual ~MIDIPort(); public: - nsPIDOMWindowInner* GetParentObject() const { return GetOwner(); } + nsIGlobalObject* GetParentObject() const { return GetOwnerGlobal(); } // Getters void GetId(nsString& aRetVal) const; diff --git a/dom/network/TCPServerSocket.cpp b/dom/network/TCPServerSocket.cpp index b39cad0e1464..da889d47b260 100644 --- a/dom/network/TCPServerSocket.cpp +++ b/dom/network/TCPServerSocket.cpp @@ -14,6 +14,8 @@ #include "TCPServerSocket.h" #include "TCPSocket.h" #include "nsComponentManagerUtils.h" +#include "nsGlobalWindowInner.h" + using namespace mozilla::dom; @@ -139,7 +141,7 @@ TCPServerSocket::OnSocketAccepted(nsIServerSocket* aServer, NS_IMETHODIMP TCPServerSocket::OnStopListening(nsIServerSocket* aServer, nsresult aStatus) { if (aStatus != NS_BINDING_ABORTED) { - RefPtr event = new Event(GetOwner()); + RefPtr event = new Event(GetOwnerWindow()); event->InitEvent(u"error"_ns, false, false); event->SetTrusted(true); DispatchEvent(*event); diff --git a/dom/network/TCPServerSocket.h b/dom/network/TCPServerSocket.h index 550cba683eb2..8a3f2e80fc94 100644 --- a/dom/network/TCPServerSocket.h +++ b/dom/network/TCPServerSocket.h @@ -32,10 +32,8 @@ class TCPServerSocket final : public DOMEventTargetHelper, DOMEventTargetHelper) NS_DECL_NSISERVERSOCKETLISTENER - nsPIDOMWindowInner* GetParentObject() const { return GetOwner(); } - - virtual JSObject* WrapObject(JSContext* aCx, - JS::Handle aGivenProto) override; + nsIGlobalObject* GetParentObject() const { return GetOwnerGlobal(); } + JSObject* WrapObject(JSContext*, JS::Handle aGivenProto) override; nsresult Init(); diff --git a/dom/network/UDPSocket.cpp b/dom/network/UDPSocket.cpp index 7dfcae36526f..4fe771ac1d3d 100644 --- a/dom/network/UDPSocket.cpp +++ b/dom/network/UDPSocket.cpp @@ -374,16 +374,15 @@ bool UDPSocket::Send(const StringOrBlobOrArrayBufferOrArrayBufferView& aData, nsresult UDPSocket::InitLocal(const nsAString& aLocalAddress, const uint16_t& aLocalPort) { nsresult rv; - nsCOMPtr sock = do_CreateInstance("@mozilla.org/network/udp-socket;1", &rv); if (NS_FAILED(rv)) { return rv; } - nsCOMPtr global = do_QueryInterface(GetOwner(), &rv); - if (NS_FAILED(rv)) { - return rv; + nsCOMPtr global = GetOwnerGlobal(); + if (!global) { + return NS_ERROR_FAILURE; } nsCOMPtr principal = global->PrincipalOrNull(); @@ -458,25 +457,23 @@ nsresult UDPSocket::InitLocal(const nsAString& aLocalAddress, nsresult UDPSocket::InitRemote(const nsAString& aLocalAddress, const uint16_t& aLocalPort) { - nsresult rv; - RefPtr sock = new UDPSocketChild(); mListenerProxy = new ListenerProxy(this); - nsCOMPtr obj = do_QueryInterface(GetOwner(), &rv); - if (NS_FAILED(rv)) { - return rv; + nsCOMPtr global = GetOwnerGlobal(); + if (!global) { + return NS_ERROR_FAILURE; } - nsCOMPtr principal = obj->PrincipalOrNull(); + nsCOMPtr principal = global->PrincipalOrNull(); if (!principal) { return NS_ERROR_FAILURE; } - rv = sock->Bind(mListenerProxy, principal, - NS_ConvertUTF16toUTF8(aLocalAddress), aLocalPort, - mAddressReuse, mLoopback, 0, 0); + nsresult rv = sock->Bind(mListenerProxy, principal, + NS_ConvertUTF16toUTF8(aLocalAddress), aLocalPort, + mAddressReuse, mLoopback, 0, 0); if (NS_FAILED(rv)) { return rv; @@ -497,9 +494,9 @@ nsresult UDPSocket::Init(const nsString& aLocalAddress, mAddressReuse = aAddressReuse; mLoopback = aLoopback; - ErrorResult rv; - nsCOMPtr global = do_QueryInterface(GetOwner()); + nsCOMPtr global = GetOwnerGlobal(); + ErrorResult rv; mOpened = Promise::Create(global, rv); if (NS_WARN_IF(rv.Failed())) { return rv.StealNSResult(); @@ -571,7 +568,7 @@ nsresult UDPSocket::DispatchReceivedData(const nsACString& aRemoteAddress, const nsTArray& aData) { AutoJSAPI jsapi; - if (NS_WARN_IF(!jsapi.Init(GetOwner()))) { + if (NS_WARN_IF(!jsapi.Init(GetOwnerWindow()))) { return NS_ERROR_FAILURE; } diff --git a/dom/network/UDPSocket.h b/dom/network/UDPSocket.h index 5453fe54481a..5083ef08e9d7 100644 --- a/dom/network/UDPSocket.h +++ b/dom/network/UDPSocket.h @@ -49,7 +49,7 @@ class UDPSocket final : public DOMEventTargetHelper, NS_DECL_NSIUDPSOCKETINTERNAL public: - nsPIDOMWindowInner* GetParentObject() const { return GetOwner(); } + nsIGlobalObject* GetParentObject() const { return GetOwnerGlobal(); } virtual JSObject* WrapObject(JSContext* aCx, JS::Handle aGivenProto) override; diff --git a/dom/notification/Notification.cpp b/dom/notification/Notification.cpp index a356faa00acd..a7bd20bd2760 100644 --- a/dom/notification/Notification.cpp +++ b/dom/notification/Notification.cpp @@ -984,11 +984,10 @@ nsIPrincipal* Notification::GetPrincipal() { AssertIsOnMainThread(); if (mWorkerPrivate) { return mWorkerPrivate->GetPrincipal(); - } else { - nsCOMPtr sop = do_QueryInterface(GetOwner()); - NS_ENSURE_TRUE(sop, nullptr); - return sop->GetPrincipal(); } + nsGlobalWindowInner* win = GetOwnerWindow(); + NS_ENSURE_TRUE(win, nullptr); + return win->GetPrincipal(); } class WorkerNotificationObserver final : public MainThreadNotificationObserver { @@ -1163,7 +1162,7 @@ MainThreadNotificationObserver::Observe(nsISupports* aSubject, Notification* notification = mNotificationRef->GetNotification(); MOZ_ASSERT(notification); if (!strcmp("alertclickcallback", aTopic)) { - nsCOMPtr window = notification->GetOwner(); + nsCOMPtr window = notification->GetOwnerWindow(); if (NS_WARN_IF(!window || !window->IsCurrentInnerWindow())) { // Window has been closed, this observer is not valid anymore return NS_ERROR_FAILURE; @@ -1320,8 +1319,8 @@ bool Notification::IsInPrivateBrowsing() { if (mWorkerPrivate) { doc = mWorkerPrivate->GetDocument(); - } else if (GetOwner()) { - doc = GetOwner()->GetExtantDoc(); + } else if (nsGlobalWindowInner* win = GetOwnerWindow()) { + doc = win->GetExtantDoc(); } if (doc) { @@ -1374,7 +1373,7 @@ void Notification::ShowInternal() { if (mWorkerPrivate) { permission = GetPermissionInternal(mWorkerPrivate->GetPrincipal(), result); } else { - permission = GetPermissionInternal(GetOwner(), result); + permission = GetPermissionInternal(GetOwnerWindow(), result); } // We rely on GetPermissionInternal returning Denied on all failure codepaths. MOZ_ASSERT_IF(result.Failed(), permission == NotificationPermission::Denied); @@ -2344,11 +2343,8 @@ Notification::Observe(nsISupports* aSubject, const char* aTopic, if (!strcmp(aTopic, DOM_WINDOW_DESTROYED_TOPIC) || !strcmp(aTopic, DOM_WINDOW_FROZEN_TOPIC)) { - nsCOMPtr window = GetOwner(); - if (SameCOMIdentity(aSubject, window)) { - nsCOMPtr obs = - mozilla::services::GetObserverService(); - if (obs) { + if (SameCOMIdentity(aSubject, ToSupports(GetOwnerWindow()))) { + if (nsCOMPtr obs = services::GetObserverService()) { obs->RemoveObserver(this, DOM_WINDOW_DESTROYED_TOPIC); obs->RemoveObserver(this, DOM_WINDOW_FROZEN_TOPIC); } diff --git a/dom/notification/Notification.h b/dom/notification/Notification.h index 65ab013959f7..324031494620 100644 --- a/dom/notification/Notification.h +++ b/dom/notification/Notification.h @@ -177,10 +177,9 @@ class Notification : public DOMEventTargetHelper, void Close(); - nsPIDOMWindowInner* GetParentObject() { return GetOwner(); } + nsIGlobalObject* GetParentObject() const { return GetOwnerGlobal(); } - virtual JSObject* WrapObject(JSContext* aCx, - JS::Handle aGivenProto) override; + JSObject* WrapObject(JSContext*, JS::Handle aGivenProto) override; bool RequireInteraction() const; diff --git a/dom/payments/PaymentRequest.cpp b/dom/payments/PaymentRequest.cpp index 00f6345f0b37..6deee1109d10 100644 --- a/dom/payments/PaymentRequest.cpp +++ b/dom/payments/PaymentRequest.cpp @@ -26,6 +26,7 @@ #include "nsIURLParser.h" #include "nsNetCID.h" #include "nsServiceManagerUtils.h" +#include "nsGlobalWindowInner.h" #include "mozilla/dom/MerchantValidationEvent.h" #include "PaymentResponse.h" @@ -808,8 +809,8 @@ void PaymentRequest::RespondShowPayment(const nsAString& aMethodName, aDetails, aPayerName, aPayerEmail, aPayerPhone); } else if (mAcceptPromise) { RefPtr paymentResponse = new PaymentResponse( - GetOwner(), this, mId, aMethodName, mShippingOption, mShippingAddress, - aDetails, aPayerName, aPayerEmail, aPayerPhone); + GetOwnerWindow(), this, mId, aMethodName, mShippingOption, + mShippingAddress, aDetails, aPayerName, aPayerEmail, aPayerPhone); mResponse = paymentResponse; mAcceptPromise->MaybeResolve(paymentResponse); } else { @@ -1063,10 +1064,10 @@ nsresult PaymentRequest::UpdateShippingAddress( const nsAString& aPhone) { nsTArray emptyArray; mShippingAddress = new PaymentAddress( - GetOwner(), aCountry, emptyArray, aRegion, aRegionCode, aCity, + GetOwnerWindow(), aCountry, emptyArray, aRegion, aRegionCode, aCity, aDependentLocality, aPostalCode, aSortingCode, u""_ns, u""_ns, u""_ns); mFullShippingAddress = - new PaymentAddress(GetOwner(), aCountry, aAddressLine, aRegion, + new PaymentAddress(GetOwnerWindow(), aCountry, aAddressLine, aRegion, aRegionCode, aCity, aDependentLocality, aPostalCode, aSortingCode, aOrganization, aRecipient, aPhone); // Fire shippingaddresschange event @@ -1190,7 +1191,7 @@ bool PaymentRequest::InFullyActiveDocument() { } void PaymentRequest::RegisterActivityObserver() { - if (nsPIDOMWindowInner* window = GetOwner()) { + if (nsPIDOMWindowInner* window = GetOwnerWindow()) { mDocument = window->GetExtantDoc(); if (mDocument) { mDocument->RegisterActivityObserver( @@ -1207,7 +1208,7 @@ void PaymentRequest::UnregisterActivityObserver() { } void PaymentRequest::NotifyOwnerDocumentActivityChanged() { - nsPIDOMWindowInner* window = GetOwner(); + nsPIDOMWindowInner* window = GetOwnerWindow(); NS_ENSURE_TRUE_VOID(window); Document* doc = window->GetExtantDoc(); NS_ENSURE_TRUE_VOID(doc); diff --git a/dom/payments/PaymentRequestManager.cpp b/dom/payments/PaymentRequestManager.cpp index 1f21ff1bab3e..be7f84a70794 100644 --- a/dom/payments/PaymentRequestManager.cpp +++ b/dom/payments/PaymentRequestManager.cpp @@ -351,7 +351,7 @@ PaymentRequestChild* PaymentRequestManager::GetPaymentChild( return child; } - nsPIDOMWindowInner* win = aRequest->GetOwner(); + nsPIDOMWindowInner* win = aRequest->GetOwnerWindow(); NS_ENSURE_TRUE(win, nullptr); BrowserChild* browserChild = BrowserChild::GetFrom(win->GetDocShell()); NS_ENSURE_TRUE(browserChild, nullptr); diff --git a/dom/payments/PaymentResponse.cpp b/dom/payments/PaymentResponse.cpp index 2ea393455c46..6813b28788ec 100644 --- a/dom/payments/PaymentResponse.cpp +++ b/dom/payments/PaymentResponse.cpp @@ -13,6 +13,7 @@ #include "PaymentRequest.h" #include "PaymentRequestManager.h" #include "PaymentRequestUtils.h" +#include "nsGlobalWindowInner.h" #include "mozilla/EventStateManager.h" namespace mozilla::dom { @@ -122,7 +123,7 @@ void PaymentResponse::GetDetails(JSContext* aCx, !rawData.billingAddress.recipient.IsEmpty() || !rawData.billingAddress.phone.IsEmpty()) { basicCardResponse.mBillingAddress = new PaymentAddress( - GetOwner(), rawData.billingAddress.country, + GetOwnerWindow(), rawData.billingAddress.country, rawData.billingAddress.addressLine, rawData.billingAddress.region, rawData.billingAddress.regionCode, rawData.billingAddress.city, rawData.billingAddress.dependentLocality, @@ -198,13 +199,7 @@ already_AddRefed PaymentResponse::Complete(PaymentComplete result, return nullptr; } - if (NS_WARN_IF(!GetOwner())) { - aRv.ThrowAbortError("Global object should exist"); - return nullptr; - } - - nsIGlobalObject* global = GetOwner()->AsGlobal(); - RefPtr promise = Promise::Create(global, aRv); + RefPtr promise = Promise::Create(GetOwnerGlobal(), aRv); if (aRv.Failed()) { return nullptr; } @@ -229,8 +224,7 @@ already_AddRefed PaymentResponse::Retry( return nullptr; } - nsIGlobalObject* global = GetOwner()->AsGlobal(); - RefPtr promise = Promise::Create(global, aRv); + RefPtr promise = Promise::Create(GetOwnerGlobal(), aRv); if (aRv.Failed()) { return nullptr; } @@ -292,7 +286,7 @@ void PaymentResponse::RespondRetry(const nsAString& aMethodName, mPayerEmail = aPayerEmail; mPayerPhone = aPayerPhone; - if (NS_WARN_IF(!GetOwner())) { + if (NS_WARN_IF(!GetOwnerGlobal())) { return; } diff --git a/dom/performance/Performance.cpp b/dom/performance/Performance.cpp index 30df8f3c16d2..7df54f8e0e52 100644 --- a/dom/performance/Performance.cpp +++ b/dom/performance/Performance.cpp @@ -346,8 +346,8 @@ already_AddRefed Performance::Mark( if (profiler_thread_is_being_profiled_for_markers()) { Maybe innerWindowId; - if (GetOwner()) { - innerWindowId = Some(GetOwner()->WindowID()); + if (nsGlobalWindowInner* owner = GetOwnerWindow()) { + innerWindowId = Some(owner->WindowID()); } TimeStamp startTimeStamp = CreationTimeStamp() + @@ -800,8 +800,8 @@ already_AddRefed Performance::Measure( } Maybe innerWindowId; - if (GetOwner()) { - innerWindowId = Some(GetOwner()->WindowID()); + if (nsGlobalWindowInner* owner = GetOwnerWindow()) { + innerWindowId = Some(owner->WindowID()); } profiler_add_marker("UserTiming", geckoprofiler::category::DOM, {MarkerTiming::Interval(startTimeStamp, endTimeStamp), @@ -842,10 +842,8 @@ void Performance::TimingNotification(PerformanceEntry* aEntry, RefPtr perfEntryEvent = PerformanceEntryEvent::Constructor(this, u"performanceentry"_ns, init); - - nsCOMPtr et = do_QueryInterface(GetOwner()); - if (et) { - et->DispatchEvent(*perfEntryEvent); + if (RefPtr owner = GetOwnerWindow()) { + owner->DispatchEvent(*perfEntryEvent); } } diff --git a/dom/performance/PerformanceMainThread.cpp b/dom/performance/PerformanceMainThread.cpp index d00498d92be2..f6dc5273ea79 100644 --- a/dom/performance/PerformanceMainThread.cpp +++ b/dom/performance/PerformanceMainThread.cpp @@ -21,12 +21,11 @@ #include "mozilla/dom/PerformanceResourceTiming.h" #include "mozilla/dom/PerformanceTiming.h" #include "mozilla/StaticPrefs_dom.h" -#include "mozilla/StaticPrefs_privacy.h" #include "mozilla/PresShell.h" #include "nsIChannel.h" #include "nsIHttpChannel.h" #include "nsIDocShell.h" -#include "nsTextFrame.h" +#include "nsGlobalWindowInner.h" #include "nsContainerFrame.h" namespace mozilla::dom { @@ -110,7 +109,7 @@ PerformanceMainThread::PerformanceMainThread(nsPIDOMWindowInner* aWindow, CreateNavigationTimingEntry(); if (StaticPrefs::dom_enable_largest_contentful_paint()) { - nsCOMPtr owner = GetOwner(); + nsGlobalWindowInner* owner = GetOwnerWindow(); MarkerInnerWindowId innerWindowID = owner ? MarkerInnerWindowId(owner->WindowID()) : MarkerInnerWindowId::NoId(); @@ -418,7 +417,7 @@ void PerformanceMainThread::InsertUserEntry(PerformanceEntry* aEntry) { if (StaticPrefs::dom_performance_enable_user_timing_logging() || StaticPrefs::dom_performance_enable_notify_performance_timing()) { nsresult rv = NS_ERROR_FAILURE; - nsCOMPtr owner = GetOwner(); + nsGlobalWindowInner* owner = GetOwnerWindow(); if (owner && owner->GetDocumentURI()) { rv = owner->GetDocumentURI()->GetHost(uri); } diff --git a/dom/permission/PermissionStatus.cpp b/dom/permission/PermissionStatus.cpp index fd3d2ebcacad..985958235e95 100644 --- a/dom/permission/PermissionStatus.cpp +++ b/dom/permission/PermissionStatus.cpp @@ -13,6 +13,7 @@ #include "nsIPermissionManager.h" #include "PermissionObserver.h" #include "PermissionUtils.h" +#include "nsGlobalWindowInner.h" namespace mozilla::dom { @@ -70,7 +71,7 @@ RefPtr PermissionStatus::UpdateState() { // does not exactly match what the spec has. (Not passing "permission key" for // example) - nsCOMPtr window = GetOwner(); + RefPtr window = GetOwnerWindow(); if (NS_WARN_IF(!window)) { return SimplePromise::CreateAndReject(NS_ERROR_FAILURE, __func__); } @@ -100,7 +101,7 @@ RefPtr PermissionStatus::UpdateState() { bool PermissionStatus::MaybeUpdatedBy(nsIPermission* aPermission) const { NS_ENSURE_TRUE(aPermission, false); - nsCOMPtr window = GetOwner(); + RefPtr window = GetOwnerWindow(); if (NS_WARN_IF(!window)) { return false; } diff --git a/dom/permission/StorageAccessPermissionStatus.cpp b/dom/permission/StorageAccessPermissionStatus.cpp index fc39e1440eac..23dcddd86057 100644 --- a/dom/permission/StorageAccessPermissionStatus.cpp +++ b/dom/permission/StorageAccessPermissionStatus.cpp @@ -12,6 +12,7 @@ #include "mozilla/dom/FeaturePolicyUtils.h" #include "mozilla/dom/PermissionStatus.h" #include "mozilla/dom/PermissionStatusBinding.h" +#include "nsGlobalWindowInner.h" #include "nsIPermissionManager.h" namespace mozilla::dom { @@ -22,7 +23,7 @@ StorageAccessPermissionStatus::StorageAccessPermissionStatus( RefPtr StorageAccessPermissionStatus::UpdateState() { - nsCOMPtr window = GetOwner(); + nsGlobalWindowInner* window = GetOwnerWindow(); if (NS_WARN_IF(!window)) { return SimplePromise::CreateAndReject(NS_ERROR_FAILURE, __func__); } @@ -63,7 +64,7 @@ bool StorageAccessPermissionStatus::MaybeUpdatedBy( bool StorageAccessPermissionStatus::MaybeUpdatedByNotifyOnly( nsPIDOMWindowInner* aInnerWindow) const { - nsPIDOMWindowInner* owner = GetOwner(); + nsPIDOMWindowInner* owner = GetOwnerWindow(); NS_ENSURE_TRUE(owner, false); NS_ENSURE_TRUE(aInnerWindow, false); return owner->WindowID() == aInnerWindow->WindowID(); diff --git a/dom/serviceworkers/ServiceWorker.cpp b/dom/serviceworkers/ServiceWorker.cpp index c554124fac75..0b265ee890a7 100644 --- a/dom/serviceworkers/ServiceWorker.cpp +++ b/dom/serviceworkers/ServiceWorker.cpp @@ -181,7 +181,7 @@ void ServiceWorker::PostMessage(JSContext* aCx, JS::Handle aMessage, return; } - nsPIDOMWindowInner* window = GetOwner(); + nsPIDOMWindowInner* window = GetOwnerWindow(); if (NS_WARN_IF(!window || !window->GetExtantDoc())) { aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR); return; diff --git a/dom/serviceworkers/ServiceWorkerContainer.cpp b/dom/serviceworkers/ServiceWorkerContainer.cpp index 1a7b5bbed6ef..a450e86e3ef6 100644 --- a/dom/serviceworkers/ServiceWorkerContainer.cpp +++ b/dom/serviceworkers/ServiceWorkerContainer.cpp @@ -16,9 +16,9 @@ #include "nsNetUtil.h" #include "nsPIDOMWindow.h" #include "mozilla/Components.h" -#include "mozilla/StaticPrefs_dom.h" #include "nsCycleCollectionParticipant.h" +#include "nsGlobalWindowInner.h" #include "nsServiceManagerUtils.h" #include "mozilla/LoadInfo.h" #include "mozilla/SchedulerGroup.h" @@ -678,7 +678,7 @@ void ServiceWorkerContainer::GetScopeForUrl(const nsAString& aUrl, return; } - nsCOMPtr window = GetOwner(); + nsCOMPtr window = GetOwnerWindow(); if (NS_WARN_IF(!window)) { aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR); return; @@ -707,7 +707,7 @@ nsIGlobalObject* ServiceWorkerContainer::GetGlobalIfValid( // not exposed on worker globals yet. The main thing we need // to fix here to support that is the storage access check via // the nsIGlobalObject. - nsPIDOMWindowInner* window = GetOwner(); + nsGlobalWindowInner* window = GetOwnerWindow(); if (NS_WARN_IF(!window)) { aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR); return nullptr; @@ -753,10 +753,7 @@ void ServiceWorkerContainer::EnqueueReceivedMessageDispatch( template void ServiceWorkerContainer::RunWithJSContext(F&& aCallable) { - nsCOMPtr globalObject; - if (nsPIDOMWindowInner* const window = GetOwner()) { - globalObject = do_QueryInterface(window); - } + nsCOMPtr globalObject = GetOwnerGlobal(); // If AutoJSAPI::Init() fails then either global is nullptr or not // in a usable state. diff --git a/dom/vr/VRDisplay.cpp b/dom/vr/VRDisplay.cpp index 4fe272e33851..bc2e3c89eda1 100644 --- a/dom/vr/VRDisplay.cpp +++ b/dom/vr/VRDisplay.cpp @@ -25,8 +25,8 @@ #include "VRManagerChild.h" #include "VRDisplayPresentation.h" #include "nsIObserverService.h" -#include "nsIFrame.h" #include "nsISupportsPrimitives.h" +#include "nsGlobalWindowInner.h" using namespace mozilla::gfx; @@ -507,7 +507,7 @@ VRDisplay::Observe(nsISupports* aSubject, const char* aTopic, nsresult rv = wrapper->GetData(&innerID); NS_ENSURE_SUCCESS(rv, rv); - if (!GetOwner() || GetOwner()->WindowID() == innerID) { + if (!GetOwnerWindow() || GetOwnerWindow()->WindowID() == innerID) { Shutdown(); } diff --git a/dom/vr/VRServiceTest.cpp b/dom/vr/VRServiceTest.cpp index 4e7691638d36..716c1b43a340 100644 --- a/dom/vr/VRServiceTest.cpp +++ b/dom/vr/VRServiceTest.cpp @@ -38,7 +38,7 @@ bool ReadFloat32Array(T& aDestination, const Float32Array& aSource, }; // anonymous namespace VRMockDisplay::VRMockDisplay(VRServiceTest* aVRServiceTest) - : DOMEventTargetHelper(aVRServiceTest->GetOwner()), + : DOMEventTargetHelper(aVRServiceTest->GetOwnerGlobal()), mVRServiceTest(aVRServiceTest) {} JSObject* VRMockDisplay::WrapObject(JSContext* aCx, @@ -339,7 +339,7 @@ NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED_0(VRMockController, VRMockController::VRMockController(VRServiceTest* aVRServiceTest, uint32_t aControllerIdx) - : DOMEventTargetHelper(aVRServiceTest->GetOwner()), + : DOMEventTargetHelper(aVRServiceTest->GetOwnerGlobal()), mVRServiceTest(aVRServiceTest), mControllerIdx(aControllerIdx) { MOZ_ASSERT(aControllerIdx < kVRControllerMaxCount); diff --git a/dom/vr/XRSession.cpp b/dom/vr/XRSession.cpp index 41c73031c33e..0901a731fd09 100644 --- a/dom/vr/XRSession.cpp +++ b/dom/vr/XRSession.cpp @@ -299,9 +299,8 @@ void XRSession::WillRefresh(mozilla::TimeStamp aTime) { // Inline sessions are driven by nsRefreshDriver directly, // unlike immersive sessions, which are driven VRDisplayClient. if (!IsImmersive() && !mXRSystem->HasActiveImmersiveSession()) { - nsGlobalWindowInner* win = nsGlobalWindowInner::Cast(GetOwner()); - if (win) { - if (JSObject* obj = win->AsGlobal()->GetGlobalJSObject()) { + if (nsIGlobalObject* global = GetOwnerGlobal()) { + if (JSObject* obj = global->GetGlobalJSObject()) { js::NotifyAnimationActivity(obj); } } diff --git a/dom/vr/XRSystem.cpp b/dom/vr/XRSystem.cpp index 2dd66e41f412..4afa95d63107 100644 --- a/dom/vr/XRSystem.cpp +++ b/dom/vr/XRSystem.cpp @@ -272,7 +272,7 @@ void XRSystem::OnXRPermissionRequestCancel() { } bool XRSystem::FeaturePolicyBlocked() const { - nsGlobalWindowInner* win = nsGlobalWindowInner::Cast(GetOwner()); + nsGlobalWindowInner* win = GetOwnerWindow(); if (!win) { return true; } @@ -332,11 +332,11 @@ void XRSystem::ResolveSessionRequests( if (request->ResolveSupport(display, enabledReferenceSpaceTypes)) { if (request->IsImmersive()) { session = XRSession::CreateImmersiveSession( - GetOwner(), this, display, request->GetPresentationGroup(), + GetOwnerWindow(), this, display, request->GetPresentationGroup(), enabledReferenceSpaceTypes); mActiveImmersiveSession = session; } else { - session = XRSession::CreateInlineSession(GetOwner(), this, + session = XRSession::CreateInlineSession(GetOwnerWindow(), this, enabledReferenceSpaceTypes); mInlineSessions.AppendElement(session); } @@ -445,8 +445,7 @@ void XRSystem::ProcessSessionRequestsWaitingForRuntimeDetection() { * allowing xr-spatial-tracking for inline sessions do not * present a modal XR permission UI. (eg. Android Firefox Reality) */ - nsGlobalWindowInner* win = nsGlobalWindowInner::Cast(GetOwner()); - win->RequestXRPermission(); + GetOwnerWindow()->RequestXRPermission(); } } diff --git a/dom/websocket/WebSocket.cpp b/dom/websocket/WebSocket.cpp index 4d7f413c51e9..0004b42cbf53 100644 --- a/dom/websocket/WebSocket.cpp +++ b/dom/websocket/WebSocket.cpp @@ -638,8 +638,8 @@ void WebSocketImpl::Disconnect(const RefPtr& aProofOfRef) { // If we haven't called WebSocket::DisconnectFromOwner yet, update // web socket count here. - if (mWebSocket->GetOwner()) { - mWebSocket->GetOwner()->UpdateWebSocketCount(-1); + if (nsGlobalWindowInner* win = mWebSocket->GetOwnerWindow()) { + win->UpdateWebSocketCount(-1); } } else { RefPtr runnable = @@ -1373,8 +1373,8 @@ already_AddRefed WebSocket::ConstructorCommon( if (NS_IsMainThread()) { // We're keeping track of all main thread web sockets to be able to // avoid throttling timeouts when we have active web sockets. - if (webSocket->GetOwner()) { - webSocket->GetOwner()->UpdateWebSocketCount(1); + if (nsGlobalWindowInner* win = webSocket->GetOwnerWindow()) { + win->UpdateWebSocketCount(1); } bool isSecure = principal->SchemeIs("https"); @@ -1582,8 +1582,8 @@ void WebSocket::DisconnectFromOwner() { // If we haven't called WebSocketImpl::Disconnect yet, update web // socket count here. if (NS_IsMainThread() && mImpl && !mImpl->mDisconnectingOrDisconnected && - GetOwner()) { - GetOwner()->UpdateWebSocketCount(-1); + GetOwnerWindow()) { + GetOwnerWindow()->UpdateWebSocketCount(-1); } DOMEventTargetHelper::DisconnectFromOwner(); @@ -1674,7 +1674,7 @@ nsresult WebSocketImpl::Init(JSContext* aCx, bool aIsSecure, // inner-windowID. This can happen in sharedWorkers and ServiceWorkers or in // DedicateWorkers created by JSM. if (aCx) { - if (nsPIDOMWindowInner* ownerWindow = mWebSocket->GetOwner()) { + if (nsPIDOMWindowInner* ownerWindow = mWebSocket->GetOwnerWindow()) { mInnerWindowID = ownerWindow->WindowID(); } } @@ -2596,17 +2596,17 @@ WebSocketImpl::Observe(nsISupports* aSubject, const char* aTopic, AssertIsOnMainThread(); int64_t readyState = mWebSocket->ReadyState(); - if ((readyState == WebSocket::CLOSING) || (readyState == WebSocket::CLOSED)) { + if (readyState == WebSocket::CLOSING || readyState == WebSocket::CLOSED) { return NS_OK; } nsCOMPtr window = do_QueryInterface(aSubject); - if (!mWebSocket->GetOwner() || window != mWebSocket->GetOwner()) { + if (!mWebSocket->GetOwnerWindow() || window != mWebSocket->GetOwnerWindow()) { return NS_OK; } - if ((strcmp(aTopic, DOM_WINDOW_FROZEN_TOPIC) == 0) || - (strcmp(aTopic, DOM_WINDOW_DESTROYED_TOPIC) == 0)) { + if (!strcmp(aTopic, DOM_WINDOW_FROZEN_TOPIC) || + !strcmp(aTopic, DOM_WINDOW_DESTROYED_TOPIC)) { RefPtr self(this); CloseConnection(self, nsIWebSocketChannel::CLOSE_GOING_AWAY); } diff --git a/dom/workers/sharedworkers/SharedWorkerChild.cpp b/dom/workers/sharedworkers/SharedWorkerChild.cpp index 21ae74681bf3..ac977f99d357 100644 --- a/dom/workers/sharedworkers/SharedWorkerChild.cpp +++ b/dom/workers/sharedworkers/SharedWorkerChild.cpp @@ -17,6 +17,7 @@ #include "mozilla/dom/WindowGlobalChild.h" #include "mozilla/dom/WorkerError.h" #include "mozilla/dom/locks/LockManagerChild.h" +#include "nsGlobalWindowInner.h" namespace mozilla { @@ -74,7 +75,7 @@ IPCResult SharedWorkerChild::RecvError(const ErrorValue& aValue) { return IPC_OK(); } - nsPIDOMWindowInner* window = mParent->GetOwner(); + nsPIDOMWindowInner* window = mParent->GetOwnerWindow(); uint64_t innerWindowId = window ? window->WindowID() : 0; if (aValue.type() == ErrorValue::TCSPViolation) { @@ -153,7 +154,7 @@ IPCResult SharedWorkerChild::RecvNotifyLock(bool aCreated) { return IPC_OK(); } - locks::LockManagerChild::NotifyBFCacheOnMainThread(mParent->GetOwner(), + locks::LockManagerChild::NotifyBFCacheOnMainThread(mParent->GetOwnerWindow(), aCreated); return IPC_OK(); @@ -164,7 +165,7 @@ IPCResult SharedWorkerChild::RecvNotifyWebTransport(bool aCreated) { return IPC_OK(); } - WebTransport::NotifyBFCacheOnMainThread(mParent->GetOwner(), aCreated); + WebTransport::NotifyBFCacheOnMainThread(mParent->GetOwnerWindow(), aCreated); return IPC_OK(); } diff --git a/dom/xhr/XMLHttpRequestEventTarget.h b/dom/xhr/XMLHttpRequestEventTarget.h index 89c13e13386b..711c2132ebd8 100644 --- a/dom/xhr/XMLHttpRequestEventTarget.h +++ b/dom/xhr/XMLHttpRequestEventTarget.h @@ -37,9 +37,8 @@ class XMLHttpRequestEventTarget : public DOMEventTargetHelper { IMPL_EVENT_HANDLER(timeout) IMPL_EVENT_HANDLER(loadend) - nsISupports* GetParentObject() const { return GetOwner(); } - - virtual void DisconnectFromOwner() override; + nsISupports* GetParentObject() const { return GetOwnerGlobal(); } + void DisconnectFromOwner() override; }; } // namespace mozilla::dom diff --git a/dom/xhr/XMLHttpRequestMainThread.cpp b/dom/xhr/XMLHttpRequestMainThread.cpp index 36c05ba51d4d..11ade62cf163 100644 --- a/dom/xhr/XMLHttpRequestMainThread.cpp +++ b/dom/xhr/XMLHttpRequestMainThread.cpp @@ -53,6 +53,7 @@ #include "nsIBaseChannel.h" #include "nsIJARChannel.h" #include "nsIJARURI.h" +#include "nsGlobalWindowInner.h" #include "nsReadableUtils.h" #include "nsSandboxFlags.h" @@ -525,7 +526,7 @@ Document* XMLHttpRequestMainThread::GetResponseXML(ErrorResult& aRv) { } if (mWarnAboutSyncHtml) { mWarnAboutSyncHtml = false; - LogMessage("HTMLSyncXHRWarning", GetOwner()); + LogMessage("HTMLSyncXHRWarning", GetOwnerWindow()); } if (mState != XMLHttpRequest_Binding::DONE) { return nullptr; @@ -559,7 +560,7 @@ nsresult XMLHttpRequestMainThread::DetectCharset() { if (mResponseType == XMLHttpRequestResponseType::Json && encoding != UTF_8_ENCODING) { // The XHR spec says only UTF-8 is supported for responseType == "json" - LogMessage("JSONCharsetWarning", GetOwner()); + LogMessage("JSONCharsetWarning", GetOwnerWindow()); encoding = UTF_8_ENCODING; } @@ -726,9 +727,9 @@ void XMLHttpRequestMainThread::SetResponseType( } // sync request is not allowed setting responseType in window context - if (HasOrHasHadOwner() && mState != XMLHttpRequest_Binding::UNSENT && + if (HasOrHasHadOwnerWindow() && mState != XMLHttpRequest_Binding::UNSENT && mFlagSynchronous) { - LogMessage("ResponseTypeSyncXHRWarning", GetOwner()); + LogMessage("ResponseTypeSyncXHRWarning", GetOwnerWindow()); aRv.ThrowInvalidAccessError( "synchronous XMLHttpRequests do not support timeout and responseType"); return; @@ -1542,9 +1543,9 @@ void XMLHttpRequestMainThread::Open(const nsACString& aMethod, NOT_CALLABLE_IN_SYNC_SEND_RV // Gecko-specific - if (!aAsync && !DontWarnAboutSyncXHR() && GetOwner() && - GetOwner()->GetExtantDoc()) { - GetOwner()->GetExtantDoc()->WarnOnceAbout( + if (!aAsync && !DontWarnAboutSyncXHR() && GetOwnerWindow() && + GetOwnerWindow()->GetExtantDoc()) { + GetOwnerWindow()->GetExtantDoc()->WarnOnceAbout( DeprecatedOperations::eSyncXMLHttpRequestDeprecated); } @@ -1572,7 +1573,7 @@ void XMLHttpRequestMainThread::Open(const nsACString& aMethod, } // Gecko-specific - if (!aAsync && responsibleDocument && GetOwner()) { + if (!aAsync && responsibleDocument && GetOwnerWindow()) { // We have no extant document during unload, so the above general // syncXHR warning will not display. But we do want to display a // recommendation to use sendBeacon instead of syncXHR during unload. @@ -1581,7 +1582,8 @@ void XMLHttpRequestMainThread::Open(const nsACString& aMethod, bool inUnload = false; shell->GetIsInUnload(&inUnload); if (inUnload) { - LogMessage("UseSendBeaconDuringUnloadAndPagehideWarning", GetOwner()); + LogMessage("UseSendBeaconDuringUnloadAndPagehideWarning", + GetOwnerWindow()); } } } @@ -1640,14 +1642,14 @@ void XMLHttpRequestMainThread::Open(const nsACString& aMethod, } // Step 9 - if (!aAsync && HasOrHasHadOwner() && + if (!aAsync && HasOrHasHadOwnerWindow() && (mTimeoutMilliseconds || mResponseType != XMLHttpRequestResponseType::_empty)) { if (mTimeoutMilliseconds) { - LogMessage("TimeoutSyncXHRWarning", GetOwner()); + LogMessage("TimeoutSyncXHRWarning", GetOwnerWindow()); } if (mResponseType != XMLHttpRequestResponseType::_empty) { - LogMessage("ResponseTypeSyncXHRWarning", GetOwner()); + LogMessage("ResponseTypeSyncXHRWarning", GetOwnerWindow()); } aRv.ThrowInvalidAccessError( "synchronous XMLHttpRequests do not support timeout and responseType"); @@ -2492,7 +2494,7 @@ void XMLHttpRequestMainThread::ChangeStateToDone(bool aWasSync) { nsLoadFlags loadFlags = 0; mChannel->GetLoadFlags(&loadFlags); if (loadFlags & nsIRequest::LOAD_BACKGROUND) { - nsPIDOMWindowInner* owner = GetOwner(); + nsPIDOMWindowInner* owner = GetOwnerWindow(); BrowsingContext* bc = owner ? owner->GetBrowsingContext() : nullptr; bc = bc ? bc->Top() : nullptr; if (bc && bc->IsLoading()) { @@ -2746,7 +2748,7 @@ nsresult XMLHttpRequestMainThread::InitiateFetch( mAuthorRequestHeaders.ApplyToChannel(httpChannel, false, false); if (!IsSystemXHR()) { - nsCOMPtr owner = GetOwner(); + nsCOMPtr owner = GetOwnerWindow(); nsCOMPtr doc = owner ? owner->GetExtantDoc() : nullptr; nsCOMPtr referrerInfo = ReferrerInfo::CreateForFetch(mPrincipal, doc); @@ -3246,9 +3248,9 @@ void XMLHttpRequestMainThread::SendInternal(const BodyExtractorBase* aBody, mFlagSyncLooping = true; - if (GetOwner()) { + if (GetOwnerWindow()) { if (nsCOMPtr topWindow = - GetOwner()->GetOuterWindow()->GetInProcessTop()) { + GetOwnerWindow()->GetOuterWindow()->GetInProcessTop()) { if (nsCOMPtr topInner = topWindow->GetCurrentInnerWindow()) { suspendedDoc = topWindow->GetExtantDoc(); @@ -3341,7 +3343,7 @@ void XMLHttpRequestMainThread::SetRequestHeader(const nsACString& aName, if (!isPrivilegedCaller && isForbiddenHeader) { AutoTArray params; CopyUTF8toUTF16(aName, *params.AppendElement()); - LogMessage("ForbiddenHeaderWarning", GetOwner(), params); + LogMessage("ForbiddenHeaderWarning", GetOwnerWindow(), params); return; } @@ -3363,10 +3365,10 @@ void XMLHttpRequestMainThread::SetTimeout(uint32_t aTimeout, ErrorResult& aRv) { NOT_CALLABLE_IN_SYNC_SEND_RV if (mFlagSynchronous && mState != XMLHttpRequest_Binding::UNSENT && - HasOrHasHadOwner()) { + HasOrHasHadOwnerWindow()) { /* Timeout is not supported for synchronous requests with an owning window, per XHR2 spec. */ - LogMessage("TimeoutSyncXHRWarning", GetOwner()); + LogMessage("TimeoutSyncXHRWarning", GetOwnerWindow()); aRv.ThrowInvalidAccessError( "synchronous XMLHttpRequests do not support timeout and responseType"); return; @@ -3692,8 +3694,8 @@ XMLHttpRequestMainThread::GetInterface(const nsIID& aIID, void** aResult) { // Get the an auth prompter for our window so that the parenting // of the dialogs works as it should when using tabs. nsCOMPtr window; - if (GetOwner()) { - window = GetOwner()->GetOuterWindow(); + if (nsGlobalWindowInner* inner = GetOwnerWindow()) { + window = inner->GetOuterWindow(); } return wwatch->GetPrompt(window, aIID, reinterpret_cast(aResult)); } diff --git a/netwerk/cookie/CookieParser.cpp b/netwerk/cookie/CookieParser.cpp index 2f9adad8b240..4f49cc0d6c7b 100644 --- a/netwerk/cookie/CookieParser.cpp +++ b/netwerk/cookie/CookieParser.cpp @@ -8,8 +8,8 @@ #include "mozilla/dom/nsMixedContentBlocker.h" #include "mozilla/glean/GleanMetrics.h" +#include "mozilla/net/Cookie.h" #include "mozilla/StaticPrefs_network.h" -#include "mozilla/Telemetry.h" #include "nsIConsoleReportCollector.h" #include "nsIScriptError.h" #include "nsIURI.h"