From 6557402e1086a0295709c9372f2fadd1fb001901 Mon Sep 17 00:00:00 2001 From: Paul Bone Date: Thu, 16 Jan 2020 03:52:46 +0000 Subject: [PATCH] Bug 1597154 - pt 3. Defer to documentchannel for process switching for all schemes r=mattwoodrow Differential Revision: https://phabricator.services.mozilla.com/D58899 --HG-- extra : moz-landing-system : lando --- docshell/base/nsDocShell.cpp | 2 ++ toolkit/modules/E10SUtils.jsm | 51 +++++++++++++++++++++++++---------- 2 files changed, 39 insertions(+), 14 deletions(-) diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index c25f2637ffd4..f9ec5054f7c8 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -9374,6 +9374,8 @@ static bool IsConsideredSameOriginForUIR(nsIPrincipal* aTriggeringPrincipal, return NS_OK; } +// Changes here should also be made in +// E10SUtils.documentChannelPermittedForURI(). static bool SchemeUsesDocChannel(nsIURI* aURI) { if (SchemeIsJavascript(aURI) || NS_IsAboutBlank(aURI)) { return false; diff --git a/toolkit/modules/E10SUtils.jsm b/toolkit/modules/E10SUtils.jsm index 3a2c7bb8f87b..1f557df25321 100644 --- a/toolkit/modules/E10SUtils.jsm +++ b/toolkit/modules/E10SUtils.jsm @@ -137,7 +137,22 @@ const kSafeSchemes = [ "xmpp", ]; -const kDocumentChannelAllowedSchemes = ["http", "https", "ftp", "data"]; +const kDocumentChannelDeniedSchemes = ["javascript"]; +const kDocumentChannelDeniedURIs = [ + "about:blank", + "about:printpreview", + "about:privatebrowsing", + "about:crashcontent", +]; + +// Changes here should also be made in SchemeUsesDocChannel in +// nsDocShell.cpp. +function documentChannelPermittedForURI(aURI) { + return ( + !kDocumentChannelDeniedSchemes.includes(aURI.scheme) && + !kDocumentChannelDeniedURIs.includes(aURI.spec) + ); +} // Note that even if the scheme fits the criteria for a web-handled scheme // (ie it is compatible with the checks registerProtocolHandler uses), it may @@ -724,9 +739,10 @@ var E10SUtils = { // for now, and let DocumentChannel do it during the response. if ( currentRemoteType != NOT_REMOTE && + requiredRemoteType != NOT_REMOTE && uriObject && (remoteSubframes || documentChannel) && - kDocumentChannelAllowedSchemes.includes(uriObject.scheme) + documentChannelPermittedForURI(uriObject) ) { mustChangeProcess = false; } @@ -788,18 +804,6 @@ var E10SUtils = { return false; } - // If we are using DocumentChannel or remote subframes (fission), and - // are loading a HTTP URI, we can start the load in the current - // process, and then perform the switch later-on using the - // RedirectProcessChooser mechanism. - if ( - Services.appinfo.remoteType != NOT_REMOTE && - (useRemoteSubframes || documentChannel) && - kDocumentChannelAllowedSchemes.includes(aURI.scheme) - ) { - return true; - } - // If we are in a Large-Allocation process, and it wouldn't be content visible // to change processes, we want to load into a new process so that we can throw // this one out. We don't want to move into a new process if we have post data, @@ -841,6 +845,25 @@ var E10SUtils = { ); } + // If we are using DocumentChannel or remote subframes (fission), we + // can start the load in the current process, and then perform the + // switch later-on using the nsIProcessSwitchRequestor mechanism. + let wantRemoteType = this.getRemoteTypeForURIObject( + aURI, + true, + useRemoteSubframes, + Services.appinfo.remoteType, + webNav.currentURI + ); + if ( + (useRemoteSubframes || documentChannel) && + Services.appinfo.remoteType != NOT_REMOTE && + wantRemoteType != NOT_REMOTE && + documentChannelPermittedForURI(aURI) + ) { + return true; + } + // If the URI can be loaded in the current process then continue return this.shouldLoadURIInThisProcess(aURI, useRemoteSubframes); },