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

Side by Side Diff: lib/icon.js

Issue 29374674: Issue 4864 - Start using ESLint for adblockpluschrome (Closed)
Patch Set: Update adblockplusui dependency to include the notification fix Created March 19, 2017, 6:48 a.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 | « lib/filterValidation.js ('k') | lib/io.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 <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 const {FilterNotifier} = require("filterNotifier"); 22 const {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 28
29 let stopRequested = false; 29 let stopRequested = false;
30 let canUpdateIcon = true; 30 let canUpdateIcon = true;
31 let notRunning = Promise.resolve(); 31 let notRunning = Promise.resolve();
32 let whitelistedState = new ext.PageMap(); 32 let whitelistedState = new ext.PageMap();
33 33
34 function loadImage(url) 34 function loadImage(url)
35 { 35 {
36 return new Promise((resolve, reject) => 36 return new Promise((resolve, reject) =>
37 { 37 {
38 let image = new Image(); 38 let image = new Image();
39 image.src = url; 39 image.src = url;
40 image.addEventListener("load", () => 40 image.addEventListener("load", () =>
41 { 41 {
42 resolve(image); 42 resolve(image);
43 }); 43 });
44 image.addEventListener("error", () => 44 image.addEventListener("error", () =>
45 { 45 {
46 reject("Failed to load image " + url); 46 reject("Failed to load image " + url);
47 }); 47 });
48 }); 48 });
49 }; 49 }
50 50
51 function setIcon(page, notificationType, opacity, frames) 51 function setIcon(page, notificationType, opacity, frames)
52 { 52 {
53 opacity = opacity || 0; 53 opacity = opacity || 0;
54 let whitelisted = !!whitelistedState.get(page); 54 let whitelisted = !!whitelistedState.get(page);
55 55
56 if (!notificationType || !frames) 56 if (!notificationType || !frames)
57 { 57 {
58 if (opacity > 0.5) 58 if (opacity > 0.5)
59 page.browserAction.setIcon("icons/abp-$size-notification-" 59 {
60 + notificationType + ".png"); 60 page.browserAction.setIcon("icons/abp-$size-notification-" +
61 notificationType + ".png");
62 }
61 else 63 else
64 {
62 page.browserAction.setIcon("icons/abp-$size" + 65 page.browserAction.setIcon("icons/abp-$size" +
63 (whitelisted ? "-whitelisted" : "") + ".png"); 66 (whitelisted ? "-whitelisted" : "") + ".png");
67 }
64 } 68 }
65 else 69 else
66 { 70 {
67 chrome.browserAction.setIcon({ 71 chrome.browserAction.setIcon({
68 tabId: page.id, 72 tabId: page.id,
69 imageData: frames["" + opacity + whitelisted] 73 imageData: frames["" + opacity + whitelisted]
70 }); 74 });
71 } 75 }
72 } 76 }
73 77
(...skipping 21 matching lines...) Expand all
95 loadImage("icons/abp-32-notification-" + notificationType + ".png"), 99 loadImage("icons/abp-32-notification-" + notificationType + ".png"),
96 loadImage("icons/abp-38.png"), 100 loadImage("icons/abp-38.png"),
97 loadImage("icons/abp-38-whitelisted.png"), 101 loadImage("icons/abp-38-whitelisted.png"),
98 loadImage("icons/abp-38-notification-" + notificationType + ".png"), 102 loadImage("icons/abp-38-notification-" + notificationType + ".png"),
99 loadImage("icons/abp-40.png"), 103 loadImage("icons/abp-40.png"),
100 loadImage("icons/abp-40-whitelisted.png"), 104 loadImage("icons/abp-40-whitelisted.png"),
101 loadImage("icons/abp-40-notification-" + notificationType + ".png") 105 loadImage("icons/abp-40-notification-" + notificationType + ".png")
102 ]).then(images => 106 ]).then(images =>
103 { 107 {
104 let imageMap = { 108 let imageMap = {
105 16: { base: [images[0], images[1]], overlay: images[2] }, 109 16: {base: [images[0], images[1]], overlay: images[2]},
106 19: { base: [images[3], images[4]], overlay: images[5] }, 110 19: {base: [images[3], images[4]], overlay: images[5]},
107 20: { base: [images[6], images[7]], overlay: images[8] }, 111 20: {base: [images[6], images[7]], overlay: images[8]},
108 32: { base: [images[9], images[10]], overlay: images[11] }, 112 32: {base: [images[9], images[10]], overlay: images[11]},
109 38: { base: [images[12], images[13]], overlay: images[14] }, 113 38: {base: [images[12], images[13]], overlay: images[14]},
110 40: { base: [images[15], images[16]], overlay: images[17] } 114 40: {base: [images[15], images[16]], overlay: images[17]}
111 }; 115 };
112 116
113 let frames = {}; 117 let frames = {};
114 let canvas = document.createElement("canvas"); 118 let canvas = document.createElement("canvas");
115 let context = canvas.getContext("2d"); 119 let context = canvas.getContext("2d");
116 120
117 for (let whitelisted of [false, true]) 121 for (let whitelisted of [false, true])
118 { 122 {
119 for (let i = 0, opacity = 0; i <= 10; opacity = ++i / 10) 123 for (let i = 0, opacity = 0; i <= 10; opacity = ++i / 10)
120 { 124 {
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 { 196 {
193 stopRequested = false; 197 stopRequested = false;
194 }); 198 });
195 }; 199 };
196 200
197 /** 201 /**
198 * Starts to animate the browser action icon to indicate a pending notifcation. 202 * Starts to animate the browser action icon to indicate a pending notifcation.
199 * If the icon is already animated, it replaces the previous 203 * If the icon is already animated, it replaces the previous
200 * animation as soon as the current interval has been finished. 204 * animation as soon as the current interval has been finished.
201 * 205 *
202 * @param {string} type The notification type (i.e: "information" or "critical" ) 206 * @param {string} type The notification type (i.e: "information" or
207 * "critical".)
203 */ 208 */
204 exports.startIconAnimation = type => 209 exports.startIconAnimation = type =>
205 { 210 {
206 notRunning = new Promise(resolve => 211 notRunning = new Promise(resolve =>
207 { 212 {
208 Promise.all([renderFrames(type), stopIconAnimation()]).then(results => 213 Promise.all([renderFrames(type), stopIconAnimation()]).then(results =>
209 { 214 {
210 if (stopRequested) 215 if (stopRequested)
211 { 216 {
212 resolve(); 217 resolve();
(...skipping 10 matching lines...) Expand all
223 clearInterval(interval); 228 clearInterval(interval);
224 resolve(); 229 resolve();
225 return; 230 return;
226 } 231 }
227 232
228 animateIcon(type, frames); 233 animateIcon(type, frames);
229 }, 10000); 234 }, 10000);
230 }); 235 });
231 }); 236 });
232 }; 237 };
OLDNEW
« no previous file with comments | « lib/filterValidation.js ('k') | lib/io.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld