Remove PlatformFile from profile_browsertest
[chromium-blink-merge.git] / content / browser / web_contents / web_contents_view_android.cc
blob2092700984deb8f353056d260443795b73723b47
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.
5 #include "content/browser/web_contents/web_contents_view_android.h"
7 #include "base/logging.h"
8 #include "content/browser/android/content_view_core_impl.h"
9 #include "content/browser/frame_host/interstitial_page_impl.h"
10 #include "content/browser/media/android/browser_media_player_manager.h"
11 #include "content/browser/renderer_host/render_widget_host_view_android.h"
12 #include "content/browser/renderer_host/render_view_host_factory.h"
13 #include "content/browser/renderer_host/render_view_host_impl.h"
14 #include "content/browser/web_contents/web_contents_impl.h"
15 #include "content/public/browser/web_contents_delegate.h"
17 namespace content {
18 WebContentsViewPort* 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;
28 WebContentsViewAndroid::WebContentsViewAndroid(
29 WebContentsImpl* web_contents,
30 WebContentsViewDelegate* delegate)
31 : web_contents_(web_contents),
32 content_view_core_(NULL),
33 delegate_(delegate) {
36 WebContentsViewAndroid::~WebContentsViewAndroid() {
39 void 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_);
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_);
57 gfx::NativeView WebContentsViewAndroid::GetNativeView() const {
58 return content_view_core_ ? content_view_core_->GetViewAndroid() : NULL;
61 gfx::NativeView WebContentsViewAndroid::GetContentNativeView() const {
62 return content_view_core_ ? content_view_core_->GetViewAndroid() : NULL;
65 gfx::NativeWindow WebContentsViewAndroid::GetTopLevelNativeWindow() const {
66 return content_view_core_ ? content_view_core_->GetWindowAndroid() : NULL;
69 void WebContentsViewAndroid::GetContainerBounds(gfx::Rect* out) const {
70 RenderWidgetHostView* rwhv = web_contents_->GetRenderWidgetHostView();
71 if (rwhv)
72 *out = rwhv->GetViewBounds();
75 void WebContentsViewAndroid::SetPageTitle(const base::string16& title) {
76 if (content_view_core_)
77 content_view_core_->SetTitle(title);
80 void WebContentsViewAndroid::OnTabCrashed(base::TerminationStatus status,
81 int error_code) {
82 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>(
83 web_contents_->GetRenderViewHost());
84 if (rvh->media_player_manager())
85 rvh->media_player_manager()->DestroyAllMediaPlayers();
86 if (content_view_core_)
87 content_view_core_->OnTabCrashed();
90 void WebContentsViewAndroid::SizeContents(const gfx::Size& size) {
91 // TODO(klobag): Do we need to do anything else?
92 RenderWidgetHostView* rwhv = web_contents_->GetRenderWidgetHostView();
93 if (rwhv)
94 rwhv->SetSize(size);
97 void WebContentsViewAndroid::Focus() {
98 if (web_contents_->ShowingInterstitialPage())
99 web_contents_->GetInterstitialPage()->Focus();
100 else
101 web_contents_->GetRenderWidgetHostView()->Focus();
104 void WebContentsViewAndroid::SetInitialFocus() {
105 if (web_contents_->FocusLocationBarByDefault())
106 web_contents_->SetFocusToLocationBar(false);
107 else
108 Focus();
111 void WebContentsViewAndroid::StoreFocus() {
112 NOTIMPLEMENTED();
115 void WebContentsViewAndroid::RestoreFocus() {
116 NOTIMPLEMENTED();
119 DropData* WebContentsViewAndroid::GetDropData() const {
120 NOTIMPLEMENTED();
121 return NULL;
124 gfx::Rect WebContentsViewAndroid::GetViewBounds() const {
125 RenderWidgetHostView* rwhv = web_contents_->GetRenderWidgetHostView();
126 if (rwhv)
127 return rwhv->GetViewBounds();
128 else
129 return gfx::Rect();
132 void WebContentsViewAndroid::CreateView(
133 const gfx::Size& initial_size, gfx::NativeView context) {
136 RenderWidgetHostView* WebContentsViewAndroid::CreateViewForWidget(
137 RenderWidgetHost* render_widget_host) {
138 if (render_widget_host->GetView()) {
139 // During testing, the view will already be set up in most cases to the
140 // test view, so we don't want to clobber it with a real one. To verify that
141 // this actually is happening (and somebody isn't accidentally creating the
142 // view twice), we check for the RVH Factory, which will be set when we're
143 // making special ones (which go along with the special views).
144 DCHECK(RenderViewHostFactory::has_factory());
145 return render_widget_host->GetView();
147 // Note that while this instructs the render widget host to reference
148 // |native_view_|, this has no effect without also instructing the
149 // native view (i.e. ContentView) how to obtain a reference to this widget in
150 // order to paint it. See ContentView::GetRenderWidgetHostViewAndroid for an
151 // example of how this is achieved for InterstitialPages.
152 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(render_widget_host);
153 RenderWidgetHostView* view = new RenderWidgetHostViewAndroid(
154 rwhi, content_view_core_);
155 return view;
158 RenderWidgetHostView* WebContentsViewAndroid::CreateViewForPopupWidget(
159 RenderWidgetHost* render_widget_host) {
160 return RenderWidgetHostViewPort::CreateViewForWidget(render_widget_host);
163 void WebContentsViewAndroid::RenderViewCreated(RenderViewHost* host) {
166 void WebContentsViewAndroid::RenderViewSwappedIn(RenderViewHost* host) {
169 void WebContentsViewAndroid::SetOverscrollControllerEnabled(bool enabled) {
172 void WebContentsViewAndroid::ShowContextMenu(
173 RenderFrameHost* render_frame_host, const ContextMenuParams& params) {
174 if (delegate_)
175 delegate_->ShowContextMenu(render_frame_host, params);
178 void WebContentsViewAndroid::ShowPopupMenu(
179 const gfx::Rect& bounds,
180 int item_height,
181 double item_font_size,
182 int selected_item,
183 const std::vector<MenuItem>& items,
184 bool right_aligned,
185 bool allow_multiple_selection) {
186 if (content_view_core_) {
187 content_view_core_->ShowSelectPopupMenu(
188 items, selected_item, allow_multiple_selection);
192 void WebContentsViewAndroid::HidePopupMenu() {
193 // TODO(tkent): implement
196 void WebContentsViewAndroid::StartDragging(
197 const DropData& drop_data,
198 blink::WebDragOperationsMask allowed_ops,
199 const gfx::ImageSkia& image,
200 const gfx::Vector2d& image_offset,
201 const DragEventSourceInfo& event_info) {
202 NOTIMPLEMENTED();
205 void WebContentsViewAndroid::UpdateDragCursor(blink::WebDragOperation op) {
206 NOTIMPLEMENTED();
209 void WebContentsViewAndroid::GotFocus() {
210 // This is only used in the views FocusManager stuff but it bleeds through
211 // all subclasses. http://crbug.com/21875
214 // This is called when we the renderer asks us to take focus back (i.e., it has
215 // iterated past the last focusable element on the page).
216 void WebContentsViewAndroid::TakeFocus(bool reverse) {
217 if (web_contents_->GetDelegate() &&
218 web_contents_->GetDelegate()->TakeFocus(web_contents_, reverse))
219 return;
220 web_contents_->GetRenderWidgetHostView()->Focus();
223 } // namespace content