[Pkg-mozext-commits] [requestpolicy] 121/280: [refact] introducing `PrefManager`
David Prévot
taffit at moszumanska.debian.org
Sat May 2 20:30:09 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 bbae80cadd9e1ba0fa12ad0f7ab046c3bf904462
Author: Martin Kimmerle <dev at 256k.de>
Date: Tue Jan 6 15:51:27 2015 +0100
[refact] introducing `PrefManager`
This module is the first to be loaded and initialized in the
main environment.
---
src/content/lib/default-prefs-initializer.js | 42 --------
src/content/lib/process-environment.jsm | 21 +++-
src/content/main/pref-manager.jsm | 137 +++++++++++++++++++++++++++
src/content/main/requestpolicy-service.jsm | 28 ------
4 files changed, 154 insertions(+), 74 deletions(-)
diff --git a/src/content/lib/default-prefs-initializer.js b/src/content/lib/default-prefs-initializer.js
index 60dc970..77a62c7 100644
--- a/src/content/lib/default-prefs-initializer.js
+++ b/src/content/lib/default-prefs-initializer.js
@@ -112,45 +112,3 @@ try {
"chrome://requestpolicy/content/lib/default-preferences.js",
defaultPrefScriptScope);
} catch (e) {}
-
-
-//
-// Do what else to do on startup.
-//
-
-var rpPrefBranch = Services.prefs.getBranch("extensions.requestpolicy.")
- .QueryInterface(Ci.nsIPrefBranch2);
-var rootPrefBranch = Services.prefs.getBranch("")
- .QueryInterface(Ci.nsIPrefBranch2);
-
-// Disable link prefetch.
-if (rpPrefBranch.getBoolPref("prefetch.link.disableOnStartup")) {
- if (rootPrefBranch.getBoolPref("network.prefetch-next")) {
- rootPrefBranch.setBoolPref("network.prefetch-next", false);
- //dump("Disabled link prefetch.\n");
- }
-}
-// Disable DNS prefetch.
-if (rpPrefBranch.getBoolPref("prefetch.dns.disableOnStartup")) {
- // network.dns.disablePrefetch only exists starting in Firefox 3.1 (and it
- // doesn't have a default value, at least in 3.1b2, but if and when it
- // does have a default it will be false).
- if (!rootPrefBranch.prefHasUserValue("network.dns.disablePrefetch") ||
- !rootPrefBranch.getBoolPref("network.dns.disablePrefetch")) {
- rootPrefBranch.setBoolPref("network.dns.disablePrefetch", true);
- //dump("Disabled DNS prefetch.\n");
- }
-}
-
-// Clean up old, unused prefs (removed in 0.2.0).
-let deletePrefs = [
- "temporarilyAllowedOrigins",
- "temporarilyAllowedDestinations",
- "temporarilyAllowedOriginsToDestinations"
-];
-for (var i = 0; i < deletePrefs.length; i++) {
- if (rpPrefBranch.prefHasUserValue(deletePrefs[i])) {
- rpPrefBranch.clearUserPref(deletePrefs[i]);
- }
-}
-Services.prefs.savePrefFile(null);
diff --git a/src/content/lib/process-environment.jsm b/src/content/lib/process-environment.jsm
index 6cb4c35..3c37d50 100644
--- a/src/content/lib/process-environment.jsm
+++ b/src/content/lib/process-environment.jsm
@@ -113,14 +113,27 @@ if (ProcessEnvironment.isMainProcess) {
// ProcessEnvironment says "You can't load me, I didn't
// finish yet!"
{
- // At first initialize the preferences. Its scope doesn't need to be
- // remembered.
- Services.scriptloader.loadSubScript("chrome://requestpolicy/content/lib/"+
- "default-prefs-initializer.js", {});
+ // =======================================================================
+ // The following section is not optimal – read on…
+ // -----------------------------------------------
+
+ // load init PrefManager before anything else is loaded!
+ // the reason is that the Logger expects the prefs to be initialized
+ // and available already.
+ let {PrefManager} = ScriptLoader.importModule("main/pref-manager");
+ PrefManager.init();
+
+ // TODO: use the Browser Console for logging, see #563.
+ // *Then* it's no longer necessary to load and init PrefManager
+ // first. PrefManager will then be loaded and initialized when all
+ // other back end modules are loaded / initialized.
// import the Logger as the first module so that its startup-function
// will be called after this one
ScriptLoader.importModule("lib/logger", globalScope);
+ // =======================================================================
+
+ // import main modules:
ScriptLoader.importModules([
"main/requestpolicy-service",
"lib/content-policy",
diff --git a/src/content/main/pref-manager.jsm b/src/content/main/pref-manager.jsm
new file mode 100644
index 0000000..3a8582e
--- /dev/null
+++ b/src/content/main/pref-manager.jsm
@@ -0,0 +1,137 @@
+/*
+ * ***** BEGIN LICENSE BLOCK *****
+ *
+ * RequestPolicy - A Firefox extension for control over cross-site requests.
+ * Copyright (c) 2008-2012 Justin Samuel
+ * Copyright (c) 2014-2015 Martin Kimmerle
+ *
+ * This program is free software: you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later
+ * version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * ***** END LICENSE BLOCK *****
+ */
+
+const Ci = Components.interfaces;
+const Cc = Components.classes;
+const Cu = Components.utils;
+
+let EXPORTED_SYMBOLS = ["PrefManager"];
+
+let globalScope = this;
+
+Cu.import("resource://gre/modules/Services.jsm");
+Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+Cu.import("resource://gre/modules/devtools/Console.jsm");
+
+Cu.import("chrome://requestpolicy/content/lib/script-loader.jsm");
+ScriptLoader.importModules([
+ "lib/utils/constants",
+ "lib/process-environment"
+], globalScope);
+
+XPCOMUtils.defineLazyGetter(globalScope, "rpPrefBranch", function() {
+ return Services.prefs.getBranch("extensions.requestpolicy.")
+ .QueryInterface(Ci.nsIPrefBranch2);
+});
+XPCOMUtils.defineLazyGetter(globalScope, "rootPrefBranch", function() {
+ return Services.prefs.getBranch("").QueryInterface(Ci.nsIPrefBranch2);
+});
+
+
+
+
+
+let PrefManager = (function() {
+ let self = {};
+
+
+ // TODO: move to bootstrap.js
+ function handleUninstallOrDisable() {
+ console.info("Performing 'disable' operations.");
+ var resetLinkPrefetch = rpPrefBranch.getBoolPref(
+ "prefetch.link.restoreDefaultOnUninstall");
+ var resetDNSPrefetch = rpPrefBranch.getBoolPref(
+ "prefetch.dns.restoreDefaultOnUninstall");
+
+ if (resetLinkPrefetch) {
+ if (rootPrefBranch.prefHasUserValue("network.prefetch-next")) {
+ rootPrefBranch.clearUserPref("network.prefetch-next");
+ }
+ }
+ if (resetDNSPrefetch) {
+ if (rootPrefBranch.prefHasUserValue("network.dns.disablePrefetch")) {
+ rootPrefBranch.clearUserPref("network.dns.disablePrefetch");
+ }
+ }
+ Services.prefs.savePrefFile(null);
+ }
+
+
+ self.init = function() {
+ // ================================
+ // manually handle RP's default preferences
+ // ----------------------------------------
+ // The following script needs to be called because bootsrapped addons have
+ // to handle their default preferences manually, see Mozilla Bug 564675:
+ // https://bugzilla.mozilla.org/show_bug.cgi?id=564675
+ // The scope of that script doesn't need to be remembered.
+ Services.scriptloader.loadSubScript("chrome://requestpolicy/content/lib/"+
+ "default-prefs-initializer.js", {});
+ // ================================
+
+
+ // Disable link prefetch.
+ if (rpPrefBranch.getBoolPref("prefetch.link.disableOnStartup")) {
+ if (rootPrefBranch.getBoolPref("network.prefetch-next")) {
+ rootPrefBranch.setBoolPref("network.prefetch-next", false);
+ console.info("Disabled link prefetch.");
+ }
+ }
+ // Disable DNS prefetch.
+ if (rpPrefBranch.getBoolPref("prefetch.dns.disableOnStartup")) {
+ // network.dns.disablePrefetch only exists starting in Firefox 3.1 (and it
+ // doesn't have a default value, at least in 3.1b2, but if and when it
+ // does have a default it will be false).
+ if (!rootPrefBranch.prefHasUserValue("network.dns.disablePrefetch") ||
+ !rootPrefBranch.getBoolPref("network.dns.disablePrefetch")) {
+ rootPrefBranch.setBoolPref("network.dns.disablePrefetch", true);
+ console.info("Disabled DNS prefetch.");
+ }
+ }
+
+ // Clean up old, unused prefs (removed in 0.2.0).
+ let deletePrefs = [
+ "temporarilyAllowedOrigins",
+ "temporarilyAllowedDestinations",
+ "temporarilyAllowedOriginsToDestinations"
+ ];
+ for (var i = 0; i < deletePrefs.length; i++) {
+ if (rpPrefBranch.prefHasUserValue(deletePrefs[i])) {
+ rpPrefBranch.clearUserPref(deletePrefs[i]);
+ }
+ }
+
+ Services.prefs.savePrefFile(null);
+ };
+
+
+ ProcessEnvironment.pushShutdownFunction(function(data, reason) {
+ if (reason == C.ADDON_DISABLE || reason == C.ADDON_UNINSTALL) {
+ // TODO: Handle uninstallation in bootstrap.js, not here, RP might be
+ // disabled when being uninstalled.
+ handleUninstallOrDisable();
+ }
+ });
+
+ return self;
+}());
diff --git a/src/content/main/requestpolicy-service.jsm b/src/content/main/requestpolicy-service.jsm
index d0715f4..b90c49d 100644
--- a/src/content/main/requestpolicy-service.jsm
+++ b/src/content/main/requestpolicy-service.jsm
@@ -58,26 +58,6 @@ let rpService = (function() {
// Utility
// /////////////////////////////////////////////////////////////////////////
- function handleUninstallOrDisable() {
- Logger.debug(Logger.TYPE_INTERNAL, "Performing 'disable' operations.");
- var resetLinkPrefetch = rpPrefBranch.getBoolPref(
- "prefetch.link.restoreDefaultOnUninstall");
- var resetDNSPrefetch = rpPrefBranch.getBoolPref(
- "prefetch.dns.restoreDefaultOnUninstall");
-
- if (resetLinkPrefetch) {
- if (rootPrefBranch.prefHasUserValue("network.prefetch-next")) {
- rootPrefBranch.clearUserPref("network.prefetch-next");
- }
- }
- if (resetDNSPrefetch) {
- if (rootPrefBranch.prefHasUserValue("network.dns.disablePrefetch")) {
- rootPrefBranch.clearUserPref("network.dns.disablePrefetch");
- }
- }
- Services.prefs.savePrefFile(null);
- }
-
function loadConfigAndRules() {
subscriptions = new UserSubscriptions();
@@ -166,14 +146,6 @@ let rpService = (function() {
});
});
- ProcessEnvironment.pushShutdownFunction(function(data, reason) {
- if (reason == C.ADDON_DISABLE || reason == C.ADDON_UNINSTALL) {
- // TODO: Handle uninstallation in bootstrap.js, not here, RP might be
- // disabled when being uninstalled.
- handleUninstallOrDisable();
- }
- });
-
--
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