Skip to content

Commit 76799bf

Browse files
committed
Apply haviah's patch (correctly rewrite URLs passed on the commandline)
This should close https://trac.torproject.org/projects/tor/ticket/3533
1 parent 33a1dc1 commit 76799bf

File tree

2 files changed

+43
-28
lines changed

2 files changed

+43
-28
lines changed

src/chrome/content/code/HTTPSRules.js

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ RuleSet.prototype = {
141141
};
142142

143143
const RuleWriter = {
144-
addonDir: false,
145144

146145
getCustomRuleDir: function() {
147146
var loc = "ProfD"; // profile directory
@@ -161,21 +160,47 @@ const RuleWriter = {
161160
return file;
162161
},
163162

163+
chromeToPath: function (aPath) {
164+
if (!aPath || !(/^chrome:/.test(aPath)))
165+
return; //not a chrome url
166+
167+
var ios =
168+
CC['@mozilla.org/network/io-service;1']
169+
.getService(CI.nsIIOService);
170+
var uri = ios.newURI(aPath, "UTF-8", null);
171+
var cr =
172+
CC['@mozilla.org/chrome/chrome-registry;1']
173+
.getService(CI.nsIChromeRegistry);
174+
var rv = cr.convertChromeURL(uri).spec;
175+
176+
if (/^file:/.test(rv))
177+
rv = this.urlToPath(rv);
178+
else
179+
rv = this.urlToPath("file://"+rv);
180+
181+
return rv;
182+
},
183+
184+
urlToPath: function (aPath) {
185+
if (!aPath || !/^file:/.test(aPath))
186+
return ;
187+
188+
var ph =
189+
CC["@mozilla.org/network/protocol;1?name=file"]
190+
.createInstance(CI.nsIFileProtocolHandler);
191+
var rv = ph.getFileFromURLSpec(aPath).path;
192+
193+
return rv;
194+
},
195+
164196
getRuleDir: function() {
165-
if (!this.addonDir)
166-
try {
167-
// Firefox < 4
168-
this.addonDir = CC["@mozilla.org/extensions/manager;1"].
169-
getService(CI.nsIExtensionManager).
170-
getInstallLocation("https-everywhere@eff.org").
171-
getItemFile("https-everywhere@eff.org", "");
172-
} catch(e) {
173-
// Firefox >= 4 (this should not be reached)
174-
}
175-
var file = this.addonDir.clone();
176-
file.append("chrome");
177-
file.append("content");
178-
file.append("rules");
197+
loc = "chrome://https-everywhere/content/rules/";
198+
199+
var file =
200+
CC["@mozilla.org/file/local;1"]
201+
.createInstance(CI.nsILocalFile);
202+
file.initWithPath(this.chromeToPath(loc));
203+
179204
if (!file.isDirectory()) {
180205
// XXX: Arg, death!
181206
this.log(WARN,"Catastrophic failure: extension directory is not a directory");

src/components/https-everywhere.js

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -448,19 +448,9 @@ HTTPSEverywhere.prototype = {
448448
dls.addProgressListener(this, CI.nsIWebProgress.NOTIFY_STATE_REQUEST |
449449
CI.nsIWebProgress.NOTIFY_LOCATION);
450450
this.log(INFO,"ChannelReplacement.supported = "+ChannelReplacement.supported);
451-
try {
452-
// Firefox >= 4
453-
Components.utils.import("resource://gre/modules/AddonManager.jsm");
454-
AddonManager.getAddonByID("https-everywhere@eff.org",
455-
function(addon) {
456-
RuleWriter.addonDir = addon.
457-
getResourceURI("").QueryInterface(CI.nsIFileURL).file;
458-
HTTPSRules.init();
459-
});
460-
} catch(e) {
461-
// Firefox < 4
462-
HTTPSRules.init();
463-
}
451+
452+
HTTPSRules.init();
453+
464454
Thread.hostRunning = true;
465455
var catman = Components.classes["@mozilla.org/categorymanager;1"]
466456
.getService(Components.interfaces.nsICategoryManager);

0 commit comments

Comments
 (0)