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"); | 22 let {FilterNotifier} = require("filterNotifier"); |
23 | 23 |
24 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, |
25 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, |
26 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]; |
27 const numberOfFrames = frameOpacities.length; | 27 const numberOfFrames = frameOpacities.length; |
28 const safariPlatform = require("info").platform == "safari"; | |
29 | 28 |
30 let stopRequested = false; | 29 let stopRequested = false; |
31 let canUpdateIcon = true; | 30 let canUpdateIcon = true; |
32 let notRunning = Promise.resolve(); | 31 let notRunning = Promise.resolve(); |
33 let whitelistedState = new ext.PageMap(); | 32 let whitelistedState = new ext.PageMap(); |
34 | 33 |
35 function loadImage(url) | 34 function loadImage(url) |
36 { | 35 { |
37 return new Promise((resolve, reject) => | 36 return new Promise((resolve, reject) => |
38 { | 37 { |
39 let image = new Image(); | 38 let image = new Image(); |
40 image.src = url; | 39 image.src = url; |
41 image.addEventListener("load", () => | 40 image.addEventListener("load", () => |
42 { | 41 { |
43 resolve(image); | 42 resolve(image); |
44 }); | 43 }); |
45 image.addEventListener("error", () => | 44 image.addEventListener("error", () => |
46 { | 45 { |
47 reject("Failed to load image " + url); | 46 reject("Failed to load image " + url); |
48 }); | 47 }); |
49 }); | 48 }); |
50 }; | 49 }; |
51 | 50 |
52 function setIcon(page, notificationType, opacity, frames) | 51 function setIcon(page, notificationType, opacity, frames) |
53 { | 52 { |
54 opacity = opacity || 0; | 53 opacity = opacity || 0; |
55 let whitelisted = !!whitelistedState.get(page) && !safariPlatform; | 54 let whitelisted = !!whitelistedState.get(page); |
56 | 55 |
57 if (!notificationType || !frames) | 56 if (!notificationType || !frames) |
58 { | 57 { |
59 if (opacity > 0.5) | 58 if (opacity > 0.5) |
60 page.browserAction.setIcon("icons/abp-$size-notification-" | 59 page.browserAction.setIcon("icons/abp-$size-notification-" |
61 + notificationType + ".png"); | 60 + notificationType + ".png"); |
62 else | 61 else |
63 page.browserAction.setIcon("icons/abp-$size" + | 62 page.browserAction.setIcon("icons/abp-$size" + |
64 (whitelisted ? "-whitelisted" : "") + ".png"); | 63 (whitelisted ? "-whitelisted" : "") + ".png"); |
65 } | 64 } |
66 else | 65 else |
67 { | 66 { |
68 page.browserAction._safeSetIcon({ | 67 page.browserAction._safeSetIcon({ |
69 tabId: page.id, | 68 tabId: page.id, |
70 imageData: frames["" + opacity + whitelisted] | 69 imageData: frames["" + opacity + whitelisted] |
71 }); | 70 }); |
72 } | 71 } |
73 } | 72 } |
74 | 73 |
75 FilterNotifier.on("page.WhitelistingStateRevalidate", (page, filter) => | 74 FilterNotifier.on("page.WhitelistingStateRevalidate", (page, filter) => |
76 { | 75 { |
77 whitelistedState.set(page, !!filter); | 76 whitelistedState.set(page, !!filter); |
78 if (canUpdateIcon) | 77 if (canUpdateIcon) |
79 setIcon(page); | 78 setIcon(page); |
80 }); | 79 }); |
81 | 80 |
82 function renderFrames(notificationType) | 81 function renderFrames(notificationType) |
83 { | 82 { |
84 if (safariPlatform) | |
85 return Promise.resolve(null); | |
86 | |
87 return Promise.all([ | 83 return Promise.all([ |
88 loadImage("icons/abp-16.png"), | 84 loadImage("icons/abp-16.png"), |
89 loadImage("icons/abp-16-whitelisted.png"), | 85 loadImage("icons/abp-16-whitelisted.png"), |
90 loadImage("icons/abp-16-notification-" + notificationType + ".png"), | 86 loadImage("icons/abp-16-notification-" + notificationType + ".png"), |
91 loadImage("icons/abp-19.png"), | 87 loadImage("icons/abp-19.png"), |
92 loadImage("icons/abp-19-whitelisted.png"), | 88 loadImage("icons/abp-19-whitelisted.png"), |
93 loadImage("icons/abp-19-notification-" + notificationType + ".png"), | 89 loadImage("icons/abp-19-notification-" + notificationType + ".png"), |
94 loadImage("icons/abp-20.png"), | 90 loadImage("icons/abp-20.png"), |
95 loadImage("icons/abp-20-whitelisted.png"), | 91 loadImage("icons/abp-20-whitelisted.png"), |
96 loadImage("icons/abp-20-notification-" + notificationType + ".png"), | 92 loadImage("icons/abp-20-notification-" + notificationType + ".png"), |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 clearInterval(interval); | 223 clearInterval(interval); |
228 resolve(); | 224 resolve(); |
229 return; | 225 return; |
230 } | 226 } |
231 | 227 |
232 animateIcon(type, frames); | 228 animateIcon(type, frames); |
233 }, 10000); | 229 }, 10000); |
234 }); | 230 }); |
235 }); | 231 }); |
236 }; | 232 }; |
OLD | NEW |