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, 7:25 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') | iconAnimation.js » ('J')
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, animation)
104 function refreshIconAndContextMenu(tab)
105 { 104 {
106 var whitelisted = isWhitelisted(tab.url); 105 var whitelisted = isWhitelisted(tab.url);
107 106
108 var iconFilename; 107 var icon;
109 if (require("info").platform == "safari") 108 if (require("info").platform == "safari")
110 // There is no grayscale version of the icon for whitelisted tabs 109 // pick an icon with approtiate size for Safari. However since
111 // when using Safari, because icons are grayscale already and icons 110 // toolbar item icons can't use different colors, we don't have
112 // aren't per tab in Safari. 111 // different versions indicating whether the page is whitelisted
113 iconFilename = "icons/abp-16.png" 112 icon = "icons/abp-16";
114 else 113 else
115 iconFilename = whitelisted ? "icons/abp-19-whitelisted.png" : "icons/abp-19. png"; 114 {
115 // pick an icon with the approtiate size for Chrome/Opera
116 // that indicates whether the page is whitelisted
117 if (whitelisted && (!animation || animation.step < 10))
Felix Dahlke 2014/02/27 22:02:05 So we will use the red ABP icon if the animation s
Sebastian Noack 2014/02/28 08:35:16 We are neither going to use the red default nor th
118 icon = "icons/abp-19-whitelisted";
119 else
120 icon = "icons/abp-19";
121 }
116 122
117 tab.browserAction.setIcon(iconFilename); 123 // pick the current frame if the icon is currently animating
118 iconAnimation.registerTab(tab, iconFilename); 124 // in order to indicate a pending notification
125 if (animation && animation.step > 0)
126 {
127 icon += "-notification-";
128 icon += animation.severity;
Wladimir Palant 2014/03/06 14:31:35 Nit: why split this to two statements? This seems
Sebastian Noack 2014/03/06 20:41:13 I found it slightly more readable to have one oper
119 129
120 // Set context menu status according to whether current tab has whitelisted do main 130 if (animation.step < 10)
121 if (whitelisted || !/^https?:/.test(tab.url)) 131 {
132 icon += "-";
133 icon += animation.step;
134 }
135 }
136
137 icon += ".png";
138
139 return {icon: icon, whitelisted: whitelisted};
140 }
141
142 function refreshIconAndContextMenu(tab)
143 {
144 var status = getTabStatus(tab);
145
146 // update icon indicating whether the page is whitelisted.
147 // But don't interfere the icon animation if active.
Felix Dahlke 2014/02/27 22:02:05 s/interfere/interrupt/?
Sebastian Noack 2014/02/28 08:35:16 Don't know. It wouldn't just pause the animation,
Wladimir Palant 2014/03/06 14:31:35 If we now have a generic function to calculate the
Wladimir Palant 2014/03/06 14:34:33 In fact, this isn't even necessary. If iconAnimati
Sebastian Noack 2014/03/06 20:41:13 Done. On 2014/03/06 14:34:33, Wladimir Palant wro
Wladimir Palant 2014/03/06 20:49:44 Isn't that exactly the issue that registerTab() wa
Sebastian Noack 2014/03/07 17:26:11 Now it is addressed within getTabStatus() as you s
Wladimir Palant 2014/03/07 22:13:29 Still missing something that would start the anima
Sebastian Noack 2014/03/08 11:36:39 Considering that the animation is interrupted anyw
Wladimir Palant 2014/03/21 14:10:11 Why interrupted? The animation step doesn't change
Sebastian Noack 2014/03/31 13:20:32 Since the icon is set per tab, when the active tab
148 // In that case the icon animation takes care to update
149 // the icon to its new status with its next frame.
150 if (!iconAnimation.tabs.has(tab))
151 tab.browserAction.setIcon(status.icon);
152
153 // show or hide the context menu entry dependent on whether
154 // adblocking is active in the tab
155 if (status.whitelisted || !/^https?:/.test(tab.url))
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') | iconAnimation.js » ('J')

Powered by Google App Engine
This is Rietveld