| Index: chrome/renderer/resources/extensions/web_request_custom_bindings.js
|
| diff --git a/chrome/renderer/resources/extensions/web_request_custom_bindings.js b/chrome/renderer/resources/extensions/web_request_custom_bindings.js
|
| index 6d28188048d9e5a4169e6a439b51b9dbea1a58e2..4de01b96d77b909e418ddc5ad73c8b8370ba220a 100644
|
| --- a/chrome/renderer/resources/extensions/web_request_custom_bindings.js
|
| +++ b/chrome/renderer/resources/extensions/web_request_custom_bindings.js
|
| @@ -21,7 +21,8 @@ var chromeHidden = GetChromeHidden();
|
| // chrome.webRequest.onBeforeRequest.addListener(
|
| // callback, {urls: "http://*.google.com/*"});
|
| // ^ callback will only be called for onBeforeRequests matching the filter.
|
| -function WebRequestEvent(eventName, opt_argSchemas, opt_extraArgSchemas) {
|
| +function WebRequestEvent(eventName, opt_argSchemas, opt_extraArgSchemas,
|
| + opt_eventOptions, opt_typesAPI) {
|
| if (typeof eventName != "string")
|
| throw new Error("chrome.WebRequestEvent requires an event name.");
|
|
|
| @@ -29,15 +30,26 @@ function WebRequestEvent(eventName, opt_argSchemas, opt_extraArgSchemas) {
|
| this.argSchemas_ = opt_argSchemas;
|
| this.extraArgSchemas_ = opt_extraArgSchemas;
|
| this.subEvents_ = [];
|
| + this.eventOptions_ = opt_eventOptions ||
|
| + {'supports_listeners': true, 'supports_rules': false};
|
| +
|
| + if (this.eventOptions_.supports_rules)
|
| + this.eventForRules_ =
|
| + new chrome.Event(eventName, opt_argSchemas, opt_eventOptions,
|
| + opt_typesAPI);
|
| };
|
|
|
| // Test if the given callback is registered for this event.
|
| WebRequestEvent.prototype.hasListener = function(cb) {
|
| + if (!this.eventOptions_.supports_listeners)
|
| + throw new Error("This event does not support listeners.");
|
| return this.findListener_(cb) > -1;
|
| };
|
|
|
| // Test if any callbacks are registered fur thus event.
|
| WebRequestEvent.prototype.hasListeners = function() {
|
| + if (!this.eventOptions_.supports_listeners)
|
| + throw new Error("This event does not support listeners.");
|
| return this.subEvents_.length > 0;
|
| };
|
|
|
| @@ -47,6 +59,8 @@ WebRequestEvent.prototype.hasListeners = function() {
|
| // info is sent to the callback.
|
| WebRequestEvent.prototype.addListener =
|
| function(cb, opt_filter, opt_extraInfo) {
|
| + if (!this.eventOptions_.supports_listeners)
|
| + throw new Error("This event does not support listeners.");
|
| var subEventName = GetUniqueSubEventName(this.eventName_);
|
| // Note: this could fail to validate, in which case we would not add the
|
| // subEvent listener.
|
| @@ -90,6 +104,8 @@ WebRequestEvent.prototype.addListener =
|
|
|
| // Unregisters a callback.
|
| WebRequestEvent.prototype.removeListener = function(cb) {
|
| + if (!this.eventOptions_.supports_listeners)
|
| + throw new Error("This event does not support listeners.");
|
| var idx;
|
| while ((idx = this.findListener_(cb)) >= 0) {
|
| var e = this.subEvents_[idx];
|
| @@ -115,6 +131,24 @@ WebRequestEvent.prototype.findListener_ = function(cb) {
|
| return -1;
|
| };
|
|
|
| +WebRequestEvent.prototype.addRules = function(rules, opt_cb) {
|
| + if (!this.eventOptions_.supports_rules)
|
| + throw new Error("This event does not support listeners.");
|
| + this.eventForRules_.addRules(rules, opt_cb);
|
| +}
|
| +
|
| +WebRequestEvent.prototype.removeRules = function(cb) {
|
| + if (!this.eventOptions_.supports_rules)
|
| + throw new Error("This event does not support listeners.");
|
| + this.eventForRules_.removeRules(cb);
|
| +}
|
| +
|
| +WebRequestEvent.prototype.getRules = function(rule_identifiers, cb) {
|
| + if (!this.eventOptions_.supports_rules)
|
| + throw new Error("This event does not support listeners.");
|
| + this.eventForRules_.getRules(rule_identifiers, cb);
|
| +}
|
| +
|
| chromeHidden.registerCustomEvent('webRequest', WebRequestEvent);
|
|
|
| chromeHidden.registerCustomHook('webRequest', function(api) {
|
|
|