Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 411977b

Browse filesBrowse files
committed
Experiment with using nsIControllers for data storage
1 parent 7557f83 commit 411977b
Copy full SHA for 411977b

4 files changed

+78-27Lines changed: 78 additions & 27 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/chrome/content/code/HTTPS.js‎

Copy file name to clipboardExpand all lines: src/chrome/content/code/HTTPS.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
INCLUDE('Cookie','ApplicableList');
1+
INCLUDE('Cookie');
22
// XXX: Disable STS for now.
33
var STS = {
44
isSTSURI : function(uri) {
Collapse file

‎src/chrome/content/code/HTTPSRules.js‎

Copy file name to clipboardExpand all lines: src/chrome/content/code/HTTPSRules.js
+7-5Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -404,16 +404,16 @@ const HTTPSRules = {
404404
shouldSecureCookie: function(applicable_list, c) {
405405
// Check to see if the Cookie object c meets any of our cookierule citeria
406406
// for being marked as secure
407-
this.log(DBUG, "Testing cookie:");
408-
this.log(DBUG, " name: " + c.name);
409-
this.log(DBUG, " host: " + c.host);
407+
//this.log(DBUG, "Testing cookie:");
408+
//this.log(DBUG, " name: " + c.name);
409+
//this.log(DBUG, " host: " + c.host);
410410
//this.log(DBUG, " domain: " + c.domain);
411411
//this.log(DBUG, " rawhost: " + c.rawHost);
412412
var i,j;
413413
var rs = this.potentiallyApplicableRulesets(c.host);
414414
for (i = 0; i < rs.length; ++i) {
415415
var ruleset = rs[i];
416-
if (ruleset.active)
416+
if (ruleset.active) {
417417
for (j = 0; j < ruleset.cookierules.length; j++) {
418418
var cr = ruleset.cookierules[j];
419419
if (cr.host_c.test(c.host) && cr.name_c.test(c.name)) {
@@ -422,7 +422,9 @@ const HTTPSRules = {
422422
return true;
423423
}
424424
}
425-
else if (ruleset.cookierules.length > 0) {
425+
if (ruleset.cookierules.length > 0)
426+
applicable_list.moot_rule(ruleset);
427+
} else if (ruleset.cookierules.length > 0) {
426428
applicable_list.inactive_rule(ruleset);
427429
this.log(INFO,"Inactive cookie rule " + ruleset.name);
428430
}
Collapse file

‎src/chrome/content/toolbar_button.js‎

Copy file name to clipboardExpand all lines: src/chrome/content/toolbar_button.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function show_applicable_list() {
4343
}
4444

4545
var HTTPSEverywhere = CC["@eff.org/https-everywhere;1"].getService(Components.interfaces.nsISupports).wrappedJSObject;
46-
var alist = HTTPSEverywhere.getExpando(domWin.document,"applicable_rules", null);
46+
var alist = HTTPSEverywhere.getExpando(domWin,"applicable_rules", null);
4747

4848
if (alist) {
4949
alist.log(WARN,"Success wherein domWin is " + domWin);
Collapse file

‎src/components/https-everywhere.js‎

Copy file name to clipboardExpand all lines: src/components/https-everywhere.js
+69-20Lines changed: 69 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,35 @@ INCLUDE('IOUtil', 'HTTPSRules', 'HTTPS', 'Thread', 'ApplicableList');
119119

120120
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
121121

122+
// This is black magic for storing Expando data w/ an nsIDOMWindow
123+
// See http://pastebin.com/qY28Jwbv ,
124+
// https://developer.mozilla.org/en/XPCOM_Interface_Reference/nsIControllers
125+
126+
StorageController.prototype = {
127+
QueryInterface: XPCOMUtils.generateQI(
128+
[ Components.interfaces.nsISupports,
129+
Components.interfaces.nsIController ]),
130+
wrappedJSObject: null, // Initialized by constructor
131+
supportsCommand: function (cmd) {return (cmd == this.command)},
132+
isCommandEnabled: function (cmd) {return (cmd == this.command)},
133+
onEvent: function(eventName) {return true},
134+
doCommand: function() {return true}
135+
};
136+
137+
function StorageController(command) {
138+
this.command = command;
139+
this.data = {};
140+
this.wrappedJSObject = this;
141+
};
142+
143+
/*var Controller = Class("Controller", XPCOM(CI.nsIController), {
144+
init: function (command, data) {
145+
this.command = command;
146+
this.data = data;
147+
},
148+
supportsCommand: function (cmd) cmd === this.command
149+
});*/
150+
122151
function HTTPSEverywhere() {
123152

124153
// Set up logging in each component:
@@ -141,6 +170,9 @@ function HTTPSEverywhere() {
141170
return;
142171
}
143172

173+
174+
175+
144176
// This defines for Mozilla what stuff HTTPSEverywhere will implement.
145177

146178
// We need to use both ContentPolicy and Observer, because there are some
@@ -199,20 +231,29 @@ HTTPSEverywhere.prototype = {
199231
},
200232

201233
// An "expando" is an attribute glued onto something. From NoScript.
202-
getExpando: function(domObject, key, defValue) {
203-
return domObject && domObject.__httpsEStorage && domObject.__httpsEStorage[key] ||
204-
(defValue ? this.setExpando(domObject, key, defValue) : null);
234+
getExpando: function(domWin, key) {
235+
var c = domWin.controllers.getControllerForCommand("https-everywhere-storage");
236+
if (c) {
237+
c = c.wrappedJSObject;
238+
this.log(DBUG, "Found a controller, returning data");
239+
return c.data[key];
240+
} else {
241+
this.log(INFO, "No controller attached to " + domWin);
242+
return null;
243+
}
205244
},
206-
207-
setExpando: function(domObject, key, value) {
208-
if (!domObject) return null;
209-
if (!domObject.__httpsEStorage) domObject.__httpsEStorage = {};
210-
if (domObject.__httpsEStorage) domObject.__httpsEStorage[key] = value;
211-
else this.log(WARN, "Warning: cannot set expando " + key + " to value " + value);
212-
return value;
245+
setExpando: function(domWin, key, value) {
246+
var c = domWin.controllers.getControllerForCommand("https-everywhere-storage");
247+
if (!c) {
248+
this.log(DBUG, "Appending new StorageController for " + domWin);
249+
c = new StorageController("https-everywhere-storage");
250+
domWin.controllers.appendController(c);
251+
} else {
252+
c = c.wrappedJSObject;
253+
}
254+
c.data[key] = value;
213255
},
214256

215-
216257
// This function is registered solely to detect favicon loads by virtue
217258
// of their failure to pass through this function.
218259
onStateChange: function(wp, req, stateFlags, status) {
@@ -231,12 +272,8 @@ HTTPSEverywhere.prototype = {
231272
// content is embedded / requested by JavaScript.
232273
onLocationChange: function(wp, req, uri) {
233274
if (wp instanceof CI.nsIWebProgress) {
234-
// XXX this should not work like this, and it possibly shouldn't exist
235-
// at all
236-
//this.log(DBUG,"(Probably) Making new alist in onLocationChange");
237-
if (!this.getApplicableListForDOMWin(wp.DOMWindow, "onLocChange"))
275+
if (!this.newApplicableListForDOMWin(wp.DOMWindow))
238276
this.log(WARN,"Something went wrong in onLocationChange");
239-
//this.log(DBUG,"ok");
240277
} else {
241278
this.log(WARN,"onLocationChange: no nsIWebProgress");
242279
}
@@ -275,19 +312,31 @@ HTTPSEverywhere.prototype = {
275312
return this.getApplicableListForDOMWin(domWin, "on-modify-request w " + domWin);
276313
},
277314

315+
newApplicableListForDOMWin: function(domWin) {
316+
if (!domWin || !(domWin instanceof CI.nsIDOMWindow)) {
317+
this.log(WARN, "Get alist without domWin");
318+
return null;
319+
}
320+
var dw = domWin.top;
321+
this.log(DBUG, "Forcing new AL in getApplicableListForDOMWin in onLocationChange");
322+
var alist = new ApplicableList(this.log,dw.document);
323+
this.setExpando(dw,"applicable_rules",alist);
324+
return alist;
325+
},
326+
278327
getApplicableListForDOMWin: function(domWin, where) {
279328
if (!domWin || !(domWin instanceof CI.nsIDOMWindow)) {
280329
this.log(WARN, "Get alist without domWin");
281330
return null;
282331
}
283-
var doc = domWin.top.document;
284-
var alist= this.getExpando(doc,"applicable_rules",null);
332+
var dw = domWin.top;
333+
var alist= this.getExpando(dw,"applicable_rules",null);
285334
if (alist) {
286335
this.log(DBUG,"get AL success in " + where);
287336
} else {
288337
this.log(DBUG, "Making new AL in getApplicableListForDOMWin in " + where);
289-
alist = new ApplicableList(this.log,doc);
290-
this.setExpando(doc,"applicable_rules",alist);
338+
alist = new ApplicableList(this.log,dw.document);
339+
this.setExpando(dw,"applicable_rules",alist);
291340
}
292341
return alist;
293342
},

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.