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/browser/android_protocol_handler.h" | 5 #include "android_webview/browser/android_protocol_handler.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "android_webview/browser/input_stream_impl.h" | 9 #include "android_webview/browser/input_stream.h" |
10 #include "android_webview/browser/net/android_stream_reader_url_request_job.h" | 10 #include "android_webview/browser/net/android_stream_reader_url_request_job.h" |
11 #include "android_webview/browser/net/aw_url_request_job_factory.h" | 11 #include "android_webview/browser/net/aw_url_request_job_factory.h" |
12 #include "android_webview/common/url_constants.h" | 12 #include "android_webview/common/url_constants.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/android/jni_weak_ref.h" | 15 #include "base/android/jni_weak_ref.h" |
16 #include "base/memory/ptr_util.h" | 16 #include "base/memory/ptr_util.h" |
17 #include "content/public/common/url_constants.h" | 17 #include "content/public/common/url_constants.h" |
18 #include "jni/AndroidProtocolHandler_jni.h" | 18 #include "jni/AndroidProtocolHandler_jni.h" |
19 #include "net/base/io_buffer.h" | 19 #include "net/base/io_buffer.h" |
20 #include "net/base/mime_util.h" | 20 #include "net/base/mime_util.h" |
21 #include "net/base/net_errors.h" | 21 #include "net/base/net_errors.h" |
22 #include "net/http/http_util.h" | 22 #include "net/http/http_util.h" |
23 #include "net/url_request/url_request.h" | 23 #include "net/url_request/url_request.h" |
24 #include "net/url_request/url_request_interceptor.h" | 24 #include "net/url_request/url_request_interceptor.h" |
25 #include "url/gurl.h" | 25 #include "url/gurl.h" |
26 #include "url/url_constants.h" | 26 #include "url/url_constants.h" |
27 | 27 |
28 using android_webview::AndroidStreamReaderURLRequestJob; | 28 using android_webview::AndroidStreamReaderURLRequestJob; |
29 using android_webview::InputStream; | 29 using android_webview::InputStream; |
30 using android_webview::InputStreamImpl; | 30 using android_webview::InputStream; |
31 using base::android::AttachCurrentThread; | 31 using base::android::AttachCurrentThread; |
32 using base::android::ClearException; | 32 using base::android::ClearException; |
33 using base::android::ConvertUTF8ToJavaString; | 33 using base::android::ConvertUTF8ToJavaString; |
34 using base::android::JavaParamRef; | 34 using base::android::JavaParamRef; |
35 using base::android::ScopedJavaGlobalRef; | 35 using base::android::ScopedJavaGlobalRef; |
36 using base::android::ScopedJavaLocalRef; | 36 using base::android::ScopedJavaLocalRef; |
37 | 37 |
38 namespace { | 38 namespace { |
39 | 39 |
40 void* kPreviouslyFailedKey = &kPreviouslyFailedKey; | 40 void* kPreviouslyFailedKey = &kPreviouslyFailedKey; |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 | 113 |
114 // Open the input stream. | 114 // Open the input stream. |
115 ScopedJavaLocalRef<jstring> jurl = ConvertUTF8ToJavaString(env, url.spec()); | 115 ScopedJavaLocalRef<jstring> jurl = ConvertUTF8ToJavaString(env, url.spec()); |
116 ScopedJavaLocalRef<jobject> stream = | 116 ScopedJavaLocalRef<jobject> stream = |
117 android_webview::Java_AndroidProtocolHandler_open(env, jurl); | 117 android_webview::Java_AndroidProtocolHandler_open(env, jurl); |
118 | 118 |
119 if (stream.is_null()) { | 119 if (stream.is_null()) { |
120 DLOG(ERROR) << "Unable to open input stream for Android URL"; | 120 DLOG(ERROR) << "Unable to open input stream for Android URL"; |
121 return std::unique_ptr<InputStream>(); | 121 return std::unique_ptr<InputStream>(); |
122 } | 122 } |
123 return base::MakeUnique<InputStreamImpl>(stream); | 123 return base::MakeUnique<InputStream>(stream); |
124 } | 124 } |
125 | 125 |
126 void AndroidStreamReaderURLRequestJobDelegateImpl::OnInputStreamOpenFailed( | 126 void AndroidStreamReaderURLRequestJobDelegateImpl::OnInputStreamOpenFailed( |
127 net::URLRequest* request, | 127 net::URLRequest* request, |
128 bool* restart) { | 128 bool* restart) { |
129 DCHECK(!HasRequestPreviouslyFailed(request)); | 129 DCHECK(!HasRequestPreviouslyFailed(request)); |
130 MarkRequestAsFailed(request); | 130 MarkRequestAsFailed(request); |
131 *restart = true; | 131 *restart = true; |
132 } | 132 } |
133 | 133 |
134 bool AndroidStreamReaderURLRequestJobDelegateImpl::GetMimeType( | 134 bool AndroidStreamReaderURLRequestJobDelegateImpl::GetMimeType( |
135 JNIEnv* env, | 135 JNIEnv* env, |
136 net::URLRequest* request, | 136 net::URLRequest* request, |
137 android_webview::InputStream* stream, | 137 android_webview::InputStream* stream, |
138 std::string* mime_type) { | 138 std::string* mime_type) { |
139 DCHECK(env); | 139 DCHECK(env); |
140 DCHECK(request); | 140 DCHECK(request); |
141 DCHECK(mime_type); | 141 DCHECK(mime_type); |
142 | 142 |
143 // Query the mime type from the Java side. It is possible for the query to | 143 // Query the mime type from the Java side. It is possible for the query to |
144 // fail, as the mime type cannot be determined for all supported schemes. | 144 // fail, as the mime type cannot be determined for all supported schemes. |
145 ScopedJavaLocalRef<jstring> url = | 145 ScopedJavaLocalRef<jstring> url = |
146 ConvertUTF8ToJavaString(env, request->url().spec()); | 146 ConvertUTF8ToJavaString(env, request->url().spec()); |
147 const InputStreamImpl* stream_impl = InputStreamImpl::FromInputStream(stream); | |
148 ScopedJavaLocalRef<jstring> returned_type = | 147 ScopedJavaLocalRef<jstring> returned_type = |
149 android_webview::Java_AndroidProtocolHandler_getMimeType( | 148 android_webview::Java_AndroidProtocolHandler_getMimeType( |
150 env, stream_impl->jobj(), url); | 149 env, stream->jobj(), url); |
151 if (returned_type.is_null()) | 150 if (returned_type.is_null()) |
152 return false; | 151 return false; |
153 | 152 |
154 *mime_type = base::android::ConvertJavaStringToUTF8(returned_type); | 153 *mime_type = base::android::ConvertJavaStringToUTF8(returned_type); |
155 return true; | 154 return true; |
156 } | 155 } |
157 | 156 |
158 bool AndroidStreamReaderURLRequestJobDelegateImpl::GetCharset( | 157 bool AndroidStreamReaderURLRequestJobDelegateImpl::GetCharset( |
159 JNIEnv* env, | 158 JNIEnv* env, |
160 net::URLRequest* request, | 159 net::URLRequest* request, |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 return ConvertUTF8ToJavaString(env, android_webview::kAndroidAssetPath); | 242 return ConvertUTF8ToJavaString(env, android_webview::kAndroidAssetPath); |
244 } | 243 } |
245 | 244 |
246 static ScopedJavaLocalRef<jstring> GetAndroidResourcePath( | 245 static ScopedJavaLocalRef<jstring> GetAndroidResourcePath( |
247 JNIEnv* env, | 246 JNIEnv* env, |
248 const JavaParamRef<jclass>& /*clazz*/) { | 247 const JavaParamRef<jclass>& /*clazz*/) { |
249 return ConvertUTF8ToJavaString(env, android_webview::kAndroidResourcePath); | 248 return ConvertUTF8ToJavaString(env, android_webview::kAndroidResourcePath); |
250 } | 249 } |
251 | 250 |
252 } // namespace android_webview | 251 } // namespace android_webview |
OLD | NEW |