| 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 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 // dispatchEvent(), and dispatch is a function(args) that dispatches args to | 234 // dispatchEvent(), and dispatch is a function(args) that dispatches args to |
| 235 // its listeners. | 235 // its listeners. |
| 236 function registerArgumentMassager(name, callback) { | 236 function registerArgumentMassager(name, callback) { |
| 237 if (eventArgumentMassagers[name]) | 237 if (eventArgumentMassagers[name]) |
| 238 throw new Error("Massager already registered for event: " + name); | 238 throw new Error("Massager already registered for event: " + name); |
| 239 eventArgumentMassagers[name] = callback; | 239 eventArgumentMassagers[name] = callback; |
| 240 } | 240 } |
| 241 | 241 |
| 242 // Dispatches a named event with the given argument array. The args array is | 242 // Dispatches a named event with the given argument array. The args array is |
| 243 // the list of arguments that will be sent to the event callback. | 243 // the list of arguments that will be sent to the event callback. |
| 244 function dispatchEvent(name, args, filteringInfo) { | 244 // |listenerIds| contains the ids of matching listeners, or is an empty array |
| 245 var listenerIDs = []; | 245 // for all listeners. |
| 246 | 246 function dispatchEvent(name, args, listenerIds) { |
| 247 if (filteringInfo) | |
| 248 listenerIDs = eventNatives.MatchAgainstEventFilter(name, filteringInfo); | |
| 249 | |
| 250 var event = attachedNamedEvents[name]; | 247 var event = attachedNamedEvents[name]; |
| 251 if (!event) | 248 if (!event) |
| 252 return; | 249 return; |
| 253 | 250 |
| 254 var dispatchArgs = function(args) { | 251 var dispatchArgs = function(args) { |
| 255 var result = event.dispatch_(args, listenerIDs); | 252 var result = event.dispatch_(args, listenerIds); |
| 256 if (result) | 253 if (result) |
| 257 logging.DCHECK(!result.validationErrors, result.validationErrors); | 254 logging.DCHECK(!result.validationErrors, result.validationErrors); |
| 258 return result; | 255 return result; |
| 259 }; | 256 }; |
| 260 | 257 |
| 261 if (eventArgumentMassagers[name]) | 258 if (eventArgumentMassagers[name]) |
| 262 eventArgumentMassagers[name](args, dispatchArgs); | 259 eventArgumentMassagers[name](args, dispatchArgs); |
| 263 else | 260 else |
| 264 dispatchArgs(args); | 261 dispatchArgs(args); |
| 265 } | 262 } |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 'getRules', | 518 'getRules', |
| 522 ], | 519 ], |
| 523 }); | 520 }); |
| 524 | 521 |
| 525 // NOTE: Event is (lazily) exposed as chrome.Event from dispatcher.cc. | 522 // NOTE: Event is (lazily) exposed as chrome.Event from dispatcher.cc. |
| 526 exports.$set('Event', Event); | 523 exports.$set('Event', Event); |
| 527 | 524 |
| 528 exports.$set('dispatchEvent', dispatchEvent); | 525 exports.$set('dispatchEvent', dispatchEvent); |
| 529 exports.$set('parseEventOptions', parseEventOptions); | 526 exports.$set('parseEventOptions', parseEventOptions); |
| 530 exports.$set('registerArgumentMassager', registerArgumentMassager); | 527 exports.$set('registerArgumentMassager', registerArgumentMassager); |
| OLD | NEW |