Bug 1479310: Don't load content-UITour.js until needed. r=Mossop
authorKris Maglione <maglione.k@gmail.com>
Sun, 29 Jul 2018 12:36:45 -0700
changeset 430426 332b27e88d1199d89c419c9ae0fc276dfa4afaad
parent 430425 d1c733c33be923a49a5f968a838323810f45fee8
child 430427 d9e6ce390607ad8c227adc2ad2ff3cac89a814bc
child 430461 ffcc2ae2ef834a3ebc36d18b35c5f2156dd04843
push id34403
push usercbrindusan@mozilla.com
push dateTue, 07 Aug 2018 21:52:23 +0000
treeherdermozilla-central@d9e6ce390607 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMossop
bugs1479310
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 1479310: Don't load content-UITour.js until needed. r=Mossop MozReview-Commit-ID: 55EPBxUYv9o
browser/base/content/browser.js
browser/components/uitour/ContentUITour.jsm
browser/components/uitour/content-UITour.js
browser/components/uitour/jar.mn
browser/components/uitour/moz.build
toolkit/content/browser-content.js
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -1314,17 +1314,16 @@ var gBrowserInit = {
     FeedHandler.init();
     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://browser/content/content-UITour.js", true);
     mm.loadFrameScript("chrome://global/content/content-HybridContentTelemetry.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);
rename from browser/components/uitour/content-UITour.js
rename to browser/components/uitour/ContentUITour.jsm
--- a/browser/components/uitour/content-UITour.js
+++ b/browser/components/uitour/ContentUITour.jsm
@@ -1,35 +1,39 @@
 /* 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/. */
 
-/* eslint-env mozilla/frame-script */
+var EXPORTED_SYMBOLS = ["UITourListener"];
 
 ChromeUtils.import("resource://gre/modules/Services.jsm");
 
 const PREF_TEST_WHITELIST = "browser.uitour.testingOrigins";
 const UITOUR_PERMISSION   = "uitour";
 
-var UITourListener = {
+class UITourListener {
+  constructor(mm) {
+    this.mm = mm;
+  }
+
   handleEvent(event) {
     if (!Services.prefs.getBoolPref("browser.uitour.enabled")) {
       return;
     }
     if (!this.ensureTrustedOrigin()) {
       return;
     }
-    addMessageListener("UITour:SendPageCallback", this);
-    addMessageListener("UITour:SendPageNotification", this);
-    sendAsyncMessage("UITour:onPageEvent", {
+    this.mm.addMessageListener("UITour:SendPageCallback", this);
+    this.mm.addMessageListener("UITour:SendPageNotification", this);
+    this.mm.sendAsyncMessage("UITour:onPageEvent", {
       detail: event.detail,
       type: event.type,
-      pageVisibilityState: content.document.visibilityState,
+      pageVisibilityState: this.mm.content.document.visibilityState,
     });
-  },
+  }
 
   isTestingOrigin(aURI) {
     if (Services.prefs.getPrefType(PREF_TEST_WHITELIST) != Services.prefs.PREF_STRING) {
       return false;
     }
 
     // Add any testing origins (comma-seperated) to the whitelist for the session.
     for (let origin of Services.prefs.getCharPref(PREF_TEST_WHITELIST).split(",")) {
@@ -38,68 +42,68 @@ var UITourListener = {
         if (aURI.prePath == testingURI.prePath) {
           return true;
         }
       } catch (ex) {
         Cu.reportError(ex);
       }
     }
     return false;
-  },
+  }
 
   // This function is copied from UITour.jsm.
   isSafeScheme(aURI) {
     let allowedSchemes = new Set(["https", "about"]);
     if (!Services.prefs.getBoolPref("browser.uitour.requireSecure"))
       allowedSchemes.add("http");
 
     if (!allowedSchemes.has(aURI.scheme))
       return false;
 
     return true;
-  },
+  }
 
   ensureTrustedOrigin() {
+    let {content} = this.mm;
+
     if (content.top != content)
       return false;
 
     let uri = content.document.documentURIObject;
 
     if (uri.schemeIs("chrome"))
       return true;
 
     if (!this.isSafeScheme(uri))
       return false;
 
     let permission = Services.perms.testPermission(uri, UITOUR_PERMISSION);
     if (permission == Services.perms.ALLOW_ACTION)
       return true;
 
     return this.isTestingOrigin(uri);
-  },
+  }
 
   receiveMessage(aMessage) {
     switch (aMessage.name) {
       case "UITour:SendPageCallback":
         this.sendPageEvent("Response", aMessage.data);
         break;
       case "UITour:SendPageNotification":
         this.sendPageEvent("Notification", aMessage.data);
         break;
       }
-  },
+  }
 
   sendPageEvent(type, detail) {
     if (!this.ensureTrustedOrigin()) {
       return;
     }
 
-    let doc = content.document;
+    let win = this.mm.content;
     let eventName = "mozUITour" + type;
-    let event = new doc.defaultView.CustomEvent(eventName, {
+    let event = new win.CustomEvent(eventName, {
       bubbles: true,
-      detail: Cu.cloneInto(detail, doc.defaultView)
+      detail: Cu.cloneInto(detail, win),
     });
-    doc.dispatchEvent(event);
+    win.document.dispatchEvent(event);
   }
-};
-
-addEventListener("mozUITour", UITourListener, false, true);
+}
deleted file mode 100644
--- a/browser/components/uitour/jar.mn
+++ /dev/null
@@ -1,6 +0,0 @@
-# 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/.
-
-browser.jar:
-       content/browser/content-UITour.js
--- a/browser/components/uitour/moz.build
+++ b/browser/components/uitour/moz.build
@@ -1,16 +1,15 @@
 # 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/.
 
 EXTRA_JS_MODULES += [
+    'ContentUITour.jsm',
     'UITour.jsm',
 ]
 
-JAR_MANIFESTS += ['jar.mn']
-
 BROWSER_CHROME_MANIFESTS += [
     'test/browser.ini',
 ]
 
 with Files('**'):
     BUG_COMPONENT = ('Firefox', 'Tours')
--- a/toolkit/content/browser-content.js
+++ b/toolkit/content/browser-content.js
@@ -32,16 +32,28 @@ XPCOMUtils.defineLazyServiceGetter(this,
 var global = this;
 
 XPCOMUtils.defineLazyProxy(this, "PopupBlocking", () => {
   let tmp = {};
   ChromeUtils.import("resource://gre/modules/PopupBlocking.jsm", tmp);
   return new tmp.PopupBlocking(global);
 });
 
+XPCOMUtils.defineLazyProxy(this, "ShieldFrameListener", () => {
+  let tmp = {};
+  ChromeUtils.import("resource://normandy-content/ShieldFrameListener.jsm", tmp);
+  return new tmp.ShieldFrameListener(global);
+});
+
+XPCOMUtils.defineLazyProxy(this, "UITourListener", () => {
+  let tmp = {};
+  ChromeUtils.import("resource:///modules/ContentUITour.jsm", tmp);
+  return new tmp.UITourListener(global);
+});
+
 XPCOMUtils.defineLazyProxy(this, "SelectionSourceContent",
   "resource://gre/modules/SelectionSourceContent.jsm");
 
 XPCOMUtils.defineLazyProxy(this, "WebChannelContent",
   "resource://gre/modules/WebChannelContent.jsm");
 
 XPCOMUtils.defineLazyProxy(this, "DateTimePickerContent", () => {
   let tmp = {};
@@ -428,8 +440,12 @@ let ExtFind = {
       case "ext-Finder:clearHighlighting":
         this._findContent.highlighter.highlight(false);
         break;
     }
   },
 };
 
 ExtFind.init();
+
+addEventListener("ShieldPageEvent", ShieldFrameListener, false, true);
+
+addEventListener("mozUITour", UITourListener, false, true);