summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormkosiba <mkosiba@chromium.org>2014-11-11 17:21:36 -0800
committerCommit bot <commit-bot@chromium.org>2014-11-12 01:22:00 +0000
commit58fa72f0dcafa8250ed0e88a0a666624c31bcafa (patch)
tree84c88b845266dbfdba087d33925082de3475fb3c
parenta0aa60810717ba0c4f3626bd4f28ebd07e819c9b (diff)
downloadchromium_src-58fa72f0dcafa8250ed0e88a0a666624c31bcafa.zip
chromium_src-58fa72f0dcafa8250ed0e88a0a666624c31bcafa.tar.gz
chromium_src-58fa72f0dcafa8250ed0e88a0a666624c31bcafa.tar.bz2
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}
-rw-r--r--chrome/test/data/extensions/platform_apps/web_view/shim/main.js1
-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
-rw-r--r--extensions/browser/guest_view/guest_view_base.cc6
-rw-r--r--extensions/test/data/web_view/apitest/main.js3
17 files changed, 290 insertions, 124 deletions
diff --git a/chrome/test/data/extensions/platform_apps/web_view/shim/main.js b/chrome/test/data/extensions/platform_apps/web_view/shim/main.js
index 332a85e..a7afd75 100644
--- a/chrome/test/data/extensions/platform_apps/web_view/shim/main.js
+++ b/chrome/test/data/extensions/platform_apps/web_view/shim/main.js
@@ -140,7 +140,6 @@ function testAutosizeHeight() {
webview.addEventListener('sizechanged', function(e) {
switch (step) {
case 1:
- embedder.test.assertEq(0, e.oldHeight);
embedder.test.assertEq(200, e.newHeight);
// Change the maxheight to verify that we see the change.
webview.maxheight = 50;
diff --git a/content/browser/compositor/delegated_frame_host.cc b/content/browser/compositor/delegated_frame_host.cc
index 5dbaed1..1e39486 100644
--- a/content/browser/compositor/delegated_frame_host.cc
+++ b/content/browser/compositor/delegated_frame_host.cc
@@ -138,7 +138,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 6f98bf5..8bafdab 100644
--- a/content/browser/renderer_host/render_view_host_impl.cc
+++ b/content/browser/renderer_host/render_view_host_impl.cc
@@ -289,9 +289,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.
@@ -1379,12 +1384,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 9a1d709..e88295a 100644
--- a/content/browser/renderer_host/render_widget_host_impl.cc
+++ b/content/browser/renderer_host/render_widget_host_impl.cc
@@ -167,12 +167,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),
@@ -362,7 +360,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() {
@@ -564,61 +563,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);
}
}
@@ -746,7 +764,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())
@@ -800,7 +818,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
@@ -1380,8 +1398,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() {
@@ -1581,7 +1603,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 71aa04f..41ecb35 100644
--- a/content/browser/renderer_host/render_widget_host_impl.h
+++ b/content/browser/renderer_host/render_widget_host_impl.h
@@ -46,6 +46,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;
@@ -435,7 +436,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 FrameSwapped(const ui::LatencyInfo& latency_info);
void DidReceiveRendererFrame();
@@ -543,7 +554,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.
@@ -702,9 +722,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_;
@@ -722,31 +739,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 830ab01..32ed9c8 100644
--- a/content/browser/renderer_host/render_widget_host_unittest.cc
+++ b/content/browser/renderer_host/render_widget_host_unittest.cc
@@ -139,9 +139,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_;
@@ -440,10 +442,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();
}
+
void TearDown() override {
view_.reset();
host_.reset();
@@ -464,6 +469,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();
}
@@ -630,7 +644,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.
@@ -639,7 +653,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
@@ -654,7 +668,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.
@@ -663,7 +677,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
@@ -674,7 +688,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.
@@ -682,7 +696,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
@@ -692,7 +706,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.
@@ -700,21 +714,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));
}
@@ -729,7 +743,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
@@ -738,7 +752,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());
@@ -1494,4 +1508,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 6ce4333..fb91f45 100644
--- a/content/common/view_messages.h
+++ b/content/common/view_messages.h
@@ -413,6 +413,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)
@@ -460,8 +480,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)
@@ -564,16 +593,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 5a86b05..f931461 100644
--- a/content/public/test/render_view_test.cc
+++ b/content/public/test/render_view_test.cc
@@ -204,7 +204,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;
}
@@ -407,6 +411,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 baab05a..46dc35c 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;
}
@@ -133,6 +135,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
void SetUp() override;
diff --git a/content/renderer/render_thread_impl.cc b/content/renderer/render_thread_impl.cc
index ebc30cd..aaada3d 100644
--- a/content/renderer/render_thread_impl.cc
+++ b/content/renderer/render_thread_impl.cc
@@ -1362,7 +1362,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 7dc2da8..bc75a42 100644
--- a/content/renderer/render_view_browsertest.cc
+++ b/content/renderer/render_view_browsertest.cc
@@ -2494,4 +2494,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 56a719e..fb5e4ca 100644
--- a/content/renderer/render_view_impl.cc
+++ b/content/renderer/render_view_impl.cc
@@ -643,7 +643,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),
@@ -790,6 +790,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);
@@ -1142,7 +1148,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,
@@ -1159,7 +1168,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 67adc19..be982b0 100644
--- a/content/renderer/render_view_impl.h
+++ b/content/renderer/render_view_impl.h
@@ -78,6 +78,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 {
@@ -178,7 +179,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 6864a3d..5a39b4c 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 ad9a26c..173b6a4 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
diff --git a/extensions/browser/guest_view/guest_view_base.cc b/extensions/browser/guest_view/guest_view_base.cc
index 01c7a5e..6679985 100644
--- a/extensions/browser/guest_view/guest_view_base.cc
+++ b/extensions/browser/guest_view/guest_view_base.cc
@@ -419,12 +419,6 @@ void GuestViewBase::DidStopLoading(content::RenderViewHost* render_view_host) {
void GuestViewBase::RenderViewReady() {
GuestReady();
- content::RenderViewHost* rvh = web_contents()->GetRenderViewHost();
- if (auto_size_enabled_) {
- rvh->EnableAutoResize(min_auto_size_, max_auto_size_);
- } else {
- rvh->DisableAutoResize(element_size_);
- }
}
void GuestViewBase::WebContentsDestroyed() {
diff --git a/extensions/test/data/web_view/apitest/main.js b/extensions/test/data/web_view/apitest/main.js
index 78c56b7..29bfdc3 100644
--- a/extensions/test/data/web_view/apitest/main.js
+++ b/extensions/test/data/web_view/apitest/main.js
@@ -222,8 +222,6 @@ function testAutosizeBeforeNavigation() {
webview.setAttribute('maxheight', 110);
webview.addEventListener('sizechanged', function(e) {
- embedder.test.assertEq(0, e.oldWidth);
- embedder.test.assertEq(0, e.oldHeight);
embedder.test.assertTrue(e.newWidth >= 200 && e.newWidth <= 210);
embedder.test.assertTrue(e.newHeight >= 100 && e.newHeight <= 110);
embedder.test.succeed();
@@ -248,7 +246,6 @@ function testAutosizeHeight() {
webview.addEventListener('sizechanged', function(e) {
switch (step) {
case 1:
- embedder.test.assertEq(0, e.oldHeight);
embedder.test.assertEq(200, e.newHeight);
// Change the maxheight to verify that we see the change.
webview.maxheight = 50;