Bug 1472491: Part 5u - Add URIFixupChild actor. r=gijs draft
authorKris Maglione <maglione.k@gmail.com>
Sun, 29 Jul 2018 22:30:34 -0700
changeset 828456 4781eff0b24e5e425c46f905da301dc420e989e4
parent 828455 fab2ba86bb392f4deb6a28fa8a6701f39ca95281
child 828457 491517ca82f6f0fbb4354c58d22415d906386b25
push id118680
push usermaglione.k@gmail.com
push dateFri, 10 Aug 2018 23:04:22 +0000
reviewersgijs
bugs1472491
milestone63.0a1
Bug 1472491: Part 5u - Add URIFixupChild actor. r=gijs MozReview-Commit-ID: IqFGfjXhc6z
browser/actors/URIFixupChild.jsm
browser/actors/moz.build
browser/base/content/tab-content.js
browser/components/nsBrowserGlue.js
new file mode 100644
--- /dev/null
+++ b/browser/actors/URIFixupChild.jsm
@@ -0,0 +1,37 @@
+/* vim: set ts=2 sw=2 sts=2 et tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+"use strict";
+
+var EXPORTED_SYMBOLS = ["URIFixupChild"];
+
+ChromeUtils.import("resource://gre/modules/ActorChild.jsm");
+
+class URIFixupChild extends ActorChild {
+  observe(subject) {
+    let fixupInfo = subject.QueryInterface(Ci.nsIURIFixupInfo);
+    if (!fixupInfo.consumer) {
+      return;
+    }
+
+    // Ignore info from other docshells
+    let parent = fixupInfo.consumer.QueryInterface(Ci.nsIDocShellTreeItem).sameTypeRootTreeItem;
+    if (parent != this.mm.docShell)
+      return;
+
+    let data = {};
+    for (let f of Object.keys(fixupInfo)) {
+      if (f == "consumer" || typeof fixupInfo[f] == "function")
+        continue;
+
+      if (fixupInfo[f] && fixupInfo[f] instanceof Ci.nsIURI) {
+        data[f] = fixupInfo[f].spec;
+      } else {
+        data[f] = fixupInfo[f];
+      }
+    }
+
+    this.mm.sendAsyncMessage("Browser:URIFixup", data);
+  }
+}
--- a/browser/actors/moz.build
+++ b/browser/actors/moz.build
@@ -25,9 +25,10 @@ FINAL_TARGET_FILES.actors += [
     'ContextMenuChild.jsm',
     'DOMFullscreenChild.jsm',
     'LightWeightThemeInstallChild.jsm',
     'NetErrorChild.jsm',
     'OfflineAppsChild.jsm',
     'PageInfoChild.jsm',
     'PageStyleChild.jsm',
     'PluginChild.jsm',
+    'URIFixupChild.jsm',
 ]
--- a/browser/base/content/tab-content.js
+++ b/browser/base/content/tab-content.js
@@ -56,46 +56,16 @@ addEventListener("pageshow", function({ 
 
 // Keep a reference to the translation content handler to avoid it it being GC'ed.
 var trHandler = null;
 if (Services.prefs.getBoolPref("browser.translation.detectLanguage")) {
   ChromeUtils.import("resource:///modules/translation/TranslationContentHandler.jsm");
   trHandler = new TranslationContentHandler(global, docShell);
 }
 
-function gKeywordURIFixup(fixupInfo) {
-  fixupInfo.QueryInterface(Ci.nsIURIFixupInfo);
-  if (!fixupInfo.consumer) {
-    return;
-  }
-
-  // Ignore info from other docshells
-  let parent = fixupInfo.consumer.QueryInterface(Ci.nsIDocShellTreeItem).sameTypeRootTreeItem;
-  if (parent != docShell)
-    return;
-
-  let data = {};
-  for (let f of Object.keys(fixupInfo)) {
-    if (f == "consumer" || typeof fixupInfo[f] == "function")
-      continue;
-
-    if (fixupInfo[f] && fixupInfo[f] instanceof Ci.nsIURI) {
-      data[f] = fixupInfo[f].spec;
-    } else {
-      data[f] = fixupInfo[f];
-    }
-  }
-
-  sendAsyncMessage("Browser:URIFixup", data);
-}
-Services.obs.addObserver(gKeywordURIFixup, "keyword-uri-fixup");
-addEventListener("unload", () => {
-  Services.obs.removeObserver(gKeywordURIFixup, "keyword-uri-fixup");
-}, false);
-
 var WebBrowserChrome = {
   onBeforeLinkTraversal(originalTarget, linkURI, linkNode, isAppTab) {
     return BrowserUtils.onBeforeLinkTraversal(originalTarget, linkURI, linkNode, isAppTab);
   },
 
   // Check whether this URI should load in the current process
   shouldLoadURI(aDocShell, aURI, aReferrer, aHasPostData, aTriggeringPrincipal) {
     if (!E10SUtils.shouldLoadURI(aDocShell, aURI, aReferrer, aHasPostData)) {
--- a/browser/components/nsBrowserGlue.js
+++ b/browser/components/nsBrowserGlue.js
@@ -204,16 +204,24 @@ let ACTORS = {
         "BrowserPlugins:Test:ClearCrashData",
       ],
 
       observers: [
         "decoder-doctor-notification",
       ],
     },
   },
+
+  URIFixup: {
+    child: {
+      module: "resource:///actors/URIFixupChild.jsm",
+      group: "browsers",
+      observers: ["keyword-uri-fixup"],
+    },
+  },
 };
 
 (function earlyBlankFirstPaint() {
   if (!Services.prefs.getBoolPref("browser.startup.blankWindow", false))
     return;
 
   let store = Services.xulStore;
   let getValue = attr =>