OLD | NEW |
---|---|
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/android/content_view_core_impl.h" | 5 #include "content/browser/android/content_view_core_impl.h" |
6 | 6 |
7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
8 #include "base/android/jni_array.h" | 8 #include "base/android/jni_array.h" |
9 #include "base/android/jni_string.h" | 9 #include "base/android/jni_string.h" |
10 #include "base/android/scoped_java_ref.h" | 10 #include "base/android/scoped_java_ref.h" |
(...skipping 16 matching lines...) Expand all Loading... | |
27 #include "content/public/browser/notification_source.h" | 27 #include "content/public/browser/notification_source.h" |
28 #include "content/public/browser/notification_types.h" | 28 #include "content/public/browser/notification_types.h" |
29 #include "content/public/browser/web_contents.h" | 29 #include "content/public/browser/web_contents.h" |
30 #include "content/public/common/content_client.h" | 30 #include "content/public/common/content_client.h" |
31 #include "content/public/common/page_transition_types.h" | 31 #include "content/public/common/page_transition_types.h" |
32 #include "jni/ContentViewCore_jni.h" | 32 #include "jni/ContentViewCore_jni.h" |
33 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" | 33 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" |
34 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" | 34 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
35 #include "third_party/WebKit/Source/WebKit/chromium/public/android/WebInputEvent Factory.h" | 35 #include "third_party/WebKit/Source/WebKit/chromium/public/android/WebInputEvent Factory.h" |
36 #include "ui/gfx/android/java_bitmap.h" | 36 #include "ui/gfx/android/java_bitmap.h" |
37 #include "ui/gfx/android/window_android.h" | |
37 #include "webkit/glue/user_agent.h" | 38 #include "webkit/glue/user_agent.h" |
38 #include "webkit/glue/webmenuitem.h" | 39 #include "webkit/glue/webmenuitem.h" |
39 | 40 |
40 using base::android::AttachCurrentThread; | 41 using base::android::AttachCurrentThread; |
41 using base::android::ConvertJavaStringToUTF16; | 42 using base::android::ConvertJavaStringToUTF16; |
42 using base::android::ConvertJavaStringToUTF8; | 43 using base::android::ConvertJavaStringToUTF8; |
43 using base::android::ConvertUTF16ToJavaString; | 44 using base::android::ConvertUTF16ToJavaString; |
44 using base::android::ConvertUTF8ToJavaString; | 45 using base::android::ConvertUTF8ToJavaString; |
45 using base::android::GetClass; | 46 using base::android::GetClass; |
46 using base::android::HasField; | 47 using base::android::HasField; |
(...skipping 24 matching lines...) Expand all Loading... | |
71 ContentViewCore* ContentViewCore::GetNativeContentViewCore(JNIEnv* env, | 72 ContentViewCore* ContentViewCore::GetNativeContentViewCore(JNIEnv* env, |
72 jobject obj) { | 73 jobject obj) { |
73 return reinterpret_cast<ContentViewCore*>( | 74 return reinterpret_cast<ContentViewCore*>( |
74 env->GetIntField(obj, g_native_content_view)); | 75 env->GetIntField(obj, g_native_content_view)); |
75 } | 76 } |
76 | 77 |
77 | 78 |
78 ContentViewCoreImpl::ContentViewCoreImpl(JNIEnv* env, jobject obj, | 79 ContentViewCoreImpl::ContentViewCoreImpl(JNIEnv* env, jobject obj, |
79 bool hardware_accelerated, | 80 bool hardware_accelerated, |
80 bool take_ownership_of_web_contents, | 81 bool take_ownership_of_web_contents, |
81 WebContents* web_contents) | 82 WebContents* web_contents, |
83 WindowAndroid* window_android) | |
82 : java_ref_(env, obj), | 84 : java_ref_(env, obj), |
83 web_contents_(static_cast<WebContentsImpl*>(web_contents)), | 85 web_contents_(static_cast<WebContentsImpl*>(web_contents)), |
84 owns_web_contents_(take_ownership_of_web_contents), | 86 owns_web_contents_(take_ownership_of_web_contents), |
85 tab_crashed_(false) { | 87 tab_crashed_(false) { |
86 DCHECK(web_contents) << | 88 DCHECK(web_contents) << |
87 "A ContentViewCoreImpl should be created with a valid WebContents."; | 89 "A ContentViewCoreImpl should be created with a valid WebContents."; |
88 | 90 |
91 window_android_ = window_android; | |
David Trainor- moved to gerrit
2012/09/10 20:51:05
Put this up with java_ref_, just make sure you do
aurimas (slooooooooow)
2012/09/10 23:48:47
Done.
| |
92 | |
89 // TODO(leandrogracia): make use of the hardware_accelerated argument. | 93 // TODO(leandrogracia): make use of the hardware_accelerated argument. |
90 | 94 |
91 InitJNI(env, obj); | 95 InitJNI(env, obj); |
92 | 96 |
93 notification_registrar_.Add(this, | 97 notification_registrar_.Add(this, |
94 NOTIFICATION_EXECUTE_JAVASCRIPT_RESULT, | 98 NOTIFICATION_EXECUTE_JAVASCRIPT_RESULT, |
95 NotificationService::AllSources()); | 99 NotificationService::AllSources()); |
96 | 100 |
97 // Currently, the only use case we have for overriding a user agent involves | 101 // Currently, the only use case we have for overriding a user agent involves |
98 // spoofing a desktop Linux user agent for "Request desktop site". | 102 // spoofing a desktop Linux user agent for "Request desktop site". |
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
513 // -------------------------------------------------------------------------- | 517 // -------------------------------------------------------------------------- |
514 // Methods called from native code | 518 // Methods called from native code |
515 // -------------------------------------------------------------------------- | 519 // -------------------------------------------------------------------------- |
516 | 520 |
517 void ContentViewCoreImpl::LoadUrl( | 521 void ContentViewCoreImpl::LoadUrl( |
518 NavigationController::LoadURLParams& params) { | 522 NavigationController::LoadURLParams& params) { |
519 web_contents()->GetController().LoadURLWithParams(params); | 523 web_contents()->GetController().LoadURLWithParams(params); |
520 PostLoadUrl(params.url); | 524 PostLoadUrl(params.url); |
521 } | 525 } |
522 | 526 |
527 WindowAndroid* ContentViewCoreImpl::GetWindowAndroid() { | |
528 return window_android_; | |
529 } | |
530 | |
523 void ContentViewCoreImpl::PostLoadUrl(const GURL& url) { | 531 void ContentViewCoreImpl::PostLoadUrl(const GURL& url) { |
524 tab_crashed_ = false; | 532 tab_crashed_ = false; |
525 // TODO(tedchoc): Update the content view client of the page load request. | 533 // TODO(tedchoc): Update the content view client of the page load request. |
526 } | 534 } |
527 | 535 |
528 // ---------------------------------------------------------------------------- | 536 // ---------------------------------------------------------------------------- |
529 // Native JNI methods | 537 // Native JNI methods |
530 // ---------------------------------------------------------------------------- | 538 // ---------------------------------------------------------------------------- |
531 | 539 |
532 // This is called for each ContentViewCore. | 540 // This is called for each ContentViewCore. |
533 jint Init(JNIEnv* env, jobject obj, | 541 jint Init(JNIEnv* env, jobject obj, |
534 jboolean hardware_accelerated, | 542 jboolean hardware_accelerated, |
535 jboolean take_ownership_of_web_contents, | 543 jboolean take_ownership_of_web_contents, |
536 jint native_web_contents) { | 544 jint native_web_contents, |
545 jint native_window) { | |
537 ContentViewCoreImpl* view = new ContentViewCoreImpl( | 546 ContentViewCoreImpl* view = new ContentViewCoreImpl( |
538 env, obj, hardware_accelerated, take_ownership_of_web_contents, | 547 env, obj, hardware_accelerated, take_ownership_of_web_contents, |
539 reinterpret_cast<WebContents*>(native_web_contents)); | 548 reinterpret_cast<WebContents*>(native_web_contents), |
549 reinterpret_cast<WindowAndroid*>(native_window)); | |
540 return reinterpret_cast<jint>(view); | 550 return reinterpret_cast<jint>(view); |
541 } | 551 } |
542 | 552 |
543 jint EvaluateJavaScript(JNIEnv* env, jobject obj, jstring script) { | 553 jint EvaluateJavaScript(JNIEnv* env, jobject obj, jstring script) { |
544 ContentViewCoreImpl* view = static_cast<ContentViewCoreImpl*> | 554 ContentViewCoreImpl* view = static_cast<ContentViewCoreImpl*> |
545 (ContentViewCore::GetNativeContentViewCore(env, obj)); | 555 (ContentViewCore::GetNativeContentViewCore(env, obj)); |
546 | 556 |
547 return view->EvaluateJavaScript(env, obj, script); | 557 return view->EvaluateJavaScript(env, obj, script); |
548 } | 558 } |
549 | 559 |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
705 if (!HasField(env, clazz, "mNativeContentViewCore", "I")) { | 715 if (!HasField(env, clazz, "mNativeContentViewCore", "I")) { |
706 DLOG(ERROR) << "Unable to find ContentView.mNativeContentViewCore!"; | 716 DLOG(ERROR) << "Unable to find ContentView.mNativeContentViewCore!"; |
707 return false; | 717 return false; |
708 } | 718 } |
709 g_native_content_view = GetFieldID(env, clazz, "mNativeContentViewCore", "I"); | 719 g_native_content_view = GetFieldID(env, clazz, "mNativeContentViewCore", "I"); |
710 | 720 |
711 return RegisterNativesImpl(env) >= 0; | 721 return RegisterNativesImpl(env) >= 0; |
712 } | 722 } |
713 | 723 |
714 } // namespace content | 724 } // namespace content |
OLD | NEW |