OLD | NEW |
---|---|
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 var binding = require('binding').Binding.create('notifications'); | 6 var binding = require('binding').Binding.create('notifications'); |
7 | 7 |
8 var sendRequest = require('sendRequest').sendRequest; | 8 var sendRequest = require('sendRequest').sendRequest; |
9 var imageUtil = require('imageUtil'); | 9 var imageUtil = require('imageUtil'); |
10 var lastError = require('lastError'); | 10 var lastError = require('lastError'); |
11 | 11 |
12 function image_data_setter(context, key) { | 12 function image_data_setter(context, key) { |
13 var f = function(val) { | 13 var f = function(val) { |
14 this[key] = val; | 14 this[key] = val; |
15 }; | 15 }; |
16 return $Function.bind(f, context); | 16 return $Function.bind(f, context); |
17 } | 17 } |
18 | 18 |
19 function replaceNotificationOptionURLs(notification_details, callback) { | 19 function replaceNotificationOptionURLs(notification_details, callback) { |
20 // A URL Spec is an object with the following keys: | 20 // A URL Spec is an object with the following keys: |
21 // path: The resource to be downloaded. | 21 // path: The resource to be downloaded. |
22 // width: (optional) The maximum width of the image to be downloaded. | 22 // width: (optional) The maximum width of the image to be downloaded. |
23 // height: (optional) The maximum height of the image to be downloaded. | 23 // height: (optional) The maximum height of the image to be downloaded. |
24 // callback: A function to be called when the URL is complete. It | 24 // callback: A function to be called when the URL is complete. It |
25 // should accept an ImageData object and set the appropriate | 25 // should accept an ImageData object and set the appropriate |
26 // field in the output of create. | 26 // field in the output of create. |
27 | 27 |
28 // |iconUrl| might be optional for notification updates. | |
29 if (!notification_details.iconUrl) { | |
30 callback(true); | |
dewittj
2013/07/24 23:09:53
What if all they want to update is the image url,
jianli
2013/07/25 01:02:41
Done.
| |
31 return; | |
32 } | |
33 | |
28 // TODO(dewittj): Try to remove hard-coding of image sizes. | 34 // TODO(dewittj): Try to remove hard-coding of image sizes. |
29 // |iconUrl| is required. | |
30 var url_specs = [{ | 35 var url_specs = [{ |
31 path: notification_details.iconUrl, | 36 path: notification_details.iconUrl, |
32 width: 80, | 37 width: 80, |
33 height: 80, | 38 height: 80, |
34 callback: image_data_setter(notification_details, 'iconBitmap') | 39 callback: image_data_setter(notification_details, 'iconBitmap') |
35 }]; | 40 }]; |
36 | 41 |
37 // |imageUrl| is optional. | 42 // |imageUrl| is optional. |
38 if (notification_details.imageUrl) { | 43 if (notification_details.imageUrl) { |
39 $Array.push(url_specs, { | 44 $Array.push(url_specs, { |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
109 | 114 |
110 var notificationsCustomHook = function(bindingsAPI, extensionId) { | 115 var notificationsCustomHook = function(bindingsAPI, extensionId) { |
111 var apiFunctions = bindingsAPI.apiFunctions; | 116 var apiFunctions = bindingsAPI.apiFunctions; |
112 apiFunctions.setHandleRequest('create', handleCreate); | 117 apiFunctions.setHandleRequest('create', handleCreate); |
113 apiFunctions.setHandleRequest('update', handleUpdate); | 118 apiFunctions.setHandleRequest('update', handleUpdate); |
114 }; | 119 }; |
115 | 120 |
116 binding.registerCustomHook(notificationsCustomHook); | 121 binding.registerCustomHook(notificationsCustomHook); |
117 | 122 |
118 exports.binding = binding.generate(); | 123 exports.binding = binding.generate(); |
OLD | NEW |