OLD | NEW |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-present eyeo GmbH | 3 * Copyright (C) 2006-present eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 let priority = rule.style.getPropertyPriority(property); | 120 let priority = rule.style.getPropertyPriority(property); |
121 styles.push(`${property}: ${value}${priority ? " !" + priority : ""};`); | 121 styles.push(`${property}: ${value}${priority ? " !" + priority : ""};`); |
122 } | 122 } |
123 styles.sort(); | 123 styles.sort(); |
124 return { | 124 return { |
125 style: styles.join(" "), | 125 style: styles.join(" "), |
126 subSelectors: splitSelector(rule.selectorText) | 126 subSelectors: splitSelector(rule.selectorText) |
127 }; | 127 }; |
128 } | 128 } |
129 | 129 |
| 130 function getCSSRules(stylesheet) |
| 131 { |
| 132 try |
| 133 { |
| 134 return stylesheet.cssRules; |
| 135 } |
| 136 catch (e) |
| 137 { |
| 138 // On Firefox, a style sheet injected by another extension has the same |
| 139 // origin, but accessing the cssRules property is still an error. |
| 140 // See #6594. |
| 141 } |
| 142 } |
| 143 |
130 let scopeSupported = null; | 144 let scopeSupported = null; |
131 | 145 |
132 function tryQuerySelector(subtree, selector, all) | 146 function tryQuerySelector(subtree, selector, all) |
133 { | 147 { |
134 let elements = null; | 148 let elements = null; |
135 try | 149 try |
136 { | 150 { |
137 elements = all ? subtree.querySelectorAll(selector) : | 151 elements = all ? subtree.querySelectorAll(selector) : |
138 subtree.querySelector(selector); | 152 subtree.querySelector(selector); |
139 scopeSupported = true; | 153 scopeSupported = true; |
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
601 if (mutations && patterns.some(pattern => pattern.dependsOnStylesAndDOM)) | 615 if (mutations && patterns.some(pattern => pattern.dependsOnStylesAndDOM)) |
602 stylesheets = this.document.styleSheets; | 616 stylesheets = this.document.styleSheets; |
603 | 617 |
604 for (let stylesheet of stylesheets || []) | 618 for (let stylesheet of stylesheets || []) |
605 { | 619 { |
606 // Explicitly ignore third-party stylesheets to ensure consistent behavior | 620 // Explicitly ignore third-party stylesheets to ensure consistent behavior |
607 // between Firefox and Chrome. | 621 // between Firefox and Chrome. |
608 if (!this.isSameOrigin(stylesheet)) | 622 if (!this.isSameOrigin(stylesheet)) |
609 continue; | 623 continue; |
610 | 624 |
611 let rules = stylesheet.cssRules; | 625 let rules = getCSSRules(stylesheet); |
612 if (!rules) | 626 if (!rules) |
613 continue; | 627 continue; |
614 | 628 |
615 for (let rule of rules) | 629 for (let rule of rules) |
616 { | 630 { |
617 if (rule.type != rule.STYLE_RULE) | 631 if (rule.type != rule.STYLE_RULE) |
618 continue; | 632 continue; |
619 | 633 |
620 cssStyles.push(stringifyStyle(rule)); | 634 cssStyles.push(stringifyStyle(rule)); |
621 } | 635 } |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
809 characterData: shouldObserveCharacterData(this.patterns), | 823 characterData: shouldObserveCharacterData(this.patterns), |
810 subtree: true | 824 subtree: true |
811 } | 825 } |
812 ); | 826 ); |
813 this.document.addEventListener("load", this.onLoad.bind(this), true); | 827 this.document.addEventListener("load", this.onLoad.bind(this), true); |
814 } | 828 } |
815 } | 829 } |
816 }; | 830 }; |
817 | 831 |
818 exports.ElemHideEmulation = ElemHideEmulation; | 832 exports.ElemHideEmulation = ElemHideEmulation; |
OLD | NEW |