diff options
author | fsamuel <fsamuel@chromium.org> | 2014-09-10 17:59:30 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-09-11 01:06:20 +0000 |
commit | 9e3d9ad06062b656f0366f7828ad870b5430f999 (patch) | |
tree | f7638f2d3d1f9a2d6e9a54b32aa4876e56c208c4 /content/browser | |
parent | cdcb5f741f8163b771d66f6017a67cff06193b50 (diff) | |
download | chromium_src-9e3d9ad06062b656f0366f7828ad870b5430f999.zip chromium_src-9e3d9ad06062b656f0366f7828ad870b5430f999.tar.gz chromium_src-9e3d9ad06062b656f0366f7828ad870b5430f999.tar.bz2 |
BrowserPlugin: Interstitial Pages work
This CL fixes resize, focus and cursor issues for interstitial pages inside
Browser Plugin.
Interstitial page RenderViewHosts are not a part of the main page's WebContents. Thus, BrowserPluginGuest's (a WebContentsObserver) OnMessageReceived method will not catch IPCs coming from interstitials. However, guest interstitials have RenderWidgetHostViewGuests.
By hanlding focus, resize, cursors and the like through RenderWidgetHostViewGuest, we ensure that interstitial pages get the same treatment inside a BrowserPlugin as RenderViewHosts that belong to the guest WebContents.
BUG=273089
Review URL: https://codereview.chromium.org/549323002
Cr-Commit-Position: refs/heads/master@{#294281}
Diffstat (limited to 'content/browser')
4 files changed, 58 insertions, 29 deletions
diff --git a/content/browser/browser_plugin/browser_plugin_guest.cc b/content/browser/browser_plugin/browser_plugin_guest.cc index f582394..569c9de 100644 --- a/content/browser/browser_plugin/browser_plugin_guest.cc +++ b/content/browser/browser_plugin/browser_plugin_guest.cc @@ -35,7 +35,6 @@ #include "content/public/browser/user_metrics.h" #include "content/public/browser/web_contents_observer.h" #include "content/public/common/drop_data.h" -#include "third_party/WebKit/public/platform/WebCursorInfo.h" #include "ui/gfx/geometry/size_conversions.h" #if defined(OS_MACOSX) @@ -108,6 +107,24 @@ base::WeakPtr<BrowserPluginGuest> BrowserPluginGuest::AsWeakPtr() { return weak_ptr_factory_.GetWeakPtr(); } +void BrowserPluginGuest::SetFocus(RenderWidgetHost* rwh, bool focused) { + focused_ = focused; + rwh->Send(new InputMsg_SetFocus(rwh->GetRoutingID(), focused)); + if (!focused && mouse_locked_) + OnUnlockMouse(); + + // Restore the last seen state of text input to the view. + RenderWidgetHostViewBase* rwhv = static_cast<RenderWidgetHostViewBase*>( + web_contents()->GetRenderWidgetHostView()); + if (rwhv) { + ViewHostMsg_TextInputState_Params params; + params.type = last_text_input_type_; + params.mode = last_input_mode_; + params.can_compose_inline = last_can_compose_inline_; + rwhv->TextInputStateChanged(params); + } +} + bool BrowserPluginGuest::LockMouse(bool allowed) { if (!attached() || (mouse_locked_ == allowed)) return false; @@ -495,7 +512,6 @@ bool BrowserPluginGuest::OnMessageReceived(const IPC::Message& message) { IPC_MESSAGE_HANDLER(ViewHostMsg_HasTouchEventHandlers, OnHasTouchEventHandlers) IPC_MESSAGE_HANDLER(ViewHostMsg_LockMouse, OnLockMouse) - IPC_MESSAGE_HANDLER(ViewHostMsg_SetCursor, OnSetCursor) IPC_MESSAGE_HANDLER(ViewHostMsg_ShowWidget, OnShowWidget) IPC_MESSAGE_HANDLER(ViewHostMsg_TakeFocus, OnTakeFocus) IPC_MESSAGE_HANDLER(ViewHostMsg_TextInputStateChanged, @@ -702,21 +718,10 @@ void BrowserPluginGuest::OnResizeGuest( void BrowserPluginGuest::OnSetFocus(int browser_plugin_instance_id, bool focused) { - focused_ = focused; - Send(new InputMsg_SetFocus(routing_id(), focused)); - if (!focused && mouse_locked_) - OnUnlockMouse(); - // Restore the last seen state of text input to the view. - RenderWidgetHostViewBase* rwhv = static_cast<RenderWidgetHostViewBase*>( - web_contents()->GetRenderWidgetHostView()); - if (rwhv) { - ViewHostMsg_TextInputState_Params params; - params.type = last_text_input_type_; - params.mode = last_input_mode_; - params.can_compose_inline = last_can_compose_inline_; - rwhv->TextInputStateChanged(params); - } + RenderWidgetHost* rwh = web_contents()->GetRenderWidgetHostView()-> + GetRenderWidgetHost(); + SetFocus(rwh, focused); } void BrowserPluginGuest::OnSetEditCommandsForNextKeyEvent( @@ -784,11 +789,6 @@ void BrowserPluginGuest::OnHasTouchEventHandlers(bool accept) { browser_plugin_instance_id(), accept)); } -void BrowserPluginGuest::OnSetCursor(const WebCursor& cursor) { - SendMessageToEmbedder( - new BrowserPluginMsg_SetCursor(browser_plugin_instance_id(), cursor)); -} - #if defined(OS_MACOSX) void BrowserPluginGuest::OnShowPopup( RenderFrameHost* render_frame_host, diff --git a/content/browser/browser_plugin/browser_plugin_guest.h b/content/browser/browser_plugin/browser_plugin_guest.h index f0f8e24..805af4a 100644 --- a/content/browser/browser_plugin/browser_plugin_guest.h +++ b/content/browser/browser_plugin/browser_plugin_guest.h @@ -46,7 +46,6 @@ struct FrameHostMsg_ReclaimCompositorResources_Params; struct FrameHostMsg_ShowPopup_Params; #endif struct ViewHostMsg_TextInputState_Params; -struct ViewHostMsg_UpdateRect_Params; namespace blink { class WebInputEvent; @@ -64,9 +63,9 @@ namespace content { class BrowserPluginGuestManager; class RenderViewHostImpl; +class RenderWidgetHost; class RenderWidgetHostView; class SiteInstance; -class WebCursor; struct DropData; // A browser plugin guest provides functionality for WebContents to operate in @@ -102,6 +101,9 @@ class CONTENT_EXPORT BrowserPluginGuest : public WebContentsObserver { // Returns a WeakPtr to this BrowserPluginGuest. base::WeakPtr<BrowserPluginGuest> AsWeakPtr(); + // Sets the focus state of the current RenderWidgetHostView. + void SetFocus(RenderWidgetHost* rwh, bool focused); + // Sets the lock state of the pointer. Returns true if |allowed| is true and // the mouse has been successfully locked. bool LockMouse(bool allowed); @@ -304,13 +306,10 @@ class CONTENT_EXPORT BrowserPluginGuest : public WebContentsObserver { #endif // Message handlers for messages from guest. - - void OnDragStopped(); void OnHandleInputEventAck( blink::WebInputEvent::Type event_type, InputEventAckState ack_result); void OnHasTouchEventHandlers(bool accept); - void OnSetCursor(const WebCursor& cursor); #if defined(OS_MACOSX) // On MacOS X popups are painted by the browser process. We handle them here // so that they are positioned correctly. diff --git a/content/browser/frame_host/render_widget_host_view_guest.cc b/content/browser/frame_host/render_widget_host_view_guest.cc index 7aa5b21..17abb25 100644 --- a/content/browser/frame_host/render_widget_host_view_guest.cc +++ b/content/browser/frame_host/render_widget_host_view_guest.cc @@ -86,6 +86,12 @@ void RenderWidgetHostViewGuest::WasShown() { // |guest_| is NULL during test. if ((guest_ && guest_->is_in_destruction()) || !host_->is_hidden()) return; + // Make sure the size of this view matches the size of the WebContentsView. + // The two sizes may fall out of sync if we switch RenderWidgetHostViews, + // resize, and then switch page, as is the case with interstitial pages. + // NOTE: |guest_| is NULL in unit tests. + if (guest_) + SetSize(guest_->web_contents()->GetViewBounds().size()); host_->WasShown(ui::LatencyInfo()); } @@ -105,6 +111,20 @@ void RenderWidgetHostViewGuest::SetBounds(const gfx::Rect& rect) { SetSize(rect.size()); } +void RenderWidgetHostViewGuest::Focus() { + // InterstitialPageImpl focuses views directly, so we place focus logic here. + // InterstitialPages are not WebContents, and so BrowserPluginGuest does not + // have direct access to the interstitial page's RenderWidgetHost. + if (guest_) + guest_->SetFocus(host_, true); +} + +bool RenderWidgetHostViewGuest::HasFocus() const { + if (!guest_) + return false; + return guest_->focused(); +} + #if defined(USE_AURA) void RenderWidgetHostViewGuest::ProcessAckedTouchEvent( const TouchEventWithLatencyInfo& touch, InputEventAckState ack_result) { @@ -266,7 +286,16 @@ void RenderWidgetHostViewGuest::MovePluginWindows( } void RenderWidgetHostViewGuest::UpdateCursor(const WebCursor& cursor) { - platform_view_->UpdateCursor(cursor); + // InterstitialPages are not WebContents so we cannot intercept + // ViewHostMsg_SetCursor for interstitial pages in BrowserPluginGuest. + // All guest RenderViewHosts have RenderWidgetHostViewGuests however, + // and so we will always hit this code path. + if (!guest_) + return; + guest_->SendMessageToEmbedder( + new BrowserPluginMsg_SetCursor(guest_->browser_plugin_instance_id(), + cursor)); + } void RenderWidgetHostViewGuest::SetIsLoading(bool is_loading) { @@ -563,8 +592,7 @@ void RenderWidgetHostViewGuest::OnHandleInputEvent( if (blink::WebInputEvent::isKeyboardEventType(event->type)) { if (!embedder->GetLastKeyboardEvent()) return; - NativeWebKeyboardEvent keyboard_event( - *embedder->GetLastKeyboardEvent()); + NativeWebKeyboardEvent keyboard_event(*embedder->GetLastKeyboardEvent()); host_->ForwardKeyboardEvent(keyboard_event); return; } diff --git a/content/browser/frame_host/render_widget_host_view_guest.h b/content/browser/frame_host/render_widget_host_view_guest.h index 779df36..1f0a938 100644 --- a/content/browser/frame_host/render_widget_host_view_guest.h +++ b/content/browser/frame_host/render_widget_host_view_guest.h @@ -54,6 +54,8 @@ class CONTENT_EXPORT RenderWidgetHostViewGuest virtual void InitAsChild(gfx::NativeView parent_view) OVERRIDE; virtual void SetSize(const gfx::Size& size) OVERRIDE; virtual void SetBounds(const gfx::Rect& rect) OVERRIDE; + virtual void Focus() OVERRIDE; + virtual bool HasFocus() const OVERRIDE; virtual gfx::NativeView GetNativeView() const OVERRIDE; virtual gfx::NativeViewId GetNativeViewId() const OVERRIDE; virtual gfx::NativeViewAccessible GetNativeViewAccessible() OVERRIDE; |