Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(955)

Side by Side Diff: content/browser/web_contents/web_contents_view_android.cc

Issue 2453213003: Have WebContentsViewAndroid own ViewAndroid (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/web_contents/web_contents_view_android.h" 5 #include "content/browser/web_contents/web_contents_view_android.h"
6 6
7 #include "base/android/jni_android.h" 7 #include "base/android/jni_android.h"
8 #include "base/android/jni_string.h" 8 #include "base/android/jni_string.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "cc/layers/layer.h"
10 #include "content/browser/android/content_view_core_impl.h" 11 #include "content/browser/android/content_view_core_impl.h"
11 #include "content/browser/frame_host/interstitial_page_impl.h" 12 #include "content/browser/frame_host/interstitial_page_impl.h"
12 #include "content/browser/renderer_host/render_widget_host_view_android.h" 13 #include "content/browser/renderer_host/render_widget_host_view_android.h"
13 #include "content/browser/renderer_host/render_view_host_factory.h" 14 #include "content/browser/renderer_host/render_view_host_factory.h"
14 #include "content/browser/renderer_host/render_view_host_impl.h" 15 #include "content/browser/renderer_host/render_view_host_impl.h"
15 #include "content/browser/web_contents/web_contents_impl.h" 16 #include "content/browser/web_contents/web_contents_impl.h"
16 #include "content/public/browser/render_widget_host.h" 17 #include "content/public/browser/render_widget_host.h"
17 #include "content/public/browser/web_contents_delegate.h" 18 #include "content/public/browser/web_contents_delegate.h"
18 #include "content/public/common/drop_data.h" 19 #include "content/public/common/drop_data.h"
19 #include "ui/display/screen.h" 20 #include "ui/display/screen.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 58
58 WebContentsViewAndroid::WebContentsViewAndroid( 59 WebContentsViewAndroid::WebContentsViewAndroid(
59 WebContentsImpl* web_contents, 60 WebContentsImpl* web_contents,
60 WebContentsViewDelegate* delegate) 61 WebContentsViewDelegate* delegate)
61 : web_contents_(web_contents), 62 : web_contents_(web_contents),
62 content_view_core_(NULL), 63 content_view_core_(NULL),
63 delegate_(delegate) { 64 delegate_(delegate) {
64 } 65 }
65 66
66 WebContentsViewAndroid::~WebContentsViewAndroid() { 67 WebContentsViewAndroid::~WebContentsViewAndroid() {
68 if (view_ && view_->GetLayer())
69 view_->GetLayer()->RemoveFromParent();
67 } 70 }
68 71
69 void WebContentsViewAndroid::SetContentViewCore( 72 void WebContentsViewAndroid::SetContentViewCore(
70 ContentViewCoreImpl* content_view_core) { 73 ContentViewCoreImpl* content_view_core) {
71 content_view_core_ = content_view_core; 74 content_view_core_ = content_view_core;
72 RenderWidgetHostViewAndroid* rwhv = static_cast<RenderWidgetHostViewAndroid*>( 75 RenderWidgetHostViewAndroid* rwhv = static_cast<RenderWidgetHostViewAndroid*>(
73 web_contents_->GetRenderWidgetHostView()); 76 web_contents_->GetRenderWidgetHostView());
74 if (rwhv) 77 if (rwhv)
75 rwhv->SetContentViewCore(content_view_core_); 78 rwhv->SetContentViewCore(content_view_core_);
76 79
77 if (web_contents_->ShowingInterstitialPage()) { 80 if (web_contents_->ShowingInterstitialPage()) {
78 rwhv = static_cast<RenderWidgetHostViewAndroid*>( 81 rwhv = static_cast<RenderWidgetHostViewAndroid*>(
79 web_contents_->GetInterstitialPage() 82 web_contents_->GetInterstitialPage()
80 ->GetMainFrame() 83 ->GetMainFrame()
81 ->GetRenderViewHost() 84 ->GetRenderViewHost()
82 ->GetWidget() 85 ->GetWidget()
83 ->GetView()); 86 ->GetView());
84 if (rwhv) 87 if (rwhv)
85 rwhv->SetContentViewCore(content_view_core_); 88 rwhv->SetContentViewCore(content_view_core_);
86 } 89 }
87 } 90 }
88 91
89 gfx::NativeView WebContentsViewAndroid::GetNativeView() const { 92 gfx::NativeView WebContentsViewAndroid::GetNativeView() const {
90 return content_view_core_ ? content_view_core_->GetViewAndroid() : nullptr; 93 return view_.get();
91 } 94 }
92 95
93 gfx::NativeView WebContentsViewAndroid::GetContentNativeView() const { 96 gfx::NativeView WebContentsViewAndroid::GetContentNativeView() const {
94 RenderWidgetHostView* rwhv = web_contents_->GetRenderWidgetHostView(); 97 RenderWidgetHostView* rwhv = web_contents_->GetRenderWidgetHostView();
95 if (rwhv) 98 if (rwhv)
96 return rwhv->GetNativeView(); 99 return rwhv->GetNativeView();
97 100
98 // TODO(sievers): This should return null. 101 // TODO(sievers): This should return null.
99 return GetNativeView(); 102 return GetNativeView();
100 } 103 }
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 157
155 gfx::Rect WebContentsViewAndroid::GetViewBounds() const { 158 gfx::Rect WebContentsViewAndroid::GetViewBounds() const {
156 if (content_view_core_) 159 if (content_view_core_)
157 return gfx::Rect(content_view_core_->GetViewSize()); 160 return gfx::Rect(content_view_core_->GetViewSize());
158 161
159 return gfx::Rect(); 162 return gfx::Rect();
160 } 163 }
161 164
162 void WebContentsViewAndroid::CreateView( 165 void WebContentsViewAndroid::CreateView(
163 const gfx::Size& initial_size, gfx::NativeView context) { 166 const gfx::Size& initial_size, gfx::NativeView context) {
167 // On Android, avoid using the native view copied over from the CreateParams
168 // of the existing web contents view where initial size and the view are
169 // already set. Embedder provides one associated with a Java layer
170 // content view and the delegate.
171 if (initial_size.IsEmpty() && context) view_.reset(context);
164 } 172 }
165 173
166 RenderWidgetHostViewBase* WebContentsViewAndroid::CreateViewForWidget( 174 RenderWidgetHostViewBase* WebContentsViewAndroid::CreateViewForWidget(
167 RenderWidgetHost* render_widget_host, bool is_guest_view_hack) { 175 RenderWidgetHost* render_widget_host, bool is_guest_view_hack) {
168 if (render_widget_host->GetView()) { 176 if (render_widget_host->GetView()) {
169 // During testing, the view will already be set up in most cases to the 177 // During testing, the view will already be set up in most cases to the
170 // test view, so we don't want to clobber it with a real one. To verify that 178 // test view, so we don't want to clobber it with a real one. To verify that
171 // this actually is happening (and somebody isn't accidentally creating the 179 // this actually is happening (and somebody isn't accidentally creating the
172 // view twice), we check for the RVH Factory, which will be set when we're 180 // view twice), we check for the RVH Factory, which will be set when we're
173 // making special ones (which go along with the special views). 181 // making special ones (which go along with the special views).
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 // This is called when we the renderer asks us to take focus back (i.e., it has 328 // This is called when we the renderer asks us to take focus back (i.e., it has
321 // iterated past the last focusable element on the page). 329 // iterated past the last focusable element on the page).
322 void WebContentsViewAndroid::TakeFocus(bool reverse) { 330 void WebContentsViewAndroid::TakeFocus(bool reverse) {
323 if (web_contents_->GetDelegate() && 331 if (web_contents_->GetDelegate() &&
324 web_contents_->GetDelegate()->TakeFocus(web_contents_, reverse)) 332 web_contents_->GetDelegate()->TakeFocus(web_contents_, reverse))
325 return; 333 return;
326 web_contents_->GetRenderWidgetHostView()->Focus(); 334 web_contents_->GetRenderWidgetHostView()->Focus();
327 } 335 }
328 336
329 } // namespace content 337 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698