diff options
author | lazyboy@chromium.org <lazyboy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-15 23:55:04 +0000 |
---|---|---|
committer | lazyboy@chromium.org <lazyboy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-15 23:55:04 +0000 |
commit | 32deec6509deb789265c50ba2943bc575b7f547c (patch) | |
tree | bc0bbbecb4d843daa9bca2808990658440edefaf /content/browser/browser_plugin | |
parent | 38fa08719c97f7cd60c3379883488cb50b6fcb73 (diff) | |
download | chromium_src-32deec6509deb789265c50ba2943bc575b7f547c.zip chromium_src-32deec6509deb789265c50ba2943bc575b7f547c.tar.gz chromium_src-32deec6509deb789265c50ba2943bc575b7f547c.tar.bz2 |
Make renderer aware of browser plugin position.
We need to send updated screen rects to renderer whenever the embedder's browser side has screen rect updates. This informs webkit/renderer about the correct position of browser plugin.
Fix view bounds/coordinates for RWHViewGuest.
Both changes together should fix
a) datalist/html5 popups appearing in correct position: i. initially, ii: after moving app window, iii: after resizing app window.
b) window.screenX/Y/Left/Top for guests as well.
BUG=233285, 226653
TEST=Added tests, ran them on trybots. Ran PopupPositioning test in trybot for 50 times on each run, still found few flaky occurrences, will work on it more.
Review URL: https://chromiumcodereview.appspot.com/14123006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@200393 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/browser_plugin')
7 files changed, 62 insertions, 14 deletions
diff --git a/content/browser/browser_plugin/browser_plugin_embedder.cc b/content/browser/browser_plugin/browser_plugin_embedder.cc index 12de8ef..ba8b10a 100644 --- a/content/browser/browser_plugin/browser_plugin_embedder.cc +++ b/content/browser/browser_plugin/browser_plugin_embedder.cc @@ -75,6 +75,10 @@ void BrowserPluginEmbedder::GetRenderViewHostAtPosition( ++next_get_render_view_request_id_; } +void BrowserPluginEmbedder::DidSendScreenRects(RenderWidgetHostImpl* rwh) { + GetBrowserPluginGuestManager()->DidSendScreenRects(web_contents(), rwh); +} + void BrowserPluginEmbedder::RenderViewGone(base::TerminationStatus status) { CleanUp(); } diff --git a/content/browser/browser_plugin/browser_plugin_embedder.h b/content/browser/browser_plugin/browser_plugin_embedder.h index 1b6c8b2..3dbb3f3 100644 --- a/content/browser/browser_plugin/browser_plugin_embedder.h +++ b/content/browser/browser_plugin/browser_plugin_embedder.h @@ -33,6 +33,7 @@ namespace content { class BrowserPluginGuest; class BrowserPluginGuestManager; class BrowserPluginHostFactory; +class RenderWidgetHostImpl; class WebContentsImpl; class CONTENT_EXPORT BrowserPluginEmbedder : public WebContentsObserver { @@ -49,6 +50,9 @@ class CONTENT_EXPORT BrowserPluginEmbedder : public WebContentsObserver { int y, const WebContents::GetRenderViewHostCallback& callback); + // Called when embedder's |rwh| has sent screen rects to renderer. + void DidSendScreenRects(RenderWidgetHostImpl* rwh); + // Overrides factory for testing. Default (NULL) value indicates regular // (non-test) environment. static void set_factory_for_testing(BrowserPluginHostFactory* factory) { diff --git a/content/browser/browser_plugin/browser_plugin_guest.cc b/content/browser/browser_plugin/browser_plugin_guest.cc index ea8ce65..d1c6caa 100644 --- a/content/browser/browser_plugin/browser_plugin_guest.cc +++ b/content/browser/browser_plugin/browser_plugin_guest.cc @@ -356,6 +356,7 @@ bool BrowserPluginGuest::OnMessageReceivedFromEmbedder( IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_Stop, OnStop) IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_TerminateGuest, OnTerminateGuest) IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_UnlockMouse_ACK, OnUnlockMouseAck) + IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_UpdateGeometry, OnUpdateGeometry) IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_UpdateRect_ACK, OnUpdateRectACK) IPC_MESSAGE_UNHANDLED(handled = false) IPC_END_MESSAGE_MAP() @@ -367,6 +368,8 @@ void BrowserPluginGuest::Initialize( const BrowserPluginHostMsg_Attach_Params& params) { focused_ = params.focused; guest_visible_ = params.visible; + guest_window_rect_ = params.resize_guest_params.view_rect; + if (!params.name.empty()) name_ = params.name; auto_size_enabled_ = params.auto_size_params.enable; @@ -472,6 +475,13 @@ void BrowserPluginGuest::UpdateVisibility() { OnSetVisibility(instance_id_, visible()); } +// screen. +gfx::Rect BrowserPluginGuest::ToGuestRect(const gfx::Rect& bounds) { + gfx::Rect guest_rect(bounds); + guest_rect.Offset(guest_window_rect_.OffsetFromOrigin()); + return guest_rect; +} + void BrowserPluginGuest::Observe(int type, const NotificationSource& source, const NotificationDetails& details) { @@ -667,7 +677,7 @@ void BrowserPluginGuest::SetDamageBuffer( DCHECK(*static_cast<unsigned int*>(damage_buffer_->memory()) == 0xdeadbeef); damage_buffer_sequence_id_ = params.damage_buffer_sequence_id; damage_buffer_size_ = params.damage_buffer_size; - damage_view_size_ = params.view_size; + damage_view_size_ = params.view_rect.size(); damage_buffer_scale_factor_ = params.scale_factor; } @@ -972,6 +982,7 @@ bool BrowserPluginGuest::ShouldForwardToBrowserPluginGuest( case BrowserPluginHostMsg_Stop::ID: case BrowserPluginHostMsg_TerminateGuest::ID: case BrowserPluginHostMsg_UnlockMouse_ACK::ID: + case BrowserPluginHostMsg_UpdateGeometry::ID: case BrowserPluginHostMsg_UpdateRect_ACK::ID: return true; default: @@ -1251,16 +1262,16 @@ void BrowserPluginGuest::OnResizeGuest( // Invalid damage buffer means we are in HW compositing mode, // so just resize the WebContents and repaint if needed. if (!base::SharedMemory::IsHandleValid(params.damage_buffer_handle)) { - if (!params.view_size.IsEmpty()) - GetWebContents()->GetView()->SizeContents(params.view_size); + if (!params.view_rect.size().IsEmpty()) + GetWebContents()->GetView()->SizeContents(params.view_rect.size()); if (params.repaint) - Send(new ViewMsg_Repaint(routing_id(), params.view_size)); + Send(new ViewMsg_Repaint(routing_id(), params.view_rect.size())); return; } SetDamageBuffer(params); - GetWebContents()->GetView()->SizeContents(params.view_size); + GetWebContents()->GetView()->SizeContents(params.view_rect.size()); if (params.repaint) - Send(new ViewMsg_Repaint(routing_id(), params.view_size)); + Send(new ViewMsg_Repaint(routing_id(), params.view_rect.size())); } void BrowserPluginGuest::OnSetFocus(int instance_id, bool focused) { @@ -1304,7 +1315,7 @@ void BrowserPluginGuest::OnSetSize( Send(new ViewMsg_Repaint(routing_id(), max_auto_size_)); } else if (!auto_size_enabled_ && old_auto_size_enabled) { GetWebContents()->GetRenderViewHost()->DisableAutoResize( - resize_guest_params.view_size); + resize_guest_params.view_rect.size()); } OnResizeGuest(instance_id_, resize_guest_params); } @@ -1386,6 +1397,17 @@ void BrowserPluginGuest::OnUpdateRectACK( OnSetSize(instance_id_, auto_size_params, resize_guest_params); } +void BrowserPluginGuest::OnUpdateGeometry(int instance_id, + const gfx::Rect& view_rect) { + // The plugin has moved within the embedder without resizing or the + // embedder/container's view rect changing. + guest_window_rect_ = view_rect; + RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( + GetWebContents()->GetRenderViewHost()); + if (rvh) + rvh->SendScreenRects(); +} + void BrowserPluginGuest::OnHasTouchEventHandlers(bool accept) { SendMessageToEmbedder( new BrowserPluginMsg_ShouldAcceptTouchEvents(instance_id(), accept)); @@ -1415,9 +1437,7 @@ void BrowserPluginGuest::OnShowPopup( void BrowserPluginGuest::OnShowWidget(int route_id, const gfx::Rect& initial_pos) { - gfx::Rect screen_pos(initial_pos); - screen_pos.Offset(guest_screen_rect_.OffsetFromOrigin()); - GetWebContents()->ShowCreatedWidget(route_id, screen_pos); + GetWebContents()->ShowCreatedWidget(route_id, initial_pos); } void BrowserPluginGuest::OnTakeFocus(bool reverse) { @@ -1482,8 +1502,7 @@ void BrowserPluginGuest::OnUpdateRect( // The scaling change can happen due to asynchronous updates of the DPI on a // resolution change. if (((auto_size_enabled_ && InAutoSizeBounds(params.view_size)) || - (params.view_size.width() == damage_view_size().width() && - params.view_size.height() == damage_view_size().height())) && + (params.view_size == damage_view_size())) && params.scale_factor == damage_buffer_scale_factor()) { TransportDIB* dib = GetWebContents()->GetRenderProcessHost()-> GetTransportDIB(params.bitmap); diff --git a/content/browser/browser_plugin/browser_plugin_guest.h b/content/browser/browser_plugin/browser_plugin_guest.h index 155d9f3..a298922 100644 --- a/content/browser/browser_plugin/browser_plugin_guest.h +++ b/content/browser/browser_plugin/browser_plugin_guest.h @@ -254,6 +254,7 @@ class CONTENT_EXPORT BrowserPluginGuest // Returns whether BrowserPluginGuest is interested in receiving the given // |message|. static bool ShouldForwardToBrowserPluginGuest(const IPC::Message& message); + gfx::Rect ToGuestRect(const gfx::Rect& rect); void DragSourceEndedAt(int client_x, int client_y, int screen_x, int screen_y, WebKit::WebDragOperation operation); @@ -391,6 +392,7 @@ class CONTENT_EXPORT BrowserPluginGuest void OnTerminateGuest(int instance_id); void OnUnlockMouse(); void OnUnlockMouseAck(int instance_id); + void OnUpdateGeometry(int instance_id, const gfx::Rect& view_rect); void OnUpdateRectACK( int instance_id, const BrowserPluginHostMsg_AutoSize_Params& auto_size_params, diff --git a/content/browser/browser_plugin/browser_plugin_guest_manager.cc b/content/browser/browser_plugin/browser_plugin_guest_manager.cc index 081f332..1a33e9a 100644 --- a/content/browser/browser_plugin/browser_plugin_guest_manager.cc +++ b/content/browser/browser_plugin/browser_plugin_guest_manager.cc @@ -230,4 +230,19 @@ void BrowserPluginGuestManager::OnUnhandledSwapBuffersACK( sync_point); } +void BrowserPluginGuestManager::DidSendScreenRects( + WebContents* embedder_web_contents, RenderWidgetHostImpl* rwh) { + // TODO(lazyboy): Generalize iterating over guest instances and performing + // actions on the guests. + for (GuestInstanceMap::iterator it = + guest_web_contents_by_instance_id_.begin(); + it != guest_web_contents_by_instance_id_.end(); ++it) { + BrowserPluginGuest* guest = it->second->GetBrowserPluginGuest(); + if (embedder_web_contents == guest->embedder_web_contents()) { + static_cast<RenderViewHostImpl*>( + guest->GetWebContents()->GetRenderViewHost())->SendScreenRects(); + } + } +} + } // namespace content diff --git a/content/browser/browser_plugin/browser_plugin_guest_manager.h b/content/browser/browser_plugin/browser_plugin_guest_manager.h index 4e1ba28..f915362 100644 --- a/content/browser/browser_plugin/browser_plugin_guest_manager.h +++ b/content/browser/browser_plugin/browser_plugin_guest_manager.h @@ -31,6 +31,7 @@ namespace content { class BrowserPluginGuest; class BrowserPluginHostFactory; class RenderProcessHostImpl; +class RenderWidgetHostImpl; class SiteInstance; class WebContents; class WebContentsImpl; @@ -79,6 +80,9 @@ class CONTENT_EXPORT BrowserPluginGuestManager : bool CanEmbedderAccessInstanceIDMaybeKill(int embedder_render_process_id, int instance_id) const; + void DidSendScreenRects(WebContents* embedder_web_contents, + RenderWidgetHostImpl* rwh); + void OnMessageReceived(const IPC::Message& message, int render_process_id); private: diff --git a/content/browser/browser_plugin/test_browser_plugin_guest.cc b/content/browser/browser_plugin/test_browser_plugin_guest.cc index 083ea5a..5205752 100644 --- a/content/browser/browser_plugin/test_browser_plugin_guest.cc +++ b/content/browser/browser_plugin/test_browser_plugin_guest.cc @@ -265,10 +265,10 @@ void TestBrowserPluginGuest::OnStop(int instance_id) { void TestBrowserPluginGuest::SetDamageBuffer( const BrowserPluginHostMsg_ResizeGuest_Params& params) { ++damage_buffer_call_count_; - last_damage_buffer_size_ = params.view_size; + last_damage_buffer_size_ = params.view_rect.size(); if (waiting_for_damage_buffer_with_size_ && - expected_damage_buffer_size_ == params.view_size && + expected_damage_buffer_size_ == params.view_rect.size() && damage_buffer_message_loop_runner_) { damage_buffer_message_loop_runner_->Quit(); waiting_for_damage_buffer_with_size_ = false; |