| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 // TODO(robwu): Fix indentation. | 5 // TODO(robwu): Fix indentation. |
| 6 | 6 |
| 7 var exceptionHandler = require('uncaught_exception_handler'); | 7 var exceptionHandler = require('uncaught_exception_handler'); |
| 8 var eventNatives = requireNative('event_natives'); | 8 var eventNatives = requireNative('event_natives'); |
| 9 var logging = requireNative('logging'); | 9 var logging = requireNative('logging'); |
| 10 var schemaRegistry = requireNative('schema_registry'); | 10 var schemaRegistry = requireNative('schema_registry'); |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 // dispatchEvent(), and dispatch is a function(args) that dispatches args to | 219 // dispatchEvent(), and dispatch is a function(args) that dispatches args to |
| 220 // its listeners. | 220 // its listeners. |
| 221 function registerArgumentMassager(name, callback) { | 221 function registerArgumentMassager(name, callback) { |
| 222 if (eventArgumentMassagers[name]) | 222 if (eventArgumentMassagers[name]) |
| 223 throw new Error("Massager already registered for event: " + name); | 223 throw new Error("Massager already registered for event: " + name); |
| 224 eventArgumentMassagers[name] = callback; | 224 eventArgumentMassagers[name] = callback; |
| 225 } | 225 } |
| 226 | 226 |
| 227 // Dispatches a named event with the given argument array. The args array is | 227 // Dispatches a named event with the given argument array. The args array is |
| 228 // the list of arguments that will be sent to the event callback. | 228 // the list of arguments that will be sent to the event callback. |
| 229 function dispatchEvent(name, args, filteringInfo) { | 229 // |listenerIds| contains the ids of matching listeners, or is an empty array |
| 230 var listenerIDs = []; | 230 // for all listeners. |
| 231 | 231 function dispatchEvent(name, args, listenerIds) { |
| 232 if (filteringInfo) | |
| 233 listenerIDs = eventNatives.MatchAgainstEventFilter(name, filteringInfo); | |
| 234 | |
| 235 var event = attachedNamedEvents[name]; | 232 var event = attachedNamedEvents[name]; |
| 236 if (!event) | 233 if (!event) |
| 237 return; | 234 return; |
| 238 | 235 |
| 239 var dispatchArgs = function(args) { | 236 var dispatchArgs = function(args) { |
| 240 var result = event.dispatch_(args, listenerIDs); | 237 var result = event.dispatch_(args, listenerIds); |
| 241 if (result) | 238 if (result) |
| 242 logging.DCHECK(!result.validationErrors, result.validationErrors); | 239 logging.DCHECK(!result.validationErrors, result.validationErrors); |
| 243 return result; | 240 return result; |
| 244 }; | 241 }; |
| 245 | 242 |
| 246 if (eventArgumentMassagers[name]) | 243 if (eventArgumentMassagers[name]) |
| 247 eventArgumentMassagers[name](args, dispatchArgs); | 244 eventArgumentMassagers[name](args, dispatchArgs); |
| 248 else | 245 else |
| 249 dispatchArgs(args); | 246 dispatchArgs(args); |
| 250 } | 247 } |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 'getRules', | 503 'getRules', |
| 507 ], | 504 ], |
| 508 }); | 505 }); |
| 509 | 506 |
| 510 // NOTE: Event is (lazily) exposed as chrome.Event from dispatcher.cc. | 507 // NOTE: Event is (lazily) exposed as chrome.Event from dispatcher.cc. |
| 511 exports.$set('Event', Event); | 508 exports.$set('Event', Event); |
| 512 | 509 |
| 513 exports.$set('dispatchEvent', dispatchEvent); | 510 exports.$set('dispatchEvent', dispatchEvent); |
| 514 exports.$set('parseEventOptions', parseEventOptions); | 511 exports.$set('parseEventOptions', parseEventOptions); |
| 515 exports.$set('registerArgumentMassager', registerArgumentMassager); | 512 exports.$set('registerArgumentMassager', registerArgumentMassager); |
| OLD | NEW |