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

Delta Between Two Patch Sets: ext/background.js

Issue 29995555: Issue 7253 - Pre-render icons for badge on Chromium (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Left Patch Set: Update for loop Created Feb. 3, 2019, 7:31 a.m.
Right Patch Set: Rewrite renderIcons Created Feb. 3, 2019, 9:45 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | lib/icon.js » ('j') | lib/icon.js » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 == "icon" && "setIcon" in browser.browserAction) 330 if (change == "iconPath" && "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
341 let path = { 332 let path = {
342 16: this._changes.icon.path.replace("$size", "16"), 333 16: this._changes.iconPath.replace("$size", "16"),
343 19: this._changes.icon.path.replace("$size", "19"), 334 20: this._changes.iconPath.replace("$size", "20"),
344 20: this._changes.icon.path.replace("$size", "20"), 335 32: this._changes.iconPath.replace("$size", "32"),
345 32: this._changes.icon.path.replace("$size", "32"), 336 40: this._changes.iconPath.replace("$size", "40")
346 38: this._changes.icon.path.replace("$size", "38"),
347 40: this._changes.icon.path.replace("$size", "40")
348 }; 337 };
349 try 338 try
350 { 339 {
351 return browser.browserAction.setIcon({tabId: this._tabId, path}); 340 return browser.browserAction.setIcon({tabId: this._tabId, path});
352 } 341 }
353 catch (e) 342 catch (e)
354 { 343 {
355 // Edge throws if passed icon sizes different than 19,20,38,40px. 344 // Edge throws if passed icon sizes different than 19,20,38,40px.
356 delete path[16]; 345 delete path[16];
357 delete path[32]; 346 delete path[32];
358 return browser.browserAction.setIcon({tabId: this._tabId, path}); 347 return browser.browserAction.setIcon({tabId: this._tabId, path});
359 } 348 }
360 } 349 }
361 350
351 if (change == "iconImageData" && "setIcon" in browser.browserAction)
352 {
353 return browser.browserAction.setIcon({
354 tabId: this._tabId,
355 imageData: this._changes.iconImageData
356 });
357 }
358
362 // There is no badge on Firefox for Android; the browser action is 359 // There is no badge on Firefox for Android; the browser action is
363 // simply a menu item. 360 // simply a menu item.
364 if (change == "badgeText" && "setBadgeText" in browser.browserAction) 361 if (change == "badgeText" && "setBadgeText" in browser.browserAction)
365 return browser.browserAction.setBadgeText({ 362 return browser.browserAction.setBadgeText({
366 tabId: this._tabId, 363 tabId: this._tabId,
367 text: this._changes.badgeText 364 text: this._changes.badgeText
368 }); 365 });
369 366
370 // There is no badge on Firefox for Android; the browser action is 367 // There is no badge on Firefox for Android; the browser action is
371 // simply a menu item. 368 // simply a menu item.
(...skipping 29 matching lines...) Expand all
401 this._changes = null; 398 this._changes = null;
402 }).catch(() => 399 }).catch(() =>
403 { 400 {
404 // If the tab is prerendered, browser.browserAction.set* fails 401 // If the tab is prerendered, browser.browserAction.set* fails
405 // and we have to delay our changes until the currently visible tab 402 // and we have to delay our changes until the currently visible tab
406 // is replaced with the prerendered tab. 403 // is replaced with the prerendered tab.
407 browser.tabs.onReplaced.addListener(onReplaced); 404 browser.tabs.onReplaced.addListener(onReplaced);
408 }); 405 });
409 } 406 }
410 }, 407 },
411 setIcon(path, imageData = null) 408 setIconPath(path)
412 { 409 {
413 this._addChange("icon", {path, imageData}); 410 this._addChange("iconPath", path);
Sebastian Noack 2019/02/03 07:45:15 How about using _addChange("iconPath") and _addCha
411 },
412 setIconImageData(imageData)
413 {
414 this._addChange("iconImageData", imageData);
414 }, 415 },
415 setBadge(badge) 416 setBadge(badge)
416 { 417 {
417 if (!badge) 418 if (!badge)
418 { 419 {
419 this._addChange("badgeText", ""); 420 this._addChange("badgeText", "");
420 } 421 }
421 else 422 else
422 { 423 {
423 if ("number" in badge) 424 if ("number" in badge)
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 return frames.get(0) || null; 529 return frames.get(0) || null;
529 } 530 }
530 }; 531 };
531 } 532 }
532 533
533 return ext.onMessage._dispatch( 534 return ext.onMessage._dispatch(
534 message, sender, sendResponse 535 message, sender, sendResponse
535 ).includes(true); 536 ).includes(true);
536 }); 537 });
537 } 538 }
LEFTRIGHT
« no previous file | lib/icon.js » ('j') | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld