web_contents_view_guest.cc revision 868fa2fe829687343ffae624259930155e16dbd8
1// Copyright (c) 2012 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#include "content/browser/web_contents/web_contents_view_guest.h" 6 7#include "build/build_config.h" 8#include "content/browser/browser_plugin/browser_plugin_embedder.h" 9#include "content/browser/browser_plugin/browser_plugin_guest.h" 10#include "content/browser/renderer_host/render_view_host_factory.h" 11#include "content/browser/renderer_host/render_view_host_impl.h" 12#include "content/browser/renderer_host/render_widget_host_view_guest.h" 13#include "content/browser/web_contents/interstitial_page_impl.h" 14#include "content/browser/web_contents/web_contents_impl.h" 15#include "content/common/drag_messages.h" 16#include "content/public/browser/web_contents_delegate.h" 17#include "ui/gfx/image/image_skia.h" 18#include "ui/gfx/point.h" 19#include "ui/gfx/rect.h" 20#include "ui/gfx/size.h" 21#include "webkit/common/webdropdata.h" 22 23using WebKit::WebDragOperation; 24using WebKit::WebDragOperationsMask; 25 26namespace content { 27 28WebContentsViewGuest::WebContentsViewGuest( 29 WebContentsImpl* web_contents, 30 BrowserPluginGuest* guest, 31 WebContentsViewPort* platform_view) 32 : web_contents_(web_contents), 33 guest_(guest), 34 platform_view_(platform_view) { 35} 36 37WebContentsViewGuest::~WebContentsViewGuest() { 38} 39 40gfx::NativeView WebContentsViewGuest::GetNativeView() const { 41 return platform_view_->GetNativeView(); 42} 43 44gfx::NativeView WebContentsViewGuest::GetContentNativeView() const { 45 RenderWidgetHostView* rwhv = web_contents_->GetRenderWidgetHostView(); 46 if (!rwhv) 47 return NULL; 48 return rwhv->GetNativeView(); 49} 50 51gfx::NativeWindow WebContentsViewGuest::GetTopLevelNativeWindow() const { 52 return guest_->embedder_web_contents()->GetView()->GetTopLevelNativeWindow(); 53} 54 55void WebContentsViewGuest::GetContainerBounds(gfx::Rect* out) const { 56 out->SetRect(0, 0, size_.width(), size_.height()); 57} 58 59void WebContentsViewGuest::SizeContents(const gfx::Size& size) { 60 size_ = size; 61 RenderWidgetHostView* rwhv = web_contents_->GetRenderWidgetHostView(); 62 if (rwhv) 63 rwhv->SetSize(size); 64} 65 66void WebContentsViewGuest::SetInitialFocus() { 67 platform_view_->SetInitialFocus(); 68} 69 70gfx::Rect WebContentsViewGuest::GetViewBounds() const { 71 return gfx::Rect(size_); 72} 73 74#if defined(OS_MACOSX) 75void WebContentsViewGuest::SetAllowOverlappingViews(bool overlapping) { 76 platform_view_->SetAllowOverlappingViews(overlapping); 77} 78#endif 79 80void WebContentsViewGuest::CreateView(const gfx::Size& initial_size, 81 gfx::NativeView context) { 82 platform_view_->CreateView(initial_size, context); 83 size_ = initial_size; 84} 85 86RenderWidgetHostView* WebContentsViewGuest::CreateViewForWidget( 87 RenderWidgetHost* render_widget_host) { 88 if (render_widget_host->GetView()) { 89 // During testing, the view will already be set up in most cases to the 90 // test view, so we don't want to clobber it with a real one. To verify that 91 // this actually is happening (and somebody isn't accidentally creating the 92 // view twice), we check for the RVH Factory, which will be set when we're 93 // making special ones (which go along with the special views). 94 DCHECK(RenderViewHostFactory::has_factory()); 95 return render_widget_host->GetView(); 96 } 97 98 RenderWidgetHostView* platform_widget = NULL; 99 platform_widget = platform_view_->CreateViewForWidget(render_widget_host); 100 101 RenderWidgetHostView* view = new RenderWidgetHostViewGuest( 102 render_widget_host, 103 guest_, 104 platform_widget); 105 106 return view; 107} 108 109RenderWidgetHostView* WebContentsViewGuest::CreateViewForPopupWidget( 110 RenderWidgetHost* render_widget_host) { 111 return RenderWidgetHostViewPort::CreateViewForWidget(render_widget_host); 112} 113 114void WebContentsViewGuest::SetPageTitle(const string16& title) { 115} 116 117void WebContentsViewGuest::RenderViewCreated(RenderViewHost* host) { 118 platform_view_->RenderViewCreated(host); 119} 120 121void WebContentsViewGuest::RenderViewSwappedIn(RenderViewHost* host) { 122 platform_view_->RenderViewSwappedIn(host); 123} 124 125void WebContentsViewGuest::SetOverscrollControllerEnabled(bool enabled) { 126 // This should never override the setting of the embedder view. 127} 128 129#if defined(OS_MACOSX) 130bool WebContentsViewGuest::IsEventTracking() const { 131 return false; 132} 133 134void WebContentsViewGuest::CloseTabAfterEventTracking() { 135} 136#endif 137 138WebContents* WebContentsViewGuest::web_contents() { 139 return web_contents_; 140} 141 142void WebContentsViewGuest::RestoreFocus() { 143 platform_view_->RestoreFocus(); 144} 145 146void WebContentsViewGuest::OnTabCrashed(base::TerminationStatus status, 147 int error_code) { 148} 149 150void WebContentsViewGuest::Focus() { 151 platform_view_->Focus(); 152} 153 154void WebContentsViewGuest::StoreFocus() { 155 platform_view_->StoreFocus(); 156} 157 158WebDropData* WebContentsViewGuest::GetDropData() const { 159 NOTIMPLEMENTED(); 160 return NULL; 161} 162 163void WebContentsViewGuest::UpdateDragCursor(WebDragOperation operation) { 164 RenderViewHostImpl* embedder_render_view_host = 165 static_cast<RenderViewHostImpl*>( 166 guest_->embedder_web_contents()->GetRenderViewHost()); 167 CHECK(embedder_render_view_host); 168 RenderViewHostDelegateView* view = 169 embedder_render_view_host->GetDelegate()->GetDelegateView(); 170 if (view) 171 view->UpdateDragCursor(operation); 172} 173 174void WebContentsViewGuest::GotFocus() { 175} 176 177void WebContentsViewGuest::TakeFocus(bool reverse) { 178} 179 180void WebContentsViewGuest::ShowContextMenu( 181 const ContextMenuParams& params, 182 ContextMenuSourceType type) { 183 NOTIMPLEMENTED(); 184} 185 186void WebContentsViewGuest::ShowPopupMenu(const gfx::Rect& bounds, 187 int item_height, 188 double item_font_size, 189 int selected_item, 190 const std::vector<WebMenuItem>& items, 191 bool right_aligned, 192 bool allow_multiple_selection) { 193 // External popup menus are only used on Mac and Android. 194 NOTIMPLEMENTED(); 195} 196 197void WebContentsViewGuest::StartDragging( 198 const WebDropData& drop_data, 199 WebDragOperationsMask ops, 200 const gfx::ImageSkia& image, 201 const gfx::Vector2d& image_offset, 202 const DragEventSourceInfo& event_info) { 203 WebContentsImpl* embedder_web_contents = guest_->embedder_web_contents(); 204 embedder_web_contents->GetBrowserPluginEmbedder()->StartDrag(guest_); 205 RenderViewHostImpl* embedder_render_view_host = 206 static_cast<RenderViewHostImpl*>( 207 embedder_web_contents->GetRenderViewHost()); 208 CHECK(embedder_render_view_host); 209 RenderViewHostDelegateView* view = 210 embedder_render_view_host->GetDelegate()->GetDelegateView(); 211 if (view) 212 view->StartDragging(drop_data, ops, image, image_offset, event_info); 213 else 214 embedder_web_contents->SystemDragEnded(); 215} 216 217} // namespace content 218