OLD | NEW |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 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 |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
16 */ | 16 */ |
17 | 17 |
18 /** @module icon */ | 18 /** @module icon */ |
19 | 19 |
20 "use strict"; | 20 "use strict"; |
21 | 21 |
| 22 let {FilterNotifier} = require("filterNotifier"); |
| 23 |
22 const frameOpacities = [0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, | 24 const frameOpacities = [0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, |
23 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, | 25 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, |
24 0.9, 0.8, 0.7, 0.6, 0.5, 0.4, 0.3, 0.2, 0.1, 0.0]; | 26 0.9, 0.8, 0.7, 0.6, 0.5, 0.4, 0.3, 0.2, 0.1, 0.0]; |
25 const numberOfFrames = frameOpacities.length; | 27 const numberOfFrames = frameOpacities.length; |
26 const safariPlatform = require("info").platform == "safari"; | 28 const safariPlatform = require("info").platform == "safari"; |
27 | 29 |
28 let stopRequested = false; | 30 let stopRequested = false; |
29 let canUpdateIcon = true; | 31 let canUpdateIcon = true; |
30 let notRunning = Promise.resolve(); | 32 let notRunning = Promise.resolve(); |
31 let whitelistedState = new ext.PageMap(); | 33 let whitelistedState = new ext.PageMap(); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 } | 65 } |
64 else | 66 else |
65 { | 67 { |
66 chrome.browserAction.setIcon({ | 68 chrome.browserAction.setIcon({ |
67 tabId: page.id, | 69 tabId: page.id, |
68 imageData: frames["" + opacity + whitelisted] | 70 imageData: frames["" + opacity + whitelisted] |
69 }); | 71 }); |
70 } | 72 } |
71 } | 73 } |
72 | 74 |
| 75 FilterNotifier.addListener((action, page, filter) => |
| 76 { |
| 77 if (action == "page.WhitelistingStateRevalidate") |
| 78 { |
| 79 whitelistedState.set(page, !!filter); |
| 80 if (canUpdateIcon) |
| 81 setIcon(page); |
| 82 } |
| 83 }); |
| 84 |
73 function renderFrames(notificationType) | 85 function renderFrames(notificationType) |
74 { | 86 { |
75 if (safariPlatform) | 87 if (safariPlatform) |
76 return Promise.resolve(null); | 88 return Promise.resolve(null); |
77 | 89 |
78 return Promise.all([ | 90 return Promise.all([ |
79 loadImage("icons/abp-19.png"), | 91 loadImage("icons/abp-19.png"), |
80 loadImage("icons/abp-19-whitelisted.png"), | 92 loadImage("icons/abp-19-whitelisted.png"), |
81 loadImage("icons/abp-19-notification-" + notificationType + ".png"), | 93 loadImage("icons/abp-19-notification-" + notificationType + ".png"), |
82 loadImage("icons/abp-38.png"), | 94 loadImage("icons/abp-38.png"), |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 if (animationStep > numberOfFrames) | 160 if (animationStep > numberOfFrames) |
149 { | 161 { |
150 clearInterval(interval); | 162 clearInterval(interval); |
151 ext.pages.onActivated.removeListener(onActivated); | 163 ext.pages.onActivated.removeListener(onActivated); |
152 canUpdateIcon = true; | 164 canUpdateIcon = true; |
153 } | 165 } |
154 }, 100); | 166 }, 100); |
155 }); | 167 }); |
156 } | 168 } |
157 | 169 |
158 /** | |
159 * Set the browser action icon for the given page, indicating whether | |
160 * adblocking is active there, and considering the icon animation. | |
161 * | |
162 * @param {Page} page The page to set the browser action icon for | |
163 * @param {Boolean} whitelisted Whether the page has been whitelisted | |
164 */ | |
165 exports.updateIcon = function(page, whitelisted) | |
166 { | |
167 whitelistedState.set(page, whitelisted); | |
168 if (canUpdateIcon) | |
169 setIcon(page); | |
170 }; | |
171 | |
172 let stopIconAnimation = | 170 let stopIconAnimation = |
173 /** | 171 /** |
174 * Stops to animate the browser action icon | 172 * Stops to animate the browser action icon |
175 * after the current interval has been finished. | 173 * after the current interval has been finished. |
176 * | 174 * |
177 * @return {Promise} A promise that is fullfilled when | 175 * @return {Promise} A promise that is fullfilled when |
178 * the icon animation has been stopped. | 176 * the icon animation has been stopped. |
179 */ | 177 */ |
180 exports.stopIconAnimation = function() | 178 exports.stopIconAnimation = function() |
181 { | 179 { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 clearInterval(interval); | 213 clearInterval(interval); |
216 resolve(); | 214 resolve(); |
217 return; | 215 return; |
218 } | 216 } |
219 | 217 |
220 animateIcon(type, frames); | 218 animateIcon(type, frames); |
221 }, 10000); | 219 }, 10000); |
222 }); | 220 }); |
223 }); | 221 }); |
224 }; | 222 }; |
OLD | NEW |