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 eventNatives = requireNative('event_natives'); | 5 var eventNatives = requireNative('event_natives'); |
6 var logging = requireNative('logging'); | 6 var logging = requireNative('logging'); |
7 var schemaRegistry = requireNative('schema_registry'); | 7 var schemaRegistry = requireNative('schema_registry'); |
8 var sendRequest = require('sendRequest').sendRequest; | 8 var sendRequest = require('sendRequest').sendRequest; |
9 var utils = require('utils'); | 9 var utils = require('utils'); |
10 var validate = require('schemaUtils').validate; | 10 var validate = require('schemaUtils').validate; |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 // its listeners. | 221 // its listeners. |
222 function registerArgumentMassager(name, callback) { | 222 function registerArgumentMassager(name, callback) { |
223 if (eventArgumentMassagers[name]) | 223 if (eventArgumentMassagers[name]) |
224 throw new Error("Massager already registered for event: " + name); | 224 throw new Error("Massager already registered for event: " + name); |
225 eventArgumentMassagers[name] = callback; | 225 eventArgumentMassagers[name] = callback; |
226 } | 226 } |
227 | 227 |
228 // Dispatches a named event with the given argument array. The args array is | 228 // Dispatches a named event with the given argument array. The args array is |
229 // the list of arguments that will be sent to the event callback. | 229 // the list of arguments that will be sent to the event callback. |
230 function dispatchEvent(name, args, filteringInfo) { | 230 function dispatchEvent(name, args, filteringInfo) { |
231 var listenerIDs = null; | 231 var listenerIDs = []; |
232 | 232 |
233 if (filteringInfo) | 233 if (filteringInfo) |
234 listenerIDs = eventNatives.MatchAgainstEventFilter(name, filteringInfo); | 234 listenerIDs = eventNatives.MatchAgainstEventFilter(name, filteringInfo); |
235 | 235 |
236 var event = attachedNamedEvents[name]; | 236 var event = attachedNamedEvents[name]; |
237 if (!event) | 237 if (!event) |
238 return; | 238 return; |
239 | 239 |
240 var dispatchArgs = function(args) { | 240 var dispatchArgs = function(args) { |
241 var result = event.dispatch_(args, listenerIDs); | 241 var result = event.dispatch_(args, listenerIDs); |
(...skipping 13 matching lines...) Expand all Loading... |
255 if (!this.eventOptions_.supportsListeners) | 255 if (!this.eventOptions_.supportsListeners) |
256 throw new Error("This event does not support listeners."); | 256 throw new Error("This event does not support listeners."); |
257 if (this.eventOptions_.maxListeners && | 257 if (this.eventOptions_.maxListeners && |
258 this.getListenerCount() >= this.eventOptions_.maxListeners) { | 258 this.getListenerCount() >= this.eventOptions_.maxListeners) { |
259 throw new Error("Too many listeners for " + this.eventName_); | 259 throw new Error("Too many listeners for " + this.eventName_); |
260 } | 260 } |
261 if (filters) { | 261 if (filters) { |
262 if (!this.eventOptions_.supportsFilters) | 262 if (!this.eventOptions_.supportsFilters) |
263 throw new Error("This event does not support filters."); | 263 throw new Error("This event does not support filters."); |
264 if (filters.url && !(filters.url instanceof Array)) | 264 if (filters.url && !(filters.url instanceof Array)) |
265 throw new Error("filters.url should be an array"); | 265 throw new Error("filters.url should be an array."); |
| 266 if (filters.serviceType && |
| 267 !(typeof filters.serviceType === 'string')) { |
| 268 throw new Error("filters.serviceType should be a string.") |
| 269 } |
266 } | 270 } |
267 var listener = {callback: cb, filters: filters}; | 271 var listener = {callback: cb, filters: filters}; |
268 this.attach_(listener); | 272 this.attach_(listener); |
269 $Array.push(this.listeners_, listener); | 273 $Array.push(this.listeners_, listener); |
270 }; | 274 }; |
271 | 275 |
272 Event.prototype.attach_ = function(listener) { | 276 Event.prototype.attach_ = function(listener) { |
273 this.attachmentStrategy_.onAddedListener(listener); | 277 this.attachmentStrategy_.onAddedListener(listener); |
274 | 278 |
275 if (this.listeners_.length == 0) { | 279 if (this.listeners_.length == 0) { |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 event.detach_(); | 490 event.detach_(); |
487 } | 491 } |
488 }); | 492 }); |
489 | 493 |
490 // NOTE: Event is (lazily) exposed as chrome.Event from dispatcher.cc. | 494 // NOTE: Event is (lazily) exposed as chrome.Event from dispatcher.cc. |
491 exports.Event = Event; | 495 exports.Event = Event; |
492 | 496 |
493 exports.dispatchEvent = dispatchEvent; | 497 exports.dispatchEvent = dispatchEvent; |
494 exports.parseEventOptions = parseEventOptions; | 498 exports.parseEventOptions = parseEventOptions; |
495 exports.registerArgumentMassager = registerArgumentMassager; | 499 exports.registerArgumentMassager = registerArgumentMassager; |
OLD | NEW |