Bug 1479313: Don't load manifestMessages.js until needed. r=felipe
authorKris Maglione <maglione.k@gmail.com>
Sun, 29 Jul 2018 13:18:26 -0700
changeset 429724 f5d647fae9733c5a19f53539fc6702de2a7fbbab
parent 429723 d403426d1dcdd7b7cd5b51e62b7b71c5d69631a3
child 429725 177e4adb94d1b63002577995deed230ba15624f8
push id34372
push usernerli@mozilla.com
push dateThu, 02 Aug 2018 08:55:28 +0000
treeherdermozilla-central@bd79b07f57a3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfelipe
bugs1479313
milestone63.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 1479313: Don't load manifestMessages.js until needed. r=felipe MozReview-Commit-ID: s2fq6XcgQ7
browser/base/content/browser.js
browser/base/content/tab-content.js
dom/ipc/ManifestMessages.jsm
dom/ipc/jar.mn
dom/ipc/manifestMessages.js
dom/ipc/moz.build
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -1316,17 +1316,16 @@ var gBrowserInit = {
     TrackingProtection.init();
     CaptivePortalWatcher.init();
     ZoomUI.init(window);
 
     let mm = window.getGroupMessageManager("browsers");
     mm.loadFrameScript("chrome://browser/content/tab-content.js", true);
     mm.loadFrameScript("chrome://browser/content/content.js", true);
     mm.loadFrameScript("chrome://global/content/content-HybridContentTelemetry.js", true);
-    mm.loadFrameScript("chrome://global/content/manifestMessages.js", true);
 
     window.messageManager.addMessageListener("Browser:LoadURI", RedirectLoad);
 
     if (!gMultiProcessBrowser) {
       // There is a Content:Click message manually sent from content.
       Services.els.addSystemEventListener(gBrowser.tabpanels, "click",
         contentAreaClick, true);
     }
--- a/browser/base/content/tab-content.js
+++ b/browser/base/content/tab-content.js
@@ -85,16 +85,22 @@ addMessageListener("Browser:Reload", fun
 
 addMessageListener("MixedContent:ReenableProtection", function() {
   docShell.mixedContentChannel = null;
 });
 
 XPCOMUtils.defineLazyProxy(this, "LightweightThemeChildHelper",
   "resource:///modules/LightweightThemeChildHelper.jsm");
 
+XPCOMUtils.defineLazyProxy(this, "ManifestMessages", () => {
+  let tmp = {};
+  ChromeUtils.import("resource://gre/modules/ManifestMessages.jsm", tmp);
+  return new tmp.ManifestMessages(global);
+});
+
 let themeablePagesWhitelist = new Set([
   "about:home",
   "about:newtab",
   "about:welcome",
 ]);
 
 addEventListener("pageshow", function({ originalTarget }) {
   if (originalTarget.defaultView == content && themeablePagesWhitelist.has(content.document.documentURI)) {
@@ -512,8 +518,13 @@ addEventListener("MozAfterPaint", functi
 
 // Remove this once bug 1397365 is fixed.
 addEventListener("MozAfterPaint", function onFirstNonBlankPaint() {
   if (content.document.documentURI == "about:blank" && !content.opener)
     return;
   removeEventListener("MozAfterPaint", onFirstNonBlankPaint);
   sendAsyncMessage("Browser:FirstNonBlankPaint");
 });
+
+addMessageListener("DOM:WebManifest:hasManifestLink", ManifestMessages);
+addMessageListener("DOM:ManifestObtainer:Obtain", ManifestMessages);
+addMessageListener("DOM:Manifest:FireAppInstalledEvent", ManifestMessages);
+addMessageListener("DOM:WebManifest:fetchIcon", ManifestMessages);
rename from dom/ipc/manifestMessages.js
rename to dom/ipc/ManifestMessages.jsm
--- a/dom/ipc/manifestMessages.js
+++ b/dom/ipc/ManifestMessages.jsm
@@ -6,109 +6,107 @@
  * http://www.w3.org/TR/appmanifest/#obtaining
  *
  * It searches a top-level browsing context for
  * a <link rel=manifest> element. Then fetches
  * and processes the linked manifest.
  *
  * BUG: https://bugzilla.mozilla.org/show_bug.cgi?id=1083410
  */
-/*globals Task, ManifestObtainer, ManifestFinder, content, sendAsyncMessage, addMessageListener, Components*/
 "use strict";
-const {
-  utils: Cu,
-} = Components;
+
+var EXPORTED_SYMBOLS = ["ManifestMessages"];
+
 ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
 
 ChromeUtils.defineModuleGetter(this, "ManifestObtainer",
-				  "resource://gre/modules/ManifestObtainer.jsm");
+                               "resource://gre/modules/ManifestObtainer.jsm");
 ChromeUtils.defineModuleGetter(this, "ManifestFinder",
-				  "resource://gre/modules/ManifestFinder.jsm");
+                               "resource://gre/modules/ManifestFinder.jsm");
 ChromeUtils.defineModuleGetter(this, "ManifestIcons",
-				  "resource://gre/modules/ManifestIcons.jsm");
+                               "resource://gre/modules/ManifestIcons.jsm");
+
+class ManifestMessages {
+  constructor(mm) {
+    this.mm = mm;
+  }
 
-const MessageHandler = {
-  registerListeners() {
-    addMessageListener(
-      "DOM:WebManifest:hasManifestLink",
-      this.hasManifestLink.bind(this)
-    );
-    addMessageListener(
-      "DOM:ManifestObtainer:Obtain",
-      this.obtainManifest.bind(this)
-    );
-    addMessageListener(
-      "DOM:Manifest:FireAppInstalledEvent",
-      this.fireAppInstalledEvent.bind(this)
-    );
-    addMessageListener(
-      "DOM:WebManifest:fetchIcon",
-      this.fetchIcon.bind(this)
-    );
-  },
+  receiveMessage(message) {
+    switch (message.name) {
+    case "DOM:WebManifest:hasManifestLink":
+      return this.hasManifestLink(message);
+    case "DOM:ManifestObtainer:Obtain":
+      return this.obtainManifest(message);
+    case "DOM:Manifest:FireAppInstalledEvent":
+      return this.fireAppInstalledEvent(message);
+    case "DOM:WebManifest:fetchIcon":
+      return this.fetchIcon(message);
+    }
+    return undefined;
+  }
 
   /**
-   * Check if the content document includes a link to a web manifest.
+   * Check if the this.mm.content document includes a link to a web manifest.
    * @param {Object} aMsg The IPC message, which is destructured to just
    *                      get the id.
    */
   hasManifestLink({data: {id}}) {
     const response = makeMsgResponse(id);
-    response.result = ManifestFinder.contentHasManifestLink(content);
+    response.result = ManifestFinder.contentHasManifestLink(this.mm.content);
     response.success = true;
-    sendAsyncMessage("DOM:WebManifest:hasManifestLink", response);
-  },
+    this.mm.sendAsyncMessage("DOM:WebManifest:hasManifestLink", response);
+  }
 
   /**
-   * Asynchronously obtains a web manifest from content by using the
+   * Asynchronously obtains a web manifest from this.mm.content by using the
    * ManifestObtainer and messages back the result.
    * @param {Object} aMsg The IPC message, which is destructured to just
    *                      get the id.
    */
   async obtainManifest({data: {id}}) {
     const response = makeMsgResponse(id);
     try {
-      response.result = await ManifestObtainer.contentObtainManifest(content);
+      response.result = await ManifestObtainer.contentObtainManifest(this.mm.content);
       response.success = true;
     } catch (err) {
       response.result = serializeError(err);
     }
-    sendAsyncMessage("DOM:ManifestObtainer:Obtain", response);
-  },
+    this.mm.sendAsyncMessage("DOM:ManifestObtainer:Obtain", response);
+  }
 
-  fireAppInstalledEvent({data: {id}}){
+  fireAppInstalledEvent({data: {id}}) {
     const ev = new Event("appinstalled");
     const response = makeMsgResponse(id);
-    if (!content || content.top !== content) {
+    if (!this.mm.content || this.mm.content.top !== this.mm.content) {
       const msg = "Can only dispatch install event on top-level browsing contexts.";
       response.result = serializeError(new Error(msg));
     } else {
       response.success = true;
-      content.dispatchEvent(ev);
+      this.mm.content.dispatchEvent(ev);
     }
-    sendAsyncMessage("DOM:Manifest:FireAppInstalledEvent", response);
-  },
+    this.mm.sendAsyncMessage("DOM:Manifest:FireAppInstalledEvent", response);
+  }
 
   /**
    * Given a manifest and an expected icon size, ask ManifestIcons
    * to fetch the appropriate icon and send along result
    */
   async fetchIcon({data: {id, manifest, iconSize}}) {
     const response = makeMsgResponse(id);
     try {
       response.result =
-        await ManifestIcons.contentFetchIcon(content, manifest, iconSize);
+        await ManifestIcons.contentFetchIcon(this.mm.content, manifest, iconSize);
       response.success = true;
     } catch (err) {
       response.result = serializeError(err);
     }
-    sendAsyncMessage("DOM:WebManifest:fetchIcon", response);
-  },
+    this.mm.sendAsyncMessage("DOM:WebManifest:fetchIcon", response);
+  }
+}
 
-};
 /**
  * Utility function to Serializes an JS Error, so it can be transferred over
  * the message channel.
  * FIX ME: https://bugzilla.mozilla.org/show_bug.cgi?id=1172586
  * @param  {Error} aError The error to serialize.
  * @return {Object} The serialized object.
  */
 function serializeError(aError) {
@@ -119,16 +117,14 @@ function serializeError(aError) {
     "stack": aError.stack,
     "message": aError.message,
     "name": aError.name
   };
   return clone;
 }
 
 function makeMsgResponse(aId) {
-    return {
-      id: aId,
-      success: false,
-      result: undefined
-    };
-  }
-
-MessageHandler.registerListeners();
+  return {
+    id: aId,
+    success: false,
+    result: undefined
+  };
+}
--- a/dom/ipc/jar.mn
+++ b/dom/ipc/jar.mn
@@ -3,9 +3,8 @@
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 toolkit.jar:
         content/global/test-ipc.xul (test.xul)
         content/global/remote-test-ipc.js (remote-test.js)
         content/global/BrowserElementChild.js (../browser-element/BrowserElementChild.js)
         content/global/BrowserElementChildPreload.js (../browser-element/BrowserElementChildPreload.js)
         content/global/BrowserElementCopyPaste.js (../browser-element/BrowserElementCopyPaste.js)
-        content/global/manifestMessages.js (manifestMessages.js)
--- a/dom/ipc/moz.build
+++ b/dom/ipc/moz.build
@@ -8,16 +8,20 @@ with Files("**"):
     BUG_COMPONENT = ("Core", "DOM: Content Processes")
 
 XPIDL_SOURCES += [
     'nsIHangReport.idl',
 ]
 
 XPIDL_MODULE = 'dom'
 
+EXTRA_JS_MODULES += [
+    'ManifestMessages.jsm',
+]
+
 EXPORTS.mozilla.dom.ipc += [
     'IdType.h',
     'MemMapSnapshot.h',
     'SharedMap.h',
     'SharedMapChangeEvent.h',
     'SharedStringMap.h',
     'StringTable.h',
     'StructuredCloneData.h',