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

Side by Side Diff: content/browser/android/content_view_core_impl.cc

Issue 2752113005: Let ImeAdapterAndroid have the same lifecycle as its Java peer (Closed)
Patch Set: background rwhva Created 3 years, 9 months 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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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/android/content_view_core_impl.h" 5 #include "content/browser/android/content_view_core_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/android/jni_android.h" 9 #include "base/android/jni_android.h"
10 #include "base/android/jni_array.h" 10 #include "base/android/jni_array.h"
(...skipping 11 matching lines...) Expand all
22 #include "cc/output/begin_frame_args.h" 22 #include "cc/output/begin_frame_args.h"
23 #include "content/browser/accessibility/browser_accessibility_manager_android.h" 23 #include "content/browser/accessibility/browser_accessibility_manager_android.h"
24 #include "content/browser/accessibility/browser_accessibility_state_impl.h" 24 #include "content/browser/accessibility/browser_accessibility_state_impl.h"
25 #include "content/browser/android/gesture_event_type.h" 25 #include "content/browser/android/gesture_event_type.h"
26 #include "content/browser/android/interstitial_page_delegate_android.h" 26 #include "content/browser/android/interstitial_page_delegate_android.h"
27 #include "content/browser/android/java/gin_java_bridge_dispatcher_host.h" 27 #include "content/browser/android/java/gin_java_bridge_dispatcher_host.h"
28 #include "content/browser/android/load_url_params.h" 28 #include "content/browser/android/load_url_params.h"
29 #include "content/browser/frame_host/interstitial_page_impl.h" 29 #include "content/browser/frame_host/interstitial_page_impl.h"
30 #include "content/browser/media/media_web_contents_observer.h" 30 #include "content/browser/media/media_web_contents_observer.h"
31 #include "content/browser/renderer_host/compositor_impl_android.h" 31 #include "content/browser/renderer_host/compositor_impl_android.h"
32 #include "content/browser/renderer_host/ime_adapter_android.h"
32 #include "content/browser/renderer_host/input/web_input_event_builders_android.h " 33 #include "content/browser/renderer_host/input/web_input_event_builders_android.h "
33 #include "content/browser/renderer_host/render_view_host_impl.h" 34 #include "content/browser/renderer_host/render_view_host_impl.h"
34 #include "content/browser/renderer_host/render_widget_host_impl.h" 35 #include "content/browser/renderer_host/render_widget_host_impl.h"
35 #include "content/browser/renderer_host/render_widget_host_view_android.h" 36 #include "content/browser/renderer_host/render_widget_host_view_android.h"
36 #include "content/browser/web_contents/web_contents_view_android.h" 37 #include "content/browser/web_contents/web_contents_view_android.h"
37 #include "content/common/frame_messages.h" 38 #include "content/common/frame_messages.h"
38 #include "content/common/input_messages.h" 39 #include "content/common/input_messages.h"
39 #include "content/common/view_messages.h" 40 #include "content/common/view_messages.h"
40 #include "content/public/browser/android/compositor.h" 41 #include "content/public/browser/android/compositor.h"
41 #include "content/public/browser/browser_context.h" 42 #include "content/public/browser/browser_context.h"
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 // static 203 // static
203 ContentViewCore* ContentViewCore::FromWebContents( 204 ContentViewCore* ContentViewCore::FromWebContents(
204 content::WebContents* web_contents) { 205 content::WebContents* web_contents) {
205 return ContentViewCoreImpl::FromWebContents(web_contents); 206 return ContentViewCoreImpl::FromWebContents(web_contents);
206 } 207 }
207 208
208 ContentViewCoreImpl::ContentViewCoreImpl( 209 ContentViewCoreImpl::ContentViewCoreImpl(
209 JNIEnv* env, 210 JNIEnv* env,
210 const JavaRef<jobject>& obj, 211 const JavaRef<jobject>& obj,
211 WebContents* web_contents, 212 WebContents* web_contents,
213 ImeAdapterAndroid* ime_adapter,
212 float dpi_scale, 214 float dpi_scale,
213 const JavaRef<jobject>& java_bridge_retained_object_set) 215 const JavaRef<jobject>& java_bridge_retained_object_set)
214 : WebContentsObserver(web_contents), 216 : WebContentsObserver(web_contents),
215 java_ref_(env, obj), 217 java_ref_(env, obj),
216 web_contents_(static_cast<WebContentsImpl*>(web_contents)), 218 web_contents_(static_cast<WebContentsImpl*>(web_contents)),
219 ime_adapter_(ime_adapter),
boliu 2017/03/24 17:13:16 this is backwards If CVC owns ime adapter, then C
Jinsuk Kim 2017/03/27 03:19:33 Assuming that 'creator should be owner' should hol
217 page_scale_(1), 220 page_scale_(1),
218 dpi_scale_(dpi_scale), 221 dpi_scale_(dpi_scale),
222 active_rwhva_(nullptr),
219 device_orientation_(0), 223 device_orientation_(0),
220 accessibility_enabled_(false) { 224 accessibility_enabled_(false) {
221 GetViewAndroid()->SetLayer(cc::Layer::Create()); 225 GetViewAndroid()->SetLayer(cc::Layer::Create());
222 gfx::Size physical_size( 226 gfx::Size physical_size(
223 Java_ContentViewCore_getPhysicalBackingWidthPix(env, obj), 227 Java_ContentViewCore_getPhysicalBackingWidthPix(env, obj),
224 Java_ContentViewCore_getPhysicalBackingHeightPix(env, obj)); 228 Java_ContentViewCore_getPhysicalBackingHeightPix(env, obj));
225 GetViewAndroid()->GetLayer()->SetBounds(physical_size); 229 GetViewAndroid()->GetLayer()->SetBounds(physical_size);
226 230
227 // Currently, the only use case we have for overriding a user agent involves 231 // Currently, the only use case we have for overriding a user agent involves
228 // spoofing a desktop Linux user agent for "Request desktop site". 232 // spoofing a desktop Linux user agent for "Request desktop site".
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 DCHECK(web_contents_); 324 DCHECK(web_contents_);
321 static_cast<WebContentsViewAndroid*>( 325 static_cast<WebContentsViewAndroid*>(
322 static_cast<WebContentsImpl*>(web_contents_)->GetView())-> 326 static_cast<WebContentsImpl*>(web_contents_)->GetView())->
323 SetContentViewCore(this); 327 SetContentViewCore(this);
324 DCHECK(!web_contents_->GetUserData(kContentViewUserDataKey)); 328 DCHECK(!web_contents_->GetUserData(kContentViewUserDataKey));
325 web_contents_->SetUserData(kContentViewUserDataKey, 329 web_contents_->SetUserData(kContentViewUserDataKey,
326 new ContentViewUserData(this)); 330 new ContentViewUserData(this));
327 } 331 }
328 332
329 void ContentViewCoreImpl::RenderViewReady() { 333 void ContentViewCoreImpl::RenderViewReady() {
334 active_rwhva_ = GetRenderWidgetHostViewAndroid();
boliu 2017/03/24 17:13:16 need to update this in RenderViewHostChanged as we
Jinsuk Kim 2017/03/27 03:19:33 Done.
330 JNIEnv* env = AttachCurrentThread(); 335 JNIEnv* env = AttachCurrentThread();
331 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); 336 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
332 if (!obj.is_null()) 337 if (!obj.is_null())
333 Java_ContentViewCore_onRenderProcessChange(env, obj); 338 Java_ContentViewCore_onRenderProcessChange(env, obj);
334 339
335 if (device_orientation_ != 0) 340 if (device_orientation_ != 0)
336 SendOrientationChangeEventInternal(); 341 SendOrientationChangeEventInternal();
337 } 342 }
338 343
339 void ContentViewCoreImpl::RenderViewHostChanged(RenderViewHost* old_host, 344 void ContentViewCoreImpl::RenderViewHostChanged(RenderViewHost* old_host,
(...skipping 21 matching lines...) Expand all
361 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); 366 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
362 if (!obj.is_null()) { 367 if (!obj.is_null()) {
363 Java_ContentViewCore_onRenderProcessChange(env, obj); 368 Java_ContentViewCore_onRenderProcessChange(env, obj);
364 } 369 }
365 } 370 }
366 371
367 SetFocusInternal(HasFocus()); 372 SetFocusInternal(HasFocus());
368 SetAccessibilityEnabledInternal(accessibility_enabled_); 373 SetAccessibilityEnabledInternal(accessibility_enabled_);
369 } 374 }
370 375
376 void ContentViewCoreImpl::DidAttachInterstitialPage() {
boliu 2017/03/24 17:13:16 should this stuff live in the ImeAdapter instead?
Jinsuk Kim 2017/03/27 03:19:33 Nice. IAA being WebContentsObserver helps decouple
377 if (active_rwhva_)
378 active_rwhva_->ConnectImeAdapter(nullptr);
379 active_rwhva_ = GetRenderWidgetHostViewAndroid();
380 }
381
382 void ContentViewCoreImpl::DidDetachInterstitialPage() {
383 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid();
384 if (rwhv)
385 rwhv->ConnectImeAdapter(ime_adapter());
386 active_rwhva_ = rwhv;
387 }
388
371 RenderWidgetHostViewAndroid* 389 RenderWidgetHostViewAndroid*
372 ContentViewCoreImpl::GetRenderWidgetHostViewAndroid() const { 390 ContentViewCoreImpl::GetRenderWidgetHostViewAndroid() const {
373 RenderWidgetHostView* rwhv = NULL; 391 RenderWidgetHostView* rwhv = NULL;
374 if (web_contents_) { 392 if (web_contents_) {
375 rwhv = web_contents_->GetRenderWidgetHostView(); 393 rwhv = web_contents_->GetRenderWidgetHostView();
376 if (web_contents_->ShowingInterstitialPage()) { 394 if (web_contents_->ShowingInterstitialPage()) {
377 rwhv = web_contents_->GetInterstitialPage() 395 rwhv = web_contents_->GetInterstitialPage()
378 ->GetMainFrame() 396 ->GetMainFrame()
379 ->GetRenderViewHost() 397 ->GetRenderViewHost()
380 ->GetWidget() 398 ->GetWidget()
(...skipping 744 matching lines...) Expand 10 before | Expand all | Expand 10 after
1125 void ContentViewCoreImpl::WasResized(JNIEnv* env, 1143 void ContentViewCoreImpl::WasResized(JNIEnv* env,
1126 const JavaParamRef<jobject>& obj) { 1144 const JavaParamRef<jobject>& obj) {
1127 gfx::Size physical_size( 1145 gfx::Size physical_size(
1128 Java_ContentViewCore_getPhysicalBackingWidthPix(env, obj), 1146 Java_ContentViewCore_getPhysicalBackingWidthPix(env, obj),
1129 Java_ContentViewCore_getPhysicalBackingHeightPix(env, obj)); 1147 Java_ContentViewCore_getPhysicalBackingHeightPix(env, obj));
1130 GetViewAndroid()->GetLayer()->SetBounds(physical_size); 1148 GetViewAndroid()->GetLayer()->SetBounds(physical_size);
1131 1149
1132 SendScreenRectsAndResizeWidget(); 1150 SendScreenRectsAndResizeWidget();
1133 } 1151 }
1134 1152
1135 long ContentViewCoreImpl::GetNativeImeAdapter( 1153 void ContentViewCoreImpl::UpdateImeAdapter(int text_input_type,
1136 JNIEnv* env,
1137 const JavaParamRef<jobject>& obj) {
1138 RenderWidgetHostViewAndroid* rwhva = GetRenderWidgetHostViewAndroid();
1139 if (!rwhva)
1140 return 0;
1141 return rwhva->GetNativeImeAdapter();
1142 }
1143
1144 void ContentViewCoreImpl::ForceUpdateImeAdapter(long native_ime_adapter) {
1145 JNIEnv* env = AttachCurrentThread();
1146 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
1147 if (obj.is_null())
1148 return;
1149 Java_ContentViewCore_forceUpdateImeAdapter(env, obj, native_ime_adapter);
1150 }
1151
1152 void ContentViewCoreImpl::UpdateImeAdapter(long native_ime_adapter,
1153 int text_input_type,
1154 int text_input_flags, 1154 int text_input_flags,
1155 int text_input_mode, 1155 int text_input_mode,
1156 const std::string& text, 1156 const std::string& text,
1157 int selection_start, 1157 int selection_start,
1158 int selection_end, 1158 int selection_end,
1159 int composition_start, 1159 int composition_start,
1160 int composition_end, 1160 int composition_end,
1161 bool show_ime_if_needed, 1161 bool show_ime_if_needed,
1162 bool reply_to_request) { 1162 bool reply_to_request) {
1163 JNIEnv* env = AttachCurrentThread(); 1163 JNIEnv* env = AttachCurrentThread();
1164 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); 1164 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
1165 if (obj.is_null()) 1165 if (obj.is_null())
1166 return; 1166 return;
1167 1167
1168 ScopedJavaLocalRef<jstring> jstring_text = ConvertUTF8ToJavaString(env, text); 1168 ScopedJavaLocalRef<jstring> jstring_text = ConvertUTF8ToJavaString(env, text);
1169 Java_ContentViewCore_updateImeAdapter( 1169 Java_ContentViewCore_updateImeAdapter(
1170 env, obj, native_ime_adapter, text_input_type, text_input_flags, 1170 env, obj, text_input_type, text_input_flags, text_input_mode,
1171 text_input_mode, jstring_text, selection_start, selection_end, 1171 jstring_text, selection_start, selection_end, composition_start,
1172 composition_start, composition_end, show_ime_if_needed, reply_to_request); 1172 composition_end, show_ime_if_needed, reply_to_request);
1173 } 1173 }
1174 1174
1175 void ContentViewCoreImpl::SetAccessibilityEnabled( 1175 void ContentViewCoreImpl::SetAccessibilityEnabled(
1176 JNIEnv* env, 1176 JNIEnv* env,
1177 const JavaParamRef<jobject>& obj, 1177 const JavaParamRef<jobject>& obj,
1178 bool enabled) { 1178 bool enabled) {
1179 SetAccessibilityEnabledInternal(enabled); 1179 SetAccessibilityEnabledInternal(enabled);
1180 } 1180 }
1181 1181
1182 void ContentViewCoreImpl::SetTextTrackSettings( 1182 void ContentViewCoreImpl::SetTextTrackSettings(
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
1369 DCHECK(wcva); 1369 DCHECK(wcva);
1370 wcva->SetContentViewCore(NULL); 1370 wcva->SetContentViewCore(NULL);
1371 } 1371 }
1372 1372
1373 // This is called for each ContentView. 1373 // This is called for each ContentView.
1374 jlong Init(JNIEnv* env, 1374 jlong Init(JNIEnv* env,
1375 const JavaParamRef<jobject>& obj, 1375 const JavaParamRef<jobject>& obj,
1376 const JavaParamRef<jobject>& jweb_contents, 1376 const JavaParamRef<jobject>& jweb_contents,
1377 const JavaParamRef<jobject>& jview_android_delegate, 1377 const JavaParamRef<jobject>& jview_android_delegate,
1378 jlong jwindow_android, 1378 jlong jwindow_android,
1379 jfloat dipScale, 1379 jlong jime_adapter,
1380 jfloat dip_scale,
1380 const JavaParamRef<jobject>& retained_objects_set) { 1381 const JavaParamRef<jobject>& retained_objects_set) {
1381 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( 1382 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>(
1382 WebContents::FromJavaWebContents(jweb_contents)); 1383 WebContents::FromJavaWebContents(jweb_contents));
1383 CHECK(web_contents) << 1384 CHECK(web_contents) <<
1384 "A ContentViewCoreImpl should be created with a valid WebContents."; 1385 "A ContentViewCoreImpl should be created with a valid WebContents.";
1385 ui::ViewAndroid* view_android = web_contents->GetView()->GetNativeView(); 1386 ui::ViewAndroid* view_android = web_contents->GetView()->GetNativeView();
1386 view_android->SetDelegate(jview_android_delegate); 1387 view_android->SetDelegate(jview_android_delegate);
1387 view_android->SetLayout(ui::ViewAndroid::LayoutParams::MatchParent()); 1388 view_android->SetLayout(ui::ViewAndroid::LayoutParams::MatchParent());
1388 1389
1389 ui::WindowAndroid* window_android = 1390 ui::WindowAndroid* window_android =
1390 reinterpret_cast<ui::WindowAndroid*>(jwindow_android); 1391 reinterpret_cast<ui::WindowAndroid*>(jwindow_android);
1391 DCHECK(window_android); 1392 DCHECK(window_android);
1392 window_android->AddChild(view_android); 1393 window_android->AddChild(view_android);
1393 1394
1394 // TODO: pass dipScale.
1395 ContentViewCoreImpl* view = new ContentViewCoreImpl( 1395 ContentViewCoreImpl* view = new ContentViewCoreImpl(
1396 env, obj, web_contents, dipScale, retained_objects_set); 1396 env, obj, web_contents,
1397 reinterpret_cast<ImeAdapterAndroid*>(jime_adapter), dip_scale,
1398 retained_objects_set);
1397 return reinterpret_cast<intptr_t>(view); 1399 return reinterpret_cast<intptr_t>(view);
1398 } 1400 }
1399 1401
1400 static ScopedJavaLocalRef<jobject> FromWebContentsAndroid( 1402 static ScopedJavaLocalRef<jobject> FromWebContentsAndroid(
1401 JNIEnv* env, 1403 JNIEnv* env,
1402 const JavaParamRef<jclass>& clazz, 1404 const JavaParamRef<jclass>& clazz,
1403 const JavaParamRef<jobject>& jweb_contents) { 1405 const JavaParamRef<jobject>& jweb_contents) {
1404 WebContents* web_contents = WebContents::FromJavaWebContents(jweb_contents); 1406 WebContents* web_contents = WebContents::FromJavaWebContents(jweb_contents);
1405 if (!web_contents) 1407 if (!web_contents)
1406 return ScopedJavaLocalRef<jobject>(); 1408 return ScopedJavaLocalRef<jobject>();
1407 1409
1408 ContentViewCore* view = ContentViewCore::FromWebContents(web_contents); 1410 ContentViewCore* view = ContentViewCore::FromWebContents(web_contents);
1409 if (!view) 1411 if (!view)
1410 return ScopedJavaLocalRef<jobject>(); 1412 return ScopedJavaLocalRef<jobject>();
1411 1413
1412 return view->GetJavaObject(); 1414 return view->GetJavaObject();
1413 } 1415 }
1414 1416
1415 bool RegisterContentViewCore(JNIEnv* env) { 1417 bool RegisterContentViewCore(JNIEnv* env) {
1416 return RegisterNativesImpl(env); 1418 return RegisterNativesImpl(env);
1417 } 1419 }
1418 1420
1419 } // namespace content 1421 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698