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

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

Issue 9965005: Deprecate chrome.extension.sendRequest in favor of sendMessage, with a safer (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync Created 8 years, 8 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 var eventBindingsNatives = requireNative('event_bindings'); 5 var eventBindingsNatives = requireNative('event_bindings');
6 var AttachEvent = eventBindingsNatives.AttachEvent; 6 var AttachEvent = eventBindingsNatives.AttachEvent;
7 var DetachEvent = eventBindingsNatives.DetachEvent; 7 var DetachEvent = eventBindingsNatives.DetachEvent;
8 var Print = eventBindingsNatives.Print; 8 var Print = eventBindingsNatives.Print;
9 9
10 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); 10 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden();
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 // Dispatches a named event with the given JSON array, which is deserialized 108 // Dispatches a named event with the given JSON array, which is deserialized
109 // before dispatch. The JSON array is the list of arguments that will be 109 // before dispatch. The JSON array is the list of arguments that will be
110 // sent with the event callback. 110 // sent with the event callback.
111 chromeHidden.Event.dispatchJSON = function(name, args) { 111 chromeHidden.Event.dispatchJSON = function(name, args) {
112 if (attachedNamedEvents[name]) { 112 if (attachedNamedEvents[name]) {
113 if (args) { 113 if (args) {
114 args = chromeHidden.JSON.parse(args); 114 args = chromeHidden.JSON.parse(args);
115 if (eventArgumentMassagers[name]) 115 if (eventArgumentMassagers[name])
116 eventArgumentMassagers[name](args); 116 eventArgumentMassagers[name](args);
117 } 117 }
118 return attachedNamedEvents[name].dispatch.apply( 118 var result = attachedNamedEvents[name].dispatch.apply(
119 attachedNamedEvents[name], args); 119 attachedNamedEvents[name], args);
120 if (result && result.validationErrors)
121 return result.validationErrors;
120 } 122 }
121 }; 123 };
122 124
123 // Dispatches a named event with the given arguments, supplied as an array. 125 // Dispatches a named event with the given arguments, supplied as an array.
124 chromeHidden.Event.dispatch = function(name, args) { 126 chromeHidden.Event.dispatch = function(name, args) {
125 if (attachedNamedEvents[name]) { 127 if (attachedNamedEvents[name]) {
126 attachedNamedEvents[name].dispatch.apply( 128 attachedNamedEvents[name].dispatch.apply(
127 attachedNamedEvents[name], args); 129 attachedNamedEvents[name], args);
128 } 130 }
129 }; 131 };
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 }; 188 };
187 189
188 // Dispatches this event object to all listeners, passing all supplied 190 // Dispatches this event object to all listeners, passing all supplied
189 // arguments to this function each listener. 191 // arguments to this function each listener.
190 chrome.Event.prototype.dispatch = function(varargs) { 192 chrome.Event.prototype.dispatch = function(varargs) {
191 if (!this.eventOptions_.supportsListeners) 193 if (!this.eventOptions_.supportsListeners)
192 throw new Error("This event does not support listeners."); 194 throw new Error("This event does not support listeners.");
193 var args = Array.prototype.slice.call(arguments); 195 var args = Array.prototype.slice.call(arguments);
194 var validationErrors = this.validate_(args); 196 var validationErrors = this.validate_(args);
195 if (validationErrors) { 197 if (validationErrors) {
196 return validationErrors; 198 return {validationErrors: validationErrors};
197 } 199 }
200 var results = [];
198 for (var i = 0; i < this.listeners_.length; i++) { 201 for (var i = 0; i < this.listeners_.length; i++) {
199 try { 202 try {
200 this.listeners_[i].apply(null, args); 203 var result = this.listeners_[i].apply(null, args);
204 if (result !== undefined)
205 results.push(result);
201 } catch (e) { 206 } catch (e) {
202 console.error("Error in event handler for '" + this.eventName_ + 207 console.error("Error in event handler for '" + this.eventName_ +
203 "': " + e.stack); 208 "': " + e.stack);
204 } 209 }
205 } 210 }
211 if (results.length)
212 return {results: results};
206 }; 213 };
207 214
208 // Attaches this event object to its name. Only one object can have a given 215 // Attaches this event object to its name. Only one object can have a given
209 // name. 216 // name.
210 chrome.Event.prototype.attach_ = function() { 217 chrome.Event.prototype.attach_ = function() {
211 AttachEvent(this.eventName_); 218 AttachEvent(this.eventName_);
212 allAttachedEvents[allAttachedEvents.length] = this; 219 allAttachedEvents[allAttachedEvents.length] = this;
213 if (!this.eventName_) 220 if (!this.eventName_)
214 return; 221 return;
215 222
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 for (var i = 0; i < allAttachedEvents.length; ++i) { 309 for (var i = 0; i < allAttachedEvents.length; ++i) {
303 var event = allAttachedEvents[i]; 310 var event = allAttachedEvents[i];
304 if (event) 311 if (event)
305 event.detach_(false); 312 event.detach_(false);
306 } 313 }
307 }; 314 };
308 315
309 chromeHidden.dispatchError = function(msg) { 316 chromeHidden.dispatchError = function(msg) {
310 console.error(msg); 317 console.error(msg);
311 }; 318 };
OLDNEW
« no previous file with comments | « chrome/common/extensions/docs/tabs.html ('k') | chrome/renderer/resources/extensions/extension_custom_bindings.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698