| 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 27 matching lines...) Expand all  Loading... | 
| 38 // Last right click state stored for element blocking via the context menu. | 38 // Last right click state stored for element blocking via the context menu. | 
| 39 let lastRightClickEvent = null; | 39 let lastRightClickEvent = null; | 
| 40 let lastRightClickEventIsMostRecent = false; | 40 let lastRightClickEventIsMostRecent = false; | 
| 41 | 41 | 
| 42 | 42 | 
| 43 /* Utilities */ | 43 /* Utilities */ | 
| 44 | 44 | 
| 45 function getFiltersForElement(element, callback) | 45 function getFiltersForElement(element, callback) | 
| 46 { | 46 { | 
| 47   let src = element.getAttribute("src"); | 47   let src = element.getAttribute("src"); | 
| 48   chrome.runtime.sendMessage({ | 48   browser.runtime.sendMessage({ | 
| 49     type: "composer.getFilters", | 49     type: "composer.getFilters", | 
| 50     tagName: element.localName, | 50     tagName: element.localName, | 
| 51     id: element.id, | 51     id: element.id, | 
| 52     src: src && src.length <= 1000 ? src : null, | 52     src: src && src.length <= 1000 ? src : null, | 
| 53     style: element.getAttribute("style"), | 53     style: element.getAttribute("style"), | 
| 54     classes: Array.prototype.slice.call(element.classList), | 54     classes: Array.prototype.slice.call(element.classList), | 
| 55     urls: getURLsFromElement(element), | 55     urls: getURLsFromElement(element), | 
| 56     mediatype: typeMap.get(element.localName), | 56     mediatype: typeMap.get(element.localName), | 
| 57     baseURL: document.location.href | 57     baseURL: document.location.href | 
| 58   }, | 58   }, | 
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 382 { | 382 { | 
| 383   if (!currentElement) | 383   if (!currentElement) | 
| 384     return; | 384     return; | 
| 385 | 385 | 
| 386   let element = currentElement.prisoner || currentElement; | 386   let element = currentElement.prisoner || currentElement; | 
| 387   getFiltersForElement(element, (filters, selectors) => | 387   getFiltersForElement(element, (filters, selectors) => | 
| 388   { | 388   { | 
| 389     if (currentlyPickingElement) | 389     if (currentlyPickingElement) | 
| 390       stopPickingElement(); | 390       stopPickingElement(); | 
| 391 | 391 | 
| 392     chrome.runtime.sendMessage({ | 392     browser.runtime.sendMessage({ | 
| 393       type: "composer.openDialog" | 393       type: "composer.openDialog" | 
| 394     }, | 394     }, | 
| 395     popupId => | 395     popupId => | 
| 396     { | 396     { | 
| 397       chrome.runtime.sendMessage({ | 397       browser.runtime.sendMessage({ | 
| 398         type: "forward", | 398         type: "forward", | 
| 399         targetPageId: popupId, | 399         targetPageId: popupId, | 
| 400         payload: {type: "composer.dialog.init", filters} | 400         payload: {type: "composer.dialog.init", filters} | 
| 401       }); | 401       }); | 
| 402 | 402 | 
| 403       // Only the top frame keeps a record of the popup window's ID, | 403       // Only the top frame keeps a record of the popup window's ID, | 
| 404       // so if this isn't the top frame we need to pass the ID on. | 404       // so if this isn't the top frame we need to pass the ID on. | 
| 405       if (window == window.top) | 405       if (window == window.top) | 
| 406       { | 406       { | 
| 407         blockelementPopupId = popupId; | 407         blockelementPopupId = popupId; | 
| 408       } | 408       } | 
| 409       else | 409       else | 
| 410       { | 410       { | 
| 411         chrome.runtime.sendMessage({ | 411         browser.runtime.sendMessage({ | 
| 412           type: "forward", | 412           type: "forward", | 
| 413           payload: {type: "composer.content.dialogOpened", popupId} | 413           payload: {type: "composer.content.dialogOpened", popupId} | 
| 414         }); | 414         }); | 
| 415       } | 415       } | 
| 416     }); | 416     }); | 
| 417 | 417 | 
| 418     if (selectors.length > 0) | 418     if (selectors.length > 0) | 
| 419       highlightElements(selectors.join(",")); | 419       highlightElements(selectors.join(",")); | 
| 420 | 420 | 
| 421     highlightElement(currentElement, "#fd1708", "#f6a1b5"); | 421     highlightElement(currentElement, "#fd1708", "#f6a1b5"); | 
| (...skipping 22 matching lines...) Expand all  Loading... | 
| 444 /* Core logic */ | 444 /* Core logic */ | 
| 445 | 445 | 
| 446 // We're done with the block element feature for now, tidy everything up. | 446 // We're done with the block element feature for now, tidy everything up. | 
| 447 function deactivateBlockElement() | 447 function deactivateBlockElement() | 
| 448 { | 448 { | 
| 449   if (currentlyPickingElement) | 449   if (currentlyPickingElement) | 
| 450     stopPickingElement(); | 450     stopPickingElement(); | 
| 451 | 451 | 
| 452   if (blockelementPopupId != null) | 452   if (blockelementPopupId != null) | 
| 453   { | 453   { | 
| 454     chrome.runtime.sendMessage({ | 454     browser.runtime.sendMessage({ | 
| 455       type: "forward", | 455       type: "forward", | 
| 456       targetPageId: blockelementPopupId, | 456       targetPageId: blockelementPopupId, | 
| 457       payload: | 457       payload: | 
| 458       { | 458       { | 
| 459         type: "composer.dialog.close" | 459         type: "composer.dialog.close" | 
| 460       } | 460       } | 
| 461     }); | 461     }); | 
| 462 | 462 | 
| 463     blockelementPopupId = null; | 463     blockelementPopupId = null; | 
| 464   } | 464   } | 
| (...skipping 21 matching lines...) Expand all  Loading... | 
| 486   // this because the contextMenu API only provides a URL, not the actual DOM | 486   // this because the contextMenu API only provides a URL, not the actual DOM | 
| 487   // element. | 487   // element. | 
| 488   //   We also need to make sure that the previous right click event, | 488   //   We also need to make sure that the previous right click event, | 
| 489   // if there is one, is removed. We don't know which frame it is in so we must | 489   // if there is one, is removed. We don't know which frame it is in so we must | 
| 490   // send a message to the other frames to clear their old right click events. | 490   // send a message to the other frames to clear their old right click events. | 
| 491   document.addEventListener("contextmenu", event => | 491   document.addEventListener("contextmenu", event => | 
| 492   { | 492   { | 
| 493     lastRightClickEvent = event; | 493     lastRightClickEvent = event; | 
| 494     lastRightClickEventIsMostRecent = true; | 494     lastRightClickEventIsMostRecent = true; | 
| 495 | 495 | 
| 496     chrome.runtime.sendMessage({ | 496     browser.runtime.sendMessage({ | 
| 497       type: "forward", | 497       type: "forward", | 
| 498       payload: | 498       payload: | 
| 499       { | 499       { | 
| 500         type: "composer.content.clearPreviousRightClickEvent" | 500         type: "composer.content.clearPreviousRightClickEvent" | 
| 501       } | 501       } | 
| 502     }); | 502     }); | 
| 503   }, true); | 503   }, true); | 
| 504 | 504 | 
| 505   ext.onMessage.addListener((msg, sender, sendResponse) => | 505   ext.onMessage.addListener((msg, sender, sendResponse) => | 
| 506   { | 506   { | 
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 555         break; | 555         break; | 
| 556       case "composer.content.dialogOpened": | 556       case "composer.content.dialogOpened": | 
| 557         if (window == window.top) | 557         if (window == window.top) | 
| 558           blockelementPopupId = msg.popupId; | 558           blockelementPopupId = msg.popupId; | 
| 559         break; | 559         break; | 
| 560       case "composer.content.dialogClosed": | 560       case "composer.content.dialogClosed": | 
| 561         // The onRemoved hook for the popup can create a race condition, so we | 561         // The onRemoved hook for the popup can create a race condition, so we | 
| 562         // to be careful here. (This is not perfect, but best we can do.) | 562         // to be careful here. (This is not perfect, but best we can do.) | 
| 563         if (window == window.top && blockelementPopupId == msg.popupId) | 563         if (window == window.top && blockelementPopupId == msg.popupId) | 
| 564         { | 564         { | 
| 565           chrome.runtime.sendMessage({ | 565           browser.runtime.sendMessage({ | 
| 566             type: "forward", | 566             type: "forward", | 
| 567             payload: | 567             payload: | 
| 568             { | 568             { | 
| 569               type: "composer.content.finished" | 569               type: "composer.content.finished" | 
| 570             } | 570             } | 
| 571           }); | 571           }); | 
| 572         } | 572         } | 
| 573         break; | 573         break; | 
| 574     } | 574     } | 
| 575   }); | 575   }); | 
| 576 | 576 | 
| 577   if (window == window.top) | 577   if (window == window.top) | 
| 578     chrome.runtime.sendMessage({type: "composer.ready"}); | 578     browser.runtime.sendMessage({type: "composer.ready"}); | 
| 579 } | 579 } | 
| OLD | NEW | 
|---|