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
--- 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.
*/
/**
* Used when the tools should be loaded from the Firefox package itself.
* This is the default case.
*/