Bug 1369801 - dt-addon-prefs: load DevTools prefs when starting Loader.jsm;r=ochameau
authorJulian Descottes <jdescottes@mozilla.com>
Fri, 21 Jul 2017 16:05:19 +0200
changeset 419864 ad2a532a50f023a28490bf19659e9635abb99ffd
parent 419863 1b1a7c913f135d850a02899c30104e7db305378d
child 419865 d0ed0997f4e08e56d3e43d861987555ba7eae678
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersochameau
bugs1369801
milestone56.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 1369801 - dt-addon-prefs: load DevTools prefs when starting Loader.jsm;r=ochameau DevTools should not execute any code on the browser startup. Loading preferences takes a non negligeable time and should be deferred to the devtools initialization. For all devtools entry points, Loader.jsm is always loaded first, so it is safe to load the preferences here. MozReview-Commit-ID: Hg4VBj2LqPo
devtools/bootstrap.js
devtools/shared/Loader.jsm
--- a/devtools/bootstrap.js
+++ b/devtools/bootstrap.js
@@ -5,20 +5,16 @@
 /* global content, APP_SHUTDOWN */
 /* exported startup, shutdown, install, uninstall */
 
 "use strict";
 
 const Cu = Components.utils;
 const {Services} = Cu.import("resource://gre/modules/Services.jsm", {});
 
-XPCOMUtils.defineLazyGetter(this, "DevToolsPreferences", function () {
-  return Cu.import("chrome://devtools/content/preferences/DevToolsPreferences.jsm", {}).DevToolsPreferences;
-});
-
 function unload(reason) {
   // This frame script is going to be executed in all processes:
   // parent and child
   Services.ppmm.loadProcessScript("data:,(" + function (scriptReason) {
     /* Flush message manager cached frame scripts as well as chrome locales */
     let obs = Components.classes["@mozilla.org/observer-service;1"]
                         .getService(Components.interfaces.nsIObserverService);
     obs.notifyObservers(null, "message-manager-flush-caches");
@@ -45,20 +41,17 @@ function unload(reason) {
   Cu.unload("resource://devtools/shared/Parser.jsm");
   Cu.unload("resource://devtools/client/shared/DOMHelpers.jsm");
   Cu.unload("resource://devtools/client/shared/widgets/VariablesView.jsm");
   Cu.unload("resource://devtools/client/responsivedesign/responsivedesign.jsm");
   Cu.unload("resource://devtools/client/shared/widgets/AbstractTreeItem.jsm");
   Cu.unload("resource://devtools/shared/deprecated-sync-thenables.js");
 }
 
-function startup(data) {
-  // Load DevToolsPreferences as early as possible.
-  DevToolsPreferences.loadPrefs();
-}
+function startup(data) {}
 
 function shutdown(data, reason) {
   // On browser shutdown, do not try to cleanup anything
   if (reason == APP_SHUTDOWN) {
     return;
   }
 
   unload("disable");
--- a/devtools/shared/Loader.jsm
+++ b/devtools/shared/Loader.jsm
@@ -11,16 +11,31 @@
 var { utils: Cu } = Components;
 var { Services } = Cu.import("resource://gre/modules/Services.jsm", {});
 var { Loader, descriptor, resolveURI } = Cu.import("resource://gre/modules/commonjs/toolkit/loader.js", {});
 var { requireRawId } = Cu.import("resource://devtools/shared/loader-plugin-raw.jsm", {});
 
 this.EXPORTED_SYMBOLS = ["DevToolsLoader", "devtools", "BuiltinProvider",
                          "require", "loader"];
 
+// Fire an event to notify the DevTools addon bootstrap that DevTools are being
+// initialized. The loader is always the first entry point for all DevTools consumers.
+Services.obs.notifyObservers(null, "devtools-loader-starting");
+
+// Load DevToolsPreferences as soon as DevTools code starts being required.
+// With DevTools as an addon, the DevTools preferences need to be dynamically loaded.
+const isParentProcess =
+    Services.appinfo.processType === Services.appinfo.PROCESS_TYPE_DEFAULT;
+const isFirefox = Services.appinfo.ID == "{ec8030f7-c20a-464f-9b0e-13a3a9e97384}";
+if (isParentProcess && isFirefox) {
+  // Load client preferences if we are in Firefox's parent process only.
+  const {DevToolsPreferences} =
+    Cu.import("chrome://devtools/content/preferences/DevToolsPreferences.jsm", {});
+  DevToolsPreferences.loadPrefs();
+}
 /**
  * Providers are different strategies for loading the devtools.
  */
 
 var sharedGlobalBlocklist = ["sdk/indexed-db"];
 
 /**
  * Used when the tools should be loaded from the Firefox package itself.