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

Side by Side Diff: background.js

Issue 5196306347720704: Issue 1965 - Simplified and fixed missing image for icon animation (Closed)
Patch Set: Created Feb. 27, 2014, 4:54 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 | iconAnimation.js » ('j') | 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 <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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 if (option in localStorage) 93 if (option in localStorage)
94 delete localStorage[option]; 94 delete localStorage[option];
95 }); 95 });
96 } 96 }
97 97
98 // Remove deprecated options before we do anything else. 98 // Remove deprecated options before we do anything else.
99 removeDeprecatedOptions(); 99 removeDeprecatedOptions();
100 100
101 var activeNotification = null; 101 var activeNotification = null;
102 102
103 // Adds or removes browser action icon according to options. 103 function getTabStatus(tab)
104 {
105 var icon;
106 var excluded = !/^https?:/.test(tab.url) || isWhitelisted(tab.url);
107
108 if (require("info").platform == "safari")
109 // pick an icon with approtiate size for Safari. However since
110 // toolbar item icons can't use different colors, we don't have
111 // different versions indicating whether adblocking is active.
112 icon = "icons/abp-16"
113 else
114 {
115 // pick an icon with the approtiate size for Chrome/Opera
116 // that indicates whether adblocking is active in the tab
117 if (excluded && iconAnimation.step < 10)
118 icon = "icons/abp-19-whitelisted";
119 else
120 icon = "icons/abp-19";
121 }
122
123 // pick the current frame if the icon is currently animating
124 // in order to indicate a pending notification
125 if (iconAnimation.step > 0)
126 {
127 icon += "-notification-"
128 icon += iconAnimation.severity;
129
130 if (iconAnimation.step < 10)
131 {
132 icon += "-"
133 icon += iconAnimation.step;
134 }
135 }
136
137 icon += ".png";
138
139 return {icon: icon, excluded: excluded};
140 }
141
104 function refreshIconAndContextMenu(tab) 142 function refreshIconAndContextMenu(tab)
105 { 143 {
106 var excluded = !/^https?:/.test(tab.url) || isWhitelisted(tab.url); 144 var status = getTabStatus(tab);
107 145
108 var iconFilename; 146 // update icon indicating whether adblocking is active in the tab.
109 if (require("info").platform == "safari") 147 // But don't interfere the icon animation if active. In that case
110 // There is no grayscale version of the icon for whitelisted tabs 148 // the icon animation takes care to update the icon to its new status
111 // when using Safari, because icons are grayscale already and icons 149 // with its next frame.
112 // aren't per tab in Safari. 150 if (!iconAnimation.tabs.has(tab))
113 iconFilename = "icons/abp-16.png" 151 tab.browserAction.setIcon(status.icon);
114 else
115 iconFilename = excluded ? "icons/abp-19-whitelisted.png" : "icons/abp-19.png ";
116 152
117 tab.browserAction.setIcon(iconFilename); 153 // show or hide the context menu entry dependent on whether adblocking
118 iconAnimation.registerTab(tab, iconFilename); 154 // is active in the tab
119 155 if (status.excluded)
120 // Set context menu status according to whether current tab has whitelisted do main
121 if (excluded)
122 ext.contextMenus.hideMenuItems(); 156 ext.contextMenus.hideMenuItems();
123 else 157 else
124 ext.contextMenus.showMenuItems(); 158 ext.contextMenus.showMenuItems();
125 } 159 }
126 160
127 /** 161 /**
128 * Old versions for Opera stored patterns.ini in the localStorage object, this 162 * Old versions for Opera stored patterns.ini in the localStorage object, this
129 * will import it into FilterStorage properly. 163 * will import it into FilterStorage properly.
130 * @return {Boolean} true if data import is in progress 164 * @return {Boolean} true if data import is in progress
131 */ 165 */
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 tab.sendMessage({type: "clickhide-deactivate"}); 453 tab.sendMessage({type: "clickhide-deactivate"});
420 refreshIconAndContextMenu(tab); 454 refreshIconAndContextMenu(tab);
421 }); 455 });
422 456
423 setTimeout(function() 457 setTimeout(function()
424 { 458 {
425 var notificationToShow = Notification.getNextToShow(); 459 var notificationToShow = Notification.getNextToShow();
426 if (notificationToShow) 460 if (notificationToShow)
427 showNotification(notificationToShow); 461 showNotification(notificationToShow);
428 }, 3 * 60 * 1000); 462 }, 3 * 60 * 1000);
OLDNEW
« no previous file with comments | « no previous file | iconAnimation.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld