diff options
Diffstat (limited to 'chrome/renderer/resources/extensions/event.js')
-rw-r--r-- | chrome/renderer/resources/extensions/event.js | 46 |
1 files changed, 22 insertions, 24 deletions
diff --git a/chrome/renderer/resources/extensions/event.js b/chrome/renderer/resources/extensions/event.js index 0ccd586..ac7574c 100644 --- a/chrome/renderer/resources/extensions/event.js +++ b/chrome/renderer/resources/extensions/event.js @@ -3,8 +3,6 @@ // found in the LICENSE file. var DCHECK = requireNative('logging').DCHECK; - // TODO(cduvall/kalman): json_schema shouldn't put things on chromeHidden. - require('json_schema'); var eventBindingsNatives = requireNative('event_bindings'); var AttachEvent = eventBindingsNatives.AttachEvent; var DetachEvent = eventBindingsNatives.DetachEvent; @@ -16,8 +14,8 @@ var validate = require('schemaUtils').validate; var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); - var chrome = requireNative('chrome').GetChrome(); - var schemaRegistry = requireNative('schema_registry'); + var GetExtensionAPIDefinition = + requireNative('apiDefinitions').GetExtensionAPIDefinition; // Schemas for the rule-style functions on the events API that // only need to be generated occasionally, so populate them lazily. @@ -32,7 +30,7 @@ function ensureRuleSchemasLoaded() { if (ruleFunctionSchemas.addRules) return; - var eventsSchema = schemaRegistry.GetSchema("events"); + var eventsSchema = GetExtensionAPIDefinition("events")[0]; var eventType = utils.lookup(eventsSchema.types, 'id', 'events.Event'); ruleFunctionSchemas.addRules = @@ -153,7 +151,7 @@ // // If opt_eventOptions exists, it is a dictionary that contains the boolean // entries "supportsListeners" and "supportsRules". - var Event = function(opt_eventName, opt_argSchemas, opt_eventOptions) { + chrome.Event = function(opt_eventName, opt_argSchemas, opt_eventOptions) { this.eventName_ = opt_eventName; this.listeners_ = []; this.eventOptions_ = chromeHidden.parseEventOptions(opt_eventOptions); @@ -228,7 +226,7 @@ }; // Registers a callback to be called when this event is dispatched. - Event.prototype.addListener = function(cb, filters) { + chrome.Event.prototype.addListener = function(cb, filters) { if (!this.eventOptions_.supportsListeners) throw new Error("This event does not support listeners."); if (this.eventOptions_.maxListeners && @@ -245,7 +243,7 @@ this.listeners_.push(listener); }; - Event.prototype.attach_ = function(listener) { + chrome.Event.prototype.attach_ = function(listener) { this.attachmentStrategy_.onAddedListener(listener); if (this.listeners_.length == 0) { allAttachedEvents[allAttachedEvents.length] = this; @@ -262,7 +260,7 @@ }; // Unregisters a callback. - Event.prototype.removeListener = function(cb) { + chrome.Event.prototype.removeListener = function(cb) { if (!this.eventOptions_.supportsListeners) throw new Error("This event does not support listeners."); var idx = this.findListener_(cb); @@ -290,19 +288,19 @@ }; // Test if the given callback is registered for this event. - Event.prototype.hasListener = function(cb) { + chrome.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. - Event.prototype.hasListeners = function() { + chrome.Event.prototype.hasListeners = function() { return this.getListenerCount() > 0; }; // Return the number of listeners on this event. - Event.prototype.getListenerCount = function() { + chrome.Event.prototype.getListenerCount = function() { if (!this.eventOptions_.supportsListeners) throw new Error("This event does not support listeners."); return this.listeners_.length; @@ -310,7 +308,7 @@ // Returns the index of the given callback if registered, or -1 if not // found. - Event.prototype.findListener_ = function(cb) { + chrome.Event.prototype.findListener_ = function(cb) { for (var i = 0; i < this.listeners_.length; i++) { if (this.listeners_[i].callback == cb) { return i; @@ -320,7 +318,7 @@ return -1; }; - Event.prototype.dispatch_ = function(args, listenerIDs) { + chrome.Event.prototype.dispatch_ = function(args, listenerIDs) { if (!this.eventOptions_.supportsListeners) throw new Error("This event does not support listeners."); var validationErrors = this.validateEventArgs_(args); @@ -350,28 +348,28 @@ } // Can be overridden to support custom dispatching. - Event.prototype.dispatchToListener = function(callback, args) { + chrome.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. - Event.prototype.dispatch = function(varargs) { + chrome.Event.prototype.dispatch = function(varargs) { return this.dispatch_(Array.prototype.slice.call(arguments), undefined); }; // Detaches this event object from its name. - Event.prototype.detach_ = function() { + chrome.Event.prototype.detach_ = function() { this.attachmentStrategy_.detach(false); }; - Event.prototype.destroy_ = function() { + chrome.Event.prototype.destroy_ = function() { this.listeners_ = []; this.validateEventArgs_ = []; this.detach_(false); }; - Event.prototype.addRules = function(rules, opt_cb) { + chrome.Event.prototype.addRules = function(rules, opt_cb) { if (!this.eventOptions_.supportsRules) throw new Error("This event does not support rules."); @@ -421,7 +419,7 @@ ruleFunctionSchemas.addRules.parameters); } - Event.prototype.removeRules = function(ruleIdentifiers, opt_cb) { + chrome.Event.prototype.removeRules = function(ruleIdentifiers, opt_cb) { if (!this.eventOptions_.supportsRules) throw new Error("This event does not support rules."); ensureRuleSchemasLoaded(); @@ -434,7 +432,7 @@ ruleFunctionSchemas.removeRules.parameters); } - Event.prototype.getRules = function(ruleIdentifiers, cb) { + chrome.Event.prototype.getRules = function(ruleIdentifiers, cb) { if (!this.eventOptions_.supportsRules) throw new Error("This event does not support rules."); ensureRuleSchemasLoaded(); @@ -451,8 +449,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 Event(); - chromeHidden.onUnload = new Event(); + chromeHidden.onLoad = new chrome.Event(); + chromeHidden.onUnload = new chrome.Event(); chromeHidden.dispatchOnLoad = chromeHidden.onLoad.dispatch.bind(chromeHidden.onLoad); @@ -472,4 +470,4 @@ console.error(msg); }; - chrome.Event = Event; + exports.Event = chrome.Event; |