Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1454)

Unified Diff: chrome/renderer/resources/extensions/web_request_custom_bindings.js

Issue 9192029: Bindings layer for declarative events API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Continued Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..0c1ee2220013b957746ef9e3ef918d9b760ac939 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 ||
+ {"supportsListeners": true, "supportsRules": false};
Matt Perry 2012/01/24 22:39:10 indent 2 more
battre 2012/01/25 19:25:08 Done.
+
+ if (this.eventOptions_.supportsRules)
+ 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_.supportsListeners)
+ 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_.supportsListeners)
+ 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_.supportsListeners)
+ 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_.supportsListeners)
+ throw new Error("This event does not support listeners.");
var idx;
while ((idx = this.findListener_(cb)) >= 0) {
var e = this.subEvents_[idx];
@@ -115,9 +131,27 @@ WebRequestEvent.prototype.findListener_ = function(cb) {
return -1;
};
-chromeHidden.registerCustomEvent('webRequest', WebRequestEvent);
+WebRequestEvent.prototype.addRules = function(rules, opt_cb) {
+ if (!this.eventOptions_.supportsRules)
+ throw new Error("This event does not support listeners.");
Matt Perry 2012/01/24 22:39:10 s/listeners/rules
battre 2012/01/25 19:25:08 Done.
+ this.eventForRules_.addRules(rules, opt_cb);
+}
+
+WebRequestEvent.prototype.removeRules = function(rule_identifiers, opt_cb) {
+ if (!this.eventOptions_.supportsRules)
+ throw new Error("This event does not support listeners.");
+ this.eventForRules_.removeRules(rule_identifiers, opt_cb);
+}
+
+WebRequestEvent.prototype.getRules = function(rule_identifiers, cb) {
+ if (!this.eventOptions_.supportsRules)
+ throw new Error("This event does not support listeners.");
+ this.eventForRules_.getRules(rule_identifiers, cb);
+}
+
+chromeHidden.registerCustomEvent("webRequest", WebRequestEvent);
-chromeHidden.registerCustomHook('webRequest', function(api) {
+chromeHidden.registerCustomHook("webRequest", function(api) {
var apiFunctions = api.apiFunctions;
var sendRequest = api.sendRequest;

Powered by Google App Engine
This is Rietveld 408576698