| 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 "android_webview/native/aw_contents.h" | 5 #include "android_webview/native/aw_contents.h" |
| 6 | 6 |
| 7 #include "android_webview/browser/renderer_host/aw_render_view_host_ext.h" | 7 #include "android_webview/browser/renderer_host/aw_render_view_host_ext.h" |
| 8 #include "android_webview/common/render_view_messages.h" | 8 #include "android_webview/common/render_view_messages.h" |
| 9 #include "android_webview/native/aw_browser_dependency_factory.h" | 9 #include "android_webview/native/aw_browser_dependency_factory.h" |
| 10 #include "android_webview/native/aw_contents_container.h" | 10 #include "android_webview/native/aw_contents_container.h" |
| 11 #include "android_webview/native/aw_web_contents_delegate.h" | 11 #include "android_webview/native/aw_web_contents_delegate.h" |
| 12 #include "android_webview/native/aw_contents_io_thread_client_impl.h" | 12 #include "android_webview/native/aw_contents_io_thread_client_impl.h" |
| 13 #include "base/android/jni_android.h" | 13 #include "base/android/jni_android.h" |
| 14 #include "base/android/jni_string.h" | 14 #include "base/android/jni_string.h" |
| 15 #include "base/bind.h" | 15 #include "base/bind.h" |
| 16 #include "base/callback.h" | 16 #include "base/callback.h" |
| 17 #include "base/supports_user_data.h" | 17 #include "base/supports_user_data.h" |
| 18 #include "chrome/browser/component/navigation_interception/intercept_navigation_
delegate.h" |
| 18 #include "content/public/browser/android/content_view_core.h" | 19 #include "content/public/browser/android/content_view_core.h" |
| 19 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
| 20 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
| 21 #include "jni/AwContents_jni.h" | 22 #include "jni/AwContents_jni.h" |
| 22 | 23 |
| 23 using base::android::AttachCurrentThread; | 24 using base::android::AttachCurrentThread; |
| 24 using base::android::ConvertJavaStringToUTF16; | 25 using base::android::ConvertJavaStringToUTF16; |
| 25 using base::android::ConvertJavaStringToUTF8; | 26 using base::android::ConvertJavaStringToUTF8; |
| 26 using base::android::ConvertUTF16ToJavaString; | 27 using base::android::ConvertUTF16ToJavaString; |
| 27 using base::android::ConvertUTF8ToJavaString; | 28 using base::android::ConvertUTF8ToJavaString; |
| 28 using base::android::JavaRef; | 29 using base::android::JavaRef; |
| 29 using base::android::ScopedJavaGlobalRef; | 30 using base::android::ScopedJavaGlobalRef; |
| 30 using base::android::ScopedJavaLocalRef; | 31 using base::android::ScopedJavaLocalRef; |
| 31 using content::BrowserThread; | 32 using content::BrowserThread; |
| 32 using content::ContentViewCore; | 33 using content::ContentViewCore; |
| 33 using content::WebContents; | 34 using content::WebContents; |
| 35 using navigation_interception::InterceptNavigationDelegate; |
| 34 | 36 |
| 35 namespace android_webview { | 37 namespace android_webview { |
| 36 | 38 |
| 37 namespace { | 39 namespace { |
| 38 | 40 |
| 39 const void* kAwContentsUserDataKey = &kAwContentsUserDataKey; | 41 const void* kAwContentsUserDataKey = &kAwContentsUserDataKey; |
| 40 | 42 |
| 41 class AwContentsUserData : public base::SupportsUserData::Data { | 43 class AwContentsUserData : public base::SupportsUserData::Data { |
| 42 public: | 44 public: |
| 43 AwContentsUserData(AwContents* ptr) : contents_(ptr) {} | 45 AwContentsUserData(AwContents* ptr) : contents_(ptr) {} |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 } | 95 } |
| 94 | 96 |
| 95 jint AwContents::GetWebContents(JNIEnv* env, jobject obj) { | 97 jint AwContents::GetWebContents(JNIEnv* env, jobject obj) { |
| 96 return reinterpret_cast<jint>(contents_container_->GetWebContents()); | 98 return reinterpret_cast<jint>(contents_container_->GetWebContents()); |
| 97 } | 99 } |
| 98 | 100 |
| 99 void AwContents::Destroy(JNIEnv* env, jobject obj) { | 101 void AwContents::Destroy(JNIEnv* env, jobject obj) { |
| 100 delete this; | 102 delete this; |
| 101 } | 103 } |
| 102 | 104 |
| 105 AwWebContentsDelegate* AwContents::GetAwWebContentsDelegate() const { |
| 106 return web_contents_delegate_.get(); |
| 107 } |
| 108 |
| 103 namespace { | 109 namespace { |
| 104 // |message| is passed as base::Owned, so it will automatically be deleted | 110 // |message| is passed as base::Owned, so it will automatically be deleted |
| 105 // when the callback goes out of scope. | 111 // when the callback goes out of scope. |
| 106 void DocumentHasImagesCallback(ScopedJavaGlobalRef<jobject>* message, | 112 void DocumentHasImagesCallback(ScopedJavaGlobalRef<jobject>* message, |
| 107 bool has_images) { | 113 bool has_images) { |
| 108 Java_AwContents_onDocumentHasImagesResponse(AttachCurrentThread(), | 114 Java_AwContents_onDocumentHasImagesResponse(AttachCurrentThread(), |
| 109 has_images, | 115 has_images, |
| 110 message->obj()); | 116 message->obj()); |
| 111 } | 117 } |
| 112 } // namespace | 118 } // namespace |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 jrealm.obj()); | 213 jrealm.obj()); |
| 208 } | 214 } |
| 209 | 215 |
| 210 void AwContents::SetIoThreadClient(JNIEnv* env, jobject obj, jobject client) { | 216 void AwContents::SetIoThreadClient(JNIEnv* env, jobject obj, jobject client) { |
| 211 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 217 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 212 content::WebContents* web_contents = contents_container_->GetWebContents(); | 218 content::WebContents* web_contents = contents_container_->GetWebContents(); |
| 213 AwContentsIoThreadClientImpl::Associate( | 219 AwContentsIoThreadClientImpl::Associate( |
| 214 web_contents, ScopedJavaLocalRef<jobject>(env, client)); | 220 web_contents, ScopedJavaLocalRef<jobject>(env, client)); |
| 215 } | 221 } |
| 216 | 222 |
| 223 void AwContents::SetInterceptNavigationDelegate(JNIEnv* env, |
| 224 jobject obj, |
| 225 jobject delegate) { |
| 226 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 227 content::WebContents* web_contents = contents_container_->GetWebContents(); |
| 228 InterceptNavigationDelegate::Associate( |
| 229 web_contents, |
| 230 make_scoped_ptr(new InterceptNavigationDelegate(env, delegate))); |
| 231 } |
| 232 |
| 217 static jint Init(JNIEnv* env, | 233 static jint Init(JNIEnv* env, |
| 218 jobject obj, | 234 jobject obj, |
| 219 jobject web_contents_delegate, | 235 jobject web_contents_delegate, |
| 220 jboolean private_browsing) { | 236 jboolean private_browsing) { |
| 221 AwContents* tab = new AwContents(env, obj, web_contents_delegate, | 237 AwContents* tab = new AwContents(env, obj, web_contents_delegate, |
| 222 private_browsing); | 238 private_browsing); |
| 223 return reinterpret_cast<jint>(tab); | 239 return reinterpret_cast<jint>(tab); |
| 224 } | 240 } |
| 225 | 241 |
| 226 bool RegisterAwContents(JNIEnv* env) { | 242 bool RegisterAwContents(JNIEnv* env) { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 JNIEnv* env = AttachCurrentThread(); | 283 JNIEnv* env = AttachCurrentThread(); |
| 268 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 284 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
| 269 if (obj.is_null()) | 285 if (obj.is_null()) |
| 270 return; | 286 return; |
| 271 | 287 |
| 272 Java_AwContents_onFindResultReceived( | 288 Java_AwContents_onFindResultReceived( |
| 273 env, obj.obj(), active_ordinal, match_count, finished); | 289 env, obj.obj(), active_ordinal, match_count, finished); |
| 274 } | 290 } |
| 275 | 291 |
| 276 } // namespace android_webview | 292 } // namespace android_webview |
| OLD | NEW |