| Left: | ||
| Right: |
| 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-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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 57 baseURL: document.location.href | 57 baseURL: document.location.href |
| 58 }, | 58 }, |
| 59 response => | 59 response => |
| 60 { | 60 { |
| 61 callback(response.filters, response.selectors); | 61 callback(response.filters, response.selectors); |
| 62 }); | 62 }); |
| 63 } | 63 } |
| 64 | 64 |
| 65 function getBlockableElementOrAncestor(element, callback) | 65 function getBlockableElementOrAncestor(element, callback) |
| 66 { | 66 { |
| 67 // If we're offering to block the iframe element given by window.frameElement | |
| 68 // we must use the context of the parent frame. | |
| 69 let document = element.ownerDocument; | |
| 70 let HTMLElement = document.defaultView.HTMLElement; | |
| 71 | |
| 67 // We assume that the user doesn't want to block the whole page. | 72 // We assume that the user doesn't want to block the whole page. |
| 68 // So we never consider the <html> or <body> element. | 73 // So we never consider the <html> or <body> element. |
| 69 while (element && element != document.documentElement && | 74 while (element && element != document.documentElement && |
| 70 element != document.body) | 75 element != document.body) |
| 71 { | 76 { |
| 72 // We can't handle non-HTML (like SVG) elements, as well as | 77 // We can't handle non-HTML (like SVG) elements, as well as |
| 73 // <area> elements (see below). So fall back to the parent element. | 78 // <area> elements (see below). So fall back to the parent element. |
| 74 if (!(element instanceof HTMLElement) || element.localName == "area") | 79 if (!(element instanceof HTMLElement) || element.localName == "area") |
| 75 element = element.parentElement; | 80 element = element.parentElement; |
| 76 | 81 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 115 // We reached the document root without finding a blockable element. | 120 // We reached the document root without finding a blockable element. |
| 116 callback(null); | 121 callback(null); |
| 117 } | 122 } |
| 118 | 123 |
| 119 | 124 |
| 120 /* Element highlighting */ | 125 /* Element highlighting */ |
| 121 | 126 |
| 122 // Adds an overlay to an element in order to highlight it. | 127 // Adds an overlay to an element in order to highlight it. |
| 123 function addElementOverlay(element) | 128 function addElementOverlay(element) |
| 124 { | 129 { |
| 130 let document = element.ownerDocument; | |
| 131 | |
| 125 let position = "absolute"; | 132 let position = "absolute"; |
| 126 let offsetX = window.scrollX; | 133 let offsetX = window.scrollX; |
| 127 let offsetY = window.scrollY; | 134 let offsetY = window.scrollY; |
| 128 | 135 |
| 129 for (let e = element; e; e = e.parentElement) | 136 for (let e = element; e; e = e.parentElement) |
| 130 { | 137 { |
| 131 let style = getComputedStyle(e); | 138 let style = getComputedStyle(e); |
| 132 | 139 |
| 133 // If the element isn't rendered (since its or one of its ancestor's | 140 // If the element isn't rendered (since its or one of its ancestor's |
| 134 // "display" property is "none"), the overlay wouldn't match the element. | 141 // "display" property is "none"), the overlay wouldn't match the element. |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 414 }); | 421 }); |
| 415 } | 422 } |
| 416 }); | 423 }); |
| 417 | 424 |
| 418 if (selectors.length > 0) | 425 if (selectors.length > 0) |
| 419 highlightElements(selectors.join(",")); | 426 highlightElements(selectors.join(",")); |
| 420 | 427 |
| 421 highlightElement(currentElement, "#fd1708", "#f6a1b5"); | 428 highlightElement(currentElement, "#fd1708", "#f6a1b5"); |
| 422 }); | 429 }); |
| 423 | 430 |
| 424 event.preventDefault(); | 431 if (event) |
| 425 event.stopPropagation(); | 432 { |
| 433 event.preventDefault(); | |
| 434 event.stopPropagation(); | |
| 435 } | |
| 426 } | 436 } |
| 427 | 437 |
| 428 function stopPickingElement() | 438 function stopPickingElement() |
| 429 { | 439 { |
| 430 currentlyPickingElement = false; | 440 currentlyPickingElement = false; |
| 431 | 441 |
| 432 document.removeEventListener("mousedown", stopEventPropagation, true); | 442 document.removeEventListener("mousedown", stopEventPropagation, true); |
| 433 document.removeEventListener("mouseup", stopEventPropagation, true); | 443 document.removeEventListener("mouseup", stopEventPropagation, true); |
| 434 document.removeEventListener("mouseenter", stopEventPropagation, true); | 444 document.removeEventListener("mouseenter", stopEventPropagation, true); |
| 435 document.removeEventListener("mouseleave", stopEventPropagation, true); | 445 document.removeEventListener("mouseleave", stopEventPropagation, true); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 513 active: currentlyPickingElement || blockelementPopupId != null | 523 active: currentlyPickingElement || blockelementPopupId != null |
| 514 }); | 524 }); |
| 515 } | 525 } |
| 516 break; | 526 break; |
| 517 case "composer.content.startPickingElement": | 527 case "composer.content.startPickingElement": |
| 518 if (window == window.top) | 528 if (window == window.top) |
| 519 startPickingElement(); | 529 startPickingElement(); |
| 520 break; | 530 break; |
| 521 case "composer.content.contextMenuClicked": | 531 case "composer.content.contextMenuClicked": |
| 522 let event = lastRightClickEvent; | 532 let event = lastRightClickEvent; |
| 533 let target = event && event.target; | |
| 534 | |
| 535 // When the user attempts to block an element inside an iframe for which | |
| 536 // our right click event listener was trashed the best we can do is to | |
| 537 // offer to block the entire iframe. This of course only works if the | |
| 538 // parent frame is considered to be of the same origin. | |
| 539 // Note: Since Edge doesn't yet support per-frame messaging[1] we | |
| 540 // can't use this workaround there yet. (The contextMenuClicked message | |
| 541 // will be sent to all of the page's frames.) | |
| 542 // [1] - https://developer.microsoft.com/en-us/microsoft-edge/platform/d ocumentation/extensions/api-support/supported-apis/ | |
| 543 if (!target && window.frameElement && typeof chrome != "undefined") | |
|
kzar
2017/08/09 15:29:24
Note: This check `typeof chrome != "undefined"` is
kzar
2017/10/18 14:57:26
Done.
| |
| 544 target = addElementOverlay(window.frameElement); | |
| 545 | |
| 523 deactivateBlockElement(); | 546 deactivateBlockElement(); |
| 524 if (event) | 547 if (target) |
| 525 { | 548 { |
| 526 getBlockableElementOrAncestor(event.target, element => | 549 getBlockableElementOrAncestor(target, element => |
| 527 { | 550 { |
| 528 if (element) | 551 if (element) |
| 529 { | 552 { |
| 530 currentElement = element; | 553 currentElement = element; |
| 531 elementPicked(event); | 554 elementPicked(event); |
| 532 } | 555 } |
| 533 }); | 556 }); |
| 534 } | 557 } |
| 535 break; | 558 break; |
| 536 case "composer.content.finished": | 559 case "composer.content.finished": |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 570 } | 593 } |
| 571 }); | 594 }); |
| 572 } | 595 } |
| 573 break; | 596 break; |
| 574 } | 597 } |
| 575 }); | 598 }); |
| 576 | 599 |
| 577 if (window == window.top) | 600 if (window == window.top) |
| 578 ext.backgroundPage.sendMessage({type: "composer.ready"}); | 601 ext.backgroundPage.sendMessage({type: "composer.ready"}); |
| 579 } | 602 } |
| OLD | NEW |