Bug 1400886 - Change BrowserCLH subscripts into modules; r?snorp draft
authorJim Chen <nchen@mozilla.com>
Tue, 19 Sep 2017 00:57:51 -0400
changeset 666753 c61e65416da03b46ebb0c2803f455c61160255d9
parent 666598 30a386ff1192cba08a2f899343f81f6946bc6148
child 666754 86def6799a4173bbda6be8a391f0774ca004a8f0
push id80490
push userbmo:nchen@mozilla.com
push dateTue, 19 Sep 2017 04:58:09 +0000
reviewerssnorp
bugs1400886
milestone57.0a1
Bug 1400886 - Change BrowserCLH subscripts into modules; r?snorp Change the subscripts (e.g. FormAssistant.js) that we load in BrowserCLH into proper .jsm modules. This avoids the `defineLazyScriptGetter` incompatibility mentioned in the bug, and when we turn on shared JSM global, any memory advantage we get from using subscripts should not matter anymore. MozReview-Commit-ID: krSwANdtb5
mobile/android/chrome/content/ActionBarHandler.js
mobile/android/chrome/content/FormAssistant.js
mobile/android/chrome/content/InputWidgetHelper.js
mobile/android/chrome/content/SelectHelper.js
mobile/android/chrome/content/WebrtcUI.js
mobile/android/chrome/jar.mn
mobile/android/components/BrowserCLH.js
mobile/android/modules/ActionBarHandler.jsm
mobile/android/modules/FormAssistant.jsm
mobile/android/modules/InputWidgetHelper.jsm
mobile/android/modules/SelectHelper.jsm
mobile/android/modules/WebrtcUI.jsm
mobile/android/modules/geckoview/GeckoViewUtils.jsm
mobile/android/modules/moz.build
--- a/mobile/android/chrome/jar.mn
+++ b/mobile/android/chrome/jar.mn
@@ -26,29 +26,24 @@ chrome.jar:
   content/browser.xul                  (content/browser.xul)
   content/browser.css                  (content/browser.css)
   content/browser.js                   (content/browser.js)
   content/PresentationView.xul         (content/PresentationView.xul)
   content/PresentationView.js          (content/PresentationView.js)
   content/bindings/checkbox.xml        (content/bindings/checkbox.xml)
   content/bindings/settings.xml        (content/bindings/settings.xml)
   content/netError.xhtml               (content/netError.xhtml)
-  content/SelectHelper.js              (content/SelectHelper.js)
-  content/ActionBarHandler.js          (content/ActionBarHandler.js)
   content/EmbedRT.js                   (content/EmbedRT.js)
-  content/InputWidgetHelper.js         (content/InputWidgetHelper.js)
-  content/WebrtcUI.js                  (content/WebrtcUI.js)
   content/MemoryObserver.js            (content/MemoryObserver.js)
   content/ConsoleAPI.js                (content/ConsoleAPI.js)
   content/PluginHelper.js              (content/PluginHelper.js)
   content/PrintHelper.js               (content/PrintHelper.js)
   content/OfflineApps.js               (content/OfflineApps.js)
   content/MasterPassword.js            (content/MasterPassword.js)
   content/FindHelper.js                (content/FindHelper.js)
-  content/FormAssistant.js             (content/FormAssistant.js)
   content/PermissionsHelper.js         (content/PermissionsHelper.js)
   content/FeedHandler.js               (content/FeedHandler.js)
   content/Feedback.js                  (content/Feedback.js)
   content/Linkify.js                   (content/Linkify.js)
   content/CastingApps.js               (content/CastingApps.js)
   content/RemoteDebugger.js            (content/RemoteDebugger.js)
 #ifdef MOZ_SERVICES_HEALTHREPORT
   content/aboutHealthReport.xhtml      (content/aboutHealthReport.xhtml)
