OLD | NEW |
---|---|
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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
48 #include "content/public/browser/web_contents.h" | 48 #include "content/public/browser/web_contents.h" |
49 #include "content/public/common/content_client.h" | 49 #include "content/public/common/content_client.h" |
50 #include "content/public/common/content_switches.h" | 50 #include "content/public/common/content_switches.h" |
51 #include "content/public/common/menu_item.h" | 51 #include "content/public/common/menu_item.h" |
52 #include "content/public/common/user_agent.h" | 52 #include "content/public/common/user_agent.h" |
53 #include "device/geolocation/geolocation_service_context.h" | 53 #include "device/geolocation/geolocation_service_context.h" |
54 #include "jni/ContentViewCore_jni.h" | 54 #include "jni/ContentViewCore_jni.h" |
55 #include "jni/DragEvent_jni.h" | 55 #include "jni/DragEvent_jni.h" |
56 #include "third_party/WebKit/public/platform/WebInputEvent.h" | 56 #include "third_party/WebKit/public/platform/WebInputEvent.h" |
57 #include "ui/android/view_android.h" | 57 #include "ui/android/view_android.h" |
58 #include "ui/android/view_root.h" | |
58 #include "ui/android/window_android.h" | 59 #include "ui/android/window_android.h" |
59 #include "ui/base/clipboard/clipboard.h" | 60 #include "ui/base/clipboard/clipboard.h" |
60 #include "ui/base/ui_base_switches_util.h" | 61 #include "ui/base/ui_base_switches_util.h" |
61 #include "ui/events/android/motion_event_android.h" | 62 #include "ui/events/android/motion_event_android.h" |
62 #include "ui/events/blink/blink_event_util.h" | 63 #include "ui/events/blink/blink_event_util.h" |
63 #include "ui/events/blink/web_input_event_traits.h" | 64 #include "ui/events/blink/web_input_event_traits.h" |
64 #include "ui/events/event_utils.h" | 65 #include "ui/events/event_utils.h" |
65 #include "ui/events/gesture_detection/motion_event.h" | 66 #include "ui/events/gesture_detection/motion_event.h" |
66 #include "ui/gfx/android/java_bitmap.h" | 67 #include "ui/gfx/android/java_bitmap.h" |
67 #include "ui/gfx/geometry/point_conversions.h" | 68 #include "ui/gfx/geometry/point_conversions.h" |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
223 WebContents* web_contents, | 224 WebContents* web_contents, |
224 float dpi_scale, | 225 float dpi_scale, |
225 const JavaRef<jobject>& java_bridge_retained_object_set) | 226 const JavaRef<jobject>& java_bridge_retained_object_set) |
226 : WebContentsObserver(web_contents), | 227 : WebContentsObserver(web_contents), |
227 java_ref_(env, obj), | 228 java_ref_(env, obj), |
228 web_contents_(static_cast<WebContentsImpl*>(web_contents)), | 229 web_contents_(static_cast<WebContentsImpl*>(web_contents)), |
229 page_scale_(1), | 230 page_scale_(1), |
230 dpi_scale_(dpi_scale), | 231 dpi_scale_(dpi_scale), |
231 device_orientation_(0), | 232 device_orientation_(0), |
232 accessibility_enabled_(false) { | 233 accessibility_enabled_(false) { |
233 GetViewAndroid()->SetLayer(cc::Layer::Create()); | |
boliu
2017/02/13 22:58:08
this code can just stay here, right? nothing here
Jinsuk Kim
2017/02/14 05:09:59
Yes I just wanted to keep all the initialization/s
| |
234 gfx::Size physical_size( | |
235 Java_ContentViewCore_getPhysicalBackingWidthPix(env, obj), | |
236 Java_ContentViewCore_getPhysicalBackingHeightPix(env, obj)); | |
237 GetViewAndroid()->GetLayer()->SetBounds(physical_size); | |
238 | |
239 // Currently, the only use case we have for overriding a user agent involves | 234 // Currently, the only use case we have for overriding a user agent involves |
240 // spoofing a desktop Linux user agent for "Request desktop site". | 235 // spoofing a desktop Linux user agent for "Request desktop site". |
241 // Automatically set it for all WebContents so that it is available when a | 236 // Automatically set it for all WebContents so that it is available when a |
242 // NavigationEntry requires the user agent to be overridden. | 237 // NavigationEntry requires the user agent to be overridden. |
243 const char kLinuxInfoStr[] = "X11; Linux x86_64"; | 238 const char kLinuxInfoStr[] = "X11; Linux x86_64"; |
244 std::string product = content::GetContentClient()->GetProduct(); | 239 std::string product = content::GetContentClient()->GetProduct(); |
245 std::string spoofed_ua = | 240 std::string spoofed_ua = |
246 BuildUserAgentFromOSAndProduct(kLinuxInfoStr, product); | 241 BuildUserAgentFromOSAndProduct(kLinuxInfoStr, product); |
247 web_contents->SetUserAgentOverride(spoofed_ua); | 242 web_contents->SetUserAgentOverride(spoofed_ua); |
248 | 243 |
(...skipping 21 matching lines...) Expand all Loading... | |
270 | 265 |
271 JNIEnv* env = base::android::AttachCurrentThread(); | 266 JNIEnv* env = base::android::AttachCurrentThread(); |
272 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); | 267 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); |
273 java_ref_.reset(); | 268 java_ref_.reset(); |
274 if (!j_obj.is_null()) { | 269 if (!j_obj.is_null()) { |
275 Java_ContentViewCore_onNativeContentViewCoreDestroyed( | 270 Java_ContentViewCore_onNativeContentViewCoreDestroyed( |
276 env, j_obj, reinterpret_cast<intptr_t>(this)); | 271 env, j_obj, reinterpret_cast<intptr_t>(this)); |
277 } | 272 } |
278 } | 273 } |
279 | 274 |
280 void ContentViewCoreImpl::UpdateWindowAndroid( | 275 void ContentViewCoreImpl::UpdateViewRoot( |
281 JNIEnv* env, | 276 JNIEnv* env, |
282 const base::android::JavaParamRef<jobject>& obj, | 277 const base::android::JavaParamRef<jobject>& obj, |
283 jlong window_android) { | 278 jlong view_root_ptr) { |
279 ui::ViewRoot* view_root = reinterpret_cast<ui::ViewRoot*>(view_root_ptr); | |
284 ui::ViewAndroid* view = GetViewAndroid(); | 280 ui::ViewAndroid* view = GetViewAndroid(); |
285 ui::WindowAndroid* window = | 281 if (view_root == view->GetViewRoot()) |
286 reinterpret_cast<ui::WindowAndroid*>(window_android); | |
287 if (window == GetWindowAndroid()) | |
288 return; | 282 return; |
289 if (GetWindowAndroid()) { | 283 if (view->GetViewRoot()) { |
290 for (auto& observer : observer_list_) | 284 for (auto& observer : observer_list_) |
291 observer.OnDetachedFromWindow(); | 285 observer.OnDetachedFromWindow(); |
292 view->RemoveFromParent(); | 286 view->RemoveFromParent(); |
293 } | 287 } |
294 if (window) { | 288 if (view_root) { |
295 window->AddChild(view); | 289 view_root->AddChild(view); |
296 for (auto& observer : observer_list_) | 290 for (auto& observer : observer_list_) |
297 observer.OnAttachedToWindow(); | 291 observer.OnAttachedToWindow(); |
298 } | 292 } |
299 } | 293 } |
300 | 294 |
301 base::android::ScopedJavaLocalRef<jobject> | 295 base::android::ScopedJavaLocalRef<jobject> |
302 ContentViewCoreImpl::GetWebContentsAndroid(JNIEnv* env, | 296 ContentViewCoreImpl::GetWebContentsAndroid(JNIEnv* env, |
303 const JavaParamRef<jobject>& obj) { | 297 const JavaParamRef<jobject>& obj) { |
304 return web_contents_->GetJavaWebContents(); | 298 return web_contents_->GetJavaWebContents(); |
305 } | 299 } |
(...skipping 937 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1243 ConvertJavaStringToUTF8(env, name)); | 1237 ConvertJavaStringToUTF8(env, name)); |
1244 } | 1238 } |
1245 | 1239 |
1246 void ContentViewCoreImpl::WasResized(JNIEnv* env, | 1240 void ContentViewCoreImpl::WasResized(JNIEnv* env, |
1247 const JavaParamRef<jobject>& obj) { | 1241 const JavaParamRef<jobject>& obj) { |
1248 gfx::Size physical_size( | 1242 gfx::Size physical_size( |
1249 Java_ContentViewCore_getPhysicalBackingWidthPix(env, obj), | 1243 Java_ContentViewCore_getPhysicalBackingWidthPix(env, obj), |
1250 Java_ContentViewCore_getPhysicalBackingHeightPix(env, obj)); | 1244 Java_ContentViewCore_getPhysicalBackingHeightPix(env, obj)); |
1251 GetViewAndroid()->GetLayer()->SetBounds(physical_size); | 1245 GetViewAndroid()->GetLayer()->SetBounds(physical_size); |
1252 | 1246 |
1247 gfx::Size view_size(GetViewSize()); | |
1248 GetViewAndroid()->SetLayout(0, 0, view_size.width(), view_size.height(), | |
1249 false); | |
1250 | |
1253 SendScreenRectsAndResizeWidget(); | 1251 SendScreenRectsAndResizeWidget(); |
1254 } | 1252 } |
1255 | 1253 |
1256 long ContentViewCoreImpl::GetNativeImeAdapter( | 1254 long ContentViewCoreImpl::GetNativeImeAdapter( |
1257 JNIEnv* env, | 1255 JNIEnv* env, |
1258 const JavaParamRef<jobject>& obj) { | 1256 const JavaParamRef<jobject>& obj) { |
1259 RenderWidgetHostViewAndroid* rwhva = GetRenderWidgetHostViewAndroid(); | 1257 RenderWidgetHostViewAndroid* rwhva = GetRenderWidgetHostViewAndroid(); |
1260 if (!rwhva) | 1258 if (!rwhva) |
1261 return 0; | 1259 return 0; |
1262 return rwhva->GetNativeImeAdapter(); | 1260 return rwhva->GetNativeImeAdapter(); |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1490 static_cast<WebContentsImpl*>(web_contents())->GetView()); | 1488 static_cast<WebContentsImpl*>(web_contents())->GetView()); |
1491 DCHECK(wcva); | 1489 DCHECK(wcva); |
1492 wcva->SetContentViewCore(NULL); | 1490 wcva->SetContentViewCore(NULL); |
1493 } | 1491 } |
1494 | 1492 |
1495 // This is called for each ContentView. | 1493 // This is called for each ContentView. |
1496 jlong Init(JNIEnv* env, | 1494 jlong Init(JNIEnv* env, |
1497 const JavaParamRef<jobject>& obj, | 1495 const JavaParamRef<jobject>& obj, |
1498 const JavaParamRef<jobject>& jweb_contents, | 1496 const JavaParamRef<jobject>& jweb_contents, |
1499 const JavaParamRef<jobject>& jview_android_delegate, | 1497 const JavaParamRef<jobject>& jview_android_delegate, |
1500 jlong jwindow_android, | 1498 jlong jview_root_ptr, |
1501 jfloat dipScale, | 1499 jfloat dipScale, |
1502 const JavaParamRef<jobject>& retained_objects_set) { | 1500 const JavaParamRef<jobject>& retained_objects_set) { |
1503 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( | 1501 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( |
1504 WebContents::FromJavaWebContents(jweb_contents)); | 1502 WebContents::FromJavaWebContents(jweb_contents)); |
1505 CHECK(web_contents) << | 1503 CHECK(web_contents) << |
1506 "A ContentViewCoreImpl should be created with a valid WebContents."; | 1504 "A ContentViewCoreImpl should be created with a valid WebContents."; |
1507 ui::ViewAndroid* view_android = web_contents->GetView()->GetNativeView(); | 1505 ui::ViewAndroid* view_android = web_contents->GetView()->GetNativeView(); |
1508 view_android->SetDelegate(jview_android_delegate); | 1506 view_android->SetDelegate(jview_android_delegate); |
1507 view_android->SetLayer(cc::Layer::Create()); | |
1508 gfx::Size physical_size( | |
1509 Java_ContentViewCore_getPhysicalBackingWidthPix(env, obj), | |
1510 Java_ContentViewCore_getPhysicalBackingHeightPix(env, obj)); | |
1511 view_android->GetLayer()->SetBounds(physical_size); | |
1509 | 1512 |
1510 ui::WindowAndroid* window_android = | 1513 ui::ViewRoot* view_root = reinterpret_cast<ui::ViewRoot*>(jview_root_ptr); |
1511 reinterpret_cast<ui::WindowAndroid*>(jwindow_android); | 1514 DCHECK(view_root->GetWindowAndroid()); |
1512 DCHECK(window_android); | 1515 view_root->AddChild(view_android); |
1513 window_android->AddChild(view_android); | |
1514 | 1516 |
1515 // TODO: pass dipScale. | 1517 // TODO: pass dipScale. |
1516 ContentViewCoreImpl* view = new ContentViewCoreImpl( | 1518 ContentViewCoreImpl* view = new ContentViewCoreImpl( |
1517 env, obj, web_contents, dipScale, retained_objects_set); | 1519 env, obj, web_contents, dipScale, retained_objects_set); |
1518 return reinterpret_cast<intptr_t>(view); | 1520 return reinterpret_cast<intptr_t>(view); |
1519 } | 1521 } |
1520 | 1522 |
1521 static ScopedJavaLocalRef<jobject> FromWebContentsAndroid( | 1523 static ScopedJavaLocalRef<jobject> FromWebContentsAndroid( |
1522 JNIEnv* env, | 1524 JNIEnv* env, |
1523 const JavaParamRef<jclass>& clazz, | 1525 const JavaParamRef<jclass>& clazz, |
1524 const JavaParamRef<jobject>& jweb_contents) { | 1526 const JavaParamRef<jobject>& jweb_contents) { |
1525 WebContents* web_contents = WebContents::FromJavaWebContents(jweb_contents); | 1527 WebContents* web_contents = WebContents::FromJavaWebContents(jweb_contents); |
1526 if (!web_contents) | 1528 if (!web_contents) |
1527 return ScopedJavaLocalRef<jobject>(); | 1529 return ScopedJavaLocalRef<jobject>(); |
1528 | 1530 |
1529 ContentViewCore* view = ContentViewCore::FromWebContents(web_contents); | 1531 ContentViewCore* view = ContentViewCore::FromWebContents(web_contents); |
1530 if (!view) | 1532 if (!view) |
1531 return ScopedJavaLocalRef<jobject>(); | 1533 return ScopedJavaLocalRef<jobject>(); |
1532 | 1534 |
1533 return view->GetJavaObject(); | 1535 return view->GetJavaObject(); |
1534 } | 1536 } |
1535 | 1537 |
1536 bool RegisterContentViewCore(JNIEnv* env) { | 1538 bool RegisterContentViewCore(JNIEnv* env) { |
1537 return RegisterNativesImpl(env); | 1539 return RegisterNativesImpl(env); |
1538 } | 1540 } |
1539 | 1541 |
1540 } // namespace content | 1542 } // namespace content |
OLD | NEW |