Left: | ||
Right: |
LEFT | RIGHT |
---|---|
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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
114 function refreshIconAndContextMenu(tab) | 114 function refreshIconAndContextMenu(tab) |
115 { | 115 { |
116 // The tab could have been closed by the time this function is called | 116 // The tab could have been closed by the time this function is called |
117 if(!tab) | 117 if(!tab) |
118 return; | 118 return; |
119 | 119 |
120 var excluded = isWhitelisted(tab.url); | 120 var excluded = isWhitelisted(tab.url); |
121 var iconFilename = excluded ? "icons/abp-19-whitelisted.png" : "icons/abp-19.p ng"; | 121 var iconFilename = excluded ? "icons/abp-19-whitelisted.png" : "icons/abp-19.p ng"; |
122 | 122 |
123 if (activeNotification) | 123 if (activeNotification) |
124 startIconAnimation(tab, iconFilename); | 124 startIconAnimation(tab, iconFilename); |
Wladimir Palant
2013/07/23 11:53:17
Don't we need to check whether this is actually th
Felix Dahlke
2013/07/23 12:52:02
I don't think it's necessary, since we only refres
| |
125 else | 125 else |
126 chrome.pageAction.setIcon({tabId: tab.id, path: iconFilename}); | 126 chrome.pageAction.setIcon({tabId: tab.id, path: iconFilename}); |
127 | 127 |
128 // Only show icon for pages we can influence (http: and https:) | 128 // Only show icon for pages we can influence (http: and https:) |
129 if(/^https?:/.test(tab.url)) | 129 if(/^https?:/.test(tab.url)) |
130 { | 130 { |
131 chrome.pageAction.setTitle({tabId: tab.id, title: "Adblock Plus"}); | 131 chrome.pageAction.setTitle({tabId: tab.id, title: "Adblock Plus"}); |
132 if ("shouldShowIcon" in localStorage && localStorage["shouldShowIcon"] == "f alse") | 132 if ("shouldShowIcon" in localStorage && localStorage["shouldShowIcon"] == "f alse") |
133 chrome.pageAction.hide(tab.id); | 133 chrome.pageAction.hide(tab.id); |
134 else | 134 else |
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
483 var iconAnimationTimer = null; | 483 var iconAnimationTimer = null; |
484 var animatedIconTab = null; | 484 var animatedIconTab = null; |
485 | 485 |
486 function stopIconAnimation() | 486 function stopIconAnimation() |
487 { | 487 { |
488 if (!iconAnimationTimer) | 488 if (!iconAnimationTimer) |
489 return; | 489 return; |
490 | 490 |
491 clearTimeout(iconAnimationTimer); | 491 clearTimeout(iconAnimationTimer); |
492 iconAnimationTimer = null; | 492 iconAnimationTimer = null; |
493 animatedIconTab = null; | 493 animatedIconTab = null; |
Wladimir Palant
2013/07/23 11:53:17
refreshIconAndContextMenu(animatedIconTab)? Well,
Felix Dahlke
2013/07/23 12:52:02
Not necessary, no. I used to do that here, but rem
| |
494 } | 494 } |
495 | 495 |
496 function loadImages(imageFiles, callback) | 496 function loadImages(imageFiles, callback) |
497 { | 497 { |
498 var images = {}; | 498 var images = {}; |
499 var imagesLoaded = 0; | 499 var imagesLoaded = 0; |
500 imageFiles.forEach(function(imageFile) | 500 imageFiles.forEach(function(imageFile) |
501 { | 501 { |
502 var image = new Image(); | 502 var image = new Image(); |
503 image.src = imageFile; | 503 image.src = imageFile; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
558 interval = 10000; | 558 interval = 10000; |
559 } | 559 } |
560 iconAnimationTimer = setTimeout(animationStep, interval); | 560 iconAnimationTimer = setTimeout(animationStep, interval); |
561 } | 561 } |
562 animationStep(); | 562 animationStep(); |
563 }); | 563 }); |
564 } | 564 } |
565 | 565 |
566 function prepareNotificationIconAndPopup() | 566 function prepareNotificationIconAndPopup() |
567 { | 567 { |
568 function refreshAll(tabs) | |
569 { | |
570 tabs.forEach(refreshIconAndContextMenu); | |
571 } | |
572 | |
573 activeNotification.onClicked = function() | 568 activeNotification.onClicked = function() |
574 { | 569 { |
570 var tab = animatedIconTab; | |
575 stopIconAnimation(); | 571 stopIconAnimation(); |
576 activeNotification = null; | 572 activeNotification = null; |
577 chrome.tabs.query(null, refreshAll); | 573 refreshIconAndContextMenu(tab); |
Wladimir Palant
2013/07/23 11:53:17
Do we still need to refresh all icons here?
if (a
Felix Dahlke
2013/07/23 12:52:02
Done. You're right, it's not necessary anymore now
| |
578 }; | 574 }; |
579 | 575 |
580 chrome.windows.getLastFocused({populate: true}, function(window) | 576 chrome.windows.getLastFocused({populate: true}, function(window) |
581 { | 577 { |
582 chrome.tabs.query({active: true, windowId: window.id}, refreshAll); | 578 chrome.tabs.query({active: true, windowId: window.id}, function(tabs) |
579 { | |
580 tabs.forEach(refreshIconAndContextMenu); | |
581 }); | |
583 }); | 582 }); |
584 } | 583 } |
585 | 584 |
586 function showNotification(notification) | 585 function showNotification(notification) |
587 { | 586 { |
588 activeNotification = notification; | 587 activeNotification = notification; |
589 | 588 |
590 if (activeNotification.severity === "critical") | 589 if (activeNotification.severity === "critical") |
591 { | 590 { |
592 var notification = webkitNotifications.createHTMLNotification("notification. html"); | 591 var notification = webkitNotifications.createHTMLNotification("notification. html"); |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
731 { | 730 { |
732 chrome.tabs.sendRequest(tabId, {reqtype: "clickhide-deactivate"}) | 731 chrome.tabs.sendRequest(tabId, {reqtype: "clickhide-deactivate"}) |
733 if(changeInfo.status == "loading") | 732 if(changeInfo.status == "loading") |
734 refreshIconAndContextMenu(tab); | 733 refreshIconAndContextMenu(tab); |
735 }); | 734 }); |
736 | 735 |
737 // Refresh icon when switching tabs or windows | 736 // Refresh icon when switching tabs or windows |
738 chrome.tabs.onActivated.addListener(function(activeInfo) | 737 chrome.tabs.onActivated.addListener(function(activeInfo) |
739 { | 738 { |
740 refreshIconAndContextMenu(animatedIconTab); | 739 refreshIconAndContextMenu(animatedIconTab); |
741 chrome.tabs.get(activeInfo.tabId, function(tab) | 740 chrome.tabs.get(activeInfo.tabId, refreshIconAndContextMenu); |
742 { | |
743 refreshIconAndContextMenu(tab); | |
744 }); | |
Wladimir Palant
2013/07/23 11:53:17
How about:
chrome.tabs.get(activeInfo.tabId, refr
Felix Dahlke
2013/07/23 12:52:02
Done.
| |
745 }); | 741 }); |
746 chrome.windows.onFocusChanged.addListener(function(windowId) | 742 chrome.windows.onFocusChanged.addListener(function(windowId) |
747 { | 743 { |
748 refreshIconAndContextMenu(animatedIconTab); | 744 refreshIconAndContextMenu(animatedIconTab); |
749 chrome.tabs.query({active: true, windowId: windowId}, function(tabs) | 745 chrome.tabs.query({active: true, windowId: windowId}, function(tabs) |
750 { | 746 { |
751 refreshIconAndContextMenu(tabs[0]); | 747 tabs.forEach(refreshIconAndContextMenu); |
Wladimir Palant
2013/07/23 11:53:17
How about dropping the assumption that there is on
Felix Dahlke
2013/07/23 12:52:02
This should really only be one, but yeah, forEach
| |
752 }); | 748 }); |
753 }); | 749 }); |
754 | 750 |
755 setTimeout(function() | 751 setTimeout(function() |
756 { | 752 { |
757 var notificationToShow = Notification.getNextToShow(); | 753 var notificationToShow = Notification.getNextToShow(); |
758 if (notificationToShow) | 754 if (notificationToShow) |
759 showNotification(notificationToShow); | 755 showNotification(notificationToShow); |
760 }, 3 * 60 * 1000); | 756 }, 3 * 60 * 1000); |
LEFT | RIGHT |