Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1379)

Side by Side Diff: chrome/renderer/resources/extensions/notifications_custom_bindings.js

Issue 291193009: Reland: Allow high-res bitmaps to be passed in from notifications API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix test post-rebase. Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Custom bindings for the notifications API. 5 // Custom bindings for the notifications API.
6 //
6 var binding = require('binding').Binding.create('notifications'); 7 var binding = require('binding').Binding.create('notifications');
7 8
8 var sendRequest = require('sendRequest').sendRequest; 9 var sendRequest = require('sendRequest').sendRequest;
9 var imageUtil = require('imageUtil'); 10 var imageUtil = require('imageUtil');
10 var lastError = require('lastError'); 11 var lastError = require('lastError');
12 var notificationsPrivate = requireNative('notifications_private');
11 13
12 function image_data_setter(context, key) { 14 function imageDataSetter(context, key) {
13 var f = function(val) { 15 var f = function(val) {
14 this[key] = val; 16 this[key] = val;
15 }; 17 };
16 return $Function.bind(f, context); 18 return $Function.bind(f, context);
17 } 19 }
18 20
19 function replaceNotificationOptionURLs(notification_details, callback) { 21 // A URL Spec is an object with the following keys:
20 // A URL Spec is an object with the following keys: 22 // path: The resource to be downloaded.
21 // path: The resource to be downloaded. 23 // width: (optional) The maximum width of the image to be downloaded in device
22 // width: (optional) The maximum width of the image to be downloaded. 24 // pixels.
23 // height: (optional) The maximum height of the image to be downloaded. 25 // height: (optional) The maximum height of the image to be downloaded in
24 // callback: A function to be called when the URL is complete. It 26 // device pixels.
25 // should accept an ImageData object and set the appropriate 27 // callback: A function to be called when the URL is complete. It
26 // field in the output of create. 28 // should accept an ImageData object and set the appropriate
29 // field in |notificationDetails|.
30 function getUrlSpecs(imageSizes, notificationDetails) {
31 var urlSpecs = [];
27 32
28 // TODO(dewittj): Try to remove hard-coding of image sizes.
29 // |iconUrl| might be optional for notification updates. 33 // |iconUrl| might be optional for notification updates.
30 var url_specs = []; 34 if (notificationDetails.iconUrl) {
31 if (notification_details.iconUrl) { 35 $Array.push(urlSpecs, {
32 $Array.push(url_specs, { 36 path: notificationDetails.iconUrl,
33 path: notification_details.iconUrl, 37 width: imageSizes.icon.width * imageSizes.scaleFactor,
34 width: 80, 38 height: imageSizes.icon.height * imageSizes.scaleFactor,
35 height: 80, 39 callback: imageDataSetter(notificationDetails, 'iconBitmap')
36 callback: image_data_setter(notification_details, 'iconBitmap')
37 }); 40 });
38 } 41 }
39 42
40 // |imageUrl| is optional. 43 // |imageUrl| is optional.
41 if (notification_details.imageUrl) { 44 if (notificationDetails.imageUrl) {
42 $Array.push(url_specs, { 45 $Array.push(urlSpecs, {
43 path: notification_details.imageUrl, 46 path: notificationDetails.imageUrl,
44 width: 360, 47 width: imageSizes.image.width * imageSizes.scaleFactor,
45 height: 240, 48 height: imageSizes.image.height * imageSizes.scaleFactor,
46 callback: image_data_setter(notification_details, 'imageBitmap') 49 callback: imageDataSetter(notificationDetails, 'imageBitmap')
47 }); 50 });
48 } 51 }
49 52
50 // Each button has an optional icon. 53 // Each button has an optional icon.
51 var button_list = notification_details.buttons; 54 var buttonList = notificationDetails.buttons;
52 if (button_list && typeof button_list.length === 'number') { 55 if (buttonList && typeof buttonList.length === 'number') {
53 var num_buttons = button_list.length; 56 var numButtons = buttonList.length;
54 for (var i = 0; i < num_buttons; i++) { 57 for (var i = 0; i < numButtons; i++) {
55 if (button_list[i].iconUrl) { 58 if (buttonList[i].iconUrl) {
56 $Array.push(url_specs, { 59 $Array.push(urlSpecs, {
57 path: button_list[i].iconUrl, 60 path: buttonList[i].iconUrl,
58 width: 16, 61 width: imageSizes.buttonIcon.width * imageSizes.scaleFactor,
59 height: 16, 62 height: imageSizes.buttonIcon.height * imageSizes.scaleFactor,
60 callback: image_data_setter(button_list[i], 'iconBitmap') 63 callback: imageDataSetter(buttonList[i], 'iconBitmap')
61 }); 64 });
62 } 65 }
63 } 66 }
64 } 67 }
65 68
69 return urlSpecs;
70 }
71
72 function replaceNotificationOptionURLs(notification_details, callback) {
73 var imageSizes = notificationsPrivate.GetNotificationImageSizes();
74 var url_specs = getUrlSpecs(imageSizes, notification_details);
66 if (!url_specs.length) { 75 if (!url_specs.length) {
67 callback(true); 76 callback(true);
68 return; 77 return;
69 } 78 }
70 79
71 var errors = 0; 80 var errors = 0;
72 81
73 imageUtil.loadAllImages(url_specs, { 82 imageUtil.loadAllImages(url_specs, {
74 onerror: function(index) { 83 onerror: function(index) {
75 errors++; 84 errors++;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 126
118 var notificationsCustomHook = function(bindingsAPI, extensionId) { 127 var notificationsCustomHook = function(bindingsAPI, extensionId) {
119 var apiFunctions = bindingsAPI.apiFunctions; 128 var apiFunctions = bindingsAPI.apiFunctions;
120 apiFunctions.setHandleRequest('create', handleCreate); 129 apiFunctions.setHandleRequest('create', handleCreate);
121 apiFunctions.setHandleRequest('update', handleUpdate); 130 apiFunctions.setHandleRequest('update', handleUpdate);
122 }; 131 };
123 132
124 binding.registerCustomHook(notificationsCustomHook); 133 binding.registerCustomHook(notificationsCustomHook);
125 134
126 exports.binding = binding.generate(); 135 exports.binding = binding.generate();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698