summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-02 20:46:37 +0000
committerjochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-02 20:46:37 +0000
commit96e867d99f62bc1d34fee7c1df0b3602acea4862 (patch)
treee2f076d2758b5e05831af7fcfd32ce88e8abdf01
parent22bc912e8ead4576e8fff27d49da8d75fd6802eb (diff)
downloadchromium_src-96e867d99f62bc1d34fee7c1df0b3602acea4862.zip
chromium_src-96e867d99f62bc1d34fee7c1df0b3602acea4862.tar.gz
chromium_src-96e867d99f62bc1d34fee7c1df0b3602acea4862.tar.bz2
Add hasListener/hasListeners to webRequestEvents
BUG=none TEST=ExtensionApiTest.WebRequestEvents Review URL: http://codereview.chromium.org/7542010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@95151 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/renderer/resources/extension_process_bindings.js10
-rw-r--r--chrome/test/data/extensions/api_test/webrequest/events/test.html2
2 files changed, 11 insertions, 1 deletions
diff --git a/chrome/renderer/resources/extension_process_bindings.js b/chrome/renderer/resources/extension_process_bindings.js
index 98e31cb..b2d10ff 100644
--- a/chrome/renderer/resources/extension_process_bindings.js
+++ b/chrome/renderer/resources/extension_process_bindings.js
@@ -274,6 +274,16 @@ var chrome = chrome || {};
this.callbackMap_ = {};
};
+ // Test if the given callback is registered for this event.
+ chrome.WebRequestEvent.prototype.hasListener = function(cb) {
+ return this.findListener_(cb) > -1;
+ };
+
+ // Test if any callbacks are registered fur thus event.
+ chrome.WebRequestEvent.prototype.hasListeners = function(cb) {
+ return this.subEvents_.length > 0;
+ };
+
// Registers a callback to be called when this event is dispatched. If
// opt_filter is specified, then the callback is only called for events that
// match the given filters. If opt_extraInfo is specified, the given optional
diff --git a/chrome/test/data/extensions/api_test/webrequest/events/test.html b/chrome/test/data/extensions/api_test/webrequest/events/test.html
index 2a35531..181acda 100644
--- a/chrome/test/data/extensions/api_test/webrequest/events/test.html
+++ b/chrome/test/data/extensions/api_test/webrequest/events/test.html
@@ -226,7 +226,7 @@ function removeListeners() {
for (var cb in event.callbackMap_) {
event.removeListener(cb);
}
- chrome.test.assertEq(0, event.subEvents_.length);
+ chrome.test.assertFalse(event.hasListeners());
}
helper(chrome.experimental.webRequest.onBeforeRequest);
helper(chrome.experimental.webRequest.onBeforeSendHeaders);