| 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 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 JSON array, which is deserialized |
| 137 // before dispatch. The JSON array is the list of arguments that will be | 137 // before dispatch. The JSON array is the list of arguments that will be |
| 138 // sent with the event callback. | 138 // sent with the event callback. |
| 139 chromeHidden.Event.dispatchJSON = function(name, args) { | 139 chromeHidden.Event.dispatchJSON = function(name, args) { |
| 140 if (attachedNamedEvents[name]) { | 140 if (attachedNamedEvents[name]) { |
| 141 if (args) { | 141 if (args) { |
| 142 args = chromeHidden.JSON.parse(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 } |
| 143 if (eventArgumentMassagers[name]) | 148 if (eventArgumentMassagers[name]) |
| 144 eventArgumentMassagers[name](args); | 149 eventArgumentMassagers[name](args); |
| 145 } | 150 } |
| 146 var result = attachedNamedEvents[name].dispatch.apply( | 151 var result = attachedNamedEvents[name].dispatch.apply( |
| 147 attachedNamedEvents[name], args); | 152 attachedNamedEvents[name], args); |
| 148 if (result && result.validationErrors) | 153 if (result && result.validationErrors) |
| 149 return result.validationErrors; | 154 return result.validationErrors; |
| 150 } | 155 } |
| 151 }; | 156 }; |
| 152 | 157 |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 if (event) | 365 if (event) |
| 361 event.detach_(false); | 366 event.detach_(false); |
| 362 } | 367 } |
| 363 }; | 368 }; |
| 364 | 369 |
| 365 chromeHidden.dispatchError = function(msg) { | 370 chromeHidden.dispatchError = function(msg) { |
| 366 console.error(msg); | 371 console.error(msg); |
| 367 }; | 372 }; |
| 368 | 373 |
| 369 exports.Event = chrome.Event; | 374 exports.Event = chrome.Event; |
| OLD | NEW |