| 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/native/aw_browser_dependency_factory.h" | 8 #include "android_webview/native/aw_browser_dependency_factory.h" |
| 8 #include "android_webview/native/aw_contents_container.h" | 9 #include "android_webview/native/aw_contents_container.h" |
| 9 #include "android_webview/native/aw_web_contents_delegate.h" | 10 #include "android_webview/native/aw_web_contents_delegate.h" |
| 10 #include "base/android/jni_android.h" | 11 #include "base/android/jni_android.h" |
| 11 #include "base/android/jni_string.h" | 12 #include "base/android/jni_string.h" |
| 13 #include "base/bind.h" |
| 14 #include "base/callback.h" |
| 12 #include "base/supports_user_data.h" | 15 #include "base/supports_user_data.h" |
| 13 #include "content/public/browser/android/content_view_core.h" | 16 #include "content/public/browser/android/content_view_core.h" |
| 14 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
| 15 #include "jni/AwContents_jni.h" | 18 #include "jni/AwContents_jni.h" |
| 16 | 19 |
| 17 using base::android::AttachCurrentThread; | 20 using base::android::AttachCurrentThread; |
| 18 using base::android::ConvertUTF16ToJavaString; | 21 using base::android::ConvertUTF16ToJavaString; |
| 22 using base::android::ScopedJavaGlobalRef; |
| 23 using base::android::ScopedJavaLocalRef; |
| 19 using content::ContentViewCore; | 24 using content::ContentViewCore; |
| 20 using content::WebContents; | 25 using content::WebContents; |
| 21 | 26 |
| 22 namespace android_webview { | 27 namespace android_webview { |
| 23 | 28 |
| 24 namespace { | 29 namespace { |
| 25 | 30 |
| 26 const void* kAwContentsUserDataKey = &kAwContentsUserDataKey; | 31 const void* kAwContentsUserDataKey = &kAwContentsUserDataKey; |
| 27 | 32 |
| 28 class AwContentsUserData : public base::SupportsUserData::Data { | 33 class AwContentsUserData : public base::SupportsUserData::Data { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 57 android_webview::AwBrowserDependencyFactory::GetInstance(); | 62 android_webview::AwBrowserDependencyFactory::GetInstance(); |
| 58 content::WebContents* web_contents = | 63 content::WebContents* web_contents = |
| 59 dependency_factory->CreateWebContents(private_browsing); | 64 dependency_factory->CreateWebContents(private_browsing); |
| 60 contents_container_.reset(dependency_factory->CreateContentsContainer( | 65 contents_container_.reset(dependency_factory->CreateContentsContainer( |
| 61 web_contents)); | 66 web_contents)); |
| 62 web_contents->SetDelegate(web_contents_delegate_.get()); | 67 web_contents->SetDelegate(web_contents_delegate_.get()); |
| 63 web_contents_delegate_->SetJavaScriptDialogCreator( | 68 web_contents_delegate_->SetJavaScriptDialogCreator( |
| 64 dependency_factory->GetJavaScriptDialogCreator()); | 69 dependency_factory->GetJavaScriptDialogCreator()); |
| 65 web_contents->SetUserData(kAwContentsUserDataKey, | 70 web_contents->SetUserData(kAwContentsUserDataKey, |
| 66 new AwContentsUserData(this)); | 71 new AwContentsUserData(this)); |
| 72 render_view_host_ext_.reset(new AwRenderViewHostExt(web_contents)); |
| 67 } | 73 } |
| 68 | 74 |
| 69 AwContents::~AwContents() { | 75 AwContents::~AwContents() { |
| 70 content::WebContents* web_contents = contents_container_->GetWebContents(); | 76 content::WebContents* web_contents = contents_container_->GetWebContents(); |
| 71 DCHECK(AwContents::FromWebContents(web_contents) == this); | 77 DCHECK(AwContents::FromWebContents(web_contents) == this); |
| 72 web_contents->RemoveUserData(kAwContentsUserDataKey); | 78 web_contents->RemoveUserData(kAwContentsUserDataKey); |
| 73 } | 79 } |
| 74 | 80 |
| 75 jint AwContents::GetWebContents(JNIEnv* env, jobject obj) { | 81 jint AwContents::GetWebContents(JNIEnv* env, jobject obj) { |
| 76 return reinterpret_cast<jint>(contents_container_->GetWebContents()); | 82 return reinterpret_cast<jint>(contents_container_->GetWebContents()); |
| 77 } | 83 } |
| 78 | 84 |
| 79 void AwContents::Destroy(JNIEnv* env, jobject obj) { | 85 void AwContents::Destroy(JNIEnv* env, jobject obj) { |
| 80 delete this; | 86 delete this; |
| 81 } | 87 } |
| 82 | 88 |
| 89 namespace { |
| 90 // |message| is passed as base::Owned, so it will automatically be deleted |
| 91 // when the callback goes out of scope. |
| 92 void DocumentHasImagesCallback(ScopedJavaGlobalRef<jobject>* message, |
| 93 bool has_images) { |
| 94 Java_AwContents_onDocumentHasImagesResponse(AttachCurrentThread(), |
| 95 has_images, |
| 96 message->obj()); |
| 97 } |
| 98 } // namespace |
| 99 |
| 100 void AwContents::DocumentHasImages(JNIEnv* env, jobject obj, jobject message) { |
| 101 render_view_host_ext_->DocumentHasImages( |
| 102 base::Bind(&DocumentHasImagesCallback, |
| 103 base::Owned(new ScopedJavaGlobalRef<jobject>( |
| 104 ScopedJavaLocalRef<jobject>(env, message))))); |
| 105 } |
| 106 |
| 83 static jint Init(JNIEnv* env, | 107 static jint Init(JNIEnv* env, |
| 84 jobject obj, | 108 jobject obj, |
| 85 jobject web_contents_delegate, | 109 jobject web_contents_delegate, |
| 86 jboolean private_browsing) { | 110 jboolean private_browsing) { |
| 87 AwContents* tab = new AwContents(env, obj, web_contents_delegate, | 111 AwContents* tab = new AwContents(env, obj, web_contents_delegate, |
| 88 private_browsing); | 112 private_browsing); |
| 89 return reinterpret_cast<jint>(tab); | 113 return reinterpret_cast<jint>(tab); |
| 90 } | 114 } |
| 91 | 115 |
| 92 bool RegisterAwContents(JNIEnv* env) { | 116 bool RegisterAwContents(JNIEnv* env) { |
| 93 return RegisterNativesImpl(env) >= 0; | 117 return RegisterNativesImpl(env) >= 0; |
| 94 } | 118 } |
| 95 | 119 |
| 96 | 120 |
| 97 } // namespace android_webview | 121 } // namespace android_webview |
| OLD | NEW |