summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfsamuel@chromium.org <fsamuel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-12-20 01:02:54 +0000
committerfsamuel@chromium.org <fsamuel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-12-20 01:02:54 +0000
commit3997b1b2d067f9b3a4d5214e5585b19bfca3c72c (patch)
treece1acd55dc2e4fb41ca85dcb6985cd382c9fdc6c
parentacaf7c04e85fabf9f5aa6ed8e5a0d208a4a79b65 (diff)
downloadchromium_src-3997b1b2d067f9b3a4d5214e5585b19bfca3c72c.zip
chromium_src-3997b1b2d067f9b3a4d5214e5585b19bfca3c72c.tar.gz
chromium_src-3997b1b2d067f9b3a4d5214e5585b19bfca3c72c.tar.bz2
Browser Plugin: Simplify BrowserPluginHostMsg_* message routing
1. Remove BrowserPluginEmbedderHelper as its no longer needed (we assume that the lifetime of the BrowserPlugin is strictly less than the lifetime of the embedder's RenderViewHost). 2. Move the bulk of BrowserPluginHostMsg_* message handling to BrowserPluginGuest. BUG=166165 Test=BrowserPluginHostTest.* Review URL: https://chromiumcodereview.appspot.com/11616008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@174063 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--content/browser/browser_plugin/browser_plugin_embedder.cc331
-rw-r--r--content/browser/browser_plugin/browser_plugin_embedder.h105
-rw-r--r--content/browser/browser_plugin/browser_plugin_embedder_helper.cc171
-rw-r--r--content/browser/browser_plugin/browser_plugin_embedder_helper.h107
-rw-r--r--content/browser/browser_plugin/browser_plugin_guest.cc354
-rw-r--r--content/browser/browser_plugin/browser_plugin_guest.h126
-rw-r--r--content/browser/browser_plugin/browser_plugin_host_browsertest.cc1
-rw-r--r--content/browser/browser_plugin/test_browser_plugin_guest.cc26
-rw-r--r--content/browser/browser_plugin/test_browser_plugin_guest.h13
-rw-r--r--content/browser/web_contents/web_contents_impl.cc8
-rw-r--r--content/content_browser.gypi2
11 files changed, 454 insertions, 790 deletions
diff --git a/content/browser/browser_plugin/browser_plugin_embedder.cc b/content/browser/browser_plugin/browser_plugin_embedder.cc
index ce7b012..ade5081 100644
--- a/content/browser/browser_plugin/browser_plugin_embedder.cc
+++ b/content/browser/browser_plugin/browser_plugin_embedder.cc
@@ -5,23 +5,20 @@
#include "content/browser/browser_plugin/browser_plugin_embedder.h"
#include "base/stl_util.h"
-#include "content/browser/browser_plugin/browser_plugin_embedder_helper.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_messages.h"
+#include "content/common/gpu/gpu_messages.h"
#include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_source.h"
#include "content/public/browser/notification_types.h"
-#include "content/public/browser/render_widget_host_view.h"
#include "content/public/browser/user_metrics.h"
#include "content/public/common/result_codes.h"
#include "content/public/common/url_constants.h"
#include "net/base/escape.h"
-#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
-#include "ui/gfx/size.h"
namespace content {
@@ -40,9 +37,6 @@ BrowserPluginEmbedder::BrowserPluginEmbedder(
registrar_.Add(this,
NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
Source<WebContents>(web_contents));
-
- // |render_view_host| manages the ownership of this BrowserPluginGuestHelper.
- new BrowserPluginEmbedderHelper(this, render_view_host);
}
BrowserPluginEmbedder::~BrowserPluginEmbedder() {
@@ -60,6 +54,69 @@ BrowserPluginEmbedder* BrowserPluginEmbedder::Create(
return new BrowserPluginEmbedder(web_contents, render_view_host);
}
+void BrowserPluginEmbedder::GetRenderViewHostAtPosition(
+ int x, int y, const WebContents::GetRenderViewHostCallback& callback) {
+ // Store the callback so we can call it later when we have the response.
+ pending_get_render_view_callbacks_.insert(
+ std::make_pair(next_get_render_view_request_id_, callback));
+ render_view_host_->Send(
+ new BrowserPluginMsg_PluginAtPositionRequest(
+ render_view_host_->GetRoutingID(),
+ next_get_render_view_request_id_,
+ gfx::Point(x, y)));
+ ++next_get_render_view_request_id_;
+}
+
+void BrowserPluginEmbedder::RenderViewDeleted(
+ RenderViewHost* render_view_host) {
+}
+
+void BrowserPluginEmbedder::RenderViewGone(base::TerminationStatus status) {
+ CleanUp();
+}
+
+bool BrowserPluginEmbedder::OnMessageReceived(const IPC::Message& message) {
+ if (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);
+ BrowserPluginGuest* guest = GetGuestByInstanceID(instance_id);
+ if (guest && guest->OnMessageReceivedFromEmbedder(message))
+ return true;
+ }
+ bool handled = true;
+ IPC_BEGIN_MESSAGE_MAP(BrowserPluginEmbedder, message)
+ IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_CreateGuest,
+ OnCreateGuest)
+ IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_NavigateGuest,
+ OnNavigateGuest)
+ IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_PluginAtPositionResponse,
+ OnPluginAtPositionResponse)
+ IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_PluginDestroyed,
+ OnPluginDestroyed)
+ IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_BuffersSwappedACK,
+ OnSwapBuffersACK)
+ IPC_MESSAGE_UNHANDLED(handled = false)
+ IPC_END_MESSAGE_MAP()
+ return handled;
+}
+
+void BrowserPluginEmbedder::Observe(int type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
+ switch (type) {
+ case NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED: {
+ bool visible = *Details<bool>(details).ptr();
+ WebContentsVisibilityChanged(visible);
+ break;
+ }
+ default:
+ NOTREACHED() << "Unexpected notification type: " << type;
+ }
+}
+
BrowserPluginGuest* BrowserPluginEmbedder::GetGuestByInstanceID(
int instance_id) const {
ContainerInstanceMap::const_iterator it =
@@ -76,8 +133,65 @@ void BrowserPluginEmbedder::AddGuest(int instance_id,
guest_web_contents_by_instance_id_[instance_id] = guest_web_contents;
}
-void BrowserPluginEmbedder::CreateGuest(
- RenderViewHost* render_view_host,
+void BrowserPluginEmbedder::DestroyGuestByInstanceID(int instance_id) {
+ BrowserPluginGuest* guest = GetGuestByInstanceID(instance_id);
+ if (guest) {
+ WebContents* guest_web_contents = guest->GetWebContents();
+
+ // Destroy the guest's web_contents.
+ delete guest_web_contents;
+ guest_web_contents_by_instance_id_.erase(instance_id);
+ }
+}
+
+void BrowserPluginEmbedder::CleanUp() {
+ // Destroy guests that are managed by the current embedder.
+ STLDeleteContainerPairSecondPointers(
+ guest_web_contents_by_instance_id_.begin(),
+ guest_web_contents_by_instance_id_.end());
+ guest_web_contents_by_instance_id_.clear();
+
+ // CleanUp gets called when BrowserPluginEmbedder's WebContents goes away
+ // or the associated RenderViewHost is destroyed or swapped out. Therefore we
+ // don't need to care about the pending callbacks anymore.
+ pending_get_render_view_callbacks_.clear();
+}
+
+void BrowserPluginEmbedder::WebContentsVisibilityChanged(bool visible) {
+ visible_ = visible;
+ // If the embedder is hidden we need to hide the guests as well.
+ for (ContainerInstanceMap::const_iterator it =
+ guest_web_contents_by_instance_id_.begin();
+ it != guest_web_contents_by_instance_id_.end(); ++it) {
+ WebContentsImpl* web_contents = static_cast<WebContentsImpl*>(it->second);
+ BrowserPluginGuest* guest = web_contents->GetBrowserPluginGuest();
+ guest->UpdateVisibility();
+ }
+}
+
+// static
+bool BrowserPluginEmbedder::ShouldForwardToBrowserPluginGuest(
+ const IPC::Message& message) {
+ switch (message.type()) {
+ case BrowserPluginHostMsg_DragStatusUpdate::ID:
+ case BrowserPluginHostMsg_Go::ID:
+ case BrowserPluginHostMsg_HandleInputEvent::ID:
+ case BrowserPluginHostMsg_Reload::ID:
+ case BrowserPluginHostMsg_ResizeGuest::ID:
+ case BrowserPluginHostMsg_SetAutoSize::ID:
+ case BrowserPluginHostMsg_SetFocus::ID:
+ case BrowserPluginHostMsg_SetVisibility::ID:
+ case BrowserPluginHostMsg_Stop::ID:
+ case BrowserPluginHostMsg_TerminateGuest::ID:
+ case BrowserPluginHostMsg_UpdateRect_ACK::ID:
+ return true;
+ default:
+ break;
+ }
+ return false;
+}
+
+void BrowserPluginEmbedder::OnCreateGuest(
int instance_id,
const BrowserPluginHostMsg_CreateGuest_Params& params) {
WebContentsImpl* guest_web_contents = NULL;
@@ -90,13 +204,13 @@ void BrowserPluginEmbedder::CreateGuest(
// renderer process.
if (!IsStringUTF8(params.storage_partition_id)) {
content::RecordAction(UserMetricsAction("BadMessageTerminate_BPE"));
- base::KillProcess(render_view_host->GetProcess()->GetHandle(),
+ base::KillProcess(render_view_host_->GetProcess()->GetHandle(),
content::RESULT_CODE_KILLED_BAD_MESSAGE, false);
return;
}
const std::string& host =
- render_view_host->GetSiteInstance()->GetSiteURL().host();
+ render_view_host_->GetSiteInstance()->GetSiteURL().host();
std::string url_encoded_partition = net::EscapeQueryParamValue(
params.storage_partition_id, false);
@@ -161,14 +275,13 @@ void BrowserPluginEmbedder::CreateGuest(
int guest_routing_id =
static_cast<WebContentsImpl*>(guest->GetWebContents())->
CreateSwappedOutRenderView(web_contents()->GetSiteInstance());
- render_view_host->Send(new BrowserPluginMsg_GuestContentWindowReady(
- render_view_host->GetRoutingID(), instance_id, guest_routing_id));
+ render_view_host_->Send(new BrowserPluginMsg_GuestContentWindowReady(
+ render_view_host_->GetRoutingID(), instance_id, guest_routing_id));
- guest->SetSize(params.auto_size_params, params.resize_guest_params);
+ guest->Initialize(params, guest_web_contents->GetRenderViewHost());
}
-void BrowserPluginEmbedder::NavigateGuest(
- RenderViewHost* render_view_host,
+void BrowserPluginEmbedder::OnNavigateGuest(
int instance_id,
const std::string& src) {
BrowserPluginGuest* guest = GetGuestByInstanceID(instance_id);
@@ -194,165 +307,7 @@ void BrowserPluginEmbedder::NavigateGuest(
}
}
-void BrowserPluginEmbedder::UpdateRectACK(
- int instance_id,
- const BrowserPluginHostMsg_AutoSize_Params& auto_size_params,
- const BrowserPluginHostMsg_ResizeGuest_Params& resize_guest_params) {
- BrowserPluginGuest* guest = GetGuestByInstanceID(instance_id);
- if (guest)
- guest->UpdateRectACK(auto_size_params, resize_guest_params);
-}
-
-void BrowserPluginEmbedder::ResizeGuest(
- RenderViewHost* render_view_host,
- int instance_id,
- const BrowserPluginHostMsg_ResizeGuest_Params& params) {
- BrowserPluginGuest* guest = GetGuestByInstanceID(instance_id);
- if (guest)
- guest->Resize(render_view_host, params);
-}
-
-void BrowserPluginEmbedder::SetFocus(int instance_id,
- bool focused) {
- BrowserPluginGuest* guest = GetGuestByInstanceID(instance_id);
- if (guest)
- guest->SetFocus(focused);
-}
-
-void BrowserPluginEmbedder::CleanUp() {
- // Destroy guests that are managed by the current embedder.
- STLDeleteContainerPairSecondPointers(
- guest_web_contents_by_instance_id_.begin(),
- guest_web_contents_by_instance_id_.end());
- guest_web_contents_by_instance_id_.clear();
-
- // CleanUp gets called when BrowserPluginEmbedder's WebContents goes away
- // or the associated RenderViewHost is destroyed or swapped out. Therefore we
- // don't need to care about the pending callbacks anymore.
- pending_get_render_view_callbacks_.clear();
-}
-
-void BrowserPluginEmbedder::HandleInputEvent(
- int instance_id,
- RenderViewHost* render_view_host,
- const gfx::Rect& guest_window_rect,
- const WebKit::WebInputEvent& event) {
- // Convert the window coordinates into screen coordinates.
- gfx::Rect guest_screen_rect(guest_window_rect);
- guest_screen_rect.Offset(
- static_cast<RenderViewHostImpl*>(render_view_host)->GetView()->
- GetViewBounds().OffsetFromOrigin());
- BrowserPluginGuest* guest = GetGuestByInstanceID(instance_id);
- if (guest) {
- guest->HandleInputEvent(render_view_host,
- guest_window_rect,
- guest_screen_rect,
- event);
- }
-}
-
-void BrowserPluginEmbedder::DestroyGuestByInstanceID(int instance_id) {
- BrowserPluginGuest* guest = GetGuestByInstanceID(instance_id);
- if (guest) {
- WebContents* guest_web_contents = guest->GetWebContents();
-
- // Destroy the guest's web_contents.
- delete guest_web_contents;
- guest_web_contents_by_instance_id_.erase(instance_id);
- }
-}
-
-void BrowserPluginEmbedder::RenderViewDeleted(
- RenderViewHost* render_view_host) {
-}
-
-void BrowserPluginEmbedder::RenderViewGone(base::TerminationStatus status) {
- CleanUp();
-}
-
-void BrowserPluginEmbedder::WebContentsVisibilityChanged(bool visible) {
- visible_ = visible;
- // If the embedder is hidden we need to hide the guests as well.
- for (ContainerInstanceMap::const_iterator it =
- guest_web_contents_by_instance_id_.begin();
- it != guest_web_contents_by_instance_id_.end(); ++it) {
- WebContentsImpl* web_contents = static_cast<WebContentsImpl*>(it->second);
- BrowserPluginGuest* guest = web_contents->GetBrowserPluginGuest();
- guest->SetVisibility(visible, guest->visible());
- }
-}
-
-void BrowserPluginEmbedder::PluginDestroyed(int instance_id) {
- DestroyGuestByInstanceID(instance_id);
-}
-
-void BrowserPluginEmbedder::SetGuestVisibility(int instance_id,
- bool guest_visible) {
- BrowserPluginGuest* guest = GetGuestByInstanceID(instance_id);
- if (guest)
- guest->SetVisibility(visible_, guest_visible);
-}
-
-void BrowserPluginEmbedder::DragStatusUpdate(
- int instance_id,
- WebKit::WebDragStatus drag_status,
- const WebDropData& drop_data,
- WebKit::WebDragOperationsMask drag_mask,
- const gfx::Point& location) {
- BrowserPluginGuest* guest = GetGuestByInstanceID(instance_id);
- if (guest)
- guest->DragStatusUpdate(drag_status, drop_data, drag_mask, location);
-}
-
-void BrowserPluginEmbedder::SetAutoSize(
- int instance_id,
- const BrowserPluginHostMsg_AutoSize_Params& auto_size_params,
- const BrowserPluginHostMsg_ResizeGuest_Params& resize_guest_params) {
- BrowserPluginGuest* guest = GetGuestByInstanceID(instance_id);
- if (guest)
- guest->SetSize(auto_size_params, resize_guest_params);
-}
-
-void BrowserPluginEmbedder::Go(int instance_id, int relative_index) {
- BrowserPluginGuest* guest = GetGuestByInstanceID(instance_id);
- if (guest)
- guest->Go(relative_index);
-}
-
-void BrowserPluginEmbedder::Stop(int instance_id) {
- BrowserPluginGuest* guest = GetGuestByInstanceID(instance_id);
- if (guest)
- guest->Stop();
-}
-
-void BrowserPluginEmbedder::Reload(int instance_id) {
- BrowserPluginGuest* guest = GetGuestByInstanceID(instance_id);
- if (guest)
- guest->Reload();
-}
-
-void BrowserPluginEmbedder::TerminateGuest(int instance_id) {
- BrowserPluginGuest* guest = GetGuestByInstanceID(instance_id);
- if (guest)
- guest->Terminate();
-}
-
-void BrowserPluginEmbedder::GetRenderViewHostAtPosition(
- int x,
- int y,
- const WebContents::GetRenderViewHostCallback& callback) {
- // Store the callback so we can call it later when we have the response.
- pending_get_render_view_callbacks_.insert(
- std::make_pair(next_get_render_view_request_id_, callback));
- render_view_host_->Send(
- new BrowserPluginMsg_PluginAtPositionRequest(
- render_view_host_->GetRoutingID(),
- next_get_render_view_request_id_,
- gfx::Point(x, y)));
- ++next_get_render_view_request_id_;
-}
-
-void BrowserPluginEmbedder::PluginAtPositionResponse(
+void BrowserPluginEmbedder::OnPluginAtPositionResponse(
int instance_id, int request_id, const gfx::Point& position) {
const std::map<int, WebContents::GetRenderViewHostCallback>::iterator
callback_iter = pending_get_render_view_callbacks_.find(request_id);
@@ -370,18 +325,20 @@ void BrowserPluginEmbedder::PluginAtPositionResponse(
pending_get_render_view_callbacks_.erase(callback_iter);
}
-void BrowserPluginEmbedder::Observe(int type,
- const NotificationSource& source,
- const NotificationDetails& details) {
- switch (type) {
- case NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED: {
- bool visible = *Details<bool>(details).ptr();
- WebContentsVisibilityChanged(visible);
- break;
- }
- default:
- NOTREACHED() << "Unexpected notification type: " << type;
- }
+void BrowserPluginEmbedder::OnPluginDestroyed(int instance_id) {
+ DestroyGuestByInstanceID(instance_id);
+}
+
+void BrowserPluginEmbedder::OnSwapBuffersACK(int route_id,
+ int gpu_host_id,
+ uint64 surface_handle,
+ uint32 sync_point) {
+ AcceleratedSurfaceMsg_BufferPresented_Params ack_params;
+ ack_params.surface_handle = 0; // TODO
+ ack_params.sync_point = sync_point;
+ RenderWidgetHostImpl::AcknowledgeBufferPresent(route_id,
+ gpu_host_id,
+ ack_params);
}
} // namespace content
diff --git a/content/browser/browser_plugin/browser_plugin_embedder.h b/content/browser/browser_plugin/browser_plugin_embedder.h
index 1562bf0..5216ace 100644
--- a/content/browser/browser_plugin/browser_plugin_embedder.h
+++ b/content/browser/browser_plugin/browser_plugin_embedder.h
@@ -22,28 +22,16 @@
#include <map>
-#include "base/compiler_specific.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_observer.h"
-#include "third_party/WebKit/Source/WebKit/chromium/public/WebDragStatus.h"
-#include "third_party/WebKit/Source/WebKit/chromium/public/WebDragOperation.h"
-#include "ui/surface/transport_dib.h"
-#include "webkit/glue/webdropdata.h"
-struct BrowserPluginHostMsg_AutoSize_Params;
struct BrowserPluginHostMsg_CreateGuest_Params;
struct BrowserPluginHostMsg_ResizeGuest_Params;
-namespace WebKit {
-class WebInputEvent;
-}
-
namespace gfx {
class Point;
-class Rect;
-class Size;
}
namespace content {
@@ -69,74 +57,14 @@ class CONTENT_EXPORT BrowserPluginEmbedder : public WebContentsObserver,
static BrowserPluginEmbedder* Create(WebContentsImpl* web_contents,
RenderViewHost* render_view_host);
- // Creates a new guest.
- void CreateGuest(RenderViewHost* render_view_host,
- int instance_id,
- const BrowserPluginHostMsg_CreateGuest_Params& params);
-
- // Navigates in a guest (new or existing).
- void NavigateGuest(
- RenderViewHost* render_view_host,
- int instance_id,
- const std::string& src);
-
- void ResizeGuest(RenderViewHost* render_view_host,
- int instance_id,
- const BrowserPluginHostMsg_ResizeGuest_Params& params);
-
- void Go(int instance_id, int relative_index);
- void Stop(int instance_id);
- void Reload(int instance_id);
- void TerminateGuest(int instance_id);
-
- // WebContentsObserver implementation.
- virtual void RenderViewDeleted(RenderViewHost* render_view_host) OVERRIDE;
- virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE;
-
- // NotificationObserver method override.
- virtual void Observe(int type,
- const NotificationSource& source,
- const NotificationDetails& details) OVERRIDE;
-
- // Message handlers (direct/indirect via BrowserPluginEmbedderHelper).
- // Routes update rect ack message to the appropriate guest.
- void UpdateRectACK(
- int instance_id,
- const BrowserPluginHostMsg_AutoSize_Params& auto_size_params,
- const BrowserPluginHostMsg_ResizeGuest_Params& resize_guest_params);
- void SetFocus(int instance_id, bool focused);
- // Handles input events sent from the BrowserPlugin (embedder's renderer
- // process) by passing them to appropriate guest's input handler. The
- // BrowserPlugin behaves like a black hole for events, so the embedder does
- // not see them in the capture or bubble phase.
- // Currently scroll events do not propagate back to the embedder process
- // and so even if the guest discards a scroll event, it won't make its
- // way back to the embedder. This may change in the future.
- void HandleInputEvent(int instance_id,
- RenderViewHost* render_view_host,
- const gfx::Rect& guest_window_rect,
- const WebKit::WebInputEvent& event);
- void PluginDestroyed(int instance_id);
- void SetGuestVisibility(int instance_id,
- bool guest_visible);
- void DragStatusUpdate(int instance_id,
- WebKit::WebDragStatus drag_status,
- const WebDropData& drop_data,
- WebKit::WebDragOperationsMask drag_mask,
- const gfx::Point& location);
- void SetAutoSize(
- int instance_id,
- const BrowserPluginHostMsg_AutoSize_Params& auto_size_params,
- const BrowserPluginHostMsg_ResizeGuest_Params& resize_guest_params);
-
- bool visible() const { return visible_; }
-
// Overrides factory for testing. Default (NULL) value indicates regular
// (non-test) environment.
static void set_factory_for_testing(BrowserPluginHostFactory* factory) {
factory_ = factory;
}
+ bool visible() const { return visible_; }
+
// Returns the RenderViewHost at a point (|x|, |y|) asynchronously via
// |callback|. We need a roundtrip to renderer process to get this
// information.
@@ -144,9 +72,16 @@ class CONTENT_EXPORT BrowserPluginEmbedder : public WebContentsObserver,
int x,
int y,
const WebContents::GetRenderViewHostCallback& callback);
- void PluginAtPositionResponse(int instance_id,
- int request_id,
- const gfx::Point& position);
+
+ // WebContentsObserver implementation.
+ virtual void RenderViewDeleted(RenderViewHost* render_view_host) OVERRIDE;
+ virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE;
+ virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
+
+ // NotificationObserver method override.
+ virtual void Observe(int type,
+ const NotificationSource& source,
+ const NotificationDetails& details) OVERRIDE;
private:
friend class TestBrowserPluginEmbedder;
@@ -166,6 +101,22 @@ class CONTENT_EXPORT BrowserPluginEmbedder : public WebContentsObserver,
// show/hide its guest.
void WebContentsVisibilityChanged(bool visible);
+ static bool ShouldForwardToBrowserPluginGuest(const IPC::Message& message);
+
+ // Message handlers.
+
+ void OnCreateGuest(int instance_id,
+ const BrowserPluginHostMsg_CreateGuest_Params& params);
+ void OnNavigateGuest(int instance_id, const std::string& src);
+ void OnPluginAtPositionResponse(int instance_id,
+ int request_id,
+ const gfx::Point& position);
+ void OnPluginDestroyed(int instance_id);
+ void OnSwapBuffersACK(int route_id,
+ int gpu_host_id,
+ uint64 surface_handle,
+ uint32 sync_point);
+
// Static factory instance (always NULL for non-test).
static BrowserPluginHostFactory* factory_;
diff --git a/content/browser/browser_plugin/browser_plugin_embedder_helper.cc b/content/browser/browser_plugin/browser_plugin_embedder_helper.cc
deleted file mode 100644
index 1c8d438..0000000
--- a/content/browser/browser_plugin/browser_plugin_embedder_helper.cc
+++ /dev/null
@@ -1,171 +0,0 @@
-// Copyright (c) 2012 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_embedder_helper.h"
-
-#include "content/browser/browser_plugin/browser_plugin_embedder.h"
-#include "content/browser/renderer_host/render_view_host_impl.h"
-#include "content/common/browser_plugin_messages.h"
-#include "content/common/gpu/gpu_messages.h"
-#include "content/common/view_messages.h"
-#include "content/public/browser/render_process_host.h"
-#include "content/public/browser/render_view_host.h"
-#include "content/public/browser/render_widget_host_view.h"
-#include "ui/gfx/size.h"
-
-namespace content {
-
-BrowserPluginEmbedderHelper::BrowserPluginEmbedderHelper(
- BrowserPluginEmbedder* embedder,
- RenderViewHost* render_view_host)
- : RenderViewHostObserver(render_view_host),
- embedder_(embedder) {
-}
-
-BrowserPluginEmbedderHelper::~BrowserPluginEmbedderHelper() {
-}
-
-bool BrowserPluginEmbedderHelper::Send(IPC::Message* message) {
- return RenderViewHostObserver::Send(message);
-}
-
-bool BrowserPluginEmbedderHelper::OnMessageReceived(
- const IPC::Message& message) {
- bool handled = true;
- IPC_BEGIN_MESSAGE_MAP(BrowserPluginEmbedderHelper, message)
- IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_CreateGuest,
- OnCreateGuest)
- IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_NavigateGuest,
- OnNavigateGuest)
- IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ResizeGuest, OnResizeGuest)
- IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_UpdateRect_ACK, OnUpdateRectACK)
- IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetFocus, OnSetFocus)
- IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_HandleInputEvent,
- OnHandleInputEvent)
- IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_PluginDestroyed,
- OnPluginDestroyed)
- IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_Go, OnGo)
- IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_Stop, OnStop)
- IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_Reload, OnReload)
- IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_TerminateGuest, OnTerminateGuest)
- IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetVisibility,
- OnSetGuestVisibility)
- IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_DragStatusUpdate,
- OnDragStatusUpdate)
- IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetAutoSize, OnSetAutoSize)
- IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_PluginAtPositionResponse,
- OnPluginAtPositionResponse)
- IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_BuffersSwappedACK,
- OnSwapBuffersACK)
- IPC_MESSAGE_UNHANDLED(handled = false)
- IPC_END_MESSAGE_MAP()
- return handled;
-}
-
-void BrowserPluginEmbedderHelper::OnResizeGuest(
- int instance_id,
- const BrowserPluginHostMsg_ResizeGuest_Params& params) {
- embedder_->ResizeGuest(render_view_host(), instance_id, params);
-}
-
-void BrowserPluginEmbedderHelper::OnHandleInputEvent(
- int instance_id,
- const gfx::Rect& guest_window_rect,
- const WebKit::WebInputEvent* input_event) {
- RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>(
- render_view_host());
- embedder_->HandleInputEvent(instance_id,
- rvh,
- guest_window_rect,
- *input_event);
-}
-
-void BrowserPluginEmbedderHelper::OnCreateGuest(
- int instance_id,
- const BrowserPluginHostMsg_CreateGuest_Params& params) {
- // The first BrowserPluginHostMsg_CreateGuest message is handled in
- // WebContentsImpl. All subsequent BrowserPluginHostMsg_CreateGuest
- // messages are handled here.
- embedder_->CreateGuest(render_view_host(), instance_id, params);
-}
-
-void BrowserPluginEmbedderHelper::OnNavigateGuest(
- int instance_id,
- const std::string& src) {
- embedder_->NavigateGuest(render_view_host(), instance_id, src);
-}
-
-void BrowserPluginEmbedderHelper::OnUpdateRectACK(
- int instance_id,
- const BrowserPluginHostMsg_AutoSize_Params& auto_size_params,
- const BrowserPluginHostMsg_ResizeGuest_Params& resize_guest_params) {
- embedder_->UpdateRectACK(instance_id,
- auto_size_params,
- resize_guest_params);
-}
-
-void BrowserPluginEmbedderHelper::OnSwapBuffersACK(int route_id,
- int gpu_host_id,
- uint64 surface_handle,
- uint32 sync_point) {
- AcceleratedSurfaceMsg_BufferPresented_Params ack_params;
- ack_params.surface_handle = surface_handle;
- ack_params.sync_point = sync_point;
- RenderWidgetHostImpl::AcknowledgeBufferPresent(route_id,
- gpu_host_id,
- ack_params);
-}
-
-void BrowserPluginEmbedderHelper::OnSetFocus(int instance_id, bool focused) {
- embedder_->SetFocus(instance_id, focused);
-}
-
-void BrowserPluginEmbedderHelper::OnPluginAtPositionResponse(
- int instance_id, int request_id, const gfx::Point& location) {
- embedder_->PluginAtPositionResponse(instance_id, request_id, location);
-}
-
-void BrowserPluginEmbedderHelper::OnPluginDestroyed(int instance_id) {
- embedder_->PluginDestroyed(instance_id);
-}
-
-void BrowserPluginEmbedderHelper::OnGo(int instance_id, int relative_index) {
- embedder_->Go(instance_id, relative_index);
-}
-
-void BrowserPluginEmbedderHelper::OnStop(int instance_id) {
- embedder_->Stop(instance_id);
-}
-
-void BrowserPluginEmbedderHelper::OnReload(int instance_id) {
- embedder_->Reload(instance_id);
-}
-
-void BrowserPluginEmbedderHelper::OnTerminateGuest(int instance_id) {
- embedder_->TerminateGuest(instance_id);
-}
-
-void BrowserPluginEmbedderHelper::OnSetGuestVisibility(int instance_id,
- bool visible) {
- embedder_->SetGuestVisibility(instance_id, visible);
-}
-
-void BrowserPluginEmbedderHelper::OnDragStatusUpdate(
- int instance_id,
- WebKit::WebDragStatus drag_status,
- const WebDropData& drop_data,
- WebKit::WebDragOperationsMask drag_mask,
- const gfx::Point& location) {
- embedder_->DragStatusUpdate(instance_id, drag_status, drop_data, drag_mask,
- location);
-}
-
-void BrowserPluginEmbedderHelper::OnSetAutoSize(
- int instance_id,
- const BrowserPluginHostMsg_AutoSize_Params& auto_size_params,
- const BrowserPluginHostMsg_ResizeGuest_Params& resize_guest_params) {
- embedder_->SetAutoSize(instance_id, auto_size_params, resize_guest_params);
-}
-
-} // namespace content
diff --git a/content/browser/browser_plugin/browser_plugin_embedder_helper.h b/content/browser/browser_plugin/browser_plugin_embedder_helper.h
deleted file mode 100644
index d6a89b4..0000000
--- a/content/browser/browser_plugin/browser_plugin_embedder_helper.h
+++ /dev/null
@@ -1,107 +0,0 @@
-// Copyright (c) 2012 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_BROWSER_PLUGIN_EMBEDDER_HELPER_H_
-#define CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_EMBEDDER_HELPER_H_
-
-#include <string>
-
-#include "base/compiler_specific.h"
-#include "content/public/browser/render_view_host_observer.h"
-#include "third_party/WebKit/Source/WebKit/chromium/public/WebDragStatus.h"
-#include "third_party/WebKit/Source/WebKit/chromium/public/WebDragOperation.h"
-
-namespace IPC {
-class Message;
-}
-
-namespace gfx {
-class Point;
-class Rect;
-class Size;
-}
-
-namespace WebKit {
-class WebInputEvent;
-}
-
-struct BrowserPluginHostMsg_AutoSize_Params;
-struct BrowserPluginHostMsg_CreateGuest_Params;
-struct BrowserPluginHostMsg_ResizeGuest_Params;
-struct WebDropData;
-
-namespace content {
-
-class BrowserPluginEmbedder;
-class RenderViewHost;
-
-// Helper for browser plugin embedder.
-//
-// A lot of messages coming from guests need to know the guest's RenderViewHost.
-// BrowserPluginEmbedderHelper handles BrowserPluginHostMsg messages and
-// relays them with their associated RenderViewHosts to its delegate where they
-// will be handled.
-//
-// A BrowserPluginEmbedderHelper is created whenever a BrowserPluginEmbedder is
-// created. BrowserPluginEmbedder's lifetime is managed by the associated
-// RenderViewHost. Functions in this class is assumed to be run on UI thread.
-class BrowserPluginEmbedderHelper : public RenderViewHostObserver {
- public:
- BrowserPluginEmbedderHelper(BrowserPluginEmbedder* embedder,
- RenderViewHost* render_view_host);
- virtual ~BrowserPluginEmbedderHelper();
-
- // Make it public for sync IPCs.
- virtual bool Send(IPC::Message* message) OVERRIDE;
-
- protected:
- // RenderViewHostObserver implementation.
- virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
-
- private:
- // Message handlers.
- void OnCreateGuest(int instance_id,
- const BrowserPluginHostMsg_CreateGuest_Params& params);
- void OnNavigateGuest(int instance_id, const std::string& src);
- void OnResizeGuest(int instance_id,
- const BrowserPluginHostMsg_ResizeGuest_Params& params);
- void OnUpdateRectACK(
- int instance_id,
- const BrowserPluginHostMsg_AutoSize_Params& auto_size_params,
- const BrowserPluginHostMsg_ResizeGuest_Params& resize_guest_params);
- void OnSwapBuffersACK(int route_id,
- int gpu_host_id,
- uint64 surface_handle,
- uint32 sync_point);
- void OnHandleInputEvent(int instance_id,
- const gfx::Rect& guest_window_rect,
- const WebKit::WebInputEvent* input_event);
- void OnSetFocus(int instance_id, bool focused);
- void OnPluginDestroyed(int instance_id);
- void OnGo(int instance_id, int relative_index);
- void OnStop(int instance_id);
- void OnReload(int instance_id);
- void OnTerminateGuest(int instance_id);
- void OnSetGuestVisibility(int instance_id, bool visible);
- void OnDragStatusUpdate(int instance_id,
- WebKit::WebDragStatus drag_status,
- const WebDropData& drop_data,
- WebKit::WebDragOperationsMask drag_mask,
- const gfx::Point& location);
- void OnSetAutoSize(
- int instance_id,
- const BrowserPluginHostMsg_AutoSize_Params& auto_size_params,
- const BrowserPluginHostMsg_ResizeGuest_Params& resize_guest_params);
- void OnPluginAtPositionResponse(int instance_id,
- int request_id,
- const gfx::Point& position);
-
- BrowserPluginEmbedder* embedder_;
-
- DISALLOW_COPY_AND_ASSIGN(BrowserPluginEmbedderHelper);
-};
-
-} // namespace content
-
-#endif // CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_EMBEDDER_HELPER_H_
diff --git a/content/browser/browser_plugin/browser_plugin_guest.cc b/content/browser/browser_plugin/browser_plugin_guest.cc
index f7cc004..a4cfbea 100644
--- a/content/browser/browser_plugin/browser_plugin_guest.cc
+++ b/content/browser/browser_plugin/browser_plugin_guest.cc
@@ -64,7 +64,30 @@ BrowserPluginGuest::BrowserPluginGuest(
DCHECK(web_contents);
}
-void BrowserPluginGuest::InstallHelper(
+bool BrowserPluginGuest::OnMessageReceivedFromEmbedder(
+ const IPC::Message& message) {
+ bool handled = true;
+ IPC_BEGIN_MESSAGE_MAP(BrowserPluginGuest, message)
+ IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_DragStatusUpdate,
+ OnDragStatusUpdate)
+ IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_Go, OnGo)
+ IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_HandleInputEvent,
+ OnHandleInputEvent)
+ IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_Reload, OnReload)
+ IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ResizeGuest, OnResizeGuest)
+ IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetAutoSize, OnSetSize)
+ IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetFocus, OnSetFocus)
+ IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetVisibility, OnSetVisibility)
+ IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_Stop, OnStop)
+ IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_TerminateGuest, OnTerminateGuest)
+ IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_UpdateRect_ACK, OnUpdateRectACK)
+ IPC_MESSAGE_UNHANDLED(handled = false)
+ IPC_END_MESSAGE_MAP()
+ return handled;
+}
+
+void BrowserPluginGuest::Initialize(
+ const BrowserPluginHostMsg_CreateGuest_Params& params,
content::RenderViewHost* render_view_host) {
// |render_view_host| manages the ownership of this BrowserPluginGuestHelper.
new BrowserPluginGuestHelper(this, render_view_host);
@@ -72,6 +95,8 @@ void BrowserPluginGuest::InstallHelper(
notification_registrar_.Add(
this, content::NOTIFICATION_RESOURCE_RECEIVED_REDIRECT,
content::Source<content::WebContents>(web_contents()));
+
+ OnSetSize(instance_id_, params.auto_size_params, params.resize_guest_params);
}
BrowserPluginGuest::~BrowserPluginGuest() {
@@ -91,6 +116,10 @@ BrowserPluginGuest* BrowserPluginGuest::Create(
return new BrowserPluginGuest(instance_id, web_contents,params);
}
+void BrowserPluginGuest::UpdateVisibility() {
+ OnSetVisibility(instance_id_, visible());
+}
+
void BrowserPluginGuest::Observe(int type,
const NotificationSource& source,
const NotificationDetails& details) {
@@ -112,10 +141,6 @@ void BrowserPluginGuest::Observe(int type,
}
}
-void BrowserPluginGuest::Go(int relative_index) {
- web_contents()->GetController().GoToOffset(relative_index);
-}
-
bool BrowserPluginGuest::CanDownload(RenderViewHost* render_view_host,
int request_id,
const std::string& request_method) {
@@ -165,114 +190,17 @@ bool BrowserPluginGuest::ShouldFocusPageAfterCrash() {
return false;
}
-void BrowserPluginGuest::SetVisibility(bool embedder_visible, bool visible) {
- visible_ = visible;
- if (embedder_visible && visible)
- web_contents()->WasShown();
- else
- web_contents()->WasHidden();
-}
-
-void BrowserPluginGuest::DragStatusUpdate(WebKit::WebDragStatus drag_status,
- const WebDropData& drop_data,
- WebKit::WebDragOperationsMask mask,
- const gfx::Point& location) {
- RenderViewHost* host = web_contents()->GetRenderViewHost();
- switch (drag_status) {
- case WebKit::WebDragStatusEnter:
- host->DragTargetDragEnter(drop_data, location, location, mask, 0);
- break;
- case WebKit::WebDragStatusOver:
- host->DragTargetDragOver(location, location, mask, 0);
- break;
- case WebKit::WebDragStatusLeave:
- host->DragTargetDragLeave();
- break;
- case WebKit::WebDragStatusDrop:
- host->DragTargetDrop(location, location, 0);
- break;
- case WebKit::WebDragStatusUnknown:
- NOTREACHED();
- }
-}
-
-void BrowserPluginGuest::SetSize(
- const BrowserPluginHostMsg_AutoSize_Params& auto_size_params,
- const BrowserPluginHostMsg_ResizeGuest_Params& resize_guest_params) {
- bool old_auto_size_enabled = auto_size_enabled_;
- gfx::Size old_max_size = max_auto_size_;
- gfx::Size old_min_size = min_auto_size_;
- auto_size_enabled_ = auto_size_params.enable;
- max_auto_size_ = auto_size_params.max_size;
- min_auto_size_ = auto_size_params.min_size;
- if (auto_size_enabled_ && (!old_auto_size_enabled ||
- (old_max_size != max_auto_size_) ||
- (old_min_size != min_auto_size_))) {
- web_contents()->GetRenderViewHost()->EnableAutoResize(
- min_auto_size_, max_auto_size_);
- // TODO(fsamuel): If we're changing autosize parameters, then we force
- // the guest to completely repaint itself, because BrowserPlugin has
- // allocated a new damage buffer and expects a full frame of pixels.
- // Ideally, we shouldn't need to do this because we shouldn't need to
- // allocate a new damage buffer unless |max_auto_size_| has changed.
- // However, even in that case, layout may not change and so we may
- // not get a full frame worth of pixels.
- web_contents()->GetRenderViewHost()->Send(new ViewMsg_Repaint(
- web_contents()->GetRenderViewHost()->GetRoutingID(),
- max_auto_size_));
- } else if (!auto_size_enabled_ && old_auto_size_enabled) {
- web_contents()->GetRenderViewHost()->DisableAutoResize(
- resize_guest_params.view_size);
- }
- Resize(embedder_web_contents_->GetRenderViewHost(), resize_guest_params);
-}
-
WebContents* BrowserPluginGuest::GetWebContents() {
return web_contents();
}
-void BrowserPluginGuest::Terminate() {
- RecordAction(UserMetricsAction("BrowserPlugin.Guest.Terminate"));
- base::ProcessHandle process_handle =
- web_contents()->GetRenderProcessHost()->GetHandle();
- base::KillProcess(process_handle, RESULT_CODE_KILLED, false);
-}
-
-void BrowserPluginGuest::Resize(
- RenderViewHost* embedder_rvh,
- const BrowserPluginHostMsg_ResizeGuest_Params& params) {
- // BrowserPlugin manages resize flow control itself and does not depend
- // on RenderWidgetHost's mechanisms for flow control, so we reset those flags
- // here.
- RenderWidgetHostImpl* render_widget_host =
- RenderWidgetHostImpl::From(web_contents()->GetRenderViewHost());
- render_widget_host->ResetSizeAndRepaintPendingFlags();
- if (!TransportDIB::is_valid_id(params.damage_buffer_id)) {
- // Invalid transport dib, so just resize the WebContents.
- if (!params.view_size.IsEmpty())
- web_contents()->GetView()->SizeContents(params.view_size);
- return;
- }
- TransportDIB* damage_buffer =
- GetDamageBufferFromEmbedder(embedder_rvh, params);
- SetDamageBuffer(damage_buffer,
-#if defined(OS_WIN)
- params.damage_buffer_size,
- params.damage_buffer_id.handle,
-#endif
- params.view_size,
- params.scale_factor);
- web_contents()->GetView()->SizeContents(params.view_size);
-}
-
TransportDIB* BrowserPluginGuest::GetDamageBufferFromEmbedder(
- RenderViewHost* embedder_rvh,
const BrowserPluginHostMsg_ResizeGuest_Params& params) {
TransportDIB* damage_buffer = NULL;
#if defined(OS_WIN)
// On Windows we need to duplicate the handle from the remote process.
HANDLE section;
- DuplicateHandle(embedder_rvh->GetProcess()->GetHandle(),
+ DuplicateHandle(embedder_web_contents_->GetRenderProcessHost()->GetHandle(),
params.damage_buffer_id.handle,
GetCurrentProcess(),
&section,
@@ -328,59 +256,6 @@ bool BrowserPluginGuest::InAutoSizeBounds(const gfx::Size& size) const {
size.height() <= max_auto_size_.height();
}
-void BrowserPluginGuest::UpdateRectACK(
- const BrowserPluginHostMsg_AutoSize_Params& auto_size_params,
- const BrowserPluginHostMsg_ResizeGuest_Params& resize_guest_params) {
- RenderViewHost* render_view_host = web_contents()->GetRenderViewHost();
- render_view_host->Send(
- new ViewMsg_UpdateRect_ACK(render_view_host->GetRoutingID()));
- SetSize(auto_size_params, resize_guest_params);
-}
-
-void BrowserPluginGuest::HandleInputEvent(RenderViewHost* render_view_host,
- const gfx::Rect& guest_window_rect,
- const gfx::Rect& guest_screen_rect,
- const WebKit::WebInputEvent& event) {
- guest_window_rect_ = guest_window_rect;
- guest_screen_rect_ = guest_screen_rect;
- RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>(
- web_contents()->GetRenderViewHost());
-
- IPC::Message* message = NULL;
-
- // TODO(fsamuel): What should we do for keyboard_shortcut field?
- if (event.type == WebKit::WebInputEvent::KeyDown) {
- CHECK_EQ(sizeof(WebKit::WebKeyboardEvent), event.size);
- WebKit::WebKeyboardEvent key_event;
- memcpy(&key_event, &event, event.size);
- key_event.type = WebKit::WebInputEvent::RawKeyDown;
- message = new ViewMsg_HandleInputEvent(routing_id(), &key_event, false);
- } else {
- message = new ViewMsg_HandleInputEvent(routing_id(), &event, false);
- }
-
- guest_rvh->Send(message);
- guest_rvh->StartHangMonitorTimeout(guest_hang_timeout_);
-}
-
-void BrowserPluginGuest::Stop() {
- web_contents()->Stop();
-}
-
-void BrowserPluginGuest::Reload() {
- // TODO(fsamuel): Don't check for repost because we don't want to show
- // Chromium's repost warning. We might want to implement a separate API
- // for registering a callback if a repost is about to happen.
- web_contents()->GetController().Reload(false);
-}
-
-void BrowserPluginGuest::SetFocus(bool focused) {
- if (focused_ == focused)
- return;
- focused_ = focused;
- Send(new ViewMsg_SetFocus(routing_id(), focused));
-}
-
void BrowserPluginGuest::DidStartProvisionalLoadForFrame(
int64 frame_id,
int64 parent_frame_id,
@@ -462,9 +337,7 @@ void BrowserPluginGuest::RenderViewReady() {
// TODO(fsamuel): Investigate whether it's possible to update state earlier
// here (see http://crbug.com/158151).
Send(new ViewMsg_SetFocus(routing_id(), focused_));
- bool embedder_visible =
- embedder_web_contents_->GetBrowserPluginEmbedder()->visible();
- SetVisibility(embedder_visible, visible());
+ UpdateVisibility();
if (auto_size_enabled_) {
web_contents()->GetRenderViewHost()->EnableAutoResize(
min_auto_size_, max_auto_size_);
@@ -516,6 +389,169 @@ bool BrowserPluginGuest::OnMessageReceived(const IPC::Message& message) {
return handled;
}
+void BrowserPluginGuest::OnGo(int instance_id, int relative_index) {
+ web_contents()->GetController().GoToOffset(relative_index);
+}
+
+void BrowserPluginGuest::OnDragStatusUpdate(int instance_id,
+ WebKit::WebDragStatus drag_status,
+ const WebDropData& drop_data,
+ WebKit::WebDragOperationsMask mask,
+ const gfx::Point& location) {
+ RenderViewHost* host = web_contents()->GetRenderViewHost();
+ switch (drag_status) {
+ case WebKit::WebDragStatusEnter:
+ host->DragTargetDragEnter(drop_data, location, location, mask, 0);
+ break;
+ case WebKit::WebDragStatusOver:
+ host->DragTargetDragOver(location, location, mask, 0);
+ break;
+ case WebKit::WebDragStatusLeave:
+ host->DragTargetDragLeave();
+ break;
+ case WebKit::WebDragStatusDrop:
+ host->DragTargetDrop(location, location, 0);
+ break;
+ case WebKit::WebDragStatusUnknown:
+ NOTREACHED();
+ }
+}
+
+void BrowserPluginGuest::OnHandleInputEvent(
+ int instance_id,
+ const gfx::Rect& guest_window_rect,
+ const WebKit::WebInputEvent* event) {
+ guest_window_rect_ = guest_window_rect;
+ guest_screen_rect_ = guest_window_rect;
+ guest_screen_rect_.Offset(
+ embedder_web_contents_->GetRenderViewHost()->GetView()->
+ GetViewBounds().OffsetFromOrigin());
+ RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>(
+ web_contents()->GetRenderViewHost());
+
+ IPC::Message* message = NULL;
+
+ // TODO(fsamuel): What should we do for keyboard_shortcut field?
+ if (event->type == WebKit::WebInputEvent::KeyDown) {
+ CHECK_EQ(sizeof(WebKit::WebKeyboardEvent), event->size);
+ WebKit::WebKeyboardEvent key_event;
+ memcpy(&key_event, event, event->size);
+ key_event.type = WebKit::WebInputEvent::RawKeyDown;
+ message = new ViewMsg_HandleInputEvent(routing_id(), &key_event, false);
+ } else {
+ message = new ViewMsg_HandleInputEvent(routing_id(), event, false);
+ }
+
+ guest_rvh->Send(message);
+ guest_rvh->StartHangMonitorTimeout(guest_hang_timeout_);
+}
+
+void BrowserPluginGuest::OnReload(int instance_id) {
+ // TODO(fsamuel): Don't check for repost because we don't want to show
+ // Chromium's repost warning. We might want to implement a separate API
+ // for registering a callback if a repost is about to happen.
+ web_contents()->GetController().Reload(false);
+}
+
+void BrowserPluginGuest::OnResizeGuest(
+ int instance_id,
+ const BrowserPluginHostMsg_ResizeGuest_Params& params) {
+ // BrowserPlugin manages resize flow control itself and does not depend
+ // on RenderWidgetHost's mechanisms for flow control, so we reset those flags
+ // here. If we are setting the size for the first time before navigating then
+ // BrowserPluginGuest does not yet have a RenderViewHost.
+ if (web_contents()->GetRenderViewHost()) {
+ RenderWidgetHostImpl* render_widget_host =
+ RenderWidgetHostImpl::From(web_contents()->GetRenderViewHost());
+ render_widget_host->ResetSizeAndRepaintPendingFlags();
+ }
+ if (!TransportDIB::is_valid_id(params.damage_buffer_id)) {
+ // Invalid transport dib, so just resize the WebContents.
+ if (!params.view_size.IsEmpty())
+ web_contents()->GetView()->SizeContents(params.view_size);
+ return;
+ }
+ TransportDIB* damage_buffer = GetDamageBufferFromEmbedder(params);
+ SetDamageBuffer(damage_buffer,
+#if defined(OS_WIN)
+ params.damage_buffer_size,
+ params.damage_buffer_id.handle,
+#endif
+ params.view_size,
+ params.scale_factor);
+ web_contents()->GetView()->SizeContents(params.view_size);
+}
+
+void BrowserPluginGuest::OnSetSize(
+ int instance_id,
+ const BrowserPluginHostMsg_AutoSize_Params& auto_size_params,
+ const BrowserPluginHostMsg_ResizeGuest_Params& resize_guest_params) {
+ bool old_auto_size_enabled = auto_size_enabled_;
+ gfx::Size old_max_size = max_auto_size_;
+ gfx::Size old_min_size = min_auto_size_;
+ auto_size_enabled_ = auto_size_params.enable;
+ max_auto_size_ = auto_size_params.max_size;
+ min_auto_size_ = auto_size_params.min_size;
+ if (auto_size_enabled_ && (!old_auto_size_enabled ||
+ (old_max_size != max_auto_size_) ||
+ (old_min_size != min_auto_size_))) {
+ web_contents()->GetRenderViewHost()->EnableAutoResize(
+ min_auto_size_, max_auto_size_);
+ // TODO(fsamuel): If we're changing autosize parameters, then we force
+ // the guest to completely repaint itself, because BrowserPlugin has
+ // allocated a new damage buffer and expects a full frame of pixels.
+ // Ideally, we shouldn't need to do this because we shouldn't need to
+ // allocate a new damage buffer unless |max_auto_size_| has changed.
+ // However, even in that case, layout may not change and so we may
+ // not get a full frame worth of pixels.
+ web_contents()->GetRenderViewHost()->Send(new ViewMsg_Repaint(
+ web_contents()->GetRenderViewHost()->GetRoutingID(),
+ max_auto_size_));
+ } else if (!auto_size_enabled_ && old_auto_size_enabled) {
+ web_contents()->GetRenderViewHost()->DisableAutoResize(
+ resize_guest_params.view_size);
+ }
+ OnResizeGuest(instance_id_, resize_guest_params);
+}
+
+void BrowserPluginGuest::OnSetFocus(int instance_id, bool focused) {
+ if (focused_ == focused)
+ return;
+ focused_ = focused;
+ Send(new ViewMsg_SetFocus(routing_id(), focused));
+}
+
+void BrowserPluginGuest::OnSetVisibility(int instance_id, bool visible) {
+ visible_ = visible;
+ BrowserPluginEmbedder* embedder =
+ embedder_web_contents_->GetBrowserPluginEmbedder();
+ if (embedder->visible() && visible)
+ web_contents()->WasShown();
+ else
+ web_contents()->WasHidden();
+}
+
+void BrowserPluginGuest::OnStop(int instance_id) {
+ web_contents()->Stop();
+}
+
+void BrowserPluginGuest::OnTerminateGuest(int instance_id) {
+ RecordAction(UserMetricsAction("BrowserPlugin.Guest.Terminate"));
+ base::ProcessHandle process_handle =
+ web_contents()->GetRenderProcessHost()->GetHandle();
+ base::KillProcess(process_handle, RESULT_CODE_KILLED, false);
+}
+
+void BrowserPluginGuest::OnUpdateRectACK(
+ int instance_id,
+ const BrowserPluginHostMsg_AutoSize_Params& auto_size_params,
+ const BrowserPluginHostMsg_ResizeGuest_Params& resize_guest_params) {
+ RenderViewHost* render_view_host = web_contents()->GetRenderViewHost();
+ render_view_host->Send(
+ new ViewMsg_UpdateRect_ACK(render_view_host->GetRoutingID()));
+ OnSetSize(instance_id_, auto_size_params, resize_guest_params);
+}
+
void BrowserPluginGuest::OnHandleInputEventAck(
WebKit::WebInputEvent::Type event_type,
InputEventAckState ack_result) {
diff --git a/content/browser/browser_plugin/browser_plugin_guest.h b/content/browser/browser_plugin/browser_plugin_guest.h
index 99ffbf6..9a75a98 100644
--- a/content/browser/browser_plugin/browser_plugin_guest.h
+++ b/content/browser/browser_plugin/browser_plugin_guest.h
@@ -79,7 +79,10 @@ class CONTENT_EXPORT BrowserPluginGuest : public NotificationObserver,
content::BrowserPluginGuest::factory_ = factory;
}
- void InstallHelper(content::RenderViewHost* render_view_host);
+ bool OnMessageReceivedFromEmbedder(const IPC::Message& message);
+
+ void Initialize(const BrowserPluginHostMsg_CreateGuest_Params& params,
+ content::RenderViewHost* render_view_host);
void set_guest_hang_timeout_for_testing(const base::TimeDelta& timeout) {
guest_hang_timeout_ = timeout;
@@ -95,6 +98,8 @@ class CONTENT_EXPORT BrowserPluginGuest : public NotificationObserver,
bool focused() const { return focused_; }
bool visible() const { return visible_; }
+ void UpdateVisibility();
+
// NotificationObserver implementation.
virtual void Observe(int type,
const NotificationSource& source,
@@ -139,69 +144,12 @@ class CONTENT_EXPORT BrowserPluginGuest : public NotificationObserver,
const FileChooserParams& params) OVERRIDE;
virtual bool ShouldFocusPageAfterCrash() OVERRIDE;
- void UpdateRectACK(
- const BrowserPluginHostMsg_AutoSize_Params& auto_size_params,
- const BrowserPluginHostMsg_ResizeGuest_Params& resize_guest_params);
-
- // The guest WebContents is visible if both its embedder is visible and
- // the browser plugin element is visible. If either one is not then the
- // WebContents is marked as hidden. A hidden WebContents will consume
- // fewer GPU and CPU resources.
- //
- // When the every WebContents in a RenderProcessHost is hidden, it will lower
- // the priority of the process (see RenderProcessHostImpl::WidgetHidden).
- //
- // It will also send a message to the guest renderer process to cleanup
- // resources such as dropping back buffers and adjusting memory limits (if in
- // compositing mode, see CCLayerTreeHost::setVisible).
- //
- // Additionally it will slow down Javascript execution and garbage collection.
- // See RenderThreadImpl::IdleHandler (executed when hidden) and
- // RenderThreadImpl::IdleHandlerInForegroundTab (executed when visible).
- void SetVisibility(bool embedder_visible, bool visible);
-
- // Handles drag events from the embedder.
- // When dragging, the drag events go to the embedder first, and if the drag
- // happens on the browser plugin, then the plugin sends a corresponding
- // drag-message to the guest. This routes the drag-message to the guest
- // renderer.
- void DragStatusUpdate(WebKit::WebDragStatus drag_status,
- const WebDropData& drop_data,
- WebKit::WebDragOperationsMask drag_mask,
- const gfx::Point& location);
-
- // Updates the size state of the guest.
- void SetSize(
- const BrowserPluginHostMsg_AutoSize_Params& auto_size_params,
- const BrowserPluginHostMsg_ResizeGuest_Params& resize_guest_params);
-
// Exposes the protected web_contents() from WebContentsObserver.
WebContents* GetWebContents();
// Kill the guest process.
void Terminate();
- // Grab the new damage buffer from the embedder, and resize the guest's
- // web contents.
- void Resize(RenderViewHost* embedder_rvh,
- const BrowserPluginHostMsg_ResizeGuest_Params& params);
-
- // Overridden in tests.
- // Handles input event routed through the embedder (which is initiated in the
- // browser plugin (renderer side of the embedder)).
- virtual void HandleInputEvent(RenderViewHost* render_view_host,
- const gfx::Rect& guest_window_rect,
- const gfx::Rect& guest_screen_rect,
- const WebKit::WebInputEvent& event);
- // If possible, navigate the guest to |relative_index| entries away from the
- // current navigation entry.
- virtual void Go(int relative_index);
- // Overridden in tests.
- virtual void SetFocus(bool focused);
- // Reload the guest.
- virtual void Reload();
- // Stop loading the guest.
- virtual void Stop();
// Overridden in tests.
virtual void SetDamageBuffer(TransportDIB* damage_buffer,
#if defined(OS_WIN)
@@ -237,7 +185,6 @@ class CONTENT_EXPORT BrowserPluginGuest : public NotificationObserver,
}
// Returns the transport DIB associated with the dib in resize |params|.
TransportDIB* GetDamageBufferFromEmbedder(
- RenderViewHost* embedder_rvh,
const BrowserPluginHostMsg_ResizeGuest_Params& params);
// Called when a redirect notification occurs.
@@ -247,7 +194,64 @@ class CONTENT_EXPORT BrowserPluginGuest : public NotificationObserver,
bool InAutoSizeBounds(const gfx::Size& size) const;
- // Message handlers.
+ // Message handlers for messsages from embedder.
+
+ // If possible, navigate the guest to |relative_index| entries away from the
+ // current navigation entry.
+ virtual void OnGo(int instance_id, int relative_index);
+ // Handles drag events from the embedder.
+ // When dragging, the drag events go to the embedder first, and if the drag
+ // happens on the browser plugin, then the plugin sends a corresponding
+ // drag-message to the guest. This routes the drag-message to the guest
+ // renderer.
+ void OnDragStatusUpdate(int instance_id,
+ WebKit::WebDragStatus drag_status,
+ const WebDropData& drop_data,
+ WebKit::WebDragOperationsMask drag_mask,
+ const gfx::Point& location);
+ // Overriden in tests.
+ virtual void OnHandleInputEvent(int instance_id,
+ const gfx::Rect& guest_window_rect,
+ const WebKit::WebInputEvent* event);
+ // Reload the guest. Overriden in tests.
+ virtual void OnReload(int instance_id);
+ // Grab the new damage buffer from the embedder, and resize the guest's
+ // web contents.
+ void OnResizeGuest(int instance_id,
+ const BrowserPluginHostMsg_ResizeGuest_Params& params);
+ // Updates the size state of the guest.
+ void OnSetSize(
+ int instance_id,
+ const BrowserPluginHostMsg_AutoSize_Params& auto_size_params,
+ const BrowserPluginHostMsg_ResizeGuest_Params& resize_guest_params);
+ // Overriden in tests.
+ virtual void OnSetFocus(int instance_id, bool focused);
+ // The guest WebContents is visible if both its embedder is visible and
+ // the browser plugin element is visible. If either one is not then the
+ // WebContents is marked as hidden. A hidden WebContents will consume
+ // fewer GPU and CPU resources.
+ //
+ // When every WebContents in a RenderProcessHost is hidden, it will lower
+ // the priority of the process (see RenderProcessHostImpl::WidgetHidden).
+ //
+ // It will also send a message to the guest renderer process to cleanup
+ // resources such as dropping back buffers and adjusting memory limits (if in
+ // compositing mode, see CCLayerTreeHost::setVisible).
+ //
+ // Additionally, it will slow down Javascript execution and garbage
+ // collection. See RenderThreadImpl::IdleHandler (executed when hidden) and
+ // RenderThreadImpl::IdleHandlerInForegroundTab (executed when visible).
+ void OnSetVisibility(int instance_id, bool visible);
+ // Stop loading the guest. Overriden in tests.
+ virtual void OnStop(int instance_id);
+ void OnTerminateGuest(int instance_id);
+ void OnUpdateRectACK(
+ int instance_id,
+ const BrowserPluginHostMsg_AutoSize_Params& auto_size_params,
+ const BrowserPluginHostMsg_ResizeGuest_Params& resize_guest_params);
+
+
+ // Message handlers for messages from guest.
void OnHandleInputEventAck(
WebKit::WebInputEvent::Type event_type,
@@ -260,7 +264,7 @@ class CONTENT_EXPORT BrowserPluginGuest : public NotificationObserver,
void OnShowPopup(const ViewHostMsg_ShowPopup_Params& params);
#endif
void OnShowWidget(int route_id, const gfx::Rect& initial_pos);
- // Overriden in tests
+ // Overriden in tests.
virtual void OnTakeFocus(bool reverse);
void OnUpdateDragCursor(WebKit::WebDragOperation operation);
void OnUpdateRect(const ViewHostMsg_UpdateRect_Params& params);
diff --git a/content/browser/browser_plugin/browser_plugin_host_browsertest.cc b/content/browser/browser_plugin/browser_plugin_host_browsertest.cc
index 7518a5c..b72818c 100644
--- a/content/browser/browser_plugin/browser_plugin_host_browsertest.cc
+++ b/content/browser/browser_plugin/browser_plugin_host_browsertest.cc
@@ -27,6 +27,7 @@
#include "net/base/net_util.h"
#include "net/test/test_server.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
+#include "webkit/glue/webdropdata.h"
using WebKit::WebInputEvent;
using WebKit::WebMouseEvent;
diff --git a/content/browser/browser_plugin/test_browser_plugin_guest.cc b/content/browser/browser_plugin/test_browser_plugin_guest.cc
index b39b43f..60f7167 100644
--- a/content/browser/browser_plugin/test_browser_plugin_guest.cc
+++ b/content/browser/browser_plugin/test_browser_plugin_guest.cc
@@ -115,15 +115,13 @@ void TestBrowserPluginGuest::RenderViewGone(base::TerminationStatus status) {
BrowserPluginGuest::RenderViewGone(status);
}
-void TestBrowserPluginGuest::HandleInputEvent(
- RenderViewHost* render_view_host,
+void TestBrowserPluginGuest::OnHandleInputEvent(
+ int instance_id,
const gfx::Rect& guest_window_rect,
- const gfx::Rect& guest_screen_rect,
- const WebKit::WebInputEvent& event) {
- BrowserPluginGuest::HandleInputEvent(render_view_host,
- guest_window_rect,
- guest_screen_rect,
- event);
+ const WebKit::WebInputEvent* event) {
+ BrowserPluginGuest::OnHandleInputEvent(instance_id,
+ guest_window_rect,
+ event);
input_observed_ = true;
if (input_message_loop_runner_)
input_message_loop_runner_->Quit();
@@ -231,7 +229,7 @@ void TestBrowserPluginGuest::WaitForViewSize(const gfx::Size& view_size) {
last_view_size_observed_ = gfx::Size();
}
-void TestBrowserPluginGuest::SetFocus(bool focused) {
+void TestBrowserPluginGuest::OnSetFocus(int instance_id, bool focused) {
if (focused) {
focus_observed_ = true;
if (focus_message_loop_runner_)
@@ -241,7 +239,7 @@ void TestBrowserPluginGuest::SetFocus(bool focused) {
if (blur_message_loop_runner_)
blur_message_loop_runner_->Quit();
}
- BrowserPluginGuest::SetFocus(focused);
+ BrowserPluginGuest::OnSetFocus(instance_id, focused);
}
void TestBrowserPluginGuest::OnTakeFocus(bool reverse) {
@@ -251,18 +249,18 @@ void TestBrowserPluginGuest::OnTakeFocus(bool reverse) {
BrowserPluginGuest::OnTakeFocus(reverse);
}
-void TestBrowserPluginGuest::Reload() {
+void TestBrowserPluginGuest::OnReload(int instance_id) {
reload_observed_ = true;
if (reload_message_loop_runner_)
reload_message_loop_runner_->Quit();
- BrowserPluginGuest::Reload();
+ BrowserPluginGuest::OnReload(instance_id);
}
-void TestBrowserPluginGuest::Stop() {
+void TestBrowserPluginGuest::OnStop(int instance_id) {
stop_observed_ = true;
if (stop_message_loop_runner_)
stop_message_loop_runner_->Quit();
- BrowserPluginGuest::Stop();
+ BrowserPluginGuest::OnStop(instance_id);
}
void TestBrowserPluginGuest::SetDamageBuffer(
diff --git a/content/browser/browser_plugin/test_browser_plugin_guest.h b/content/browser/browser_plugin/test_browser_plugin_guest.h
index 9f3b302..b9dc20b 100644
--- a/content/browser/browser_plugin/test_browser_plugin_guest.h
+++ b/content/browser/browser_plugin/test_browser_plugin_guest.h
@@ -37,14 +37,13 @@ class TestBrowserPluginGuest : public BrowserPluginGuest {
// Overridden methods from BrowserPluginGuest to intercept in test objects.
virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE;
- virtual void HandleInputEvent(RenderViewHost* render_view_host,
- const gfx::Rect& guest_window_rect,
- const gfx::Rect& guest_screen_rect,
- const WebKit::WebInputEvent& event) OVERRIDE;
- virtual void SetFocus(bool focused) OVERRIDE;
+ virtual void OnHandleInputEvent(int instance_id,
+ const gfx::Rect& guest_window_rect,
+ const WebKit::WebInputEvent* event) OVERRIDE;
+ virtual void OnSetFocus(int instance_id, bool focused) OVERRIDE;
virtual void OnTakeFocus(bool reverse) OVERRIDE;
- virtual void Reload() OVERRIDE;
- virtual void Stop() OVERRIDE;
+ virtual void OnReload(int instance_id) OVERRIDE;
+ virtual void OnStop(int instance_id) OVERRIDE;
virtual void SetDamageBuffer(TransportDIB* damage_buffer,
#if defined(OS_WIN)
int damage_buffer_size,
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
index d324987..5e4d732 100644
--- a/content/browser/web_contents/web_contents_impl.cc
+++ b/content/browser/web_contents/web_contents_impl.cc
@@ -404,8 +404,6 @@ WebContentsImpl* WebContentsImpl::CreateGuest(
params));
new_contents->Init(WebContents::CreateParams(browser_context, site_instance));
- new_contents->browser_plugin_guest_->InstallHelper(
- new_contents->GetRenderViewHost());
return new_contents;
}
@@ -2358,9 +2356,9 @@ void WebContentsImpl::OnBrowserPluginCreateGuest(
CHECK(!browser_plugin_embedder_.get());
browser_plugin_embedder_.reset(
BrowserPluginEmbedder::Create(this, GetRenderViewHost()));
- browser_plugin_embedder_->CreateGuest(GetRenderViewHost(),
- instance_id,
- params);
+ BrowserPluginHostMsg_CreateGuest create_guest_msg(
+ GetRenderViewHost()->GetRoutingID(), instance_id, params);
+ browser_plugin_embedder_->OnMessageReceived(create_guest_msg);
}
void WebContentsImpl::OnDidDownloadFavicon(
diff --git a/content/content_browser.gypi b/content/content_browser.gypi
index 00b5d22..9fd6569 100644
--- a/content/content_browser.gypi
+++ b/content/content_browser.gypi
@@ -246,8 +246,6 @@
'browser/browser_main_runner.cc',
'browser/browser_plugin/browser_plugin_embedder.cc',
'browser/browser_plugin/browser_plugin_embedder.h',
- 'browser/browser_plugin/browser_plugin_embedder_helper.cc',
- 'browser/browser_plugin/browser_plugin_embedder_helper.h',
'browser/browser_plugin/browser_plugin_guest.cc',
'browser/browser_plugin/browser_plugin_guest.h',
'browser/browser_plugin/browser_plugin_guest_helper.cc',