OLD | NEW |
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 DCHECK = requireNative('logging').DCHECK; | 5 var DCHECK = requireNative('logging').DCHECK; |
6 var eventBindingsNatives = requireNative('event_bindings'); | 6 var eventBindingsNatives = requireNative('event_bindings'); |
7 var AttachEvent = eventBindingsNatives.AttachEvent; | 7 var AttachEvent = eventBindingsNatives.AttachEvent; |
8 var DetachEvent = eventBindingsNatives.DetachEvent; | 8 var DetachEvent = eventBindingsNatives.DetachEvent; |
9 var AttachFilteredEvent = eventBindingsNatives.AttachFilteredEvent; | 9 var AttachFilteredEvent = eventBindingsNatives.AttachFilteredEvent; |
10 var DetachFilteredEvent = eventBindingsNatives.DetachFilteredEvent; | 10 var DetachFilteredEvent = eventBindingsNatives.DetachFilteredEvent; |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 } | 203 } |
204 }; | 204 }; |
205 } else { | 205 } else { |
206 this.validateEventArgs_ = function() {} | 206 this.validateEventArgs_ = function() {} |
207 } | 207 } |
208 }; | 208 }; |
209 | 209 |
210 chromeHidden.Event = {}; | 210 chromeHidden.Event = {}; |
211 | 211 |
212 // callback is a function(args, dispatch). args are the args we receive from | 212 // callback is a function(args, dispatch). args are the args we receive from |
213 // dispatchJSON(), and dispatch is a function(args) that dispatches args to | 213 // dispatchEvent(), and dispatch is a function(args) that dispatches args to |
214 // its listeners. | 214 // its listeners. |
215 chromeHidden.Event.registerArgumentMassager = function(name, callback) { | 215 chromeHidden.Event.registerArgumentMassager = function(name, callback) { |
216 if (eventArgumentMassagers[name]) | 216 if (eventArgumentMassagers[name]) |
217 throw new Error("Massager already registered for event: " + name); | 217 throw new Error("Massager already registered for event: " + name); |
218 eventArgumentMassagers[name] = callback; | 218 eventArgumentMassagers[name] = callback; |
219 }; | 219 }; |
220 | 220 |
221 // Dispatches a named event with the given JSON array, which is deserialized | 221 // Dispatches a named event with the given argument array. The args array is |
222 // before dispatch. The JSON array is the list of arguments that will be | 222 // the list of arguments that will be sent to the event callback. |
223 // sent with the event callback. | 223 chromeHidden.Event.dispatchEvent = function(name, args, filteringInfo) { |
224 chromeHidden.Event.dispatchJSON = function(name, args, filteringInfo) { | |
225 var listenerIDs = null; | 224 var listenerIDs = null; |
226 | 225 |
227 if (filteringInfo) | 226 if (filteringInfo) |
228 listenerIDs = MatchAgainstEventFilter(name, filteringInfo); | 227 listenerIDs = MatchAgainstEventFilter(name, filteringInfo); |
229 | 228 |
230 var event = attachedNamedEvents[name]; | 229 var event = attachedNamedEvents[name]; |
231 if (!event) | 230 if (!event) |
232 return; | 231 return; |
233 | 232 |
234 // TODO(asargent): This is an antiquity. Until all callers of | |
235 // dispatchJSON use actual values, this must remain here to catch the | |
236 // cases where a caller has hard-coded a JSON string to pass in. | |
237 if (typeof(args) == "string") | |
238 args = chromeHidden.JSON.parse(args); | |
239 | |
240 var dispatchArgs = function(args) { | 233 var dispatchArgs = function(args) { |
241 result = event.dispatch_(args, listenerIDs); | 234 result = event.dispatch_(args, listenerIDs); |
242 if (result) | 235 if (result) |
243 DCHECK(!result.validationErrors, result.validationErrors); | 236 DCHECK(!result.validationErrors, result.validationErrors); |
244 }; | 237 }; |
245 | 238 |
246 if (eventArgumentMassagers[name]) | 239 if (eventArgumentMassagers[name]) |
247 eventArgumentMassagers[name](args, dispatchArgs); | 240 eventArgumentMassagers[name](args, dispatchArgs); |
248 else | 241 else |
249 dispatchArgs(args); | 242 dispatchArgs(args); |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
476 if (event) | 469 if (event) |
477 event.detach_(); | 470 event.detach_(); |
478 } | 471 } |
479 }; | 472 }; |
480 | 473 |
481 chromeHidden.dispatchError = function(msg) { | 474 chromeHidden.dispatchError = function(msg) { |
482 console.error(msg); | 475 console.error(msg); |
483 }; | 476 }; |
484 | 477 |
485 exports.Event = chrome.Event; | 478 exports.Event = chrome.Event; |
OLD | NEW |