Skip to content

Commit f67a80f

Browse files
committed
Disable ContentPolicy callbacks, if channel.redirecTo() is available.
Fixes https://bugzilla.mozilla.org/show_bug.cgi?id=939180 This is implemented in 3.x by keeping the callbacks but not actually using them. For elegance and performance we should probably not register for them at all, but I'm a little unsure about whether the version-comparator service might take a while to appear during startup. 4.x has a better solution, which is to never register and simply be incompatible with FF < 20.
1 parent 83c1e5b commit f67a80f

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

src/components/https-everywhere.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -242,13 +242,21 @@ const shouldLoadTargets = {
242242

243243
// This defines for Mozilla what stuff HTTPSEverywhere will implement.
244244

245-
// We need to use both ContentPolicy and Observer, because there are some
246-
// things, such as Favicons, who don't get caught by ContentPolicy; we don't
247-
// yet know why we don't just use the observer :/
248-
245+
// For FF < 20, we need to use both ContentPolicy and Observer, because there
246+
// are some things, such as Favicons, who don't get caught by ContentPolicy,
247+
// and Observers didn't work for everything until channel.redirectTo landed in FF 20.
248+
//
249249
// ChannelEventSink seems to be necessary in order to handle redirects (eg
250250
// HTTP redirects) correctly.
251251

252+
// Firefox 20 has nsIHTTPChannel.redirectTo
253+
// it also has https://bugzilla.mozilla.org/show_bug.cgi?id=939180
254+
var appInfo = CC["@mozilla.org/xre/app-info;1"].getService(CI.nsIXULAppInfo);
255+
var platformVer = appInfo.platformVersion;
256+
var versionChecker = CC["@mozilla.org/xpcom/version-comparator;1"]
257+
.getService(CI.nsIVersionComparator);
258+
var hasRedirectTo = (versionChecker.compare(appInfo.version, "20.0a1") >= 0);
259+
252260
HTTPSEverywhere.prototype = {
253261
prefs: null,
254262
// properties required for XPCOM registration:
@@ -440,7 +448,7 @@ HTTPSEverywhere.prototype = {
440448
if (channel.URI.spec in https_everywhere_blacklist) {
441449
this.log(DBUG, "Avoiding blacklisted " + channel.URI.spec);
442450
if (lst) lst.breaking_rule(https_everywhere_blacklist[channel.URI.spec])
443-
else this.log(WARN,"Failed to indicate breakage in content menu");
451+
else this.log(NOTE,"Failed to indicate breakage in content menu");
444452
return;
445453
}
446454
HTTPS.replaceChannel(lst, channel);
@@ -583,6 +591,9 @@ HTTPSEverywhere.prototype = {
583591
// to "should this load?", but also allow us to change the thing.
584592

585593
shouldLoad: function(aContentType, aContentLocation, aRequestOrigin, aContext, aMimeTypeGuess, aInternalCall) {
594+
// we don't need contentpolicy if we have channel.redirectTo, and it causes problems
595+
if (hasRedirectTo) return true;
596+
586597
//this.log(WARN,"shouldLoad for " + unwrappedLocation.spec + " of type " + aContentType);
587598
if (shouldLoadTargets[aContentType] != null) {
588599
var unwrappedLocation = IOUtil.unwrapURL(aContentLocation);

0 commit comments

Comments
 (0)