Skip to content

Commit

Permalink
Propagate window and view rects from parent to child RenderWidgetHost…
Browse files Browse the repository at this point in the history
…View.

This change also moves SendScreenRects to WebContentsImpl,
which will be needed in a follow-up patch to update the
screen rects of all widgets in the frame tree (needed to
handle window rects for out-of-process iframes).

BUG=581897
CQ_INCLUDE_TRYBOTS=tryserver.chromium.linux:linux_site_isolation

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

Cr-Commit-Position: refs/heads/master@{#378386}
  • Loading branch information
lucasgadani authored and Commit bot committed Mar 1, 2016
1 parent 7633ced commit bb9c28a
Show file tree
Hide file tree
Showing 19 changed files with 113 additions and 47 deletions.
4 changes: 0 additions & 4 deletions chrome/browser/apps/guest_view/web_view_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2004,10 +2004,6 @@ IN_PROC_BROWSER_TEST_P(WebViewTest, MediaAccessAPIAllow_TestCheck) {
// Checks that window.screenX/screenY/screenLeft/screenTop works correctly for
// guests.
IN_PROC_BROWSER_TEST_P(WebViewTest, ScreenCoordinates) {
// TODO(lfg): https://crbug.com/581897
if (content::BrowserPluginGuestMode::UseCrossProcessFramesForGuests())
return;

ASSERT_TRUE(RunPlatformAppTestWithArg(
"platform_apps/web_view/common", "screen_coordinates"))
<< message_;
Expand Down
4 changes: 1 addition & 3 deletions content/browser/android/content_view_core_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1262,9 +1262,7 @@ void ContentViewCoreImpl::WasResized(JNIEnv* env,
root_layer_->SetBounds(physical_size);

if (view) {
RenderWidgetHostImpl* host = RenderWidgetHostImpl::From(
view->GetRenderWidgetHost());
host->SendScreenRects();
web_contents_->SendScreenRects();
view->WasResized();
}
}
Expand Down
4 changes: 1 addition & 3 deletions content/browser/browser_plugin/browser_plugin_embedder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,7 @@ void BrowserPluginEmbedder::ClearGuestDragStateIfApplicable() {
// static
bool BrowserPluginEmbedder::DidSendScreenRectsCallback(
WebContents* guest_web_contents) {
RenderWidgetHostImpl::From(
guest_web_contents->GetRenderViewHost()->GetWidget())
->SendScreenRects();
static_cast<WebContentsImpl*>(guest_web_contents)->SendScreenRects();
// Not handled => Iterate over all guests.
return false;
}
Expand Down
5 changes: 1 addition & 4 deletions content/browser/browser_plugin/browser_plugin_guest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -949,10 +949,7 @@ void BrowserPluginGuest::OnUpdateGeometry(int browser_plugin_instance_id,
// The plugin has moved within the embedder without resizing or the
// embedder/container's view rect changing.
guest_window_rect_ = view_rect;
RenderWidgetHostImpl* rwh = RenderWidgetHostImpl::From(
GetWebContents()->GetRenderViewHost()->GetWidget());
if (rwh)
rwh->SendScreenRects();
GetWebContents()->SendScreenRects();
}

void BrowserPluginGuest::OnHasTouchEventHandlers(bool accept) {
Expand Down
23 changes: 23 additions & 0 deletions content/browser/frame_host/cross_process_frame_connector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -249,4 +249,27 @@ CrossProcessFrameConnector::GetRootRenderWidgetHostView() {
return static_cast<RenderWidgetHostViewBase*>(top_host->GetView());
}

RenderWidgetHostViewBase*
CrossProcessFrameConnector::GetParentRenderWidgetHostView() {
FrameTreeNode* parent =
frame_proxy_in_parent_renderer_->frame_tree_node()->parent();

if (!parent &&
frame_proxy_in_parent_renderer_->frame_tree_node()
->render_manager()
->GetOuterDelegateNode()) {
parent = frame_proxy_in_parent_renderer_->frame_tree_node()
->render_manager()
->GetOuterDelegateNode()
->parent();
}

if (parent) {
return static_cast<RenderWidgetHostViewBase*>(
parent->current_frame_host()->GetView());
}

return nullptr;
}

} // namespace content
9 changes: 6 additions & 3 deletions content/browser/frame_host/cross_process_frame_connector.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ class CONTENT_EXPORT CrossProcessFrameConnector {
// page) has focus.
bool HasFocus();

// Returns the parent RenderWidgetHostView or nullptr it it doesn't have one.
RenderWidgetHostViewBase* GetParentRenderWidgetHostView();

// Returns the view for the top-level frame under the same WebContents.
RenderWidgetHostViewBase* GetRootRenderWidgetHostView();

// Exposed for tests.
RenderWidgetHostViewBase* GetRootRenderWidgetHostViewForTesting() {
return GetRootRenderWidgetHostView();
Expand All @@ -118,9 +124,6 @@ class CONTENT_EXPORT CrossProcessFrameConnector {
void SetDeviceScaleFactor(float scale_factor);
void SetSize(gfx::Rect frame_rect);

// Retrieve the view for the top-level frame under the same WebContents.
RenderWidgetHostViewBase* GetRootRenderWidgetHostView();

// The RenderFrameProxyHost that routes messages to the parent frame's
// renderer process.
RenderFrameProxyHost* frame_proxy_in_parent_renderer_;
Expand Down
24 changes: 21 additions & 3 deletions content/browser/frame_host/render_widget_host_view_child_frame.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,18 @@ bool RenderWidgetHostViewChildFrame::IsShowing() {

gfx::Rect RenderWidgetHostViewChildFrame::GetViewBounds() const {
gfx::Rect rect;
if (frame_connector_)
if (frame_connector_) {
rect = frame_connector_->ChildFrameRect();

RenderWidgetHostView* parent_view =
frame_connector_->GetParentRenderWidgetHostView();

// The parent_view can be null in tests when using a TestWebContents.
if (parent_view) {
// Translate frame_rect by the parent's RenderWidgetHostView offset.
rect.Offset(parent_view->GetViewBounds().OffsetFromOrigin());
}
}
return rect;
}

Expand Down Expand Up @@ -342,8 +352,16 @@ bool RenderWidgetHostViewChildFrame::GetScreenColorProfile(
}

gfx::Rect RenderWidgetHostViewChildFrame::GetBoundsInRootWindow() {
// We do not have any root window specific parts in this view.
return GetViewBounds();
gfx::Rect rect;
if (frame_connector_) {
RenderWidgetHostViewBase* root_view =
frame_connector_->GetRootRenderWidgetHostView();

// The root_view can be null in tests when using a TestWebContents.
if (root_view)
rect = root_view->GetBoundsInRootWindow();
}
return rect;
}

#if defined(USE_AURA)
Expand Down
4 changes: 4 additions & 0 deletions content/browser/frame_host/render_widget_host_view_guest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ gfx::Rect RenderWidgetHostViewGuest::GetViewBounds() const {
guest_->GetScreenCoordinates(embedder_bounds.origin()), size_);
}

gfx::Rect RenderWidgetHostViewGuest::GetBoundsInRootWindow() {
return GetViewBounds();
}

void RenderWidgetHostViewGuest::RenderProcessGone(
base::TerminationStatus status,
int error_code) {
Expand Down
1 change: 1 addition & 0 deletions content/browser/frame_host/render_widget_host_view_guest.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class CONTENT_EXPORT RenderWidgetHostViewGuest
gfx::NativeViewId GetNativeViewId() const override;
gfx::NativeViewAccessible GetNativeViewAccessible() override;
gfx::Rect GetViewBounds() const override;
gfx::Rect GetBoundsInRootWindow() override;
gfx::Size GetPhysicalBackingSize() const override;
base::string16 GetSelectedText() const override;

Expand Down
3 changes: 2 additions & 1 deletion content/browser/renderer_host/render_view_host_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "content/browser/renderer_host/render_process_host_impl.h"
#include "content/browser/renderer_host/render_view_host_delegate.h"
#include "content/browser/renderer_host/render_view_host_delegate_view.h"
#include "content/browser/renderer_host/render_widget_host_delegate.h"
#include "content/browser/renderer_host/render_widget_host_view_base.h"
#include "content/common/browser_plugin/browser_plugin_messages.h"
#include "content/common/content_switches_internal.h"
Expand Down Expand Up @@ -365,7 +366,7 @@ bool RenderViewHostImpl::CreateRenderView(
RenderFrameHostImpl::FromID(GetProcess()->GetID(), main_frame_routing_id_)
->SetRenderFrameCreated(true);
}
GetWidget()->SendScreenRects();
GetWidget()->delegate()->SendScreenRects();
PostRenderViewReady();

return true;
Expand Down
3 changes: 3 additions & 0 deletions content/browser/renderer_host/render_widget_host_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ class CONTENT_EXPORT RenderWidgetHostDelegate {
// WebContents.
virtual void OnRenderFrameProxyVisibilityChanged(bool visible) {}

// Update the renderer's cache of the screen rect of the view and window.
virtual void SendScreenRects() {}

protected:
virtual ~RenderWidgetHostDelegate() {}
};
Expand Down
2 changes: 0 additions & 2 deletions content/browser/renderer_host/render_widget_host_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -377,8 +377,6 @@ void RenderWidgetHostImpl::SendScreenRects() {
last_window_screen_rect_ = view_->GetBoundsInRootWindow();
Send(new ViewMsg_UpdateScreenRects(
GetRoutingID(), last_view_screen_rect_, last_window_screen_rect_));
if (delegate_)
delegate_->DidSendScreenRects(this);
waiting_for_screen_rects_ack_ = true;
}

Expand Down
10 changes: 8 additions & 2 deletions content/browser/renderer_host/render_widget_host_view_aura.cc
Original file line number Diff line number Diff line change
Expand Up @@ -882,8 +882,14 @@ void RenderWidgetHostViewAura::HandleParentBoundsChanged() {
window_->GetBoundsInRootWindow());
}
#endif
if (!in_shutdown_)
host_->SendScreenRects();
if (!in_shutdown_) {
// Send screen rects through the delegate if there is one. Not every
// RenderWidgetHost has a delegate (for example, drop-down widgets).
if (host_->delegate())
host_->delegate()->SendScreenRects();
else
host_->SendScreenRects();
}
}

void RenderWidgetHostViewAura::ParentHierarchyChanged() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,11 @@ class TestOverscrollDelegate : public OverscrollControllerDelegate {

class MockRenderWidgetHostDelegate : public RenderWidgetHostDelegate {
public:
MockRenderWidgetHostDelegate() {}
MockRenderWidgetHostDelegate() : rwh_(nullptr) {}
~MockRenderWidgetHostDelegate() override {}
const NativeWebKeyboardEvent* last_event() const { return last_event_.get(); }
void set_widget_host(RenderWidgetHostImpl* rwh) { rwh_ = rwh; }

protected:
// RenderWidgetHostDelegate:
bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
Expand All @@ -166,9 +168,14 @@ class MockRenderWidgetHostDelegate : public RenderWidgetHostDelegate {
void Copy() override {}
void Paste() override {}
void SelectAll() override {}
void SendScreenRects() override {
if (rwh_)
rwh_->SendScreenRects();
}

private:
scoped_ptr<NativeWebKeyboardEvent> last_event_;
RenderWidgetHostImpl* rwh_;
DISALLOW_COPY_AND_ASSIGN(MockRenderWidgetHostDelegate);
};

Expand Down Expand Up @@ -406,8 +413,10 @@ class RenderWidgetHostViewAuraTest : public testing::Test {
sink_ = &process_host_->sink();

int32_t routing_id = process_host_->GetNextRoutingID();
parent_host_ =
new RenderWidgetHostImpl(&delegate_, process_host_, routing_id, false);
delegates_.push_back(make_scoped_ptr(new MockRenderWidgetHostDelegate));
parent_host_ = new RenderWidgetHostImpl(delegates_.back().get(),
process_host_, routing_id, false);
delegates_.back()->set_widget_host(parent_host_);
parent_view_ = new RenderWidgetHostViewAura(parent_host_,
is_guest_view_hack_);
parent_view_->InitAsChild(NULL);
Expand All @@ -416,8 +425,10 @@ class RenderWidgetHostViewAuraTest : public testing::Test {
gfx::Rect());

routing_id = process_host_->GetNextRoutingID();
widget_host_ =
new RenderWidgetHostImpl(&delegate_, process_host_, routing_id, false);
delegates_.push_back(make_scoped_ptr(new MockRenderWidgetHostDelegate));
widget_host_ = new RenderWidgetHostImpl(delegates_.back().get(),
process_host_, routing_id, false);
delegates_.back()->set_widget_host(widget_host_);
widget_host_->Init();
view_ = new FakeRenderWidgetHostViewAura(widget_host_, is_guest_view_hack_);
}
Expand Down Expand Up @@ -529,7 +540,7 @@ class RenderWidgetHostViewAuraTest : public testing::Test {
BrowserThreadImpl browser_thread_for_ui_;
scoped_ptr<aura::test::AuraTestHelper> aura_test_helper_;
scoped_ptr<BrowserContext> browser_context_;
MockRenderWidgetHostDelegate delegate_;
std::vector<scoped_ptr<MockRenderWidgetHostDelegate>> delegates_;
MockRenderProcessHost* process_host_;

// Tests should set these to NULL if they've already triggered their
Expand Down Expand Up @@ -1940,8 +1951,10 @@ TEST_F(RenderWidgetHostViewAuraTest, DiscardDelegatedFrames) {
// Create a bunch of renderers.
for (size_t i = 0; i < renderer_count; ++i) {
int32_t routing_id = process_host_->GetNextRoutingID();
hosts[i] =
new RenderWidgetHostImpl(&delegate_, process_host_, routing_id, false);
delegates_.push_back(make_scoped_ptr(new MockRenderWidgetHostDelegate));
hosts[i] = new RenderWidgetHostImpl(delegates_.back().get(), process_host_,
routing_id, false);
delegates_.back()->set_widget_host(hosts[i]);
hosts[i]->Init();
views[i] = new FakeRenderWidgetHostViewAura(hosts[i], false);
views[i]->InitAsChild(NULL);
Expand Down Expand Up @@ -2104,8 +2117,10 @@ TEST_F(RenderWidgetHostViewAuraTest, DiscardDelegatedFramesWithLocking) {
// Create a bunch of renderers.
for (size_t i = 0; i < renderer_count; ++i) {
int32_t routing_id = process_host_->GetNextRoutingID();
hosts[i] =
new RenderWidgetHostImpl(&delegate_, process_host_, routing_id, false);
delegates_.push_back(make_scoped_ptr(new MockRenderWidgetHostDelegate));
hosts[i] = new RenderWidgetHostImpl(delegates_.back().get(), process_host_,
routing_id, false);
delegates_.back()->set_widget_host(hosts[i]);
hosts[i]->Init();
views[i] = new FakeRenderWidgetHostViewAura(hosts[i], false);
views[i]->InitAsChild(NULL);
Expand Down Expand Up @@ -2173,8 +2188,10 @@ TEST_F(RenderWidgetHostViewAuraTest, DiscardDelegatedFramesWithMemoryPressure) {
// Create a bunch of renderers.
for (size_t i = 0; i < renderer_count; ++i) {
int32_t routing_id = process_host_->GetNextRoutingID();
hosts[i] =
new RenderWidgetHostImpl(&delegate_, process_host_, routing_id, false);
delegates_.push_back(make_scoped_ptr(new MockRenderWidgetHostDelegate));
hosts[i] = new RenderWidgetHostImpl(delegates_.back().get(), process_host_,
routing_id, false);
delegates_.back()->set_widget_host(hosts[i]);
hosts[i]->Init();
views[i] = new FakeRenderWidgetHostViewAura(hosts[i], false);
views[i]->InitAsChild(NULL);
Expand Down Expand Up @@ -3998,7 +4015,7 @@ TEST_F(RenderWidgetHostViewAuraTest, KeyEvent) {
ui::EF_NONE);
view_->OnKeyEvent(&key_event);

const NativeWebKeyboardEvent* event = delegate_.last_event();
const NativeWebKeyboardEvent* event = delegates_.back()->last_event();
EXPECT_NE(nullptr, event);
if (event) {
EXPECT_EQ(key_event.key_code(), event->windowsKeyCode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "content/browser/gpu/gpu_data_manager_impl.h"
#include "content/browser/renderer_host/input/synthetic_gesture_target_base.h"
#include "content/browser/renderer_host/render_process_host_impl.h"
#include "content/browser/renderer_host/render_widget_host_delegate.h"
#include "content/browser/renderer_host/render_widget_host_impl.h"
#include "content/browser/renderer_host/render_widget_host_view_base_observer.h"
#include "content/common/content_switches_internal.h"
Expand Down Expand Up @@ -544,7 +545,7 @@ void RenderWidgetHostViewBase::UpdateScreenInfo(gfx::NativeView view) {
impl = RenderWidgetHostImpl::From(GetRenderWidgetHost());

if (impl)
impl->SendScreenRects();
impl->delegate()->SendScreenRects();

if (HasDisplayPropertyChanged(view) && impl)
impl->NotifyScreenInfoChanged();
Expand Down
5 changes: 4 additions & 1 deletion content/browser/renderer_host/render_widget_host_view_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -2620,7 +2620,10 @@ - (void)setFrameSize:(NSSize)newSize {
if (!renderWidgetHostView_->render_widget_host_)
return;

renderWidgetHostView_->render_widget_host_->SendScreenRects();
if (renderWidgetHostView_->render_widget_host_->delegate())
renderWidgetHostView_->render_widget_host_->delegate()->SendScreenRects();
else
renderWidgetHostView_->render_widget_host_->SendScreenRects();
renderWidgetHostView_->render_widget_host_->WasResized();
if (renderWidgetHostView_->delegated_frame_host_)
renderWidgetHostView_->delegated_frame_host_->WasResized();
Expand Down
5 changes: 4 additions & 1 deletion content/browser/web_contents/web_contents_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2207,7 +2207,10 @@ void WebContentsImpl::OnMoveValidationMessage(
delegate_->MoveValidationMessage(this, anchor_in_root_view);
}

void WebContentsImpl::DidSendScreenRects(RenderWidgetHostImpl* rwh) {
void WebContentsImpl::SendScreenRects() {
RenderWidgetHostImpl::From(GetRenderViewHost()->GetWidget())
->SendScreenRects();

if (browser_plugin_embedder_)
browser_plugin_embedder_->DidSendScreenRects();
}
Expand Down
2 changes: 1 addition & 1 deletion content/browser/web_contents/web_contents_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,6 @@ class CONTENT_EXPORT WebContentsImpl
void HandleKeyboardEvent(const NativeWebKeyboardEvent& event) override;
bool HandleWheelEvent(const blink::WebMouseWheelEvent& event) override;
bool PreHandleGestureEvent(const blink::WebGestureEvent& event) override;
void DidSendScreenRects(RenderWidgetHostImpl* rwh) override;
BrowserAccessibilityManager* GetRootBrowserAccessibilityManager() override;
BrowserAccessibilityManager* GetOrCreateRootBrowserAccessibilityManager()
override;
Expand Down Expand Up @@ -617,6 +616,7 @@ class CONTENT_EXPORT WebContentsImpl
void ForwardCompositorProto(RenderWidgetHostImpl* render_widget_host,
const std::vector<uint8_t>& proto) override;
void OnRenderFrameProxyVisibilityChanged(bool visible) override;
void SendScreenRects() override;

// RenderFrameHostManager::Delegate ------------------------------------------

Expand Down
6 changes: 1 addition & 5 deletions content/browser/web_contents/web_contents_view_aura.cc
Original file line number Diff line number Diff line change
Expand Up @@ -598,11 +598,7 @@ class WebContentsViewAura::WindowObserver
}

private:
void SendScreenRects() {
RenderWidgetHostImpl::From(
view_->web_contents_->GetRenderViewHost()->GetWidget())
->SendScreenRects();
}
void SendScreenRects() { view_->web_contents_->SendScreenRects(); }

#if defined(OS_WIN)
void UpdateConstrainedWindows(aura::Window* exclude) {
Expand Down

0 comments on commit bb9c28a

Please sign in to comment.