12a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 22a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 32a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// found in the LICENSE file. 42a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 52a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/browser/web_contents/web_contents_view_guest.h" 62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "build/build_config.h" 8c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "content/browser/browser_plugin/browser_plugin_embedder.h" 92a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/browser/browser_plugin/browser_plugin_guest.h" 101e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "content/browser/frame_host/interstitial_page_impl.h" 112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/browser/renderer_host/render_view_host_factory.h" 122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/browser/renderer_host/render_view_host_impl.h" 132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/browser/renderer_host/render_widget_host_view_guest.h" 142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/browser/web_contents/web_contents_impl.h" 15c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "content/common/drag_messages.h" 162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/public/browser/web_contents_delegate.h" 177d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "content/public/common/context_menu_params.h" 18eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "content/public/common/drop_data.h" 192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/gfx/image/image_skia.h" 202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/gfx/point.h" 212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/gfx/rect.h" 222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/gfx/size.h" 232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 24bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch#if defined(USE_AURA) 25bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch#include "ui/aura/window.h" 26bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch#endif 27bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch 28f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)using blink::WebDragOperation; 29f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)using blink::WebDragOperationsMask; 302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace content { 322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)WebContentsViewGuest::WebContentsViewGuest( 342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) WebContentsImpl* web_contents, 352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) BrowserPluginGuest* guest, 367dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch scoped_ptr<WebContentsViewPort> platform_view, 377d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) RenderViewHostDelegateView* platform_view_delegate_view) 382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) : web_contents_(web_contents), 392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) guest_(guest), 407dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch platform_view_(platform_view.Pass()), 417d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) platform_view_delegate_view_(platform_view_delegate_view) { 422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)WebContentsViewGuest::~WebContentsViewGuest() { 452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)gfx::NativeView WebContentsViewGuest::GetNativeView() const { 48c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) return platform_view_->GetNativeView(); 492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)gfx::NativeView WebContentsViewGuest::GetContentNativeView() const { 522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) RenderWidgetHostView* rwhv = web_contents_->GetRenderWidgetHostView(); 532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (!rwhv) 542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return NULL; 552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return rwhv->GetNativeView(); 562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)gfx::NativeWindow WebContentsViewGuest::GetTopLevelNativeWindow() const { 592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return guest_->embedder_web_contents()->GetView()->GetTopLevelNativeWindow(); 602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 62bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdochvoid WebContentsViewGuest::OnGuestInitialized(WebContentsView* parent_view) { 63bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch#if defined(USE_AURA) || defined(OS_WIN) 64bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch // In aura and windows, ScreenPositionClient doesn't work properly if we do 65bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch // not have the native view associated with this WebContentsViewGuest in the 66bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch // view hierarchy. We add this view as embedder's child here. 67bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch // This would go in WebContentsViewGuest::CreateView, but that is too early to 68bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch // access embedder_web_contents(). Therefore, we do it here. 69bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch#if defined(USE_AURA) 70bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch // This can be win aura or chromeos. 71bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch parent_view->GetNativeView()->AddChild(platform_view_->GetNativeView()); 72bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch#elif defined(OS_WIN) 73bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch SetParent(platform_view_->GetNativeView(), parent_view->GetNativeView()); 74bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch#endif 75bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch#endif // defined(USE_AURA) || defined(OS_WIN) 76bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch} 77bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch 782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void WebContentsViewGuest::GetContainerBounds(gfx::Rect* out) const { 797d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // We need embedder container's bounds to calculate our bounds. 807d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) guest_->embedder_web_contents()->GetView()->GetContainerBounds(out); 817d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) gfx::Point guest_coordinates = guest_->GetScreenCoordinates(gfx::Point()); 827d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) out->Offset(guest_coordinates.x(), guest_coordinates.y()); 837d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) out->set_size(size_); 842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void WebContentsViewGuest::SizeContents(const gfx::Size& size) { 87c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) size_ = size; 88c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) RenderWidgetHostView* rwhv = web_contents_->GetRenderWidgetHostView(); 89c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) if (rwhv) 90c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) rwhv->SetSize(size); 912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void WebContentsViewGuest::SetInitialFocus() { 942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) platform_view_->SetInitialFocus(); 952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)gfx::Rect WebContentsViewGuest::GetViewBounds() const { 98c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) return gfx::Rect(size_); 992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 1002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#if defined(OS_MACOSX) 1022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void WebContentsViewGuest::SetAllowOverlappingViews(bool overlapping) { 1032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) platform_view_->SetAllowOverlappingViews(overlapping); 1042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 1057d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 1067d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)bool WebContentsViewGuest::GetAllowOverlappingViews() const { 1077d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) return platform_view_->GetAllowOverlappingViews(); 1087d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)} 109a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 110a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)void WebContentsViewGuest::SetOverlayView( 111a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) WebContentsView* overlay, const gfx::Point& offset) { 112a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) platform_view_->SetOverlayView(overlay, offset); 113a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)} 114a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 115a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)void WebContentsViewGuest::RemoveOverlayView() { 116a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) platform_view_->RemoveOverlayView(); 117a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)} 1182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif 1192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void WebContentsViewGuest::CreateView(const gfx::Size& initial_size, 1212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::NativeView context) { 1222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) platform_view_->CreateView(initial_size, context); 123c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) size_ = initial_size; 1242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 1252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)RenderWidgetHostView* WebContentsViewGuest::CreateViewForWidget( 1272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) RenderWidgetHost* render_widget_host) { 1282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (render_widget_host->GetView()) { 1292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // During testing, the view will already be set up in most cases to the 1302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // test view, so we don't want to clobber it with a real one. To verify that 1312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // this actually is happening (and somebody isn't accidentally creating the 1322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // view twice), we check for the RVH Factory, which will be set when we're 1332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // making special ones (which go along with the special views). 1342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(RenderViewHostFactory::has_factory()); 1352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return render_widget_host->GetView(); 1362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 1372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) RenderWidgetHostView* platform_widget = NULL; 1392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) platform_widget = platform_view_->CreateViewForWidget(render_widget_host); 1402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) RenderWidgetHostView* view = new RenderWidgetHostViewGuest( 1422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) render_widget_host, 1432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) guest_, 1442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) platform_widget); 1452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return view; 1472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 1482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)RenderWidgetHostView* WebContentsViewGuest::CreateViewForPopupWidget( 1502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) RenderWidgetHost* render_widget_host) { 1512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return RenderWidgetHostViewPort::CreateViewForWidget(render_widget_host); 1522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 1532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 154a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)void WebContentsViewGuest::SetPageTitle(const base::string16& title) { 1552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 1562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void WebContentsViewGuest::RenderViewCreated(RenderViewHost* host) { 1582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) platform_view_->RenderViewCreated(host); 1592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 1602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void WebContentsViewGuest::RenderViewSwappedIn(RenderViewHost* host) { 1622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) platform_view_->RenderViewSwappedIn(host); 1632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 1642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void WebContentsViewGuest::SetOverscrollControllerEnabled(bool enabled) { 1662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // This should never override the setting of the embedder view. 1672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 1682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#if defined(OS_MACOSX) 1702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)bool WebContentsViewGuest::IsEventTracking() const { 1712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return false; 1722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 1732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void WebContentsViewGuest::CloseTabAfterEventTracking() { 1752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 1762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif 1772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)WebContents* WebContentsViewGuest::web_contents() { 1792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return web_contents_; 1802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 1812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void WebContentsViewGuest::RestoreFocus() { 1832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) platform_view_->RestoreFocus(); 1842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 1852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void WebContentsViewGuest::OnTabCrashed(base::TerminationStatus status, 1872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int error_code) { 1882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 1892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void WebContentsViewGuest::Focus() { 1912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) platform_view_->Focus(); 1922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 1932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void WebContentsViewGuest::StoreFocus() { 1952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) platform_view_->StoreFocus(); 1962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 1972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 198eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen MurdochDropData* WebContentsViewGuest::GetDropData() const { 1992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) NOTIMPLEMENTED(); 2002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return NULL; 2012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 2022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void WebContentsViewGuest::UpdateDragCursor(WebDragOperation operation) { 204c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) RenderViewHostImpl* embedder_render_view_host = 205c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) static_cast<RenderViewHostImpl*>( 206c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) guest_->embedder_web_contents()->GetRenderViewHost()); 207c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) CHECK(embedder_render_view_host); 208c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) RenderViewHostDelegateView* view = 209c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) embedder_render_view_host->GetDelegate()->GetDelegateView(); 210c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) if (view) 211c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) view->UpdateDragCursor(operation); 2122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 2132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void WebContentsViewGuest::GotFocus() { 2152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 2162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void WebContentsViewGuest::TakeFocus(bool reverse) { 2182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 2192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2207d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)void WebContentsViewGuest::ShowContextMenu(const ContextMenuParams& params) { 221bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch#if defined(USE_AURA) || defined(OS_WIN) 222bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch // Context menu uses ScreenPositionClient::ConvertPointToScreen() in aura and 223bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch // windows to calculate popup position. Guest's native view 224bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch // (platform_view_->GetNativeView()) is part of the embedder's view hierarchy, 225bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch // but is placed at (0, 0) w.r.t. the embedder's position. Therefore, |offset| 226bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch // is added to |params|. 227bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch gfx::Rect embedder_bounds; 228bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch guest_->embedder_web_contents()->GetView()->GetContainerBounds( 229bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch &embedder_bounds); 230bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch gfx::Rect guest_bounds; 231bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch GetContainerBounds(&guest_bounds); 232bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch 233bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch gfx::Vector2d offset = guest_bounds.origin() - embedder_bounds.origin(); 234bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch ContextMenuParams params_in_embedder = params; 235bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch params_in_embedder.x += offset.x(); 236bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch params_in_embedder.y += offset.y(); 237bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch platform_view_delegate_view_->ShowContextMenu(params_in_embedder); 238bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch#else 2397d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) platform_view_delegate_view_->ShowContextMenu(params); 240bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch#endif // defined(USE_AURA) || defined(OS_WIN) 2412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 2422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void WebContentsViewGuest::ShowPopupMenu(const gfx::Rect& bounds, 2442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int item_height, 2452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) double item_font_size, 2462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int selected_item, 2477dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch const std::vector<MenuItem>& items, 2482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool right_aligned, 2492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool allow_multiple_selection) { 2502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // External popup menus are only used on Mac and Android. 2512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) NOTIMPLEMENTED(); 2522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 2532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void WebContentsViewGuest::StartDragging( 255eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch const DropData& drop_data, 2562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) WebDragOperationsMask ops, 2572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const gfx::ImageSkia& image, 2582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const gfx::Vector2d& image_offset, 2592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const DragEventSourceInfo& event_info) { 260c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) WebContentsImpl* embedder_web_contents = guest_->embedder_web_contents(); 261c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) embedder_web_contents->GetBrowserPluginEmbedder()->StartDrag(guest_); 262c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) RenderViewHostImpl* embedder_render_view_host = 263c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) static_cast<RenderViewHostImpl*>( 264c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) embedder_web_contents->GetRenderViewHost()); 265c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) CHECK(embedder_render_view_host); 266c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) RenderViewHostDelegateView* view = 267c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) embedder_render_view_host->GetDelegate()->GetDelegateView(); 268c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) if (view) 269c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) view->StartDragging(drop_data, ops, image, image_offset, event_info); 270c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) else 271c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) embedder_web_contents->SystemDragEnded(); 2722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 2732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} // namespace content 275