| Index: chrome/renderer/resources/extensions/notifications_custom_bindings.js
|
| diff --git a/chrome/renderer/resources/extensions/notifications_custom_bindings.js b/chrome/renderer/resources/extensions/notifications_custom_bindings.js
|
| index 013628abff281af8a238a343e2793c12a5e98b9c..d35fba3202e08326aa53099b89fecfb65b2e93d8 100644
|
| --- a/chrome/renderer/resources/extensions/notifications_custom_bindings.js
|
| +++ b/chrome/renderer/resources/extensions/notifications_custom_bindings.js
|
| @@ -11,13 +11,31 @@ var imageUtil = require('imageUtil');
|
| var lastError = require('lastError');
|
| var notificationsPrivate = requireNative('notifications_private');
|
|
|
| -function imageDataSetter(context, key) {
|
| +function imageDataSetter(context) {
|
| var f = function(val) {
|
| - this[key] = val;
|
| + this.data = val;
|
| };
|
| return $Function.bind(f, context);
|
| }
|
|
|
| +function getUrlsForBitmapList(notificationBitmapList, imageSize, scaleFactor) {
|
| + // Returns a list of specs to be used by the image util library.
|
| + var rv = [];
|
| + $Array.forEach(notificationBitmapList, function(bitmap) {
|
| + if (typeof bitmap.data === 'string' ||
|
| + bitmap.data instanceof $String.self) {
|
| + $Array.push(rv, {
|
| + path: bitmap.data,
|
| + width: imageSize.width * scaleFactor,
|
| + height: imageSize.height * scaleFactor,
|
| + scale: bitmap.scale || 1.0,
|
| + callback: imageDataSetter(bitmap)
|
| + });
|
| + }
|
| + });
|
| + return rv;
|
| +}
|
| +
|
| // 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
|
| @@ -28,45 +46,23 @@ function imageDataSetter(context, key) {
|
| // 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.
|
| - 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 (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 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')
|
| - });
|
| - }
|
| - }
|
| + var urls = $Array.concat(
|
| + getUrlsForBitmapList(
|
| + notificationDetails.icons,
|
| + imageSizes.icon,
|
| + imageSizes.scaleFactor),
|
| + getUrlsForBitmapList(
|
| + notificationDetails.images,
|
| + imageSizes.image));
|
| + for (var i = 0; i < notificationDetails.buttons.length; i++) {
|
| + urls = $Array.concat(
|
| + urls,
|
| + getUrlsForBitmapList(
|
| + notificationDetails.buttons[i].icons,
|
| + imageSizes.buttonIcon));
|
| }
|
|
|
| - return urlSpecs;
|
| + return urls;
|
| }
|
|
|
| function replaceNotificationOptionURLs(notification_details, callback) {
|
| @@ -98,11 +94,7 @@ function replaceNotificationOptionURLs(notification_details, callback) {
|
| }
|
|
|
| function genHandle(name, failure_function) {
|
| - return function(id, input_notification_details, callback) {
|
| - // TODO(dewittj): Remove this hack. This is used as a way to deep
|
| - // copy a complex JSON object.
|
| - var notification_details = JSON.parse(
|
| - JSON.stringify(input_notification_details));
|
| + return function(id, notification_details, callback) {
|
| var that = this;
|
| replaceNotificationOptionURLs(notification_details, function(success) {
|
| if (success) {
|
| @@ -114,11 +106,43 @@ function genHandle(name, failure_function) {
|
| lastError.run(name,
|
| 'Unable to download all specified images.',
|
| null,
|
| - failure_function, [callback, id])
|
| + failure_function, [callback, id]);
|
| });
|
| };
|
| }
|
|
|
| +function translateBitmapUrls(id, input_options, callback) {
|
| + var args = $Array.slice(arguments);
|
| +
|
| + // TODO(dewittj): Remove this hack. This is used as a way to deep
|
| + // copy a complex JSON object.
|
| + var options = JSON.parse(JSON.stringify(input_options));
|
| +
|
| + options.icons = options.icons || [];
|
| + if (options.iconUrl) {
|
| + $Array.splice(options.icons, 0, 0, {scale: 1.0, data: options.iconUrl});
|
| + }
|
| +
|
| + options.images = options.images || [];
|
| + if (options.imageUrl) {
|
| + $Array.splice(options.images, 0, 0, {scale: 1.0, data: options.imageUrl});
|
| + }
|
| +
|
| + options.buttons = options.buttons || [];
|
| + for (var i = 0; i < options.buttons.length; i++) {
|
| + options.buttons[i].icons = options.buttons[i].icons || [];
|
| + if (options.buttons[i].url) {
|
| + $Array.splice(
|
| + options.buttons[i].icons,
|
| + 0,
|
| + 0,
|
| + {scale: 1.0, data: options.buttons[i].url});
|
| + }
|
| + }
|
| +
|
| + return [id, options, callback];
|
| +}
|
| +
|
| var handleCreate = genHandle('notifications.create',
|
| function(callback, id) { callback(id); });
|
| var handleUpdate = genHandle('notifications.update',
|
| @@ -126,6 +150,7 @@ var handleUpdate = genHandle('notifications.update',
|
|
|
| var notificationsCustomHook = function(bindingsAPI, extensionId) {
|
| var apiFunctions = bindingsAPI.apiFunctions;
|
| + apiFunctions.setUpdateArgumentsPostValidate('create', translateBitmapUrls);
|
| apiFunctions.setHandleRequest('create', handleCreate);
|
| apiFunctions.setHandleRequest('update', handleUpdate);
|
| };
|
|
|