Commit aa1e74ff authored by fsamuel@chromium.org's avatar fsamuel@chromium.org

BrowserPlugin: Implemented BrowserPluginGuestManager::ForEachGuest

Use this pattern to replace existing methods in BrowserPluginGuestManager. This CL is just a refactor, there is no change in functionality.

BUG=330843

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@243893 0039d316-1c4b-4281-b951-d872f2087c98
parent 00b8a1d1
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "content/browser/browser_plugin/browser_plugin_guest.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_guest_manager.h"
#include "content/browser/browser_plugin/browser_plugin_host_factory.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/browser/web_contents/web_contents_impl.h"
#include "content/common/browser_plugin/browser_plugin_constants.h" #include "content/common/browser_plugin/browser_plugin_constants.h"
#include "content/common/browser_plugin/browser_plugin_messages.h" #include "content/common/browser_plugin/browser_plugin_messages.h"
...@@ -22,6 +23,7 @@ ...@@ -22,6 +23,7 @@
#include "content/public/common/result_codes.h" #include "content/public/common/result_codes.h"
#include "content/public/common/url_constants.h" #include "content/public/common/url_constants.h"
#include "net/base/escape.h" #include "net/base/escape.h"
#include "ui/events/keycodes/keyboard_codes.h"
namespace content { namespace content {
...@@ -79,15 +81,42 @@ void BrowserPluginEmbedder::GetRenderViewHostAtPosition( ...@@ -79,15 +81,42 @@ void BrowserPluginEmbedder::GetRenderViewHostAtPosition(
++next_get_render_view_request_id_; ++next_get_render_view_request_id_;
} }
bool BrowserPluginEmbedder::DidSendScreenRectsCallback(
BrowserPluginGuest* guest) {
static_cast<RenderViewHostImpl*>(
guest->GetWebContents()->GetRenderViewHost())->SendScreenRects();
// Not handled => Iterate over all guests.
return false;
}
void BrowserPluginEmbedder::DidSendScreenRects() { void BrowserPluginEmbedder::DidSendScreenRects() {
GetBrowserPluginGuestManager()->DidSendScreenRects( WebContentsImpl* embedder =
static_cast<WebContentsImpl*>(web_contents())); static_cast<WebContentsImpl*>(web_contents());
GetBrowserPluginGuestManager()->ForEachGuest(embedder, base::Bind(
&BrowserPluginEmbedder::DidSendScreenRectsCallback,
base::Unretained(this)));
}
bool BrowserPluginEmbedder::UnlockMouseIfNecessaryCallback(
const NativeWebKeyboardEvent& event,
BrowserPluginGuest* guest) {
return guest->UnlockMouseIfNecessary(event);
} }
bool BrowserPluginEmbedder::HandleKeyboardEvent( bool BrowserPluginEmbedder::HandleKeyboardEvent(
const NativeWebKeyboardEvent& event) { const NativeWebKeyboardEvent& event) {
return GetBrowserPluginGuestManager()->UnlockMouseIfNecessary( if ((event.type != blink::WebInputEvent::RawKeyDown) ||
static_cast<WebContentsImpl*>(web_contents()), event); (event.windowsKeyCode != ui::VKEY_ESCAPE) ||
(event.modifiers & blink::WebInputEvent::InputModifiers)) {
return false;
}
WebContentsImpl* embedder =
static_cast<WebContentsImpl*>(web_contents());
return GetBrowserPluginGuestManager()->ForEachGuest(embedder, base::Bind(
&BrowserPluginEmbedder::UnlockMouseIfNecessaryCallback,
base::Unretained(this),
event));
} }
void BrowserPluginEmbedder::RenderProcessGone(base::TerminationStatus status) { void BrowserPluginEmbedder::RenderProcessGone(base::TerminationStatus status) {
......
...@@ -98,6 +98,11 @@ class CONTENT_EXPORT BrowserPluginEmbedder : public WebContentsObserver { ...@@ -98,6 +98,11 @@ class CONTENT_EXPORT BrowserPluginEmbedder : public WebContentsObserver {
BrowserPluginGuestManager* GetBrowserPluginGuestManager(); BrowserPluginGuestManager* GetBrowserPluginGuestManager();
bool DidSendScreenRectsCallback(BrowserPluginGuest* guest);
bool UnlockMouseIfNecessaryCallback(const NativeWebKeyboardEvent& event,
BrowserPluginGuest* guest);
// Message handlers. // Message handlers.
void OnAllocateInstanceID(int request_id); void OnAllocateInstanceID(int request_id);
......
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
#include "content/public/common/url_constants.h" #include "content/public/common/url_constants.h"
#include "content/public/common/url_utils.h" #include "content/public/common/url_utils.h"
#include "net/base/escape.h" #include "net/base/escape.h"
#include "ui/events/keycodes/keyboard_codes.h"
namespace content { namespace content {
...@@ -224,41 +223,18 @@ void BrowserPluginGuestManager::OnUnhandledSwapBuffersACK( ...@@ -224,41 +223,18 @@ void BrowserPluginGuestManager::OnUnhandledSwapBuffersACK(
params.sync_point); params.sync_point);
} }
void BrowserPluginGuestManager::DidSendScreenRects( bool BrowserPluginGuestManager::ForEachGuest(
WebContentsImpl* embedder_web_contents) { WebContentsImpl* embedder_web_contents, const GuestCallback& callback) {
// TODO(lazyboy): Generalize iterating over guest instances and performing
// actions on the guests.
for (GuestInstanceMap::iterator it = for (GuestInstanceMap::iterator it =
guest_web_contents_by_instance_id_.begin(); guest_web_contents_by_instance_id_.begin();
it != guest_web_contents_by_instance_id_.end(); ++it) { it != guest_web_contents_by_instance_id_.end(); ++it) {
BrowserPluginGuest* guest = it->second->GetBrowserPluginGuest(); BrowserPluginGuest* guest = it->second->GetBrowserPluginGuest();
if (embedder_web_contents == guest->embedder_web_contents()) { if (embedder_web_contents != guest->embedder_web_contents())
static_cast<RenderViewHostImpl*>( continue;
guest->GetWebContents()->GetRenderViewHost())->SendScreenRects();
}
}
}
bool BrowserPluginGuestManager::UnlockMouseIfNecessary(
WebContentsImpl* embedder_web_contents,
const NativeWebKeyboardEvent& event) {
if ((event.type != blink::WebInputEvent::RawKeyDown) ||
(event.windowsKeyCode != ui::VKEY_ESCAPE) ||
(event.modifiers & blink::WebInputEvent::InputModifiers)) {
return false;
}
// TODO(lazyboy): Generalize iterating over guest instances and performing if (callback.Run(guest))
// actions on the guests.
for (GuestInstanceMap::iterator it =
guest_web_contents_by_instance_id_.begin();
it != guest_web_contents_by_instance_id_.end(); ++it) {
BrowserPluginGuest* guest = it->second->GetBrowserPluginGuest();
if (embedder_web_contents == guest->embedder_web_contents()) {
if (guest->UnlockMouseIfNecessary(event))
return true; return true;
} }
}
return false; return false;
} }
......
...@@ -37,7 +37,6 @@ class RenderWidgetHostImpl; ...@@ -37,7 +37,6 @@ class RenderWidgetHostImpl;
class SiteInstance; class SiteInstance;
class WebContents; class WebContents;
class WebContentsImpl; class WebContentsImpl;
struct NativeWebKeyboardEvent;
// WARNING: All APIs should be guarded with a process ID check like // WARNING: All APIs should be guarded with a process ID check like
// CanEmbedderAccessInstanceIDMaybeKill, to prevent abuse by normal renderer // CanEmbedderAccessInstanceIDMaybeKill, to prevent abuse by normal renderer
...@@ -87,10 +86,9 @@ class CONTENT_EXPORT BrowserPluginGuestManager : ...@@ -87,10 +86,9 @@ class CONTENT_EXPORT BrowserPluginGuestManager :
bool CanEmbedderAccessInstanceIDMaybeKill(int embedder_render_process_id, bool CanEmbedderAccessInstanceIDMaybeKill(int embedder_render_process_id,
int instance_id) const; int instance_id) const;
void DidSendScreenRects(WebContentsImpl* embedder_web_contents); typedef base::Callback<bool(BrowserPluginGuest*)> GuestCallback;
bool ForEachGuest(WebContentsImpl* embedder_web_contents,
bool UnlockMouseIfNecessary(WebContentsImpl* embedder_web_contents_, const GuestCallback& callback);
const NativeWebKeyboardEvent& event);
void OnMessageReceived(const IPC::Message& message, int render_process_id); void OnMessageReceived(const IPC::Message& message, int render_process_id);
......
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