Skip to content

Commit

Permalink
Several things are done in this CL:
Browse files Browse the repository at this point in the history
- Update _api_features.json and _permissions.json to allow the following features in extensions:
 - declarativeWebrequest,
 - events
 - webRequest
 - webViewRequest

- Move web_view_request_custom_bindings.js and web_view_request.json to extensions.

- Remove ExtensionsAPIClient::GetRuleRegistry() since RuleRegisteryService has been moved to extension.

- Clean up extensions/extensions.gyp.

TBR=sky@chromium.org
BUG=352293

Committed: https://crrev.com/4499156f5a5784eee9e0dc021f13b4ea0fd7d0d2
Cr-Commit-Position: refs/heads/master@{#297413}

Review URL: https://codereview.chromium.org/596003002

Cr-Commit-Position: refs/heads/master@{#297532}
  • Loading branch information
hanxi authored and Commit bot committed Sep 30, 2014
1 parent a3e007d commit c93416a
Show file tree
Hide file tree
Showing 35 changed files with 200 additions and 235 deletions.
3 changes: 0 additions & 3 deletions chrome/app/generated_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -4474,9 +4474,6 @@ Make sure you do not expose any sensitive information.
<message name="IDS_EXTENSION_PROMPT_WARNING_DESKTOP_CAPTURE" desc="Permission string for Desktop Capture API.">
Capture content of your screen
</message>
<message name="IDS_EXTENSION_PROMPT_WARNING_DECLARATIVE_WEB_REQUEST" desc="Permission string for Declarative Web Request API.">
Block parts of web pages
</message>
<message name="IDS_EXTENSION_PROMPT_WARNING_BLUETOOTH_PRIVATE" desc="Permission string for Bluetooth Private API.">
Control Bluetooth adapter state and pairing
</message>
Expand Down
9 changes: 0 additions & 9 deletions chrome/browser/extensions/api/chrome_extensions_api_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#include "chrome/browser/guest_view/web_view/chrome_web_view_permission_helper_delegate.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
#include "extensions/browser/api/declarative/rules_registry_service.h"
#include "extensions/browser/guest_view/web_view/web_view_guest.h"
#include "extensions/browser/guest_view/web_view/web_view_permission_helper.h"

Expand Down Expand Up @@ -75,14 +74,6 @@ WebViewPermissionHelperDelegate* ChromeExtensionsAPIClient::
return new ChromeWebViewPermissionHelperDelegate(web_view_permission_helper);
}

scoped_refptr<RulesRegistry> ChromeExtensionsAPIClient::GetRulesRegistry(
content::BrowserContext* browser_context,
const RulesRegistry::WebViewKey& webview_key,
const std::string& event_name) {
return RulesRegistryService::Get(browser_context)->
GetRulesRegistry(webview_key, event_name);
}

WebRequestEventRouterDelegate*
ChromeExtensionsAPIClient::CreateWebRequestEventRouterDelegate() const {
return new ChromeExtensionWebRequestEventRouterDelegate();
Expand Down
4 changes: 0 additions & 4 deletions chrome/browser/extensions/api/chrome_extensions_api_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ class ChromeExtensionsAPIClient : public ExtensionsAPIClient {
virtual WebViewPermissionHelperDelegate*
CreateWebViewPermissionHelperDelegate(
WebViewPermissionHelper* web_view_permission_helper) const OVERRIDE;
virtual scoped_refptr<RulesRegistry> GetRulesRegistry(
content::BrowserContext* browser_context,
const RulesRegistry::WebViewKey& webview_key,
const std::string& event_name) OVERRIDE;
virtual WebRequestEventRouterDelegate* CreateWebRequestEventRouterDelegate()
const OVERRIDE;
virtual scoped_refptr<ContentRulesRegistry> CreateContentRulesRegistry(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,6 @@
#endif // defined(ENABLE_FULL_PRINTING)
#endif // defined(ENABLE_PRINTING)

void RemoveWebViewEventListenersOnIOThread(
void* profile,
const std::string& extension_id,
int embedder_process_id,
int view_instance_id) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
ExtensionWebRequestEventRouter::GetInstance()->RemoveWebViewEventListeners(
profile,
extension_id,
embedder_process_id,
view_instance_id);
}

ChromeWebViewGuestDelegate::ChromeWebViewGuestDelegate(
extensions::WebViewGuest* web_view_guest)
: pending_context_menu_request_id_(0),
Expand Down Expand Up @@ -104,25 +91,6 @@ void ChromeWebViewGuestDelegate::OnAttachWebViewHelpers(
new ChromePDFWebContentsHelperClient()));
}

void ChromeWebViewGuestDelegate::OnEmbedderDestroyed() {
// TODO(fsamuel): WebRequest event listeners for <webview> should survive
// reparenting of a <webview> within a single embedder. Right now, we keep
// around the browser state for the listener for the lifetime of the embedder.
// Ideally, the lifetime of the listeners should match the lifetime of the
// <webview> DOM node. Once http://crbug.com/156219 is resolved we can move
// the call to RemoveWebViewEventListenersOnIOThread back to
// WebViewGuest::WebContentsDestroyed.
content::BrowserThread::PostTask(
content::BrowserThread::IO,
FROM_HERE,
base::Bind(
&RemoveWebViewEventListenersOnIOThread,
web_view_guest()->browser_context(),
web_view_guest()->embedder_extension_id(),
web_view_guest()->embedder_render_process_id(),
web_view_guest()->view_instance_id()));
}

void ChromeWebViewGuestDelegate::OnDidAttachToEmbedder() {
// TODO(fsamuel): This code should be implemented in GuestViewBase once the
// ZoomController moves to the extensions module.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class ChromeWebViewGuestDelegate : public extensions::WebViewGuestDelegate,
virtual bool HandleContextMenu(
const content::ContextMenuParams& params) OVERRIDE;
virtual void OnAttachWebViewHelpers(content::WebContents* contents) OVERRIDE;
virtual void OnEmbedderDestroyed() OVERRIDE;
virtual void OnDidAttachToEmbedder() OVERRIDE;
virtual void OnDidCommitProvisionalLoadForFrame(bool is_main_frame) OVERRIDE;
virtual void OnDidInitialize() OVERRIDE;
Expand Down
3 changes: 0 additions & 3 deletions chrome/chrome_renderer.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,6 @@
'renderer/resources/extensions/system_indicator_custom_bindings.js',
'renderer/resources/extensions/tts_custom_bindings.js',
'renderer/resources/extensions/tts_engine_custom_bindings.js',
'renderer/resources/extensions/web_view.js',
'renderer/resources/extensions/web_view_events.js',
'renderer/resources/extensions/web_view_experimental.js',
],
'chrome_renderer_non_android_sources': [
'renderer/prerender/prerender_media_load_deferrer.cc',
Expand Down
34 changes: 0 additions & 34 deletions chrome/common/extensions/api/_api_features.json
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,6 @@
"dependencies": ["permission:declarativeContent"],
"contexts": ["blessed_extension"]
},
"declarativeWebRequest": {
"dependencies": ["permission:declarativeWebRequest"],
"contexts": ["blessed_extension"]
},
"desktopCapture": {
"dependencies": ["permission:desktopCapture"],
"contexts": ["blessed_extension"]
Expand Down Expand Up @@ -313,13 +309,6 @@
"dependencies": ["permission:enterprise.platformKeysPrivate"],
"contexts": ["blessed_extension"]
},
"events": {
"internal": true,
"channel": "stable",
"extension_types": ["platform_app", "extension"],
"contexts": "all",
"matches": ["<all_urls>"]
},
"experienceSamplingPrivate": {
"dependencies": ["permission:experienceSamplingPrivate"],
"contexts": ["blessed_extension"]
Expand Down Expand Up @@ -726,21 +715,6 @@
"dependencies": ["permission:webNavigation"],
"contexts": ["blessed_extension"]
},
"webRequest": {
"dependencies": ["permission:webRequest"],
"contexts": ["blessed_extension"]
},
"webRequestInternal": [{
"internal": true,
"channel": "stable",
"contexts": ["blessed_extension"]
}, {
// webview uses webRequestInternal API.
"channel": "stable",
"internal": true,
"contexts": ["webui"],
"matches": ["chrome://chrome-signin/*"]
}],
"webrtcAudioPrivate": {
"dependencies": ["permission:webrtcAudioPrivate"],
"contexts": ["blessed_extension"]
Expand Down Expand Up @@ -768,14 +742,6 @@
// given the blessed_extension denomination. Confusing.
"contexts": ["blessed_extension"]
},
"webViewRequest": [{
"dependencies": ["permission:webview"],
"contexts": ["blessed_extension"]
}, {
"channel": "stable",
"contexts": ["webui"],
"matches": ["chrome://chrome-signin/*"]
}],
"webviewTag": {
"internal": true,
"channel": "stable",
Expand Down
14 changes: 0 additions & 14 deletions chrome/common/extensions/api/_permission_features.json
Original file line number Diff line number Diff line change
Expand Up @@ -329,12 +329,6 @@
"channel": "stable",
"extension_types": ["extension"]
},
"declarativeWebRequest": [
{
"channel": "beta",
"extension_types": ["extension", "legacy_packaged_app"]
}
],
"desktopCapture": {
"channel": "stable",
"extension_types": ["extension", "platform_app"]
Expand Down Expand Up @@ -1062,13 +1056,5 @@
"2653F6F6C39BC6EEBD36A09AFB92A19782FF7EB4", // Enterprise Web Store
"2779FA8B45841D61A37207CCFAC9CB393964FE5B" // Login Proxy (prototype)
]
},
"webRequest": {
"channel": "stable",
"extension_types": ["extension", "legacy_packaged_app"]
},
"webRequestBlocking": {
"channel": "stable",
"extension_types": ["extension", "legacy_packaged_app"]
}
}
4 changes: 0 additions & 4 deletions chrome/common/extensions/chrome_extensions_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,6 @@ void ChromeExtensionsClient::RegisterAPISchemaResources(
api->RegisterSchemaResource("commands", IDR_EXTENSION_API_JSON_COMMANDS);
api->RegisterSchemaResource("declarativeContent",
IDR_EXTENSION_API_JSON_DECLARATIVE_CONTENT);
api->RegisterSchemaResource("declarativeWebRequest",
IDR_EXTENSION_API_JSON_DECLARATIVE_WEBREQUEST);
api->RegisterSchemaResource("fileBrowserHandler",
IDR_EXTENSION_API_JSON_FILEBROWSERHANDLER);
api->RegisterSchemaResource("inputMethodPrivate",
Expand All @@ -285,8 +283,6 @@ void ChromeExtensionsClient::RegisterAPISchemaResources(
api->RegisterSchemaResource("types.private",
IDR_EXTENSION_API_JSON_TYPES_PRIVATE);
api->RegisterSchemaResource("webstore", IDR_EXTENSION_API_JSON_WEBSTORE);
api->RegisterSchemaResource("webViewRequest",
IDR_EXTENSION_API_JSON_WEB_VIEW_REQUEST);
#endif // defined(ENABLE_EXTENSIONS)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ std::vector<APIPermissionInfo*> ChromeAPIPermissions::GetAllPermissions()
PermissionMessage::kClipboard},
{APIPermission::kClipboardWrite, "clipboardWrite"},
{APIPermission::kDeclarativeContent, "declarativeContent"},
{APIPermission::kDeclarativeWebRequest, "declarativeWebRequest",
APIPermissionInfo::kFlagNone,
IDS_EXTENSION_PROMPT_WARNING_DECLARATIVE_WEB_REQUEST,
PermissionMessage::kDeclarativeWebRequest},
{APIPermission::kDesktopCapture, "desktopCapture",
APIPermissionInfo::kFlagNone,
IDS_EXTENSION_PROMPT_WARNING_DESKTOP_CAPTURE,
Expand Down Expand Up @@ -151,8 +147,6 @@ std::vector<APIPermissionInfo*> ChromeAPIPermissions::GetAllPermissions()
{APIPermission::kWebNavigation, "webNavigation",
APIPermissionInfo::kFlagNone, IDS_EXTENSION_PROMPT_WARNING_HISTORY_READ,
PermissionMessage::kTabs},
{APIPermission::kWebRequest, "webRequest"},
{APIPermission::kWebRequestBlocking, "webRequestBlocking"},

// Register private permissions.
{APIPermission::kScreenlockPrivate, "screenlockPrivate",
Expand Down
1 change: 0 additions & 1 deletion chrome/common/extensions_api_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
<include name="IDR_EXTENSION_API_JSON_TYPES" file="extensions\api\types.json" type="BINDATA" />
<include name="IDR_EXTENSION_API_JSON_TYPES_PRIVATE" file="extensions\api\types_private.json" type="BINDATA" />
<include name="IDR_EXTENSION_API_JSON_WEBSTORE" file="extensions\api\webstore.json" type="BINDATA" />
<include name="IDR_EXTENSION_API_JSON_WEB_VIEW_REQUEST" file="extensions\api\web_view_request.json" type="BINDATA" />
</includes>
</release>
</grit>
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,6 @@ void ChromeExtensionsDispatcherDelegate::PopulateSourceMap(
source_map->RegisterSource("chromeWebView", IDR_CHROME_WEB_VIEW_JS);
source_map->RegisterSource("chromeWebViewExperimental",
IDR_CHROME_WEB_VIEW_EXPERIMENTAL_JS);
source_map->RegisterSource("webViewRequest",
IDR_WEB_VIEW_REQUEST_CUSTOM_BINDINGS_JS);
source_map->RegisterSource("denyAppView", IDR_APP_VIEW_DENY_JS);
source_map->RegisterSource("injectAppTitlebar", IDR_INJECT_APP_TITLEBAR_JS);
}
Expand Down
91 changes: 0 additions & 91 deletions chrome/renderer/resources/extensions/chrome_web_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,9 @@

var ChromeWebView = require('chromeWebViewInternal').ChromeWebView;
var CreateEvent = require('webViewEvents').CreateEvent;
var DeclarativeWebRequestSchema =
requireNative('schema_registry').GetSchema('declarativeWebRequest');
var EventBindings = require('event_bindings');
var IdGenerator = requireNative('id_generator');
var WebRequestEvent = require('webRequestInternal').WebRequestEvent;
var WebRequestSchema =
requireNative('schema_registry').GetSchema('webRequest');
var WebViewInternal = require('webView').WebViewInternal

var WebRequestMessageEvent = CreateEvent('webViewInternal.onMessage');

var CHROME_WEB_VIEW_EVENTS = {
'contextmenu': {
evt: CreateEvent('chromeWebViewInternal.contextmenu'),
Expand All @@ -28,25 +20,6 @@ var CHROME_WEB_VIEW_EVENTS = {
}
};

function DeclarativeWebRequestEvent(opt_eventName,
opt_argSchemas,
opt_eventOptions,
opt_webViewInstanceId) {
var subEventName = opt_eventName + '/' + IdGenerator.GetNextId();
EventBindings.Event.call(this, subEventName, opt_argSchemas, opt_eventOptions,
opt_webViewInstanceId);

// TODO(lazyboy): When do we dispose this listener?
WebRequestMessageEvent.addListener(function() {
// Re-dispatch to subEvent's listeners.
$Function.apply(this.dispatch, this, $Array.slice(arguments));
}.bind(this), {instanceId: opt_webViewInstanceId || 0});
}

DeclarativeWebRequestEvent.prototype = {
__proto__: EventBindings.Event.prototype
};

/**
* Implemented when the ChromeWebView API is available.
* @private
Expand All @@ -68,67 +41,3 @@ WebViewInternal.prototype.maybeHandleContextMenu = function(e, webViewEvent) {
var params = undefined;
ChromeWebView.showContextMenu(this.guestInstanceId, requestId, params);
};

WebViewInternal.prototype.maybeSetupChromeWebViewEvents = function() {
var request = {};
var createWebRequestEvent = function(webRequestEvent) {
return function() {
if (!this[webRequestEvent.name]) {
this[webRequestEvent.name] =
new WebRequestEvent(
'webViewInternal.' + webRequestEvent.name,
webRequestEvent.parameters,
webRequestEvent.extraParameters, webRequestEvent.options,
this.viewInstanceId);
}
return this[webRequestEvent.name];
}.bind(this);
}.bind(this);

var createDeclarativeWebRequestEvent = function(webRequestEvent) {
return function() {
if (!this[webRequestEvent.name]) {
// The onMessage event gets a special event type because we want
// the listener to fire only for messages targeted for this particular
// <webview>.
var EventClass = webRequestEvent.name === 'onMessage' ?
DeclarativeWebRequestEvent : EventBindings.Event;
this[webRequestEvent.name] =
new EventClass(
'webViewInternal.' + webRequestEvent.name,
webRequestEvent.parameters,
webRequestEvent.options,
this.viewInstanceId);
}
return this[webRequestEvent.name];
}.bind(this);
}.bind(this);

for (var i = 0; i < DeclarativeWebRequestSchema.events.length; ++i) {
var eventSchema = DeclarativeWebRequestSchema.events[i];
var webRequestEvent = createDeclarativeWebRequestEvent(eventSchema);
Object.defineProperty(
request,
eventSchema.name,
{
get: webRequestEvent,
enumerable: true
}
);
}

// Populate the WebRequest events from the API definition.
for (var i = 0; i < WebRequestSchema.events.length; ++i) {
var webRequestEvent = createWebRequestEvent(WebRequestSchema.events[i]);
Object.defineProperty(
request,
WebRequestSchema.events[i].name,
{
get: webRequestEvent,
enumerable: true
}
);
}

this.setRequestPropertyOnWebViewNode(request);
};
1 change: 0 additions & 1 deletion chrome/renderer/resources/renderer_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@
<include name="IDR_TTS_CUSTOM_BINDINGS_JS" file="extensions\tts_custom_bindings.js" type="BINDATA" />
<include name="IDR_TTS_ENGINE_CUSTOM_BINDINGS_JS" file="extensions\tts_engine_custom_bindings.js" type="BINDATA" />
<include name="IDR_WEBSTORE_CUSTOM_BINDINGS_JS" file="extensions\webstore_custom_bindings.js" type="BINDATA" />
<include name="IDR_WEB_VIEW_REQUEST_CUSTOM_BINDINGS_JS" file="extensions\web_view_request_custom_bindings.js" type="BINDATA" />

<!-- Platform app support. -->
<include name="IDR_INJECT_APP_TITLEBAR_JS" file="extensions\inject_app_titlebar.js" type="BINDATA" />
Expand Down
5 changes: 3 additions & 2 deletions extensions/browser/api/declarative/declarative_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h"
#include "extensions/browser/api/declarative/rules_registry_service.h"
#include "extensions/browser/api/extensions_api_client.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/guest_view/web_view/web_view_constants.h"
Expand Down Expand Up @@ -153,8 +154,8 @@ bool RulesFunction::RunAsync() {

// The following call will return a NULL pointer for apps_shell, but should
// never be called there anyways.
rules_registry_ = ExtensionsAPIClient::Get()->GetRulesRegistry(
browser_context(), key, event_name);
rules_registry_ = RulesRegistryService::Get(browser_context())->
GetRulesRegistry(key, event_name);
DCHECK(rules_registry_.get());
// Raw access to this function is not available to extensions, therefore
// there should never be a request for a nonexisting rules registry.
Expand Down
Loading

0 comments on commit c93416a

Please sign in to comment.