[Pkg-mozext-commits] [requestpolicy] 100/280: initialize preferences *before* earlier at startup
David Prévot
taffit at moszumanska.debian.org
Sat May 2 20:30:06 UTC 2015
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository requestpolicy.
commit c90413c02b33d82563feaec99374eb109965528b
Author: Martin Kimmerle <dev at 256k.de>
Date: Fri Jan 2 00:31:49 2015 +0100
initialize preferences *before* earlier at startup
Now the prefs are loaded/initialized explicitly early at
startup, before `Logger` is loaded. This means that the prefs
are directly available for Logger.
---
src/content/lib/bootstrap-manager.jsm | 9 +++-
...efs.manager.js => default-prefs-initializer.js} | 50 +++++-----------------
src/content/lib/logger.jsm | 21 ++-------
src/content/lib/prefs.jsm | 11 -----
4 files changed, 22 insertions(+), 69 deletions(-)
diff --git a/src/content/lib/bootstrap-manager.jsm b/src/content/lib/bootstrap-manager.jsm
index 4c6b0ed..36b4491 100644
--- a/src/content/lib/bootstrap-manager.jsm
+++ b/src/content/lib/bootstrap-manager.jsm
@@ -98,8 +98,13 @@ let BootstrapManager = (function() {
// which wouldn't be available if BootstrapManager is *itself* still being
// loaded. This would be an "import()-loop".
{
- // import the Logger first so that its startup-function will be called
- // after this one
+ // At first initialize the preferences. Its scope doesn't need to be
+ // remembered.
+ Services.scriptloader.loadSubScript(
+ "chrome://requestpolicy/content/lib/default-prefs-initializer.js",
+ {});
+ // import the Logger as the first module so that its startup-function
+ // will be called after this one
ScriptLoader.importModule("logger");
ScriptLoader.importModules(["requestpolicy-service", "window-manager",
"about-uri"], globalScope);
diff --git a/src/content/lib/prefs.manager.js b/src/content/lib/default-prefs-initializer.js
similarity index 78%
rename from src/content/lib/prefs.manager.js
rename to src/content/lib/default-prefs-initializer.js
index 994d479..60dc970 100644
--- a/src/content/lib/prefs.manager.js
+++ b/src/content/lib/default-prefs-initializer.js
@@ -20,19 +20,21 @@
* ***** END LICENSE BLOCK *****
*/
+// This file has to be called only once. It handles the default preferences [1],
+// so it has to be called quite early at the extension startup.
+//
+// Note that this script may *only* be loaded from the main process!
+// Also note that if possible this script shouldn't import any other of RP's
+// modules, e.g. to prevent import() loops.
+//
+// [1] https://developer.mozilla.org/en-US/Add-ons/How_to_convert_an_overlay_extension_to_restartless#Step_4.3A_Manually_handle_default_preferences
+
const Ci = Components.interfaces;
const Cc = Components.classes;
const Cu = Components.utils;
-const MMID = "requestpolicy at requestpolicy.com";
-
-let EXPORTED_SYMBOLS = [];
-
Cu.import("resource://gre/modules/Services.jsm");
-Cu.import("chrome://requestpolicy/content/lib/script-loader.jsm");
-ScriptLoader.importModules(["logger"], this);
-
let prefInitFunctions = {
@@ -125,7 +127,7 @@ var rootPrefBranch = Services.prefs.getBranch("")
if (rpPrefBranch.getBoolPref("prefetch.link.disableOnStartup")) {
if (rootPrefBranch.getBoolPref("network.prefetch-next")) {
rootPrefBranch.setBoolPref("network.prefetch-next", false);
- Logger.info(Logger.TYPE_INTERNAL, "Disabled link prefetch.");
+ //dump("Disabled link prefetch.\n");
}
}
// Disable DNS prefetch.
@@ -136,7 +138,7 @@ if (rpPrefBranch.getBoolPref("prefetch.dns.disableOnStartup")) {
if (!rootPrefBranch.prefHasUserValue("network.dns.disablePrefetch") ||
!rootPrefBranch.getBoolPref("network.dns.disablePrefetch")) {
rootPrefBranch.setBoolPref("network.dns.disablePrefetch", true);
- Logger.info(Logger.TYPE_INTERNAL, "Disabled DNS prefetch.");
+ //dump("Disabled DNS prefetch.\n");
}
}
@@ -152,33 +154,3 @@ for (var i = 0; i < deletePrefs.length; i++) {
}
}
Services.prefs.savePrefFile(null);
-
-
-function setPref(aPrefBranch, aPrefName, aDataType, aValue) {
- let functionName;
- switch (aDataType) {
- case Services.prefs.PREF_BOOL:
- functionName = "setBoolPref";
- break;
- case Services.prefs.PREF_INT:
- functionName = "setIntPref";
- break;
- case Services.prefs.PREF_STRING:
- default:
- functionName = "setCharPref";
- break;
- }
- aPrefBranch[functionName](aPrefName, aValue);
-}
-
-let globalMM = Cc["@mozilla.org/globalmessagemanager;1"]
- .getService(Ci.nsIMessageListenerManager);
-
-globalMM.addMessageListener(MMID + ":setPref", function(message) {
- let {name, dataType, value} = message.data;
- setPref(rpPrefBranch, name, dataType, value);
- });
-globalMM.addMessageListener(MMID + ":setRootPref", function(message) {
- let {name, dataType, value} = message.data;
- setPref(rootPrefBranch, name, dataType, value);
- });
diff --git a/src/content/lib/logger.jsm b/src/content/lib/logger.jsm
index f380f82..87d2533 100644
--- a/src/content/lib/logger.jsm
+++ b/src/content/lib/logger.jsm
@@ -30,7 +30,10 @@ let EXPORTED_SYMBOLS = ["Logger"];
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("chrome://requestpolicy/content/lib/script-loader.jsm");
-ScriptLoader.importModules(["bootstrap-manager"], this)
+ScriptLoader.importModules([
+ "bootstrap-manager",
+ "prefs"
+], this);
/**
@@ -76,7 +79,6 @@ let Logger = (function() {
let initialized = false;
- let rpPrefBranch = null;
// initially, enable logging. later the logging preferences of the user will
// will be loaded.
@@ -100,11 +102,6 @@ let Logger = (function() {
}
};
- function displayMessageNotInitiallized() {
- dump("[RequestPolicy] [INFO] [INTERNAL] preferences are not available " +
- "yet, so logging is still enabled.\n");
- }
-
/**
* init() is called by doLog() until initialization was successful.
* For the case that nothing is logged at all, init is registered as a
@@ -116,16 +113,6 @@ let Logger = (function() {
return;
}
- // Try to get rpPrefBranch.
- // That pref branch might not be available when init() is called, e.g. when
- // prefs.jsm logs something on initialization.
- let prefScope = ScriptLoader.importModule("prefs");
- if (!("rpPrefBranch" in prefScope)) {
- displayMessageNotInitiallized();
- // cancel init()
- return;
- }
- rpPrefBranch = prefScope.rpPrefBranch;
rpPrefBranch.addObserver("log", prefObserver, false);
updateLoggingSettings();
diff --git a/src/content/lib/prefs.jsm b/src/content/lib/prefs.jsm
index 825c36c..7f32da5 100644
--- a/src/content/lib/prefs.jsm
+++ b/src/content/lib/prefs.jsm
@@ -29,18 +29,7 @@ let EXPORTED_SYMBOLS = ['rpPrefBranch', 'rootPrefBranch', 'Prefs'];
Cu.import("resource://gre/modules/Services.jsm");
-Cu.import("chrome://requestpolicy/content/lib/script-loader.jsm");
-let {isMainProcess} = ScriptLoader.importModule("utils/process-info");
-let prefManagerScope = {};
-
-
-if (isMainProcess) {
- // if it's the main process (the chrome process). We will get here on startup.
- // initialize preferences:
- let uri = "chrome://requestpolicy/content/lib/prefs.manager.js";
- Services.scriptloader.loadSubScript(uri, prefManagerScope);
-}
let rpPrefBranch = Services.prefs.getBranch("extensions.requestpolicy.")
.QueryInterface(Ci.nsIPrefBranch2);
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/requestpolicy.git
More information about the Pkg-mozext-commits
mailing list