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: Separate unrelated changes into other code reviews Created Jan. 16, 2015, 8:29 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
« background.js ('K') | « background.js ('k') | 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 lastRightClickEventRandom = null;
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: "clickHide-showDialog",
537 screenX: e.screenX,
538 screenY: e.screenY,
539 clickHideFilters: clickHideFilters
540 });
529 541
530 // Highlight the elements specified by selector in yellow 542 // Highlight the elements specified by selector in yellow
531 if (selectorList.length > 0) 543 if (selectorList.length > 0)
532 highlightElements(selectorList.join(",")); 544 highlightElements(selectorList.join(","));
533 // Now, actually highlight the element the user clicked on in red 545 // Now, actually highlight the element the user clicked on in red
534 highlightElement(currentElement, "#fd1708", "#f6a1b5"); 546 highlightElement(currentElement, "#fd1708", "#f6a1b5");
535 547
536 // Make sure the browser doesn't handle this click 548 // Make sure the browser doesn't handle this click
537 e.preventDefault(); 549 e.preventDefault();
538 e.stopPropagation(); 550 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 582 // 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 583 // 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". 584 // exists before continuing to avoid "Uncaught ReferenceError: ext is not define d".
573 // See https://crbug.com/416907 585 // See https://crbug.com/416907
574 if ("ext" in window && document instanceof HTMLDocument) 586 if ("ext" in window && document instanceof HTMLDocument)
575 { 587 {
576 // Use a contextmenu handler to save the last element the user right-clicked o n. 588 // 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. 589 // 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 590 // We have to do this because the contextMenu API only provides a URL, not the actual
579 // DOM element. 591 // DOM element.
580 document.addEventListener('contextmenu', function(e) { 592 document.addEventListener('contextmenu', function(e)
593 {
581 lastRightClickEvent = e; 594 lastRightClickEvent = e;
595 // We also need to ensure any old lastRightClickEvent variables in other
596 // frames are cleared. So we store a random number, send a message to all
597 // frames that they should clear lastRightClickEvent unless the number match es
598 lastRightClickEventRandom = Math.random();
Sebastian Noack 2015/01/16 22:45:31 I don't really like the approach here to generate
kzar 2015/01/16 23:03:45 Done.
599 ext.backgroundPage.sendMessage(
600 {
601 type: "clickHide-clear-lastRightClickEvent",
602 random: lastRightClickEventRandom
603 });
582 }, true); 604 }, true);
583 605
584 document.addEventListener("click", function(event) 606 document.addEventListener("click", function(event)
585 { 607 {
586 // Ignore right-clicks 608 // Ignore right-clicks
587 if (event.button == 2) 609 if (event.button == 2)
588 return; 610 return;
589 611
590 // Search the link associated with the click 612 // Search the link associated with the click
591 var link = event.target; 613 var link = event.target;
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
674 } 696 }
675 break; 697 break;
676 case "clickhide-move": 698 case "clickhide-move":
677 if (clickHideFiltersDialog) 699 if (clickHideFiltersDialog)
678 { 700 {
679 clickHideFiltersDialog.style.left = (parseInt(clickHideFiltersDialog.s tyle.left, 10) + msg.x) + "px"; 701 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"; 702 clickHideFiltersDialog.style.top = (parseInt(clickHideFiltersDialog.st yle.top, 10) + msg.y) + "px";
681 } 703 }
682 break; 704 break;
683 case "clickhide-close": 705 case "clickhide-close":
684 if (clickHideFiltersDialog && msg.remove) 706 if (currentElement && msg.remove)
685 { 707 {
686 // Explicitly get rid of currentElement 708 // Explicitly get rid of currentElement
687 var element = currentElement.prisoner || currentElement; 709 var element = currentElement.prisoner || currentElement;
688 if (element && element.parentNode) 710 if (element && element.parentNode)
689 element.parentNode.removeChild(element); 711 element.parentNode.removeChild(element);
690 } 712 }
691 clickHide_deactivate(); 713 clickHide_deactivate();
692 break; 714 break;
715 case "clickHide-showDialog":
Sebastian Noack 2015/01/16 22:45:31 For consistency with the message types implemented
kzar 2015/01/16 23:03:45 Done.
716 if (window.self == window.top)
717 clickHide_showDialog(msg.screenX + window.pageXOffset,
718 msg.screenY + window.pageYOffset,
719 msg.clickHideFilters);
720 break;
721 case "clickHide-clear-lastRightClickEvent":
722 if (msg.random != lastRightClickEventRandom)
723 lastRightClickEvent = null;
724 lastRightClickEventRandom = null;
725 break;
693 } 726 }
694 }); 727 });
695 728
696 if (window == window.top) 729 if (window == window.top)
697 ext.backgroundPage.sendMessage({type: "report-html-page"}); 730 ext.backgroundPage.sendMessage({type: "report-html-page"});
698 } 731 }
OLDNEW
« background.js ('K') | « background.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld