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

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

Issue 296113009: Revert 272211 "Allow high-res bitmaps to be passed in from notif..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 years, 7 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 //
7 var binding = require('binding').Binding.create('notifications'); 6 var binding = require('binding').Binding.create('notifications');
8 7
9 var sendRequest = require('sendRequest').sendRequest; 8 var sendRequest = require('sendRequest').sendRequest;
10 var imageUtil = require('imageUtil'); 9 var imageUtil = require('imageUtil');
11 var lastError = require('lastError'); 10 var lastError = require('lastError');
12 var notificationsPrivate = requireNative('notifications_private');
13 11
14 function imageDataSetter(context, key) { 12 function image_data_setter(context, key) {
15 var f = function(val) { 13 var f = function(val) {
16 this[key] = val; 14 this[key] = val;
17 }; 15 };
18 return $Function.bind(f, context); 16 return $Function.bind(f, context);
19 } 17 }
20 18
21 // A URL Spec is an object with the following keys: 19 function replaceNotificationOptionURLs(notification_details, callback) {
22 // path: The resource to be downloaded. 20 // A URL Spec is an object with the following keys:
23 // width: (optional) The maximum width of the image to be downloaded in device 21 // path: The resource to be downloaded.
24 // pixels. 22 // width: (optional) The maximum width of the image to be downloaded.
25 // height: (optional) The maximum height of the image to be downloaded in 23 // height: (optional) The maximum height of the image to be downloaded.
26 // device pixels. 24 // callback: A function to be called when the URL is complete. It
27 // callback: A function to be called when the URL is complete. It 25 // should accept an ImageData object and set the appropriate
28 // should accept an ImageData object and set the appropriate 26 // field in the output of create.
29 // field in |notificationDetails|.
30 function getUrlSpecs(imageSizes, notificationDetails) {
31 var urlSpecs = [];
32 27
28 // TODO(dewittj): Try to remove hard-coding of image sizes.
33 // |iconUrl| might be optional for notification updates. 29 // |iconUrl| might be optional for notification updates.
34 if (notificationDetails.iconUrl) { 30 var url_specs = [];
35 $Array.push(urlSpecs, { 31 if (notification_details.iconUrl) {
36 path: notificationDetails.iconUrl, 32 $Array.push(url_specs, {
37 width: imageSizes.icon.width * imageSizes.scaleFactor, 33 path: notification_details.iconUrl,
38 height: imageSizes.icon.height * imageSizes.scaleFactor, 34 width: 80,
39 callback: imageDataSetter(notificationDetails, 'iconBitmap') 35 height: 80,
36 callback: image_data_setter(notification_details, 'iconBitmap')
40 }); 37 });
41 } 38 }
42 39
43 // |imageUrl| is optional. 40 // |imageUrl| is optional.
44 if (notificationDetails.imageUrl) { 41 if (notification_details.imageUrl) {
45 $Array.push(urlSpecs, { 42 $Array.push(url_specs, {
46 path: notificationDetails.imageUrl, 43 path: notification_details.imageUrl,
47 width: imageSizes.image.width * imageSizes.scaleFactor, 44 width: 360,
48 height: imageSizes.image.height * imageSizes.scaleFactor, 45 height: 240,
49 callback: imageDataSetter(notificationDetails, 'imageBitmap') 46 callback: image_data_setter(notification_details, 'imageBitmap')
50 }); 47 });
51 } 48 }
52 49
53 // Each button has an optional icon. 50 // Each button has an optional icon.
54 var buttonList = notificationDetails.buttons; 51 var button_list = notification_details.buttons;
55 if (buttonList && typeof buttonList.length === 'number') { 52 if (button_list && typeof button_list.length === 'number') {
56 var numButtons = buttonList.length; 53 var num_buttons = button_list.length;
57 for (var i = 0; i < numButtons; i++) { 54 for (var i = 0; i < num_buttons; i++) {
58 if (buttonList[i].iconUrl) { 55 if (button_list[i].iconUrl) {
59 $Array.push(urlSpecs, { 56 $Array.push(url_specs, {
60 path: buttonList[i].iconUrl, 57 path: button_list[i].iconUrl,
61 width: imageSizes.buttonIcon.width * imageSizes.scaleFactor, 58 width: 16,
62 height: imageSizes.buttonIcon.height * imageSizes.scaleFactor, 59 height: 16,
63 callback: imageDataSetter(buttonList[i], 'iconBitmap') 60 callback: image_data_setter(button_list[i], 'iconBitmap')
64 }); 61 });
65 } 62 }
66 } 63 }
67 } 64 }
68 65
69 return urlSpecs;
70 }
71
72 function replaceNotificationOptionURLs(notification_details, callback) {
73 var imageSizes = notificationsPrivate.GetNotificationImageSizes();
74 var url_specs = getUrlSpecs(imageSizes, notification_details);
75 if (!url_specs.length) { 66 if (!url_specs.length) {
76 callback(true); 67 callback(true);
77 return; 68 return;
78 } 69 }
79 70
80 var errors = 0; 71 var errors = 0;
81 72
82 imageUtil.loadAllImages(url_specs, { 73 imageUtil.loadAllImages(url_specs, {
83 onerror: function(index) { 74 onerror: function(index) {
84 errors++; 75 errors++;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 117
127 var notificationsCustomHook = function(bindingsAPI, extensionId) { 118 var notificationsCustomHook = function(bindingsAPI, extensionId) {
128 var apiFunctions = bindingsAPI.apiFunctions; 119 var apiFunctions = bindingsAPI.apiFunctions;
129 apiFunctions.setHandleRequest('create', handleCreate); 120 apiFunctions.setHandleRequest('create', handleCreate);
130 apiFunctions.setHandleRequest('update', handleUpdate); 121 apiFunctions.setHandleRequest('update', handleUpdate);
131 }; 122 };
132 123
133 binding.registerCustomHook(notificationsCustomHook); 124 binding.registerCustomHook(notificationsCustomHook);
134 125
135 exports.binding = binding.generate(); 126 exports.binding = binding.generate();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698