Skip to content

Commit 83ea5a9

Browse files
committed
Identify a category of applicable but "moot" rulesets
1 parent 8595b58 commit 83ea5a9

5 files changed

Lines changed: 55 additions & 19 deletions

File tree

src/chrome/content/code/ApplicableList.js

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,36 @@
44

55
function ApplicableList(logger) {
66
this.log = logger;
7+
this.active = {};
8+
this.inactive = {};
9+
this.moot={}; // rulesets that might be applicable but uris are already https
710
};
811

912
ApplicableList.prototype = {
10-
active: {},
11-
inactive: {},
1213

1314
active_rule: function(ruleset) {
14-
this.log(WARN,"active rule" + ruleset);
15+
this.log(WARN,"active rule " + ruleset);
1516
this.active[ruleset.name] = ruleset;
1617
},
1718

1819
inactive_rule: function(ruleset) {
19-
this.log(WARN,"inactive rule" + ruleset);
20+
this.log(WARN,"inactive rule " + ruleset);
2021
this.inactive[ruleset.name] = ruleset;
2122
},
2223

24+
moot_rule: function(ruleset) {
25+
this.log(WARN,"moot rule " + ruleset.name);
26+
this.moot[ruleset.name] = ruleset;
27+
},
28+
29+
2330
populate_menu: function(doc, xul_popupmenu) {
2431
// called from the XUL when the context popup is about to be displayed;
2532
// fill out the UI showing which rules are active and inactive in this
2633
// page
2734
while (xul_popupmenu.firstChild) {
2835
// delete whatever was in the menu previously
36+
//this.log(WARN,"removing " + xul_popupmenu.firstChild.label +" from menu");
2937
xul_popupmenu.removeChild(xul_popupmenu.firstChild);
3038
}
3139

@@ -39,16 +47,27 @@ ApplicableList.prototype = {
3947
item.setAttribute("label",this.inactive[x].name);
4048
xul_popupmenu.appendChild(item);
4149
}
50+
51+
for (var x in this.moot) {
52+
if (! (x in this.active) ) {
53+
// rules that are active for some uris are not really moot
54+
var item = doc.createElement("menuitem");
55+
item.setAttribute("label","moot " + this.moot[x].name);
56+
} else {
57+
this.log(WARN,"Moot rule invisible " + this.moot[x].name);
58+
}
59+
}
60+
this.log(WARN, "finished menu");
61+
4262
},
4363

4464
show_applicable: function() {
45-
for (var x in this.active) {
65+
for (var x in this.active)
4666
this.log(WARN,"Active: " + this.active[x].name);
47-
}
4867

49-
for (x in this.inactive) {
68+
for (x in this.inactive)
5069
this.log(WARN,"Inctive: " + this.inactive[x].name);
51-
}
70+
5271
}
5372
};
5473

