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/native/aw_browser_dependency_factory.h" | 8 #include "android_webview/native/aw_browser_dependency_factory.h" |
9 #include "android_webview/native/aw_contents_container.h" | 9 #include "android_webview/native/aw_contents_container.h" |
10 #include "android_webview/native/aw_web_contents_delegate.h" | 10 #include "android_webview/native/aw_web_contents_delegate.h" |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
92 // when the callback goes out of scope. | 92 // when the callback goes out of scope. |
93 void DocumentHasImagesCallback(ScopedJavaGlobalRef<jobject>* message, | 93 void DocumentHasImagesCallback(ScopedJavaGlobalRef<jobject>* message, |
94 bool has_images) { | 94 bool has_images) { |
95 Java_AwContents_onDocumentHasImagesResponse(AttachCurrentThread(), | 95 Java_AwContents_onDocumentHasImagesResponse(AttachCurrentThread(), |
96 has_images, | 96 has_images, |
97 message->obj()); | 97 message->obj()); |
98 } | 98 } |
99 } // namespace | 99 } // namespace |
100 | 100 |
101 void AwContents::DocumentHasImages(JNIEnv* env, jobject obj, jobject message) { | 101 void AwContents::DocumentHasImages(JNIEnv* env, jobject obj, jobject message) { |
102 ScopedJavaGlobalRef<jobject>* j_message = new ScopedJavaGlobalRef<jobject>(); | |
benm (inactive)
2012/09/19 14:06:52
did you mean to change this here?
Ted C
2012/09/19 16:53:22
Yeah, when looking at refactoring the code below,
| |
103 j_message->Reset(env, message); | |
102 render_view_host_ext_->DocumentHasImages( | 104 render_view_host_ext_->DocumentHasImages( |
103 base::Bind(&DocumentHasImagesCallback, | 105 base::Bind(&DocumentHasImagesCallback, base::Owned(j_message))); |
104 base::Owned(new ScopedJavaGlobalRef<jobject>( | 106 } |
105 ScopedJavaLocalRef<jobject>(env, message))))); | 107 |
108 namespace { | |
109 void GenerateMHTMLCallback(ScopedJavaGlobalRef<jobject>* callback, | |
110 const FilePath& path, int64 size) { | |
111 JNIEnv* env = AttachCurrentThread(); | |
112 // Android files are UTF8, so the path conversion below is safe. | |
113 Java_AwContents_generateMHTMLCallback( | |
114 env, | |
115 base::android::ConvertUTF8ToJavaString(env, path.AsUTF8Unsafe()).obj(), | |
116 size, callback->obj()); | |
117 } | |
118 } // namespace | |
119 | |
120 void AwContents::GenerateMHTML(JNIEnv* env, jobject obj, | |
121 jstring jpath, jobject callback) { | |
122 ScopedJavaGlobalRef<jobject>* j_callback = new ScopedJavaGlobalRef<jobject>(); | |
123 j_callback->Reset(env, callback); | |
124 contents_container_->GetWebContents()->GenerateMHTML( | |
125 FilePath(base::android::ConvertJavaStringToUTF8(env, jpath)), | |
126 base::Bind(&GenerateMHTMLCallback, base::Owned(j_callback))); | |
106 } | 127 } |
107 | 128 |
108 void AwContents::onReceivedHttpAuthRequest( | 129 void AwContents::onReceivedHttpAuthRequest( |
109 const base::android::JavaRef<jobject>& handler, | 130 const base::android::JavaRef<jobject>& handler, |
110 const std::string& host, | 131 const std::string& host, |
111 const std::string& realm) { | 132 const std::string& realm) { |
112 JNIEnv* env = AttachCurrentThread(); | 133 JNIEnv* env = AttachCurrentThread(); |
113 ScopedJavaLocalRef<jstring> jhost = ConvertUTF8ToJavaString(env, host); | 134 ScopedJavaLocalRef<jstring> jhost = ConvertUTF8ToJavaString(env, host); |
114 ScopedJavaLocalRef<jstring> jrealm = ConvertUTF8ToJavaString(env, realm); | 135 ScopedJavaLocalRef<jstring> jrealm = ConvertUTF8ToJavaString(env, realm); |
115 Java_AwContents_onReceivedHttpAuthRequest(env, java_ref_.get(env).obj(), | 136 Java_AwContents_onReceivedHttpAuthRequest(env, java_ref_.get(env).obj(), |
116 handler.obj(), jhost.obj(), | 137 handler.obj(), jhost.obj(), |
117 jrealm.obj()); | 138 jrealm.obj()); |
118 } | 139 } |
119 | 140 |
120 static jint Init(JNIEnv* env, | 141 static jint Init(JNIEnv* env, |
121 jobject obj, | 142 jobject obj, |
122 jobject web_contents_delegate, | 143 jobject web_contents_delegate, |
123 jboolean private_browsing) { | 144 jboolean private_browsing) { |
124 AwContents* tab = new AwContents(env, obj, web_contents_delegate, | 145 AwContents* tab = new AwContents(env, obj, web_contents_delegate, |
125 private_browsing); | 146 private_browsing); |
126 return reinterpret_cast<jint>(tab); | 147 return reinterpret_cast<jint>(tab); |
127 } | 148 } |
128 | 149 |
129 bool RegisterAwContents(JNIEnv* env) { | 150 bool RegisterAwContents(JNIEnv* env) { |
130 return RegisterNativesImpl(env) >= 0; | 151 return RegisterNativesImpl(env) >= 0; |
131 } | 152 } |
132 | 153 |
133 | 154 |
134 } // namespace android_webview | 155 } // namespace android_webview |
OLD | NEW |