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

Unified 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.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | iconAnimation.js » ('j') | iconAnimation.js » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: background.js
===================================================================
--- a/background.js
+++ b/background.js
@@ -100,25 +100,59 @@
var activeNotification = null;
-// Adds or removes browser action icon according to options.
-function refreshIconAndContextMenu(tab)
+function getTabStatus(tab, animation)
{
var whitelisted = isWhitelisted(tab.url);
- var iconFilename;
+ var icon;
if (require("info").platform == "safari")
- // There is no grayscale version of the icon for whitelisted tabs
- // when using Safari, because icons are grayscale already and icons
- // aren't per tab in Safari.
- iconFilename = "icons/abp-16.png"
+ // pick an icon with approtiate size for Safari. However since
+ // toolbar item icons can't use different colors, we don't have
+ // different versions indicating whether the page is whitelisted
+ icon = "icons/abp-16";
else
- iconFilename = whitelisted ? "icons/abp-19-whitelisted.png" : "icons/abp-19.png";
+ {
+ // pick an icon with the approtiate size for Chrome/Opera
+ // that indicates whether the page is whitelisted
+ 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
+ icon = "icons/abp-19-whitelisted";
+ else
+ icon = "icons/abp-19";
+ }
- tab.browserAction.setIcon(iconFilename);
- iconAnimation.registerTab(tab, iconFilename);
+ // pick the current frame if the icon is currently animating
+ // in order to indicate a pending notification
+ if (animation && animation.step > 0)
+ {
+ icon += "-notification-";
+ 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
- // Set context menu status according to whether current tab has whitelisted domain
- if (whitelisted || !/^https?:/.test(tab.url))
+ if (animation.step < 10)
+ {
+ icon += "-";
+ icon += animation.step;
+ }
+ }
+
+ icon += ".png";
+
+ return {icon: icon, whitelisted: whitelisted};
+}
+
+function refreshIconAndContextMenu(tab)
+{
+ var status = getTabStatus(tab);
+
+ // update icon indicating whether the page is whitelisted.
+ // 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
+ // In that case the icon animation takes care to update
+ // the icon to its new status with its next frame.
+ if (!iconAnimation.tabs.has(tab))
+ tab.browserAction.setIcon(status.icon);
+
+ // show or hide the context menu entry dependent on whether
+ // adblocking is active in the tab
+ if (status.whitelisted || !/^https?:/.test(tab.url))
ext.contextMenus.hideMenuItems();
else
ext.contextMenus.showMenuItems();
« no previous file with comments | « no previous file | iconAnimation.js » ('j') | iconAnimation.js » ('J')

Powered by Google App Engine
This is Rietveld