summaryrefslogtreecommitdiffstats
path: root/chromium/chrome/renderer/resources/extensions/notifications_custom_bindings.js
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/chrome/renderer/resources/extensions/notifications_custom_bindings.js')
-rw-r--r--chromium/chrome/renderer/resources/extensions/notifications_custom_bindings.js77
1 files changed, 43 insertions, 34 deletions
diff --git a/chromium/chrome/renderer/resources/extensions/notifications_custom_bindings.js b/chromium/chrome/renderer/resources/extensions/notifications_custom_bindings.js
index fb8264d1868..013628abff2 100644
--- a/chromium/chrome/renderer/resources/extensions/notifications_custom_bindings.js
+++ b/chromium/chrome/renderer/resources/extensions/notifications_custom_bindings.js
@@ -3,66 +3,75 @@
// found in the LICENSE file.
// Custom bindings for the notifications API.
+//
var binding = require('binding').Binding.create('notifications');
var sendRequest = require('sendRequest').sendRequest;
var imageUtil = require('imageUtil');
var lastError = require('lastError');
+var notificationsPrivate = requireNative('notifications_private');
-function image_data_setter(context, key) {
+function imageDataSetter(context, key) {
var f = function(val) {
this[key] = val;
};
return $Function.bind(f, context);
}
-function replaceNotificationOptionURLs(notification_details, callback) {
- // A URL Spec is an object with the following keys:
- // path: The resource to be downloaded.
- // width: (optional) The maximum width of the image to be downloaded.
- // height: (optional) The maximum height of the image to be downloaded.
- // callback: A function to be called when the URL is complete. It
- // should accept an ImageData object and set the appropriate
- // field in the output of create.
-
- // TODO(dewittj): Try to remove hard-coding of image sizes.
+// A URL Spec is an object with the following keys:
+// path: The resource to be downloaded.
+// width: (optional) The maximum width of the image to be downloaded in device
+// pixels.
+// height: (optional) The maximum height of the image to be downloaded in
+// device pixels.
+// callback: A function to be called when the URL is complete. It
+// should accept an ImageData object and set the appropriate
+// field in |notificationDetails|.
+function getUrlSpecs(imageSizes, notificationDetails) {
+ var urlSpecs = [];
+
// |iconUrl| might be optional for notification updates.
- var url_specs = [];
- if (notification_details.iconUrl) {
- $Array.push(url_specs, {
- path: notification_details.iconUrl,
- width: 80,
- height: 80,
- callback: image_data_setter(notification_details, 'iconBitmap')
+ if (notificationDetails.iconUrl) {
+ $Array.push(urlSpecs, {
+ path: notificationDetails.iconUrl,
+ width: imageSizes.icon.width * imageSizes.scaleFactor,
+ height: imageSizes.icon.height * imageSizes.scaleFactor,
+ callback: imageDataSetter(notificationDetails, 'iconBitmap')
});
}
// |imageUrl| is optional.
- if (notification_details.imageUrl) {
- $Array.push(url_specs, {
- path: notification_details.imageUrl,
- width: 360,
- height: 240,
- callback: image_data_setter(notification_details, 'imageBitmap')
+ if (notificationDetails.imageUrl) {
+ $Array.push(urlSpecs, {
+ path: notificationDetails.imageUrl,
+ width: imageSizes.image.width * imageSizes.scaleFactor,
+ height: imageSizes.image.height * imageSizes.scaleFactor,
+ callback: imageDataSetter(notificationDetails, 'imageBitmap')
});
}
// Each button has an optional icon.
- var button_list = notification_details.buttons;
- if (button_list && typeof button_list.length === 'number') {
- var num_buttons = button_list.length;
- for (var i = 0; i < num_buttons; i++) {
- if (button_list[i].iconUrl) {
- $Array.push(url_specs, {
- path: button_list[i].iconUrl,
- width: 16,
- height: 16,
- callback: image_data_setter(button_list[i], 'iconBitmap')
+ var buttonList = notificationDetails.buttons;
+ if (buttonList && typeof buttonList.length === 'number') {
+ var numButtons = buttonList.length;
+ for (var i = 0; i < numButtons; i++) {
+ if (buttonList[i].iconUrl) {
+ $Array.push(urlSpecs, {
+ path: buttonList[i].iconUrl,
+ width: imageSizes.buttonIcon.width * imageSizes.scaleFactor,
+ height: imageSizes.buttonIcon.height * imageSizes.scaleFactor,
+ callback: imageDataSetter(buttonList[i], 'iconBitmap')
});
}
}
}
+ return urlSpecs;
+}
+
+function replaceNotificationOptionURLs(notification_details, callback) {
+ var imageSizes = notificationsPrivate.GetNotificationImageSizes();
+ var url_specs = getUrlSpecs(imageSizes, notification_details);
if (!url_specs.length) {
callback(true);
return;