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-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 |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
16 */ | 16 */ |
17 | 17 |
18 "use strict"; | 18 "use strict"; |
19 | 19 |
20 const {checkCollapse, elemhide, | 20 const {checkCollapse, elemhide, |
21 getURLsFromElement, typeMap} = require("./include.preload"); | 21 getURLsFromElement, typeMap} = require("./include.preload"); |
22 const info = require("info"); | |
23 | 22 |
24 // The page ID for the popup filter selection dialog (top frame only). | 23 // The page ID for the popup filter selection dialog (top frame only). |
25 let blockelementPopupId = null; | 24 let blockelementPopupId = null; |
26 | 25 |
27 // Element picking state (top frame only). | 26 // Element picking state (top frame only). |
28 let currentlyPickingElement = false; | 27 let currentlyPickingElement = false; |
29 let lastMouseOverEvent = null; | 28 let lastMouseOverEvent = null; |
30 | 29 |
31 // During element picking this is the currently highlighted element. When | 30 // During element picking this is the currently highlighted element. When |
32 // element has been picked this is the element that is due to be blocked. | 31 // element has been picked this is the element that is due to be blocked. |
33 let currentElement = null; | 32 let currentElement = null; |
34 | 33 |
35 // Highlighting state, used by the top frame during element picking and all | 34 // Highlighting state, used by the top frame during element picking and all |
36 // frames when the chosen element is highlighted red. | 35 // frames when the chosen element is highlighted red. |
37 let highlightedElementsSelector = null; | 36 let highlightedElementsSelector = null; |
38 let highlightedElementsInterval = null; | 37 let highlightedElementsInterval = null; |
39 | 38 |
40 // Last right click state stored for element blocking via the context menu. | 39 // Last right click state stored for element blocking via the context menu. |
41 let lastRightClickEvent = null; | 40 let lastRightClickEvent = null; |
42 let lastRightClickEventIsMostRecent = false; | 41 let lastRightClickEventIsMostRecent = false; |
43 | 42 |
| 43 let perFrameMessagingSupported = false; |
| 44 browser.runtime.sendMessage( |
| 45 {type: "app.get", what: "application"}, |
| 46 application => { perFrameMessagingSupported = application != "edge"; } |
| 47 ); |
44 | 48 |
45 /* Utilities */ | 49 /* Utilities */ |
46 | 50 |
47 function getFiltersForElement(element, callback) | 51 function getFiltersForElement(element, callback) |
48 { | 52 { |
49 let src = element.getAttribute("src"); | 53 let src = element.getAttribute("src"); |
50 browser.runtime.sendMessage({ | 54 browser.runtime.sendMessage({ |
51 type: "composer.getFilters", | 55 type: "composer.getFilters", |
52 tagName: element.localName, | 56 tagName: element.localName, |
53 id: element.id, | 57 id: element.id, |
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
536 case "composer.content.contextMenuClicked": | 540 case "composer.content.contextMenuClicked": |
537 let event = lastRightClickEvent; | 541 let event = lastRightClickEvent; |
538 let target = event && event.target; | 542 let target = event && event.target; |
539 | 543 |
540 // When the user attempts to block an element inside an iframe for which | 544 // When the user attempts to block an element inside an iframe for which |
541 // our right click event listener was trashed the best we can do is to | 545 // our right click event listener was trashed the best we can do is to |
542 // offer to block the entire iframe. This doesn't work for cross origin | 546 // offer to block the entire iframe. This doesn't work for cross origin |
543 // frames, neither on Edge where per-frame messaging isn't supported | 547 // frames, neither on Edge where per-frame messaging isn't supported |
544 // yet[1], but it's the best we can do. | 548 // yet[1], but it's the best we can do. |
545 // [1] - https://developer.microsoft.com/en-us/microsoft-edge/platform/d
ocumentation/extensions/api-support/supported-apis/ | 549 // [1] - https://developer.microsoft.com/en-us/microsoft-edge/platform/d
ocumentation/extensions/api-support/supported-apis/ |
546 if (!target && window.frameElement && info.application != "edge") | 550 if (!target && window.frameElement && perFrameMessagingSupported) |
547 target = addElementOverlay(window.frameElement); | 551 target = addElementOverlay(window.frameElement); |
548 | 552 |
549 deactivateBlockElement(); | 553 deactivateBlockElement(); |
550 if (target) | 554 if (target) |
551 { | 555 { |
552 getBlockableElementOrAncestor(target, element => | 556 getBlockableElementOrAncestor(target, element => |
553 { | 557 { |
554 if (element) | 558 if (element) |
555 { | 559 { |
556 currentElement = element; | 560 currentElement = element; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
609 if (document instanceof HTMLDocument) | 613 if (document instanceof HTMLDocument) |
610 { | 614 { |
611 // There's a bug in Firefox that causes document_end content scripts to run | 615 // There's a bug in Firefox that causes document_end content scripts to run |
612 // before document_start content scripts on extension startup. In this case | 616 // before document_start content scripts on extension startup. In this case |
613 // the ext object is undefined, we fail to initialize, and initializeComposer | 617 // the ext object is undefined, we fail to initialize, and initializeComposer |
614 // returns false. As a workaround, try again after a timeout. | 618 // returns false. As a workaround, try again after a timeout. |
615 // https://bugzilla.mozilla.org/show_bug.cgi?id=1395287 | 619 // https://bugzilla.mozilla.org/show_bug.cgi?id=1395287 |
616 if (!initializeComposer()) | 620 if (!initializeComposer()) |
617 setTimeout(initializeComposer, 2000); | 621 setTimeout(initializeComposer, 2000); |
618 } | 622 } |
LEFT | RIGHT |