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

Unified Diff: lib/notificationHelper.js

Issue 29334223: Issue 3532 - Generate animation images at runtime (Closed)
Patch Set: Don't bother generate Safari icons at build time Created Jan. 21, 2016, 10:45 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: lib/notificationHelper.js
diff --git a/lib/notificationHelper.js b/lib/notificationHelper.js
index ebfd7d3161d310820e6f46c51e60322025b52138..59014d08ba8c13ad9da05168d284429a0f786cac 100644
--- a/lib/notificationHelper.js
+++ b/lib/notificationHelper.js
@@ -154,18 +154,15 @@ function notificationClosed()
function imgToBase64(url, callback)
{
- let canvas = document.createElement("canvas"),
- ctx = canvas.getContext("2d"),
- img = new Image;
- img.src = url;
- img.onload = function()
+ return Utils.loadImage(url).then(function(image)
{
- canvas.height = img.height;
- canvas.width = img.width;
- ctx.drawImage(img, 0, 0);
- callback(canvas.toDataURL("image/png"));
- canvas = null;
- };
+ let canvas = document.createElement("canvas");
+ let ctx = canvas.getContext("2d");
+ canvas.height = image.height;
+ canvas.width = image.width;
+ ctx.drawImage(image, 0, 0);
+ return canvas.toDataURL("image/png");
+ });
}
function initChromeNotifications()
@@ -217,7 +214,7 @@ function showNotification(notification)
priority: 2 // We use the highest priority to prevent the notification from closing automatically
};
- imgToBase64(iconUrl, function(iconData)
+ imgToBase64(iconUrl).then(function(iconData)
{
opts.iconUrl = iconData;
chrome.notifications.create("", opts, function() {});
@@ -228,7 +225,7 @@ function showNotification(notification)
if (linkCount > 0)
message += " " + ext.i18n.getMessage("notification_without_buttons");
- imgToBase64(iconUrl, function(iconData)
+ imgToBase64(iconUrl).then(function(iconData)
{
let notification = new Notification(
title,

Powered by Google App Engine
This is Rietveld