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

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: comments #25 Created 5 years, 10 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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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 lastError.run(name,
125 'Unable to download all specified images.', 127 'Unable to download all specified images.',
126 null, 128 stack,
127 failure_function, [callback, id]) 129 failure_function, [callback || function() {}, id]);
128 }); 130 });
129 }; 131 };
130 } 132 }
131 133
132 var handleCreate = genHandle('notifications.create', 134 var handleCreate = genHandle('notifications.create',
133 function(callback, id) { callback(id); }); 135 function(callback, id) { callback(id); });
134 var handleUpdate = genHandle('notifications.update', 136 var handleUpdate = genHandle('notifications.update',
135 function(callback, id) { callback(false); }); 137 function(callback, id) { callback(false); });
136 138
137 var notificationsCustomHook = function(bindingsAPI, extensionId) { 139 var notificationsCustomHook = function(bindingsAPI, extensionId) {
138 var apiFunctions = bindingsAPI.apiFunctions; 140 var apiFunctions = bindingsAPI.apiFunctions;
139 apiFunctions.setHandleRequest('create', handleCreate); 141 apiFunctions.setHandleRequest('create', handleCreate);
140 apiFunctions.setHandleRequest('update', handleUpdate); 142 apiFunctions.setHandleRequest('update', handleUpdate);
141 }; 143 };
142 144
143 binding.registerCustomHook(notificationsCustomHook); 145 binding.registerCustomHook(notificationsCustomHook);
144 146
145 exports.binding = binding.generate(); 147 exports.binding = binding.generate();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698