web_contents_view_android.cc revision 2a99a7e74a7f215066514fe81d2bfa6639d9eddd
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_android.h" 6 7#include "base/logging.h" 8#include "content/browser/android/content_view_core_impl.h" 9#include "content/browser/android/media_player_manager_android.h" 10#include "content/browser/renderer_host/render_widget_host_view_android.h" 11#include "content/browser/renderer_host/render_view_host_factory.h" 12#include "content/browser/renderer_host/render_view_host_impl.h" 13#include "content/browser/web_contents/interstitial_page_impl.h" 14#include "content/browser/web_contents/web_contents_impl.h" 15#include "content/public/browser/web_contents_delegate.h" 16 17namespace content { 18WebContentsViewPort* CreateWebContentsView( 19 WebContentsImpl* web_contents, 20 WebContentsViewDelegate* delegate, 21 RenderViewHostDelegateView** render_view_host_delegate_view) { 22 WebContentsViewAndroid* rv = new WebContentsViewAndroid( 23 web_contents, delegate); 24 *render_view_host_delegate_view = rv; 25 return rv; 26} 27 28WebContentsViewAndroid::WebContentsViewAndroid( 29 WebContentsImpl* web_contents, 30 WebContentsViewDelegate* delegate) 31 : web_contents_(web_contents), 32 content_view_core_(NULL), 33 delegate_(delegate) { 34} 35 36WebContentsViewAndroid::~WebContentsViewAndroid() { 37} 38 39void WebContentsViewAndroid::SetContentViewCore( 40 ContentViewCoreImpl* content_view_core) { 41 content_view_core_ = content_view_core; 42 RenderWidgetHostViewAndroid* rwhv = static_cast<RenderWidgetHostViewAndroid*>( 43 web_contents_->GetRenderWidgetHostView()); 44 if (rwhv) 45 rwhv->SetContentViewCore(content_view_core_); 46 47 if (web_contents_->ShowingInterstitialPage()) { 48 rwhv = static_cast<RenderWidgetHostViewAndroid*>( 49 static_cast<InterstitialPageImpl*>( 50 web_contents_->GetInterstitialPage())-> 51 GetRenderViewHost()->GetView()); 52 if (rwhv) 53 rwhv->SetContentViewCore(content_view_core_); 54 } 55} 56 57void WebContentsViewAndroid::RequestExternalVideoSurface(int player_id) { 58 if (content_view_core_) 59 content_view_core_->RequestExternalVideoSurface(player_id); 60} 61 62gfx::NativeView WebContentsViewAndroid::GetNativeView() const { 63 return content_view_core_; 64} 65 66gfx::NativeView WebContentsViewAndroid::GetContentNativeView() const { 67 return content_view_core_; 68} 69 70gfx::NativeWindow WebContentsViewAndroid::GetTopLevelNativeWindow() const { 71 return content_view_core_->GetWindowAndroid(); 72} 73 74void WebContentsViewAndroid::GetContainerBounds(gfx::Rect* out) const { 75 RenderWidgetHostView* rwhv = web_contents_->GetRenderWidgetHostView(); 76 if (rwhv) 77 *out = rwhv->GetViewBounds(); 78} 79 80void WebContentsViewAndroid::SetPageTitle(const string16& title) { 81 if (content_view_core_) 82 content_view_core_->SetTitle(title); 83} 84 85void WebContentsViewAndroid::OnTabCrashed(base::TerminationStatus status, 86 int error_code) { 87 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( 88 web_contents_->GetRenderViewHost()); 89 if (rvh->media_player_manager()) 90 rvh->media_player_manager()->DestroyAllMediaPlayers(); 91 if (content_view_core_) 92 content_view_core_->OnTabCrashed(); 93} 94 95void WebContentsViewAndroid::SizeContents(const gfx::Size& size) { 96 // TODO(klobag): Do we need to do anything else? 97 RenderWidgetHostView* rwhv = web_contents_->GetRenderWidgetHostView(); 98 if (rwhv) 99 rwhv->SetSize(size); 100} 101 102void WebContentsViewAndroid::Focus() { 103 if (web_contents_->ShowingInterstitialPage()) 104 web_contents_->GetInterstitialPage()->Focus(); 105 else 106 web_contents_->GetRenderWidgetHostView()->Focus(); 107} 108 109void WebContentsViewAndroid::SetInitialFocus() { 110 if (web_contents_->FocusLocationBarByDefault()) 111 web_contents_->SetFocusToLocationBar(false); 112 else 113 Focus(); 114} 115 116void WebContentsViewAndroid::StoreFocus() { 117 NOTIMPLEMENTED(); 118} 119 120void WebContentsViewAndroid::RestoreFocus() { 121 NOTIMPLEMENTED(); 122} 123 124WebDropData* WebContentsViewAndroid::GetDropData() const { 125 NOTIMPLEMENTED(); 126 return NULL; 127} 128 129gfx::Rect WebContentsViewAndroid::GetViewBounds() const { 130 RenderWidgetHostView* rwhv = web_contents_->GetRenderWidgetHostView(); 131 if (rwhv) 132 return rwhv->GetViewBounds(); 133 else 134 return gfx::Rect(); 135} 136 137void WebContentsViewAndroid::CreateView( 138 const gfx::Size& initial_size, gfx::NativeView context) { 139} 140 141RenderWidgetHostView* WebContentsViewAndroid::CreateViewForWidget( 142 RenderWidgetHost* render_widget_host) { 143 if (render_widget_host->GetView()) { 144 // During testing, the view will already be set up in most cases to the 145 // test view, so we don't want to clobber it with a real one. To verify that 146 // this actually is happening (and somebody isn't accidentally creating the 147 // view twice), we check for the RVH Factory, which will be set when we're 148 // making special ones (which go along with the special views). 149 DCHECK(RenderViewHostFactory::has_factory()); 150 return render_widget_host->GetView(); 151 } 152 // Note that while this instructs the render widget host to reference 153 // |native_view_|, this has no effect without also instructing the 154 // native view (i.e. ContentView) how to obtain a reference to this widget in 155 // order to paint it. See ContentView::GetRenderWidgetHostViewAndroid for an 156 // example of how this is achieved for InterstitialPages. 157 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(render_widget_host); 158 RenderWidgetHostView* view = new RenderWidgetHostViewAndroid( 159 rwhi, content_view_core_); 160 return view; 161} 162 163RenderWidgetHostView* WebContentsViewAndroid::CreateViewForPopupWidget( 164 RenderWidgetHost* render_widget_host) { 165 return RenderWidgetHostViewPort::CreateViewForWidget(render_widget_host); 166} 167 168void WebContentsViewAndroid::RenderViewCreated(RenderViewHost* host) { 169} 170 171void WebContentsViewAndroid::RenderViewSwappedIn(RenderViewHost* host) { 172} 173 174void WebContentsViewAndroid::SetOverscrollControllerEnabled(bool enabled) { 175} 176 177void WebContentsViewAndroid::ShowContextMenu( 178 const ContextMenuParams& params, 179 ContextMenuSourceType type) { 180 if (delegate_.get()) 181 delegate_->ShowContextMenu(params, type); 182} 183 184void WebContentsViewAndroid::ShowPopupMenu( 185 const gfx::Rect& bounds, 186 int item_height, 187 double item_font_size, 188 int selected_item, 189 const std::vector<WebMenuItem>& items, 190 bool right_aligned, 191 bool allow_multiple_selection) { 192 if (content_view_core_) { 193 content_view_core_->ShowSelectPopupMenu( 194 items, selected_item, allow_multiple_selection); 195 } 196} 197 198void WebContentsViewAndroid::StartDragging( 199 const WebDropData& drop_data, 200 WebKit::WebDragOperationsMask allowed_ops, 201 const gfx::ImageSkia& image, 202 const gfx::Vector2d& image_offset, 203 const DragEventSourceInfo& event_info) { 204 NOTIMPLEMENTED(); 205} 206 207void WebContentsViewAndroid::UpdateDragCursor(WebKit::WebDragOperation op) { 208 NOTIMPLEMENTED(); 209} 210 211void WebContentsViewAndroid::GotFocus() { 212 // This is only used in the views FocusManager stuff but it bleeds through 213 // all subclasses. http://crbug.com/21875 214} 215 216// This is called when we the renderer asks us to take focus back (i.e., it has 217// iterated past the last focusable element on the page). 218void WebContentsViewAndroid::TakeFocus(bool reverse) { 219 if (web_contents_->GetDelegate() && 220 web_contents_->GetDelegate()->TakeFocus(web_contents_, reverse)) 221 return; 222 web_contents_->GetRenderWidgetHostView()->Focus(); 223} 224 225} // namespace content 226