--- a/mobile/android/components/BrowserCLH.js
+++ b/mobile/android/components/BrowserCLH.js
@@ -1,33 +1,24 @@
 /* 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";
 
 const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
 
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 
 XPCOMUtils.defineLazyModuleGetters(this, {
   AppConstants: "resource://gre/modules/AppConstants.jsm",
   DelayedInit: "resource://gre/modules/DelayedInit.jsm",
-  EventDispatcher: "resource://gre/modules/Messaging.jsm",
   GeckoViewUtils: "resource://gre/modules/GeckoViewUtils.jsm",
   Services: "resource://gre/modules/Services.jsm",
 });
 
-var Strings = {};
-
-XPCOMUtils.defineLazyGetter(Strings, "brand", _ =>
-        Services.strings.createBundle("chrome://branding/locale/brand.properties"));
-XPCOMUtils.defineLazyGetter(Strings, "browser", _ =>
-        Services.strings.createBundle("chrome://browser/locale/browser.properties"));
-XPCOMUtils.defineLazyGetter(Strings, "reader", _ =>
-        Services.strings.createBundle("chrome://global/locale/aboutReader.properties"));
-
 function BrowserCLH() {
   this.wrappedJSObject = this;
 }
 
 BrowserCLH.prototype = {
   /**
    * Register resource://android as the APK root.
    *
@@ -55,37 +46,37 @@ BrowserCLH.prototype = {
         GeckoViewUtils.addLazyGetter(this, "DownloadNotifications", {
           module: "resource://gre/modules/DownloadNotifications.jsm",
           observers: ["chrome-document-loaded"],
           once: true,
         });
 
         if (AppConstants.MOZ_WEBRTC) {
           GeckoViewUtils.addLazyGetter(this, "WebrtcUI", {
-            script: "chrome://browser/content/WebrtcUI.js",
+            module: "resource://gre/modules/WebrtcUI.jsm",
             observers: [
               "getUserMedia:ask-device-permission",
               "getUserMedia:request",
               "PeerConnection:request",
               "recording-device-events",
               "VideoCapture:Paused",
               "VideoCapture:Resumed",
             ],
           });
         }
 
         GeckoViewUtils.addLazyGetter(this, "SelectHelper", {
-          script: "chrome://browser/content/SelectHelper.js",
+          module: "resource://gre/modules/SelectHelper.jsm",
         });
         GeckoViewUtils.addLazyGetter(this, "InputWidgetHelper", {
-          script: "chrome://browser/content/InputWidgetHelper.js",
+          module: "resource://gre/modules/InputWidgetHelper.jsm",
         });
 
         GeckoViewUtils.addLazyGetter(this, "FormAssistant", {
-          script: "chrome://browser/content/FormAssistant.js",
+          module: "resource://gre/modules/FormAssistant.jsm",
         });
         Services.obs.addObserver({
           QueryInterface: XPCOMUtils.generateQI([
             Ci.nsIObserver, Ci.nsIFormSubmitObserver,
           ]),
           notifyInvalidSubmit: (form, element) => {
             this.FormAssistant.notifyInvalidSubmit(form, element);
           },
@@ -104,17 +95,17 @@ BrowserCLH.prototype = {
             // PLEASE KEEP THIS LIST IN SYNC WITH THE DESKTOP LIST IN nsBrowserGlue.js
           ],
         });
         GeckoViewUtils.addLazyGetter(this, "LoginManagerContent", {
           module: "resource://gre/modules/LoginManagerContent.jsm",
         });
 
         GeckoViewUtils.addLazyGetter(this, "ActionBarHandler", {
-          script: "chrome://browser/content/ActionBarHandler.js",
+          module: "resource://gre/modules/ActionBarHandler.jsm",
         });
 
         // Once the first chrome window is loaded, schedule a list of startup
         // tasks to be performed on idle.
         GeckoViewUtils.addLazyGetter(this, "DelayedStartup", {
           observers: ["chrome-document-loaded"],
           once: true,
           handler: _ => DelayedInit.scheduleList([
rename from mobile/android/chrome/content/ActionBarHandler.js
rename to mobile/android/modules/ActionBarHandler.jsm
--- a/mobile/android/chrome/content/ActionBarHandler.js
+++ b/mobile/android/modules/ActionBarHandler.jsm
@@ -1,23 +1,37 @@
 // -*- indent-tabs-mode: nil; js-indent-level: 2 -*-
 /* 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";
 
+const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
+
+this.EXPORTED_SYMBOLS = ["ActionBarHandler"];
+
+Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+
 XPCOMUtils.defineLazyModuleGetters(this, {
+  EventDispatcher: "resource://gre/modules/Messaging.jsm",
+  GeckoViewUtils: "resource://gre/modules/GeckoViewUtils.jsm",
   PrivateBrowsingUtils: "resource://gre/modules/PrivateBrowsingUtils.jsm",
+  Services: "resource://gre/modules/Services.jsm",
   Snackbars: "resource://gre/modules/Snackbars.jsm",
   UITelemetry: "resource://gre/modules/UITelemetry.jsm",
 });
 
 XPCOMUtils.defineLazyServiceGetter(this, "ParentalControls",
   "@mozilla.org/parental-controls-service;1", "nsIParentalControlsService");
 
+var Strings = {};
+
+XPCOMUtils.defineLazyGetter(Strings, "browser", _ =>
+        Services.strings.createBundle("chrome://browser/locale/browser.properties"));
+
 const PHONE_REGEX = /^\+?[0-9\s,-.\(\)*#pw]{1,30}$/; // Are we a phone #?
 
 /**
  * ActionBarHandler Object and methods. Interface between Gecko Text Selection code
  * (AccessibleCaret, etc) and the Mobile ActionBar UI.
  */
 var ActionBarHandler = {
   // Error codes returned from _init().
rename from mobile/android/chrome/content/FormAssistant.js
rename to mobile/android/modules/FormAssistant.jsm
--- a/mobile/android/chrome/content/FormAssistant.js
+++ b/mobile/android/modules/FormAssistant.jsm
@@ -1,15 +1,24 @@
 /* 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";
 
-XPCOMUtils.defineLazyModuleGetter(this, "FormHistory", "resource://gre/modules/FormHistory.jsm");
+const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
+
+this.EXPORTED_SYMBOLS = ["FormAssistant"];
+
+Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+
+XPCOMUtils.defineLazyModuleGetters(this, {
+  FormHistory: "resource://gre/modules/FormHistory.jsm",
+  GeckoViewUtils: "resource://gre/modules/GeckoViewUtils.jsm",
+  Services: "resource://gre/modules/Services.jsm",
+});
 
 var FormAssistant = {
   // Weak-ref used to keep track of the currently focused element.
   _currentFocusedElement: null,
 
   // Whether we're in the middle of an autocomplete.
   _doingAutocomplete: false,
 
rename from mobile/android/chrome/content/InputWidgetHelper.js
rename to mobile/android/modules/InputWidgetHelper.jsm
--- a/mobile/android/chrome/content/InputWidgetHelper.js
+++ b/mobile/android/modules/InputWidgetHelper.jsm
@@ -1,15 +1,23 @@
 /* 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";
 
-XPCOMUtils.defineLazyModuleGetter(this, "Prompt",
-                                  "resource://gre/modules/Prompt.jsm");
+const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
+
+this.EXPORTED_SYMBOLS = ["InputWidgetHelper"];
+
+Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+
+XPCOMUtils.defineLazyModuleGetters(this, {
+  Prompt: "resource://gre/modules/Prompt.jsm",
+  Services: "resource://gre/modules/Services.jsm",
+});
 
 var InputWidgetHelper = {
   _uiBusy: false,
 
   strings: function() {
     if (!this._strings) {
       this._strings = Services.strings.createBundle(
           "chrome://browser/locale/browser.properties");
rename from mobile/android/chrome/content/SelectHelper.js
rename to mobile/android/modules/SelectHelper.jsm
--- a/mobile/android/chrome/content/SelectHelper.js
+++ b/mobile/android/modules/SelectHelper.jsm
@@ -1,15 +1,23 @@
 /* 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";
 
-XPCOMUtils.defineLazyModuleGetter(this, "Prompt",
-                                  "resource://gre/modules/Prompt.jsm");
+const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
+
+this.EXPORTED_SYMBOLS = ["SelectHelper"];
+
+Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+
+XPCOMUtils.defineLazyModuleGetters(this, {
+  Prompt: "resource://gre/modules/Prompt.jsm",
+  Services: "resource://gre/modules/Services.jsm",
+});
 
 var SelectHelper = {
   _uiBusy: false,
 
   strings: function() {
     if (!this._strings) {
       this._strings = Services.strings.createBundle(
           "chrome://browser/locale/browser.properties");
rename from mobile/android/chrome/content/WebrtcUI.js
rename to mobile/android/modules/WebrtcUI.jsm
--- a/mobile/android/chrome/content/WebrtcUI.js
+++ b/mobile/android/modules/WebrtcUI.jsm
@@ -1,22 +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/. */
 "use strict";
 
+const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
+
 this.EXPORTED_SYMBOLS = ["WebrtcUI"];
 
-XPCOMUtils.defineLazyServiceGetter(this, "MediaManagerService", "@mozilla.org/mediaManagerService;1", "nsIMediaManagerService");
-XPCOMUtils.defineLazyModuleGetter(this, "Notifications", "resource://gre/modules/Notifications.jsm");
-XPCOMUtils.defineLazyServiceGetter(this, "ParentalControls", "@mozilla.org/parental-controls-service;1", "nsIParentalControlsService");
-XPCOMUtils.defineLazyModuleGetter(this, "RuntimePermissions", "resource://gre/modules/RuntimePermissions.jsm");
+Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+
+XPCOMUtils.defineLazyModuleGetters(this, {
+  DoorHanger: "resource://gre/modules/Prompt.jsm",
+  Notifications: "resource://gre/modules/Notifications.jsm",
+  RuntimePermissions: "resource://gre/modules/RuntimePermissions.jsm",
+  Services: "resource://gre/modules/Services.jsm",
+});
 
-XPCOMUtils.defineLazyModuleGetter(this, "DoorHanger",
-                                  "resource://gre/modules/Prompt.jsm");
+XPCOMUtils.defineLazyServiceGetter(this, "MediaManagerService",
+                                   "@mozilla.org/mediaManagerService;1",
+                                   "nsIMediaManagerService");
+XPCOMUtils.defineLazyServiceGetter(this, "ParentalControls",
+                                   "@mozilla.org/parental-controls-service;1",
+                                   "nsIParentalControlsService");
+
+var Strings = {};
+
+XPCOMUtils.defineLazyGetter(Strings, "brand", _ =>
+        Services.strings.createBundle("chrome://branding/locale/brand.properties"));
+XPCOMUtils.defineLazyGetter(Strings, "browser", _ =>
+        Services.strings.createBundle("chrome://browser/locale/browser.properties"));
 
 var WebrtcUI = {
   _notificationId: null,
 
   // Add-ons can override stock permission behavior by doing:
   //
   //   var stockObserve = WebrtcUI.observe;
   //
--- a/mobile/android/modules/geckoview/GeckoViewUtils.jsm
+++ b/mobile/android/modules/geckoview/GeckoViewUtils.jsm
@@ -17,56 +17,51 @@ this.EXPORTED_SYMBOLS = ["GeckoViewUtils
 var GeckoViewUtils = {
   /**
    * Define a lazy getter that loads an object from external code, and
    * optionally handles observer and/or message manager notifications for the
    * object, so the object only loads when a notification is received.
    *
    * @param scope     Scope for holding the loaded object.
    * @param name      Name of the object to load.
-   * @param script    If specified, load the object from a JS subscript.
    * @param service   If specified, load the object from a JS component; the
    *                  component must include the line
    *                  "this.wrappedJSObject = this;" in its constructor.
    * @param module    If specified, load the object from a JS module.
-   * @param init      For non-scripts, optional post-load initialization function.
+   * @param init      Optional post-load initialization function.
    * @param observers If specified, listen to specified observer notifications.
    * @param ppmm      If specified, listen to specified process messages.
    * @param mm        If specified, listen to specified frame messages.
    * @param ged       If specified, listen to specified global EventDispatcher events.
    * @param once      if true, only listen to the specified
    *                  events/messages/notifications once.
    */
-  addLazyGetter: function(scope, name, {script, service, module, handler,
+  addLazyGetter: function(scope, name, {service, module, handler,
                                         observers, ppmm, mm, ged, init, once}) {
-    if (script) {
-      XPCOMUtils.defineLazyScriptGetter(scope, name, script);
-    } else {
-      XPCOMUtils.defineLazyGetter(scope, name, _ => {
-        let ret = undefined;
-        if (module) {
-          ret = Cu.import(module, {})[name];
-        } else if (service) {
-          ret = Cc[service].getService(Ci.nsISupports).wrappedJSObject;
-        } else if (typeof handler === "function") {
-          ret = {
-            handleEvent: handler,
-            observe: handler,
-            onEvent: handler,
-            receiveMessage: handler,
-          };
-        } else if (handler) {
-          ret = handler;
-        }
-        if (ret && init) {
-          init.call(scope, ret);
-        }
-        return ret;
-      });
-    }
+    XPCOMUtils.defineLazyGetter(scope, name, _ => {
+      let ret = undefined;
+      if (module) {
+        ret = Cu.import(module, {})[name];
+      } else if (service) {
+        ret = Cc[service].getService(Ci.nsISupports).wrappedJSObject;
+      } else if (typeof handler === "function") {
+        ret = {
+          handleEvent: handler,
+          observe: handler,
+          onEvent: handler,
+          receiveMessage: handler,
+        };
+      } else if (handler) {
+        ret = handler;
+      }
+      if (ret && init) {
+        init.call(scope, ret);
+      }
+      return ret;
+    });
 
     if (observers) {
       let observer = (subject, topic, data) => {
         Services.obs.removeObserver(observer, topic);
         if (!once) {
           Services.obs.addObserver(scope[name], topic);
         }
         scope[name].observe(subject, topic, data); // Explicitly notify new observer
--- a/mobile/android/modules/moz.build
+++ b/mobile/android/modules/moz.build
@@ -16,30 +16,35 @@ with Files('HomeProvider.jsm'):
 
 with Files('geckoview/**'):
     BUG_COMPONENT = ('Firefox for Android', 'GeckoView')
 
 DIRS += ['geckoview']
 
 EXTRA_JS_MODULES += [
     'Accounts.jsm',
+    'ActionBarHandler.jsm',
     'BrowserActions.jsm',
     'dbg-browser-actors.js',
     'DelayedInit.jsm',
     'DownloadNotifications.jsm',
+    'FormAssistant.jsm',
     'FxAccountsWebChannel.jsm',
     'HelperApps.jsm',
     'Home.jsm',
     'HomeProvider.jsm',
+    'InputWidgetHelper.jsm',
     'JNI.jsm',
     'LightweightThemeConsumer.jsm',
     'MediaPlayerApp.jsm',
     'NetErrorHelper.jsm',
     'Notifications.jsm',
     'PageActions.jsm',
     'Prompt.jsm',
     'RuntimePermissions.jsm',
     'Sanitizer.jsm',
+    'SelectHelper.jsm',
     'SharedPreferences.jsm',
     'Snackbars.jsm',
     'SSLExceptions.jsm',
+    'WebrtcUI.jsm',
     'WebsiteMetadata.jsm'
 ]