1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-11-23 19:03:02 +01: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})';
let icons = [
{
tabId: 0,
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' }
}
];
@ -679,10 +677,14 @@ vAPI.setIcon = (function() {
// https://searchfox.org/mozilla-central/rev/5ff2d7683078c96e4b11b8a13674daded935aa44/browser/components/extensions/parent/ext-browserAction.js#631
if ( vAPI.webextFlavor.soup.has('chromium') === false ) { return; }
let imgs = [
{ i: 0, p: '16' }, { i: 0, p: '32' },
{ i: 1, p: '16' }, { i: 1, p: '32' },
];
let imgs = [];
for ( let i = 0; i < icons.length; i++ ) {
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() {
for ( let img of imgs ) {
if ( img.r.complete === false ) { return; }
@ -708,8 +710,11 @@ vAPI.setIcon = (function() {
}
iconData[img.i][img.p] = imgData;
}
icons[0] = { tabId: 0, imageData: iconData[0] };
icons[1] = { tabId: 0, imageData: iconData[1] };
for ( let i = 0; i < iconData.length; i++ ) {
if ( iconData[i] ) {
icons[i] = { imageData: iconData[i] };
}
}
};
for ( let img of imgs ) {
img.r = new Image();
@ -723,8 +728,9 @@ vAPI.setIcon = (function() {
if ( browserAction.setIcon !== undefined ) {
if ( parts === undefined || (parts & 0x01) !== 0 ) {
icons[state].tabId = tab.id;
browserAction.setIcon(icons[state]);
browserAction.setIcon(
Object.assign({ tabId: tab.id }, icons[state])
);
}
browserAction.setBadgeText({ tabId: tab.id, text: badge });
}