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

Unified Diff: background.js

Issue 5677191404716032: make abp-128.png icon non web accessible (Closed)
Patch Set: Created March 28, 2014, 11:52 a.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 | « no previous file | metadata.chrome » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: background.js
===================================================================
--- a/background.js
+++ b/background.js
@@ -351,6 +351,22 @@
}
}
+function imgToBase64(url, callback)
+{
+ var canvas = document.createElement("CANVAS"),
Wladimir Palant 2014/03/28 14:18:29 Nit: document.createElement("canvas") please (lowe
saroyanm 2014/03/28 15:16:02 Done.
+ 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 showNotification(notification)
{
if (activeNotification && activeNotification.id === notification.id)
@@ -382,7 +398,6 @@
type: "basic",
title: title,
message: message,
- iconUrl: iconUrl,
buttons: [],
priority: 2 // We use the highest priority to prevent the notification from closing automatically
};
@@ -400,17 +415,24 @@
opts.buttons.push({title: match[1]});
}
- chrome.notifications.create("", opts, function() {});
- chrome.notifications.onButtonClicked.addListener(notificationButtonClick);
+ imgToBase64(iconUrl, function(iconData)
+ {
+ opts["iconUrl"] = iconData;
+ chrome.notifications.create("", opts, function() {});
+ chrome.notifications.onButtonClicked.addListener(notificationButtonClick);
+ });
}
else if (hasWebkitNotifications && "createNotification" in webkitNotifications && activeNotification.type !== "question")
{
if (hasLinks)
message += " " + ext.i18n.getMessage("notification_without_buttons");
- var notification = webkitNotifications.createNotification(iconUrl, title, message);
- notification.show();
- notification.addEventListener("click", openNotificationLinks, false);
+ imgToBase64(iconUrl, function(iconData)
+ {
+ var notification = webkitNotifications.createNotification(iconData, title, message);
+ notification.show();
+ notification.addEventListener("click", openNotificationLinks, false);
+ });
}
else
{
« no previous file with comments | « no previous file | metadata.chrome » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld