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 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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 var eventArgumentMassagers = {}; | 126 var eventArgumentMassagers = {}; |
127 | 127 |
128 chromeHidden.Event = {}; | 128 chromeHidden.Event = {}; |
129 | 129 |
130 chromeHidden.Event.registerArgumentMassager = function(name, fn) { | 130 chromeHidden.Event.registerArgumentMassager = function(name, fn) { |
131 if (eventArgumentMassagers[name]) | 131 if (eventArgumentMassagers[name]) |
132 throw new Error("Massager already registered for event: " + name); | 132 throw new Error("Massager already registered for event: " + name); |
133 eventArgumentMassagers[name] = fn; | 133 eventArgumentMassagers[name] = fn; |
134 }; | 134 }; |
135 | 135 |
136 // Dispatches a named event with the given JSON array, which is deserialized | 136 // Dispatches a named event with the given argument array. The args array is |
137 // before dispatch. The JSON array is the list of arguments that will be | 137 // the list of arguments that will be sent to the event callback. |
138 // sent with the event callback. | 138 chromeHidden.Event.dispatch = function(name, args) { |
139 chromeHidden.Event.dispatchJSON = function(name, args) { | |
140 if (attachedNamedEvents[name]) { | 139 if (attachedNamedEvents[name]) { |
141 if (args) { | 140 if (args) { |
142 // TODO(asargent): This is an antiquity. Until all callers of | |
143 // dispatchJSON use actual values, this must remain here to catch the | |
144 // cases where a caller has hard-coded a JSON string to pass in. | |
145 if (typeof(args) == "string") { | |
146 args = chromeHidden.JSON.parse(args); | |
147 } | |
148 if (eventArgumentMassagers[name]) | 141 if (eventArgumentMassagers[name]) |
149 eventArgumentMassagers[name](args); | 142 eventArgumentMassagers[name](args); |
150 } | 143 } |
151 var result = attachedNamedEvents[name].dispatch.apply( | 144 var result = attachedNamedEvents[name].dispatch.apply( |
152 attachedNamedEvents[name], args); | 145 attachedNamedEvents[name], args); |
153 if (result && result.validationErrors) | 146 if (result && result.validationErrors) |
154 return result.validationErrors; | 147 return result.validationErrors; |
155 } | 148 } |
156 }; | 149 }; |
157 | 150 |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 if (event) | 358 if (event) |
366 event.detach_(false); | 359 event.detach_(false); |
367 } | 360 } |
368 }; | 361 }; |
369 | 362 |
370 chromeHidden.dispatchError = function(msg) { | 363 chromeHidden.dispatchError = function(msg) { |
371 console.error(msg); | 364 console.error(msg); |
372 }; | 365 }; |
373 | 366 |
374 exports.Event = chrome.Event; | 367 exports.Event = chrome.Event; |
OLD | NEW |