Skip to content

Commit ab7277f

Browse files
committed
Enable use-strict & drop (broken) old Opera mixedcontent support
Because of the IIFE (immediately-invoked function expression) surrounding `localPlatformRegexp`, it's never worked. `this.userAgent` is undefined during the execution, and the else is always taken, resulting in `chromium` being the platform always. Signed-off-by: Nick Semenkovich <semenko@alum.mit.edu>
1 parent 1235963 commit ab7277f

File tree

2 files changed

+8
-20
lines changed

2 files changed

+8
-20
lines changed

chromium/background.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function loadExtensionFile(url, returnType) {
2222

2323

2424
// Rules are loaded here
25-
var all_rules = new RuleSets(navigator.userAgent, LRUCache, localStorage);
25+
var all_rules = new RuleSets(LRUCache, localStorage);
2626
var rule_list = 'rules/default.rulesets';
2727
all_rules.addFromXml(loadExtensionFile(rule_list, 'xml'));
2828

chromium/rules.js

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
"use strict";
12
// Stubs so this runs under nodejs. They get overwritten later by util.js
23
var DBUG = 1;
34
function log(){};
@@ -87,16 +88,14 @@ RuleSet.prototype = {
8788

8889
/**
8990
* Initialize Rule Sets
90-
* @param userAgent The browser's user agent
9191
* @param cache a cache object (lru)
9292
* @param ruleActiveStates default state for rules
9393
* @constructor
9494
*/
95-
function RuleSets(userAgent, cache, ruleActiveStates) {
95+
function RuleSets(cache, ruleActiveStates) {
9696
// Load rules into structure
9797
var t1 = new Date().getTime();
9898
this.targets = {};
99-
this.userAgent = userAgent;
10099

101100
// A cache for potentiallyApplicableRulesets
102101
// Size chosen /completely/ arbitrarily.
@@ -107,6 +106,9 @@ function RuleSets(userAgent, cache, ruleActiveStates) {
107106

108107
// A hash of rule name -> active status (true/false).
109108
this.ruleActiveStates = ruleActiveStates;
109+
110+
// A regex to match platform-specific features
111+
this.localPlatformRegexp = new RegExp("chromium");
110112
}
111113

112114

@@ -125,21 +127,6 @@ RuleSets.prototype = {
125127
}
126128
},
127129

128-
/**
129-
* Return the RegExp for the local platform
130-
*/
131-
localPlatformRegexp: (function() {
132-
var isOpera = /(?:OPR|Opera)[\/\s](\d+)(?:\.\d+)/.test(this.userAgent);
133-
if (isOpera && isOpera.length === 2 && parseInt(isOpera[1]) < 23) {
134-
// Opera <23 does not have mixed content blocking
135-
log(DBUG, 'Detected that we are running Opera < 23');
136-
return new RegExp("chromium|mixedcontent");
137-
} else {
138-
log(DBUG, 'Detected that we are running Chrome/Chromium');
139-
return new RegExp("chromium");
140-
}
141-
})(),
142-
143130
/**
144131
* Load a user rule
145132
* @param params
@@ -177,7 +164,7 @@ RuleSets.prototype = {
177164
}
178165

179166
// If a ruleset declares a platform, and we don't match it, treat it as
180-
// off-by-default
167+
// off-by-default. In practice, this excludes "mixedcontent" & "cacert" rules.
181168
var platform = ruletag.getAttribute("platform");
182169
if (platform) {
183170
if (platform.search(this.localPlatformRegexp) == -1) {
@@ -274,6 +261,7 @@ RuleSets.prototype = {
274261
}
275262
// now eat away from the left, with *, so that for x.y.z.google.com we
276263
// check *.z.google.com and *.google.com (we did *.y.z.google.com above)
264+
var t;
277265
for (var i = 2; i <= segmented.length - 2; ++i) {
278266
t = "*." + segmented.slice(i,segmented.length).join(".");
279267
this.setInsert(results, this.targets[t]);

0 commit comments

Comments
 (0)