From 252c246034562034b0591e4146a6e195ad645580 Mon Sep 17 00:00:00 2001 From: Anny Gakhokidze Date: Tue, 19 Oct 2021 18:46:46 +0000 Subject: [PATCH] Bug 1731613 - Move GetProcessSwitchBehavior method to C++, r=nika Differential Revision: https://phabricator.services.mozilla.com/D128898 --- dom/interfaces/base/nsIBrowser.idl | 22 ------------ netwerk/ipc/DocumentLoadListener.cpp | 35 ++++++++++++------- netwerk/ipc/DocumentLoadListener.h | 19 ++++++++++ .../content/widgets/browser-custom-element.js | 19 ---------- 4 files changed, 41 insertions(+), 54 deletions(-) diff --git a/dom/interfaces/base/nsIBrowser.idl b/dom/interfaces/base/nsIBrowser.idl index 973a9244b8f8..499580240ac2 100644 --- a/dom/interfaces/base/nsIBrowser.idl +++ b/dom/interfaces/base/nsIBrowser.idl @@ -129,28 +129,6 @@ interface nsIBrowser : nsISupports in uint64_t aRequestContextID, in AString aContentType); - /** - * Determine what process switching behavior this browser element should have. - */ - cenum ProcessBehavior : 8 { - // Gecko won't automatically change which process this frame, or it's - // subframes, are loaded in. - PROCESS_BEHAVIOR_DISABLED, - - // If `useRemoteTabs` is enabled, Gecko will change which process this frame - // is loaded in automatically, without calling `performProcessSwitch`. - // When `useRemoteSubframes` is enabled, subframes will change processes. - PROCESS_BEHAVIOR_STANDARD, - - // Gecko won't automatically change which process this frame is loaded, but - // when `useRemoteSubframes` is enabled, subframes will change processes. - // - // NOTE: This configuration is included only for backwards compatibility, - // and will be removed, as it can easily lead to invalid behavior. - PROCESS_BEHAVIOR_SUBFRAME_ONLY, - }; - readonly attribute nsIBrowser_ProcessBehavior processSwitchBehavior; - /** * Called to perform any async tasks which must be completed before changing * remoteness. Gecko will wait for the returned promise to resolve before diff --git a/netwerk/ipc/DocumentLoadListener.cpp b/netwerk/ipc/DocumentLoadListener.cpp index 5250cbf4efb2..cc6387616d9b 100644 --- a/netwerk/ipc/DocumentLoadListener.cpp +++ b/netwerk/ipc/DocumentLoadListener.cpp @@ -1467,6 +1467,21 @@ void DocumentLoadListener::SerializeRedirectData( } } +DocumentLoadListener::ProcessBehavior GetProcessSwitchBehavior( + Element* aBrowserElement) { + if (aBrowserElement->HasAttribute(u"maychangeremoteness"_ns)) { + return DocumentLoadListener::ProcessBehavior::PROCESS_BEHAVIOR_STANDARD; + } + nsCOMPtr browser = aBrowserElement->AsBrowser(); + bool isRemoteBrowser = false; + browser->GetIsRemoteBrowser(&isRemoteBrowser); + if (isRemoteBrowser) { + return DocumentLoadListener::ProcessBehavior:: + PROCESS_BEHAVIOR_SUBFRAME_ONLY; + } + return DocumentLoadListener::ProcessBehavior::PROCESS_BEHAVIOR_DISABLED; +} + static bool ContextCanProcessSwitch(CanonicalBrowsingContext* aBrowsingContext, WindowGlobalParent* aParentWindow) { if (NS_WARN_IF(!aBrowsingContext)) { @@ -1507,26 +1522,20 @@ static bool ContextCanProcessSwitch(CanonicalBrowsingContext* aBrowsingContext, return false; } - nsIBrowser::ProcessBehavior processBehavior = - nsIBrowser::PROCESS_BEHAVIOR_DISABLED; - nsresult rv = browser->GetProcessSwitchBehavior(&processBehavior); - if (NS_FAILED(rv)) { - MOZ_ASSERT_UNREACHABLE( - "nsIBrowser::GetProcessSwitchBehavior shouldn't fail"); - MOZ_LOG(gProcessIsolationLog, LogLevel::Warning, - ("Process Switch Abort: failed to get process switch behavior")); - return false; - } + DocumentLoadListener::ProcessBehavior processBehavior = + GetProcessSwitchBehavior(browserElement); // Check if the process switch we're considering is disabled by the // 's process behavior. - if (processBehavior == nsIBrowser::PROCESS_BEHAVIOR_DISABLED) { + if (processBehavior == + DocumentLoadListener::ProcessBehavior::PROCESS_BEHAVIOR_DISABLED) { MOZ_LOG(gProcessIsolationLog, LogLevel::Warning, ("Process Switch Abort: switch disabled by ")); return false; } - if (!aParentWindow && - processBehavior == nsIBrowser::PROCESS_BEHAVIOR_SUBFRAME_ONLY) { + if (!aParentWindow && processBehavior == + DocumentLoadListener::ProcessBehavior:: + PROCESS_BEHAVIOR_SUBFRAME_ONLY) { MOZ_LOG(gProcessIsolationLog, LogLevel::Warning, ("Process Switch Abort: toplevel switch disabled by ")); return false; diff --git a/netwerk/ipc/DocumentLoadListener.h b/netwerk/ipc/DocumentLoadListener.h index d1ff1fefb3aa..9d1a102fd068 100644 --- a/netwerk/ipc/DocumentLoadListener.h +++ b/netwerk/ipc/DocumentLoadListener.h @@ -289,6 +289,25 @@ class DocumentLoadListener : public nsIInterfaceRequestor, bool IsDocumentLoad() const { return mIsDocumentLoad; } + // Determine what process switching behavior a browser element should have. + enum ProcessBehavior : uint8_t { + // Gecko won't automatically change which process this frame, or it's + // subframes, are loaded in. + PROCESS_BEHAVIOR_DISABLED, + + // If `useRemoteTabs` is enabled, Gecko will change which process this frame + // is loaded in automatically, without calling `performProcessSwitch`. + // When `useRemoteSubframes` is enabled, subframes will change processes. + PROCESS_BEHAVIOR_STANDARD, + + // Gecko won't automatically change which process this frame is loaded, but + // when `useRemoteSubframes` is enabled, subframes will change processes. + // + // NOTE: This configuration is included only for backwards compatibility, + // and will be removed, as it can easily lead to invalid behavior. + PROCESS_BEHAVIOR_SUBFRAME_ONLY, + }; + protected: virtual ~DocumentLoadListener(); diff --git a/toolkit/content/widgets/browser-custom-element.js b/toolkit/content/widgets/browser-custom-element.js index bc80fc697a56..8f7ef8cd178d 100644 --- a/toolkit/content/widgets/browser-custom-element.js +++ b/toolkit/content/widgets/browser-custom-element.js @@ -1803,25 +1803,6 @@ return origins; } - get processSwitchBehavior() { - // If a `remotenessChangeHandler` is attached to this browser, it supports - // having its toplevel process switched dynamically in response to - // navigations. - if (this.hasAttribute("maychangeremoteness")) { - return Ci.nsIBrowser.PROCESS_BEHAVIOR_STANDARD; - } - - // For backwards compatibility, we need to mark remote, but - // non-`allowremote`, frames as `PROCESS_BEHAVIOR_SUBFRAME_ONLY`, as some - // tests rely on it. - // FIXME: Remove this? - if (this.isRemoteBrowser) { - return Ci.nsIBrowser.PROCESS_BEHAVIOR_SUBFRAME_ONLY; - } - // Otherwise, don't allow gecko-initiated toplevel process switches. - return Ci.nsIBrowser.PROCESS_BEHAVIOR_DISABLED; - } - // This method is replaced by frontend code in order to delay performing the // process switch until some async operatin is completed. //