Index: include.preload.js |
diff --git a/include.preload.js b/include.preload.js |
index bb6b97a01c6d5cc7bff5dc9ab8ca8285880f89bc..5133b364532cb718528401ba64c90f16b3aee048 100644 |
--- a/include.preload.js |
+++ b/include.preload.js |
@@ -347,6 +347,9 @@ function reinjectStyleSheetWhenRemoved(document, style) |
{ |
parentNode.appendChild(style); |
+ // Our style element's sheet is sometimes lost when the element is removed |
+ // from the DOM. A new empty sheet is then created in its place so we have |
+ // to restore the rules ourselves. |
if (style.sheet.rules.length == 0) |
{ |
for (var i = 0; i < rules.length; i += 1) |
@@ -359,6 +362,7 @@ function reinjectStyleSheetWhenRemoved(document, style) |
var style = document.getElementById(id) || |
document.documentElement.shadowRoot.getElementById(id); |
style.removeAttribute("id"); |
+ |
Object.defineProperty(style.sheet, "disabled", |
{value: false, enumerable: true}); |
}, id |
@@ -394,28 +398,36 @@ function protectStyleSheet(document, style) |
document.documentElement.shadowRoot.getElementById(id); |
style.removeAttribute("id"); |
- var i; |
- var disableables = [style, style.sheet]; |
- for (i = 0; i < disableables.length; i += 1) |
- Object.defineProperty(disableables[i], "disabled", |
- {value: false, enumerable: true}); |
+ Object.defineProperty(style, "disabled", |
+ {value: false, enumerable: true}); |
+ Object.defineProperty(style.sheet, "disabled", |
+ {value: false, enumerable: true}); |
- var methods = ["deleteRule", "removeRule"]; |
- for (i = 0; i < methods.length; i += 1) |
+ function wrapMethods(methodNames, descKey, defaultReturnValue) |
{ |
- if (methods[i] in CSSStyleSheet.prototype) |
+ for (var i = 0; i < methodNames.length; i += 1) |
{ |
- (function(method) |
+ if (methodNames[i] in CSSStyleSheet.prototype) |
{ |
- var original = CSSStyleSheet.prototype[method]; |
- CSSStyleSheet.prototype[method] = function(index) |
+ (function(method) |
{ |
- if (this != style.sheet) |
- original.call(this, index); |
- }; |
- }(methods[i])); |
+ var desc = Object.getOwnPropertyDescriptor(CSSStyleSheet.prototype, |
+ method); |
+ var original = desc[descKey]; |
+ desc[descKey] = function() |
+ { |
+ if (this != style.sheet) |
+ return original.apply(this, arguments); |
+ return defaultReturnValue; |
+ }; |
+ Object.defineProperty(CSSStyleSheet.prototype, method, desc); |
+ }(methodNames[i])); |
+ } |
} |
} |
+ |
+ wrapMethods(["deleteRule", "removeRule"], "value"); |
+ wrapMethods(["rules", "cssRules"], "get", []); |
}; |
injectJS(protector, id); |