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

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

Issue 855813002: Mark create/update/clear callbacks of notification API as optional (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 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
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 //
7 var binding = require('binding').Binding.create('notifications'); 7 var binding = require('binding').Binding.create('notifications');
8 8
9 var sendRequest = require('sendRequest').sendRequest; 9 var sendRequest = require('sendRequest').sendRequest;
10 var exceptionHandler = require('uncaught_exception_handler');
10 var imageUtil = require('imageUtil'); 11 var imageUtil = require('imageUtil');
11 var lastError = require('lastError'); 12 var lastError = require('lastError');
12 var notificationsPrivate = requireNative('notifications_private'); 13 var notificationsPrivate = requireNative('notifications_private');
13 14
14 function imageDataSetter(context, key) { 15 function imageDataSetter(context, key) {
15 var f = function(val) { 16 var f = function(val) {
16 this[key] = val; 17 this[key] = val;
17 }; 18 };
18 return $Function.bind(f, context); 19 return $Function.bind(f, context);
19 } 20 }
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 var url_spec = url_specs[index]; 103 var url_spec = url_specs[index];
103 url_spec.callback(imageData[index]); 104 url_spec.callback(imageData[index]);
104 } 105 }
105 callback(true); 106 callback(true);
106 } 107 }
107 }); 108 });
108 } 109 }
109 110
110 function genHandle(name, failure_function) { 111 function genHandle(name, failure_function) {
111 return function(id, input_notification_details, callback) { 112 return function(id, input_notification_details, callback) {
112 // TODO(dewittj): Remove this hack. This is used as a way to deep 113 // TODO(dewittj): Remove this hack. This is used as a way to deep
not at google - send to devlin 2015/01/20 17:41:35 The best way to deep copy would be to expose a nat
robwu 2015/01/20 22:34:01 Recursive objects are invalid for this API, so tha
dewittj 2015/01/20 22:46:51 The JSON copy has 2 important properties: 1) Custo
robwu 2015/01/20 22:58:44 There are many other extension APIs that suffer fr
not at google - send to devlin 2015/01/21 22:21:19 I'm sure that copying is necessary. I was addressi
robwu 2015/01/21 23:21:09 Yep, I understood that, and I pointed out that cop
113 // copy a complex JSON object. 114 // copy a complex JSON object.
114 var notification_details = JSON.parse( 115 var notification_details = $JSON.parse(
115 JSON.stringify(input_notification_details)); 116 $JSON.stringify(input_notification_details));
116 var that = this; 117 var that = this;
118 var stack = exceptionHandler.getExtensionStackTrace();
117 replaceNotificationOptionURLs(notification_details, function(success) { 119 replaceNotificationOptionURLs(notification_details, function(success) {
118 if (success) { 120 if (success) {
119 sendRequest(that.name, 121 sendRequest(that.name,
120 [id, notification_details, callback], 122 [id, notification_details, callback],
121 that.definition.parameters); 123 that.definition.parameters, {stack: stack});
122 return; 124 return;
123 } 125 }
124 lastError.run(name, 126 var error = 'Unable to download all specified images.';
125 'Unable to download all specified images.', 127 if (callback) {
126 null, 128 lastError.run(name, error, stack, failure_function, [callback, id]);
127 failure_function, [callback, id]) 129 } else {
130 lastError.reportUncheckedLastError(name, error, stack);
131 }
not at google - send to devlin 2015/01/21 22:21:19 You could avoid needing to expose reportUncheckedL
robwu 2015/01/21 23:21:09 Done. Though reportUncheckedLastError has to be pu
128 }); 132 });
129 }; 133 };
130 } 134 }
131 135
132 var handleCreate = genHandle('notifications.create', 136 var handleCreate = genHandle('notifications.create',
133 function(callback, id) { callback(id); }); 137 function(callback, id) { callback(id); });
134 var handleUpdate = genHandle('notifications.update', 138 var handleUpdate = genHandle('notifications.update',
135 function(callback, id) { callback(false); }); 139 function(callback, id) { callback(false); });
136 140
137 var notificationsCustomHook = function(bindingsAPI, extensionId) { 141 var notificationsCustomHook = function(bindingsAPI, extensionId) {
138 var apiFunctions = bindingsAPI.apiFunctions; 142 var apiFunctions = bindingsAPI.apiFunctions;
139 apiFunctions.setHandleRequest('create', handleCreate); 143 apiFunctions.setHandleRequest('create', handleCreate);
140 apiFunctions.setHandleRequest('update', handleUpdate); 144 apiFunctions.setHandleRequest('update', handleUpdate);
141 }; 145 };
142 146
143 binding.registerCustomHook(notificationsCustomHook); 147 binding.registerCustomHook(notificationsCustomHook);
144 148
145 exports.binding = binding.generate(); 149 exports.binding = binding.generate();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698