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

Side by Side Diff: ext/background.js

Issue 29995555: Issue 7253 - Pre-render icons for badge on Chromium (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Patch Set: Update for loop Created Feb. 3, 2019, 7:31 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 | « no previous file | lib/icon.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-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 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 }; 320 };
321 BrowserAction.prototype = { 321 BrowserAction.prototype = {
322 _applyChanges() 322 _applyChanges()
323 { 323 {
324 return Promise.all(Object.keys(this._changes).map(change => 324 return Promise.all(Object.keys(this._changes).map(change =>
325 { 325 {
326 // Firefox for Android displays the browser action not as an icon but 326 // Firefox for Android displays the browser action not as an icon but
327 // as a menu item. There is no icon, but such an option may be added 327 // as a menu item. There is no icon, but such an option may be added
328 // in the future. 328 // in the future.
329 // https://bugzilla.mozilla.org/show_bug.cgi?id=1331746 329 // https://bugzilla.mozilla.org/show_bug.cgi?id=1331746
330 if (change == "iconPath" && "setIcon" in browser.browserAction) 330 if (change == "icon" && "setIcon" in browser.browserAction)
331 { 331 {
332 // Use ImageData if available.
333 if (this._changes.icon.imageData)
334 {
335 return browser.browserAction.setIcon({
336 tabId: this._tabId,
337 imageData: this._changes.icon.imageData
338 });
339 }
340
332 let path = { 341 let path = {
333 16: this._changes.iconPath.replace("$size", "16"), 342 16: this._changes.icon.path.replace("$size", "16"),
334 19: this._changes.iconPath.replace("$size", "19"), 343 19: this._changes.icon.path.replace("$size", "19"),
335 20: this._changes.iconPath.replace("$size", "20"), 344 20: this._changes.icon.path.replace("$size", "20"),
336 32: this._changes.iconPath.replace("$size", "32"), 345 32: this._changes.icon.path.replace("$size", "32"),
337 38: this._changes.iconPath.replace("$size", "38"), 346 38: this._changes.icon.path.replace("$size", "38"),
338 40: this._changes.iconPath.replace("$size", "40") 347 40: this._changes.icon.path.replace("$size", "40")
339 }; 348 };
340 try 349 try
341 { 350 {
342 return browser.browserAction.setIcon({tabId: this._tabId, path}); 351 return browser.browserAction.setIcon({tabId: this._tabId, path});
343 } 352 }
344 catch (e) 353 catch (e)
345 { 354 {
346 // Edge throws if passed icon sizes different than 19,20,38,40px. 355 // Edge throws if passed icon sizes different than 19,20,38,40px.
347 delete path[16]; 356 delete path[16];
348 delete path[32]; 357 delete path[32];
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 this._changes = null; 401 this._changes = null;
393 }).catch(() => 402 }).catch(() =>
394 { 403 {
395 // If the tab is prerendered, browser.browserAction.set* fails 404 // If the tab is prerendered, browser.browserAction.set* fails
396 // and we have to delay our changes until the currently visible tab 405 // and we have to delay our changes until the currently visible tab
397 // is replaced with the prerendered tab. 406 // is replaced with the prerendered tab.
398 browser.tabs.onReplaced.addListener(onReplaced); 407 browser.tabs.onReplaced.addListener(onReplaced);
399 }); 408 });
400 } 409 }
401 }, 410 },
402 setIcon(path) 411 setIcon(path, imageData = null)
403 { 412 {
404 this._addChange("iconPath", path); 413 this._addChange("icon", {path, imageData});
Sebastian Noack 2019/02/03 07:45:15 How about using _addChange("iconPath") and _addCha
405 }, 414 },
406 setBadge(badge) 415 setBadge(badge)
407 { 416 {
408 if (!badge) 417 if (!badge)
409 { 418 {
410 this._addChange("badgeText", ""); 419 this._addChange("badgeText", "");
411 } 420 }
412 else 421 else
413 { 422 {
414 if ("number" in badge) 423 if ("number" in badge)
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 return frames.get(0) || null; 528 return frames.get(0) || null;
520 } 529 }
521 }; 530 };
522 } 531 }
523 532
524 return ext.onMessage._dispatch( 533 return ext.onMessage._dispatch(
525 message, sender, sendResponse 534 message, sender, sendResponse
526 ).includes(true); 535 ).includes(true);
527 }); 536 });
528 } 537 }
OLDNEW
« no previous file with comments | « no previous file | lib/icon.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld