Left: | ||
Right: |
LEFT | RIGHT |
---|---|
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 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
46 }); | 46 }); |
47 image.addEventListener("error", () => | 47 image.addEventListener("error", () => |
48 { | 48 { |
49 reject("Failed to load image " + url); | 49 reject("Failed to load image " + url); |
50 }); | 50 }); |
51 }); | 51 }); |
52 } | 52 } |
53 | 53 |
54 function renderIcons() | 54 function renderIcons() |
55 { | 55 { |
56 Promise.all([ | 56 let paths = [ |
57 loadImage("icons/abp-16.png"), | 57 "icons/abp-16.png", "icons/abp-16-whitelisted.png", |
58 loadImage("icons/abp-16-whitelisted.png"), | 58 "icons/abp-32.png", "icons/abp-32-whitelisted.png" |
59 loadImage("icons/abp-19.png"), | 59 ]; |
60 loadImage("icons/abp-19-whitelisted.png"), | 60 |
61 loadImage("icons/abp-20.png"), | 61 for (let path of paths) |
62 loadImage("icons/abp-20-whitelisted.png"), | 62 { |
63 loadImage("icons/abp-32.png"), | 63 loadImage(path).then(image => |
64 loadImage("icons/abp-32-whitelisted.png"), | 64 { |
65 loadImage("icons/abp-38.png"), | 65 let [, size, whitelisted] = /\/abp-(16|32)(-whitelisted)?\./.exec(path); |
Manish Jethani
2019/02/03 09:47:55
Note: size is a string, not a number, but that's f
| |
66 loadImage("icons/abp-38-whitelisted.png"), | 66 |
67 loadImage("icons/abp-40.png"), | 67 let canvas = document.createElement("canvas"); |
68 loadImage("icons/abp-40-whitelisted.png"), | 68 let context = canvas.getContext("2d"); |
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 ]) | 69 let imageData = icons[!!whitelisted | 0] || {}; |
Sebastian Noack
2019/02/03 10:07:54
Nit: Isn't coercing to boolean (through !!) redund
Manish Jethani
2019/02/03 10:37:55
`"-whitelisted" | 0` is 0. Because "-whitelisted"
| |
70 .then(images => | 70 |
71 { | 71 canvas.width = size; |
72 let imageMap = { | 72 canvas.height = size; |
73 16: [images[0], images[1]], | 73 context.globalAlpha = 1; |
74 19: [images[2], images[3]], | 74 context.drawImage(image, 0, 0); |
75 20: [images[4], images[5]], | 75 imageData[size] = context.getImageData(0, 0, size, size); |
76 32: [images[6], images[7]], | 76 |
77 38: [images[8], images[9]], | 77 icons[!!whitelisted | 0] = imageData; |
78 40: [images[10], images[11]] | 78 }); |
79 }; | 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 } | 80 } |
102 | 81 |
103 function setIcon(page, notificationType, opacity, frames) | 82 function setIcon(page, notificationType, opacity, frames) |
104 { | 83 { |
105 opacity = opacity || 0; | 84 opacity = opacity || 0; |
106 let whitelisted = !!whitelistedState.get(page); | 85 let whitelisted = !!whitelistedState.get(page); |
107 | 86 |
108 if (!notificationType || !frames) | 87 if (!notificationType || !frames) |
109 { | 88 { |
110 if (opacity > 0.5) | 89 if (opacity > 0.5) |
111 { | 90 { |
112 page.browserAction.setIcon("/icons/abp-$size-notification-" + | 91 page.browserAction.setIconPath("/icons/abp-$size-notification-" + |
113 notificationType + ".png"); | 92 notificationType + ".png"); |
93 } | |
94 else if (icons[whitelisted | 0]) | |
95 { | |
96 page.browserAction.setIconImageData(icons[whitelisted | 0]); | |
114 } | 97 } |
115 else | 98 else |
116 { | 99 { |
117 page.browserAction.setIcon("/icons/abp-$size" + | 100 page.browserAction.setIconPath("/icons/abp-$size" + |
118 (whitelisted ? "-whitelisted" : "") + ".png", | 101 (whitelisted ? "-whitelisted" : "") + ".png "); |
119 icons[whitelisted | 0]); | |
120 } | 102 } |
121 } | 103 } |
122 else | 104 else |
123 { | 105 { |
124 browser.browserAction.setIcon({ | 106 browser.browserAction.setIconPath({ |
125 tabId: page.id, | 107 tabId: page.id, |
126 imageData: frames["" + opacity + whitelisted] | 108 imageData: frames["" + opacity + whitelisted] |
127 }); | 109 }); |
128 } | 110 } |
129 } | 111 } |
130 | 112 |
131 filterNotifier.on("page.WhitelistingStateRevalidate", (page, filter) => | 113 filterNotifier.on("page.WhitelistingStateRevalidate", (page, filter) => |
132 { | 114 { |
133 whitelistedState.set(page, !!filter); | 115 whitelistedState.set(page, !!filter); |
134 if (canUpdateIcon) | 116 if (canUpdateIcon) |
135 setIcon(page); | 117 setIcon(page); |
136 }); | 118 }); |
137 | 119 |
138 function renderFrames(notificationType) | 120 function renderFrames(notificationType) |
139 { | 121 { |
140 return Promise.all([ | 122 return Promise.all([ |
141 loadImage("icons/abp-16.png"), | 123 loadImage("icons/abp-16.png"), |
142 loadImage("icons/abp-16-whitelisted.png"), | 124 loadImage("icons/abp-16-whitelisted.png"), |
143 loadImage("icons/abp-16-notification-" + notificationType + ".png"), | 125 loadImage("icons/abp-16-notification-" + notificationType + ".png"), |
144 loadImage("icons/abp-19.png"), | |
145 loadImage("icons/abp-19-whitelisted.png"), | |
146 loadImage("icons/abp-19-notification-" + notificationType + ".png"), | |
147 loadImage("icons/abp-20.png"), | 126 loadImage("icons/abp-20.png"), |
148 loadImage("icons/abp-20-whitelisted.png"), | 127 loadImage("icons/abp-20-whitelisted.png"), |
149 loadImage("icons/abp-20-notification-" + notificationType + ".png"), | 128 loadImage("icons/abp-20-notification-" + notificationType + ".png"), |
150 loadImage("icons/abp-32.png"), | 129 loadImage("icons/abp-32.png"), |
151 loadImage("icons/abp-32-whitelisted.png"), | 130 loadImage("icons/abp-32-whitelisted.png"), |
152 loadImage("icons/abp-32-notification-" + notificationType + ".png"), | 131 loadImage("icons/abp-32-notification-" + notificationType + ".png"), |
153 loadImage("icons/abp-38.png"), | |
154 loadImage("icons/abp-38-whitelisted.png"), | |
155 loadImage("icons/abp-38-notification-" + notificationType + ".png"), | |
156 loadImage("icons/abp-40.png"), | 132 loadImage("icons/abp-40.png"), |
157 loadImage("icons/abp-40-whitelisted.png"), | 133 loadImage("icons/abp-40-whitelisted.png"), |
158 loadImage("icons/abp-40-notification-" + notificationType + ".png") | 134 loadImage("icons/abp-40-notification-" + notificationType + ".png") |
159 ]).then(images => | 135 ]).then(images => |
160 { | 136 { |
161 let imageMap = { | 137 let imageMap = { |
162 16: {base: [images[0], images[1]], overlay: images[2]}, | 138 16: {base: [images[0], images[1]], overlay: images[2]}, |
163 19: {base: [images[3], images[4]], overlay: images[5]}, | 139 20: {base: [images[3], images[4]], overlay: images[5]}, |
164 20: {base: [images[6], images[7]], overlay: images[8]}, | 140 32: {base: [images[6], images[7]], overlay: images[8]}, |
165 32: {base: [images[9], images[10]], overlay: images[11]}, | 141 40: {base: [images[9], images[10]], overlay: images[11]} |
166 38: {base: [images[12], images[13]], overlay: images[14]}, | |
167 40: {base: [images[15], images[16]], overlay: images[17]} | |
168 }; | 142 }; |
169 | 143 |
170 let frames = {}; | 144 let frames = {}; |
171 let canvas = document.createElement("canvas"); | 145 let canvas = document.createElement("canvas"); |
172 let context = canvas.getContext("2d"); | 146 let context = canvas.getContext("2d"); |
173 | 147 |
174 for (let whitelisted of [false, true]) | 148 for (let whitelisted of [false, true]) |
175 { | 149 { |
176 for (let i = 0, opacity = 0; i <= 10; opacity = ++i / 10) | 150 for (let i = 0, opacity = 0; i <= 10; opacity = ++i / 10) |
177 { | 151 { |
178 let imageData = {}; | 152 let imageData = {}; |
179 let sizes = [16, 19, 20, 32, 38, 40]; | 153 let sizes = [16, 20, 32, 40]; |
180 for (let size of sizes) | 154 for (let size of sizes) |
181 { | 155 { |
182 canvas.width = size; | 156 canvas.width = size; |
183 canvas.height = size; | 157 canvas.height = size; |
184 context.globalAlpha = 1; | 158 context.globalAlpha = 1; |
185 context.drawImage(imageMap[size]["base"][whitelisted | 0], 0, 0); | 159 context.drawImage(imageMap[size]["base"][whitelisted | 0], 0, 0); |
186 context.globalAlpha = opacity; | 160 context.globalAlpha = opacity; |
187 context.drawImage(imageMap[size]["overlay"], 0, 0); | 161 context.drawImage(imageMap[size]["overlay"], 0, 0); |
188 imageData[size] = context.getImageData(0, 0, size, size); | 162 imageData[size] = context.getImageData(0, 0, size, size); |
189 } | 163 } |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
287 | 261 |
288 animateIcon(type, frames); | 262 animateIcon(type, frames); |
289 }, 10000); | 263 }, 10000); |
290 }); | 264 }); |
291 }); | 265 }); |
292 }; | 266 }; |
293 | 267 |
294 // Pre-render icons on Chromium (#7253). | 268 // Pre-render icons on Chromium (#7253). |
295 if (info.platform == "chromium") | 269 if (info.platform == "chromium") |
296 renderIcons(); | 270 renderIcons(); |
LEFT | RIGHT |