Commit 840c1af1 authored by fsamuel's avatar fsamuel Committed by Commit bot

AppView: Fix owner_extension_id

Set the owner_extension_id in GuestViewBase::Init so that it's available in request.embedderExtensionId in onEmbedRequested in the app to be embedded. This also simplifies code in GuestViewBase a bit.

BUG=444749
TBR=rockot@chromium.org for guest_view_internal_api.cc

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

Cr-Commit-Position: refs/heads/master@{#309600}
parent 7bb1c5c7
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
// found in the LICENSE file. // found in the LICENSE file.
chrome.app.runtime.onEmbedRequested.addListener(function(request) { chrome.app.runtime.onEmbedRequested.addListener(function(request) {
if (!request.embedderId)
request.deny();
if (!request.data.foo) { if (!request.data.foo) {
request.allow('main.html'); request.allow('main.html');
return; return;
......
...@@ -39,14 +39,8 @@ bool GuestViewInternalCreateGuestFunction::RunAsync() { ...@@ -39,14 +39,8 @@ bool GuestViewInternalCreateGuestFunction::RunAsync() {
error_ = "Guest views can only be embedded in web content"; error_ = "Guest views can only be embedded in web content";
return false; return false;
} }
// If the guest is an <extensionoptions> to be embedded in a WebUI, then
// there is no extension, and extension() will be null. Use an empty string
// instead.
std::string embedder_extension_id =
extension() ? extension_id() : std::string();
guest_view_manager->CreateGuest(view_type, guest_view_manager->CreateGuest(view_type,
embedder_extension_id,
owner_web_contents, owner_web_contents,
*create_params, *create_params,
callback); callback);
......
...@@ -206,7 +206,6 @@ void ExtensionMessageFilter::OnExtensionCreateMimeHandlerViewGuest( ...@@ -206,7 +206,6 @@ void ExtensionMessageFilter::OnExtensionCreateMimeHandlerViewGuest(
create_params.SetString(mime_handler_view::kSrc, src); create_params.SetString(mime_handler_view::kSrc, src);
create_params.SetString(mime_handler_view::kContentUrl, content_url); create_params.SetString(mime_handler_view::kContentUrl, content_url);
manager->CreateGuest(MimeHandlerViewGuest::Type, manager->CreateGuest(MimeHandlerViewGuest::Type,
"",
embedder_web_contents, embedder_web_contents,
create_params, create_params,
callback); callback);
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include "extensions/browser/guest_view/mime_handler_view/mime_handler_view_guest.h" #include "extensions/browser/guest_view/mime_handler_view/mime_handler_view_guest.h"
#include "extensions/browser/guest_view/surface_worker/surface_worker_guest.h" #include "extensions/browser/guest_view/surface_worker/surface_worker_guest.h"
#include "extensions/browser/guest_view/web_view/web_view_guest.h" #include "extensions/browser/guest_view/web_view/web_view_guest.h"
#include "extensions/browser/process_manager.h"
#include "extensions/browser/process_map.h" #include "extensions/browser/process_map.h"
#include "extensions/common/extension_messages.h" #include "extensions/common/extension_messages.h"
#include "extensions/common/features/feature.h" #include "extensions/common/features/feature.h"
...@@ -150,8 +151,7 @@ GuestViewBase::GuestViewBase(content::BrowserContext* browser_context, ...@@ -150,8 +151,7 @@ GuestViewBase::GuestViewBase(content::BrowserContext* browser_context,
weak_ptr_factory_(this) { weak_ptr_factory_(this) {
} }
void GuestViewBase::Init(const std::string& owner_extension_id, void GuestViewBase::Init(const base::DictionaryValue& create_params,
const base::DictionaryValue& create_params,
const WebContentsCreatedCallback& callback) { const WebContentsCreatedCallback& callback) {
if (initialized_) if (initialized_)
return; return;
...@@ -163,15 +163,17 @@ void GuestViewBase::Init(const std::string& owner_extension_id, ...@@ -163,15 +163,17 @@ void GuestViewBase::Init(const std::string& owner_extension_id,
ProcessMap* process_map = ProcessMap::Get(browser_context()); ProcessMap* process_map = ProcessMap::Get(browser_context());
CHECK(process_map); CHECK(process_map);
const Extension* embedder_extension = ExtensionRegistry::Get(browser_context_) const Extension* owner_extension =
->enabled_extensions() ProcessManager::Get(owner_web_contents()->GetBrowserContext())->
.GetByID(owner_extension_id); GetExtensionForRenderViewHost(
owner_web_contents()->GetRenderViewHost());
owner_extension_id_ = owner_extension ? owner_extension->id() : std::string();
// Ok for |embedder_extension| to be NULL, the embedder might be WebUI. // Ok for |owner_extension| to be NULL, the embedder might be WebUI.
Feature::Availability availability = feature->IsAvailableToContext( Feature::Availability availability = feature->IsAvailableToContext(
embedder_extension, owner_extension,
process_map->GetMostLikelyContextType( process_map->GetMostLikelyContextType(
embedder_extension, owner_extension,
owner_web_contents()->GetRenderProcessHost()->GetID()), owner_web_contents()->GetRenderProcessHost()->GetID()),
GetOwnerSiteURL()); GetOwnerSiteURL());
if (!availability.is_available()) { if (!availability.is_available()) {
...@@ -185,17 +187,13 @@ void GuestViewBase::Init(const std::string& owner_extension_id, ...@@ -185,17 +187,13 @@ void GuestViewBase::Init(const std::string& owner_extension_id,
CreateWebContents(create_params, CreateWebContents(create_params,
base::Bind(&GuestViewBase::CompleteInit, base::Bind(&GuestViewBase::CompleteInit,
weak_ptr_factory_.GetWeakPtr(), weak_ptr_factory_.GetWeakPtr(),
owner_extension_id,
callback)); callback));
} }
void GuestViewBase::InitWithWebContents( void GuestViewBase::InitWithWebContents(
const std::string& owner_extension_id,
content::WebContents* guest_web_contents) { content::WebContents* guest_web_contents) {
DCHECK(guest_web_contents); DCHECK(guest_web_contents);
owner_extension_id_ = owner_extension_id;
// At this point, we have just created the guest WebContents, we need to add // At this point, we have just created the guest WebContents, we need to add
// an observer to the embedder WebContents. This observer will be responsible // an observer to the embedder WebContents. This observer will be responsible
// for destroying the guest WebContents if the embedder goes away. // for destroying the guest WebContents if the embedder goes away.
...@@ -542,8 +540,7 @@ void GuestViewBase::SendQueuedEvents() { ...@@ -542,8 +540,7 @@ void GuestViewBase::SendQueuedEvents() {
} }
} }
void GuestViewBase::CompleteInit(const std::string& owner_extension_id, void GuestViewBase::CompleteInit(const WebContentsCreatedCallback& callback,
const WebContentsCreatedCallback& callback,
content::WebContents* guest_web_contents) { content::WebContents* guest_web_contents) {
if (!guest_web_contents) { if (!guest_web_contents) {
// 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
...@@ -552,7 +549,7 @@ void GuestViewBase::CompleteInit(const std::string& owner_extension_id, ...@@ -552,7 +549,7 @@ void GuestViewBase::CompleteInit(const std::string& owner_extension_id,
callback.Run(NULL); callback.Run(NULL);
return; return;
} }
InitWithWebContents(owner_extension_id, guest_web_contents); InitWithWebContents(guest_web_contents);
callback.Run(guest_web_contents); callback.Run(guest_web_contents);
} }
......
...@@ -170,12 +170,10 @@ class GuestViewBase : public content::BrowserPluginGuestDelegate, ...@@ -170,12 +170,10 @@ class GuestViewBase : public content::BrowserPluginGuestDelegate,
// This creates a WebContents and initializes |this| GuestViewBase to use the // This creates a WebContents and initializes |this| GuestViewBase to use the
// newly created WebContents. // newly created WebContents.
void Init(const std::string& owner_extension_id, void Init(const base::DictionaryValue& create_params,
const base::DictionaryValue& create_params,
const WebContentsCreatedCallback& callback); const WebContentsCreatedCallback& callback);
void InitWithWebContents(const std::string& owner_extension_id, void InitWithWebContents(content::WebContents* guest_web_contents);
content::WebContents* guest_web_contents);
bool IsViewType(const char* const view_type) const { bool IsViewType(const char* const view_type) const {
return !strcmp(GetViewType(), view_type); return !strcmp(GetViewType(), view_type);
...@@ -276,8 +274,7 @@ class GuestViewBase : public content::BrowserPluginGuestDelegate, ...@@ -276,8 +274,7 @@ class GuestViewBase : public content::BrowserPluginGuestDelegate,
void SendQueuedEvents(); void SendQueuedEvents();
void CompleteInit(const std::string& owner_extension_id, void CompleteInit(const WebContentsCreatedCallback& callback,
const WebContentsCreatedCallback& callback,
content::WebContents* guest_web_contents); content::WebContents* guest_web_contents);
void StartTrackingEmbedderZoomLevel(); void StartTrackingEmbedderZoomLevel();
......
...@@ -140,7 +140,6 @@ int GuestViewManager::GetNextInstanceID() { ...@@ -140,7 +140,6 @@ int GuestViewManager::GetNextInstanceID() {
} }
void GuestViewManager::CreateGuest(const std::string& view_type, void GuestViewManager::CreateGuest(const std::string& view_type,
const std::string& owner_extension_id,
content::WebContents* owner_web_contents, content::WebContents* owner_web_contents,
const base::DictionaryValue& create_params, const base::DictionaryValue& create_params,
const WebContentsCreatedCallback& callback) { const WebContentsCreatedCallback& callback) {
...@@ -154,12 +153,11 @@ void GuestViewManager::CreateGuest(const std::string& view_type, ...@@ -154,12 +153,11 @@ void GuestViewManager::CreateGuest(const std::string& view_type,
callback.Run(NULL); callback.Run(NULL);
return; return;
} }
guest->Init(owner_extension_id, create_params, callback); guest->Init(create_params, callback);
} }
content::WebContents* GuestViewManager::CreateGuestWithWebContentsParams( content::WebContents* GuestViewManager::CreateGuestWithWebContentsParams(
const std::string& view_type, const std::string& view_type,
const std::string& owner_extension_id,
content::WebContents* owner_web_contents, content::WebContents* owner_web_contents,
const content::WebContents::CreateParams& create_params) { const content::WebContents::CreateParams& create_params) {
int guest_instance_id = GetNextInstanceID(); int guest_instance_id = GetNextInstanceID();
...@@ -174,7 +172,7 @@ content::WebContents* GuestViewManager::CreateGuestWithWebContentsParams( ...@@ -174,7 +172,7 @@ content::WebContents* GuestViewManager::CreateGuestWithWebContentsParams(
guest_create_params.guest_delegate = guest; guest_create_params.guest_delegate = guest;
content::WebContents* guest_web_contents = content::WebContents* guest_web_contents =
WebContents::Create(guest_create_params); WebContents::Create(guest_create_params);
guest->InitWithWebContents(owner_extension_id, guest_web_contents); guest->InitWithWebContents(guest_web_contents);
return guest_web_contents; return guest_web_contents;
} }
......
...@@ -68,14 +68,12 @@ class GuestViewManager : public content::BrowserPluginGuestManager, ...@@ -68,14 +68,12 @@ class GuestViewManager : public content::BrowserPluginGuestManager,
typedef base::Callback<void(content::WebContents*)> typedef base::Callback<void(content::WebContents*)>
WebContentsCreatedCallback; WebContentsCreatedCallback;
void CreateGuest(const std::string& view_type, void CreateGuest(const std::string& view_type,
const std::string& owner_extension_id,
content::WebContents* owner_web_contents, content::WebContents* owner_web_contents,
const base::DictionaryValue& create_params, const base::DictionaryValue& create_params,
const WebContentsCreatedCallback& callback); const WebContentsCreatedCallback& callback);
content::WebContents* CreateGuestWithWebContentsParams( content::WebContents* CreateGuestWithWebContentsParams(
const std::string& view_type, const std::string& view_type,
const std::string& owner_extension_id,
content::WebContents* owner_web_contents, content::WebContents* owner_web_contents,
const content::WebContents::CreateParams& create_params); const content::WebContents::CreateParams& create_params);
......
...@@ -544,7 +544,6 @@ void WebViewGuest::CreateNewGuestWebViewWindow( ...@@ -544,7 +544,6 @@ void WebViewGuest::CreateNewGuestWebViewWindow(
create_params.SetString(webview::kStoragePartitionId, storage_partition_id); create_params.SetString(webview::kStoragePartitionId, storage_partition_id);
guest_manager->CreateGuest(WebViewGuest::Type, guest_manager->CreateGuest(WebViewGuest::Type,
owner_extension_id(),
embedder_web_contents(), embedder_web_contents(),
create_params, create_params,
base::Bind(&WebViewGuest::NewGuestWebViewCallback, base::Bind(&WebViewGuest::NewGuestWebViewCallback,
...@@ -880,7 +879,6 @@ content::WebContents* WebViewGuest::CreateNewGuestWindow( ...@@ -880,7 +879,6 @@ content::WebContents* WebViewGuest::CreateNewGuestWindow(
GuestViewManager::FromBrowserContext(browser_context()); GuestViewManager::FromBrowserContext(browser_context());
return guest_manager->CreateGuestWithWebContentsParams( return guest_manager->CreateGuestWithWebContentsParams(
WebViewGuest::Type, WebViewGuest::Type,
owner_extension_id(),
embedder_web_contents(), embedder_web_contents(),
create_params); create_params);
} }
......
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