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