LEFT | RIGHT |
1 function splitSelector(selector) | 1 function splitSelector(selector) |
2 { | 2 { |
3 if (selector.indexOf(",") == -1) | 3 if (selector.indexOf(",") == -1) |
4 return [selector]; | 4 return [selector]; |
5 | 5 |
6 var selectors = []; | 6 var selectors = []; |
7 var start = 0; | 7 var start = 0; |
8 var level = 0; | 8 var level = 0; |
9 var sep = ""; | 9 var sep = ""; |
10 | 10 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 { | 49 { |
50 var property = style.item(i); | 50 var property = style.item(i); |
51 var value = style.getPropertyValue(property); | 51 var value = style.getPropertyValue(property); |
52 var priority = style.getPropertyPriority(property); | 52 var priority = style.getPropertyPriority(property); |
53 styles.push(property + ": " + value + (priority ? " !" + priority : "") +
";"); | 53 styles.push(property + ": " + value + (priority ? " !" + priority : "") +
";"); |
54 } | 54 } |
55 styles.sort(); | 55 styles.sort(); |
56 return styles.join(" "); | 56 return styles.join(" "); |
57 }, | 57 }, |
58 | 58 |
59 findSelectors: function(stylesheet, selectors) | 59 isSameOrigin: function(stylesheet) |
60 { | 60 { |
61 try | 61 try |
62 { | 62 { |
63 // Explicitly ignore third-party stylesheets to ensure consistent behavior | 63 return new URL(stylesheet.href).origin == this.window.location.origin; |
64 // between Firefox and Chrome. | |
65 if (stylesheet.href && | |
66 new URL(stylesheet.href).origin != this.window.location.origin) | |
67 { | |
68 return; | |
69 } | |
70 } | 64 } |
71 catch (e) | 65 catch (e) |
72 { | 66 { |
73 // An invalid URL, can be ignored. | 67 // Invalid URL, assume that it is first-party. |
74 Cu.reportError(e); | 68 return true; |
75 } | 69 } |
| 70 }, |
| 71 |
| 72 findSelectors: function(stylesheet, selectors) |
| 73 { |
| 74 // Explicitly ignore third-party stylesheets to ensure consistent behavior |
| 75 // between Firefox and Chrome. |
| 76 if (!this.isSameOrigin(stylesheet)) |
| 77 return; |
76 | 78 |
77 var rules = stylesheet.cssRules; | 79 var rules = stylesheet.cssRules; |
78 if (!rules) | 80 if (!rules) |
79 return; | 81 return; |
80 | 82 |
81 for (var i = 0; i < rules.length; i++) | 83 for (var i = 0; i < rules.length; i++) |
82 { | 84 { |
83 var rule = rules[i]; | 85 var rule = rules[i]; |
84 if (rule.type != rule.STYLE_RULE) | 86 if (rule.type != rule.STYLE_RULE) |
85 continue; | 87 continue; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 apply: function() | 138 apply: function() |
137 { | 139 { |
138 if (this.patterns.length > 0) | 140 if (this.patterns.length > 0) |
139 { | 141 { |
140 var document = this.window.document; | 142 var document = this.window.document; |
141 this.addSelectors(document.styleSheets); | 143 this.addSelectors(document.styleSheets); |
142 document.addEventListener("load", this.onLoad.bind(this), true); | 144 document.addEventListener("load", this.onLoad.bind(this), true); |
143 } | 145 } |
144 } | 146 } |
145 }; | 147 }; |
LEFT | RIGHT |