| 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 eventBindingsNatives = requireNative('event_bindings'); | 5 var eventBindingsNatives = requireNative('event_bindings'); |
| 6 var AttachEvent = eventBindingsNatives.AttachEvent; | 6 var AttachEvent = eventBindingsNatives.AttachEvent; |
| 7 var DetachEvent = eventBindingsNatives.DetachEvent; | 7 var DetachEvent = eventBindingsNatives.DetachEvent; |
| 8 var AttachFilteredEvent = eventBindingsNatives.AttachFilteredEvent; | 8 var AttachFilteredEvent = eventBindingsNatives.AttachFilteredEvent; |
| 9 var DetachFilteredEvent = eventBindingsNatives.DetachFilteredEvent; | 9 var DetachFilteredEvent = eventBindingsNatives.DetachFilteredEvent; |
| 10 var MatchAgainstEventFilter = eventBindingsNatives.MatchAgainstEventFilter; | 10 var MatchAgainstEventFilter = eventBindingsNatives.MatchAgainstEventFilter; |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 }; | 207 }; |
| 208 | 208 |
| 209 chromeHidden.Event = {}; | 209 chromeHidden.Event = {}; |
| 210 | 210 |
| 211 chromeHidden.Event.registerArgumentMassager = function(name, fn) { | 211 chromeHidden.Event.registerArgumentMassager = function(name, fn) { |
| 212 if (eventArgumentMassagers[name]) | 212 if (eventArgumentMassagers[name]) |
| 213 throw new Error("Massager already registered for event: " + name); | 213 throw new Error("Massager already registered for event: " + name); |
| 214 eventArgumentMassagers[name] = fn; | 214 eventArgumentMassagers[name] = fn; |
| 215 }; | 215 }; |
| 216 | 216 |
| 217 // Dispatches a named event with the given JSON array, which is deserialized | 217 // Dispatches a named event with the given argument array. The args array is |
| 218 // before dispatch. The JSON array is the list of arguments that will be | 218 // the list of arguments that will be sent to the event callback. |
| 219 // sent with the event callback. | 219 chromeHidden.Event.dispatch = function(name, args) { |
| 220 chromeHidden.Event.dispatchJSON = function(name, args, filteringInfo) { | |
| 221 var listenerIDs = null; | 220 var listenerIDs = null; |
| 222 | 221 |
| 223 if (filteringInfo) { | 222 if (filteringInfo) { |
| 224 listenerIDs = MatchAgainstEventFilter(name, filteringInfo); | 223 listenerIDs = MatchAgainstEventFilter(name, filteringInfo); |
| 225 } | 224 } |
| 226 if (attachedNamedEvents[name]) { | 225 if (attachedNamedEvents[name]) { |
| 227 if (args) { | 226 if (args) { |
| 228 // TODO(asargent): This is an antiquity. Until all callers of | |
| 229 // dispatchJSON use actual values, this must remain here to catch the | |
| 230 // cases where a caller has hard-coded a JSON string to pass in. | |
| 231 if (typeof(args) == "string") { | |
| 232 args = chromeHidden.JSON.parse(args); | |
| 233 } | |
| 234 if (eventArgumentMassagers[name]) | 227 if (eventArgumentMassagers[name]) |
| 235 eventArgumentMassagers[name](args); | 228 eventArgumentMassagers[name](args); |
| 236 } | 229 } |
| 237 | 230 |
| 238 var event = attachedNamedEvents[name]; | 231 var event = attachedNamedEvents[name]; |
| 239 var result; | 232 var result; |
| 240 // TODO(koz): We have to do this differently for unfiltered events (which | 233 // TODO(koz): We have to do this differently for unfiltered events (which |
| 241 // have listenerIDs = null) because some bindings write over | 234 // have listenerIDs = null) because some bindings write over |
| 242 // event.dispatch (eg: experimental.app.custom_bindings.js) and so expect | 235 // event.dispatch (eg: experimental.app.custom_bindings.js) and so expect |
| 243 // events to go through it. These places need to be fixed so that they | 236 // events to go through it. These places need to be fixed so that they |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 if (event) | 466 if (event) |
| 474 event.detach_(); | 467 event.detach_(); |
| 475 } | 468 } |
| 476 }; | 469 }; |
| 477 | 470 |
| 478 chromeHidden.dispatchError = function(msg) { | 471 chromeHidden.dispatchError = function(msg) { |
| 479 console.error(msg); | 472 console.error(msg); |
| 480 }; | 473 }; |
| 481 | 474 |
| 482 exports.Event = chrome.Event; | 475 exports.Event = chrome.Event; |
| OLD | NEW |