Bug 1602318 - Disable parent-initiated loads when using devtools. r=nika,ochameau
authorMatt Woodrow <mwoodrow@mozilla.com>
Sun, 26 Apr 2020 00:55:12 +0000
changeset 526113 eda5ef391b253da263853393a353c151d04e8ad6
parent 526112 beabc71edde261ac9729d004dbc242881e39b6dd
child 526114 d61dbc091c360277b7dacd037c20d4835c3505e7
push id37350
push usernbeleuzu@mozilla.com
push dateSun, 26 Apr 2020 09:43:12 +0000
treeherdermozilla-central@21659f178a12 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnika, ochameau
bugs1602318
milestone77.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1602318 - Disable parent-initiated loads when using devtools. r=nika,ochameau Differential Revision: https://phabricator.services.mozilla.com/D71136
docshell/base/BrowsingContext.cpp
docshell/base/BrowsingContext.h
docshell/base/CanonicalBrowsingContext.cpp
docshell/base/nsDocShell.cpp
--- a/docshell/base/BrowsingContext.cpp
+++ b/docshell/base/BrowsingContext.cpp
@@ -218,16 +218,17 @@ already_AddRefed<BrowsingContext> Browsi
     context->mFields.SetWithoutSyncing<IDX_EmbedderInnerWindowId>(
         aParent->WindowID());
   }
 
   context->mFields.SetWithoutSyncing<IDX_EmbedderPolicy>(
       nsILoadInfo::EMBEDDER_POLICY_NULL);
   context->mFields.SetWithoutSyncing<IDX_OpenerPolicy>(
       nsILoadInfo::OPENER_POLICY_UNSAFE_NONE);
+  context->mFields.SetWithoutSyncing<IDX_WatchedByDevtools>(false);
 
   if (aOpener && aOpener->SameOriginWithTop()) {
     // We inherit the opener policy if there is a creator and if the creator's
     // origin is same origin with the creator's top-level origin.
     // If it is cross origin we should not inherit the CrossOriginOpenerPolicy
     context->mFields.SetWithoutSyncing<IDX_OpenerPolicy>(
         aOpener->Top()->GetOpenerPolicy());
   } else if (aOpener) {
@@ -1853,16 +1854,22 @@ bool BrowsingContext::CanSet(FieldIndex<
 }
 
 bool BrowsingContext::CanSet(FieldIndex<IDX_AllowPlugins>,
                              const bool& aAllowPlugins,
                              ContentParent* aSource) {
   return CheckOnlyOwningProcessCanSet(aSource);
 }
 
+bool BrowsingContext::CanSet(FieldIndex<IDX_WatchedByDevtools>,
+                             const bool& aWatchedByDevtools,
+                             ContentParent* aSource) {
+  return CheckOnlyOwningProcessCanSet(aSource);
+}
+
 bool BrowsingContext::CanSet(FieldIndex<IDX_UserAgentOverride>,
                              const nsString& aUserAgent,
                              ContentParent* aSource) {
   if (!IsTop()) {
     return false;
   }
 
   return CheckOnlyOwningProcessCanSet(aSource);
--- a/docshell/base/BrowsingContext.h
+++ b/docshell/base/BrowsingContext.h
@@ -122,16 +122,17 @@ class WindowProxyHolder;
   /* ScreenOrientation-related APIs */                                       \
   FIELD(CurrentOrientationAngle, float)                                      \
   FIELD(CurrentOrientationType, mozilla::dom::OrientationType)               \
   FIELD(UserAgentOverride, nsString)                                         \
   FIELD(EmbedderElementType, Maybe<nsString>)                                \
   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
 // environment in which information about documents is stored. In
 // particular the tree structure of nested browsing contexts is
 // represented by the tree of BrowsingContexts.
 //
 // The tree of BrowsingContexts is created in step with its
@@ -693,16 +694,18 @@ class BrowsingContext : public nsILoadCo
 
   bool CanSet(FieldIndex<IDX_AllowContentRetargeting>,
               const bool& aAllowContentRetargeting, ContentParent* aSource);
   bool CanSet(FieldIndex<IDX_AllowContentRetargetingOnChildren>,
               const bool& aAllowContentRetargetingOnChildren,
               ContentParent* aSource);
   bool CanSet(FieldIndex<IDX_AllowPlugins>, const bool& aAllowPlugins,
               ContentParent* aSource);
+  bool CanSet(FieldIndex<IDX_WatchedByDevtools>, const bool& aWatchedByDevtools,
+              ContentParent* aSource);
 
   template <size_t I, typename T>
   bool CanSet(FieldIndex<I>, const T&, ContentParent*) {
     return true;
   }
 
   // Overload `DidSet` to get notifications for a particular field being set.
   //
--- a/docshell/base/CanonicalBrowsingContext.cpp
+++ b/docshell/base/CanonicalBrowsingContext.cpp
@@ -531,16 +531,25 @@ bool CanonicalBrowsingContext::AttemptLo
   // We currently only support starting loads directly from the
   // CanonicalBrowsingContext for top-level BCs.
   if (!IsTopContent() || !GetContentParent() ||
       !StaticPrefs::browser_tabs_documentchannel() ||
       !StaticPrefs::browser_tabs_documentchannel_parent_initiated()) {
     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.
   if (!net::SchemeIsHTTP(aLoadState->URI()) &&
       !net::SchemeIsHTTPS(aLoadState->URI())) {
     return false;
   }
 
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -12823,10 +12823,13 @@ nsDocShell::GetWatchedByDevtools(bool* a
   NS_ENSURE_ARG(aWatched);
   *aWatched = mWatchedByDevtools;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDocShell::SetWatchedByDevtools(bool aWatched) {
   mWatchedByDevtools = aWatched;
-  return NS_OK;
-}
+  if (!mWillChangeProcess) {
+    mBrowsingContext->SetWatchedByDevtools(aWatched);
+  }
+  return NS_OK;
+}