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/android_protocol_handler.h" | 5 #include "android_webview/native/android_protocol_handler.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "android_webview/browser/net/android_stream_reader_url_request_job.h" | 9 #include "android_webview/browser/net/android_stream_reader_url_request_job.h" |
10 #include "android_webview/browser/net/aw_url_request_job_factory.h" | 10 #include "android_webview/browser/net/aw_url_request_job_factory.h" |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 AndroidStreamReaderURLRequestJobDelegateImpl::OpenInputStream(JNIEnv* env, | 128 AndroidStreamReaderURLRequestJobDelegateImpl::OpenInputStream(JNIEnv* env, |
129 const GURL& url) { | 129 const GURL& url) { |
130 DCHECK(url.is_valid()); | 130 DCHECK(url.is_valid()); |
131 DCHECK(env); | 131 DCHECK(env); |
132 | 132 |
133 // Open the input stream. | 133 // Open the input stream. |
134 ScopedJavaLocalRef<jstring> jurl = | 134 ScopedJavaLocalRef<jstring> jurl = |
135 ConvertUTF8ToJavaString(env, url.spec()); | 135 ConvertUTF8ToJavaString(env, url.spec()); |
136 ScopedJavaLocalRef<jobject> stream = | 136 ScopedJavaLocalRef<jobject> stream = |
137 android_webview::Java_AndroidProtocolHandler_open( | 137 android_webview::Java_AndroidProtocolHandler_open( |
138 env, | 138 env, GetResourceContext(env), jurl); |
139 GetResourceContext(env).obj(), | |
140 jurl.obj()); | |
141 | 139 |
142 if (stream.is_null()) { | 140 if (stream.is_null()) { |
143 DLOG(ERROR) << "Unable to open input stream for Android URL"; | 141 DLOG(ERROR) << "Unable to open input stream for Android URL"; |
144 return std::unique_ptr<InputStream>(); | 142 return std::unique_ptr<InputStream>(); |
145 } | 143 } |
146 return base::WrapUnique(new InputStreamImpl(stream)); | 144 return base::WrapUnique(new InputStreamImpl(stream)); |
147 } | 145 } |
148 | 146 |
149 void AndroidStreamReaderURLRequestJobDelegateImpl::OnInputStreamOpenFailed( | 147 void AndroidStreamReaderURLRequestJobDelegateImpl::OnInputStreamOpenFailed( |
150 net::URLRequest* request, | 148 net::URLRequest* request, |
(...skipping 13 matching lines...) Expand all Loading... |
164 DCHECK(mime_type); | 162 DCHECK(mime_type); |
165 | 163 |
166 // Query the mime type from the Java side. It is possible for the query to | 164 // Query the mime type from the Java side. It is possible for the query to |
167 // fail, as the mime type cannot be determined for all supported schemes. | 165 // fail, as the mime type cannot be determined for all supported schemes. |
168 ScopedJavaLocalRef<jstring> url = | 166 ScopedJavaLocalRef<jstring> url = |
169 ConvertUTF8ToJavaString(env, request->url().spec()); | 167 ConvertUTF8ToJavaString(env, request->url().spec()); |
170 const InputStreamImpl* stream_impl = | 168 const InputStreamImpl* stream_impl = |
171 InputStreamImpl::FromInputStream(stream); | 169 InputStreamImpl::FromInputStream(stream); |
172 ScopedJavaLocalRef<jstring> returned_type = | 170 ScopedJavaLocalRef<jstring> returned_type = |
173 android_webview::Java_AndroidProtocolHandler_getMimeType( | 171 android_webview::Java_AndroidProtocolHandler_getMimeType( |
174 env, | 172 env, GetResourceContext(env), stream_impl->jobj(), url); |
175 GetResourceContext(env).obj(), | |
176 stream_impl->jobj(), url.obj()); | |
177 if (returned_type.is_null()) | 173 if (returned_type.is_null()) |
178 return false; | 174 return false; |
179 | 175 |
180 *mime_type = base::android::ConvertJavaStringToUTF8(returned_type); | 176 *mime_type = base::android::ConvertJavaStringToUTF8(returned_type); |
181 return true; | 177 return true; |
182 } | 178 } |
183 | 179 |
184 bool AndroidStreamReaderURLRequestJobDelegateImpl::GetCharset( | 180 bool AndroidStreamReaderURLRequestJobDelegateImpl::GetCharset( |
185 JNIEnv* env, | 181 JNIEnv* env, |
186 net::URLRequest* request, | 182 net::URLRequest* request, |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 return ConvertUTF8ToJavaString(env, android_webview::kAndroidAssetPath); | 284 return ConvertUTF8ToJavaString(env, android_webview::kAndroidAssetPath); |
289 } | 285 } |
290 | 286 |
291 static ScopedJavaLocalRef<jstring> GetAndroidResourcePath( | 287 static ScopedJavaLocalRef<jstring> GetAndroidResourcePath( |
292 JNIEnv* env, | 288 JNIEnv* env, |
293 const JavaParamRef<jclass>& /*clazz*/) { | 289 const JavaParamRef<jclass>& /*clazz*/) { |
294 return ConvertUTF8ToJavaString(env, android_webview::kAndroidResourcePath); | 290 return ConvertUTF8ToJavaString(env, android_webview::kAndroidResourcePath); |
295 } | 291 } |
296 | 292 |
297 } // namespace android_webview | 293 } // namespace android_webview |
OLD | NEW |