| 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-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 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 434 document.removeEventListener("mouseout", mouseOut, true); | 434 document.removeEventListener("mouseout", mouseOut, true); |
| 435 document.removeEventListener("click", elementPicked, true); | 435 document.removeEventListener("click", elementPicked, true); |
| 436 document.removeEventListener("contextmenu", elementPicked, true); | 436 document.removeEventListener("contextmenu", elementPicked, true); |
| 437 document.removeEventListener("keydown", keyDown, true); | 437 document.removeEventListener("keydown", keyDown, true); |
| 438 } | 438 } |
| 439 | 439 |
| 440 | 440 |
| 441 /* Core logic */ | 441 /* Core logic */ |
| 442 | 442 |
| 443 // We're done with the block element feature for now, tidy everything up. | 443 // We're done with the block element feature for now, tidy everything up. |
| 444 function deactivateBlockElement() | 444 function deactivateBlockElement(popupAlreadyClosed) |
| 445 { | 445 { |
| 446 if (currentlyPickingElement) | 446 if (currentlyPickingElement) |
| 447 stopPickingElement(); | 447 stopPickingElement(); |
| 448 | 448 |
| 449 if (blockelementPopupId != null) | 449 if (blockelementPopupId != null && !popupAlreadyClosed) |
| 450 { | 450 { |
| 451 browser.runtime.sendMessage({ | 451 browser.runtime.sendMessage({ |
| 452 type: "forward", | 452 type: "forward", |
| 453 targetPageId: blockelementPopupId, | 453 targetPageId: blockelementPopupId, |
| 454 payload: | 454 payload: |
| 455 { | 455 { |
| 456 type: "composer.dialog.close" | 456 type: "composer.dialog.close" |
| 457 } | 457 } |
| 458 }); | 458 }); |
| 459 | |
| 460 blockelementPopupId = null; | |
| 461 } | 459 } |
| 462 | 460 |
| 461 blockelementPopupId = null; | |
| 463 lastRightClickEvent = null; | 462 lastRightClickEvent = null; |
| 464 | 463 |
| 465 if (currentElement) | 464 if (currentElement) |
| 466 { | 465 { |
| 467 unhighlightElement(currentElement); | 466 unhighlightElement(currentElement); |
| 468 currentElement = null; | 467 currentElement = null; |
| 469 } | 468 } |
| 470 unhighlightElements(); | 469 unhighlightElements(); |
| 471 | 470 |
| 472 let overlays = document.getElementsByClassName("__adblockplus__overlay"); | 471 let overlays = document.getElementsByClassName("__adblockplus__overlay"); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 539 // Hide the selected element itself if an added blocking | 538 // Hide the selected element itself if an added blocking |
| 540 // filter is causing it to collapse. Note that this | 539 // filter is causing it to collapse. Note that this |
| 541 // behavior is incomplete, but the best we can do here, | 540 // behavior is incomplete, but the best we can do here, |
| 542 // e.g. if an added blocking filter matches other elements, | 541 // e.g. if an added blocking filter matches other elements, |
| 543 // the effect won't be visible until the page is is reloaded. | 542 // the effect won't be visible until the page is is reloaded. |
| 544 checkCollapse(currentElement.prisoner || currentElement); | 543 checkCollapse(currentElement.prisoner || currentElement); |
| 545 | 544 |
| 546 // Apply added element hiding filters. | 545 // Apply added element hiding filters. |
| 547 elemhide.apply(); | 546 elemhide.apply(); |
| 548 } | 547 } |
| 549 deactivateBlockElement(); | 548 deactivateBlockElement(!!message.popupAlreadyClosed); |
| 550 break; | 549 break; |
| 551 case "composer.content.clearPreviousRightClickEvent": | 550 case "composer.content.clearPreviousRightClickEvent": |
| 552 if (!lastRightClickEventIsMostRecent) | 551 if (!lastRightClickEventIsMostRecent) |
| 553 lastRightClickEvent = null; | 552 lastRightClickEvent = null; |
| 554 lastRightClickEventIsMostRecent = false; | 553 lastRightClickEventIsMostRecent = false; |
| 555 break; | 554 break; |
| 556 case "composer.content.dialogOpened": | 555 case "composer.content.dialogOpened": |
| 557 if (window == window.top) | 556 if (window == window.top) |
| 558 blockelementPopupId = message.popupId; | 557 blockelementPopupId = message.popupId; |
| 559 break; | 558 break; |
| 560 case "composer.content.dialogClosed": | 559 case "composer.content.dialogClosed": |
| 561 // The onRemoved hook for the popup can create a race condition, so we | 560 // 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.) | 561 // to be careful here. (This is not perfect, but best we can do.) |
| 563 if (window == window.top && blockelementPopupId == message.popupId) | 562 if (window == window.top && blockelementPopupId == message.popupId) |
| 564 { | 563 { |
| 565 browser.runtime.sendMessage({ | 564 browser.runtime.sendMessage({ |
| 566 type: "forward", | 565 type: "forward", |
| 567 payload: | 566 payload: |
| 568 { | 567 { |
| 569 type: "composer.content.finished" | 568 type: "composer.content.finished", |
| 569 popupAlreadyClosed: true | |
|
Manish Jethani
2018/02/20 11:17:30
We could just call this "dialogClosed" (instead of
kzar
2018/02/20 11:56:44
FWIW I prefer popupAlreadyClosed so I went with th
Manish Jethani
2018/02/20 12:33:25
Sounds good, thanks.
| |
| 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 browser.runtime.sendMessage({type: "composer.ready"}); | 578 browser.runtime.sendMessage({type: "composer.ready"}); |
| 579 | 579 |
| 580 return true; | 580 return true; |
| 581 } | 581 } |
| 582 | 582 |
| 583 if (document instanceof HTMLDocument) | 583 if (document instanceof HTMLDocument) |
| 584 { | 584 { |
| 585 // There's a bug in Firefox that causes document_end content scripts to run | 585 // There's a bug in Firefox that causes document_end content scripts to run |
| 586 // before document_start content scripts on extension startup. In this case | 586 // before document_start content scripts on extension startup. In this case |
| 587 // the ext object is undefined, we fail to initialize, and initializeComposer | 587 // the ext object is undefined, we fail to initialize, and initializeComposer |
| 588 // returns false. As a workaround, try again after a timeout. | 588 // returns false. As a workaround, try again after a timeout. |
| 589 // https://bugzilla.mozilla.org/show_bug.cgi?id=1395287 | 589 // https://bugzilla.mozilla.org/show_bug.cgi?id=1395287 |
| 590 if (!initializeComposer()) | 590 if (!initializeComposer()) |
| 591 setTimeout(initializeComposer, 2000); | 591 setTimeout(initializeComposer, 2000); |
| 592 } | 592 } |
| OLD | NEW |