| Left: | ||
| Right: |
| 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-present eyeo GmbH | 3 * Copyright (C) 2006-present 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("../adblockpluscore/lib/filterNotifier"); | 22 const {filterNotifier} = require("../adblockpluscore/lib/filterNotifier"); |
| 23 const info = require("info"); | |
| 23 | 24 |
| 24 const frameOpacities = [0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, | 25 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, | 26 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]; | 27 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; | 28 const numberOfFrames = frameOpacities.length; |
| 28 | 29 |
| 29 let stopRequested = false; | 30 let stopRequested = false; |
| 30 let canUpdateIcon = true; | 31 let canUpdateIcon = true; |
| 31 let notRunning = Promise.resolve(); | 32 let notRunning = Promise.resolve(); |
| 32 let whitelistedState = new ext.PageMap(); | 33 let whitelistedState = new ext.PageMap(); |
| 33 | 34 |
| 35 let icons = [null, null]; | |
| 36 | |
| 34 function loadImage(url) | 37 function loadImage(url) |
| 35 { | 38 { |
| 36 return new Promise((resolve, reject) => | 39 return new Promise((resolve, reject) => |
| 37 { | 40 { |
| 38 let image = new Image(); | 41 let image = new Image(); |
| 39 image.src = url; | 42 image.src = url; |
| 40 image.addEventListener("load", () => | 43 image.addEventListener("load", () => |
| 41 { | 44 { |
| 42 resolve(image); | 45 resolve(image); |
| 43 }); | 46 }); |
| 44 image.addEventListener("error", () => | 47 image.addEventListener("error", () => |
| 45 { | 48 { |
| 46 reject("Failed to load image " + url); | 49 reject("Failed to load image " + url); |
| 47 }); | 50 }); |
| 48 }); | 51 }); |
| 49 } | 52 } |
| 50 | 53 |
| 54 function renderIcons() | |
| 55 { | |
| 56 Promise.all([ | |
| 57 loadImage("icons/abp-16.png"), | |
| 58 loadImage("icons/abp-16-whitelisted.png"), | |
| 59 loadImage("icons/abp-19.png"), | |
| 60 loadImage("icons/abp-19-whitelisted.png"), | |
| 61 loadImage("icons/abp-20.png"), | |
| 62 loadImage("icons/abp-20-whitelisted.png"), | |
| 63 loadImage("icons/abp-32.png"), | |
| 64 loadImage("icons/abp-32-whitelisted.png"), | |
| 65 loadImage("icons/abp-38.png"), | |
| 66 loadImage("icons/abp-38-whitelisted.png"), | |
| 67 loadImage("icons/abp-40.png"), | |
| 68 loadImage("icons/abp-40-whitelisted.png"), | |
|
Sebastian Noack
2019/02/03 06:43:18
The icons in the sizes 20 and 40 are only used on
Manish Jethani
2019/02/03 07:26:49
Done.
Sebastian Noack
2019/02/03 07:45:15
I'm certain that it will work on Chrome 49. But Ch
Manish Jethani
2019/02/03 08:00:02
Alright, let's test have QA test it out on Chrome
| |
| 69 ]) | |
| 70 .then(images => | |
| 71 { | |
| 72 let imageMap = { | |
| 73 16: [images[0], images[1]], | |
| 74 19: [images[2], images[3]], | |
| 75 20: [images[4], images[5]], | |
| 76 32: [images[6], images[7]], | |
| 77 38: [images[8], images[9]], | |
| 78 40: [images[10], images[11]] | |
| 79 }; | |
| 80 | |
| 81 let canvas = document.createElement("canvas"); | |
| 82 let context = canvas.getContext("2d"); | |
| 83 | |
| 84 for (let whitelisted of [false, true]) | |
| 85 { | |
| 86 let imageData = {}; | |
| 87 let sizes = [16, 19, 20, 32, 38, 40]; | |
| 88 | |
| 89 for (let size of sizes) | |
| 90 { | |
| 91 canvas.width = size; | |
| 92 canvas.height = size; | |
| 93 context.globalAlpha = 1; | |
| 94 context.drawImage(imageMap[size][whitelisted | 0], 0, 0); | |
| 95 imageData[size] = context.getImageData(0, 0, size, size); | |
| 96 } | |
| 97 | |
| 98 icons[whitelisted | 0] = imageData; | |
| 99 } | |
| 100 }); | |
| 101 } | |
| 102 | |
| 51 function setIcon(page, notificationType, opacity, frames) | 103 function setIcon(page, notificationType, opacity, frames) |
| 52 { | 104 { |
| 53 opacity = opacity || 0; | 105 opacity = opacity || 0; |
| 54 let whitelisted = !!whitelistedState.get(page); | 106 let whitelisted = !!whitelistedState.get(page); |
| 55 | 107 |
| 56 if (!notificationType || !frames) | 108 if (!notificationType || !frames) |
| 57 { | 109 { |
| 58 if (opacity > 0.5) | 110 if (opacity > 0.5) |
| 59 { | 111 { |
| 60 page.browserAction.setIcon("/icons/abp-$size-notification-" + | 112 page.browserAction.setIcon("/icons/abp-$size-notification-" + |
| 61 notificationType + ".png"); | 113 notificationType + ".png"); |
| 62 } | 114 } |
| 63 else | 115 else |
| 64 { | 116 { |
| 65 page.browserAction.setIcon("/icons/abp-$size" + | 117 page.browserAction.setIcon("/icons/abp-$size" + |
| 66 (whitelisted ? "-whitelisted" : "") + ".png"); | 118 (whitelisted ? "-whitelisted" : "") + ".png", |
| 119 icons[whitelisted | 0]); | |
| 67 } | 120 } |
| 68 } | 121 } |
| 69 else | 122 else |
| 70 { | 123 { |
| 71 browser.browserAction.setIcon({ | 124 browser.browserAction.setIcon({ |
| 72 tabId: page.id, | 125 tabId: page.id, |
| 73 imageData: frames["" + opacity + whitelisted] | 126 imageData: frames["" + opacity + whitelisted] |
| 74 }); | 127 }); |
| 75 } | 128 } |
| 76 } | 129 } |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 230 clearInterval(interval); | 283 clearInterval(interval); |
| 231 resolve(); | 284 resolve(); |
| 232 return; | 285 return; |
| 233 } | 286 } |
| 234 | 287 |
| 235 animateIcon(type, frames); | 288 animateIcon(type, frames); |
| 236 }, 10000); | 289 }, 10000); |
| 237 }); | 290 }); |
| 238 }); | 291 }); |
| 239 }; | 292 }; |
| 293 | |
| 294 // Pre-render icons on Chromium (#7253). | |
| 295 if (info.platform == "chromium") | |
| 296 renderIcons(); | |
| OLD | NEW |