Bug 1472212 - Rename E10SUtils.canLoadURIInProcess to E10SUtils.canLoadURIInRemoteType and modify it to accept an E10SUtils process type instead of a nsIXULRuntime process type. draft
authorJay Lim <jlim@mozilla.com>
Fri, 20 Jul 2018 18:02:45 -0400
changeset 827731 1d4eced245e4d0027aec35d373a86e6bfeb0f62f
parent 827730 93f3d65ae2aea06f43f66f44d391aeb9cdde728a
child 827732 1942fd4c56a0deb9f317fcfcfcbc9bcc9334abc0
child 828636 49e71e9cde714adf57b76f5648efd265f1706e28
push id118580
push userbmo:jay@imjching.com
push dateThu, 09 Aug 2018 03:02:02 +0000
bugs1472212
milestone63.0a1
Bug 1472212 - Rename E10SUtils.canLoadURIInProcess to E10SUtils.canLoadURIInRemoteType and modify it to accept an E10SUtils process type instead of a nsIXULRuntime process type. See next commit for more info. The idea is to use E10SUtils.canLoadURIInRemoteType to detect if a URI can load in a given E10SUtils process type. Having it to accept a nsIXULRuntime process type, which will be mapped back to an E10SUtils process type, is unnecessary. MozReview-Commit-ID: KeYkuRDyqXO
browser/base/content/test/general/browser_e10s_about_process.js
browser/base/content/test/general/browser_e10s_chrome_process.js
browser/base/content/test/general/browser_e10s_javascript.js
testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm
toolkit/content/tests/browser/browser_findbar.js
toolkit/modules/E10SUtils.jsm
toolkit/mozapps/extensions/content/extensions.js
--- a/browser/base/content/test/general/browser_e10s_about_process.js
+++ b/browser/base/content/test/general/browser_e10s_about_process.js
@@ -1,10 +1,10 @@
-const CHROME_PROCESS = Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT;
-const CONTENT_PROCESS = Ci.nsIXULRuntime.PROCESS_TYPE_CONTENT;
+const CHROME_PROCESS = E10SUtils.NOT_REMOTE;
+const WEB_CONTENT_PROCESS = E10SUtils.WEB_REMOTE_TYPE;
 
 const CHROME = {
   id: "cb34538a-d9da-40f3-b61a-069f0b2cb9fb",
   path: "test-chrome",
   flags: 0,
 };
 const CANREMOTE = {
   id: "2480d3e1-9ce4-4b84-8ae3-910b9a95cbb3",
@@ -74,36 +74,36 @@ add_task(async function init() {
 
 registerCleanupFunction(() => {
   let registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
   for (let module of TEST_MODULES) {
     registrar.unregisterFactory(Components.ID(module.id), AboutModuleFactory);
   }
 });
 
-function test_url(url, chromeResult, contentResult) {
-  is(E10SUtils.canLoadURIInProcess(url, CHROME_PROCESS),
+function test_url(url, chromeResult, webContentResult) {
+  is(E10SUtils.canLoadURIInRemoteType(url, CHROME_PROCESS),
      chromeResult, "Check URL in chrome process.");
-  is(E10SUtils.canLoadURIInProcess(url, CONTENT_PROCESS),
-     contentResult, "Check URL in content process.");
+  is(E10SUtils.canLoadURIInRemoteType(url, WEB_CONTENT_PROCESS),
+     webContentResult, "Check URL in web content process.");
 
-  is(E10SUtils.canLoadURIInProcess(url + "#foo", CHROME_PROCESS),
+  is(E10SUtils.canLoadURIInRemoteType(url + "#foo", CHROME_PROCESS),
      chromeResult, "Check URL with ref in chrome process.");
-  is(E10SUtils.canLoadURIInProcess(url + "#foo", CONTENT_PROCESS),
-     contentResult, "Check URL with ref in content process.");
+  is(E10SUtils.canLoadURIInRemoteType(url + "#foo", WEB_CONTENT_PROCESS),
+     webContentResult, "Check URL with ref in web content process.");
 
-  is(E10SUtils.canLoadURIInProcess(url + "?foo", CHROME_PROCESS),
+  is(E10SUtils.canLoadURIInRemoteType(url + "?foo", CHROME_PROCESS),
      chromeResult, "Check URL with query in chrome process.");
-  is(E10SUtils.canLoadURIInProcess(url + "?foo", CONTENT_PROCESS),
-     contentResult, "Check URL with query in content process.");
+  is(E10SUtils.canLoadURIInRemoteType(url + "?foo", WEB_CONTENT_PROCESS),
+     webContentResult, "Check URL with query in web content process.");
 
-  is(E10SUtils.canLoadURIInProcess(url + "?foo#bar", CHROME_PROCESS),
+  is(E10SUtils.canLoadURIInRemoteType(url + "?foo#bar", CHROME_PROCESS),
      chromeResult, "Check URL with query and ref in chrome process.");
-  is(E10SUtils.canLoadURIInProcess(url + "?foo#bar", CONTENT_PROCESS),
-     contentResult, "Check URL with query and ref in content process.");
+  is(E10SUtils.canLoadURIInRemoteType(url + "?foo#bar", WEB_CONTENT_PROCESS),
+     webContentResult, "Check URL with query and ref in web content process.");
 }
 
 add_task(async function test_chrome() {
   test_url("about:" + CHROME.path, true, false);
 });
 
 add_task(async function test_any() {
   test_url("about:" + CANREMOTE.path, true, true);
--- a/browser/base/content/test/general/browser_e10s_chrome_process.js
+++ b/browser/base/content/test/general/browser_e10s_chrome_process.js
@@ -27,52 +27,52 @@ function makeTest(name, startURL, startP
     }
     await docLoadedPromise;
 
     is(browser.currentURI.spec, endURL, "Should have made it to the final URL");
     is(browser.isRemoteBrowser, endProcessIsRemote, "Should be displayed in the right process");
   };
 }
 
-const CHROME_PROCESS = Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT;
-const CONTENT_PROCESS = Ci.nsIXULRuntime.PROCESS_TYPE_CONTENT;
+const CHROME_PROCESS = E10SUtils.NOT_REMOTE;
+const WEB_CONTENT_PROCESS = E10SUtils.WEB_REMOTE_TYPE;
 const PATH = (getRootDirectory(gTestPath) + "test_process_flags_chrome.html").replace("chrome://mochitests", "");
 
 const CHROME = "chrome://mochitests" + PATH;
 const CANREMOTE = "chrome://mochitests-any" + PATH;
 const MUSTREMOTE = "chrome://mochitests-content" + PATH;
 
 add_task(async function init() {
   gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser, "about:blank", {forceNotRemote: true});
 });
 
 registerCleanupFunction(() => {
   gBrowser.removeCurrentTab();
 });
 
 function test_url(url, chromeResult, contentResult) {
-  is(E10SUtils.canLoadURIInProcess(url, CHROME_PROCESS),
+  is(E10SUtils.canLoadURIInRemoteType(url, CHROME_PROCESS),
      chromeResult, "Check URL in chrome process.");
-  is(E10SUtils.canLoadURIInProcess(url, CONTENT_PROCESS),
-     contentResult, "Check URL in content process.");
+  is(E10SUtils.canLoadURIInRemoteType(url, WEB_CONTENT_PROCESS),
+     contentResult, "Check URL in web content process.");
 
-  is(E10SUtils.canLoadURIInProcess(url + "#foo", CHROME_PROCESS),
+  is(E10SUtils.canLoadURIInRemoteType(url + "#foo", CHROME_PROCESS),
      chromeResult, "Check URL with ref in chrome process.");
-  is(E10SUtils.canLoadURIInProcess(url + "#foo", CONTENT_PROCESS),
-     contentResult, "Check URL with ref in content process.");
+  is(E10SUtils.canLoadURIInRemoteType(url + "#foo", WEB_CONTENT_PROCESS),
+     contentResult, "Check URL with ref in web content process.");
 
-  is(E10SUtils.canLoadURIInProcess(url + "?foo", CHROME_PROCESS),
+  is(E10SUtils.canLoadURIInRemoteType(url + "?foo", CHROME_PROCESS),
      chromeResult, "Check URL with query in chrome process.");
-  is(E10SUtils.canLoadURIInProcess(url + "?foo", CONTENT_PROCESS),
-     contentResult, "Check URL with query in content process.");
+  is(E10SUtils.canLoadURIInRemoteType(url + "?foo", WEB_CONTENT_PROCESS),
+     contentResult, "Check URL with query in web content process.");
 
-  is(E10SUtils.canLoadURIInProcess(url + "?foo#bar", CHROME_PROCESS),
+  is(E10SUtils.canLoadURIInRemoteType(url + "?foo#bar", CHROME_PROCESS),
      chromeResult, "Check URL with query and ref in chrome process.");
-  is(E10SUtils.canLoadURIInProcess(url + "?foo#bar", CONTENT_PROCESS),
-     contentResult, "Check URL with query and ref in content process.");
+  is(E10SUtils.canLoadURIInRemoteType(url + "?foo#bar", WEB_CONTENT_PROCESS),
+     contentResult, "Check URL with query and ref in web content process.");
 }
 
 add_task(async function test_chrome() {
   test_url(CHROME, true, false);
 });
 
 add_task(async function test_any() {
   test_url(CANREMOTE, true, true);
--- a/browser/base/content/test/general/browser_e10s_javascript.js
+++ b/browser/base/content/test/general/browser_e10s_javascript.js
@@ -1,11 +1,11 @@
-const CHROME_PROCESS = Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT;
-const CONTENT_PROCESS = Ci.nsIXULRuntime.PROCESS_TYPE_CONTENT;
+const CHROME_PROCESS = E10SUtils.NOT_REMOTE;
+const WEB_CONTENT_PROCESS = E10SUtils.WEB_REMOTE_TYPE;
 
 add_task(async function() {
   let url = "javascript:dosomething()";
 
-  ok(E10SUtils.canLoadURIInProcess(url, CHROME_PROCESS),
+  ok(E10SUtils.canLoadURIInRemoteType(url, CHROME_PROCESS),
      "Check URL in chrome process.");
-  ok(E10SUtils.canLoadURIInProcess(url, CONTENT_PROCESS),
-     "Check URL in content process.");
+  ok(E10SUtils.canLoadURIInRemoteType(url, WEB_CONTENT_PROCESS),
+     "Check URL in web content process.");
 });
--- a/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm
+++ b/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm
@@ -585,22 +585,18 @@ var BrowserTestUtils = {
         let promises = [
           TestUtils.topicObserved("browser-delayed-startup-finished",
                                   subject => subject == win),
         ];
 
         if (url) {
           let browser = win.gBrowser.selectedBrowser;
 
-          // Retrieve the given browser's current process type.
-          let process =
-              browser.isRemoteBrowser ? Ci.nsIXULRuntime.PROCESS_TYPE_CONTENT
-              : Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT;
           if (win.gMultiProcessBrowser &&
-              !E10SUtils.canLoadURIInProcess(url, process)) {
+              !E10SUtils.canLoadURIInRemoteType(url, browser.remoteType)) {
             await this.waitForEvent(browser, "XULFrameLoaderCreated");
           }
 
           let loadPromise = this.browserLoaded(browser, false, url, maybeErrorPage);
           promises.push(loadPromise);
         }
 
         await Promise.all(promises);
@@ -631,24 +627,20 @@ var BrowserTestUtils = {
     // Load the new URI.
     browser.loadURI(uri);
 
     // Nothing to do in non-e10s mode.
     if (!browser.ownerGlobal.gMultiProcessBrowser) {
       return;
     }
 
-    // Retrieve the given browser's current process type.
-    let process = browser.isRemoteBrowser ? Ci.nsIXULRuntime.PROCESS_TYPE_CONTENT
-                                          : Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT;
-
     // If the new URI can't load in the browser's current process then we
     // should wait for the new frameLoader to be created. This will happen
     // asynchronously when the browser's remoteness changes.
-    if (!E10SUtils.canLoadURIInProcess(uri, process)) {
+    if (!E10SUtils.canLoadURIInRemoteType(uri, browser.remoteType)) {
       await this.waitForEvent(browser, "XULFrameLoaderCreated");
     }
   },
 
   /**
    * @param win (optional)
    *        The window we should wait to have "domwindowopened" sent through
    *        the observer service for. If this is not supplied, we'll just
--- a/toolkit/content/tests/browser/browser_findbar.js
+++ b/toolkit/content/tests/browser/browser_findbar.js
@@ -1,13 +1,13 @@
 /* eslint-disable mozilla/no-arbitrary-setTimeout */
 ChromeUtils.import("resource://gre/modules/Timer.jsm", this);
 
 const TEST_PAGE_URI = "data:text/html;charset=utf-8,The letter s.";
-// Using 'javascript' schema to bypass E10SUtils.canLoadURIInProcess, because
+// Using 'javascript' schema to bypass E10SUtils.canLoadURIInRemoteType, because
 // it does not allow 'data:' URI to be loaded in the parent process.
 const E10S_PARENT_TEST_PAGE_URI = "javascript:document.write('The letter s.');";
 
 /**
  * Makes sure that the findbar hotkeys (' and /) event listeners
  * are added to the system event group and do not get blocked
  * by calling stopPropagation on a keypress event on a page.
  */
--- a/toolkit/modules/E10SUtils.jsm
+++ b/toolkit/modules/E10SUtils.jsm
@@ -83,20 +83,24 @@ var E10SUtils = {
   DEFAULT_REMOTE_TYPE,
   NOT_REMOTE,
   WEB_REMOTE_TYPE,
   FILE_REMOTE_TYPE,
   EXTENSION_REMOTE_TYPE,
   PRIVILEGED_REMOTE_TYPE,
   LARGE_ALLOCATION_REMOTE_TYPE,
 
-  canLoadURIInProcess(aURL, aProcess) {
-    let remoteType = aProcess == Ci.nsIXULRuntime.PROCESS_TYPE_CONTENT
-                     ? DEFAULT_REMOTE_TYPE : NOT_REMOTE;
-    return remoteType == this.getRemoteTypeForURI(aURL, true, remoteType);
+  canLoadURIInRemoteType(aURL, aRemoteType = DEFAULT_REMOTE_TYPE) {
+    // We need a strict equality here because the value of `NOT_REMOTE` is
+    // `null`, and there is a possibility that `undefined` is passed as the
+    // second argument, which might result a load in the parent process.
+    let preferredRemoteType = aRemoteType === NOT_REMOTE
+      ? NOT_REMOTE
+      : DEFAULT_REMOTE_TYPE;
+    return aRemoteType == this.getRemoteTypeForURI(aURL, true, preferredRemoteType);
   },
 
   getRemoteTypeForURI(aURL, aMultiProcess,
                       aPreferredRemoteType = DEFAULT_REMOTE_TYPE,
                       aCurrentUri) {
     if (!aMultiProcess) {
       return NOT_REMOTE;
     }
--- a/toolkit/mozapps/extensions/content/extensions.js
+++ b/toolkit/mozapps/extensions/content/extensions.js
@@ -3038,20 +3038,19 @@ var gDetailView = {
       event.stopPropagation();
     });
 
     let {optionsURL, optionsBrowserStyle} = this._addon;
     if (this._addon.isWebExtension) {
       let policy = ExtensionParent.WebExtensionPolicy.getByID(this._addon.id);
       browser.sameProcessAsFrameLoader = policy.extension.groupFrameLoader;
     }
-    let remote = !E10SUtils.canLoadURIInProcess(optionsURL, Services.appinfo.PROCESS_TYPE_DEFAULT);
 
     let readyPromise;
-    if (remote) {
+    if (E10SUtils.canLoadURIInRemoteType(optionsURL, E10SUtils.EXTENSION_REMOTE_TYPE)) {
       browser.setAttribute("remote", "true");
       browser.setAttribute("remoteType", E10SUtils.EXTENSION_REMOTE_TYPE);
       readyPromise = promiseEvent("XULFrameLoaderCreated", browser);
     } else {
       readyPromise = promiseEvent("load", browser, true);
     }
 
     stack.appendChild(browser);