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 DCHECK = requireNative('logging').DCHECK; | 5 var DCHECK = requireNative('logging').DCHECK; |
6 var eventBindingsNatives = requireNative('event_bindings'); | 6 var eventBindingsNatives = requireNative('event_bindings'); |
7 var AttachEvent = eventBindingsNatives.AttachEvent; | 7 var AttachEvent = eventBindingsNatives.AttachEvent; |
8 var DetachEvent = eventBindingsNatives.DetachEvent; | 8 var DetachEvent = eventBindingsNatives.DetachEvent; |
9 var AttachFilteredEvent = eventBindingsNatives.AttachFilteredEvent; | 9 var AttachFilteredEvent = eventBindingsNatives.AttachFilteredEvent; |
10 var DetachFilteredEvent = eventBindingsNatives.DetachFilteredEvent; | 10 var DetachFilteredEvent = eventBindingsNatives.DetachFilteredEvent; |
(...skipping 23 matching lines...) Expand all Loading... |
34 var eventType = utils.lookup(eventsSchema.types, 'id', 'events.Event'); | 34 var eventType = utils.lookup(eventsSchema.types, 'id', 'events.Event'); |
35 | 35 |
36 ruleFunctionSchemas.addRules = | 36 ruleFunctionSchemas.addRules = |
37 utils.lookup(eventType.functions, 'name', 'addRules'); | 37 utils.lookup(eventType.functions, 'name', 'addRules'); |
38 ruleFunctionSchemas.getRules = | 38 ruleFunctionSchemas.getRules = |
39 utils.lookup(eventType.functions, 'name', 'getRules'); | 39 utils.lookup(eventType.functions, 'name', 'getRules'); |
40 ruleFunctionSchemas.removeRules = | 40 ruleFunctionSchemas.removeRules = |
41 utils.lookup(eventType.functions, 'name', 'removeRules'); | 41 utils.lookup(eventType.functions, 'name', 'removeRules'); |
42 } | 42 } |
43 | 43 |
44 // Local implementation of JSON.parse & JSON.stringify that protect us | |
45 // from being clobbered by an extension. | |
46 // | |
47 // TODO(aa): This makes me so sad. We shouldn't need it, as we can just pass | |
48 // Values directly over IPC without serializing to strings and use | |
49 // JSONValueConverter. | |
50 chromeHidden.JSON = new (function() { | |
51 var $Object = Object; | |
52 var $Array = Array; | |
53 var $jsonStringify = JSON.stringify; | |
54 var $jsonParse = JSON.parse; | |
55 | |
56 this.stringify = function(thing) { | |
57 var customizedObjectToJSON = $Object.prototype.toJSON; | |
58 var customizedArrayToJSON = $Array.prototype.toJSON; | |
59 if (customizedObjectToJSON !== undefined) { | |
60 $Object.prototype.toJSON = null; | |
61 } | |
62 if (customizedArrayToJSON !== undefined) { | |
63 $Array.prototype.toJSON = null; | |
64 } | |
65 try { | |
66 return $jsonStringify(thing); | |
67 } finally { | |
68 if (customizedObjectToJSON !== undefined) { | |
69 $Object.prototype.toJSON = customizedObjectToJSON; | |
70 } | |
71 if (customizedArrayToJSON !== undefined) { | |
72 $Array.prototype.toJSON = customizedArrayToJSON; | |
73 } | |
74 } | |
75 }; | |
76 | |
77 this.parse = function(thing) { | |
78 return $jsonParse(thing); | |
79 }; | |
80 })(); | |
81 | |
82 // A map of event names to the event object that is registered to that name. | 44 // A map of event names to the event object that is registered to that name. |
83 var attachedNamedEvents = {}; | 45 var attachedNamedEvents = {}; |
84 | 46 |
85 // An array of all attached event objects, used for detaching on unload. | 47 // An array of all attached event objects, used for detaching on unload. |
86 var allAttachedEvents = []; | 48 var allAttachedEvents = []; |
87 | 49 |
88 // A map of functions that massage event arguments before they are dispatched. | 50 // A map of functions that massage event arguments before they are dispatched. |
89 // Key is event name, value is function. | 51 // Key is event name, value is function. |
90 var eventArgumentMassagers = {}; | 52 var eventArgumentMassagers = {}; |
91 | 53 |
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
500 if (event) | 462 if (event) |
501 event.detach_(); | 463 event.detach_(); |
502 } | 464 } |
503 }; | 465 }; |
504 | 466 |
505 chromeHidden.dispatchError = function(msg) { | 467 chromeHidden.dispatchError = function(msg) { |
506 console.error(msg); | 468 console.error(msg); |
507 }; | 469 }; |
508 | 470 |
509 exports.Event = chrome.Event; | 471 exports.Event = chrome.Event; |
OLD | NEW |