summaryrefslogtreecommitdiff
path: root/content
diff options
context:
space:
mode:
authorMarcin Kosiba <mkosiba@google.com>2014-11-12 17:50:30 +0000
committerMarcin Kosiba <mkosiba@google.com>2014-11-12 18:41:43 +0000
commite578b2d213c837aab9cea5407d30f5c84065cd0e (patch)
tree477b2f998f20fd5986e8dd93832e030332b8bb34 /content
parent53975c7d18295b06744d5736517e1e06ba607193 (diff)
downloadchromium_org-e578b2d213c837aab9cea5407d30f5c84065cd0e.tar.gz
Cherry-pick: Pass the size to the RenderView on creation.
The size update races with the page load creating the opportunity for the page to observe the initial (0,0) renderer size. This patch addresses the issue by sending the initial size together with the RenderView creation request. BUG=424205 Review URL: https://codereview.chromium.org/659093002 Cr-Commit-Position: refs/heads/master@{#303775} Conflicts: chrome/test/data/extensions/platform_apps/web_view/shim/main.js content/browser/renderer_host/render_widget_host_unittest.cc BUG: 17892238 Change-Id: I11dca7e962421d46734d2122ec79bc501a2db09d
Diffstat (limited to 'content')
-rw-r--r--content/browser/compositor/delegated_frame_host.cc2
-rw-r--r--content/browser/renderer_host/render_view_host_impl.cc13
-rw-r--r--content/browser/renderer_host/render_widget_host_impl.cc118
-rw-r--r--content/browser/renderer_host/render_widget_host_impl.h55
-rw-r--r--content/browser/renderer_host/render_widget_host_unittest.cc75
-rw-r--r--content/common/view_messages.h43
-rw-r--r--content/public/test/render_view_test.cc10
-rw-r--r--content/public/test/render_view_test.h5
-rw-r--r--content/renderer/render_thread_impl.cc5
-rw-r--r--content/renderer/render_view_browsertest.cc21
-rw-r--r--content/renderer/render_view_impl.cc27
-rw-r--r--content/renderer/render_view_impl.h6
-rw-r--r--content/renderer/render_view_impl_params.cc10
-rw-r--r--content/renderer/render_view_impl_params.h14
14 files changed, 290 insertions, 114 deletions
diff --git a/content/browser/compositor/delegated_frame_host.cc b/content/browser/compositor/delegated_frame_host.cc
index 70b93ae08e..882840ce8a 100644
--- a/content/browser/compositor/delegated_frame_host.cc
+++ b/content/browser/compositor/delegated_frame_host.cc
@@ -114,7 +114,7 @@ bool DelegatedFrameHost::ShouldCreateResizeLock() {
if (resize_lock_)
return false;
- if (host->should_auto_resize())
+ if (host->auto_resize_enabled())
return false;
gfx::Size desired_size = client_->DesiredFrameSize();
diff --git a/content/browser/renderer_host/render_view_host_impl.cc b/content/browser/renderer_host/render_view_host_impl.cc
index 6b78d74266..8135b99349 100644
--- a/content/browser/renderer_host/render_view_host_impl.cc
+++ b/content/browser/renderer_host/render_view_host_impl.cc
@@ -298,9 +298,14 @@ bool RenderViewHostImpl::CreateRenderView(
params.never_visible = delegate_->IsNeverVisible();
params.window_was_created_with_opener = window_was_created_with_opener;
params.next_page_id = next_page_id;
- GetWebScreenInfo(&params.screen_info);
+ params.enable_auto_resize = auto_resize_enabled();
+ params.min_size = min_size_for_auto_resize();
+ params.max_size = max_size_for_auto_resize();
+ GetResizeParams(&params.initial_size);
- Send(new ViewMsg_New(params));
+ if (!Send(new ViewMsg_New(params)))
+ return false;
+ SetInitialRenderSizeParams(params.initial_size);
// If it's enabled, tell the renderer to set up the Javascript bindings for
// sending messages back to the browser.
@@ -1409,12 +1414,12 @@ void RenderViewHostImpl::EnablePreferredSizeMode() {
void RenderViewHostImpl::EnableAutoResize(const gfx::Size& min_size,
const gfx::Size& max_size) {
- SetShouldAutoResize(true);
+ SetAutoResize(true, min_size, max_size);
Send(new ViewMsg_EnableAutoResize(GetRoutingID(), min_size, max_size));
}
void RenderViewHostImpl::DisableAutoResize(const gfx::Size& new_size) {
- SetShouldAutoResize(false);
+ SetAutoResize(false, gfx::Size(), gfx::Size());
Send(new ViewMsg_DisableAutoResize(GetRoutingID(), new_size));
if (!new_size.IsEmpty())
GetView()->SetSize(new_size);
diff --git a/content/browser/renderer_host/render_widget_host_impl.cc b/content/browser/renderer_host/render_widget_host_impl.cc
index a77279a1d3..8b290d6efa 100644
--- a/content/browser/renderer_host/render_widget_host_impl.cc
+++ b/content/browser/renderer_host/render_widget_host_impl.cc
@@ -164,12 +164,10 @@ RenderWidgetHostImpl::RenderWidgetHostImpl(RenderWidgetHostDelegate* delegate,
surface_id_(0),
is_loading_(false),
is_hidden_(hidden),
- is_fullscreen_(false),
repaint_ack_pending_(false),
resize_ack_pending_(false),
screen_info_out_of_date_(false),
- top_controls_layout_height_(0.f),
- should_auto_resize_(false),
+ auto_resize_enabled_(false),
waiting_for_screen_rects_ack_(false),
needs_repainting_on_restore_(false),
is_unresponsive_(false),
@@ -359,7 +357,8 @@ void RenderWidgetHostImpl::ResetSizeAndRepaintPendingFlags() {
"renderer_host", "RenderWidgetHostImpl::repaint_ack_pending_", this);
}
repaint_ack_pending_ = false;
- last_requested_size_.SetSize(0, 0);
+ if (old_resize_params_)
+ old_resize_params_->new_size = gfx::Size();
}
void RenderWidgetHostImpl::SendScreenRects() {
@@ -561,61 +560,80 @@ void RenderWidgetHostImpl::WasShown(const ui::LatencyInfo& latency_info) {
WasResized();
}
+void RenderWidgetHostImpl::GetResizeParams(
+ ViewMsg_Resize_Params* resize_params) {
+ *resize_params = ViewMsg_Resize_Params();
+
+ if (!screen_info_) {
+ screen_info_.reset(new blink::WebScreenInfo);
+ GetWebScreenInfo(screen_info_.get());
+ }
+ resize_params->screen_info = *screen_info_;
+ resize_params->resizer_rect = GetRootWindowResizerRect();
+
+ if (view_) {
+ resize_params->new_size = view_->GetRequestedRendererSize();
+ resize_params->physical_backing_size = view_->GetPhysicalBackingSize();
+ resize_params->top_controls_layout_height =
+ view_->GetTopControlsLayoutHeight();
+ resize_params->visible_viewport_size = view_->GetVisibleViewportSize();
+ resize_params->is_fullscreen = IsFullscreen();
+ }
+}
+
+void RenderWidgetHostImpl::SetInitialRenderSizeParams(
+ const ViewMsg_Resize_Params& resize_params) {
+ // We don't expect to receive an ACK when the requested size or the physical
+ // backing size is empty, or when the main viewport size didn't change.
+ if (!resize_params.new_size.IsEmpty() &&
+ !resize_params.physical_backing_size.IsEmpty()) {
+ resize_ack_pending_ = g_check_for_pending_resize_ack;
+ }
+
+ old_resize_params_ =
+ make_scoped_ptr(new ViewMsg_Resize_Params(resize_params));
+}
+
void RenderWidgetHostImpl::WasResized() {
// Skip if the |delegate_| has already been detached because
// it's web contents is being deleted.
if (resize_ack_pending_ || !process_->HasConnection() || !view_ ||
- !renderer_initialized_ || should_auto_resize_ || !delegate_) {
+ !renderer_initialized_ || auto_resize_enabled_ || !delegate_) {
return;
}
- gfx::Size new_size(view_->GetRequestedRendererSize());
-
- gfx::Size old_physical_backing_size = physical_backing_size_;
- physical_backing_size_ = view_->GetPhysicalBackingSize();
- bool was_fullscreen = is_fullscreen_;
- is_fullscreen_ = IsFullscreen();
- float old_top_controls_layout_height =
- top_controls_layout_height_;
- top_controls_layout_height_ =
- view_->GetTopControlsLayoutHeight();
- gfx::Size old_visible_viewport_size = visible_viewport_size_;
- visible_viewport_size_ = view_->GetVisibleViewportSize();
-
- bool size_changed = new_size != last_requested_size_;
- bool side_payload_changed =
- screen_info_out_of_date_ ||
- old_physical_backing_size != physical_backing_size_ ||
- was_fullscreen != is_fullscreen_ ||
- old_top_controls_layout_height !=
- top_controls_layout_height_ ||
- old_visible_viewport_size != visible_viewport_size_;
+ bool size_changed = true;
+ bool side_payload_changed = screen_info_out_of_date_;
+ scoped_ptr<ViewMsg_Resize_Params> params(new ViewMsg_Resize_Params);
+
+ GetResizeParams(params.get());
+ if (old_resize_params_) {
+ size_changed = old_resize_params_->new_size != params->new_size;
+ side_payload_changed =
+ side_payload_changed ||
+ old_resize_params_->physical_backing_size !=
+ params->physical_backing_size ||
+ old_resize_params_->is_fullscreen != params->is_fullscreen ||
+ old_resize_params_->top_controls_layout_height !=
+ params->top_controls_layout_height ||
+ old_resize_params_->visible_viewport_size !=
+ params->visible_viewport_size;
+ }
if (!size_changed && !side_payload_changed)
return;
- if (!screen_info_) {
- screen_info_.reset(new blink::WebScreenInfo);
- GetWebScreenInfo(screen_info_.get());
- }
-
// We don't expect to receive an ACK when the requested size or the physical
// backing size is empty, or when the main viewport size didn't change.
- if (!new_size.IsEmpty() && !physical_backing_size_.IsEmpty() && size_changed)
+ if (!params->new_size.IsEmpty() && !params->physical_backing_size.IsEmpty() &&
+ size_changed) {
resize_ack_pending_ = g_check_for_pending_resize_ack;
+ }
- ViewMsg_Resize_Params params;
- params.screen_info = *screen_info_;
- params.new_size = new_size;
- params.physical_backing_size = physical_backing_size_;
- params.top_controls_layout_height = top_controls_layout_height_;
- params.visible_viewport_size = visible_viewport_size_;
- params.resizer_rect = GetRootWindowResizerRect();
- params.is_fullscreen = is_fullscreen_;
- if (!Send(new ViewMsg_Resize(routing_id_, params))) {
+ if (!Send(new ViewMsg_Resize(routing_id_, *params))) {
resize_ack_pending_ = false;
} else {
- last_requested_size_ = new_size;
+ old_resize_params_.swap(params);
}
}
@@ -741,7 +759,7 @@ void RenderWidgetHostImpl::WaitForSurface() {
// size of the view_. (For auto-sized views, current_size_ is updated during
// UpdateRect messages.)
gfx::Size view_size = current_size_;
- if (!should_auto_resize_) {
+ if (!auto_resize_enabled_) {
// Get the desired size from the current view bounds.
gfx::Rect view_rect = view_->GetViewBounds();
if (view_rect.IsEmpty())
@@ -795,7 +813,7 @@ void RenderWidgetHostImpl::WaitForSurface() {
// For auto-resized views, current_size_ determines the view_size and it
// may have changed during the handling of an UpdateRect message.
- if (should_auto_resize_)
+ if (auto_resize_enabled_)
view_size = current_size_;
// Break now if we got a backing store or accelerated surface of the
@@ -1375,8 +1393,12 @@ bool RenderWidgetHostImpl::IsFullscreen() const {
return false;
}
-void RenderWidgetHostImpl::SetShouldAutoResize(bool enable) {
- should_auto_resize_ = enable;
+void RenderWidgetHostImpl::SetAutoResize(bool enable,
+ const gfx::Size& min_size,
+ const gfx::Size& max_size) {
+ auto_resize_enabled_ = enable;
+ min_size_for_auto_resize_ = min_size;
+ max_size_for_auto_resize_ = max_size;
}
void RenderWidgetHostImpl::Destroy() {
@@ -1571,7 +1593,7 @@ void RenderWidgetHostImpl::OnUpdateRect(
DidUpdateBackingStore(params, paint_start);
- if (should_auto_resize_) {
+ if (auto_resize_enabled_) {
bool post_callback = new_auto_size_.IsEmpty();
new_auto_size_ = params.view_size;
if (post_callback) {
@@ -2073,7 +2095,7 @@ void RenderWidgetHostImpl::DelayedAutoResized() {
// indicate that no callback is in progress (i.e. without this line
// DelayedAutoResized will not get called again).
new_auto_size_.SetSize(0, 0);
- if (!should_auto_resize_)
+ if (!auto_resize_enabled_)
return;
OnRenderAutoResized(new_size);
diff --git a/content/browser/renderer_host/render_widget_host_impl.h b/content/browser/renderer_host/render_widget_host_impl.h
index 80cbfb36df..d91f044b83 100644
--- a/content/browser/renderer_host/render_widget_host_impl.h
+++ b/content/browser/renderer_host/render_widget_host_impl.h
@@ -45,6 +45,7 @@ struct ViewHostMsg_BeginSmoothScroll_Params;
struct ViewHostMsg_SelectionBounds_Params;
struct ViewHostMsg_TextInputState_Params;
struct ViewHostMsg_UpdateRect_Params;
+struct ViewMsg_Resize_Params;
namespace base {
class TimeTicks;
@@ -447,7 +448,17 @@ class CONTENT_EXPORT RenderWidgetHostImpl
// Indicates whether the renderer drives the RenderWidgetHosts's size or the
// other way around.
- bool should_auto_resize() { return should_auto_resize_; }
+ bool auto_resize_enabled() { return auto_resize_enabled_; }
+
+ // The minimum size of this renderer when auto-resize is enabled.
+ const gfx::Size& min_size_for_auto_resize() const {
+ return min_size_for_auto_resize_;
+ }
+
+ // The maximum size of this renderer when auto-resize is enabled.
+ const gfx::Size& max_size_for_auto_resize() const {
+ return max_size_for_auto_resize_;
+ }
void ComputeTouchLatency(const ui::LatencyInfo& latency_info);
void FrameSwapped(const ui::LatencyInfo& latency_info);
@@ -549,7 +560,16 @@ class CONTENT_EXPORT RenderWidgetHostImpl
// Indicates if the render widget host should track the render widget's size
// as opposed to visa versa.
- void SetShouldAutoResize(bool enable);
+ void SetAutoResize(bool enable,
+ const gfx::Size& min_size,
+ const gfx::Size& max_size);
+
+ // Fills in the |resize_params| struct.
+ void GetResizeParams(ViewMsg_Resize_Params* resize_params);
+
+ // Sets the |resize_params| that were sent to the renderer bundled with the
+ // request to create a new RenderWidget.
+ void SetInitialRenderSizeParams(const ViewMsg_Resize_Params& resize_params);
// Expose increment/decrement of the in-flight event count, so
// RenderViewHostImpl can account for in-flight beforeunload/unload events.
@@ -707,9 +727,6 @@ class CONTENT_EXPORT RenderWidgetHostImpl
// most recent call to process_->WidgetRestored() / WidgetHidden().
bool is_hidden_;
- // Indicates whether a page is fullscreen or not.
- bool is_fullscreen_;
-
// Set if we are waiting for a repaint ack for the view.
bool repaint_ack_pending_;
@@ -727,31 +744,21 @@ class CONTENT_EXPORT RenderWidgetHostImpl
// The current size of the RenderWidget.
gfx::Size current_size_;
- // The size of the view's backing surface in non-DPI-adjusted pixels.
- gfx::Size physical_backing_size_;
-
- // The amount that the viewport size given to Blink was shrunk by the URL-bar
- // (always 0 on platforms where URL-bar hiding isn't supported).
- float top_controls_layout_height_;
-
- // The size of the visible viewport, which may be smaller than the view if the
- // view is partially occluded (e.g. by a virtual keyboard). The size is in
- // DPI-adjusted pixels.
- gfx::Size visible_viewport_size_;
-
- // The size we last sent as requested size to the renderer. |current_size_|
- // is only updated once the resize message has been ack'd. This on the other
- // hand is updated when the resize message is sent. This is very similar to
- // |resize_ack_pending_|, but the latter is not set if the new size has width
- // or height zero, which is why we need this too.
- gfx::Size last_requested_size_;
+ // Resize information that was previously sent to the renderer.
+ scoped_ptr<ViewMsg_Resize_Params> old_resize_params_;
// The next auto resize to send.
gfx::Size new_auto_size_;
// True if the render widget host should track the render widget's size as
// opposed to visa versa.
- bool should_auto_resize_;
+ bool auto_resize_enabled_;
+
+ // The minimum size for the render widget if auto-resize is enabled.
+ gfx::Size min_size_for_auto_resize_;
+
+ // The maximum size for the render widget if auto-resize is enabled.
+ gfx::Size max_size_for_auto_resize_;
bool waiting_for_screen_rects_ack_;
gfx::Rect last_view_screen_rect_;
diff --git a/content/browser/renderer_host/render_widget_host_unittest.cc b/content/browser/renderer_host/render_widget_host_unittest.cc
index d70356d9bf..f597fb42f3 100644
--- a/content/browser/renderer_host/render_widget_host_unittest.cc
+++ b/content/browser/renderer_host/render_widget_host_unittest.cc
@@ -144,9 +144,11 @@ class MockRenderWidgetHost : public RenderWidgetHostImpl {
}
// Allow poking at a few private members.
+ using RenderWidgetHostImpl::GetResizeParams;
using RenderWidgetHostImpl::OnUpdateRect;
using RenderWidgetHostImpl::RendererExited;
- using RenderWidgetHostImpl::last_requested_size_;
+ using RenderWidgetHostImpl::SetInitialRenderSizeParams;
+ using RenderWidgetHostImpl::old_resize_params_;
using RenderWidgetHostImpl::is_hidden_;
using RenderWidgetHostImpl::resize_ack_pending_;
using RenderWidgetHostImpl::input_router_;
@@ -452,10 +454,13 @@ class RenderWidgetHostTest : public testing::Test {
host_.reset(
new MockRenderWidgetHost(delegate_.get(), process_, MSG_ROUTING_NONE));
view_.reset(new TestView(host_.get()));
+ ConfigureView(view_.get());
host_->SetView(view_.get());
+ SetInitialRenderSizeParams();
host_->Init();
host_->DisableGestureDebounce();
}
+
virtual void TearDown() {
view_.reset();
host_.reset();
@@ -476,6 +481,15 @@ class RenderWidgetHostTest : public testing::Test {
base::MessageLoop::current()->RunUntilIdle();
}
+ void SetInitialRenderSizeParams() {
+ ViewMsg_Resize_Params render_size_params;
+ host_->GetResizeParams(&render_size_params);
+ host_->SetInitialRenderSizeParams(render_size_params);
+ }
+
+ virtual void ConfigureView(TestView* view) {
+ }
+
int64 GetLatencyComponentId() {
return host_->GetLatencyComponentId();
}
@@ -642,7 +656,7 @@ TEST_F(RenderWidgetHostTest, Resize) {
view_->SetMockPhysicalBackingSize(gfx::Size());
host_->WasResized();
EXPECT_FALSE(host_->resize_ack_pending_);
- EXPECT_EQ(original_size.size(), host_->last_requested_size_);
+ EXPECT_EQ(original_size.size(), host_->old_resize_params_->new_size);
EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID));
// Setting the bounds to a "real" rect should send out the notification.
@@ -651,7 +665,7 @@ TEST_F(RenderWidgetHostTest, Resize) {
view_->ClearMockPhysicalBackingSize();
host_->WasResized();
EXPECT_FALSE(host_->resize_ack_pending_);
- EXPECT_EQ(original_size.size(), host_->last_requested_size_);
+ EXPECT_EQ(original_size.size(), host_->old_resize_params_->new_size);
EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID));
// Send out a update that's not a resize ack after setting resize ack pending
@@ -666,7 +680,7 @@ TEST_F(RenderWidgetHostTest, Resize) {
process_->InitUpdateRectParams(&params);
host_->OnUpdateRect(params);
EXPECT_TRUE(host_->resize_ack_pending_);
- EXPECT_EQ(second_size.size(), host_->last_requested_size_);
+ EXPECT_EQ(second_size.size(), host_->old_resize_params_->new_size);
// Sending out a new notification should NOT send out a new IPC message since
// a resize ACK is pending.
@@ -675,7 +689,7 @@ TEST_F(RenderWidgetHostTest, Resize) {
view_->set_bounds(third_size);
host_->WasResized();
EXPECT_TRUE(host_->resize_ack_pending_);
- EXPECT_EQ(second_size.size(), host_->last_requested_size_);
+ EXPECT_EQ(second_size.size(), host_->old_resize_params_->new_size);
EXPECT_FALSE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID));
// Send a update that's a resize ack, but for the original_size we sent. Since
@@ -686,7 +700,7 @@ TEST_F(RenderWidgetHostTest, Resize) {
params.view_size = original_size.size();
host_->OnUpdateRect(params);
EXPECT_TRUE(host_->resize_ack_pending_);
- EXPECT_EQ(third_size.size(), host_->last_requested_size_);
+ EXPECT_EQ(third_size.size(), host_->old_resize_params_->new_size);
ASSERT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID));
// Send the resize ack for the latest size.
@@ -694,7 +708,7 @@ TEST_F(RenderWidgetHostTest, Resize) {
params.view_size = third_size.size();
host_->OnUpdateRect(params);
EXPECT_FALSE(host_->resize_ack_pending_);
- EXPECT_EQ(third_size.size(), host_->last_requested_size_);
+ EXPECT_EQ(third_size.size(), host_->old_resize_params_->new_size);
ASSERT_FALSE(process_->sink().GetFirstMessageMatching(ViewMsg_Resize::ID));
// Now clearing the bounds should send out a notification but we shouldn't
@@ -704,7 +718,7 @@ TEST_F(RenderWidgetHostTest, Resize) {
view_->set_bounds(gfx::Rect());
host_->WasResized();
EXPECT_FALSE(host_->resize_ack_pending_);
- EXPECT_EQ(gfx::Size(), host_->last_requested_size_);
+ EXPECT_EQ(gfx::Size(), host_->old_resize_params_->new_size);
EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID));
// Send a rect that has no area but has either width or height set.
@@ -712,21 +726,21 @@ TEST_F(RenderWidgetHostTest, Resize) {
view_->set_bounds(gfx::Rect(0, 0, 0, 30));
host_->WasResized();
EXPECT_FALSE(host_->resize_ack_pending_);
- EXPECT_EQ(gfx::Size(0, 30), host_->last_requested_size_);
+ EXPECT_EQ(gfx::Size(0, 30), host_->old_resize_params_->new_size);
EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID));
// Set the same size again. It should not be sent again.
process_->sink().ClearMessages();
host_->WasResized();
EXPECT_FALSE(host_->resize_ack_pending_);
- EXPECT_EQ(gfx::Size(0, 30), host_->last_requested_size_);
+ EXPECT_EQ(gfx::Size(0, 30), host_->old_resize_params_->new_size);
EXPECT_FALSE(process_->sink().GetFirstMessageMatching(ViewMsg_Resize::ID));
// A different size should be sent again, however.
view_->set_bounds(gfx::Rect(0, 0, 0, 31));
host_->WasResized();
EXPECT_FALSE(host_->resize_ack_pending_);
- EXPECT_EQ(gfx::Size(0, 31), host_->last_requested_size_);
+ EXPECT_EQ(gfx::Size(0, 31), host_->old_resize_params_->new_size);
EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID));
}
@@ -741,7 +755,7 @@ TEST_F(RenderWidgetHostTest, ResizeThenCrash) {
view_->set_bounds(original_size);
host_->WasResized();
EXPECT_TRUE(host_->resize_ack_pending_);
- EXPECT_EQ(original_size.size(), host_->last_requested_size_);
+ EXPECT_EQ(original_size.size(), host_->old_resize_params_->new_size);
EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID));
// Simulate a renderer crash before the update message. Ensure all the
@@ -750,7 +764,7 @@ TEST_F(RenderWidgetHostTest, ResizeThenCrash) {
host_->SetView(NULL);
host_->RendererExited(base::TERMINATION_STATUS_PROCESS_CRASHED, -1);
EXPECT_FALSE(host_->resize_ack_pending_);
- EXPECT_EQ(gfx::Size(), host_->last_requested_size_);
+ EXPECT_EQ(gfx::Size(), host_->old_resize_params_->new_size);
// Reset the view so we can exit the test cleanly.
host_->SetView(view_.get());
@@ -1506,4 +1520,39 @@ TEST_F(RenderWidgetHostTest, RendererExitedResetsIsHidden) {
ASSERT_FALSE(host_->input_router()->HasPendingEvents());
}
+TEST_F(RenderWidgetHostTest, ResizeParams) {
+ gfx::Rect bounds(0, 0, 100, 100);
+ gfx::Size physical_backing_size(40, 50);
+ view_->set_bounds(bounds);
+ view_->SetMockPhysicalBackingSize(physical_backing_size);
+
+ ViewMsg_Resize_Params resize_params;
+ host_->GetResizeParams(&resize_params);
+ EXPECT_EQ(bounds.size(), resize_params.new_size);
+ EXPECT_EQ(physical_backing_size, resize_params.physical_backing_size);
+}
+
+class RenderWidgetHostInitialSizeTest : public RenderWidgetHostTest {
+ public:
+ RenderWidgetHostInitialSizeTest()
+ : RenderWidgetHostTest(), initial_size_(200, 100) {}
+
+ virtual void ConfigureView(TestView* view) override {
+ view->set_bounds(gfx::Rect(initial_size_));
+ }
+
+ protected:
+ gfx::Size initial_size_;
+};
+
+TEST_F(RenderWidgetHostInitialSizeTest, InitialSize) {
+ // Having an initial size set means that the size information had been sent
+ // with the reqiest to new up the RenderView and so subsequent WasResized
+ // calls should not result in new IPC (unless the size has actually changed).
+ host_->WasResized();
+ EXPECT_FALSE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID));
+ EXPECT_EQ(initial_size_, host_->old_resize_params_->new_size);
+ EXPECT_TRUE(host_->resize_ack_pending_);
+}
+
} // namespace content
diff --git a/content/common/view_messages.h b/content/common/view_messages.h
index 66aa5afdda..9e433b5e93 100644
--- a/content/common/view_messages.h
+++ b/content/common/view_messages.h
@@ -406,6 +406,26 @@ IPC_STRUCT_BEGIN(ViewHostMsg_UpdateRect_Params)
IPC_STRUCT_MEMBER(int, flags)
IPC_STRUCT_END()
+IPC_STRUCT_BEGIN(ViewMsg_Resize_Params)
+ // Information about the screen (dpi, depth, etc..).
+ IPC_STRUCT_MEMBER(blink::WebScreenInfo, screen_info)
+ // The size of the renderer.
+ IPC_STRUCT_MEMBER(gfx::Size, new_size)
+ // The size of the view's backing surface in non-DPI-adjusted pixels.
+ IPC_STRUCT_MEMBER(gfx::Size, physical_backing_size)
+ // The amount that the viewport size given to Blink was shrunk by the URL-bar
+ // (always 0 on platforms where URL-bar hiding isn't supported).
+ IPC_STRUCT_MEMBER(float, top_controls_layout_height)
+ // The size of the visible viewport, which may be smaller than the view if the
+ // view is partially occluded (e.g. by a virtual keyboard). The size is in
+ // DPI-adjusted pixels.
+ IPC_STRUCT_MEMBER(gfx::Size, visible_viewport_size)
+ // The resizer rect.
+ IPC_STRUCT_MEMBER(gfx::Rect, resizer_rect)
+ // Indicates whether a page is fullscreen or not.
+ IPC_STRUCT_MEMBER(bool, is_fullscreen)
+IPC_STRUCT_END()
+
IPC_STRUCT_BEGIN(ViewMsg_New_Params)
// Renderer-wide preferences.
IPC_STRUCT_MEMBER(content::RendererPreferences, renderer_preferences)
@@ -453,8 +473,17 @@ IPC_STRUCT_BEGIN(ViewMsg_New_Params)
// to a view and are only updated by the renderer after this initial value.
IPC_STRUCT_MEMBER(int32, next_page_id)
- // The properties of the screen associated with the view.
- IPC_STRUCT_MEMBER(blink::WebScreenInfo, screen_info)
+ // The initial renderer size.
+ IPC_STRUCT_MEMBER(ViewMsg_Resize_Params, initial_size)
+
+ // Whether to enable auto-resize.
+ IPC_STRUCT_MEMBER(bool, enable_auto_resize)
+
+ // The minimum size to layout the page if auto-resize is enabled.
+ IPC_STRUCT_MEMBER(gfx::Size, min_size)
+
+ // The maximum size to layout the page if auto-resize is enabled.
+ IPC_STRUCT_MEMBER(gfx::Size, max_size)
IPC_STRUCT_END()
IPC_STRUCT_BEGIN(ViewMsg_PostMessage_Params)
@@ -557,16 +586,6 @@ IPC_MESSAGE_CONTROL0(ViewMsg_TimezoneChange)
// Expects a Close_ACK message when finished.
IPC_MESSAGE_ROUTED0(ViewMsg_Close)
-IPC_STRUCT_BEGIN(ViewMsg_Resize_Params)
- IPC_STRUCT_MEMBER(blink::WebScreenInfo, screen_info)
- IPC_STRUCT_MEMBER(gfx::Size, new_size)
- IPC_STRUCT_MEMBER(gfx::Size, physical_backing_size)
- IPC_STRUCT_MEMBER(float, top_controls_layout_height)
- IPC_STRUCT_MEMBER(gfx::Size, visible_viewport_size)
- IPC_STRUCT_MEMBER(gfx::Rect, resizer_rect)
- IPC_STRUCT_MEMBER(bool, is_fullscreen)
-IPC_STRUCT_END()
-
// Tells the render view to change its size. A ViewHostMsg_UpdateRect message
// is generated in response provided new_size is not empty and not equal to
// the view's current size. The generated ViewHostMsg_UpdateRect message will
diff --git a/content/public/test/render_view_test.cc b/content/public/test/render_view_test.cc
index 25615bdf6a..4d94b51974 100644
--- a/content/public/test/render_view_test.cc
+++ b/content/public/test/render_view_test.cc
@@ -200,7 +200,11 @@ void RenderViewTest::SetUp() {
false, // hidden
false, // never_visible
1, // next_page_id
- blink::WebScreenInfo());
+ *InitialSizeParams(),
+ false, // enable_auto_resize
+ gfx::Size(), // min_size
+ gfx::Size() // max_size
+ );
view->AddRef();
view_ = view;
}
@@ -403,6 +407,10 @@ ContentRendererClient* RenderViewTest::CreateContentRendererClient() {
return new ContentRendererClient;
}
+scoped_ptr<ViewMsg_Resize_Params> RenderViewTest::InitialSizeParams() {
+ return make_scoped_ptr(new ViewMsg_Resize_Params());
+}
+
void RenderViewTest::GoToOffset(int offset, const PageState& state) {
RenderViewImpl* impl = static_cast<RenderViewImpl*>(view_);
diff --git a/content/public/test/render_view_test.h b/content/public/test/render_view_test.h
index 7f10ee864a..b42897bf02 100644
--- a/content/public/test/render_view_test.h
+++ b/content/public/test/render_view_test.h
@@ -19,6 +19,8 @@
#include "third_party/WebKit/public/platform/Platform.h"
#include "third_party/WebKit/public/web/WebFrame.h"
+struct ViewMsg_Resize_Params;
+
namespace blink {
class WebWidget;
}
@@ -132,6 +134,9 @@ class RenderViewTest : public testing::Test {
virtual ContentBrowserClient* CreateContentBrowserClient();
virtual ContentRendererClient* CreateContentRendererClient();
+ // Allows a subclass to customize the initial size of the RenderView.
+ virtual scoped_ptr<ViewMsg_Resize_Params> InitialSizeParams();
+
// testing::Test
virtual void SetUp() OVERRIDE;
diff --git a/content/renderer/render_thread_impl.cc b/content/renderer/render_thread_impl.cc
index 3b2ff69cf4..e20f8d04fb 100644
--- a/content/renderer/render_thread_impl.cc
+++ b/content/renderer/render_thread_impl.cc
@@ -1374,7 +1374,10 @@ void RenderThreadImpl::OnCreateNewView(const ViewMsg_New_Params& params) {
params.hidden,
params.never_visible,
params.next_page_id,
- params.screen_info);
+ params.initial_size,
+ params.enable_auto_resize,
+ params.min_size,
+ params.max_size);
}
GpuChannelHost* RenderThreadImpl::EstablishGpuChannelSync(
diff --git a/content/renderer/render_view_browsertest.cc b/content/renderer/render_view_browsertest.cc
index e0441fa598..c108319adf 100644
--- a/content/renderer/render_view_browsertest.cc
+++ b/content/renderer/render_view_browsertest.cc
@@ -2487,4 +2487,25 @@ TEST_F(RenderViewImplTest, NavigationStartOverride) {
EXPECT_LE(late_nav_reported_start, after_navigation);
}
+class RenderViewImplInitialSizeTest : public RenderViewImplTest {
+ public:
+ RenderViewImplInitialSizeTest()
+ : RenderViewImplTest(), initial_size_(200, 100) {}
+
+ protected:
+ virtual scoped_ptr<ViewMsg_Resize_Params> InitialSizeParams() override {
+ scoped_ptr<ViewMsg_Resize_Params> initial_size_params(
+ new ViewMsg_Resize_Params());
+ initial_size_params->new_size = initial_size_;
+ return initial_size_params.Pass();
+ }
+
+ gfx::Size initial_size_;
+};
+
+TEST_F(RenderViewImplInitialSizeTest, InitialSize) {
+ ASSERT_EQ(initial_size_, view_->GetSize());
+ ASSERT_EQ(initial_size_, gfx::Size(view_->GetWebView()->size()));
+}
+
} // namespace content
diff --git a/content/renderer/render_view_impl.cc b/content/renderer/render_view_impl.cc
index 3a1eb455d7..87022492c4 100644
--- a/content/renderer/render_view_impl.cc
+++ b/content/renderer/render_view_impl.cc
@@ -654,7 +654,7 @@ void ApplyFontsFromMap(const ScriptFontFamilyMap& map,
RenderViewImpl::RenderViewImpl(RenderViewImplParams* params)
: RenderWidget(blink::WebPopupTypeNone,
- params->screen_info,
+ params->initial_size.screen_info,
params->swapped_out,
params->hidden,
params->never_visible),
@@ -799,6 +799,12 @@ void RenderViewImpl::Initialize(RenderViewImplParams* params) {
OnSetRendererPrefs(params->renderer_prefs);
+ if (!params->enable_auto_resize) {
+ OnResize(params->initial_size);
+ } else {
+ OnEnableAutoResize(params->min_size, params->max_size);
+ }
+
new MHTMLGenerator(this);
#if defined(OS_MACOSX)
new TextInputClientObserver(this);
@@ -1143,7 +1149,10 @@ RenderViewImpl* RenderViewImpl::Create(
bool hidden,
bool never_visible,
int32 next_page_id,
- const blink::WebScreenInfo& screen_info) {
+ const ViewMsg_Resize_Params& initial_size,
+ bool enable_auto_resize,
+ const gfx::Size& min_size,
+ const gfx::Size& max_size) {
DCHECK(routing_id != MSG_ROUTING_NONE);
RenderViewImplParams params(opener_id,
window_was_created_with_opener,
@@ -1160,7 +1169,10 @@ RenderViewImpl* RenderViewImpl::Create(
hidden,
never_visible,
next_page_id,
- screen_info);
+ initial_size,
+ enable_auto_resize,
+ min_size,
+ max_size);
RenderViewImpl* render_view = NULL;
if (g_create_render_view_impl)
render_view = g_create_render_view_impl(&params);
@@ -1672,6 +1684,9 @@ WebView* RenderViewImpl::createView(WebLocalFrame* creator,
// TODO(vangelis): Can we tell if the new view will be a background page?
bool never_visible = false;
+ ViewMsg_Resize_Params initial_size = ViewMsg_Resize_Params();
+ initial_size.screen_info = screen_info_;
+
// The initial hidden state for the RenderViewImpl here has to match what the
// browser will eventually decide for the given disposition. Since we have to
// return from this call synchronously, we just have to make our best guess
@@ -1693,7 +1708,11 @@ WebView* RenderViewImpl::createView(WebLocalFrame* creator,
params.disposition == NEW_BACKGROUND_TAB, // hidden
never_visible,
1, // next_page_id
- screen_info_);
+ initial_size,
+ false, // enable_auto_resize
+ gfx::Size(), // min_size
+ gfx::Size() // max_size
+ );
view->opened_by_user_gesture_ = params.user_gesture;
// Record whether the creator frame is trying to suppress the opener field.
diff --git a/content/renderer/render_view_impl.h b/content/renderer/render_view_impl.h
index a22c3ff905..6bbdaa2fce 100644
--- a/content/renderer/render_view_impl.h
+++ b/content/renderer/render_view_impl.h
@@ -76,6 +76,7 @@ class SkBitmap;
struct PP_NetAddress_Private;
struct FrameMsg_Navigate_Params;
struct ViewMsg_PostMessage_Params;
+struct ViewMsg_Resize_Params;
struct ViewMsg_StopFinding_Params;
namespace base {
@@ -179,7 +180,10 @@ class CONTENT_EXPORT RenderViewImpl
bool hidden,
bool never_visible,
int32 next_page_id,
- const blink::WebScreenInfo& screen_info);
+ const ViewMsg_Resize_Params& initial_size,
+ bool enable_auto_resize,
+ const gfx::Size& min_size,
+ const gfx::Size& max_size);
// Used by content_layouttest_support to hook into the creation of
// RenderViewImpls.
diff --git a/content/renderer/render_view_impl_params.cc b/content/renderer/render_view_impl_params.cc
index 6864a3d0ed..5a39b4c717 100644
--- a/content/renderer/render_view_impl_params.cc
+++ b/content/renderer/render_view_impl_params.cc
@@ -22,7 +22,10 @@ RenderViewImplParams::RenderViewImplParams(
bool hidden,
bool never_visible,
int32 next_page_id,
- const blink::WebScreenInfo& screen_info)
+ const ViewMsg_Resize_Params& initial_size,
+ bool enable_auto_resize,
+ const gfx::Size& min_size,
+ const gfx::Size& max_size)
: opener_id(opener_id),
window_was_created_with_opener(window_was_created_with_opener),
renderer_prefs(renderer_prefs),
@@ -38,7 +41,10 @@ RenderViewImplParams::RenderViewImplParams(
hidden(hidden),
never_visible(never_visible),
next_page_id(next_page_id),
- screen_info(screen_info) {}
+ initial_size(initial_size),
+ enable_auto_resize(enable_auto_resize),
+ min_size(min_size),
+ max_size(max_size) {}
RenderViewImplParams::~RenderViewImplParams() {}
diff --git a/content/renderer/render_view_impl_params.h b/content/renderer/render_view_impl_params.h
index ad9a26c61d..173b6a4eff 100644
--- a/content/renderer/render_view_impl_params.h
+++ b/content/renderer/render_view_impl_params.h
@@ -9,7 +9,9 @@
#include "base/memory/ref_counted.h"
#include "base/strings/string16.h"
#include "content/common/content_export.h"
-#include "content/common/view_message_enums.h"
+#include "ui/gfx/geometry/size.h"
+
+struct ViewMsg_Resize_Params;
namespace blink {
struct WebScreenInfo;
@@ -37,7 +39,10 @@ struct CONTENT_EXPORT RenderViewImplParams {
bool hidden,
bool never_visible,
int32 next_page_id,
- const blink::WebScreenInfo& screen_info);
+ const ViewMsg_Resize_Params& initial_size,
+ bool enable_auto_resize,
+ const gfx::Size& min_size,
+ const gfx::Size& max_size);
~RenderViewImplParams();
int32 opener_id;
@@ -55,7 +60,10 @@ struct CONTENT_EXPORT RenderViewImplParams {
bool hidden;
bool never_visible;
int32 next_page_id;
- const blink::WebScreenInfo& screen_info;
+ const ViewMsg_Resize_Params& initial_size;
+ bool enable_auto_resize;
+ gfx::Size min_size;
+ gfx::Size max_size;
};
} // namespace content