Skip to content

Commit d5ebd1e

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.
1 parent 042a76a commit d5ebd1e

File tree

3 files changed

+47
-15
lines changed

3 files changed

+47
-15
lines changed

src/chrome/content/code/HTTPSRules.js

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +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-
var appInfo = CC["@mozilla.org/xre/app-info;1"].getService(CI.nsIXULAppInfo);
22-
var platformVer = appInfo.platformVersion;
23-
var versionChecker = CC["@mozilla.org/xpcom/version-comparator;1"]
24-
.getService(CI.nsIVersionComparator);
25-
if(versionChecker.compare(appInfo.version, "23.0a1") >= 0) {
26-
localPlatformRegexp = new RegExp("firefox");
27-
} else {
28-
localPlatformRegexp = new RegExp("(firefox|mixedcontent)");
29-
}
30-
31-
3219
ruleset_counter = 0;
3320
function RuleSet(name, xmlName, match_rule, default_off, platform) {
3421
if(xmlName == "WordPress.xml" || xmlName == "Github.xml") {
@@ -52,7 +39,7 @@ function RuleSet(name, xmlName, match_rule, default_off, platform) {
5239
this.on_by_default = false;
5340
}
5441
if (platform)
55-
if (platform.search(localPlatformRegexp) == -1) {
42+
if (platform.search(HTTPSRules.localPlatformRegexp) == -1) {
5643
this.on_by_default = false;
5744
this.notes = "Only for " + platform;
5845
}
@@ -396,6 +383,7 @@ const HTTPSRules = {
396383
this.rulesetsByID = {};
397384
this.rulesetsByName = {};
398385
var t1 = new Date().getTime();
386+
this.checkMixedContentHandling();
399387
var rulefiles = RuleWriter.enumerate(RuleWriter.getCustomRuleDir());
400388
this.scanRulefiles(rulefiles);
401389
rulefiles = RuleWriter.enumerate(RuleWriter.getRuleDir());
@@ -426,6 +414,30 @@ const HTTPSRules = {
426414
return;
427415
},
428416

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+
429441
scanRulefiles: function(rulefiles) {
430442
var i = 0;
431443
var r = null;

src/components/https-everywhere.js

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

@@ -501,6 +510,13 @@ HTTPSEverywhere.prototype = {
501510
this.log(DBUG,"Got sessionstore-windows-restored");
502511
this.maybeShowObservatoryPopup();
503512
this.maybeShowDevPopup();
513+
} else if (topic == "nsPref:changed") {
514+
switch (data) {
515+
case "security.mixed_content.block_active_content":
516+
case "extensions.https_everywhere.enable_mixed_rulesets":
517+
HTTPSRules.init();
518+
break;
519+
}
504520
}
505521
return;
506522
},
@@ -708,6 +724,7 @@ HTTPSEverywhere.prototype = {
708724

709725
this.log(INFO,"ChannelReplacement.supported = "+ChannelReplacement.supported);
710726

727+
// XXX: Why is this called twice?
711728
HTTPSRules.init();
712729

713730
if(!Thread.hostRunning)

src/defaults/preferences/preferences.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ pref("extensions.https_everywhere.dev_popup_shown", false);
1010
// show ruleset tests in the menu
1111
pref("extensions.https_everywhere.show_ruleset_tests", false);
1212

13+
// enable rulesets that trigger mixed content blocking
14+
pref("extensions.https_everywhere.enable_mixed_rulesets", false);
15+
1316
// SSl Observatory preferences
1417
pref("extensions.https_everywhere._observatory.enabled",false);
1518

0 commit comments

Comments
 (0)