Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: include.postload.js

Issue 6264613016436736: Issue #350 - iFrame block element improvements (Closed)
Patch Set: Improve things regarding Sebastian's feedback. Created Jan. 16, 2015, 11:01 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 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 // Click-to-hide stuff 18 // Click-to-hide stuff
19 var clickHide_activated = false; 19 var clickHide_activated = false;
20 var clickHide_filters = null; 20 var clickHide_filters = null;
21 var currentElement = null; 21 var currentElement = null;
22 var highlightedElementsSelector = null; 22 var highlightedElementsSelector = null;
23 var clickHideFiltersDialog = null; 23 var clickHideFiltersDialog = null;
24 var lastRightClickEvent = null; 24 var lastRightClickEvent = null;
25 var lastRightClickEventValid = false;
25 26
26 function escapeChar(chr) 27 function escapeChar(chr)
27 { 28 {
28 var code = chr.charCodeAt(0); 29 var code = chr.charCodeAt(0);
29 30
30 // Control characters and leading digits must be escaped based on 31 // Control characters and leading digits must be escaped based on
31 // their char code in CSS. Moreover, curly brackets aren't allowed 32 // their char code in CSS. Moreover, curly brackets aren't allowed
32 // in elemhide filters, and therefore must be escaped based on their 33 // in elemhide filters, and therefore must be escaped based on their
33 // char code as well. 34 // char code as well.
34 if (code <= 0x1F || code == 0x7F || /[\d\{\}]/.test(chr)) 35 if (code <= 0x1F || code == 0x7F || /[\d\{\}]/.test(chr))
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 clickHide_filters = null; 383 clickHide_filters = null;
383 if(!document) 384 if(!document)
384 return; // This can happen inside a nuked iframe...I think 385 return; // This can happen inside a nuked iframe...I think
385 document.removeEventListener("mouseover", clickHide_mouseOver, true); 386 document.removeEventListener("mouseover", clickHide_mouseOver, true);
386 document.removeEventListener("mouseout", clickHide_mouseOut, true); 387 document.removeEventListener("mouseout", clickHide_mouseOut, true);
387 document.removeEventListener("click", clickHide_mouseClick, true); 388 document.removeEventListener("click", clickHide_mouseClick, true);
388 document.removeEventListener("keydown", clickHide_keyDown, true); 389 document.removeEventListener("keydown", clickHide_keyDown, true);
389 390
390 if (!keepOverlays) 391 if (!keepOverlays)
391 { 392 {
393 lastRightClickEvent = null;
394
392 if (currentElement) { 395 if (currentElement) {
393 currentElement.removeEventListener("contextmenu", clickHide_elementClickH andler, true); 396 currentElement.removeEventListener("contextmenu", clickHide_elementClickH andler, true);
394 unhighlightElements(); 397 unhighlightElements();
395 unhighlightElement(currentElement); 398 unhighlightElement(currentElement);
396 currentElement = null; 399 currentElement = null;
397 } 400 }
398 unhighlightElements(); 401 unhighlightElements();
399 402
400 var overlays = document.getElementsByClassName("__adblockplus__overlay"); 403 var overlays = document.getElementsByClassName("__adblockplus__overlay");
401 while (overlays.length > 0) 404 while (overlays.length > 0)
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 } 520 }
518 521
519 // as last resort, create a filter based on inline styles 522 // as last resort, create a filter based on inline styles
520 if (clickHideFilters.length == 0) 523 if (clickHideFilters.length == 0)
521 { 524 {
522 var style = elt.getAttribute("style"); 525 var style = elt.getAttribute("style");
523 if (style) 526 if (style)
524 addSelector(escapeCSS(elt.localName) + '[style=' + quote(style) + ']'); 527 addSelector(escapeCSS(elt.localName) + '[style=' + quote(style) + ']');
525 } 528 }
526 529
527 // Show popup 530 // Show popup, or if inside frame tell the parent to do it
528 clickHide_showDialog(e.clientX, e.clientY, clickHideFilters); 531 if (window.self == window.top)
532 clickHide_showDialog(e.clientX, e.clientY, clickHideFilters);
533 else
534 ext.backgroundPage.sendMessage(
535 {
536 type: "forward",
537 payload:
538 {
539 type: "clickhide-show-dialog",
540 screenX: e.screenX,
541 screenY: e.screenY,
542 clickHideFilters: clickHideFilters
543 }
544 });
529 545
530 // Highlight the elements specified by selector in yellow 546 // Highlight the elements specified by selector in yellow
531 if (selectorList.length > 0) 547 if (selectorList.length > 0)
532 highlightElements(selectorList.join(",")); 548 highlightElements(selectorList.join(","));
533 // Now, actually highlight the element the user clicked on in red 549 // Now, actually highlight the element the user clicked on in red
534 highlightElement(currentElement, "#fd1708", "#f6a1b5"); 550 highlightElement(currentElement, "#fd1708", "#f6a1b5");
535 551
536 // Make sure the browser doesn't handle this click 552 // Make sure the browser doesn't handle this click
537 e.preventDefault(); 553 e.preventDefault();
538 e.stopPropagation(); 554 e.stopPropagation();
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 // In Chrome 37-40, the document_end content script (this one) runs properly, wh ile the 586 // In Chrome 37-40, the document_end content script (this one) runs properly, wh ile the
571 // document_start content scripts (that defines ext) might not. Check whether va riable ext 587 // document_start content scripts (that defines ext) might not. Check whether va riable ext
572 // exists before continuing to avoid "Uncaught ReferenceError: ext is not define d". 588 // exists before continuing to avoid "Uncaught ReferenceError: ext is not define d".
573 // See https://crbug.com/416907 589 // See https://crbug.com/416907
574 if ("ext" in window && document instanceof HTMLDocument) 590 if ("ext" in window && document instanceof HTMLDocument)
575 { 591 {
576 // Use a contextmenu handler to save the last element the user right-clicked o n. 592 // Use a contextmenu handler to save the last element the user right-clicked o n.
577 // To make things easier, we actually save the DOM event. 593 // To make things easier, we actually save the DOM event.
578 // We have to do this because the contextMenu API only provides a URL, not the actual 594 // We have to do this because the contextMenu API only provides a URL, not the actual
579 // DOM element. 595 // DOM element.
580 document.addEventListener('contextmenu', function(e) { 596 document.addEventListener('contextmenu', function(e)
597 {
581 lastRightClickEvent = e; 598 lastRightClickEvent = e;
599 // We also need to ensure any old lastRightClickEvent variables in other
600 // frames are cleared.
601 lastRightClickEventValid = true;
602 ext.backgroundPage.sendMessage(
603 {
604 type: "forward",
605 payload:
606 {
607 type: "clickhide-clear-last-right-click-event"
608 }
609 });
582 }, true); 610 }, true);
583 611
584 document.addEventListener("click", function(event) 612 document.addEventListener("click", function(event)
585 { 613 {
586 // Ignore right-clicks 614 // Ignore right-clicks
587 if (event.button == 2) 615 if (event.button == 2)
588 return; 616 return;
589 617
590 // Search the link associated with the click 618 // Search the link associated with the click
591 var link = event.target; 619 var link = event.target;
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
674 } 702 }
675 break; 703 break;
676 case "clickhide-move": 704 case "clickhide-move":
677 if (clickHideFiltersDialog) 705 if (clickHideFiltersDialog)
678 { 706 {
679 clickHideFiltersDialog.style.left = (parseInt(clickHideFiltersDialog.s tyle.left, 10) + msg.x) + "px"; 707 clickHideFiltersDialog.style.left = (parseInt(clickHideFiltersDialog.s tyle.left, 10) + msg.x) + "px";
680 clickHideFiltersDialog.style.top = (parseInt(clickHideFiltersDialog.st yle.top, 10) + msg.y) + "px"; 708 clickHideFiltersDialog.style.top = (parseInt(clickHideFiltersDialog.st yle.top, 10) + msg.y) + "px";
681 } 709 }
682 break; 710 break;
683 case "clickhide-close": 711 case "clickhide-close":
684 if (clickHideFiltersDialog && msg.remove) 712 if (currentElement && msg.remove)
685 { 713 {
686 // Explicitly get rid of currentElement 714 // Explicitly get rid of currentElement
687 var element = currentElement.prisoner || currentElement; 715 var element = currentElement.prisoner || currentElement;
688 if (element && element.parentNode) 716 if (element && element.parentNode)
689 element.parentNode.removeChild(element); 717 element.parentNode.removeChild(element);
690 } 718 }
691 clickHide_deactivate(); 719 clickHide_deactivate();
692 break; 720 break;
721 case "clickhide-show-dialog":
722 if (window.self == window.top)
723 clickHide_showDialog(msg.screenX + window.pageXOffset,
724 msg.screenY + window.pageYOffset,
725 msg.clickHideFilters);
726 break;
727 case "clickhide-clear-last-right-click-event":
728 if (lastRightClickEventValid)
729 lastRightClickEventValid = false;
730 else
731 lastRightClickEvent = null;
732 break;
693 } 733 }
694 }); 734 });
695 735
696 if (window == window.top) 736 if (window == window.top)
697 ext.backgroundPage.sendMessage({type: "report-html-page"}); 737 ext.backgroundPage.sendMessage({type: "report-html-page"});
698 } 738 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld