@@ -119,6 +119,35 @@ INCLUDE('IOUtil', 'HTTPSRules', 'HTTPS', 'Thread', 'ApplicableList');
119119
120120Components . 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+
122151function 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