Commit 83100cd8 authored by fsamuel@chromium.org's avatar fsamuel@chromium.org

BrowserPlugin: Move CreateGuest to chrome

BUG=364141, 330264

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@269565 0039d316-1c4b-4281-b951-d872f2087c98
parent 9f9dfb44
......@@ -17,8 +17,7 @@ static jlong CreateNativeWebContents(
if (incognito)
profile = profile->GetOffTheRecordProfile();
content::WebContents::CreateParams params =
content::WebContents::CreateParams(profile);
content::WebContents::CreateParams params(profile);
params.initially_hidden = static_cast<bool>(initially_hidden);
return reinterpret_cast<intptr_t>(content::WebContents::Create(params));
}
......
......@@ -53,6 +53,8 @@ GuestViewBase::GuestViewBase(WebContents* guest_web_contents,
weak_ptr_factory_(this) {
webcontents_guestview_map.Get().insert(
std::make_pair(guest_web_contents, this));
GuestViewManager::FromBrowserContext(browser_context_)->
AddGuest(guest_instance_id_, guest_web_contents);
}
// static
......@@ -185,6 +187,9 @@ GuestViewBase::~GuestViewBase() {
webcontents_guestview_map.Get().erase(guest_web_contents());
GuestViewManager::FromBrowserContext(browser_context_)->
RemoveGuest(guest_instance_id_);
pending_events_.clear();
}
......
......@@ -4,6 +4,7 @@
#include "chrome/browser/guest_view/guest_view_manager.h"
#include "base/strings/stringprintf.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/guest_view/guest_view_base.h"
#include "chrome/browser/guest_view/guest_view_constants.h"
......@@ -13,7 +14,9 @@
#include "content/public/browser/user_metrics.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/common/result_codes.h"
#include "content/public/common/url_constants.h"
#include "extensions/browser/extension_system.h"
#include "net/base/escape.h"
#include "url/gurl.h"
using content::BrowserContext;
......@@ -89,22 +92,59 @@ int GuestViewManager::GetNextInstanceID() {
return ++current_instance_id_;
}
void GuestViewManager::AddGuest(int guest_instance_id,
WebContents* guest_web_contents) {
DCHECK(guest_web_contents_by_instance_id_.find(guest_instance_id) ==
guest_web_contents_by_instance_id_.end());
guest_web_contents_by_instance_id_[guest_instance_id] = guest_web_contents;
// This will add the RenderProcessHost ID when we get one.
new GuestWebContentsObserver(guest_web_contents);
}
content::WebContents* GuestViewManager::CreateGuest(
content::SiteInstance* embedder_site_instance,
int instance_id,
const std::string& storage_partition_id,
bool persist_storage,
scoped_ptr<base::DictionaryValue> extra_params) {
content::RenderProcessHost* embedder_process_host =
embedder_site_instance->GetProcess();
// Validate that the partition id coming from the renderer is valid UTF-8,
// since we depend on this in other parts of the code, such as FilePath
// creation. If the validation fails, treat it as a bad message and kill the
// renderer process.
if (!base::IsStringUTF8(storage_partition_id)) {
content::RecordAction(
base::UserMetricsAction("BadMessageTerminate_BPGM"));
base::KillProcess(
embedder_process_host->GetHandle(),
content::RESULT_CODE_KILLED_BAD_MESSAGE, false);
return NULL;
}
void GuestViewManager::RemoveGuest(int guest_instance_id) {
GuestInstanceMap::iterator it =
guest_web_contents_by_instance_id_.find(guest_instance_id);
DCHECK(it != guest_web_contents_by_instance_id_.end());
render_process_host_id_multiset_.erase(
it->second->GetRenderProcessHost()->GetID());
guest_web_contents_by_instance_id_.erase(it);
const GURL& embedder_site_url = embedder_site_instance->GetSiteURL();
const std::string& host = embedder_site_url.host();
std::string url_encoded_partition = net::EscapeQueryParamValue(
storage_partition_id, false);
// 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
// belongs to and what storage partition is in use, rather than the URL
// that the tag is being navigated to.
GURL guest_site(base::StringPrintf("%s://%s/%s?%s",
content::kGuestScheme,
host.c_str(),
persist_storage ? "persist" : "",
url_encoded_partition.c_str()));
// If we already have a webview tag in the same app using the same storage
// partition, we should use the same SiteInstance so the existing tag and
// the new tag can script each other.
SiteInstance* guest_site_instance = GetGuestSiteInstance(guest_site);
if (!guest_site_instance) {
// Create the SiteInstance in a new BrowsingInstance, which will ensure
// that webview tags are also not allowed to send messages across
// different partitions.
guest_site_instance = SiteInstance::CreateForURL(
embedder_site_instance->GetBrowserContext(), guest_site);
}
WebContents::CreateParams create_params(
embedder_site_instance->GetBrowserContext(),
guest_site_instance);
create_params.guest_instance_id = instance_id;
create_params.guest_extra_params.reset(extra_params.release());
return WebContents::Create(create_params);
}
void GuestViewManager::MaybeGetGuestByInstanceIDOrKill(
......@@ -147,6 +187,24 @@ bool GuestViewManager::ForEachGuest(WebContents* embedder_web_contents,
return false;
}
void GuestViewManager::AddGuest(int guest_instance_id,
WebContents* guest_web_contents) {
DCHECK(guest_web_contents_by_instance_id_.find(guest_instance_id) ==
guest_web_contents_by_instance_id_.end());
guest_web_contents_by_instance_id_[guest_instance_id] = guest_web_contents;
// This will add the RenderProcessHost ID when we get one.
new GuestWebContentsObserver(guest_web_contents);
}
void GuestViewManager::RemoveGuest(int guest_instance_id) {
GuestInstanceMap::iterator it =
guest_web_contents_by_instance_id_.find(guest_instance_id);
DCHECK(it != guest_web_contents_by_instance_id_.end());
render_process_host_id_multiset_.erase(
it->second->GetRenderProcessHost()->GetID());
guest_web_contents_by_instance_id_.erase(it);
}
void GuestViewManager::AddRenderProcessHostID(int render_process_host_id) {
render_process_host_id_multiset_.insert(render_process_host_id);
}
......
......@@ -39,24 +39,34 @@ class GuestViewManager : public content::BrowserPluginGuestManagerDelegate,
int embedder_render_process_id);
// BrowserPluginGuestManagerDelegate implementation.
virtual content::WebContents* CreateGuest(
content::SiteInstance* embedder_site_instance,
int instance_id,
const std::string& storage_partition_id,
bool persist_storage,
scoped_ptr<base::DictionaryValue> extra_params) OVERRIDE;
virtual int GetNextInstanceID() OVERRIDE;
virtual void AddGuest(int guest_instance_id,
content::WebContents* guest_web_contents) OVERRIDE;
virtual void RemoveGuest(int guest_instance_id) OVERRIDE;
virtual void MaybeGetGuestByInstanceIDOrKill(
int guest_instance_id,
int embedder_render_process_id,
const GuestByInstanceIDCallback& callback) OVERRIDE;
virtual content::SiteInstance* GetGuestSiteInstance(
const GURL& guest_site) OVERRIDE;
virtual bool ForEachGuest(content::WebContents* embedder_web_contents,
const GuestCallback& callback) OVERRIDE;
private:
friend class GuestViewBase;
friend class GuestWebContentsObserver;
void AddGuest(int guest_instance_id,
content::WebContents* guest_web_contents);
void RemoveGuest(int guest_instance_id);
void AddRenderProcessHostID(int render_process_host_id);
content::SiteInstance* GetGuestSiteInstance(
const GURL& guest_site);
content::WebContents* GetGuestByInstanceID(
int guest_instance_id,
int embedder_render_process_id);
......
......@@ -189,10 +189,11 @@ void BrowserPluginEmbedder::OnGuestCallback(
}
scoped_ptr<base::DictionaryValue> copy_extra_params(extra_params->DeepCopy());
guest = guest_manager->CreateGuest(
GetWebContents()->GetSiteInstance(),
instance_id, params,
copy_extra_params.Pass());
guest = guest_manager->CreateGuest(GetWebContents()->GetSiteInstance(),
instance_id,
params.storage_partition_id,
params.persist_storage,
copy_extra_params.Pass());
if (guest) {
GetContentClient()->browser()->GuestWebContentsAttached(
guest->GetWebContents(),
......
......@@ -221,7 +221,6 @@ BrowserPluginGuest::BrowserPluginGuest(
weak_ptr_factory_(this) {
DCHECK(web_contents);
web_contents->SetDelegate(this);
GetBrowserPluginGuestManager()->AddGuest(instance_id_, GetWebContents());
}
bool BrowserPluginGuest::AddMessageToConsole(WebContents* source,
......@@ -316,19 +315,19 @@ BrowserPluginGuest* BrowserPluginGuest::CreateNewGuestWindow(
// We pull the partition information from the site's URL, which is of the form
// guest://site/{persist}?{partition_name}.
const GURL& site_url = GetWebContents()->GetSiteInstance()->GetSiteURL();
BrowserPluginHostMsg_Attach_Params attach_params;
attach_params.storage_partition_id = site_url.query();
attach_params.persist_storage =
site_url.path().find("persist") != std::string::npos;
// The new guest gets a copy of this guest's extra params so that the content
// embedder exposes the same API for this guest as its opener.
scoped_ptr<base::DictionaryValue> extra_params(
extra_attach_params_->DeepCopy());
const std::string& storage_partition_id = site_url.query();
bool persist_storage =
site_url.path().find("persist") != std::string::npos;
BrowserPluginGuest* new_guest =
guest_manager->CreateGuest(GetWebContents()->GetSiteInstance(),
instance_id,
attach_params,
storage_partition_id,
persist_storage,
extra_params.Pass());
if (new_guest->delegate_)
new_guest->delegate_->SetOpener(GetWebContents());
......@@ -360,7 +359,6 @@ void BrowserPluginGuest::Destroy() {
if (!attached() && GetOpener())
GetOpener()->pending_new_windows_.erase(this);
DestroyUnattachedWindows();
GetBrowserPluginGuestManager()->RemoveGuest(instance_id_);
delete GetWebContents();
}
......
......@@ -14,13 +14,11 @@
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_plugin_guest_manager_delegate.h"
#include "content/public/browser/content_browser_client.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/user_metrics.h"
#include "content/public/common/content_client.h"
#include "content/public/common/result_codes.h"
#include "content/public/common/url_constants.h"
#include "content/public/common/url_utils.h"
#include "net/base/escape.h"
namespace content {
......@@ -70,55 +68,20 @@ int BrowserPluginGuestManager::GetNextInstanceID() {
BrowserPluginGuest* BrowserPluginGuestManager::CreateGuest(
SiteInstance* embedder_site_instance,
int instance_id,
const BrowserPluginHostMsg_Attach_Params& params,
const std::string& storage_partition_id,
bool persist_storage,
scoped_ptr<base::DictionaryValue> extra_params) {
RenderProcessHost* embedder_process_host =
embedder_site_instance->GetProcess();
// Validate that the partition id coming from the renderer is valid UTF-8,
// since we depend on this in other parts of the code, such as FilePath
// creation. If the validation fails, treat it as a bad message and kill the
// renderer process.
if (!base::IsStringUTF8(params.storage_partition_id)) {
content::RecordAction(
base::UserMetricsAction("BadMessageTerminate_BPGM"));
base::KillProcess(
embedder_process_host->GetHandle(),
content::RESULT_CODE_KILLED_BAD_MESSAGE, false);
if (!GetDelegate())
return NULL;
}
const GURL& embedder_site_url = embedder_site_instance->GetSiteURL();
const std::string& host = embedder_site_url.host();
std::string url_encoded_partition = net::EscapeQueryParamValue(
params.storage_partition_id, false);
// 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
// belongs to and what storage partition is in use, rather than the URL
// that the tag is being navigated to.
GURL guest_site(base::StringPrintf("%s://%s/%s?%s",
kGuestScheme,
host.c_str(),
params.persist_storage ? "persist" : "",
url_encoded_partition.c_str()));
// If we already have a webview tag in the same app using the same storage
// partition, we should use the same SiteInstance so the existing tag and
// the new tag can script each other.
SiteInstance* guest_site_instance = GetGuestSiteInstance(guest_site);
if (!guest_site_instance) {
// Create the SiteInstance in a new BrowsingInstance, which will ensure
// that webview tags are also not allowed to send messages across
// different partitions.
guest_site_instance = SiteInstance::CreateForURL(
embedder_site_instance->GetBrowserContext(), guest_site);
}
return WebContentsImpl::CreateGuest(
embedder_site_instance->GetBrowserContext(),
guest_site_instance,
instance_id,
extra_params.Pass());
WebContents* guest_web_contents =
GetDelegate()->CreateGuest(embedder_site_instance,
instance_id,
storage_partition_id,
persist_storage,
extra_params.Pass());
return static_cast<WebContentsImpl*>(guest_web_contents)->
GetBrowserPluginGuest();
}
static void BrowserPluginGuestByInstanceIDCallback(
......@@ -148,19 +111,6 @@ void BrowserPluginGuestManager::MaybeGetGuestByInstanceIDOrKill(
callback));
}
void BrowserPluginGuestManager::AddGuest(int instance_id,
WebContents* guest_web_contents) {
if (!GetDelegate())
return;
GetDelegate()->AddGuest(instance_id, guest_web_contents);
}
void BrowserPluginGuestManager::RemoveGuest(int instance_id) {
if (!GetDelegate())
return;
GetDelegate()->RemoveGuest(instance_id);
}
static void BrowserPluginGuestMessageCallback(const IPC::Message& message,
BrowserPluginGuest* guest) {
if (!guest)
......@@ -182,13 +132,6 @@ void BrowserPluginGuestManager::OnMessageReceived(const IPC::Message& message,
message));
}
SiteInstance* BrowserPluginGuestManager::GetGuestSiteInstance(
const GURL& guest_site) {
if (!GetDelegate())
return NULL;
return GetDelegate()->GetGuestSiteInstance(guest_site);
}
static bool BrowserPluginGuestCallback(
const BrowserPluginGuestManager::GuestCallback& callback,
WebContents* guest_web_contents) {
......
......@@ -65,19 +65,13 @@ class CONTENT_EXPORT BrowserPluginGuestManager :
// If params.src is present, the new guest will also be navigated to the
// provided URL. Optionally, the new guest may be attached to a
// |guest_opener|, and may be attached to a pre-selected |routing_id|.
BrowserPluginGuest* CreateGuest(
virtual BrowserPluginGuest* CreateGuest(
SiteInstance* embedder_site_instance,
int instance_id,
const BrowserPluginHostMsg_Attach_Params& params,
const std::string& storage_partition_id,
bool persist_storage,
scoped_ptr<base::DictionaryValue> extra_params);
// Adds a new |guest_web_contents| to the embedder (overridable in test).
virtual void AddGuest(int instance_id, WebContents* guest_web_contents);
// Removes the guest with the given |instance_id| from this
// BrowserPluginGuestManager.
void RemoveGuest(int instance_id);
typedef base::Callback<void(BrowserPluginGuest*)> GuestByInstanceIDCallback;
void MaybeGetGuestByInstanceIDOrKill(
int instance_id,
......@@ -95,10 +89,6 @@ class CONTENT_EXPORT BrowserPluginGuestManager :
explicit BrowserPluginGuestManager(BrowserContext* context);
// Returns an existing SiteInstance if the current profile has a guest of the
// given |guest_site|.
SiteInstance* GetGuestSiteInstance(const GURL& guest_site);
// Static factory instance (always NULL outside of tests).
static BrowserPluginHostFactory* factory_;
......
......@@ -4,6 +4,7 @@
#include "content/browser/browser_plugin/test_browser_plugin_guest_manager.h"
#include "content/browser/browser_plugin/browser_plugin_guest.h"
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/public/test/test_utils.h"
......@@ -18,13 +19,22 @@ TestBrowserPluginGuestManager::TestBrowserPluginGuestManager(
TestBrowserPluginGuestManager::~TestBrowserPluginGuestManager() {
}
void TestBrowserPluginGuestManager::AddGuest(
BrowserPluginGuest* TestBrowserPluginGuestManager::CreateGuest(
SiteInstance* embedder_site_instance,
int instance_id,
WebContents* guest_web_contents) {
BrowserPluginGuestManager::AddGuest(instance_id, guest_web_contents);
last_guest_added_ = guest_web_contents;
const std::string& storage_partition_id,
bool persist_storage,
scoped_ptr<base::DictionaryValue> extra_params) {
BrowserPluginGuest* guest = BrowserPluginGuestManager::CreateGuest(
embedder_site_instance,
instance_id,
storage_partition_id,
persist_storage,
extra_params.Pass());
last_guest_added_ = guest->GetWebContents();
if (message_loop_runner_.get())
message_loop_runner_->Quit();
return guest;
}
WebContents* TestBrowserPluginGuestManager::WaitForGuestAdded() {
......
......@@ -25,6 +25,14 @@ class TestBrowserPluginGuestManager : public BrowserPluginGuestManager {
explicit TestBrowserPluginGuestManager(BrowserContext* context);
virtual ~TestBrowserPluginGuestManager();
// Overriden to intercept in test.
virtual BrowserPluginGuest* CreateGuest(
SiteInstance* embedder_site_instance,
int instance_id,
const std::string& storage_partition_id,
bool persist_storage,
scoped_ptr<base::DictionaryValue> extra_params) OVERRIDE;
// Waits until at least one guest is added to the guest manager.
WebContents* WaitForGuestAdded();
......@@ -32,10 +40,6 @@ class TestBrowserPluginGuestManager : public BrowserPluginGuestManager {
// BrowserPluginHostTest.ReloadEmbedder needs access to the GuestInstanceMap.
FRIEND_TEST_ALL_PREFIXES(BrowserPluginHostTest, ReloadEmbedder);
// Overriden to intercept in test.
virtual void AddGuest(int instance_id,
WebContents* guest_web_contents) OVERRIDE;
WebContents* last_guest_added_;
scoped_refptr<MessageLoopRunner> message_loop_runner_;
DISALLOW_COPY_AND_ASSIGN(TestBrowserPluginGuestManager);
......
......@@ -6,11 +6,37 @@
#include "base/logging.h"
#include "base/memory/singleton.h"
#include "base/strings/stringprintf.h"
#include "base/values.h"
#include "content/public/browser/site_instance.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/common/url_constants.h"
#include "net/base/escape.h"
namespace content {
class GuestWebContentsObserver
: public content::WebContentsObserver {
public:
explicit GuestWebContentsObserver(WebContents* guest_web_contents)
: WebContentsObserver(guest_web_contents),
guest_instance_id_(guest_web_contents->GetEmbeddedInstanceID()) {
}
virtual ~GuestWebContentsObserver() {
}
virtual void WebContentsDestroyed() OVERRIDE {
TestGuestManagerDelegate::GetInstance()->RemoveGuest(guest_instance_id_);
delete this;
}
private:
int guest_instance_id_;
DISALLOW_COPY_AND_ASSIGN(GuestWebContentsObserver);
};
TestGuestManagerDelegate::TestGuestManagerDelegate()
: next_instance_id_(0) {
}
......@@ -23,6 +49,44 @@ TestGuestManagerDelegate* TestGuestManagerDelegate::GetInstance() {
return Singleton<TestGuestManagerDelegate>::get();
}
content::WebContents* TestGuestManagerDelegate::CreateGuest(
SiteInstance* embedder_site_instance,
int instance_id,
const std::string& storage_partition_id,
bool persist_storage,
scoped_ptr<base::DictionaryValue> extra_params) {
const GURL& embedder_site_url = embedder_site_instance->GetSiteURL();
const std::string& host = embedder_site_url.host();
std::string url_encoded_partition = net::EscapeQueryParamValue(
storage_partition_id, false);
GURL guest_site(base::StringPrintf("%s://%s/%s?%s",
content::kGuestScheme,
host.c_str(),
persist_storage ? "persist" : "",
url_encoded_partition.c_str()));
// If we already have a webview tag in the same app using the same storage
// partition, we should use the same SiteInstance so the existing tag and
// the new tag can script each other.
SiteInstance* guest_site_instance = GetGuestSiteInstance(guest_site);
if (!guest_site_instance) {
// Create the SiteInstance in a new BrowsingInstance, which will ensure
// that webview tags are also not allowed to send messages across
// different partitions.
guest_site_instance = SiteInstance::CreateForURL(
embedder_site_instance->GetBrowserContext(), guest_site);
}
WebContents::CreateParams create_params(
embedder_site_instance->GetBrowserContext(),
guest_site_instance);
create_params.guest_instance_id = instance_id;
create_params.guest_extra_params.reset(extra_params.release());
WebContents* guest_web_contents = WebContents::Create(create_params);
AddGuest(instance_id, guest_web_contents);
return guest_web_contents;
}
int TestGuestManagerDelegate::GetNextInstanceID() {
return ++next_instance_id_;
}
......@@ -33,6 +97,7 @@ void TestGuestManagerDelegate::AddGuest(
DCHECK(guest_web_contents_by_instance_id_.find(guest_instance_id) ==
guest_web_contents_by_instance_id_.end());
guest_web_contents_by_instance_id_[guest_instance_id] = guest_web_contents;
new GuestWebContentsObserver(guest_web_contents);
}
void TestGuestManagerDelegate::RemoveGuest(
......
......@@ -20,17 +20,22 @@ class TestGuestManagerDelegate : public BrowserPluginGuestManagerDelegate {
static TestGuestManagerDelegate* GetInstance();
void AddGuest(int guest_instance_id, WebContents* guest_web_contents);
void RemoveGuest(int guest_instance_id);
SiteInstance* GetGuestSiteInstance(const GURL& guest_site);
// BrowserPluginGuestManagerDelegate implementation.
virtual content::WebContents* CreateGuest(
content::SiteInstance* embedder_site_instance,
int instance_id,
const std::string& storage_partition_id,
bool persist_storage,
scoped_ptr<base::DictionaryValue> extra_params) OVERRIDE;
virtual int GetNextInstanceID() OVERRIDE;
virtual void AddGuest(int guest_instance_id,
WebContents* guest_web_contents) OVERRIDE;
virtual void RemoveGuest(int guest_instance_id) OVERRIDE;
virtual void MaybeGetGuestByInstanceIDOrKill(
int guest_instance_id,
int embedder_render_process_id,
const GuestByInstanceIDCallback& callback) OVERRIDE;
virtual SiteInstance* GetGuestSiteInstance(
const GURL& guest_site) OVERRIDE;
virtual bool ForEachGuest(WebContents* embedder_web_contents,
const GuestCallback& callback) OVERRIDE;
......
......@@ -431,33 +431,23 @@ WebContentsImpl* WebContentsImpl::CreateWithOpener(
WebContentsImpl* new_contents = new WebContentsImpl(
params.browser_context, opener);
if (params.guest_instance_id) {
scoped_ptr<base::DictionaryValue> extra_params(
params.guest_extra_params->DeepCopy());
// This makes |new_contents| act as a guest.
// For more info, see comment above class BrowserPluginGuest.
BrowserPluginGuest::Create(params.guest_instance_id,
params.site_instance,
new_contents,
extra_params.Pass());
// We are instantiating a WebContents for browser plugin. Set its subframe
// bit to true.
new_contents->is_subframe_ = true;
}
new_contents->Init(params);
return new_contents;
}
// static
BrowserPluginGuest* WebContentsImpl::CreateGuest(
BrowserContext* browser_context,
SiteInstance* site_instance,
int guest_instance_id,
scoped_ptr<base::DictionaryValue> extra_params) {
WebContentsImpl* new_contents = new WebContentsImpl(browser_context, NULL);
// This makes |new_contents| act as a guest.
// For more info, see comment above class BrowserPluginGuest.
BrowserPluginGuest::Create(
guest_instance_id, site_instance, new_contents, extra_params.Pass());
WebContents::CreateParams create_params(browser_context, site_instance);
new_contents->Init(create_params);
// We are instantiating a WebContents for browser plugin. Set its subframe bit
// to true.
new_contents->is_subframe_ = true;
return new_contents->browser_plugin_guest_.get();
}
RenderFrameHostManager* WebContentsImpl::GetRenderManagerForTesting() {
return GetRenderManager();
}
......
......@@ -99,13 +99,6 @@ class CONTENT_EXPORT WebContentsImpl
// opener is closed or the page clears its window.opener.
WebContentsImpl* opener() const { return opener_; }
// Creates a WebContents to be used as a browser plugin guest.
static BrowserPluginGuest* CreateGuest(
BrowserContext* browser_context,
content::SiteInstance* site_instance,
int guest_instance_id,
scoped_ptr<base::DictionaryValue> extra_params);
// Creates a swapped out RenderView. This is used by the browser plugin to
// create a swapped out RenderView in the embedder render process for the
// guest, to expose the guest's window object to the embedder.
......
......@@ -4,15 +4,21 @@
#include "content/public/browser/browser_plugin_guest_manager_delegate.h"
#include "base/values.h"
namespace content {
int BrowserPluginGuestManagerDelegate::GetNextInstanceID() {
return 0;
content::WebContents* BrowserPluginGuestManagerDelegate::CreateGuest(
SiteInstance* embedder_site_instance,
int instance_id,
const std::string& storage_partition_id,
bool persist_storage,
scoped_ptr<base::DictionaryValue> extra_params) {
return NULL;
}
content::SiteInstance* BrowserPluginGuestManagerDelegate::GetGuestSiteInstance(
const GURL& guest_site) {
return NULL;
int BrowserPluginGuestManagerDelegate::GetNextInstanceID() {
return 0;
}
bool BrowserPluginGuestManagerDelegate::ForEachGuest(
......
......@@ -5,11 +5,17 @@
#ifndef CONTENT_PUBLIC_BROWSER_BROWSER_PLUGIN_GUEST_MANAGER_DELEGATE_H_
#define CONTENT_PUBLIC_BROWSER_BROWSER_PLUGIN_GUEST_MANAGER_DELEGATE_H_
#include <string>
#include "base/callback.h"
#include "content/common/content_export.h"
class GURL;
namespace base {
class DictionaryValue;
} // namespace base
namespace content {
class SiteInstance;
......@@ -21,22 +27,19 @@ class CONTENT_EXPORT BrowserPluginGuestManagerDelegate {
public:
virtual ~BrowserPluginGuestManagerDelegate() {}
// Requests the allocation of a new guest WebContents.
virtual content::WebContents* CreateGuest(
content::SiteInstance* embedder_site_instance,
int instance_id,
const std::string& storage_partition_id,
bool persist_storage,
scoped_ptr<base::DictionaryValue> extra_params);
// Return a new instance ID.
// TODO(fsamuel): Remove this. Once the instance ID concept is moved
// entirely out of content and into chrome, this API will be unnecessary.
virtual int GetNextInstanceID();
// Adds a new WebContents |guest_web_contents| as a guest.
// TODO(fsamuel): Remove this. Once guest WebContents allocation
// moves outside of content, this API will be unnecessary.
virtual void AddGuest(int guest_instance_id,
WebContents* guest_web_contents) {}
// Removes a |guest_instance_id| as a valid guest.
// TODO(fsamuel): Remove this. Once guest WebContents allocation
// moves outside of content, this API will be unnecessary.
virtual void RemoveGuest(int guest_instance_id) {}
typedef base::Callback<void(WebContents*)> GuestByInstanceIDCallback;
// Requests a guest WebContents associated with the provided
// |guest_instance_id|. If a guest associated with the provided ID
......@@ -49,12 +52,6 @@ class CONTENT_EXPORT BrowserPluginGuestManagerDelegate {
int embedder_render_process_id,
const GuestByInstanceIDCallback& callback) {}
// Returns an existing SiteInstance if the current profile has a guest of the
// given |guest_site|.
// TODO(fsamuel): Remove this. Once guest WebContents allocation
// moves outside of content, this API will be unnecessary.
virtual content::SiteInstance* GetGuestSiteInstance(const GURL& guest_site);
// Iterates over all WebContents belonging to a given |embedder_web_contents|,
// calling |callback| for each. If one of the callbacks returns true, then
// the iteration exits early.
......
......@@ -15,6 +15,7 @@ WebContents::CreateParams::CreateParams(BrowserContext* context)
routing_id(MSG_ROUTING_NONE),
main_frame_routing_id(MSG_ROUTING_NONE),
initially_hidden(false),
guest_instance_id(0),
context(NULL) {}
WebContents::CreateParams::CreateParams(
......@@ -25,6 +26,10 @@ WebContents::CreateParams::CreateParams(
routing_id(MSG_ROUTING_NONE),
main_frame_routing_id(MSG_ROUTING_NONE),
initially_hidden(false),
guest_instance_id(0),
context(NULL) {}
WebContents::CreateParams::~CreateParams() {
}
} // namespace content
......@@ -30,6 +30,7 @@
#endif
namespace base {
class DictionaryValue;
class TimeTicks;
}
......@@ -82,6 +83,7 @@ class WebContents : public PageNavigator,
public:
struct CONTENT_EXPORT CreateParams {
explicit CreateParams(BrowserContext* context);
~CreateParams();
CreateParams(BrowserContext* context, SiteInstance* site);
BrowserContext* browser_context;
......@@ -101,6 +103,14 @@ class WebContents : public PageNavigator,
// True if the contents should be initially hidden.
bool initially_hidden;
// If this instance ID is non-zero then it indicates that this WebContents
// should behave as a guest.
int guest_instance_id;
// TODO(fsamuel): This is temporary. Remove this once all guests are created
// from the content embedder.
scoped_ptr<base::DictionaryValue> guest_extra_params;
// Used to specify the location context which display the new view should
// belong. This can be NULL if not needed.
gfx::NativeView context;
......
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