Commit 7a2efa4e authored by vabr@chromium.org's avatar vabr@chromium.org

Making webRequest.addEventListener internal

Changes required to hide addEventListener,
moving it from webRequest to webRequestInternal.

BUG=115467
TEST=loading extensions from the ticket 115467 and observing the behaviour

Review URL: https://chromiumcodereview.appspot.com/10310028

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@138481 0039d316-1c4b-4281-b951-d872f2087c98
parent 408bb829
......@@ -377,7 +377,7 @@ class ExtensionWebRequestEventRouter {
class WebRequestAddEventListener : public SyncIOThreadExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION_NAME("webRequest.addEventListener");
DECLARE_EXTENSION_FUNCTION_NAME("webRequestInternal.addEventListener");
protected:
virtual ~WebRequestAddEventListener() {}
......@@ -388,7 +388,7 @@ class WebRequestAddEventListener : public SyncIOThreadExtensionFunction {
class WebRequestEventHandled : public SyncIOThreadExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION_NAME("webRequest.eventHandled");
DECLARE_EXTENSION_FUNCTION_NAME("webRequestInternal.eventHandled");
protected:
virtual ~WebRequestEventHandled() {}
......
......@@ -445,6 +445,8 @@ void ExtensionAPI::InitDefaultConfiguration() {
IDR_EXTENSION_API_JSON_WEBNAVIGATION));
RegisterSchema("webRequest", ReadFromResource(
IDR_EXTENSION_API_JSON_WEBREQUEST));
RegisterSchema("webRequestInternal", ReadFromResource(
IDR_EXTENSION_API_JSON_WEBREQUESTINTERNAL));
RegisterSchema("webSocketProxyPrivate", ReadFromResource(
IDR_EXTENSION_API_JSON_WEBSOCKETPROXYPRIVATE));
RegisterSchema("webstore", ReadFromResource(
......
......@@ -82,48 +82,6 @@
}
],
"functions": [
{
"name": "addEventListener",
"nodoc": true,
"type": "function",
"description": "Used internally to implement the special form of addListener for the webRequest events.",
"parameters": [
{"type": "function", "name": "callback"},
{
"$ref": "RequestFilter",
"name": "filter",
"description": "A set of filters that restricts the events that will be sent to this listener."
},
{
"type": "array",
"optional": true,
"name": "extraInfoSpec",
"description": "Array of extra information that should be passed to the listener function.",
"items": {
"type": "string",
"enum": ["requestHeaders", "responseHeaders", "blocking", "asyncBlocking"]
}
},
{"type": "string", "name": "eventName"},
{"type": "string", "name": "subEventName"}
]
},
{
"name": "eventHandled",
"nodoc": true,
"type": "function",
"description": "Used internally to send a response for a blocked event.",
"parameters": [
{"type": "string", "name": "eventName"},
{"type": "string", "name": "subEventName"},
{"type": "string", "name": "requestId"},
{
"$ref": "BlockingResponse",
"optional": true,
"name": "response"
}
]
},
{
"name": "handlerBehaviorChanged",
"type": "function",
......
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
[
{
"namespace": "webRequestInternal",
"nodoc": true,
"internal": true,
"functions": [
{
"name": "addEventListener",
"type": "function",
"description": "Used internally to implement the special form of addListener for the webRequest events.",
"parameters": [
{"type": "function", "name": "callback"},
{
"$ref": "webRequest.RequestFilter",
"name": "filter",
"description": "A set of filters that restricts the events that will be sent to this listener."
},
{
"type": "array",
"optional": true,
"name": "extraInfoSpec",
"description": "Array of extra information that should be passed to the listener function.",
"items": {
"type": "string",
"enum": ["requestHeaders", "responseHeaders", "blocking", "asyncBlocking"]
}
},
{"type": "string", "name": "eventName"},
{"type": "string", "name": "subEventName"}
]
},
{
"name": "eventHandled",
"type": "function",
"description": "Used internally to send a response for a blocked event.",
"parameters": [
{"type": "string", "name": "eventName"},
{"type": "string", "name": "subEventName"},
{"type": "string", "name": "requestId"},
{
"$ref": "webRequest.BlockingResponse",
"optional": true,
"name": "response"
}
]
}
]
}
]
......@@ -323,6 +323,9 @@ void ExtensionAPIPermission::RegisterAllPermissions(
info->RegisterPermission(
kTerminalPrivate, "terminalPrivate", 0, ExtensionPermissionMessage::kNone,
kFlagCannotBeOptional);
info->RegisterPermission(
kWebRequestInternal, "webRequestInternal", 0,
ExtensionPermissionMessage::kNone, kFlagCannotBeOptional);
info->RegisterPermission(
kWebSocketProxyPrivate, "webSocketProxyPrivate", 0,
ExtensionPermissionMessage::kNone,
......@@ -877,6 +880,10 @@ void ExtensionPermissionSet::InitImplicitExtensionPermissions(
if (!extension->devtools_url().is_empty())
apis_.insert(ExtensionAPIPermission::kDevtools);
// The webRequest permission implies the internal version as well.
if (apis_.find(ExtensionAPIPermission::kWebRequest) != apis_.end())
apis_.insert(ExtensionAPIPermission::kWebRequestInternal);
// Add the scriptable hosts.
for (UserScriptList::const_iterator content_script =
extension->content_scripts().begin();
......
......@@ -145,6 +145,7 @@ class ExtensionAPIPermission {
kWebNavigation,
kWebRequest,
kWebRequestBlocking,
kWebRequestInternal,
kWebSocketProxyPrivate,
kWebstorePrivate,
kEnumBoundary
......
......@@ -612,6 +612,7 @@ TEST(ExtensionPermissionsTest, PermissionMessages) {
skip.insert(ExtensionAPIPermission::kEchoPrivate);
skip.insert(ExtensionAPIPermission::kSystemPrivate);
skip.insert(ExtensionAPIPermission::kTerminalPrivate);
skip.insert(ExtensionAPIPermission::kWebRequestInternal);
skip.insert(ExtensionAPIPermission::kWebSocketProxyPrivate);
skip.insert(ExtensionAPIPermission::kWebstorePrivate);
......
......@@ -70,6 +70,7 @@
<include name="IDR_EXTENSION_API_JSON_WEBNAVIGATION" file="extensions\api\web_navigation.json" type="BINDATA" />
<include name="IDR_EXTENSION_API_JSON_WEBREQUEST" file="extensions\api\web_request.json" type="BINDATA" />
<include name="IDR_EXTENSION_API_JSON_WEBSOCKETPROXYPRIVATE" file="extensions\api\web_socket_proxy_private.json" type="BINDATA" />
<include name="IDR_EXTENSION_API_JSON_WEBREQUESTINTERNAL" file="extensions\api\web_request_internal.json" type="BINDATA" />
<include name="IDR_EXTENSION_API_JSON_WEBSTORE" file="extensions\api\webstore.json" type="BINDATA" />
<include name="IDR_EXTENSION_API_JSON_WEBSTOREPRIVATE" file="extensions\api\webstore_private.json" type="BINDATA" />
<include name="IDR_EXTENSION_API_JSON_WINDOWS" file="extensions\api\windows.json" type="BINDATA" />
......
......@@ -573,6 +573,8 @@ void ExtensionDispatcher::PopulateSourceMap() {
source_map_.RegisterSource("ttsEngine", IDR_TTS_ENGINE_CUSTOM_BINDINGS_JS);
source_map_.RegisterSource("types", IDR_TYPES_CUSTOM_BINDINGS_JS);
source_map_.RegisterSource("webRequest", IDR_WEB_REQUEST_CUSTOM_BINDINGS_JS);
source_map_.RegisterSource("webRequestInternal",
IDR_WEB_REQUEST_INTERNAL_CUSTOM_BINDINGS_JS);
source_map_.RegisterSource("webstore", IDR_WEBSTORE_CUSTOM_BINDINGS_JS);
}
......
......@@ -61,6 +61,7 @@ without changes to the corresponding grd file. fb9 -->
<include name="IDR_TTS_ENGINE_CUSTOM_BINDINGS_JS" file="resources\extensions\tts_engine_custom_bindings.js" type="BINDATA" />
<include name="IDR_TYPES_CUSTOM_BINDINGS_JS" file="resources\extensions\types_custom_bindings.js" type="BINDATA" />
<include name="IDR_WEB_REQUEST_CUSTOM_BINDINGS_JS" file="resources\extensions\web_request_custom_bindings.js" type="BINDATA" />
<include name="IDR_WEB_REQUEST_INTERNAL_CUSTOM_BINDINGS_JS" file="resources\extensions\web_request_internal_custom_bindings.js" type="BINDATA" />
<include name="IDR_WEBSTORE_CUSTOM_BINDINGS_JS" file="resources\extensions\webstore_custom_bindings.js" type="BINDATA" />
</if>
</includes>
......
......@@ -65,7 +65,7 @@ WebRequestEvent.prototype.addListener =
// subEvent listener.
chromeHidden.validate(Array.prototype.slice.call(arguments, 1),
this.extraArgSchemas_);
chrome.webRequest.addEventListener(
chromeHidden.internalAPIs.webRequestInternal.addEventListener(
cb, opt_filter, opt_extraInfo, this.eventName_, subEventName);
var subEvent = new chrome.Event(subEventName, this.argSchemas_);
......@@ -76,10 +76,10 @@ WebRequestEvent.prototype.addListener =
var requestId = arguments[0].requestId;
try {
var result = cb.apply(null, arguments);
chrome.webRequest.eventHandled(
chromeHidden.internalAPIs.webRequestInternal.eventHandled(
eventName, subEventName, requestId, result);
} catch (e) {
chrome.webRequest.eventHandled(
chromeHidden.internalAPIs.webRequestInternal.eventHandled(
eventName, subEventName, requestId);
throw e;
}
......@@ -90,7 +90,7 @@ WebRequestEvent.prototype.addListener =
var details = arguments[0];
var requestId = details.requestId;
var handledCallback = function(response) {
chrome.webRequest.eventHandled(
chromeHidden.internalAPIs.webRequestInternal.eventHandled(
eventName, subEventName, requestId, response);
};
cb.apply(null, [details, handledCallback]);
......@@ -153,18 +153,6 @@ chromeHidden.registerCustomEvent('webRequest', WebRequestEvent);
chromeHidden.registerCustomHook('webRequest', function(api) {
var apiFunctions = api.apiFunctions;
apiFunctions.setHandleRequest('addEventListener', function() {
var args = Array.prototype.slice.call(arguments);
sendRequest(this.name, args, this.definition.parameters,
{forIOThread: true});
});
apiFunctions.setHandleRequest('eventHandled', function() {
var args = Array.prototype.slice.call(arguments);
sendRequest(this.name, args, this.definition.parameters,
{forIOThread: true});
});
apiFunctions.setHandleRequest('handlerBehaviorChanged', function() {
var args = Array.prototype.slice.call(arguments);
sendRequest(this.name, args, this.definition.parameters,
......
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Custom bindings for the webRequestInternal API.
var chromeHidden = requireNative('chrome_hidden').GetChromeHidden();
var sendRequest = require('sendRequest').sendRequest;
chromeHidden.registerCustomHook('webRequestInternal', function(api) {
var apiFunctions = api.apiFunctions;
apiFunctions.setHandleRequest('addEventListener', function() {
var args = Array.prototype.slice.call(arguments);
sendRequest(this.name, args, this.definition.parameters,
{forIOThread: true});
});
apiFunctions.setHandleRequest('eventHandled', function() {
var args = Array.prototype.slice.call(arguments);
sendRequest(this.name, args, this.definition.parameters,
{forIOThread: true});
});
});
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment