From 7b9f6cbbdc4ad081c5ab9a08802ce19739cafcc6 Mon Sep 17 00:00:00 2001 From: Matt Woodrow Date: Thu, 12 Dec 2019 02:32:00 +0000 Subject: [PATCH] Bug 1589123 - Do BrowsingContext::LoadURI messages via PContent, not PWindowGlobal since we might not have a current global. r=kmag Depends on D56818 Differential Revision: https://phabricator.services.mozilla.com/D56820 --HG-- extra : moz-landing-system : lando --- docshell/base/BrowsingContext.cpp | 19 ++++---- dom/ipc/ContentChild.cpp | 78 +++++++++++++++++++++++++++++++ dom/ipc/ContentChild.h | 11 +++++ dom/ipc/PContent.ipdl | 7 +++ dom/ipc/PWindowGlobal.ipdl | 6 --- dom/ipc/WindowGlobalChild.cpp | 71 ---------------------------- dom/ipc/WindowGlobalChild.h | 8 ---- dom/ipc/WindowGlobalParent.cpp | 21 +-------- 8 files changed, 109 insertions(+), 112 deletions(-) diff --git a/docshell/base/BrowsingContext.cpp b/docshell/base/BrowsingContext.cpp index fc9385113937..48697605caa2 100644 --- a/docshell/base/BrowsingContext.cpp +++ b/docshell/base/BrowsingContext.cpp @@ -891,8 +891,9 @@ nsresult BrowsingContext::LoadURI(BrowsingContext* aAccessor, } if (!aAccessor && XRE_IsParentProcess()) { - Unused << Canonical()->GetCurrentWindowGlobal()->SendLoadURIInChild( - aLoadState, aSetNavigating); + if (ContentParent* cp = Canonical()->GetContentParent()) { + Unused << cp->SendLoadURI(this, aLoadState, aSetNavigating); + } } else { MOZ_DIAGNOSTIC_ASSERT(aAccessor); MOZ_DIAGNOSTIC_ASSERT(aAccessor->Group() == Group()); @@ -920,7 +921,7 @@ nsresult BrowsingContext::InternalLoad(BrowsingContext* aAccessor, } bool isActive = - aAccessor->GetIsActive() && !mIsActive && + aAccessor && aAccessor->GetIsActive() && !mIsActive && !Preferences::GetBool("browser.tabs.loadDivertedInBackground", false); if (mDocShell) { nsresult rv = nsDocShell::Cast(mDocShell)->InternalLoad( @@ -941,9 +942,10 @@ nsresult BrowsingContext::InternalLoad(BrowsingContext* aAccessor, return rv; } - if (!aAccessor && XRE_IsParentProcess()) { - Unused << Canonical()->GetCurrentWindowGlobal()->SendInternalLoadInChild( - aLoadState, isActive); + if (XRE_IsParentProcess()) { + if (ContentParent* cp = Canonical()->GetContentParent()) { + Unused << cp->SendInternalLoad(this, aLoadState, isActive); + } } else { MOZ_DIAGNOSTIC_ASSERT(aAccessor); MOZ_DIAGNOSTIC_ASSERT(aAccessor->Group() == Group()); @@ -973,8 +975,9 @@ void BrowsingContext::DisplayLoadError(const nsAString& aURI) { PromiseFlatString(aURI).get(), nullptr, &didDisplayLoadError); } else { - Unused << Canonical()->GetCurrentWindowGlobal()->SendDisplayLoadError( - PromiseFlatString(aURI)); + if (ContentParent* cp = Canonical()->GetContentParent()) { + Unused << cp->SendDisplayLoadError(this, PromiseFlatString(aURI)); + } } } diff --git a/dom/ipc/ContentChild.cpp b/dom/ipc/ContentChild.cpp index 8bc13ae5c085..32a0e9d308fc 100644 --- a/dom/ipc/ContentChild.cpp +++ b/dom/ipc/ContentChild.cpp @@ -104,6 +104,7 @@ #include "mozilla/LoadInfo.h" #include "mozilla/UnderrunHandler.h" #include "mozilla/net/HttpChannelChild.h" +#include "nsFocusManager.h" #include "nsQueryObject.h" #include "imgLoader.h" #include "GMPServiceChild.h" @@ -112,6 +113,7 @@ #include "audio_thread_priority.h" #include "nsIConsoleService.h" #include "audio_thread_priority.h" +#include "nsIURIMutator.h" #if !defined(XP_WIN) # include "mozilla/Omnijar.h" @@ -4151,6 +4153,82 @@ mozilla::ipc::IPCResult ContentChild::RecvScriptError( return IPC_OK(); } +mozilla::ipc::IPCResult ContentChild::RecvLoadURI( + BrowsingContext* aContext, nsDocShellLoadState* aLoadState, + bool aSetNavigating) { + aContext->LoadURI(nullptr, aLoadState, aSetNavigating); + + nsCOMPtr window = aContext->GetDOMWindow(); + BrowserChild* bc = BrowserChild::GetFrom(window); + if (bc) { + bc->NotifyNavigationFinished(); + } + +#ifdef MOZ_CRASHREPORTER + if (CrashReporter::GetEnabled()) { + nsCOMPtr annotationURI; + + nsresult rv = NS_MutateURI(aLoadState->URI()) + .SetUserPass(EmptyCString()) + .Finalize(annotationURI); + + if (NS_FAILED(rv)) { + // Ignore failures on about: URIs. + annotationURI = aLoadState->URI(); + } + + CrashReporter::AnnotateCrashReport(CrashReporter::Annotation::URL, + annotationURI->GetSpecOrDefault()); + } +#endif + + return IPC_OK(); +} + +mozilla::ipc::IPCResult ContentChild::RecvInternalLoad( + BrowsingContext* aContext, nsDocShellLoadState* aLoadState, + bool aTakeFocus) { + aContext->InternalLoad(nullptr, aLoadState, nullptr, nullptr); + + if (aTakeFocus) { + if (nsCOMPtr domWin = aContext->GetDOMWindow()) { + nsFocusManager::FocusWindow(domWin); + } + } + +#ifdef MOZ_CRASHREPORTER + if (CrashReporter::GetEnabled()) { + nsCOMPtr annotationURI; + + nsresult rv = NS_MutateURI(aLoadState->URI()) + .SetUserPass(EmptyCString()) + .Finalize(annotationURI); + + if (NS_FAILED(rv)) { + // Ignore failures on about: URIs. + annotationURI = aLoadState->URI(); + } + + CrashReporter::AnnotateCrashReport(CrashReporter::Annotation::URL, + annotationURI->GetSpecOrDefault()); + } +#endif + + return IPC_OK(); +} + +mozilla::ipc::IPCResult ContentChild::RecvDisplayLoadError( + BrowsingContext* aContext, const nsAString& aURI) { + aContext->DisplayLoadError(aURI); + + nsCOMPtr window = aContext->GetDOMWindow(); + BrowserChild* bc = BrowserChild::GetFrom(window); + if (bc) { + bc->NotifyNavigationFinished(); + } + return IPC_OK(); +} + #if defined(MOZ_SANDBOX) && defined(MOZ_DEBUG) && defined(ENABLE_TESTS) mozilla::ipc::IPCResult ContentChild::RecvInitSandboxTesting( Endpoint&& aEndpoint) { diff --git a/dom/ipc/ContentChild.h b/dom/ipc/ContentChild.h index c305de63d79a..77dd313f53dd 100644 --- a/dom/ipc/ContentChild.h +++ b/dom/ipc/ContentChild.h @@ -763,6 +763,17 @@ class ContentChild final const nsCString& aCategory, const bool& aFromPrivateWindow, const uint64_t& aInnerWindowId, const bool& aFromChromeContext); + mozilla::ipc::IPCResult RecvLoadURI(BrowsingContext* aContext, + nsDocShellLoadState* aLoadState, + bool aSetNavigating); + + mozilla::ipc::IPCResult RecvInternalLoad(BrowsingContext* aContext, + nsDocShellLoadState* aLoadState, + bool aTakeFocus); + + mozilla::ipc::IPCResult RecvDisplayLoadError(BrowsingContext* aContext, + const nsAString& aURI); + #ifdef NIGHTLY_BUILD virtual PContentChild::Result OnMessageReceived(const Message& aMsg) override; #else diff --git a/dom/ipc/PContent.ipdl b/dom/ipc/PContent.ipdl index ea92be55c484..3c090be01728 100644 --- a/dom/ipc/PContent.ipdl +++ b/dom/ipc/PContent.ipdl @@ -116,6 +116,7 @@ using mozilla::ipc::SharedMemoryBasic::Handle from "mozilla/ipc/SharedMemoryBasi using mozilla::fontlist::Pointer from "SharedFontList.h"; using gfxSparseBitSet from "gfxFontUtils.h"; using mozilla::dom::MediaControlActions from "ipc/MediaControlIPC.h"; +using refcounted class nsDocShellLoadState from "nsDocShellLoadState.h"; union ChromeRegistryItem { @@ -855,6 +856,12 @@ child: async EvictContentViewers(uint64_t[] aToEvictSharedStateIDs); + async LoadURI(BrowsingContext aContext, nsDocShellLoadState aLoadState, bool aSetNavigating); + + async InternalLoad(BrowsingContext aContext, nsDocShellLoadState aLoadState, bool aTakeFocus); + + async DisplayLoadError(BrowsingContext aContext, nsString aURI); + parent: async InitBackground(Endpoint aEndpoint); diff --git a/dom/ipc/PWindowGlobal.ipdl b/dom/ipc/PWindowGlobal.ipdl index af5156b8f80a..7e113d119108 100644 --- a/dom/ipc/PWindowGlobal.ipdl +++ b/dom/ipc/PWindowGlobal.ipdl @@ -61,12 +61,6 @@ child: */ async GetSecurityInfo() returns(nsCString? serializedSecInfo); - async LoadURIInChild(nsDocShellLoadState aLoadState, bool aSetNavigating); - - async InternalLoadInChild(nsDocShellLoadState aLoadState, bool aTakeFocus); - - async DisplayLoadError(nsString aURI); - both: async RawMessage(JSWindowActorMessageMeta aMetadata, ClonedMessageData aData, ClonedMessageData aStack); diff --git a/dom/ipc/WindowGlobalChild.cpp b/dom/ipc/WindowGlobalChild.cpp index 3e0d7618f11e..3a23514a5cb9 100644 --- a/dom/ipc/WindowGlobalChild.cpp +++ b/dom/ipc/WindowGlobalChild.cpp @@ -235,77 +235,6 @@ void WindowGlobalChild::Destroy() { } } -mozilla::ipc::IPCResult WindowGlobalChild::RecvLoadURIInChild( - nsDocShellLoadState* aLoadState, bool aSetNavigating) { - mWindowGlobal->GetDocShell()->LoadURI(aLoadState, aSetNavigating); - if (aSetNavigating) { - mWindowGlobal->GetBrowserChild()->NotifyNavigationFinished(); - } - -#ifdef MOZ_CRASHREPORTER - if (CrashReporter::GetEnabled()) { - nsCOMPtr annotationURI; - - nsresult rv = NS_MutateURI(aLoadState->URI()) - .SetUserPass(EmptyCString()) - .Finalize(annotationURI); - - if (NS_FAILED(rv)) { - // Ignore failures on about: URIs. - annotationURI = aLoadState->URI(); - } - - CrashReporter::AnnotateCrashReport(CrashReporter::Annotation::URL, - annotationURI->GetSpecOrDefault()); - } -#endif - - return IPC_OK(); -} - -mozilla::ipc::IPCResult WindowGlobalChild::RecvInternalLoadInChild( - nsDocShellLoadState* aLoadState, bool aTakeFocus) { - nsDocShell::Cast(mWindowGlobal->GetDocShell()) - ->InternalLoad(aLoadState, nullptr, nullptr); - - if (aTakeFocus) { - if (nsCOMPtr domWin = - mBrowsingContext->GetDOMWindow()) { - nsFocusManager::FocusWindow(domWin); - } - } - -#ifdef MOZ_CRASHREPORTER - if (CrashReporter::GetEnabled()) { - nsCOMPtr annotationURI; - - nsresult rv = NS_MutateURI(aLoadState->URI()) - .SetUserPass(EmptyCString()) - .Finalize(annotationURI); - - if (NS_FAILED(rv)) { - // Ignore failures on about: URIs. - annotationURI = aLoadState->URI(); - } - - CrashReporter::AnnotateCrashReport(CrashReporter::Annotation::URL, - annotationURI->GetSpecOrDefault()); - } -#endif - - return IPC_OK(); -} - -mozilla::ipc::IPCResult WindowGlobalChild::RecvDisplayLoadError( - const nsAString& aURI) { - bool didDisplayLoadError = false; - mWindowGlobal->GetDocShell()->DisplayLoadError( - NS_ERROR_MALFORMED_URI, nullptr, PromiseFlatString(aURI).get(), nullptr, - &didDisplayLoadError); - mWindowGlobal->GetBrowserChild()->NotifyNavigationFinished(); - return IPC_OK(); -} - mozilla::ipc::IPCResult WindowGlobalChild::RecvMakeFrameLocal( dom::BrowsingContext* aFrameContext, uint64_t aPendingSwitchId) { MOZ_DIAGNOSTIC_ASSERT(XRE_IsContentProcess()); diff --git a/dom/ipc/WindowGlobalChild.h b/dom/ipc/WindowGlobalChild.h index 9ca1e451babd..0d5b78b741e4 100644 --- a/dom/ipc/WindowGlobalChild.h +++ b/dom/ipc/WindowGlobalChild.h @@ -116,14 +116,6 @@ class WindowGlobalChild final : public WindowGlobalActor, const ClonedMessageData& aData, const ClonedMessageData& aStack); - mozilla::ipc::IPCResult RecvLoadURIInChild(nsDocShellLoadState* aLoadState, - bool aSetNavigating); - - mozilla::ipc::IPCResult RecvInternalLoadInChild( - nsDocShellLoadState* aLoadState, bool aTakeFocus); - - mozilla::ipc::IPCResult RecvDisplayLoadError(const nsAString& aURI); - mozilla::ipc::IPCResult RecvMakeFrameLocal( dom::BrowsingContext* aFrameContext, uint64_t aPendingSwitchId); diff --git a/dom/ipc/WindowGlobalParent.cpp b/dom/ipc/WindowGlobalParent.cpp index cb15736cd71c..cce6fcf22eca 100644 --- a/dom/ipc/WindowGlobalParent.cpp +++ b/dom/ipc/WindowGlobalParent.cpp @@ -198,14 +198,7 @@ mozilla::ipc::IPCResult WindowGlobalParent::RecvLoadURI( // FIXME: We should really initiate the load in the parent before bouncing // back down to the child. - WindowGlobalParent* wgp = aTargetBC->Canonical()->GetCurrentWindowGlobal(); - if (!wgp) { - MOZ_LOG(BrowsingContext::GetLog(), LogLevel::Debug, - ("ParentIPC: Target BrowsingContext has no WindowGlobalParent")); - return IPC_OK(); - } - - Unused << wgp->SendLoadURIInChild(aLoadState, aSetNavigating); + aTargetBC->LoadURI(nullptr, aLoadState, aSetNavigating); return IPC_OK(); } @@ -228,17 +221,7 @@ mozilla::ipc::IPCResult WindowGlobalParent::RecvInternalLoad( // FIXME: We should really initiate the load in the parent before bouncing // back down to the child. - WindowGlobalParent* wgp = aTargetBC->Canonical()->GetCurrentWindowGlobal(); - if (!wgp) { - MOZ_LOG(BrowsingContext::GetLog(), LogLevel::Debug, - ("ParentIPC: Target BrowsingContext has no WindowGlobalParent")); - return IPC_OK(); - } - - bool takeFocus = - mBrowsingContext->GetIsActive() && !aTargetBC->GetIsActive() && - !Preferences::GetBool("browser.tabs.loadDivertedInBackground", false); - Unused << wgp->SendInternalLoadInChild(aLoadState, takeFocus); + aTargetBC->InternalLoad(mBrowsingContext, aLoadState, nullptr, nullptr); return IPC_OK(); }