summaryrefslogtreecommitdiffstats
path: root/content/browser/browser_plugin
diff options
context:
space:
mode:
authorfsamuel@chromium.org <fsamuel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-11 01:34:32 +0000
committerfsamuel@chromium.org <fsamuel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-11 01:34:32 +0000
commit0d05a1587e9fd1af5c29facbf72f37aa121747ad (patch)
tree317803aa25573feb5cedbc4a1c0aeac3de39967a /content/browser/browser_plugin
parentd1b5295d3a1af45fab3f02468e876f5e008ea486 (diff)
downloadchromium_src-0d05a1587e9fd1af5c29facbf72f37aa121747ad.zip
chromium_src-0d05a1587e9fd1af5c29facbf72f37aa121747ad.tar.gz
chromium_src-0d05a1587e9fd1af5c29facbf72f37aa121747ad.tar.bz2
Remove BrowserPluginGuestManager
This CL removes BrowserPluginGuestManager entirely, leaving BrowserPlugin relying on the BrowserPluginGuestManagerDelegate interface. This CL significantly reduces complexity in content. In a subsequent patch, BrowserPluginGuestManagerDelegate will be renamed BrowserPluginGuestManager. I am leaving that separate so it is clear what's going on. BUG=364141, 330264 Review URL: https://codereview.chromium.org/269113002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@269680 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/browser_plugin')
-rw-r--r--content/browser/browser_plugin/browser_plugin_embedder.cc44
-rw-r--r--content/browser/browser_plugin/browser_plugin_embedder.h12
-rw-r--r--content/browser/browser_plugin/browser_plugin_guest.cc23
-rw-r--r--content/browser/browser_plugin/browser_plugin_guest.h4
-rw-r--r--content/browser/browser_plugin/browser_plugin_guest_manager.cc151
-rw-r--r--content/browser/browser_plugin/browser_plugin_guest_manager.h108
-rw-r--r--content/browser/browser_plugin/browser_plugin_host_browsertest.cc44
-rw-r--r--content/browser/browser_plugin/browser_plugin_host_factory.h3
-rw-r--r--content/browser/browser_plugin/browser_plugin_message_filter.cc36
-rw-r--r--content/browser/browser_plugin/browser_plugin_message_filter.h3
-rw-r--r--content/browser/browser_plugin/test_browser_plugin_guest_manager.cc55
-rw-r--r--content/browser/browser_plugin/test_browser_plugin_guest_manager.h50
-rw-r--r--content/browser/browser_plugin/test_guest_manager_delegate.cc23
-rw-r--r--content/browser/browser_plugin/test_guest_manager_delegate.h10
14 files changed, 113 insertions, 453 deletions
diff --git a/content/browser/browser_plugin/browser_plugin_embedder.cc b/content/browser/browser_plugin/browser_plugin_embedder.cc
index 7f2a4f7..c7fc8ba 100644
--- a/content/browser/browser_plugin/browser_plugin_embedder.cc
+++ b/content/browser/browser_plugin/browser_plugin_embedder.cc
@@ -6,7 +6,6 @@
#include "base/values.h"
#include "content/browser/browser_plugin/browser_plugin_guest.h"
-#include "content/browser/browser_plugin/browser_plugin_guest_manager.h"
#include "content/browser/browser_plugin/browser_plugin_host_factory.h"
#include "content/browser/renderer_host/render_view_host_impl.h"
#include "content/browser/web_contents/web_contents_impl.h"
@@ -15,6 +14,7 @@
#include "content/common/drag_messages.h"
#include "content/common/gpu/gpu_messages.h"
#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/native_web_keyboard_event.h"
#include "content/public/browser/render_view_host.h"
@@ -66,23 +66,21 @@ WebContentsImpl* BrowserPluginEmbedder::GetWebContents() const {
return static_cast<WebContentsImpl*>(web_contents());
}
-BrowserPluginGuestManager*
+BrowserPluginGuestManagerDelegate*
BrowserPluginEmbedder::GetBrowserPluginGuestManager() const {
- return BrowserPluginGuestManager::FromBrowserContext(
- GetWebContents()->GetBrowserContext());
+ return GetWebContents()->GetBrowserContext()->GetGuestManagerDelegate();
}
bool BrowserPluginEmbedder::DidSendScreenRectsCallback(
- BrowserPluginGuest* guest) {
+ WebContents* guest_web_contents) {
static_cast<RenderViewHostImpl*>(
- guest->GetWebContents()->GetRenderViewHost())->SendScreenRects();
+ guest_web_contents->GetRenderViewHost())->SendScreenRects();
// Not handled => Iterate over all guests.
return false;
}
void BrowserPluginEmbedder::DidSendScreenRects() {
- BrowserPluginGuestManager::FromBrowserContext(
- GetWebContents()->GetBrowserContext())->ForEachGuest(
+ GetBrowserPluginGuestManager()->ForEachGuest(
GetWebContents(), base::Bind(
&BrowserPluginEmbedder::DidSendScreenRectsCallback,
base::Unretained(this)));
@@ -90,8 +88,9 @@ void BrowserPluginEmbedder::DidSendScreenRects() {
bool BrowserPluginEmbedder::UnlockMouseIfNecessaryCallback(
const NativeWebKeyboardEvent& event,
- BrowserPluginGuest* guest) {
- return guest->UnlockMouseIfNecessary(event);
+ WebContents* guest_web_contents) {
+ return static_cast<WebContentsImpl*>(guest_web_contents)->
+ GetBrowserPluginGuest()->UnlockMouseIfNecessary(event);
}
bool BrowserPluginEmbedder::HandleKeyboardEvent(
@@ -110,9 +109,10 @@ bool BrowserPluginEmbedder::HandleKeyboardEvent(
}
bool BrowserPluginEmbedder::SetZoomLevelCallback(
- double level, BrowserPluginGuest* guest) {
+ double level, WebContents* guest_web_contents) {
double zoom_factor = content::ZoomLevelToZoomFactor(level);
- guest->SetZoom(zoom_factor);
+ static_cast<WebContentsImpl*>(guest_web_contents)->GetBrowserPluginGuest()->
+ SetZoom(zoom_factor);
// Not handled => Iterate over all guests.
return false;
}
@@ -172,8 +172,10 @@ void BrowserPluginEmbedder::OnGuestCallback(
int instance_id,
const BrowserPluginHostMsg_Attach_Params& params,
const base::DictionaryValue* extra_params,
- BrowserPluginGuest* guest) {
- BrowserPluginGuestManager* guest_manager = GetBrowserPluginGuestManager();
+ WebContents* guest_web_contents) {
+ BrowserPluginGuest* guest = guest_web_contents ?
+ static_cast<WebContentsImpl*>(guest_web_contents)->
+ GetBrowserPluginGuest() : NULL;
if (guest) {
// There is an implicit order expectation here:
// 1. The content embedder is made aware of the attachment.
@@ -189,11 +191,15 @@ void BrowserPluginEmbedder::OnGuestCallback(
}
scoped_ptr<base::DictionaryValue> copy_extra_params(extra_params->DeepCopy());
- guest = guest_manager->CreateGuest(GetWebContents()->GetSiteInstance(),
- instance_id,
- params.storage_partition_id,
- params.persist_storage,
- copy_extra_params.Pass());
+ guest_web_contents = GetBrowserPluginGuestManager()->CreateGuest(
+ GetWebContents()->GetSiteInstance(),
+ instance_id,
+ params.storage_partition_id,
+ params.persist_storage,
+ copy_extra_params.Pass());
+ guest = guest_web_contents ?
+ static_cast<WebContentsImpl*>(guest_web_contents)->
+ GetBrowserPluginGuest() : NULL;
if (guest) {
GetContentClient()->browser()->GuestWebContentsAttached(
guest->GetWebContents(),
diff --git a/content/browser/browser_plugin/browser_plugin_embedder.h b/content/browser/browser_plugin/browser_plugin_embedder.h
index 4df3dc4..a636bc9 100644
--- a/content/browser/browser_plugin/browser_plugin_embedder.h
+++ b/content/browser/browser_plugin/browser_plugin_embedder.h
@@ -32,7 +32,7 @@ class Point;
namespace content {
class BrowserPluginGuest;
-class BrowserPluginGuestManager;
+class BrowserPluginGuestManagerDelegate;
class BrowserPluginHostFactory;
class RenderWidgetHostImpl;
class WebContentsImpl;
@@ -88,21 +88,21 @@ class CONTENT_EXPORT BrowserPluginEmbedder : public WebContentsObserver {
explicit BrowserPluginEmbedder(WebContentsImpl* web_contents);
- BrowserPluginGuestManager* GetBrowserPluginGuestManager() const;
+ BrowserPluginGuestManagerDelegate* GetBrowserPluginGuestManager() const;
- bool DidSendScreenRectsCallback(BrowserPluginGuest* guest);
+ bool DidSendScreenRectsCallback(WebContents* guest_web_contents);
- bool SetZoomLevelCallback(double level, BrowserPluginGuest* guest);
+ bool SetZoomLevelCallback(double level, WebContents* guest_web_contents);
bool UnlockMouseIfNecessaryCallback(const NativeWebKeyboardEvent& event,
- BrowserPluginGuest* guest);
+ WebContents* guest);
// Called by the content embedder when a guest exists with the provided
// |instance_id|.
void OnGuestCallback(int instance_id,
const BrowserPluginHostMsg_Attach_Params& params,
const base::DictionaryValue* extra_params,
- BrowserPluginGuest* guest);
+ WebContents* guest_web_contents);
// Message handlers.
diff --git a/content/browser/browser_plugin/browser_plugin_guest.cc b/content/browser/browser_plugin/browser_plugin_guest.cc
index 5ebaf08..20a69cb 100644
--- a/content/browser/browser_plugin/browser_plugin_guest.cc
+++ b/content/browser/browser_plugin/browser_plugin_guest.cc
@@ -10,7 +10,6 @@
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "content/browser/browser_plugin/browser_plugin_embedder.h"
-#include "content/browser/browser_plugin/browser_plugin_guest_manager.h"
#include "content/browser/browser_plugin/browser_plugin_host_factory.h"
#include "content/browser/browser_thread_impl.h"
#include "content/browser/child_process_security_policy_impl.h"
@@ -30,6 +29,7 @@
#include "content/common/input_messages.h"
#include "content/common/view_messages.h"
#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/navigation_controller.h"
#include "content/public/browser/render_widget_host_view.h"
@@ -111,12 +111,16 @@ class BrowserPluginGuest::NewWindowRequest : public PermissionRequest {
virtual ~NewWindowRequest() {}
void RespondInternal(bool should_allow,
- BrowserPluginGuest* guest) {
- if (!guest) {
+ WebContents* guest_web_contents) {
+ if (!guest_web_contents) {
VLOG(0) << "Guest not found. Instance ID: " << instance_id_;
return;
}
+ BrowserPluginGuest* guest =
+ static_cast<WebContentsImpl*>(guest_web_contents)->
+ GetBrowserPluginGuest();
+ DCHECK(guest);
// If we do not destroy the guest then we allow the new window.
if (!should_allow)
guest->Destroy();
@@ -306,7 +310,8 @@ void BrowserPluginGuest::RequestPermission(
BrowserPluginGuest* BrowserPluginGuest::CreateNewGuestWindow(
const OpenURLParams& params) {
- BrowserPluginGuestManager* guest_manager = GetBrowserPluginGuestManager();
+ BrowserPluginGuestManagerDelegate* guest_manager =
+ GetBrowserPluginGuestManager();
// Allocate a new instance ID for the new guest.
int instance_id = guest_manager->GetNextInstanceID();
@@ -323,12 +328,15 @@ BrowserPluginGuest* BrowserPluginGuest::CreateNewGuestWindow(
const std::string& storage_partition_id = site_url.query();
bool persist_storage =
site_url.path().find("persist") != std::string::npos;
- BrowserPluginGuest* new_guest =
+ WebContents* new_guest_web_contents =
guest_manager->CreateGuest(GetWebContents()->GetSiteInstance(),
instance_id,
storage_partition_id,
persist_storage,
extra_params.Pass());
+ BrowserPluginGuest* new_guest =
+ static_cast<WebContentsImpl*>(new_guest_web_contents)->
+ GetBrowserPluginGuest();
if (new_guest->delegate_)
new_guest->delegate_->SetOpener(GetWebContents());
@@ -574,10 +582,9 @@ void BrowserPluginGuest::CopyFromCompositingSurface(
copy_request_id_, src_subrect, dst_size));
}
-BrowserPluginGuestManager*
+BrowserPluginGuestManagerDelegate*
BrowserPluginGuest::GetBrowserPluginGuestManager() const {
- return BrowserPluginGuestManager::FromBrowserContext(
- GetWebContents()->GetBrowserContext());
+ return GetWebContents()->GetBrowserContext()->GetGuestManagerDelegate();
}
// screen.
diff --git a/content/browser/browser_plugin/browser_plugin_guest.h b/content/browser/browser_plugin/browser_plugin_guest.h
index 7380e36..b0a23eb 100644
--- a/content/browser/browser_plugin/browser_plugin_guest.h
+++ b/content/browser/browser_plugin/browser_plugin_guest.h
@@ -59,7 +59,7 @@ class Range;
namespace content {
-class BrowserPluginGuestManager;
+class BrowserPluginGuestManagerDelegate;
class BrowserPluginHostFactory;
class RenderWidgetHostView;
class SiteInstance;
@@ -150,7 +150,7 @@ class CONTENT_EXPORT BrowserPluginGuest
gfx::Size dst_size,
const base::Callback<void(bool, const SkBitmap&)>& callback);
- BrowserPluginGuestManager* GetBrowserPluginGuestManager() const;
+ BrowserPluginGuestManagerDelegate* GetBrowserPluginGuestManager() const;
// WebContentsObserver implementation.
virtual void DidCommitProvisionalLoadForFrame(
diff --git a/content/browser/browser_plugin/browser_plugin_guest_manager.cc b/content/browser/browser_plugin/browser_plugin_guest_manager.cc
deleted file mode 100644
index bde02e2..0000000
--- a/content/browser/browser_plugin/browser_plugin_guest_manager.cc
+++ /dev/null
@@ -1,151 +0,0 @@
-// Copyright (c) 2013 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "content/browser/browser_plugin/browser_plugin_guest_manager.h"
-
-#include "content/browser/browser_plugin/browser_plugin_guest.h"
-#include "content/browser/browser_plugin/browser_plugin_host_factory.h"
-#include "content/browser/renderer_host/render_view_host_impl.h"
-#include "content/browser/web_contents/web_contents_impl.h"
-#include "content/common/browser_plugin/browser_plugin_constants.h"
-#include "content/common/browser_plugin/browser_plugin_messages.h"
-#include "content/common/content_export.h"
-#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/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"
-
-namespace content {
-
-// static
-BrowserPluginHostFactory* BrowserPluginGuestManager::factory_ = NULL;
-
-BrowserPluginGuestManager::BrowserPluginGuestManager(BrowserContext* context)
- : context_(context) {}
-
-BrowserPluginGuestManagerDelegate*
-BrowserPluginGuestManager::GetDelegate() const {
- return context_->GetGuestManagerDelegate();
-}
-
-BrowserPluginGuestManager::~BrowserPluginGuestManager() {
-}
-
-// static.
-BrowserPluginGuestManager* BrowserPluginGuestManager::FromBrowserContext(
- BrowserContext* context) {
- BrowserPluginGuestManager* guest_manager =
- static_cast<BrowserPluginGuestManager*>(
- context->GetUserData(
- browser_plugin::kBrowserPluginGuestManagerKeyName));
- if (!guest_manager) {
- guest_manager = BrowserPluginGuestManager::Create(context);
- context->SetUserData(browser_plugin::kBrowserPluginGuestManagerKeyName,
- guest_manager);
- }
- return guest_manager;
-}
-
-// static
-BrowserPluginGuestManager* BrowserPluginGuestManager::Create(
- BrowserContext* context) {
- if (factory_)
- return factory_->CreateBrowserPluginGuestManager(context);
- return new BrowserPluginGuestManager(context);
-}
-
-int BrowserPluginGuestManager::GetNextInstanceID() {
- if (!GetDelegate())
- return 0;
- return GetDelegate()->GetNextInstanceID();
-}
-
-BrowserPluginGuest* BrowserPluginGuestManager::CreateGuest(
- SiteInstance* embedder_site_instance,
- int instance_id,
- const std::string& storage_partition_id,
- bool persist_storage,
- scoped_ptr<base::DictionaryValue> extra_params) {
- if (!GetDelegate())
- return NULL;
- 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(
- const BrowserPluginGuestManager::GuestByInstanceIDCallback& callback,
- WebContents* guest_web_contents) {
- if (!guest_web_contents) {
- callback.Run(NULL);
- return;
- }
- callback.Run(static_cast<WebContentsImpl*>(guest_web_contents)->
- GetBrowserPluginGuest());
-}
-
-void BrowserPluginGuestManager::MaybeGetGuestByInstanceIDOrKill(
- int instance_id,
- int embedder_render_process_id,
- const GuestByInstanceIDCallback& callback) const {
- if (!GetDelegate()) {
- callback.Run(NULL);
- return;
- }
-
- GetDelegate()->MaybeGetGuestByInstanceIDOrKill(
- instance_id,
- embedder_render_process_id,
- base::Bind(&BrowserPluginGuestByInstanceIDCallback,
- callback));
-}
-
-static void BrowserPluginGuestMessageCallback(const IPC::Message& message,
- BrowserPluginGuest* guest) {
- if (!guest)
- return;
- guest->OnMessageReceivedFromEmbedder(message);
-}
-
-void BrowserPluginGuestManager::OnMessageReceived(const IPC::Message& message,
- int render_process_id) {
- DCHECK(BrowserPluginGuest::ShouldForwardToBrowserPluginGuest(message));
- int instance_id = 0;
- // All allowed messages must have instance_id as their first parameter.
- PickleIterator iter(message);
- bool success = iter.ReadInt(&instance_id);
- DCHECK(success);
- MaybeGetGuestByInstanceIDOrKill(instance_id,
- render_process_id,
- base::Bind(&BrowserPluginGuestMessageCallback,
- message));
-}
-
-static bool BrowserPluginGuestCallback(
- const BrowserPluginGuestManager::GuestCallback& callback,
- WebContents* guest_web_contents) {
- return callback.Run(static_cast<WebContentsImpl*>(guest_web_contents)
- ->GetBrowserPluginGuest());
-}
-
-bool BrowserPluginGuestManager::ForEachGuest(
- WebContents* embedder_web_contents, const GuestCallback& callback) {
- if (!GetDelegate())
- return false;
- return GetDelegate()->ForEachGuest(embedder_web_contents,
- base::Bind(&BrowserPluginGuestCallback,
- callback));
-}
-
-} // namespace content
diff --git a/content/browser/browser_plugin/browser_plugin_guest_manager.h b/content/browser/browser_plugin/browser_plugin_guest_manager.h
deleted file mode 100644
index 5510640..0000000
--- a/content/browser/browser_plugin/browser_plugin_guest_manager.h
+++ /dev/null
@@ -1,108 +0,0 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// A BrowserPluginGuestManager serves as a message router to BrowserPluginGuests
-// for all guests within a given profile.
-// Messages are routed to a particular guest instance based on an instance_id.
-
-#ifndef CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_GUEST_MANAGER_H_
-#define CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_GUEST_MANAGER_H_
-
-#include "base/basictypes.h"
-#include "base/supports_user_data.h"
-#include "base/values.h"
-#include "content/common/content_export.h"
-#include "content/public/browser/browser_plugin_guest_manager_delegate.h"
-#include "ipc/ipc_message.h"
-
-struct BrowserPluginHostMsg_Attach_Params;
-struct BrowserPluginHostMsg_ResizeGuest_Params;
-class GURL;
-
-namespace gfx {
-class Point;
-}
-
-namespace IPC {
-class Message;
-} // namespace IPC
-
-namespace content {
-
-class BrowserContext;
-class BrowserPluginGuest;
-class BrowserPluginHostFactory;
-class RenderWidgetHostImpl;
-class SiteInstance;
-class WebContents;
-
-// WARNING: All APIs should be guarded with a process ID check like
-// CanEmbedderAccessInstanceIDMaybeKill, to prevent abuse by normal renderer
-// processes.
-class CONTENT_EXPORT BrowserPluginGuestManager :
- public base::SupportsUserData::Data {
- public:
- virtual ~BrowserPluginGuestManager();
-
- static BrowserPluginGuestManager* FromBrowserContext(BrowserContext* context);
-
- BrowserPluginGuestManagerDelegate* GetDelegate() const;
-
- static BrowserPluginGuestManager* Create(BrowserContext* context);
-
- // Overrides factory for testing. Default (NULL) value indicates regular
- // (non-test) environment.
- static void set_factory_for_testing(BrowserPluginHostFactory* factory) {
- content::BrowserPluginGuestManager::factory_ = factory;
- }
-
- // Gets the next available instance id. 0 is considered an invalid instance
- // ID.
- int GetNextInstanceID();
-
- // Creates a guest WebContents with the provided |instance_id| and |params|.
- // 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|.
- 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);
-
- typedef base::Callback<void(BrowserPluginGuest*)> GuestByInstanceIDCallback;
- void MaybeGetGuestByInstanceIDOrKill(
- int instance_id,
- int embedder_render_process_id,
- const GuestByInstanceIDCallback& callback) const;
-
- typedef base::Callback<bool(BrowserPluginGuest*)> GuestCallback;
- bool ForEachGuest(WebContents* embedder_web_contents,
- const GuestCallback& callback);
-
- void OnMessageReceived(const IPC::Message& message, int render_process_id);
-
- private:
- friend class TestBrowserPluginGuestManager;
-
- explicit BrowserPluginGuestManager(BrowserContext* context);
-
- // Static factory instance (always NULL outside of tests).
- static BrowserPluginHostFactory* factory_;
-
- // The BrowserContext in which this manager this stored.
- BrowserContext* context_;
-
- // Contains guests' WebContents, mapping from their instance ids.
- typedef std::map<int, WebContents*> GuestInstanceMap;
- GuestInstanceMap guest_web_contents_by_instance_id_;
- int next_instance_id_;
-
- DISALLOW_COPY_AND_ASSIGN(BrowserPluginGuestManager);
-};
-
-} // namespace content
-
-#endif // CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_GUEST_MANAGER_H_
diff --git a/content/browser/browser_plugin/browser_plugin_host_browsertest.cc b/content/browser/browser_plugin/browser_plugin_host_browsertest.cc
index c054c4a..0a1b314 100644
--- a/content/browser/browser_plugin/browser_plugin_host_browsertest.cc
+++ b/content/browser/browser_plugin/browser_plugin_host_browsertest.cc
@@ -14,7 +14,6 @@
#include "content/browser/browser_plugin/browser_plugin_host_factory.h"
#include "content/browser/browser_plugin/test_browser_plugin_guest.h"
#include "content/browser/browser_plugin/test_browser_plugin_guest_delegate.h"
-#include "content/browser/browser_plugin/test_browser_plugin_guest_manager.h"
#include "content/browser/browser_plugin/test_guest_manager_delegate.h"
#include "content/browser/child_process_security_policy_impl.h"
#include "content/browser/frame_host/render_frame_host_impl.h"
@@ -103,14 +102,6 @@ class TestBrowserPluginEmbedder : public BrowserPluginEmbedder {
// BrowserPluginGuest.
class TestBrowserPluginHostFactory : public BrowserPluginHostFactory {
public:
- virtual BrowserPluginGuestManager*
- CreateBrowserPluginGuestManager(BrowserContext* context) OVERRIDE {
- guest_manager_instance_count_++;
- if (message_loop_runner_)
- message_loop_runner_->Quit();
- return new TestBrowserPluginGuestManager(context);
- }
-
virtual BrowserPluginGuest* CreateBrowserPluginGuest(
int instance_id,
WebContentsImpl* web_contents) OVERRIDE {
@@ -129,19 +120,8 @@ class TestBrowserPluginHostFactory : public BrowserPluginHostFactory {
return Singleton<TestBrowserPluginHostFactory>::get();
}
- // Waits for at least one embedder to be created in the test. Returns true if
- // we have a guest, false if waiting times out.
- void WaitForGuestManagerCreation() {
- // Check if already have created an instance.
- if (guest_manager_instance_count_ > 0)
- return;
- // Wait otherwise.
- message_loop_runner_ = new MessageLoopRunner();
- message_loop_runner_->Run();
- }
-
protected:
- TestBrowserPluginHostFactory() : guest_manager_instance_count_(0) {}
+ TestBrowserPluginHostFactory() {}
virtual ~TestBrowserPluginHostFactory() {}
private:
@@ -149,7 +129,6 @@ class TestBrowserPluginHostFactory : public BrowserPluginHostFactory {
friend struct DefaultSingletonTraits<TestBrowserPluginHostFactory>;
scoped_refptr<MessageLoopRunner> message_loop_runner_;
- int guest_manager_instance_count_;
DISALLOW_COPY_AND_ASSIGN(TestBrowserPluginHostFactory);
};
@@ -236,8 +215,6 @@ class BrowserPluginHostTest : public ContentBrowserTest {
TestBrowserPluginHostFactory::GetInstance());
BrowserPluginGuest::set_factory_for_testing(
TestBrowserPluginHostFactory::GetInstance());
- BrowserPluginGuestManager::set_factory_for_testing(
- TestBrowserPluginHostFactory::GetInstance());
ContentBrowserTest::SetUp();
}
virtual void TearDown() OVERRIDE {
@@ -313,20 +290,17 @@ class BrowserPluginHostTest : public ContentBrowserTest {
rfh, base::StringPrintf("SetSrc('%s');", guest_url.c_str()));
}
- // Wait to make sure embedder is created/attached to WebContents.
- TestBrowserPluginHostFactory::GetInstance()->WaitForGuestManagerCreation();
-
test_embedder_ = static_cast<TestBrowserPluginEmbedder*>(
embedder_web_contents->GetBrowserPluginEmbedder());
ASSERT_TRUE(test_embedder_);
- test_guest_manager_ = static_cast<TestBrowserPluginGuestManager*>(
- BrowserPluginGuestManager::FromBrowserContext(
- test_embedder_->GetWebContents()->GetBrowserContext()));
- ASSERT_TRUE(test_guest_manager_);
+ test_guest_manager_ =
+ static_cast<TestGuestManagerDelegate*>(
+ embedder_web_contents->GetBrowserContext()->
+ GetGuestManagerDelegate());
- WebContentsImpl* test_guest_web_contents = static_cast<WebContentsImpl*>(
- test_guest_manager_->WaitForGuestAdded());
+ WebContentsImpl* test_guest_web_contents =
+ test_guest_manager_->WaitForGuestAdded();
test_guest_ = static_cast<TestBrowserPluginGuest*>(
test_guest_web_contents->GetBrowserPluginGuest());
@@ -335,14 +309,14 @@ class BrowserPluginHostTest : public ContentBrowserTest {
TestBrowserPluginEmbedder* test_embedder() const { return test_embedder_; }
TestBrowserPluginGuest* test_guest() const { return test_guest_; }
- TestBrowserPluginGuestManager* test_guest_manager() const {
+ TestGuestManagerDelegate* test_guest_manager() const {
return test_guest_manager_;
}
private:
TestBrowserPluginEmbedder* test_embedder_;
TestBrowserPluginGuest* test_guest_;
- TestBrowserPluginGuestManager* test_guest_manager_;
+ TestGuestManagerDelegate* test_guest_manager_;
DISALLOW_COPY_AND_ASSIGN(BrowserPluginHostTest);
};
diff --git a/content/browser/browser_plugin/browser_plugin_host_factory.h b/content/browser/browser_plugin/browser_plugin_host_factory.h
index b347100..e368fd4 100644
--- a/content/browser/browser_plugin/browser_plugin_host_factory.h
+++ b/content/browser/browser_plugin/browser_plugin_host_factory.h
@@ -23,9 +23,6 @@ class WebContentsImpl;
// Factory to create BrowserPlugin embedder and guest.
class CONTENT_EXPORT BrowserPluginHostFactory {
public:
- virtual BrowserPluginGuestManager* CreateBrowserPluginGuestManager(
- BrowserContext* context) = 0;
-
virtual BrowserPluginGuest* CreateBrowserPluginGuest(
int instance_id,
WebContentsImpl* web_contents) = 0;
diff --git a/content/browser/browser_plugin/browser_plugin_message_filter.cc b/content/browser/browser_plugin/browser_plugin_message_filter.cc
index 512f8a7..93d58d9 100644
--- a/content/browser/browser_plugin/browser_plugin_message_filter.cc
+++ b/content/browser/browser_plugin/browser_plugin_message_filter.cc
@@ -6,7 +6,6 @@
#include "base/supports_user_data.h"
#include "content/browser/browser_plugin/browser_plugin_guest.h"
-#include "content/browser/browser_plugin/browser_plugin_guest_manager.h"
#include "content/browser/gpu/gpu_process_host.h"
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/common/browser_plugin/browser_plugin_constants.h"
@@ -14,6 +13,7 @@
#include "content/common/gpu/gpu_messages.h"
#include "content/common/view_messages.h"
#include "content/public/browser/browser_context.h"
+#include "content/public/browser/browser_plugin_guest_manager_delegate.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_view_host.h"
@@ -36,10 +36,7 @@ bool BrowserPluginMessageFilter::OnMessageReceived(
// Any message requested by a BrowserPluginGuest should be routed through
// a BrowserPluginGuestManager.
if (BrowserPluginGuest::ShouldForwardToBrowserPluginGuest(message)) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- BrowserPluginGuestManager* guest_manager = GetBrowserPluginGuestManager();
- if (guest_manager)
- guest_manager->OnMessageReceived(message, render_process_id_);
+ ForwardMessageToGuest(message);
// We always swallow messages destined for BrowserPluginGuestManager because
// we're on the UI thread and fallback code is expected to be run on the IO
// thread.
@@ -65,18 +62,33 @@ void BrowserPluginMessageFilter::OverrideThreadForMessage(
*thread = BrowserThread::UI;
}
-BrowserPluginGuestManager*
- BrowserPluginMessageFilter::GetBrowserPluginGuestManager() {
+static void BrowserPluginGuestMessageCallback(const IPC::Message& message,
+ WebContents* guest_web_contents) {
+ if (!guest_web_contents)
+ return;
+ static_cast<WebContentsImpl*>(guest_web_contents)->GetBrowserPluginGuest()->
+ OnMessageReceivedFromEmbedder(message);
+}
+
+void BrowserPluginMessageFilter::ForwardMessageToGuest(
+ const IPC::Message& message) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
RenderProcessHostImpl* host = static_cast<RenderProcessHostImpl*>(
RenderProcessHost::FromID(render_process_id_));
if (!host)
- return NULL;
+ return;
- BrowserContext* browser_context = host->GetBrowserContext();
- return static_cast<BrowserPluginGuestManager*>(
- browser_context->GetUserData(
- browser_plugin::kBrowserPluginGuestManagerKeyName));
+ int instance_id = 0;
+ // All allowed messages must have instance_id as their first parameter.
+ PickleIterator iter(message);
+ bool success = iter.ReadInt(&instance_id);
+ DCHECK(success);
+ host->GetBrowserContext()->GetGuestManagerDelegate()->
+ MaybeGetGuestByInstanceIDOrKill(
+ instance_id,
+ render_process_id_,
+ base::Bind(&BrowserPluginGuestMessageCallback,
+ message));
}
void BrowserPluginMessageFilter::OnSwapBuffersACK(
diff --git a/content/browser/browser_plugin/browser_plugin_message_filter.h b/content/browser/browser_plugin/browser_plugin_message_filter.h
index 778b3b4..8e51253 100644
--- a/content/browser/browser_plugin/browser_plugin_message_filter.h
+++ b/content/browser/browser_plugin/browser_plugin_message_filter.h
@@ -12,7 +12,6 @@ struct FrameHostMsg_BuffersSwappedACK_Params;
namespace content {
class BrowserContext;
-class BrowserPluginGuestManager;
// This class filters out incoming IPC messages for the guest renderer process
// on the IPC thread before other message filters handle them.
@@ -34,7 +33,7 @@ class BrowserPluginMessageFilter : public BrowserMessageFilter {
virtual ~BrowserPluginMessageFilter();
- BrowserPluginGuestManager* GetBrowserPluginGuestManager();
+ void ForwardMessageToGuest(const IPC::Message& message);
void OnSwapBuffersACK(const FrameHostMsg_BuffersSwappedACK_Params& params);
diff --git a/content/browser/browser_plugin/test_browser_plugin_guest_manager.cc b/content/browser/browser_plugin/test_browser_plugin_guest_manager.cc
deleted file mode 100644
index e9090fa..0000000
--- a/content/browser/browser_plugin/test_browser_plugin_guest_manager.cc
+++ /dev/null
@@ -1,55 +0,0 @@
-// Copyright (c) 2013 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#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"
-
-namespace content {
-
-TestBrowserPluginGuestManager::TestBrowserPluginGuestManager(
- BrowserContext* context)
- : BrowserPluginGuestManager(context),
- last_guest_added_(NULL) {
-}
-
-TestBrowserPluginGuestManager::~TestBrowserPluginGuestManager() {
-}
-
-BrowserPluginGuest* TestBrowserPluginGuestManager::CreateGuest(
- SiteInstance* embedder_site_instance,
- int instance_id,
- 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() {
- // Check if guests were already created.
- if (last_guest_added_) {
- WebContents* last_guest_added = last_guest_added_;
- last_guest_added_ = NULL;
- return last_guest_added;
- }
- // Wait otherwise.
- message_loop_runner_ = new MessageLoopRunner();
- message_loop_runner_->Run();
- WebContents* last_guest_added = last_guest_added_;
- last_guest_added_ = NULL;
- return last_guest_added;
-}
-
-} // namespace content
diff --git a/content/browser/browser_plugin/test_browser_plugin_guest_manager.h b/content/browser/browser_plugin/test_browser_plugin_guest_manager.h
deleted file mode 100644
index cb5da41..0000000
--- a/content/browser/browser_plugin/test_browser_plugin_guest_manager.h
+++ /dev/null
@@ -1,50 +0,0 @@
-// Copyright (c) 2013 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CONTENT_BROWSER_BROWSER_PLUGIN_TEST_BROWSER_PLUGIN_GUEST_MANAGER_H_
-#define CONTENT_BROWSER_BROWSER_PLUGIN_TEST_BROWSER_PLUGIN_GUEST_MANAGER_H_
-
-#include "base/compiler_specific.h"
-#include "base/gtest_prod_util.h"
-#include "content/browser/browser_plugin/browser_plugin_guest_manager.h"
-#include "content/public/test/test_utils.h"
-
-FORWARD_DECLARE_TEST(BrowserPluginHostTest, ReloadEmbedder);
-
-namespace content {
-
-class WebContentsImpl;
-
-// Test class for BrowserPluginGuestManager.
-//
-// Provides utilities to wait for certain state/messages in
-// BrowserPluginGuestManager to be used in tests.
-class TestBrowserPluginGuestManager : public BrowserPluginGuestManager {
- public:
- 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();
-
- private:
- // BrowserPluginHostTest.ReloadEmbedder needs access to the GuestInstanceMap.
- FRIEND_TEST_ALL_PREFIXES(BrowserPluginHostTest, ReloadEmbedder);
-
- WebContents* last_guest_added_;
- scoped_refptr<MessageLoopRunner> message_loop_runner_;
- DISALLOW_COPY_AND_ASSIGN(TestBrowserPluginGuestManager);
-};
-
-} // namespace content
-
-#endif // CONTENT_BROWSER_BROWSER_PLUGIN_TEST_BROWSER_PLUGIN_GUEST_MANAGER_H_
diff --git a/content/browser/browser_plugin/test_guest_manager_delegate.cc b/content/browser/browser_plugin/test_guest_manager_delegate.cc
index 32b863a..2cfdb0e 100644
--- a/content/browser/browser_plugin/test_guest_manager_delegate.cc
+++ b/content/browser/browser_plugin/test_guest_manager_delegate.cc
@@ -8,10 +8,12 @@
#include "base/memory/singleton.h"
#include "base/strings/stringprintf.h"
#include "base/values.h"
+#include "content/browser/web_contents/web_contents_impl.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 "content/public/test/test_utils.h"
#include "net/base/escape.h"
namespace content {
@@ -38,7 +40,8 @@ class GuestWebContentsObserver
};
TestGuestManagerDelegate::TestGuestManagerDelegate()
- : next_instance_id_(0) {
+ : last_guest_added_(NULL),
+ next_instance_id_(0) {
}
TestGuestManagerDelegate::~TestGuestManagerDelegate() {
@@ -49,6 +52,21 @@ TestGuestManagerDelegate* TestGuestManagerDelegate::GetInstance() {
return Singleton<TestGuestManagerDelegate>::get();
}
+WebContentsImpl* TestGuestManagerDelegate::WaitForGuestAdded() {
+ // Check if guests were already created.
+ if (last_guest_added_) {
+ WebContentsImpl* last_guest_added = last_guest_added_;
+ last_guest_added_ = NULL;
+ return last_guest_added;
+ }
+ // Wait otherwise.
+ message_loop_runner_ = new MessageLoopRunner();
+ message_loop_runner_->Run();
+ WebContentsImpl* last_guest_added = last_guest_added_;
+ last_guest_added_ = NULL;
+ return last_guest_added;
+}
+
content::WebContents* TestGuestManagerDelegate::CreateGuest(
SiteInstance* embedder_site_instance,
int instance_id,
@@ -98,6 +116,9 @@ void TestGuestManagerDelegate::AddGuest(
guest_web_contents_by_instance_id_.end());
guest_web_contents_by_instance_id_[guest_instance_id] = guest_web_contents;
new GuestWebContentsObserver(guest_web_contents);
+ last_guest_added_ = static_cast<WebContentsImpl*>(guest_web_contents);
+ if (message_loop_runner_)
+ message_loop_runner_->Quit();
}
void TestGuestManagerDelegate::RemoveGuest(
diff --git a/content/browser/browser_plugin/test_guest_manager_delegate.h b/content/browser/browser_plugin/test_guest_manager_delegate.h
index 9e5915c..3adcee1 100644
--- a/content/browser/browser_plugin/test_guest_manager_delegate.h
+++ b/content/browser/browser_plugin/test_guest_manager_delegate.h
@@ -12,6 +12,9 @@
namespace content {
+class MessageLoopRunner;
+class WebContentsImpl;
+
// This class is temporary until BrowserPluginHostTest.* tests are entirely
// moved out of content.
class TestGuestManagerDelegate : public BrowserPluginGuestManagerDelegate {
@@ -24,6 +27,9 @@ class TestGuestManagerDelegate : public BrowserPluginGuestManagerDelegate {
void RemoveGuest(int guest_instance_id);
SiteInstance* GetGuestSiteInstance(const GURL& guest_site);
+ // Waits until at least one guest is added to this guest manager.
+ WebContentsImpl* WaitForGuestAdded();
+
// BrowserPluginGuestManagerDelegate implementation.
virtual content::WebContents* CreateGuest(
content::SiteInstance* embedder_site_instance,
@@ -42,11 +48,13 @@ class TestGuestManagerDelegate : public BrowserPluginGuestManagerDelegate {
private:
friend struct DefaultSingletonTraits<TestGuestManagerDelegate>;
TestGuestManagerDelegate();
+
// Contains guests' WebContents, mapping from their instance ids.
typedef std::map<int, WebContents*> GuestInstanceMap;
GuestInstanceMap guest_web_contents_by_instance_id_;
-
+ WebContentsImpl* last_guest_added_;
int next_instance_id_;
+ scoped_refptr<MessageLoopRunner> message_loop_runner_;
DISALLOW_COPY_AND_ASSIGN(TestGuestManagerDelegate);
};