Skip to content

Commit 4e20cc1

Browse files
committed
Rationalise ApplicableList storage code
And also a horrible hack to forcibly include the URL of the DOM root in the applicable list.
1 parent 7c18c52 commit 4e20cc1

5 files changed

Lines changed: 47 additions & 81 deletions

File tree

src/chrome/content/code/ApplicableList.js

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,28 @@ function ApplicableList(logger, home) {
1313
serial_number += 1;
1414
this.serial = serial_number;
1515
this.log(DBUG,"Alist serial #" + this.serial + " for " + this.home);
16+
// The base URI of the dom tends to be loaded from some /other/
17+
// ApplicableList, so pretend we're loading it from here.
18+
var HTTPSEverywhere = CC["@eff.org/https-everywhere;1"]
19+
.getService(Components.interfaces.nsISupports)
20+
.wrappedJSObject;
21+
HTTPSEverywhere.https_rules.rewrittenURI(this, home.baseURIObject);
1622
};
1723

1824
ApplicableList.prototype = {
1925

2026
active_rule: function(ruleset) {
21-
this.log(WARN,"active rule " + ruleset.name +" in "+ this.home);
27+
this.log(INFO,"active rule " + ruleset.name +" in "+ this.home);
2228
this.active[ruleset.name] = ruleset;
2329
},
2430

2531
inactive_rule: function(ruleset) {
26-
this.log(WARN,"inactive rule " + ruleset.name +" in "+ this.home);
32+
this.log(INFO,"inactive rule " + ruleset.name +" in "+ this.home);
2733
this.inactive[ruleset.name] = ruleset;
2834
},
2935

3036
moot_rule: function(ruleset) {
31-
this.log(WARN,"moot rule " + ruleset.name +" in "+ this.home);
37+
this.log(INFO,"moot rule " + ruleset.name +" in "+ this.home);
3238
this.moot[ruleset.name] = ruleset;
3339
},
3440

@@ -112,17 +118,12 @@ ApplicableList.prototype = {
112118
}
113119

114120
// add all the menu items
115-
for(var x in this.active) {
121+
for(var x in this.active)
116122
add_menuitem(this.active[x], 'active');
117-
}
118-
for(var x in this.moot) {
119-
if(!(x in this.active) ) {
120-
// rules that are active for some uris are not really moot
123+
// rules that are active for some uris are not really moot
124+
for(var x in this.moot)
125+
if(!(x in this.active))
121126
add_menuitem(this.moot[x], 'moot');
122-
} else {
123-
this.log(WARN,"Moot rule invisible " + this.moot[x].name);
124-
}
125-
}
126127
for(var x in this.inactive) {
127128
add_menuitem(this.inactive[x], 'inactive');
128129
}

src/chrome/content/code/HTTPS.js

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ const HTTPS = {
3131
replaceChannel: function(applicable_list, channel) {
3232
var uri = HTTPSRules.rewrittenURI(applicable_list, channel.URI);
3333
if (!uri) {
34-
HTTPS.log(INFO,
35-
"Got replace channel with no applicable rules for URI "
36-
+ channel.URI.spec);
34+
//HTTPS.log(INFO,
35+
// "Got replace channel with no applicable rules for URI "
36+
// + channel.URI.spec);
3737
return false;
3838
}
3939

@@ -97,34 +97,13 @@ const HTTPS = {
9797
return null;
9898
}
9999
domWin = doc.defaultView;
100-
this.log(WARN,"Coerced nsIDOMWin from Node");
100+
this.log(WARN,"Coerced nsIDOMWin from Node: " + domWin);
101101
} else {
102102
this.log(WARN, "Context for " + uri.spec +
103103
"is some bizarre unexpected thing: " + ctx);
104104
return null;
105105
}
106-
107-
if (!(domWin instanceof CI.nsIDOMWindow)) {
108-
this.log(WARN, "that isn't a domWindow");
109-
}
110-
domWin = domWin.top; // jump out of iframes
111-
doc = doc.documentElement;
112-
alist = HTTPSEverywhere.instance.getExpando(doc,"applicable_rules", null);
113-
if (alist) {
114-
this.log(DBUG,"Found existing applicable list");
115-
//alist.show_applicable();
116-
} else {
117-
// Usually onLocationChange should have put this in here for us, in some
118-
// cases perhaps we have to make it here...
119-
alist = new ApplicableList(this.log,doc);
120-
this.log(WARN, "Sanity should be, " + alist);
121-
HTTPSEverywhere.instance.setExpando(doc,"applicable_rules", alist);
122-
this.log(WARN, "had to generate applicable list in forceURI for " +
123-
uri.spec + " in " + doc.baseURIObject.spec);
124-
alist = HTTPSEverywhere.instance.getExpando(doc,"applicable_rules", null);
125-
this.log(WARN, "Sanity check: " + alist);
126-
}
127-
return alist;
106+
return HTTPSEverywhere.instance.getApplicableListForDOMWin(domWin, "for context/forceURI");
128107
},
129108

130109
forceURI: function(uri, fallback, ctx) {

src/chrome/content/code/HTTPSRules.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,6 @@ RuleSet.prototype = {
7373
if (returl != urispec) return returl;
7474
}
7575

76-
if (this.ruleset_match_c) {
77-
// This is not an error, because we do not insist the matchrule
78-
// precisely describes to target space of URLs ot redirected
79-
this.log(DBUG,"Ruleset "+this.name
80-
+" had an applicable match-rule but no matching rules");
81-
}
8276
return null;
8377
},
8478
log: function(level, msg) {

src/chrome/content/code/IOUtil.js

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -514,20 +514,15 @@ ChannelReplacement.prototype = {
514514
ABE.log("Opening delayed channel: " + oldChan.name + " - (current loading channel for this window " + (overlap && overlap.name) + ")");
515515
}
516516
*/
517-
if (true) {
518-
try {
519-
newChan.asyncOpen(this.listener, this.context);
520-
521-
// safe browsing hook
522-
if (this._mustClassify)
523-
CC["@mozilla.org/channelclassifier"].createInstance(CI.nsIChannelClassifier).start(newChan, true);
524-
525-
} catch (e) {}
526-
} else {
527-
if (ABE.consoleDump) {
528-
ABE.log("Detected double load on the same window: " + oldChan.name + " - " + (overlap && overlap.name));
529-
}
530-
}
517+
try {
518+
newChan.asyncOpen(this.listener, this.context);
519+
520+
// safe browsing hook
521+
if (this._mustClassify)
522+
CC["@mozilla.org/channelclassifier"].createInstance(CI.nsIChannelClassifier).start(newChan, true);
523+
524+
} catch (e) {}
525+
531526

532527
this.dispose();
533528
},

src/components/https-everywhere.js

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -231,20 +231,10 @@ HTTPSEverywhere.prototype = {
231231
// content is embedded / requested by JavaScript.
232232
onLocationChange: function(wp, req, uri) {
233233
if (wp instanceof CI.nsIWebProgress) {
234-
var x = wp.DOMWindow;
235-
var top_window;
236-
if (x instanceof CI.nsIDOMWindow) {
237-
top_window = x.top; // climb out of iframes
238-
if (top_window.document) {
239-
var alist = new ApplicableList(this.log,top_window.document);
240-
this.setExpando(top_window, "applicable rules", alist);
241-
this.log(WARN,"onLocationChange, made new alist for " +uri.spec);
242-
} else {
243-
this.log(WARN,"onLocationChange, document is null");
244-
}
245-
} else {
246-
this.log(WARN,"onLocationChange: no nsIDOMWindow");
247-
}
234+
this.log(DBUG,"(Probably) Making new alist in onLocationChange");
235+
if (!this.getApplicableListForDOMWin(wp.DOMWindow, "onLocChange"))
236+
this.log(WARN,"Something went wrong in onLocationChange");
237+
this.log(DBUG,"ok");
248238
} else {
249239
this.log(WARN,"onLocationChange: no nsIWebProgress");
250240
}
@@ -280,15 +270,22 @@ HTTPSEverywhere.prototype = {
280270
// need to be appended to with reference only to the channel
281271
getApplicableListForChannel: function(channel) {
282272
var domWin = this.getWindowForChannel(channel);
283-
if (!domWin) return null;
284-
var alist= this.getExpando(domWin.document,"applicable_rules",null);
273+
return this.getApplicableListForDOMWin(domWin, "on-modify-request w " + domWin);
274+
},
275+
276+
getApplicableListForDOMWin: function(domWin, where) {
277+
if (!domWin || !(domWin instanceof CI.nsIDOMWindow)) {
278+
this.log(WARN, "Get alist without domWin");
279+
return null;
280+
}
281+
var doc = domWin.top.document;
282+
var alist= this.getExpando(doc,"applicable_rules",null);
285283
if (alist) {
286-
this.log(WARN,"get AL success");
287-
return alist;
284+
this.log(DBUG,"get AL success in " + where);
288285
} else {
289-
this.log(DBUG, "Making new AL in getApplicableListForChannel");
290-
alist = new ApplicableList(this.log,domWin.document);
291-
this.setExpando(domWin.document,"applicable_rules",alist);
286+
this.log(DBUG, "Making new AL in getApplicableListForDOMWin in " + where);
287+
alist = new ApplicableList(this.log,doc);
288+
this.setExpando(doc,"applicable_rules",alist);
292289
}
293290
return alist;
294291
},
@@ -297,7 +294,7 @@ HTTPSEverywhere.prototype = {
297294
observe: function(subject, topic, data) {
298295
// Top level glue for the nsIObserver API
299296
var channel = subject;
300-
this.log(VERB,"Got observer topic: "+topic);
297+
//this.log(VERB,"Got observer topic: "+topic);
301298

302299
if (topic == "http-on-modify-request") {
303300
if (!(channel instanceof CI.nsIHttpChannel)) return;
@@ -309,7 +306,7 @@ HTTPSEverywhere.prototype = {
309306
var lst = this.getApplicableListForChannel(channel);
310307
HTTPS.replaceChannel(lst, channel);
311308
} else if (topic == "http-on-examine-response") {
312-
this.log(DBUG, "Got http-on-examine-response ");
309+
this.log(DBUG, "Got http-on-examine-response @ "+ channel.URI.spec );
313310
HTTPS.handleSecureCookies(channel);
314311
} else if (topic == "http-on-examine-merged-response") {
315312
this.log(DBUG, "Got http-on-examine-merged-response ");

0 commit comments

Comments
 (0)