Skip to content

Commit 6c9d75a

Browse files
committed
Applicable lists are now (basically) working!
1 parent bc8a0e7 commit 6c9d75a

4 files changed

Lines changed: 37 additions & 25 deletions

File tree

src/chrome/content/code/ApplicableList.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ ApplicableList.prototype = {
2121
},
2222

2323
show_applicable: function() {
24-
this.log(WARN,"showing rules");
2524
for (var x in this.active) {
26-
this.log(WARN,"Active: " + x.name);
25+
this.log(WARN,"Active: " + this.active[x].name);
2726
}
27+
2828
for (x in this.inactive) {
29-
this.log(WARN,"Inctive: " + x.name);
29+
this.log(WARN,"Inctive: " + this.inactive[x].name);
3030
}
3131
}
3232
};

src/chrome/content/code/HTTPS.js

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -82,35 +82,38 @@ const HTTPS = {
8282

8383
getApplicableListForContext: function(ctx, uri) {
8484
var alist = null;
85-
var domWinOrNode = null;
85+
var domWin = null;
8686
if (!ctx) {
8787
this.log(WARN, "No context loading " + uri.spec);
8888
return null;
8989
}
90-
91-
try {
92-
domWinOrNode = ctx.QueryInterface(CI.nsIDOMWindow);
93-
domWinOrNode = domWinOrNode.top;
94-
} catch (e) {
95-
try {
96-
domWinOrNode = ctx.QueryInterface(CI.nsIDOMNode);
97-
} catch(e) {
98-
this.log(WARN, "Context coercion failure for " + uri.spec);
99-
return null;
100-
}
90+
if (ctx instanceof CI.nsIDOMWindow) {
91+
domWin = ctx.QueryInterface(CI.nsIDOMWindow);
92+
} else if (ctx instanceof CI.nsIDOMNode) {
93+
domWin = ctx.QueryInterface(CI.nsIDOMNode).ownerDocument.defaultView;
94+
} else {
95+
this.log(WARN, "Context for " + uri.spec +
96+
"is some bizarre unexpected thing: " + ctx);
97+
return null;
10198
}
10299

103-
if ("https_everywhere_applicable_rules" in domWinOrNode) {
104-
alist = domWinOrNode.https_everywhere_applicable_rules;
100+
if (!(domWin instanceof CI.nsIDOMWindow)) {
101+
this.log(WARN, "that isn't a domWindow!");
102+
}
103+
domWin = domWin.top; // jump out of iframes
104+
if ("https_everywhere_applicable_rules" in domWin) {
105+
this.log(DBUG,"Found existing applicable list");
106+
alist = domWin.https_everywhere_applicable_rules;
107+
//alist.show_applicable();
105108
} else {
106109
// Usually onLocationChange should have put this in here for us, in some
107110
// cases perhaps we have to make it here...
108111
alist = new ApplicableList(this.log);
109-
domWinOrNode.https_everywhere_applicable_rules = alist;
112+
domWin.https_everywhere_applicable_rules = alist;
110113
this.log(WARN, "had to generate applicable list in forceURI for " +
111114
uri.spec + ", " + alist);
112115
}
113-
this.log(WARN, "Successfully returning " + alist);
116+
this.log(VERB, "Successfully returning " + alist);
114117
return alist;
115118
},
116119

@@ -122,7 +125,7 @@ const HTTPS = {
122125

123126
// first of all we need to get the applicable rules list to keep track of
124127
// what rulesets might have applied to this page
125-
this.log(WARN, "Context is " + ctx);
128+
this.log(VERB, "Context is " + ctx);
126129
var alist = this.getApplicableListForContext(ctx, uri);
127130
var newuri = HTTPSRules.rewrittenURI(alist, uri);
128131
if (!newuri) return true; // no applicable rule

src/chrome/content/code/HTTPSRules.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,12 +322,14 @@ const HTTPSRules = {
322322
newuri = rs[i].transformURI(uri);
323323
if (newuri) {
324324
if (applicable_list) {
325+
this.log("Adding active rule: " + rs[i].name);
325326
applicable_list.active_rule(rs[i]);
326327
applicable_list.show_applicable();
327328
}
328329
return newuri;
329330
} else if (0 == newuri) {
330331
if (applicable_list) {
332+
this.log("Adding inactive rule: " + rs[i].name);
331333
applicable_list.inactive_rule(rs[i]);
332334
applicable_list.show_applicable();
333335
}

src/components/https-everywhere.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -215,12 +215,12 @@ HTTPSEverywhere.prototype = {
215215
// for the context menu in the UI). This will be appended to as various
216216
// content is embedded / requested by JavaScript.
217217
onLocationChange: function(wp, req, uri) {
218-
this.log(WARN,"onLocationChange");
219218
if (wp instanceof CI.nsIWebProgress) {
220219
var x = wp.DOMWindow;
221220
if (x instanceof CI.nsIDOMWindow) {
222221
var top_window = x.top; // climb out of iframes
223222
top_window.https_everywhere_applicable_rules = new ApplicableList(this.log);
223+
this.log(WARN,"onLocationChange, made new alist for " +uri.spec);
224224
} else {
225225
this.log(WARN,"onLocationChange: no nsIDOMWindow");
226226
}
@@ -236,11 +236,18 @@ HTTPSEverywhere.prototype = {
236236
if (!nc) {
237237
this.log(WARN, "no window for " + channel.URI.spec);
238238
return null;
239+
}
240+
var domWin = nc.getInterface(CI.nsIDOMWindow);
241+
if (!domWin) {
242+
this.log(WARN, "failed to get DOMWin for " + channel.URI.spec);
243+
return null;
244+
}
245+
if ("https_everywhere_applicable_rules" in domWin) {
246+
//domWin.https_everywhere_applicable_rules.show_applicable();
247+
return domWin.https_everywhere_applicable_rules;
239248
} else {
240-
var domWin = nc.getInterface(CI.nsIDOMWindow);
241-
this.log(WARN, "list of rules is " + domWin.https_everywhere_applicable_rules);
242-
this.log(WARN, "list of rules is " +
243-
domWin.https_everywhere_applicable_rules.show_applicable());
249+
this.log(DBUG, "Making new AL in getApplicableListForChannel");
250+
domWin.https_everywhere_applicable_rules = new ApplicableList(this.log);
244251
}
245252
return domWin.https_everywhere_applicable_rules;
246253
},

0 commit comments

Comments
 (0)