| 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 // |listenerIds| contains the ids of matching listeners, or is an empty array | 244 function dispatchEvent(name, args, filteringInfo) { |
| 245 // for all listeners. | 245 var listenerIDs = []; |
| 246 function dispatchEvent(name, args, listenerIds) { | 246 |
| 247 if (filteringInfo) |
| 248 listenerIDs = eventNatives.MatchAgainstEventFilter(name, filteringInfo); |
| 249 |
| 247 var event = attachedNamedEvents[name]; | 250 var event = attachedNamedEvents[name]; |
| 248 if (!event) | 251 if (!event) |
| 249 return; | 252 return; |
| 250 | 253 |
| 251 var dispatchArgs = function(args) { | 254 var dispatchArgs = function(args) { |
| 252 var result = event.dispatch_(args, listenerIds); | 255 var result = event.dispatch_(args, listenerIDs); |
| 253 if (result) | 256 if (result) |
| 254 logging.DCHECK(!result.validationErrors, result.validationErrors); | 257 logging.DCHECK(!result.validationErrors, result.validationErrors); |
| 255 return result; | 258 return result; |
| 256 }; | 259 }; |
| 257 | 260 |
| 258 if (eventArgumentMassagers[name]) | 261 if (eventArgumentMassagers[name]) |
| 259 eventArgumentMassagers[name](args, dispatchArgs); | 262 eventArgumentMassagers[name](args, dispatchArgs); |
| 260 else | 263 else |
| 261 dispatchArgs(args); | 264 dispatchArgs(args); |
| 262 } | 265 } |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 'getRules', | 521 'getRules', |
| 519 ], | 522 ], |
| 520 }); | 523 }); |
| 521 | 524 |
| 522 // NOTE: Event is (lazily) exposed as chrome.Event from dispatcher.cc. | 525 // NOTE: Event is (lazily) exposed as chrome.Event from dispatcher.cc. |
| 523 exports.$set('Event', Event); | 526 exports.$set('Event', Event); |
| 524 | 527 |
| 525 exports.$set('dispatchEvent', dispatchEvent); | 528 exports.$set('dispatchEvent', dispatchEvent); |
| 526 exports.$set('parseEventOptions', parseEventOptions); | 529 exports.$set('parseEventOptions', parseEventOptions); |
| 527 exports.$set('registerArgumentMassager', registerArgumentMassager); | 530 exports.$set('registerArgumentMassager', registerArgumentMassager); |
| OLD | NEW |