src/chrome/content/code/HTTPS.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,26 +90,31 @@ const HTTPS = {
9090
if (ctx instanceof CI.nsIDOMWindow) {
9191
domWin = ctx.QueryInterface(CI.nsIDOMWindow);
9292
} else if (ctx instanceof CI.nsIDOMNode) {
93-
domWin = ctx.QueryInterface(CI.nsIDOMNode).ownerDocument.defaultView;
93+
domWin = ctx.QueryInterface(CI.nsIDOMNode).ownerDocument;
94+
if (! domWin) {
95+
this.log(WARN, "No Document for request " + uri.spec);
96+
return null;
97+
}
98+
domWin = domWin.defaultView;
9499
} else {
95100
this.log(WARN, "Context for " + uri.spec +
96101
"is some bizarre unexpected thing: " + ctx);
97102
return null;
98103
}
99104

100105
if (!(domWin instanceof CI.nsIDOMWindow)) {
101-
this.log(WARN, "that isn't a domWindow!");
106+
this.log(WARN, "that isn't a domWindow");
102107
}
103108
domWin = domWin.top; // jump out of iframes
104-
if ("https_everywhere_applicable_rules" in domWin) {
109+
alist = domWin.getUserData("https_everywhere_applicable_rules");
110+
if (alist) {
105111
this.log(DBUG,"Found existing applicable list");
106-
alist = domWin.https_everywhere_applicable_rules;
107112
//alist.show_applicable();
108113
} else {
109114
// Usually onLocationChange should have put this in here for us, in some
110115
// cases perhaps we have to make it here...
111116
alist = new ApplicableList(this.log);
112-
domWin.https_everywhere_applicable_rules = alist;
117+
domWin.setPropertyAsInterface("https_everywhere_applicable_rules", alist);
113118
this.log(WARN, "had to generate applicable list in forceURI for " +
114119
uri.spec + ", " + alist);
115120
}

src/chrome/content/code/HTTPSRules.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,18 +321,25 @@ const HTTPSRules = {
321321
for(i = 0; i < rs.length; ++i) {
322322
newuri = rs[i].transformURI(uri);
323323
if (newuri) {
324+
// we rewrote the uri
324325
if (applicable_list) {
325326
this.log("Adding active rule: " + rs[i].name);
326327
applicable_list.active_rule(rs[i]);
327328
applicable_list.show_applicable();
328329
}
329330
return newuri;
330331
} else if (0 == newuri) {
332+
// the ruleset is inactive
331333
if (applicable_list) {
332334
this.log("Adding inactive rule: " + rs[i].name);
333335
applicable_list.inactive_rule(rs[i]);
334336
applicable_list.show_applicable();
335337
}
338+
} else if (uri.scheme == "https" && applicable_list && rs[i].active) {
339+
// we didn't rewrite but the rule applies to this domain and the
340+
// requests are going over https
341+
applicable_list.moot_rule(rs[i]);
342+
applicable_list.show_applicable();
336343
}
337344
}
338345
return null;

src/chrome/content/toolbar_button.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,11 @@ function show_applicable_list(doc) {
3333
alert(domWin + " is not an nsICDOMWindow");
3434
return null;
3535
}
36-
if ("https_everywhere_applicable_rules" in domWin) {
37-
domWin.https_everywhere_applicable_rules.populate_menu(doc,menu_popup);
36+
var alist = domWin.document.getUserData("https_everywhere_applicable_rules");
37+
if (alist) {
38+
alist.populate_menu(doc,menu_popup);
3839
} else {
40+
alert("Missing applicable rules");
41+
return null;
3942
}
4043
}

src/components/https-everywhere.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,10 @@ HTTPSEverywhere.prototype = {
217217
onLocationChange: function(wp, req, uri) {
218218
if (wp instanceof CI.nsIWebProgress) {
219219
var x = wp.DOMWindow;
220-
if (x instanceof CI.nsIDOMWindow) {
221-
var top_window = x.top; // climb out of iframes
222-
top_window.https_everywhere_applicable_rules = new ApplicableList(this.log);
220+
var top_window;
221+
if (x instanceof CI.nsIDOMWindow) {
222+
var top_window = x.top; // climb out of iframes
223+
top_window.document.setUserData("https_everywhere_applicable_rules", new ApplicableList(this.log), null);
223224
this.log(WARN,"onLocationChange, made new alist for " +uri.spec);
224225
} else {
225226
this.log(WARN,"onLocationChange: no nsIDOMWindow");
@@ -242,12 +243,13 @@ HTTPSEverywhere.prototype = {
242243
this.log(WARN, "failed to get DOMWin for " + channel.URI.spec);
243244
return null;
244245
}
246+
domWin = domWin.top;
245247
if ("https_everywhere_applicable_rules" in domWin) {
246248
//domWin.https_everywhere_applicable_rules.show_applicable();
247249
return domWin.https_everywhere_applicable_rules;
248250
} else {
249251
this.log(DBUG, "Making new AL in getApplicableListForChannel");
250-
domWin.https_everywhere_applicable_rules = new ApplicableList(this.log);
252+
domWin.document.setUserData("https_everywhere_applicable_rules", new ApplicableList(this.log), null);
251253
}
252254
return domWin.https_everywhere_applicable_rules;
253255
},

0 commit comments

Comments
 (0)