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: Pre render frames, listen for onactivated Created Jan. 24, 2016, 3:34 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
« no previous file with comments | « lib/icon.js ('k') | metadata.chrome » ('j') | safari/ext/background.js » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/notificationHelper.js
diff --git a/lib/notificationHelper.js b/lib/notificationHelper.js
index cfe93ae8611bf6a92e2f74f17f1f3de13b1d1756..75ad148a6b38c1ee07da3a526eb1db07a9655bbe 100644
--- a/lib/notificationHelper.js
+++ b/lib/notificationHelper.js
@@ -17,7 +17,8 @@
/** @module notificationHelper */
-let {startIconAnimation, stopIconAnimation} = require("icon");
+let {loadImageAsCanvas,
+ startIconAnimation, stopIconAnimation} = require("icon");
let {Utils} = require("utils");
let {Notification: NotificationStorage} = require("notification");
let {stringifyURL} = require("url");
@@ -152,22 +153,6 @@ function notificationClosed()
activeNotification = null;
}
-function imgToBase64(url, callback)
-{
- let canvas = document.createElement("canvas"),
- ctx = canvas.getContext("2d"),
- img = new Image;
- img.src = url;
- img.onload = function()
- {
- canvas.height = img.height;
- canvas.width = img.width;
- ctx.drawImage(img, 0, 0);
- callback(canvas.toDataURL("image/png"));
- canvas = null;
- };
-}
-
function initChromeNotifications()
{
// Chrome hides notifications in notification center when clicked so we need to clear them
@@ -217,9 +202,9 @@ function showNotification(notification)
priority: 2 // We use the highest priority to prevent the notification from closing automatically
};
- imgToBase64(iconUrl, function(iconData)
+ loadImageAsCanvas(iconUrl).then(canvas =>
{
- opts.iconUrl = iconData;
+ opts.iconUrl = canvas.toDataURL("image/png");
chrome.notifications.create("", opts, function() {});
});
}
@@ -228,7 +213,7 @@ function showNotification(notification)
if (linkCount > 0)
message += " " + ext.i18n.getMessage("notification_without_buttons");
- imgToBase64(iconUrl, function(iconData)
+ loadImageAsCanvas(iconUrl).then(canvas =>
{
let notification = new Notification(
title,
@@ -236,7 +221,7 @@ function showNotification(notification)
lang: Utils.appLocale,
dir: ext.i18n.getMessage("@@bidi_dir"),
body: message,
- icon: iconData
+ icon: canvas.toDataURL("image/png")
}
);
« no previous file with comments | « lib/icon.js ('k') | metadata.chrome » ('j') | safari/ext/background.js » ('J')

Powered by Google App Engine
This is Rietveld