Skip to content

Commit 7ce42e3

Browse files
committed
Horrible hack: fallback to NoScript's get/set expandos in FF 3.*
1 parent 8eee9bf commit 7ce42e3

File tree

1 file changed

+37
-14
lines changed

1 file changed

+37
-14
lines changed

src/components/https-everywhere.js

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -233,25 +233,48 @@ HTTPSEverywhere.prototype = {
233233
// An "expando" is an attribute glued onto something. From NoScript.
234234
getExpando: function(domWin, key) {
235235
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;
236+
try {
237+
if (c) {
238+
c = c.wrappedJSObject;
239+
this.log(DBUG, "Found a controller, returning data");
240+
return c.data[key];
241+
} else {
242+
this.log(INFO, "No controller attached to " + domWin);
243+
return null;
244+
}
245+
} catch(e) {
246+
// Firefox 3.5
247+
this.log(WARN,"exception in getExpando");
248+
return this.getExpando_old(domWin.document, key, null);
243249
}
244250
},
245251
setExpando: function(domWin, key, value) {
246252
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+
try {
254+
if (!c) {
255+
this.log(DBUG, "Appending new StorageController for " + domWin);
256+
c = new StorageController("https-everywhere-storage");
257+
domWin.controllers.appendController(c);
258+
} else {
259+
c = c.wrappedJSObject;
260+
}
261+
c.data[key] = value;
262+
} catch(e) {
263+
this.setExpando_old(domWin.document, key, value);
253264
}
254-
c.data[key] = value;
265+
},
266+
267+
// This method is straight out of NoScript... we fall back to it in FF 3.*?
268+
getExpando_old: function(domObject, key, defValue) {
269+
return domObject && domObject.__httpsEStorage && domObject.__httpsEStorage[key] ||
270+
(defValue ? this.setExpando(domObject, key, defValue) : null);
271+
},
272+
setExpando_old: function(domObject, key, value) {
273+
if (!domObject) return null;
274+
if (!domObject.__httpsEStorage) domObject.__httpsEStorage = {};
275+
if (domObject.__httpsEStorage) domObject.__httpsEStorage[key] = value;
276+
else this.log(WARN, "Warning: cannot set expando " + key + " to value " + value);
277+
return value;
255278
},
256279

257280
// This function is registered solely to detect favicon loads by virtue

0 commit comments

Comments
 (0)