Index: chrome/renderer/resources/extensions/event.js |
diff --git a/chrome/renderer/resources/extensions/event.js b/chrome/renderer/resources/extensions/event.js |
index 3c944590a74da4988c464be31a9b0b5019e997a4..c232709ba9ebef6eda7d8394b02b08c7434b3ed5 100644 |
--- a/chrome/renderer/resources/extensions/event.js |
+++ b/chrome/renderer/resources/extensions/event.js |
@@ -3,6 +3,7 @@ |
// found in the LICENSE file. |
var DCHECK = requireNative('logging').DCHECK; |
+ require('json_schema'); |
not at google - send to devlin
2013/02/15 22:26:17
TODO: json_schema shouldn't put things on chromeHi
cduvall
2013/02/19 23:58:49
Done.
|
var eventBindingsNatives = requireNative('event_bindings'); |
var AttachEvent = eventBindingsNatives.AttachEvent; |
var DetachEvent = eventBindingsNatives.DetachEvent; |
@@ -14,8 +15,8 @@ |
var validate = require('schemaUtils').validate; |
var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); |
- var GetExtensionAPIDefinition = |
- requireNative('apiDefinitions').GetExtensionAPIDefinition; |
+ var chrome = requireNative('chrome').GetChrome(); |
+ var schemaRegistry = requireNative('schema_registry'); |
// Schemas for the rule-style functions on the events API that |
// only need to be generated occasionally, so populate them lazily. |
@@ -30,7 +31,7 @@ |
function ensureRuleSchemasLoaded() { |
if (ruleFunctionSchemas.addRules) |
return; |
- var eventsSchema = GetExtensionAPIDefinition("events")[0]; |
+ var eventsSchema = schemaRegistry.GetSchema("events"); |
var eventType = utils.lookup(eventsSchema.types, 'id', 'events.Event'); |
ruleFunctionSchemas.addRules = |
@@ -189,7 +190,7 @@ |
// |
// If opt_eventOptions exists, it is a dictionary that contains the boolean |
// entries "supportsListeners" and "supportsRules". |
- chrome.Event = function(opt_eventName, opt_argSchemas, opt_eventOptions) { |
+ var Event = function(opt_eventName, opt_argSchemas, opt_eventOptions) { |
this.eventName_ = opt_eventName; |
this.listeners_ = []; |
this.eventOptions_ = chromeHidden.parseEventOptions(opt_eventOptions); |
@@ -264,7 +265,7 @@ |
}; |
// Registers a callback to be called when this event is dispatched. |
- chrome.Event.prototype.addListener = function(cb, filters) { |
+ Event.prototype.addListener = function(cb, filters) { |
if (!this.eventOptions_.supportsListeners) |
throw new Error("This event does not support listeners."); |
if (this.eventOptions_.maxListeners && |
@@ -281,7 +282,7 @@ |
this.listeners_.push(listener); |
}; |
- chrome.Event.prototype.attach_ = function(listener) { |
+ Event.prototype.attach_ = function(listener) { |
this.attachmentStrategy_.onAddedListener(listener); |
if (this.listeners_.length == 0) { |
allAttachedEvents[allAttachedEvents.length] = this; |
@@ -298,7 +299,7 @@ |
}; |
// Unregisters a callback. |
- chrome.Event.prototype.removeListener = function(cb) { |
+ Event.prototype.removeListener = function(cb) { |
if (!this.eventOptions_.supportsListeners) |
throw new Error("This event does not support listeners."); |
var idx = this.findListener_(cb); |
@@ -326,19 +327,19 @@ |
}; |
// Test if the given callback is registered for this event. |
- chrome.Event.prototype.hasListener = function(cb) { |
+ Event.prototype.hasListener = function(cb) { |
if (!this.eventOptions_.supportsListeners) |
throw new Error("This event does not support listeners."); |
return this.findListener_(cb) > -1; |
}; |
// Test if any callbacks are registered for this event. |
- chrome.Event.prototype.hasListeners = function() { |
+ Event.prototype.hasListeners = function() { |
return this.getListenerCount() > 0; |
}; |
// Return the number of listeners on this event. |
- chrome.Event.prototype.getListenerCount = function() { |
+ Event.prototype.getListenerCount = function() { |
if (!this.eventOptions_.supportsListeners) |
throw new Error("This event does not support listeners."); |
return this.listeners_.length; |
@@ -346,7 +347,7 @@ |
// Returns the index of the given callback if registered, or -1 if not |
// found. |
- chrome.Event.prototype.findListener_ = function(cb) { |
+ Event.prototype.findListener_ = function(cb) { |
for (var i = 0; i < this.listeners_.length; i++) { |
if (this.listeners_[i].callback == cb) { |
return i; |
@@ -356,7 +357,7 @@ |
return -1; |
}; |
- chrome.Event.prototype.dispatch_ = function(args, listenerIDs) { |
+ Event.prototype.dispatch_ = function(args, listenerIDs) { |
if (!this.eventOptions_.supportsListeners) |
throw new Error("This event does not support listeners."); |
var validationErrors = this.validateEventArgs_(args); |
@@ -386,28 +387,28 @@ |
} |
// Can be overridden to support custom dispatching. |
- chrome.Event.prototype.dispatchToListener = function(callback, args) { |
+ Event.prototype.dispatchToListener = function(callback, args) { |
return callback.apply(null, args); |
} |
// Dispatches this event object to all listeners, passing all supplied |
// arguments to this function each listener. |
- chrome.Event.prototype.dispatch = function(varargs) { |
+ Event.prototype.dispatch = function(varargs) { |
return this.dispatch_(Array.prototype.slice.call(arguments), undefined); |
}; |
// Detaches this event object from its name. |
- chrome.Event.prototype.detach_ = function() { |
+ Event.prototype.detach_ = function() { |
this.attachmentStrategy_.detach(false); |
}; |
- chrome.Event.prototype.destroy_ = function() { |
+ Event.prototype.destroy_ = function() { |
this.listeners_ = []; |
this.validateEventArgs_ = []; |
this.detach_(false); |
}; |
- chrome.Event.prototype.addRules = function(rules, opt_cb) { |
+ Event.prototype.addRules = function(rules, opt_cb) { |
if (!this.eventOptions_.supportsRules) |
throw new Error("This event does not support rules."); |
@@ -457,7 +458,7 @@ |
ruleFunctionSchemas.addRules.parameters); |
} |
- chrome.Event.prototype.removeRules = function(ruleIdentifiers, opt_cb) { |
+ Event.prototype.removeRules = function(ruleIdentifiers, opt_cb) { |
if (!this.eventOptions_.supportsRules) |
throw new Error("This event does not support rules."); |
ensureRuleSchemasLoaded(); |
@@ -470,7 +471,7 @@ |
ruleFunctionSchemas.removeRules.parameters); |
} |
- chrome.Event.prototype.getRules = function(ruleIdentifiers, cb) { |
+ Event.prototype.getRules = function(ruleIdentifiers, cb) { |
if (!this.eventOptions_.supportsRules) |
throw new Error("This event does not support rules."); |
ensureRuleSchemasLoaded(); |
@@ -487,8 +488,8 @@ |
// Special load events: we don't use the DOM unload because that slows |
// down tab shutdown. On the other hand, onUnload might not always fire, |
// since Chrome will terminate renderers on shutdown (SuddenTermination). |
- chromeHidden.onLoad = new chrome.Event(); |
- chromeHidden.onUnload = new chrome.Event(); |
+ chromeHidden.onLoad = new Event(); |
+ chromeHidden.onUnload = new Event(); |
chromeHidden.dispatchOnLoad = |
chromeHidden.onLoad.dispatch.bind(chromeHidden.onLoad); |
@@ -506,4 +507,4 @@ |
console.error(msg); |
}; |
- exports.Event = chrome.Event; |
+ chrome.Event = Event; |