diff --git a/dom/base/Document.cpp b/dom/base/Document.cpp index 7e2de5bfbd28..e4b617b23b5c 100644 --- a/dom/base/Document.cpp +++ b/dom/base/Document.cpp @@ -3370,9 +3370,8 @@ void Document::SetDocumentURI(nsIURI* aURI) { // Tell our WindowGlobalParent that the document's URI has been changed. nsPIDOMWindowInner* inner = GetInnerWindow(); - WindowGlobalChild* wgc = inner ? inner->GetWindowGlobalChild() : nullptr; - if (wgc) { - Unused << wgc->SendUpdateDocumentURI(mDocumentURI); + if (inner && inner->GetWindowGlobalChild()) { + inner->GetWindowGlobalChild()->SetDocumentURI(mDocumentURI); } } diff --git a/dom/base/nsGlobalWindowOuter.cpp b/dom/base/nsGlobalWindowOuter.cpp index 0c16381263e0..a901c79bd66f 100644 --- a/dom/base/nsGlobalWindowOuter.cpp +++ b/dom/base/nsGlobalWindowOuter.cpp @@ -2215,9 +2215,9 @@ nsresult nsGlobalWindowOuter::SetNewDocument(Document* aDocument, // Tell the WindowGlobalParent that it should become the current window global // for our BrowsingContext if it isn't already. - mInnerWindow->GetWindowGlobalChild()->SendUpdateDocumentURI( - aDocument->GetDocumentURI()); - mInnerWindow->GetWindowGlobalChild()->SendBecomeCurrentWindowGlobal(); + WindowGlobalChild* wgc = mInnerWindow->GetWindowGlobalChild(); + wgc->SetDocumentURI(aDocument->GetDocumentURI()); + wgc->SendBecomeCurrentWindowGlobal(); // We no longer need the old inner window. Start its destruction if // its not being reused and clear our reference. diff --git a/dom/ipc/WindowGlobalChild.cpp b/dom/ipc/WindowGlobalChild.cpp index 0e546b9905ad..16544553cdb5 100644 --- a/dom/ipc/WindowGlobalChild.cpp +++ b/dom/ipc/WindowGlobalChild.cpp @@ -40,13 +40,21 @@ namespace dom { typedef nsRefPtrHashtable WGCByIdMap; static StaticAutoPtr gWindowGlobalChildById; -WindowGlobalChild::WindowGlobalChild(nsGlobalWindowInner* aWindow, - dom::BrowsingContext* aBrowsingContext) +WindowGlobalChild::WindowGlobalChild(const WindowGlobalInit& aInit, + nsGlobalWindowInner* aWindow) : mWindowGlobal(aWindow), - mBrowsingContext(aBrowsingContext), - mInnerWindowId(aWindow->WindowID()), - mOuterWindowId(aWindow->GetOuterWindow()->WindowID()), - mBeforeUnloadListeners(0) {} + mBrowsingContext(aInit.browsingContext()), + mDocumentPrincipal(aInit.principal()), + mDocumentURI(aInit.documentURI()), + mInnerWindowId(aInit.innerWindowId()), + mOuterWindowId(aInit.outerWindowId()), + mBeforeUnloadListeners(0) { + MOZ_DIAGNOSTIC_ASSERT(mBrowsingContext); + MOZ_DIAGNOSTIC_ASSERT(mDocumentPrincipal); + + MOZ_ASSERT(mInnerWindowId == aWindow->WindowID()); + MOZ_ASSERT(mOuterWindowId == aWindow->GetOuterWindow()->WindowID()); +} already_AddRefed WindowGlobalChild::Create( nsGlobalWindowInner* aWindow) { @@ -69,7 +77,11 @@ already_AddRefed WindowGlobalChild::Create( bc->SetOpenerPolicy(policy); } - RefPtr wgc = new WindowGlobalChild(aWindow, bc); + WindowGlobalInit init(principal, aWindow->GetDocumentURI(), bc, + aWindow->WindowID(), + aWindow->GetOuterWindow()->WindowID()); + + auto wgc = MakeRefPtr(init, aWindow); // If we have already closed our browsing context, return a pre-destroyed // WindowGlobalChild actor. @@ -78,9 +90,6 @@ already_AddRefed WindowGlobalChild::Create( return wgc.forget(); } - WindowGlobalInit init(principal, aWindow->GetDocumentURI(), bc, - wgc->mInnerWindowId, wgc->mOuterWindowId); - // Send the link constructor over PInProcessChild or PBrowser. if (XRE_IsParentProcess()) { InProcessChild* ipc = InProcessChild::Singleton(); @@ -337,8 +346,9 @@ void WindowGlobalChild::ReceiveRawMessage(const JSWindowActorMessageMeta& aMeta, } } -nsIURI* WindowGlobalChild::GetDocumentURI() { - return mWindowGlobal->GetDocumentURI(); +void WindowGlobalChild::SetDocumentURI(nsIURI* aDocumentURI) { + mDocumentURI = aDocumentURI; + SendUpdateDocumentURI(aDocumentURI); } const nsAString& WindowGlobalChild::GetRemoteType() { diff --git a/dom/ipc/WindowGlobalChild.h b/dom/ipc/WindowGlobalChild.h index 3607fd477fe7..374f85e89ab6 100644 --- a/dom/ipc/WindowGlobalChild.h +++ b/dom/ipc/WindowGlobalChild.h @@ -57,6 +57,9 @@ class WindowGlobalChild final : public WindowGlobalActor, // in the chrome process. bool IsInProcess() { return XRE_IsParentProcess(); } + nsIURI* GetDocumentURI() override { return mDocumentURI; } + void SetDocumentURI(nsIURI* aDocumentURI); + // The Window ID for this WindowGlobal uint64_t InnerWindowId() { return mInnerWindowId; } uint64_t OuterWindowId() { return mOuterWindowId; } @@ -90,10 +93,12 @@ class WindowGlobalChild final : public WindowGlobalActor, static already_AddRefed Create( nsGlobalWindowInner* aWindow); + WindowGlobalChild(const WindowGlobalInit& aInit, + nsGlobalWindowInner* aWindow); + nsISupports* GetParentObject(); JSObject* WrapObject(JSContext* aCx, JS::Handle aGivenProto) override; - nsIURI* GetDocumentURI() override; protected: const nsAString& GetRemoteType() override; @@ -118,12 +123,13 @@ class WindowGlobalChild final : public WindowGlobalActor, virtual void ActorDestroy(ActorDestroyReason aWhy) override; private: - WindowGlobalChild(nsGlobalWindowInner* aWindow, dom::BrowsingContext* aBc); ~WindowGlobalChild(); RefPtr mWindowGlobal; RefPtr mBrowsingContext; nsRefPtrHashtable mWindowActors; + nsCOMPtr mDocumentPrincipal; + nsCOMPtr mDocumentURI; uint64_t mInnerWindowId; uint64_t mOuterWindowId; int64_t mBeforeUnloadListeners;