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

Delta Between Two Patch Sets: safari/ext/background.js

Issue 6346177440120832: Added abstraction for frames, to fix domain-based rules, whitelisting and ad counter on Safari (Closed)
Left Patch Set: Rebased and addressed comments Created Jan. 19, 2014, 10:40 a.m.
Right Patch Set: Addressed another comment Created Jan. 20, 2014, 8:50 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « popupBlocker.js ('k') | safari/ext/common.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <http://adblockplus.org/>, 2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2013 Eyeo GmbH 3 * Copyright (C) 2006-2013 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 609 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 620
621 ext.backgroundPage = { 621 ext.backgroundPage = {
622 getWindow: function() 622 getWindow: function()
623 { 623 {
624 return safari.extension.globalPage.contentWindow; 624 return safari.extension.globalPage.contentWindow;
625 } 625 }
626 }; 626 };
627 627
628 ext.onMessage = new BackgroundMessageEventTarget(); 628 ext.onMessage = new BackgroundMessageEventTarget();
629 629
630 var contextMenu = []; 630 var contextMenuItems = [];
631 var isContextMenuHidden = false; 631 var isContextMenuHidden = true;
632 ext.contextMenus = { 632 ext.contextMenus = {
633 addMenuItem: function(title, contexts, onclick) 633 addMenuItem: function(title, contexts, onclick)
634 { 634 {
635 contextMenu.push({ 635 contextMenuItems.push({
636 id: "block-element", 636 id: String(contextMenuItems.length),
637 title: title, 637 title: title,
638 item: null, 638 item: null,
639 contexts: contexts, 639 contexts: contexts,
640 onclick: onclick 640 onclick: onclick
641 }); 641 });
642 this.showMenuItems();
642 }, 643 },
643 removeMenuItems: function() 644 removeMenuItems: function()
644 { 645 {
645 contextMenu = []; 646 contextMenuItems = [];
646 }, 647 this.hideMenuItems();
647 showMenu: function() 648 },
649 showMenuItems: function()
648 { 650 {
649 isContextMenuHidden = false; 651 isContextMenuHidden = false;
650 }, 652 },
651 hideMenu: function() 653 hideMenuItems: function()
652 { 654 {
653 isContextMenuHidden = true; 655 isContextMenuHidden = true;
654 } 656 }
655 }; 657 };
656 658
657 // Create context menu items 659 // Create context menu items
658 safari.application.addEventListener("contextmenu", function(event) 660 safari.application.addEventListener("contextmenu", function(event)
659 { 661 {
660 var context = event.userInfo.tagName.toLowerCase(); 662 if (isContextMenuHidden)
663 return;
664
665 var context = event.userInfo.tagName;
661 if (context == "img") 666 if (context == "img")
662 context = "image"; 667 context = "image";
663 668 if (!event.userInfo.srcUrl)
664 for (var i = 0; i < contextMenu.length; i++) 669 context = null;
665 { 670
666 if (isContextMenuHidden) 671 for (var i = 0; i < contextMenuItems.length; i++)
667 return; 672 {
668
669 // Supported contexts are: all, audio, image, video 673 // Supported contexts are: all, audio, image, video
670 var menuItem = contextMenu[i]; 674 var menuItem = contextMenuItems[i];
671 if (menuItem.contexts.indexOf("all") == -1 && menuItem.contexts.indexOf(co ntext) == -1) 675 if (menuItem.contexts.indexOf("all") == -1 && menuItem.contexts.indexOf(co ntext) == -1)
672 return; 676 continue;
673 677
674 menuItem.item = event.contextMenu.appendContextMenuItem(menuItem.id, menuI tem.title); 678 event.contextMenu.appendContextMenuItem(menuItem.id, menuItem.title);
675 } 679 }
676 }, false); 680 }, false);
677 681
678 // Handle context menu item clicks 682 // Handle context menu item clicks
679 safari.application.addEventListener("command", function(event) 683 safari.application.addEventListener("command", function(event)
680 { 684 {
681 for (var i = 0; i < contextMenu.length; i++) 685 for (var i = 0; i < contextMenuItems.length; i++)
682 { 686 {
683 if (contextMenu[i].id == event.command) 687 if (contextMenuItems[i].id == event.command)
684 { 688 {
685 contextMenu[i].onclick(event.userInfo.srcUrl, new Tab(safari.application .activeBrowserWindow.activeTab)); 689 contextMenuItems[i].onclick(event.userInfo.srcUrl, new Tab(safari.applic ation.activeBrowserWindow.activeTab));
686 break; 690 break;
687 } 691 }
688 } 692 }
689 }, false); 693 }, false);
690 })(); 694 })();
LEFTRIGHT

Powered by Google App Engine
This is Rietveld