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: Use iconPath and iconImageData separately Created Feb. 3, 2019, 8:10 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 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 } 343 }
344 catch (e) 344 catch (e)
345 { 345 {
346 // Edge throws if passed icon sizes different than 19,20,38,40px. 346 // Edge throws if passed icon sizes different than 19,20,38,40px.
347 delete path[16]; 347 delete path[16];
348 delete path[32]; 348 delete path[32];
349 return browser.browserAction.setIcon({tabId: this._tabId, path}); 349 return browser.browserAction.setIcon({tabId: this._tabId, path});
350 } 350 }
351 } 351 }
352 352
353 if (change == "iconImageData" && "setIcon" in browser.browserAction)
354 {
355 return browser.browserAction.setIcon({
356 tabId: this._tabId,
357 imageData: this._changes.iconImageData
358 });
359 }
360
353 // There is no badge on Firefox for Android; the browser action is 361 // There is no badge on Firefox for Android; the browser action is
354 // simply a menu item. 362 // simply a menu item.
355 if (change == "badgeText" && "setBadgeText" in browser.browserAction) 363 if (change == "badgeText" && "setBadgeText" in browser.browserAction)
356 return browser.browserAction.setBadgeText({ 364 return browser.browserAction.setBadgeText({
357 tabId: this._tabId, 365 tabId: this._tabId,
358 text: this._changes.badgeText 366 text: this._changes.badgeText
359 }); 367 });
360 368
361 // There is no badge on Firefox for Android; the browser action is 369 // There is no badge on Firefox for Android; the browser action is
362 // simply a menu item. 370 // simply a menu item.
(...skipping 29 matching lines...) Expand all
392 this._changes = null; 400 this._changes = null;
393 }).catch(() => 401 }).catch(() =>
394 { 402 {
395 // If the tab is prerendered, browser.browserAction.set* fails 403 // If the tab is prerendered, browser.browserAction.set* fails
396 // and we have to delay our changes until the currently visible tab 404 // and we have to delay our changes until the currently visible tab
397 // is replaced with the prerendered tab. 405 // is replaced with the prerendered tab.
398 browser.tabs.onReplaced.addListener(onReplaced); 406 browser.tabs.onReplaced.addListener(onReplaced);
399 }); 407 });
400 } 408 }
401 }, 409 },
402 setIcon(path) 410 setIcon(path, imageData = null)
403 { 411 {
404 this._addChange("iconPath", path); 412 // Use ImageData if available.
413 if (imageData)
414 this._addChange("iconImageData", imageData);
415 else
416 this._addChange("iconPath", path);
405 }, 417 },
406 setBadge(badge) 418 setBadge(badge)
407 { 419 {
408 if (!badge) 420 if (!badge)
409 { 421 {
410 this._addChange("badgeText", ""); 422 this._addChange("badgeText", "");
411 } 423 }
412 else 424 else
413 { 425 {
414 if ("number" in badge) 426 if ("number" in badge)
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 return frames.get(0) || null; 531 return frames.get(0) || null;
520 } 532 }
521 }; 533 };
522 } 534 }
523 535
524 return ext.onMessage._dispatch( 536 return ext.onMessage._dispatch(
525 message, sender, sendResponse 537 message, sender, sendResponse
526 ).includes(true); 538 ).includes(true);
527 }); 539 });
528 } 540 }
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