| 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 |
| 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 /* globals checkCollapse, elemhide, getURLsFromElement, typeMap */ | |
| 19 | |
| 18 "use strict"; | 20 "use strict"; |
| 19 | 21 |
| 20 // The page ID for the popup filter selection dialog (top frame only). | 22 // The page ID for the popup filter selection dialog (top frame only). |
| 21 let blockelementPopupId = null; | 23 let blockelementPopupId = null; |
| 22 | 24 |
| 23 // Element picking state (top frame only). | 25 // Element picking state (top frame only). |
| 24 let currentlyPickingElement = false; | 26 let currentlyPickingElement = false; |
| 25 let lastMouseOverEvent = null; | 27 let lastMouseOverEvent = null; |
| 26 | 28 |
| 27 // During element picking this is the currently highlighted element. When | 29 // During element picking this is the currently highlighted element. When |
| 28 // element has been picked this is the element that is due to be blocked. | 30 // element has been picked this is the element that is due to be blocked. |
| 29 let currentElement = null; | 31 let currentElement = null; |
| 30 | 32 |
| 31 // Highlighting state, used by the top frame during element picking and all | 33 // Highlighting state, used by the top frame during element picking and all |
| 32 // frames when the chosen element is highlighted red. | 34 // frames when the chosen element is highlighted red. |
| 33 let highlightedElementsSelector = null; | 35 let highlightedElementsSelector = null; |
| 34 let highlightedElementsInterval = null; | 36 let highlightedElementsInterval = null; |
| 35 | 37 |
| 36 // 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. |
| 37 let lastRightClickEvent = null; | 39 let lastRightClickEvent = null; |
| 38 let lastRightClickEventIsMostRecent = false; | 40 let lastRightClickEventIsMostRecent = false; |
| 39 | 41 |
| 40 | 42 |
| 41 /* Utilities */ | 43 /* Utilities */ |
| 42 | 44 |
| 43 function getFiltersForElement(element, callback) | 45 function getFiltersForElement(element, callback) |
| 44 { | 46 { |
| 45 let src = element.getAttribute("src"); | 47 let src = element.getAttribute("src"); |
| 46 ext.backgroundPage.sendMessage( | 48 ext.backgroundPage.sendMessage({ |
| 47 { | |
| 48 type: "composer.getFilters", | 49 type: "composer.getFilters", |
| 49 tagName: element.localName, | 50 tagName: element.localName, |
| 50 id: element.id, | 51 id: element.id, |
| 51 src: src && src.length <= 1000 ? src : null, | 52 src: src && src.length <= 1000 ? src : null, |
| 52 style: element.getAttribute("style"), | 53 style: element.getAttribute("style"), |
| 53 classes: Array.prototype.slice.call(element.classList), | 54 classes: Array.prototype.slice.call(element.classList), |
| 54 urls: getURLsFromElement(element), | 55 urls: getURLsFromElement(element), |
| 55 mediatype: typeMap[element.localName], | 56 mediatype: typeMap.get(element.localName), |
| 56 baseURL: document.location.href | 57 baseURL: document.location.href |
| 57 }, | 58 }, |
| 58 response => | 59 response => |
| 59 { | 60 { |
| 60 callback(response.filters, response.selectors); | 61 callback(response.filters, response.selectors); |
| 61 }); | 62 }); |
| 62 } | 63 } |
| 63 | 64 |
| 64 function getBlockableElementOrAncestor(element, callback) | 65 function getBlockableElementOrAncestor(element, callback) |
| 65 { | 66 { |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 381 { | 382 { |
| 382 if (!currentElement) | 383 if (!currentElement) |
| 383 return; | 384 return; |
| 384 | 385 |
| 385 let element = currentElement.prisoner || currentElement; | 386 let element = currentElement.prisoner || currentElement; |
| 386 getFiltersForElement(element, (filters, selectors) => | 387 getFiltersForElement(element, (filters, selectors) => |
| 387 { | 388 { |
| 388 if (currentlyPickingElement) | 389 if (currentlyPickingElement) |
| 389 stopPickingElement(); | 390 stopPickingElement(); |
| 390 | 391 |
| 391 ext.backgroundPage.sendMessage( | 392 ext.backgroundPage.sendMessage({ |
| 392 { | |
| 393 type: "composer.openDialog" | 393 type: "composer.openDialog" |
| 394 }, | 394 }, |
| 395 popupId => | 395 popupId => |
| 396 { | 396 { |
| 397 ext.backgroundPage.sendMessage( | 397 ext.backgroundPage.sendMessage({ |
| 398 { | |
| 399 type: "forward", | 398 type: "forward", |
| 400 targetPageId: popupId, | 399 targetPageId: popupId, |
| 401 payload: | 400 payload: {type: "composer.dialog.init", filters} |
| 402 { | |
| 403 type: "composer.dialog.init", | |
| 404 filters: filters | |
| 405 } | |
| 406 }); | 401 }); |
| 407 | 402 |
| 408 // 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, |
| 409 // 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. |
| 410 if (window == window.top) | 405 if (window == window.top) |
| 411 { | 406 { |
| 412 blockelementPopupId = popupId; | 407 blockelementPopupId = popupId; |
| 413 } | 408 } |
| 414 else | 409 else |
| 415 { | 410 { |
| 416 ext.backgroundPage.sendMessage( | 411 ext.backgroundPage.sendMessage({ |
| 417 { | |
| 418 type: "forward", | 412 type: "forward", |
| 419 payload: | 413 payload: {type: "composer.content.dialogOpened", popupId} |
| 420 { | |
| 421 type: "composer.content.dialogOpened", | |
| 422 popupId: popupId | |
| 423 } | |
| 424 }); | 414 }); |
| 425 } | 415 } |
| 426 }); | 416 }); |
| 427 | 417 |
| 428 if (selectors.length > 0) | 418 if (selectors.length > 0) |
| 429 highlightElements(selectors.join(",")); | 419 highlightElements(selectors.join(",")); |
| 430 | 420 |
| 431 highlightElement(currentElement, "#fd1708", "#f6a1b5"); | 421 highlightElement(currentElement, "#fd1708", "#f6a1b5"); |
| 432 }); | 422 }); |
| 433 | 423 |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 454 /* Core logic */ | 444 /* Core logic */ |
| 455 | 445 |
| 456 // 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. |
| 457 function deactivateBlockElement() | 447 function deactivateBlockElement() |
| 458 { | 448 { |
| 459 if (currentlyPickingElement) | 449 if (currentlyPickingElement) |
| 460 stopPickingElement(); | 450 stopPickingElement(); |
| 461 | 451 |
| 462 if (blockelementPopupId != null) | 452 if (blockelementPopupId != null) |
| 463 { | 453 { |
| 464 ext.backgroundPage.sendMessage( | 454 ext.backgroundPage.sendMessage({ |
| 465 { | |
| 466 type: "forward", | 455 type: "forward", |
| 467 targetPageId: blockelementPopupId, | 456 targetPageId: blockelementPopupId, |
| 468 payload: | 457 payload: |
| 469 { | 458 { |
| 470 type: "composer.dialog.close" | 459 type: "composer.dialog.close" |
| 471 } | 460 } |
| 472 }); | 461 }); |
| 473 | 462 |
| 474 blockelementPopupId = null; | 463 blockelementPopupId = null; |
| 475 } | 464 } |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 497 // 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 |
| 498 // element. | 487 // element. |
| 499 // 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, |
| 500 // 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 |
| 501 // 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. |
| 502 document.addEventListener("contextmenu", event => | 491 document.addEventListener("contextmenu", event => |
| 503 { | 492 { |
| 504 lastRightClickEvent = event; | 493 lastRightClickEvent = event; |
| 505 lastRightClickEventIsMostRecent = true; | 494 lastRightClickEventIsMostRecent = true; |
| 506 | 495 |
| 507 ext.backgroundPage.sendMessage( | 496 ext.backgroundPage.sendMessage({ |
| 508 { | |
| 509 type: "forward", | 497 type: "forward", |
| 510 payload: | 498 payload: |
| 511 { | 499 { |
| 512 type: "composer.content.clearPreviousRightClickEvent" | 500 type: "composer.content.clearPreviousRightClickEvent" |
| 513 } | 501 } |
| 514 }); | 502 }); |
| 515 }, true); | 503 }, true); |
| 516 | 504 |
| 517 ext.onMessage.addListener((msg, sender, sendResponse) => | 505 ext.onMessage.addListener((msg, sender, sendResponse) => |
| 518 { | 506 { |
| 519 switch (msg.type) | 507 switch (msg.type) |
| 520 { | 508 { |
| 521 case "composer.content.getState": | 509 case "composer.content.getState": |
| 522 if (window == window.top) | 510 if (window == window.top) |
| 511 { | |
|
Sebastian Noack
2017/03/29 17:14:12
Apparently we turned the "curly" rule off in the e
kzar
2017/03/30 07:20:43
I've removed most of those unrelated curly changes
| |
| 523 sendResponse({ | 512 sendResponse({ |
| 524 active: currentlyPickingElement || blockelementPopupId != null | 513 active: currentlyPickingElement || blockelementPopupId != null |
| 525 }); | 514 }); |
| 515 } | |
| 526 break; | 516 break; |
| 527 case "composer.content.startPickingElement": | 517 case "composer.content.startPickingElement": |
| 528 if (window == window.top) | 518 if (window == window.top) |
| 529 startPickingElement(); | 519 startPickingElement(); |
| 530 break; | 520 break; |
| 531 case "composer.content.contextMenuClicked": | 521 case "composer.content.contextMenuClicked": |
| 532 let event = lastRightClickEvent; | 522 let event = lastRightClickEvent; |
| 533 deactivateBlockElement(); | 523 deactivateBlockElement(); |
| 534 if (event) | 524 if (event) |
| 535 { | 525 { |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 565 break; | 555 break; |
| 566 case "composer.content.dialogOpened": | 556 case "composer.content.dialogOpened": |
| 567 if (window == window.top) | 557 if (window == window.top) |
| 568 blockelementPopupId = msg.popupId; | 558 blockelementPopupId = msg.popupId; |
| 569 break; | 559 break; |
| 570 case "composer.content.dialogClosed": | 560 case "composer.content.dialogClosed": |
| 571 // 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 |
| 572 // 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.) |
| 573 if (window == window.top && blockelementPopupId == msg.popupId) | 563 if (window == window.top && blockelementPopupId == msg.popupId) |
| 574 { | 564 { |
| 575 ext.backgroundPage.sendMessage( | 565 ext.backgroundPage.sendMessage({ |
| 576 { | |
| 577 type: "forward", | 566 type: "forward", |
| 578 payload: | 567 payload: |
| 579 { | 568 { |
| 580 type: "composer.content.finished" | 569 type: "composer.content.finished" |
| 581 } | 570 } |
| 582 }); | 571 }); |
| 583 } | 572 } |
| 584 break; | 573 break; |
| 585 } | 574 } |
| 586 }); | 575 }); |
| 587 | 576 |
| 588 if (window == window.top) | 577 if (window == window.top) |
| 589 ext.backgroundPage.sendMessage({type: "composer.ready"}); | 578 ext.backgroundPage.sendMessage({type: "composer.ready"}); |
| 590 } | 579 } |
| OLD | NEW |