[tor-commits] [torbutton/master] Bug 26100: Load extension preferences during initialization
gk at torproject.org
gk at torproject.org
Fri May 25 06:13:17 UTC 2018
commit e5ecb22e0f4bfec84935f8266cc1520642301660
Author: Igor Oliveira <igt0 at torproject.org>
Date: Mon May 14 17:56:18 2018 -0300
Bug 26100: Load extension preferences during initialization
Mozilla removed the code that loads the default extension
preferences[1].
Thus we need to load them in the startup time.
[1] https://bugzilla.mozilla.org/show_bug.cgi?id=1413413
---
src/chrome/content/torbutton.js | 8 ++++----
src/components/cookie-jar-selector.js | 4 ++++
src/components/domain-isolator.js | 11 ++++++++---
src/components/dragDropFilter.js | 2 ++
src/components/startup-observer.js | 9 ++++++---
src/components/torbutton-logger.js | 19 ++++++++++---------
src/modules/default-prefs.js | 30 ++++++++++++++++++++++++++++++
7 files changed, 64 insertions(+), 19 deletions(-)
diff --git a/src/chrome/content/torbutton.js b/src/chrome/content/torbutton.js
index cf39dc2..40d63fd 100644
--- a/src/chrome/content/torbutton.js
+++ b/src/chrome/content/torbutton.js
@@ -1217,7 +1217,7 @@ function torbutton_do_new_identity() {
torbutton_log(3, "New Identity: Syncing prefs");
// Force prefs to be synced to disk
- m_tb_prefs.savePrefFile(null);
+ Services.prefs.savePrefFile(null);
torbutton_log(3, "New Identity: Clearing permissions");
@@ -1634,7 +1634,7 @@ function torbutton_update_disk_prefs() {
} catch (e) {}
// Force prefs to be synced to disk
- m_tb_prefs.savePrefFile(null);
+ Services.prefs.savePrefFile(null);
}
function torbutton_update_fingerprinting_prefs() {
@@ -1667,7 +1667,7 @@ function torbutton_update_fingerprinting_prefs() {
m_tb_prefs.setBoolPref("extensions.torbutton.resize_new_windows", mode);
// Force prefs to be synced to disk
- m_tb_prefs.savePrefFile(null);
+ Services.prefs.savePrefFile(null);
}
function torbutton_update_isolation_prefs() {
@@ -1682,7 +1682,7 @@ function torbutton_update_isolation_prefs() {
m_tb_prefs.setBoolPref("security.enable_tls_session_tickets", !isolate);
// Force prefs to be synced to disk
- m_tb_prefs.savePrefFile(null);
+ Services.prefs.savePrefFile(null);
}
// This function closes all XUL browser windows except this one. For this
diff --git a/src/components/cookie-jar-selector.js b/src/components/cookie-jar-selector.js
index 4f137d7..8456da3 100644
--- a/src/components/cookie-jar-selector.js
+++ b/src/components/cookie-jar-selector.js
@@ -19,6 +19,10 @@ const kMODULE_CONTRACTID = "@torproject.org/cookie-jar-selector;1";
const kMODULE_CID = Components.ID("e6204253-b690-4159-bfe8-d4eedab6b3be");
const Cr = Components.results;
+const Cu = Components.utils;
+
+Cu.import("resource://torbutton/modules/default-prefs.js", {})
+ .ensureDefaultPrefs();
// XXX: Must match the definition in torcookie.js :/
function Cookie(number,name,value,isDomain,host,rawHost,HttpOnly,path,isSecure,isSession,
diff --git a/src/components/domain-isolator.js b/src/components/domain-isolator.js
index a52cccc..a698439 100644
--- a/src/components/domain-isolator.js
+++ b/src/components/domain-isolator.js
@@ -16,6 +16,12 @@ const Cc = Components.classes, Ci = Components.interfaces, Cu = Components.utils
let logger = Cc["@torproject.org/torbutton-logger;1"]
.getService(Components.interfaces.nsISupports).wrappedJSObject;
+let { ensureDefaultPrefs } = Cu.import("resource://torbutton/modules/default-prefs.js", {});
+ensureDefaultPrefs();
+
+// Import Services object
+Cu.import("resource://gre/modules/Services.jsm");
+
// Import crypto object (FF 37+).
Cu.importGlobalProperties(["crypto"]);
@@ -165,6 +171,7 @@ Cu.import("resource://gre/modules/XPCOMUtils.jsm");
function DomainIsolator() {
this.wrappedJSObject = this;
}
+
// Firefox component requirements
DomainIsolator.prototype = {
QueryInterface: XPCOMUtils.generateQI([Ci.nsISupports, Ci.nsIObserver]),
@@ -175,9 +182,7 @@ DomainIsolator.prototype = {
if (topic === "profile-after-change") {
logger.eclog(3, "domain isolator: set up isolating circuits by domain");
- let prefs = Cc["@mozilla.org/preferences-service;1"]
- .getService(Ci.nsIPrefBranch);
- if (prefs.getBoolPref("extensions.torbutton.use_nontor_proxy")) {
+ if (Services.prefs.getBoolPref("extensions.torbutton.use_nontor_proxy")) {
tor.isolationEnabled = false;
}
tor.isolateCircuitsByDomain();
diff --git a/src/components/dragDropFilter.js b/src/components/dragDropFilter.js
index 22dde86..916b835 100644
--- a/src/components/dragDropFilter.js
+++ b/src/components/dragDropFilter.js
@@ -9,6 +9,8 @@ const Cc = Components.classes;
const Ci = Components.interfaces;
const Cu = Components.utils;
+Cu.import("resource://torbutton/modules/default-prefs.js", {}).ensureDefaultPrefs();
+
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
// Module specific constants
diff --git a/src/components/startup-observer.js b/src/components/startup-observer.js
index dac7aff..144d600 100644
--- a/src/components/startup-observer.js
+++ b/src/components/startup-observer.js
@@ -22,6 +22,7 @@ Cu.import("resource://gre/modules/XPCOMUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "FileUtils",
"resource://gre/modules/FileUtils.jsm");
+Cu.import("resource://torbutton/modules/default-prefs.js", {}).ensureDefaultPrefs();
// Module specific constants
const kMODULE_NAME = "Startup";
@@ -96,7 +97,9 @@ StartupObserver.prototype = {
let tlps = Cc["@torproject.org/torlauncher-protocol-service;1"]
.getService(Ci.nsISupports).wrappedJSObject;
socksPortInfo = tlps.TorGetSOCKSPortInfo();
- } catch(e) {}
+ } catch(e) {
+ this.logger.log(3, "tor launcher failed " + e);
+ }
// If Tor Launcher is not available, check environment variables.
if (!socksPortInfo) {
@@ -143,7 +146,7 @@ StartupObserver.prototype = {
}
// Force prefs to be synced to disk
- this._prefs.savePrefFile(null);
+ Services.prefs.savePrefFile(null);
this.logger.log(3, "Synced network settings to environment.");
},
@@ -158,7 +161,7 @@ StartupObserver.prototype = {
}
// In all cases, force prefs to be synced to disk
- this._prefs.savePrefFile(null);
+ Services.prefs.savePrefFile(null);
},
QueryInterface: function(iid) {
diff --git a/src/components/torbutton-logger.js b/src/components/torbutton-logger.js
index 18a5f1e..b25d039 100644
--- a/src/components/torbutton-logger.js
+++ b/src/components/torbutton-logger.js
@@ -16,17 +16,18 @@ const kMODULE_CID = Components.ID("f36d72c9-9718-4134-b550-e109638331d7");
const Cr = Components.results;
const Cc = Components.classes;
const Ci = Components.interfaces;
+const Cu = Components.utils;
-function TorbuttonLogger() {
- this.prefs = Components.classes["@mozilla.org/preferences-service;1"]
- .getService(Components.interfaces.nsIPrefBranch);
+Cu.import("resource://torbutton/modules/default-prefs.js", {}).ensureDefaultPrefs();
+
+Cu.import("resource://gre/modules/Services.jsm");
+function TorbuttonLogger() {
// Register observer
- this._branch = this.prefs.QueryInterface(Components.interfaces.nsIPrefBranch);
- this._branch.addObserver("extensions.torbutton", this, false);
+ Services.prefs.addObserver("extensions.torbutton", this, false);
- this.loglevel = this.prefs.getIntPref("extensions.torbutton.loglevel");
- this.logmethod = this.prefs.getIntPref("extensions.torbutton.logmethod");
+ this.loglevel = Services.prefs.getIntPref("extensions.torbutton.loglevel");
+ this.logmethod = Services.prefs.getIntPref("extensions.torbutton.logmethod");
try {
var logMngr = Components.classes["@mozmonkey.com/debuglogger/manager;1"]
@@ -152,10 +153,10 @@ TorbuttonLogger.prototype =
if (topic != "nsPref:changed") return;
switch (data) {
case "extensions.torbutton.logmethod":
- this.logmethod = this.prefs.getIntPref("extensions.torbutton.logmethod");
+ this.logmethod = Services.prefs.getIntPref("extensions.torbutton.logmethod");
break;
case "extensions.torbutton.loglevel":
- this.loglevel = this.prefs.getIntPref("extensions.torbutton.loglevel");
+ this.loglevel = Services.prefs.getIntPref("extensions.torbutton.loglevel");
break;
}
}
diff --git a/src/modules/default-prefs.js b/src/modules/default-prefs.js
new file mode 100644
index 0000000..d4c948f
--- /dev/null
+++ b/src/modules/default-prefs.js
@@ -0,0 +1,30 @@
+let loaded = false;
+
+function ensureDefaultPrefs () {
+ if (loaded) {
+ return;
+ }
+ Components.utils.import("resource://gre/modules/Services.jsm");
+ const kDefaultPreferences = "resource://torbutton/defaults/preferences/preferences.js";
+ const defaultPrefBranch = Services.prefs.getDefaultBranch(null);
+
+ const context = {
+ pref: function (aPrefName, aValue) {
+ const aValueType = typeof aValue;
+ if (aValueType === "boolean") {
+ defaultPrefBranch.setBoolPref(aPrefName, aValue);
+ } else if (aValueType === "number") {
+ defaultPrefBranch.setIntPref(aPrefName, aValue);
+ } else if (aValueType === "string") {
+ defaultPrefBranch.setCharPref(aPrefName, aValue);
+ } else {
+ Services.console.logStringMessage(
+ `Preference ${aPrefName} with value ${aValue} has an invalid value type`);
+ }
+ }
+ };
+ Services.scriptloader.loadSubScript(kDefaultPreferences, context);
+ loaded = true;
+}
+
+let EXPORTED_SYMBOLS = ["ensureDefaultPrefs"];
More information about the tor-commits
mailing list