Commit 04a6f5f6 authored by fsamuel's avatar fsamuel Committed by Commit bot

BrowserPlugin: Remove dependency upon ViewHostMsg_UpdateRect

BUG=410029,  273089

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

Cr-Commit-Position: refs/heads/master@{#293362}
parent a60ad8f6
......@@ -25,6 +25,7 @@
#include "content/common/content_constants_internal.h"
#include "content/common/drag_messages.h"
#include "content/common/frame_messages.h"
#include "content/common/host_shared_bitmap_manager.h"
#include "content/common/input_messages.h"
#include "content/common/view_messages.h"
#include "content/public/browser/browser_context.h"
......@@ -310,6 +311,54 @@ void BrowserPluginGuest::PointerLockPermissionResponse(bool allow) {
new BrowserPluginMsg_SetMouseLock(browser_plugin_instance_id(), allow));
}
void BrowserPluginGuest::SwapCompositorFrame(
uint32 output_surface_id,
int host_process_id,
int host_routing_id,
scoped_ptr<cc::CompositorFrame> frame) {
if (!attached()) {
// If the guest doesn't have an embedder then there's nothing to give the
// the frame to.
return;
}
gfx::Size view_size(frame->metadata.root_layer_size.width(),
frame->metadata.root_layer_size.height());
if (last_seen_view_size_ != view_size) {
delegate_->GuestSizeChanged(last_seen_view_size_, view_size);
last_seen_view_size_ = view_size;
}
base::SharedMemoryHandle software_frame_handle =
base::SharedMemory::NULLHandle();
if (frame->software_frame_data) {
cc::SoftwareFrameData* frame_data = frame->software_frame_data.get();
scoped_ptr<cc::SharedBitmap> bitmap =
HostSharedBitmapManager::current()->GetSharedBitmapFromId(
frame_data->size, frame_data->bitmap_id);
if (!bitmap)
return;
RenderWidgetHostView* embedder_rwhv =
GetEmbedderRenderWidgetHostView();
base::ProcessHandle embedder_pid =
embedder_rwhv->GetRenderWidgetHost()->GetProcess()->GetHandle();
bitmap->memory()->ShareToProcess(embedder_pid, &software_frame_handle);
}
FrameMsg_CompositorFrameSwapped_Params guest_params;
frame->AssignTo(&guest_params.frame);
guest_params.output_surface_id = output_surface_id;
guest_params.producing_route_id = host_routing_id;
guest_params.producing_host_id = host_process_id;
guest_params.shared_memory_handle = software_frame_handle;
SendMessageToEmbedder(
new BrowserPluginMsg_CompositorFrameSwapped(
browser_plugin_instance_id(), guest_params));
}
WebContentsImpl* BrowserPluginGuest::GetWebContents() const {
return static_cast<WebContentsImpl*>(web_contents());
}
......@@ -451,7 +500,6 @@ bool BrowserPluginGuest::OnMessageReceived(const IPC::Message& message) {
IPC_MESSAGE_HANDLER(ViewHostMsg_TextInputStateChanged,
OnTextInputStateChanged)
IPC_MESSAGE_HANDLER(ViewHostMsg_UnlockMouse, OnUnlockMouse)
IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateRect, OnUpdateRect)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
......@@ -683,22 +731,15 @@ void BrowserPluginGuest::OnPluginDestroyed(int browser_plugin_instance_id) {
void BrowserPluginGuest::OnResizeGuest(
int browser_plugin_instance_id,
const BrowserPluginHostMsg_ResizeGuest_Params& params) {
if (!params.size_changed)
return;
// 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
// If we are setting the size for the first time before navigating then
// BrowserPluginGuest does not yet have a RenderViewHost.
if (GetWebContents()->GetRenderViewHost()) {
if (guest_device_scale_factor_ != params.scale_factor &&
GetWebContents()->GetRenderViewHost()) {
RenderWidgetHostImpl* render_widget_host =
RenderWidgetHostImpl::From(GetWebContents()->GetRenderViewHost());
render_widget_host->ResetSizeAndRepaintPendingFlags();
if (guest_device_scale_factor_ != params.scale_factor) {
guest_device_scale_factor_ = params.scale_factor;
render_widget_host->NotifyScreenInfoChanged();
}
}
if (last_seen_browser_plugin_size_ != params.view_size) {
delegate_->ElementSizeChanged(last_seen_browser_plugin_size_,
......@@ -830,23 +871,6 @@ void BrowserPluginGuest::OnTakeFocus(bool reverse) {
new BrowserPluginMsg_AdvanceFocus(browser_plugin_instance_id(), reverse));
}
void BrowserPluginGuest::OnUpdateRect(
const ViewHostMsg_UpdateRect_Params& params) {
BrowserPluginMsg_UpdateRect_Params relay_params;
relay_params.view_size = params.view_size;
relay_params.is_resize_ack = ViewHostMsg_UpdateRect_Flags::is_resize_ack(
params.flags);
if (last_seen_view_size_ != params.view_size) {
delegate_->GuestSizeChanged(last_seen_view_size_, params.view_size);
last_seen_view_size_ = params.view_size;
}
SendMessageToEmbedder(
new BrowserPluginMsg_UpdateRect(browser_plugin_instance_id(),
relay_params));
}
void BrowserPluginGuest::OnTextInputStateChanged(
const ViewHostMsg_TextInputState_Params& params) {
// Save the state of text input so we can restore it on focus.
......
......@@ -50,11 +50,15 @@ struct ViewHostMsg_UpdateRect_Params;
namespace blink {
class WebInputEvent;
}
} // namespace blink
namespace cc {
class CompositorFrame;
} // namespace cc
namespace gfx {
class Range;
}
} // namespace gfx
namespace content {
......@@ -193,6 +197,11 @@ class CONTENT_EXPORT BrowserPluginGuest : public WebContentsObserver {
void PointerLockPermissionResponse(bool allow);
void SwapCompositorFrame(uint32 output_surface_id,
int host_process_id,
int host_routing_id,
scoped_ptr<cc::CompositorFrame> frame);
private:
class EmbedderWebContentsObserver;
......@@ -317,7 +326,6 @@ class CONTENT_EXPORT BrowserPluginGuest : public WebContentsObserver {
void OnUpdateFrameName(int frame_id,
bool is_top_level,
const std::string& name);
void OnUpdateRect(const ViewHostMsg_UpdateRect_Params& params);
// Forwards all messages from the |pending_messages_| queue to the embedder.
void SendQueuedMessages();
......@@ -351,7 +359,7 @@ class CONTENT_EXPORT BrowserPluginGuest : public WebContentsObserver {
// maintains a JavaScript reference to its opener.
bool has_render_view_;
// Last seen size of guest contents (by OnUpdateRect).
// Last seen size of guest contents (by SwapCompositorFrame).
gfx::Size last_seen_view_size_;
// Last seen size of BrowserPlugin (by OnResizeGuest).
gfx::Size last_seen_browser_plugin_size_;
......
......@@ -12,7 +12,6 @@
#include "content/common/browser_plugin/browser_plugin_messages.h"
#include "content/common/frame_messages.h"
#include "content/common/gpu/gpu_messages.h"
#include "content/common/host_shared_bitmap_manager.h"
#include "content/common/input/web_touch_event_traits.h"
#include "content/common/view_messages.h"
#include "content/common/webplugin_geometry.h"
......@@ -192,41 +191,11 @@ void RenderWidgetHostViewGuest::OnSwapCompositorFrame(
if (!guest_)
return;
if (!guest_->attached()) {
// If the guest doesn't have an embedder then there's nothing to give the
// the frame to.
return;
}
last_scroll_offset_ = frame->metadata.root_scroll_offset;
base::SharedMemoryHandle software_frame_handle =
base::SharedMemory::NULLHandle();
if (frame->software_frame_data) {
cc::SoftwareFrameData* frame_data = frame->software_frame_data.get();
scoped_ptr<cc::SharedBitmap> bitmap =
HostSharedBitmapManager::current()->GetSharedBitmapFromId(
frame_data->size, frame_data->bitmap_id);
if (!bitmap)
return;
RenderWidgetHostView* embedder_rwhv =
guest_->GetEmbedderRenderWidgetHostView();
base::ProcessHandle embedder_pid =
embedder_rwhv->GetRenderWidgetHost()->GetProcess()->GetHandle();
bitmap->memory()->ShareToProcess(embedder_pid, &software_frame_handle);
}
FrameMsg_CompositorFrameSwapped_Params guest_params;
frame->AssignTo(&guest_params.frame);
guest_params.output_surface_id = output_surface_id;
guest_params.producing_route_id = host_->GetRoutingID();
guest_params.producing_host_id = host_->GetProcess()->GetID();
guest_params.shared_memory_handle = software_frame_handle;
guest_->SendMessageToEmbedder(
new BrowserPluginMsg_CompositorFrameSwapped(
guest_->browser_plugin_instance_id(), guest_params));
guest_->SwapCompositorFrame(output_surface_id,
host_->GetProcess()->GetID(),
host_->GetRoutingID(),
frame.Pass());
}
bool RenderWidgetHostViewGuest::OnMessageReceived(const IPC::Message& msg) {
......
......@@ -37,8 +37,6 @@
IPC_ENUM_TRAITS_MAX_VALUE(blink::WebDragStatus, blink::WebDragStatusLast)
IPC_STRUCT_BEGIN(BrowserPluginHostMsg_ResizeGuest_Params)
// Indicates whether the parameters have been populated or not.
IPC_STRUCT_MEMBER(bool, size_changed)
// The new size of guest view.
IPC_STRUCT_MEMBER(gfx::Size, view_size)
// Indicates the scale factor of the embedder WebView.
......@@ -58,18 +56,6 @@ IPC_STRUCT_BEGIN(BrowserPluginHostMsg_Attach_Params)
IPC_STRUCT_MEMBER(gfx::Point, origin)
IPC_STRUCT_END()
IPC_STRUCT_BEGIN(BrowserPluginMsg_UpdateRect_Params)
// The size of the RenderView when this message was generated. This is
// included so the host knows how large the view is from the perspective of
// the renderer process. This is necessary in case a resize operation is in
// progress. If auto-resize is enabled, this should update the corresponding
// view size.
IPC_STRUCT_MEMBER(gfx::Size, view_size)
// Is this UpdateRect an ACK to a resize request?
IPC_STRUCT_MEMBER(bool, is_resize_ack)
IPC_STRUCT_END()
// Browser plugin messages
// -----------------------------------------------------------------------------
......@@ -172,7 +158,7 @@ IPC_MESSAGE_ROUTED2(BrowserPluginHostMsg_LockMouse_ACK,
IPC_MESSAGE_ROUTED1(BrowserPluginHostMsg_UnlockMouse_ACK,
int /* browser_plugin_instance_id */)
// Sent when plugin's position has changed without UpdateRect.
// Sent when plugin's position has changed.
IPC_MESSAGE_ROUTED2(BrowserPluginHostMsg_UpdateGeometry,
int /* browser_plugin_instance_id */,
gfx::Rect /* view_rect */)
......@@ -223,12 +209,6 @@ IPC_MESSAGE_CONTROL2(BrowserPluginMsg_SetCursor,
int /* browser_plugin_instance_id */,
content::WebCursor /* cursor */)
// The guest has damage it wants to convey to the embedder so that it can
// update its backing store.
IPC_MESSAGE_CONTROL2(BrowserPluginMsg_UpdateRect,
int /* browser_plugin_instance_id */,
BrowserPluginMsg_UpdateRect_Params)
IPC_MESSAGE_CONTROL4(BrowserPluginMsg_CopyFromCompositingSurface,
int /* browser_plugin_instance_id */,
int /* request_id */,
......
......@@ -50,7 +50,6 @@ BrowserPlugin::BrowserPlugin(RenderViewImpl* render_view,
render_view_(render_view->AsWeakPtr()),
render_view_routing_id_(render_view->GetRoutingID()),
container_(NULL),
paint_ack_received_(true),
last_device_scale_factor_(GetDeviceScaleFactor()),
sad_guest_(NULL),
guest_crashed_(false),
......@@ -92,7 +91,6 @@ bool BrowserPlugin::OnMessageReceived(const IPC::Message& message) {
IPC_MESSAGE_HANDLER(BrowserPluginMsg_SetMouseLock, OnSetMouseLock)
IPC_MESSAGE_HANDLER(BrowserPluginMsg_ShouldAcceptTouchEvents,
OnShouldAcceptTouchEvents)
IPC_MESSAGE_HANDLER(BrowserPluginMsg_UpdateRect, OnUpdateRect)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
......@@ -177,7 +175,6 @@ void BrowserPlugin::Attach() {
attach_params.origin = plugin_rect().origin();
gfx::Size view_size(width(), height());
if (!view_size.IsEmpty()) {
paint_ack_received_ = false;
PopulateResizeGuestParameters(view_size,
&attach_params.resize_guest_params);
}
......@@ -222,6 +219,11 @@ void BrowserPlugin::OnCompositorFrameSwapped(const IPC::Message& message) {
BrowserPluginMsg_CompositorFrameSwapped::Param param;
if (!BrowserPluginMsg_CompositorFrameSwapped::Read(&message, &param))
return;
// Note that there is no need to send ACK for this message.
// If the guest has updated pixels then it is no longer crashed.
guest_crashed_ = false;
scoped_ptr<cc::CompositorFrame> frame(new cc::CompositorFrame);
param.b.frame.AssignTo(frame.get());
......@@ -302,33 +304,6 @@ void BrowserPlugin::OnShouldAcceptTouchEvents(int browser_plugin_instance_id,
}
}
void BrowserPlugin::OnUpdateRect(
int browser_plugin_instance_id,
const BrowserPluginMsg_UpdateRect_Params& params) {
// Note that there is no need to send ACK for this message.
// If the guest has updated pixels then it is no longer crashed.
guest_crashed_ = false;
// We receive a resize ACK in regular mode, but not in autosize.
// In Compositing mode, we need to do it here so we can continue sending
// resize messages when needed.
if (params.is_resize_ack)
paint_ack_received_ = true;
if (params.view_size.width() == width() &&
params.view_size.height() == height()) {
return;
}
BrowserPluginHostMsg_ResizeGuest_Params resize_params;
PopulateResizeGuestParameters(plugin_size(), &resize_params);
paint_ack_received_ = false;
browser_plugin_manager()->Send(new BrowserPluginHostMsg_ResizeGuest(
render_view_routing_id_,
browser_plugin_instance_id_,
resize_params));
}
NPObject* BrowserPlugin::GetContentWindow() const {
if (content_window_routing_id_ == MSG_ROUTING_NONE)
return NULL;
......@@ -354,10 +329,8 @@ float BrowserPlugin::GetDeviceScaleFactor() const {
}
void BrowserPlugin::UpdateDeviceScaleFactor() {
if (!paint_ack_received_ ||
last_device_scale_factor_ == GetDeviceScaleFactor()) {
if (last_device_scale_factor_ == GetDeviceScaleFactor())
return;
}
BrowserPluginHostMsg_ResizeGuest_Params params;
PopulateResizeGuestParameters(plugin_size(), &params);
......@@ -520,7 +493,6 @@ bool BrowserPlugin::ShouldForwardToBrowserPlugin(
case BrowserPluginMsg_SetCursor::ID:
case BrowserPluginMsg_SetMouseLock::ID:
case BrowserPluginMsg_ShouldAcceptTouchEvents::ID:
case BrowserPluginMsg_UpdateRect::ID:
return true;
default:
break;
......@@ -539,14 +511,7 @@ void BrowserPlugin::updateGeometry(
if (!attached())
return;
// In AutoSize mode, guests don't care when the BrowserPlugin container is
// resized. If |!paint_ack_received_|, then we are still waiting on a
// previous resize to be ACK'ed and so we don't issue additional resizes
// until the previous one is ACK'ed.
// TODO(mthiesse): Assess the performance of calling GetAutoSizeAttribute() on
// resize.
if (!paint_ack_received_ ||
(old_width == window_rect.width && old_height == window_rect.height)) {
if (old_width == window_rect.width && old_height == window_rect.height) {
// Let the browser know about the updated view rect.
browser_plugin_manager()->Send(new BrowserPluginHostMsg_UpdateGeometry(
render_view_routing_id_, browser_plugin_instance_id_, plugin_rect_));
......@@ -555,7 +520,6 @@ void BrowserPlugin::updateGeometry(
BrowserPluginHostMsg_ResizeGuest_Params params;
PopulateResizeGuestParameters(plugin_size(), &params);
paint_ack_received_ = false;
browser_plugin_manager()->Send(new BrowserPluginHostMsg_ResizeGuest(
render_view_routing_id_,
browser_plugin_instance_id_,
......@@ -565,7 +529,6 @@ void BrowserPlugin::updateGeometry(
void BrowserPlugin::PopulateResizeGuestParameters(
const gfx::Size& view_size,
BrowserPluginHostMsg_ResizeGuest_Params* params) {
params->size_changed = true;
params->view_size = view_size;
params->scale_factor = GetDeviceScaleFactor();
if (last_device_scale_factor_ != params->scale_factor) {
......
......@@ -201,8 +201,6 @@ class CONTENT_EXPORT BrowserPlugin :
void OnSetCursor(int instance_id, const WebCursor& cursor);
void OnSetMouseLock(int instance_id, bool enable);
void OnShouldAcceptTouchEvents(int instance_id, bool accept);
void OnUpdateRect(int instance_id,
const BrowserPluginMsg_UpdateRect_Params& params);
// This indicates whether this BrowserPlugin has been attached to a
// WebContents.
......@@ -215,7 +213,6 @@ class CONTENT_EXPORT BrowserPlugin :
const int render_view_routing_id_;
blink::WebPluginContainer* container_;
scoped_ptr<BrowserPluginBindings> bindings_;
bool paint_ack_received_;
gfx::Rect plugin_rect_;
float last_device_scale_factor_;
// Bitmap for crashed plugin. Lazily initialized, non-owning pointer.
......
......@@ -173,79 +173,6 @@ TEST_F(BrowserPluginTest, InitialResize) {
ASSERT_TRUE(browser_plugin);
}
TEST_F(BrowserPluginTest, ResizeFlowControl) {
LoadHTML(GetHTMLForBrowserPluginObject().c_str());
MockBrowserPlugin* browser_plugin = GetCurrentPlugin();
ASSERT_TRUE(browser_plugin);
int instance_id = browser_plugin->browser_plugin_instance_id();
// Send an UpdateRect to the BrowserPlugin to make sure the browser sees a
// resize related (SetAutoSize) message.
{
// We send a stale UpdateRect to the BrowserPlugin.
BrowserPluginMsg_UpdateRect_Params update_rect_params;
update_rect_params.view_size = gfx::Size(640, 480);
update_rect_params.is_resize_ack = true;
BrowserPluginMsg_UpdateRect msg(instance_id, update_rect_params);
browser_plugin->OnMessageReceived(msg);
}
browser_plugin_manager()->sink().ClearMessages();
// Resize the browser plugin three times.
ExecuteJavaScript("document.getElementById('browserplugin').width = '641px'");
GetMainFrame()->view()->layout();
ProcessPendingMessages();
ExecuteJavaScript("document.getElementById('browserplugin').width = '642px'");
GetMainFrame()->view()->layout();
ProcessPendingMessages();
ExecuteJavaScript("document.getElementById('browserplugin').width = '643px'");
GetMainFrame()->view()->layout();
ProcessPendingMessages();
// Expect to see one resize messsage in the sink. BrowserPlugin will not issue
// subsequent resize requests until the first request is satisfied by the
// guest. The rest of the messages could be
// BrowserPluginHostMsg_UpdateGeometry msgs.
EXPECT_LE(1u, browser_plugin_manager()->sink().message_count());
for (size_t i = 0; i < browser_plugin_manager()->sink().message_count();
++i) {
const IPC::Message* msg = browser_plugin_manager()->sink().GetMessageAt(i);
if (msg->type() != BrowserPluginHostMsg_ResizeGuest::ID)
EXPECT_EQ(msg->type(), BrowserPluginHostMsg_UpdateGeometry::ID);
}
const IPC::Message* msg =
browser_plugin_manager()->sink().GetUniqueMessageMatching(
BrowserPluginHostMsg_ResizeGuest::ID);
ASSERT_TRUE(msg);
BrowserPluginHostMsg_ResizeGuest::Param param;
BrowserPluginHostMsg_ResizeGuest::Read(msg, &param);
instance_id = param.a;
BrowserPluginHostMsg_ResizeGuest_Params params = param.b;
EXPECT_EQ(641, params.view_size.width());
EXPECT_EQ(480, params.view_size.height());
{
// We send a stale UpdateRect to the BrowserPlugin.
BrowserPluginMsg_UpdateRect_Params update_rect_params;
update_rect_params.view_size = gfx::Size(641, 480);
update_rect_params.is_resize_ack = true;
BrowserPluginMsg_UpdateRect msg(instance_id, update_rect_params);
browser_plugin->OnMessageReceived(msg);
}
// Send the BrowserPlugin another UpdateRect, but this time with a size
// that matches the size of the container.
{
BrowserPluginMsg_UpdateRect_Params update_rect_params;
update_rect_params.view_size = gfx::Size(643, 480);
update_rect_params.is_resize_ack = true;
BrowserPluginMsg_UpdateRect msg(instance_id, update_rect_params);
browser_plugin->OnMessageReceived(msg);
}
}
TEST_F(BrowserPluginTest, RemovePlugin) {
LoadHTML(GetHTMLForBrowserPluginObject().c_str());
MockBrowserPlugin* browser_plugin = GetCurrentPlugin();
......
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