| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 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-2017 eyeo GmbH | 3 * Copyright (C) 2006-2017 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 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 146 return [new PlainSelector(selector)]; | 146 return [new PlainSelector(selector)]; |
| 147 | 147 |
| 148 let selectors = []; | 148 let selectors = []; |
| 149 if (match.index > 0) | 149 if (match.index > 0) |
| 150 selectors.push(new PlainSelector(selector.substr(0, match.index))); | 150 selectors.push(new PlainSelector(selector.substr(0, match.index))); |
| 151 | 151 |
| 152 let startIndex = match.index + match[0].length; | 152 let startIndex = match.index + match[0].length; |
| 153 let content = parseSelectorContent(selector, startIndex); | 153 let content = parseSelectorContent(selector, startIndex); |
| 154 if (!content) | 154 if (!content) |
| 155 { | 155 { |
| 156 reportError(new SyntaxError("Failed parsing content filter " + | 156 reportError(new SyntaxError("Failed to parse Adblock Plus " + |
| 157 `selector ${selector}, didn't ` + | 157 `selector ${selector}, ` + |
| 158 "find closing parenthesis.")); | 158 "due to unmatched parentheses.")); |
| 159 return null; | 159 return null; |
| 160 } | 160 } |
| 161 if (match[1] == "properties") | 161 if (match[1] == "properties") |
| 162 selectors.push(new PropsSelector(content.text)); | 162 selectors.push(new PropsSelector(content.text)); |
| 163 else if (match[1] == "has") | 163 else if (match[1] == "has") |
| 164 { | 164 { |
| 165 let hasSelector = new HasSelector(content.text); | 165 let hasSelector = new HasSelector(content.text); |
| 166 if (!hasSelector.valid()) | 166 if (!hasSelector.valid()) |
| 167 return null; | 167 return null; |
| 168 selectors.push(hasSelector); | 168 selectors.push(hasSelector); |
| 169 } | 169 } |
| 170 else | 170 else |
| 171 { | 171 { |
| 172 // this is an error, can't parse selector. | 172 // this is an error, can't parse selector. |
| 173 reportError(new SyntaxError("Failed parsing content filter " + | 173 reportError(new SyntaxError("Failed to parse Adblock Plus " + |
| 174 `selector ${selector}, invalid ` + | 174 `selector ${selector}, invalid ` + |
| 175 `pseudo-class -abp-${match[1]}().`)); | 175 `pseudo-class :-abp-${match[1]}().`)); |
| 176 return null; | 176 return null; |
| 177 } | 177 } |
| 178 | 178 |
| 179 let suffix = parseSelector(selector.substr(content.end + 1)); | 179 let suffix = parseSelector(selector.substr(content.end + 1)); |
| 180 if (suffix == null) | 180 if (suffix == null) |
| 181 return null; | 181 return null; |
| 182 | 182 |
| 183 selectors.push(...suffix); | 183 selectors.push(...suffix); |
| 184 | 184 |
| 185 return selectors; | 185 return selectors; |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 321 } | 321 } |
| 322 }; | 322 }; |
| 323 | 323 |
| 324 function ElemHideEmulation(window, getFiltersFunc, addSelectorsFunc, | 324 function ElemHideEmulation(window, getFiltersFunc, addSelectorsFunc, |
| 325 hideElemsFunc) | 325 hideElemsFunc) |
| 326 { | 326 { |
| 327 this.window = window; | 327 this.window = window; |
| 328 this.getFiltersFunc = getFiltersFunc; | 328 this.getFiltersFunc = getFiltersFunc; |
| 329 this.addSelectorsFunc = addSelectorsFunc; | 329 this.addSelectorsFunc = addSelectorsFunc; |
| 330 this.hideElemsFunc = hideElemsFunc; | 330 this.hideElemsFunc = hideElemsFunc; |
| 331 reportError = error => this.window.console.error(error); | |
|
Wladimir Palant
2017/06/13 13:16:25
This won't work. There might be multiple windows l
hub
2017/06/13 13:53:33
doing 1)
| |
| 332 } | 331 } |
| 333 | 332 |
| 334 ElemHideEmulation.prototype = { | 333 ElemHideEmulation.prototype = { |
| 335 isSameOrigin(stylesheet) | 334 isSameOrigin(stylesheet) |
| 336 { | 335 { |
| 337 try | 336 try |
| 338 { | 337 { |
| 339 return new URL(stylesheet.href).origin == this.window.location.origin; | 338 return new URL(stylesheet.href).origin == this.window.location.origin; |
| 340 } | 339 } |
| 341 catch (e) | 340 catch (e) |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 405 { | 404 { |
| 406 let stylesheet = event.target.sheet; | 405 let stylesheet = event.target.sheet; |
| 407 if (stylesheet) | 406 if (stylesheet) |
| 408 this.addSelectors([stylesheet]); | 407 this.addSelectors([stylesheet]); |
| 409 }, | 408 }, |
| 410 | 409 |
| 411 apply() | 410 apply() |
| 412 { | 411 { |
| 413 this.getFiltersFunc(patterns => | 412 this.getFiltersFunc(patterns => |
| 414 { | 413 { |
| 414 let oldReportError = reportError; | |
| 415 reportError = error => this.window.console.error(error); | |
| 416 | |
| 415 this.patterns = []; | 417 this.patterns = []; |
| 416 for (let pattern of patterns) | 418 for (let pattern of patterns) |
| 417 { | 419 { |
| 418 let selectors = parseSelector(pattern.selector); | 420 let selectors = parseSelector(pattern.selector); |
| 419 if (selectors != null && selectors.length > 0) | 421 if (selectors != null && selectors.length > 0) |
| 420 this.patterns.push({selectors, text: pattern.text}); | 422 this.patterns.push({selectors, text: pattern.text}); |
| 421 } | 423 } |
| 422 | 424 |
| 423 if (this.patterns.length > 0) | 425 if (this.patterns.length > 0) |
| 424 { | 426 { |
| 425 let {document} = this.window; | 427 let {document} = this.window; |
| 426 this.addSelectors(document.styleSheets); | 428 this.addSelectors(document.styleSheets); |
| 427 document.addEventListener("load", this.onLoad.bind(this), true); | 429 document.addEventListener("load", this.onLoad.bind(this), true); |
| 428 } | 430 } |
| 431 reportError = oldReportError; | |
| 429 }); | 432 }); |
| 430 } | 433 } |
| 431 }; | 434 }; |
| LEFT | RIGHT |