1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-10-04 08:37:11 +02:00

improve use of imageData in setIcon

- Generate imageData according to existing path information
- Pass a copy as argument (see 06768dcadb)
This commit is contained in:
Raymond Hill 2018-05-27 11:13:25 -04:00
parent c6cab02999
commit 06756baed9
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

View File

@ -649,11 +649,9 @@ vAPI.setIcon = (function() {
' ({badge})'; ' ({badge})';
let icons = [ let icons = [
{ {
tabId: 0,
path: { '16': 'img/icon_16-off.png', '32': 'img/icon_32-off.png' } path: { '16': 'img/icon_16-off.png', '32': 'img/icon_32-off.png' }
}, },
{ {
tabId: 0,
path: { '16': 'img/icon_16.png', '32': 'img/icon_32.png' } path: { '16': 'img/icon_16.png', '32': 'img/icon_32.png' }
} }
]; ];
@ -679,10 +677,14 @@ vAPI.setIcon = (function() {
// https://searchfox.org/mozilla-central/rev/5ff2d7683078c96e4b11b8a13674daded935aa44/browser/components/extensions/parent/ext-browserAction.js#631 // https://searchfox.org/mozilla-central/rev/5ff2d7683078c96e4b11b8a13674daded935aa44/browser/components/extensions/parent/ext-browserAction.js#631
if ( vAPI.webextFlavor.soup.has('chromium') === false ) { return; } if ( vAPI.webextFlavor.soup.has('chromium') === false ) { return; }
let imgs = [ let imgs = [];
{ i: 0, p: '16' }, { i: 0, p: '32' }, for ( let i = 0; i < icons.length; i++ ) {
{ i: 1, p: '16' }, { i: 1, p: '32' }, let path = icons[i].path;
]; for ( let key in path ) {
if ( path.hasOwnProperty(key) === false ) { continue; }
imgs.push({ i: i, p: key });
}
}
let onLoaded = function() { let onLoaded = function() {
for ( let img of imgs ) { for ( let img of imgs ) {
if ( img.r.complete === false ) { return; } if ( img.r.complete === false ) { return; }
@ -708,8 +710,11 @@ vAPI.setIcon = (function() {
} }
iconData[img.i][img.p] = imgData; iconData[img.i][img.p] = imgData;
} }
icons[0] = { tabId: 0, imageData: iconData[0] }; for ( let i = 0; i < iconData.length; i++ ) {
icons[1] = { tabId: 0, imageData: iconData[1] }; if ( iconData[i] ) {
icons[i] = { imageData: iconData[i] };
}
}
}; };
for ( let img of imgs ) { for ( let img of imgs ) {
img.r = new Image(); img.r = new Image();
@ -723,8 +728,9 @@ vAPI.setIcon = (function() {
if ( browserAction.setIcon !== undefined ) { if ( browserAction.setIcon !== undefined ) {
if ( parts === undefined || (parts & 0x01) !== 0 ) { if ( parts === undefined || (parts & 0x01) !== 0 ) {
icons[state].tabId = tab.id; browserAction.setIcon(
browserAction.setIcon(icons[state]); Object.assign({ tabId: tab.id }, icons[state])
);
} }
browserAction.setBadgeText({ tabId: tab.id, text: badge }); browserAction.setBadgeText({ tabId: tab.id, text: badge });
} }