Commit 6dca7844 authored by guohui's avatar guohui Committed by Commit bot

Enable webview tag in whitelisted webui pages, following the example of <extensionoptions>.

Only whitelisted webUIs could embed webview tag, specifically, they have to be declared in _api_features.json and they have to relax CSP to allow internal browser plugins.

BUG=

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

Cr-Commit-Position: refs/heads/master@{#296251}
parent e1eb0a2d
...@@ -25,6 +25,7 @@ content::WebUIDataSource* CreateWebUIDataSource() { ...@@ -25,6 +25,7 @@ content::WebUIDataSource* CreateWebUIDataSource() {
content::WebUIDataSource* source = content::WebUIDataSource* source =
content::WebUIDataSource::Create(chrome::kChromeUIChromeSigninHost); content::WebUIDataSource::Create(chrome::kChromeUIChromeSigninHost);
source->OverrideContentSecurityPolicyFrameSrc("frame-src chrome-extension:;"); source->OverrideContentSecurityPolicyFrameSrc("frame-src chrome-extension:;");
source->OverrideContentSecurityPolicyObjectSrc("object-src *;");
source->SetUseJsonJSFormatV2(); source->SetUseJsonJSFormatV2();
source->SetJsonPath("strings.js"); source->SetJsonPath("strings.js");
......
...@@ -193,11 +193,16 @@ ...@@ -193,11 +193,16 @@
"dependencies": ["permission:chromeosInfoPrivate"], "dependencies": ["permission:chromeosInfoPrivate"],
"contexts": ["blessed_extension"] "contexts": ["blessed_extension"]
}, },
"chromeWebViewInternal": { "chromeWebViewInternal": [{
"internal": true, "internal": true,
"dependencies": ["permission:webview"], "dependencies": ["permission:webview"],
"contexts": ["blessed_extension"] "contexts": ["blessed_extension"]
}, }, {
"internal": true,
"channel": "dev",
"contexts": ["webui"],
"matches": ["chrome://chrome-signin/*"]
}],
"cloudPrintPrivate": { "cloudPrintPrivate": {
"dependencies": ["permission:cloudPrintPrivate"], "dependencies": ["permission:cloudPrintPrivate"],
"contexts": ["blessed_extension"] "contexts": ["blessed_extension"]
...@@ -731,8 +736,8 @@ ...@@ -731,8 +736,8 @@
// webview uses webRequestInternal API. // webview uses webRequestInternal API.
"channel": "stable", "channel": "stable",
"internal": true, "internal": true,
"dependencies": ["permission:webview"], "contexts": ["webui"],
"contexts": ["unblessed_extension"] "matches": ["chrome://chrome-signin/*"]
}], }],
"webrtcAudioPrivate": { "webrtcAudioPrivate": {
"dependencies": ["permission:webrtcAudioPrivate"], "dependencies": ["permission:webrtcAudioPrivate"],
...@@ -765,10 +770,9 @@ ...@@ -765,10 +770,9 @@
"dependencies": ["permission:webview"], "dependencies": ["permission:webview"],
"contexts": ["blessed_extension"] "contexts": ["blessed_extension"]
}, { }, {
// Component extensions can use the webViewRequest API from iframes. "channel": "stable",
"location": "component", "contexts": ["webui"],
"dependencies": ["permission:webview"], "matches": ["chrome://chrome-signin/*"]
"contexts": ["unblessed_extension"]
}], }],
"webviewTag": { "webviewTag": {
"internal": true, "internal": true,
......
...@@ -143,6 +143,7 @@ int AppViewGuest::GetTaskPrefix() const { ...@@ -143,6 +143,7 @@ int AppViewGuest::GetTaskPrefix() const {
void AppViewGuest::CreateWebContents( void AppViewGuest::CreateWebContents(
const std::string& embedder_extension_id, const std::string& embedder_extension_id,
int embedder_render_process_id, int embedder_render_process_id,
const GURL& embedder_site_url,
const base::DictionaryValue& create_params, const base::DictionaryValue& create_params,
const WebContentsCreatedCallback& callback) { const WebContentsCreatedCallback& callback) {
std::string app_id; std::string app_id;
......
...@@ -51,6 +51,7 @@ class AppViewGuest : public GuestView<AppViewGuest>, ...@@ -51,6 +51,7 @@ class AppViewGuest : public GuestView<AppViewGuest>,
virtual void CreateWebContents( virtual void CreateWebContents(
const std::string& embedder_extension_id, const std::string& embedder_extension_id,
int embedder_render_process_id, int embedder_render_process_id,
const GURL& embedder_site_url,
const base::DictionaryValue& create_params, const base::DictionaryValue& create_params,
const WebContentsCreatedCallback& callback) OVERRIDE; const WebContentsCreatedCallback& callback) OVERRIDE;
virtual void DidAttachToEmbedder() OVERRIDE; virtual void DidAttachToEmbedder() OVERRIDE;
......
...@@ -59,6 +59,7 @@ extensions::GuestViewBase* ExtensionOptionsGuest::Create( ...@@ -59,6 +59,7 @@ extensions::GuestViewBase* ExtensionOptionsGuest::Create(
void ExtensionOptionsGuest::CreateWebContents( void ExtensionOptionsGuest::CreateWebContents(
const std::string& embedder_extension_id, const std::string& embedder_extension_id,
int embedder_render_process_id, int embedder_render_process_id,
const GURL& embedder_site_url,
const base::DictionaryValue& create_params, const base::DictionaryValue& create_params,
const WebContentsCreatedCallback& callback) { const WebContentsCreatedCallback& callback) {
// Get the extension's base URL. // Get the extension's base URL.
......
...@@ -30,6 +30,7 @@ class ExtensionOptionsGuest ...@@ -30,6 +30,7 @@ class ExtensionOptionsGuest
virtual void CreateWebContents( virtual void CreateWebContents(
const std::string& embedder_extension_id, const std::string& embedder_extension_id,
int embedder_render_process_id, int embedder_render_process_id,
const GURL& embedder_site_url,
const base::DictionaryValue& create_params, const base::DictionaryValue& create_params,
const WebContentsCreatedCallback& callback) OVERRIDE; const WebContentsCreatedCallback& callback) OVERRIDE;
virtual void DidAttachToEmbedder() OVERRIDE; virtual void DidAttachToEmbedder() OVERRIDE;
......
...@@ -136,11 +136,12 @@ void GuestViewBase::Init(const std::string& embedder_extension_id, ...@@ -136,11 +136,12 @@ void GuestViewBase::Init(const std::string& embedder_extension_id,
int embedder_process_id = int embedder_process_id =
embedder_web_contents->GetRenderProcessHost()->GetID(); embedder_web_contents->GetRenderProcessHost()->GetID();
const GURL& embedder_site_url = embedder_web_contents->GetLastCommittedURL();
Feature::Availability availability = feature->IsAvailableToContext( Feature::Availability availability = feature->IsAvailableToContext(
embedder_extension, embedder_extension,
process_map->GetMostLikelyContextType(embedder_extension, process_map->GetMostLikelyContextType(embedder_extension,
embedder_process_id), embedder_process_id),
embedder_web_contents->GetLastCommittedURL()); embedder_site_url);
if (!availability.is_available()) { if (!availability.is_available()) {
// The derived class did not create a WebContents so this class serves no // The derived class did not create a WebContents so this class serves no
// purpose. Let's self-destruct. // purpose. Let's self-destruct.
...@@ -151,6 +152,7 @@ void GuestViewBase::Init(const std::string& embedder_extension_id, ...@@ -151,6 +152,7 @@ void GuestViewBase::Init(const std::string& embedder_extension_id,
CreateWebContents(embedder_extension_id, CreateWebContents(embedder_extension_id,
embedder_process_id, embedder_process_id,
embedder_site_url,
create_params, create_params,
base::Bind(&GuestViewBase::CompleteInit, base::Bind(&GuestViewBase::CompleteInit,
AsWeakPtr(), AsWeakPtr(),
......
...@@ -160,6 +160,7 @@ class GuestViewBase : public content::BrowserPluginGuestDelegate, ...@@ -160,6 +160,7 @@ class GuestViewBase : public content::BrowserPluginGuestDelegate,
virtual void CreateWebContents( virtual void CreateWebContents(
const std::string& embedder_extension_id, const std::string& embedder_extension_id,
int embedder_render_process_id, int embedder_render_process_id,
const GURL& embedder_site_url,
const base::DictionaryValue& create_params, const base::DictionaryValue& create_params,
const WebContentsCreatedCallback& callback) = 0; const WebContentsCreatedCallback& callback) = 0;
......
...@@ -59,6 +59,7 @@ int MimeHandlerViewGuest::GetTaskPrefix() const { ...@@ -59,6 +59,7 @@ int MimeHandlerViewGuest::GetTaskPrefix() const {
void MimeHandlerViewGuest::CreateWebContents( void MimeHandlerViewGuest::CreateWebContents(
const std::string& embedder_extension_id, const std::string& embedder_extension_id,
int embedder_render_process_id, int embedder_render_process_id,
const GURL& embedder_site_url,
const base::DictionaryValue& create_params, const base::DictionaryValue& create_params,
const WebContentsCreatedCallback& callback) { const WebContentsCreatedCallback& callback) {
std::string orig_mime_type; std::string orig_mime_type;
......
...@@ -24,6 +24,7 @@ class MimeHandlerViewGuest : public GuestView<MimeHandlerViewGuest> { ...@@ -24,6 +24,7 @@ class MimeHandlerViewGuest : public GuestView<MimeHandlerViewGuest> {
virtual void CreateWebContents( virtual void CreateWebContents(
const std::string& embedder_extension_id, const std::string& embedder_extension_id,
int embedder_render_process_id, int embedder_render_process_id,
const GURL& embedder_site_url,
const base::DictionaryValue& create_params, const base::DictionaryValue& create_params,
const WebContentsCreatedCallback& callback) OVERRIDE; const WebContentsCreatedCallback& callback) OVERRIDE;
virtual void DidAttachToEmbedder() OVERRIDE; virtual void DidAttachToEmbedder() OVERRIDE;
......
...@@ -186,6 +186,7 @@ int WebViewGuest::GetTaskPrefix() const { ...@@ -186,6 +186,7 @@ int WebViewGuest::GetTaskPrefix() const {
void WebViewGuest::CreateWebContents( void WebViewGuest::CreateWebContents(
const std::string& embedder_extension_id, const std::string& embedder_extension_id,
int embedder_render_process_id, int embedder_render_process_id,
const GURL& embedder_site_url,
const base::DictionaryValue& create_params, const base::DictionaryValue& create_params,
const WebContentsCreatedCallback& callback) { const WebContentsCreatedCallback& callback) {
content::RenderProcessHost* embedder_render_process_host = content::RenderProcessHost* embedder_render_process_host =
...@@ -210,12 +211,20 @@ void WebViewGuest::CreateWebContents( ...@@ -210,12 +211,20 @@ void WebViewGuest::CreateWebContents(
std::string url_encoded_partition = net::EscapeQueryParamValue( std::string url_encoded_partition = net::EscapeQueryParamValue(
storage_partition_id, false); storage_partition_id, false);
// The SiteInstance of a given webview tag is based on the fact that it's // The SiteInstance of a given webview tag is based on the fact that it's
// a guest process in addition to which platform application the tag // a guest process in addition to which platform application or which WebUI
// belongs to and what storage partition is in use, rather than the URL // page the tag belongs to and what storage partition is in use, rather than
// that the tag is being navigated to. // the URL that the tag is being navigated to.
std::string partition_domain;
if (embedder_extension_id.empty()) {
DCHECK(content::ChildProcessSecurityPolicy::GetInstance()->HasWebUIBindings(
embedder_render_process_id));
partition_domain = embedder_site_url.host();
} else {
partition_domain = embedder_extension_id;
}
GURL guest_site(base::StringPrintf("%s://%s/%s?%s", GURL guest_site(base::StringPrintf("%s://%s/%s?%s",
content::kGuestScheme, content::kGuestScheme,
embedder_extension_id.c_str(), partition_domain.c_str(),
persist_storage ? "persist" : "", persist_storage ? "persist" : "",
url_encoded_partition.c_str())); url_encoded_partition.c_str()));
...@@ -760,7 +769,6 @@ void WebViewGuest::PushWebViewStateToIOThread() { ...@@ -760,7 +769,6 @@ void WebViewGuest::PushWebViewStateToIOThread() {
NOTREACHED(); NOTREACHED();
return; return;
} }
DCHECK(embedder_extension_id() == partition_domain);
WebViewRendererState::WebViewInfo web_view_info; WebViewRendererState::WebViewInfo web_view_info;
web_view_info.embedder_process_id = embedder_render_process_id(); web_view_info.embedder_process_id = embedder_render_process_id();
...@@ -1113,7 +1121,6 @@ void WebViewGuest::DestroyUnattachedWindows() { ...@@ -1113,7 +1121,6 @@ void WebViewGuest::DestroyUnattachedWindows() {
GURL WebViewGuest::ResolveURL(const std::string& src) { GURL WebViewGuest::ResolveURL(const std::string& src) {
if (!in_extension()) { if (!in_extension()) {
NOTREACHED();
return GURL(src); return GURL(src);
} }
......
...@@ -83,6 +83,7 @@ class WebViewGuest : public GuestView<WebViewGuest>, ...@@ -83,6 +83,7 @@ class WebViewGuest : public GuestView<WebViewGuest>,
virtual void CreateWebContents( virtual void CreateWebContents(
const std::string& embedder_extension_id, const std::string& embedder_extension_id,
int embedder_render_process_id, int embedder_render_process_id,
const GURL& embedder_site_url,
const base::DictionaryValue& create_params, const base::DictionaryValue& create_params,
const WebContentsCreatedCallback& callback) OVERRIDE; const WebContentsCreatedCallback& callback) OVERRIDE;
virtual void DidAttachToEmbedder() OVERRIDE; virtual void DidAttachToEmbedder() OVERRIDE;
......
...@@ -72,17 +72,15 @@ ...@@ -72,17 +72,15 @@
"internal": true, "internal": true,
"channel": "stable", "channel": "stable",
"contexts": ["blessed_extension"] "contexts": ["blessed_extension"]
}, {
// Component extensions can use the guestViewInternal API from iframes.
"location": "component",
"internal": true,
"dependencies": ["permission:webview"],
"contexts": ["unblessed_extension"]
}, { }, {
"internal": true, "internal": true,
"channel": "trunk", "channel": "trunk",
"contexts": ["webui"], "contexts": ["webui"],
"matches": ["chrome://extensions-frame/*", "chrome://extensions/*"] "matches": [
"chrome://extensions-frame/*",
"chrome://extensions/*",
"chrome://chrome-signin/*"
]
} }
], ],
"hid": { "hid": {
...@@ -252,10 +250,9 @@ ...@@ -252,10 +250,9 @@
"dependencies": ["permission:webview"], "dependencies": ["permission:webview"],
"contexts": ["blessed_extension"] "contexts": ["blessed_extension"]
}, { }, {
// Component extensions can use the webViewInternal API from iframes.
"location": "component",
"internal": true, "internal": true,
"dependencies": ["permission:webview"], "channel": "dev",
"contexts": ["unblessed_extension"] "contexts": ["webui"],
"matches": ["chrome://chrome-signin/*"]
}] }]
} }
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