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

--HG--
extra : rebase_source : 86bfef7e13ecf52b9b8c761fbf7352af42a6bced
This commit is contained in:
Julian Descottes 2017-07-21 16:05:19 +02:00
parent b001b4a3ea
commit 346099c99a
2 changed files with 16 additions and 8 deletions

View file

@ -10,10 +10,6 @@
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
@ -50,10 +46,7 @@ function unload(reason) {
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

View file

@ -16,6 +16,21 @@ var { requireRawId } = Cu.import("resource://devtools/shared/loader-plugin-raw.j
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.
*/