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 @@
#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"
#include "content/common/browser_plugin/browser_plugin_constants.h"
#include "content/common/browser_plugin/browser_plugin_messages.h"
......@@ -22,6 +23,7 @@
#include "content/public/common/result_codes.h"
#include "content/public/common/url_constants.h"
#include "net/base/escape.h"
#include "ui/events/keycodes/keyboard_codes.h"
namespace content {
......@@ -79,15 +81,42 @@ void BrowserPluginEmbedder::GetRenderViewHostAtPosition(
++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() {
GetBrowserPluginGuestManager()->DidSendScreenRects(
static_cast<WebContentsImpl*>(web_contents()));
WebContentsImpl* embedder =
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(
const NativeWebKeyboardEvent& event) {
return GetBrowserPluginGuestManager()->UnlockMouseIfNecessary(
static_cast<WebContentsImpl*>(web_contents()), event);
if ((event.type != blink::WebInputEvent::RawKeyDown) ||
(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) {
......
......@@ -98,6 +98,11 @@ class CONTENT_EXPORT BrowserPluginEmbedder : public WebContentsObserver {
BrowserPluginGuestManager* GetBrowserPluginGuestManager();
bool DidSendScreenRectsCallback(BrowserPluginGuest* guest);
bool UnlockMouseIfNecessaryCallback(const NativeWebKeyboardEvent& event,
BrowserPluginGuest* guest);
// Message handlers.
void OnAllocateInstanceID(int request_id);
......
......@@ -17,7 +17,6 @@
#include "content/public/common/url_constants.h"
#include "content/public/common/url_utils.h"
#include "net/base/escape.h"
#include "ui/events/keycodes/keyboard_codes.h"
namespace content {
......@@ -224,40 +223,17 @@ void BrowserPluginGuestManager::OnUnhandledSwapBuffersACK(
params.sync_point);
}
void BrowserPluginGuestManager::DidSendScreenRects(
WebContentsImpl* embedder_web_contents) {
// TODO(lazyboy): Generalize iterating over guest instances and performing
// actions on the guests.
bool BrowserPluginGuestManager::ForEachGuest(
WebContentsImpl* embedder_web_contents, const GuestCallback& callback) {
for (GuestInstanceMap::iterator it =
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();
if (embedder_web_contents == guest->embedder_web_contents()) {
static_cast<RenderViewHostImpl*>(
guest->GetWebContents()->GetRenderViewHost())->SendScreenRects();
}
}
}
if (embedder_web_contents != guest->embedder_web_contents())
continue;
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
// 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;
}
if (callback.Run(guest))
return true;
}
return false;
}
......
......@@ -37,7 +37,6 @@ class RenderWidgetHostImpl;
class SiteInstance;
class WebContents;
class WebContentsImpl;
struct NativeWebKeyboardEvent;
// WARNING: All APIs should be guarded with a process ID check like
// CanEmbedderAccessInstanceIDMaybeKill, to prevent abuse by normal renderer
......@@ -87,10 +86,9 @@ class CONTENT_EXPORT BrowserPluginGuestManager :
bool CanEmbedderAccessInstanceIDMaybeKill(int embedder_render_process_id,
int instance_id) const;
void DidSendScreenRects(WebContentsImpl* embedder_web_contents);
bool UnlockMouseIfNecessary(WebContentsImpl* embedder_web_contents_,
const NativeWebKeyboardEvent& event);
typedef base::Callback<bool(BrowserPluginGuest*)> GuestCallback;
bool ForEachGuest(WebContentsImpl* embedder_web_contents,
const GuestCallback& callback);
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