Commit e5ecb22e authored by Igor Oliveira's avatar Igor Oliveira Committed by Arthur Edelstein
Browse files

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
parent 91f1c5de
......@@ -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
......
......@@ -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,
......
......@@ -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();
......
......@@ -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
......
......@@ -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) {
......
......@@ -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;
}
}
......
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"];
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment