From b3c5f899047bdafb598d8d7d23c290d77ea9db71 Mon Sep 17 00:00:00 2001 From: Matt Woodrow Date: Fri, 24 Apr 2020 07:01:02 +0000 Subject: [PATCH] Bug 1602318 - Disable parent-initiated loads when using devtools. r=nika,ochameau Differential Revision: https://phabricator.services.mozilla.com/D71136 --- docshell/base/BrowsingContext.cpp | 7 +++++++ docshell/base/BrowsingContext.h | 3 +++ docshell/base/CanonicalBrowsingContext.cpp | 9 +++++++++ docshell/base/nsDocShell.cpp | 1 + 4 files changed, 20 insertions(+) diff --git a/docshell/base/BrowsingContext.cpp b/docshell/base/BrowsingContext.cpp index c61c06d8dbc8..d76037c8b72c 100644 --- a/docshell/base/BrowsingContext.cpp +++ b/docshell/base/BrowsingContext.cpp @@ -201,6 +201,7 @@ already_AddRefed BrowsingContext::CreateDetached( nsILoadInfo::EMBEDDER_POLICY_NULL); context->mFields.SetWithoutSyncing( nsILoadInfo::OPENER_POLICY_UNSAFE_NONE); + context->mFields.SetWithoutSyncing(false); if (aOpener && aOpener->SameOriginWithTop()) { // We inherit the opener policy if there is a creator and if the creator's @@ -1895,6 +1896,12 @@ bool BrowsingContext::CanSet(FieldIndex, return CheckOnlyOwningProcessCanSet(aSource); } +bool BrowsingContext::CanSet(FieldIndex, + const bool& aWatchedByDevtools, + ContentParent* aSource) { + return CheckOnlyOwningProcessCanSet(aSource); +} + bool BrowsingContext::CanSet(FieldIndex, const nsString& aUserAgent, ContentParent* aSource) { diff --git a/docshell/base/BrowsingContext.h b/docshell/base/BrowsingContext.h index 1639d919bd87..170516a243c0 100644 --- a/docshell/base/BrowsingContext.h +++ b/docshell/base/BrowsingContext.h @@ -123,6 +123,7 @@ class WindowProxyHolder; FIELD(MessageManagerGroup, nsString) \ FIELD(MaxTouchPointsOverride, uint8_t) \ FIELD(FullZoom, float) \ + FIELD(WatchedByDevtools, bool) \ FIELD(TextZoom, float) // BrowsingContext, in this context, is the cross process replicated @@ -701,6 +702,8 @@ class BrowsingContext : public nsILoadContext, public nsWrapperCache { ContentParent* aSource); bool CanSet(FieldIndex, const bool& aAllowPlugins, ContentParent* aSource); + bool CanSet(FieldIndex, const bool& aWatchedByDevtools, + ContentParent* aSource); template bool CanSet(FieldIndex, const T&, ContentParent*) { diff --git a/docshell/base/CanonicalBrowsingContext.cpp b/docshell/base/CanonicalBrowsingContext.cpp index 413ab3e9c906..f28981507cd3 100644 --- a/docshell/base/CanonicalBrowsingContext.cpp +++ b/docshell/base/CanonicalBrowsingContext.cpp @@ -536,6 +536,15 @@ bool CanonicalBrowsingContext::AttemptLoadURIInParent( return false; } + // We currently don't support initiating loads in the parent when they are + // watched by devtools. This is because devtools tracks loads using content + // process notifications, which happens after the load is initiated in this + // case. Devtools clears all prior requests when it detects a new navigation, + // so it drops the main document load that happened here. + if (GetWatchedByDevtools()) { + return false; + } + // DocumentChannel currently only supports connecting channels into the // content process, so we can only support schemes that will always be loaded // there for now. Restrict to just http(s) for simplicity. diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index 37b087b78ddc..66e1a777ac15 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -12845,5 +12845,6 @@ nsDocShell::GetWatchedByDevtools(bool* aWatched) { NS_IMETHODIMP nsDocShell::SetWatchedByDevtools(bool aWatched) { mWatchedByDevtools = aWatched; + mBrowsingContext->SetWatchedByDevtools(aWatched); return NS_OK; }