Skip to content

Commit 613ea2f

Browse files
author
Mike Perry
committed
Bug 10298: Provide a preference to enable mixed content rules.
This patch enables rules that trigger mixed content blocking if mixed content blocking is disabled via security.mixed_content.block_active_content, or if the pref extensions.https_everywhere.enable_mixed_rulesets is set. Also add observers to reload the rules if either pref changes. Conflicts: src/chrome/content/code/HTTPSRules.js src/components/https-everywhere.js src/defaults/preferences/preferences.js
1 parent e3415d2 commit 613ea2f

File tree

3 files changed

+47
-17
lines changed

3 files changed

+47
-17
lines changed

src/chrome/content/code/HTTPSRules.js

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,6 @@ function CookieRule(host, cookiename) {
1616
this.name_c = new RegExp(cookiename);
1717
}
1818

19-
// Firefox 23+ blocks mixed content by default, so rulesets that create
20-
// mixed content situations should be disabled there
21-
22-
try {
23-
var appPrefs = CC["@mozilla.org/preferences-service;1"].getService(CI.nsIPrefBranch);
24-
var blockMixedContent = appPrefs.getBoolPref("security.mixed_content.block_active_content");
25-
if(blockMixedContent) {
26-
localPlatformRegexp = new RegExp("firefox");
27-
} else {
28-
localPlatformRegexp = new RegExp("(firefox|mixedcontent)");
29-
}
30-
} catch(e) {
31-
localPlatformRegexp = new RegExp("(firefox|mixedcontent)");
32-
}
33-
3419
ruleset_counter = 0;
3520
function RuleSet(name, xmlName, match_rule, default_off, platform) {
3621
if(xmlName == "WordPress.xml" || xmlName == "Github.xml") {
@@ -54,7 +39,7 @@ function RuleSet(name, xmlName, match_rule, default_off, platform) {
5439
this.on_by_default = false;
5540
}
5641
if (platform)
57-
if (platform.search(localPlatformRegexp) == -1) {
42+
if (platform.search(HTTPSRules.localPlatformRegexp) == -1) {
5843
this.on_by_default = false;
5944
this.notes = "Only for " + platform;
6045
}
@@ -398,6 +383,7 @@ const HTTPSRules = {
398383
this.rulesetsByID = {};
399384
this.rulesetsByName = {};
400385
var t1 = new Date().getTime();
386+
this.checkMixedContentHandling();
401387
var rulefiles = RuleWriter.enumerate(RuleWriter.getCustomRuleDir());
402388
this.scanRulefiles(rulefiles);
403389
rulefiles = RuleWriter.enumerate(RuleWriter.getRuleDir());
@@ -428,6 +414,30 @@ const HTTPSRules = {
428414
return;
429415
},
430416

417+
checkMixedContentHandling: function() {
418+
// Firefox 23+ blocks mixed content by default, so rulesets that create
419+
// mixed content situations should be disabled there
420+
var appInfo = CC["@mozilla.org/xre/app-info;1"].getService(CI.nsIXULAppInfo);
421+
var platformVer = appInfo.platformVersion;
422+
var versionChecker = CC["@mozilla.org/xpcom/version-comparator;1"]
423+
.getService(CI.nsIVersionComparator);
424+
var prefs = Components.classes["@mozilla.org/preferences-service;1"]
425+
.getService(Components.interfaces.nsIPrefService).getBranch("");
426+
427+
428+
// If mixed content is present and enabled, and the user hasn't opted to enable
429+
// mixed content triggering rules, leave them out. Otherwise add them in.
430+
if(versionChecker.compare(appInfo.version, "23.0a1") >= 0
431+
&& prefs.getBoolPref("security.mixed_content.block_active_content")
432+
&& !prefs.getBoolPref("extensions.https_everywhere.enable_mixed_rulesets")) {
433+
this.log(INFO, "Not loading rules that trigger mixed content errors.");
434+
this.localPlatformRegexp = new RegExp("firefox");
435+
} else {
436+
this.log(INFO, "Loading rules that would normally trigger mixed content");
437+
this.localPlatformRegexp = new RegExp("(firefox|mixedcontent)");
438+
}
439+
},
440+
431441
scanRulefiles: function(rulefiles) {
432442
var i = 0;
433443
var r = null;

src/components/https-everywhere.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,16 @@ function HTTPSEverywhere() {
199199
this.obsService.addObserver(this, "profile-after-change", false);
200200
this.obsService.addObserver(this, "sessionstore-windows-restored", false);
201201
}
202-
202+
203+
var pref_service = Components.classes["@mozilla.org/preferences-service;1"]
204+
.getService(Components.interfaces.nsIPrefBranchInternal);
205+
var branch = pref_service.QueryInterface(Components.interfaces.nsIPrefBranchInternal);
206+
207+
branch.addObserver("extensions.https_everywhere.enable_mixed_rulesets",
208+
this, false);
209+
branch.addObserver("security.mixed_content.block_active_content",
210+
this, false);
211+
203212
return;
204213
}
205214

@@ -511,6 +520,13 @@ HTTPSEverywhere.prototype = {
511520
} else if (topic == "sessionstore-windows-restored") {
512521
this.log(DBUG,"Got sessionstore-windows-restored");
513522
this.maybeShowObservatoryPopup();
523+
} else if (topic == "nsPref:changed") {
524+
switch (data) {
525+
case "security.mixed_content.block_active_content":
526+
case "extensions.https_everywhere.enable_mixed_rulesets":
527+
HTTPSRules.init();
528+
break;
529+
}
514530
}
515531
return;
516532
},
@@ -724,6 +740,7 @@ HTTPSEverywhere.prototype = {
724740

725741
this.log(INFO,"ChannelReplacement.supported = "+ChannelReplacement.supported);
726742

743+
// XXX: Why is this called twice?
727744
HTTPSRules.init();
728745

729746
if(!Thread.hostRunning)

src/defaults/preferences/preferences.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ pref("extensions.https_everywhere.globalEnabled",true);
44
// this is the HTTPS Everywhere preferences version (for migrations)
55
pref("extensions.https_everywhere.prefs_version", 0);
66

7+
// enable rulesets that trigger mixed content blocking
8+
pref("extensions.https_everywhere.enable_mixed_rulesets", false);
9+
710
// SSl Observatory preferences
811
pref("extensions.https_everywhere._observatory.enabled",false);
912

0 commit comments

Comments
 (0)