| 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/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/net/android_stream_reader_url_request_job.h" | 10 #include "android_webview/browser/net/android_stream_reader_url_request_job.h" |
| 10 #include "android_webview/browser/net/aw_url_request_job_factory.h" | 11 #include "android_webview/browser/net/aw_url_request_job_factory.h" |
| 11 #include "android_webview/common/url_constants.h" | 12 #include "android_webview/common/url_constants.h" |
| 12 #include "android_webview/native/input_stream_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/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" |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 ContentSchemeRequestInterceptor(); | 96 ContentSchemeRequestInterceptor(); |
| 97 bool ShouldHandleRequest(const net::URLRequest* request) const override; | 97 bool ShouldHandleRequest(const net::URLRequest* request) const override; |
| 98 }; | 98 }; |
| 99 | 99 |
| 100 // AndroidStreamReaderURLRequestJobDelegateImpl ------------------------------- | 100 // AndroidStreamReaderURLRequestJobDelegateImpl ------------------------------- |
| 101 | 101 |
| 102 AndroidStreamReaderURLRequestJobDelegateImpl:: | 102 AndroidStreamReaderURLRequestJobDelegateImpl:: |
| 103 AndroidStreamReaderURLRequestJobDelegateImpl() {} | 103 AndroidStreamReaderURLRequestJobDelegateImpl() {} |
| 104 | 104 |
| 105 AndroidStreamReaderURLRequestJobDelegateImpl:: | 105 AndroidStreamReaderURLRequestJobDelegateImpl:: |
| 106 ~AndroidStreamReaderURLRequestJobDelegateImpl() { | 106 ~AndroidStreamReaderURLRequestJobDelegateImpl() {} |
| 107 } | |
| 108 | 107 |
| 109 std::unique_ptr<InputStream> | 108 std::unique_ptr<InputStream> |
| 110 AndroidStreamReaderURLRequestJobDelegateImpl::OpenInputStream(JNIEnv* env, | 109 AndroidStreamReaderURLRequestJobDelegateImpl::OpenInputStream(JNIEnv* env, |
| 111 const GURL& url) { | 110 const GURL& url) { |
| 112 DCHECK(url.is_valid()); | 111 DCHECK(url.is_valid()); |
| 113 DCHECK(env); | 112 DCHECK(env); |
| 114 | 113 |
| 115 // Open the input stream. | 114 // Open the input stream. |
| 116 ScopedJavaLocalRef<jstring> jurl = | 115 ScopedJavaLocalRef<jstring> jurl = ConvertUTF8ToJavaString(env, url.spec()); |
| 117 ConvertUTF8ToJavaString(env, url.spec()); | |
| 118 ScopedJavaLocalRef<jobject> stream = | 116 ScopedJavaLocalRef<jobject> stream = |
| 119 android_webview::Java_AndroidProtocolHandler_open(env, jurl); | 117 android_webview::Java_AndroidProtocolHandler_open(env, jurl); |
| 120 | 118 |
| 121 if (stream.is_null()) { | 119 if (stream.is_null()) { |
| 122 DLOG(ERROR) << "Unable to open input stream for Android URL"; | 120 DLOG(ERROR) << "Unable to open input stream for Android URL"; |
| 123 return std::unique_ptr<InputStream>(); | 121 return std::unique_ptr<InputStream>(); |
| 124 } | 122 } |
| 125 return base::MakeUnique<InputStreamImpl>(stream); | 123 return base::MakeUnique<InputStreamImpl>(stream); |
| 126 } | 124 } |
| 127 | 125 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 139 android_webview::InputStream* stream, | 137 android_webview::InputStream* stream, |
| 140 std::string* mime_type) { | 138 std::string* mime_type) { |
| 141 DCHECK(env); | 139 DCHECK(env); |
| 142 DCHECK(request); | 140 DCHECK(request); |
| 143 DCHECK(mime_type); | 141 DCHECK(mime_type); |
| 144 | 142 |
| 145 // 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 |
| 146 // 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. |
| 147 ScopedJavaLocalRef<jstring> url = | 145 ScopedJavaLocalRef<jstring> url = |
| 148 ConvertUTF8ToJavaString(env, request->url().spec()); | 146 ConvertUTF8ToJavaString(env, request->url().spec()); |
| 149 const InputStreamImpl* stream_impl = | 147 const InputStreamImpl* stream_impl = InputStreamImpl::FromInputStream(stream); |
| 150 InputStreamImpl::FromInputStream(stream); | |
| 151 ScopedJavaLocalRef<jstring> returned_type = | 148 ScopedJavaLocalRef<jstring> returned_type = |
| 152 android_webview::Java_AndroidProtocolHandler_getMimeType( | 149 android_webview::Java_AndroidProtocolHandler_getMimeType( |
| 153 env, stream_impl->jobj(), url); | 150 env, stream_impl->jobj(), url); |
| 154 if (returned_type.is_null()) | 151 if (returned_type.is_null()) |
| 155 return false; | 152 return false; |
| 156 | 153 |
| 157 *mime_type = base::android::ConvertJavaStringToUTF8(returned_type); | 154 *mime_type = base::android::ConvertJavaStringToUTF8(returned_type); |
| 158 return true; | 155 return true; |
| 159 } | 156 } |
| 160 | 157 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 | 193 |
| 197 std::unique_ptr<AndroidStreamReaderURLRequestJobDelegateImpl> reader_delegate( | 194 std::unique_ptr<AndroidStreamReaderURLRequestJobDelegateImpl> reader_delegate( |
| 198 new AndroidStreamReaderURLRequestJobDelegateImpl()); | 195 new AndroidStreamReaderURLRequestJobDelegateImpl()); |
| 199 | 196 |
| 200 return new AndroidStreamReaderURLRequestJob(request, network_delegate, | 197 return new AndroidStreamReaderURLRequestJob(request, network_delegate, |
| 201 std::move(reader_delegate)); | 198 std::move(reader_delegate)); |
| 202 } | 199 } |
| 203 | 200 |
| 204 // AssetFileRequestInterceptor ------------------------------------------------ | 201 // AssetFileRequestInterceptor ------------------------------------------------ |
| 205 | 202 |
| 206 AssetFileRequestInterceptor::AssetFileRequestInterceptor() { | 203 AssetFileRequestInterceptor::AssetFileRequestInterceptor() {} |
| 207 } | |
| 208 | 204 |
| 209 bool AssetFileRequestInterceptor::ShouldHandleRequest( | 205 bool AssetFileRequestInterceptor::ShouldHandleRequest( |
| 210 const net::URLRequest* request) const { | 206 const net::URLRequest* request) const { |
| 211 return android_webview::IsAndroidSpecialFileUrl(request->url()); | 207 return android_webview::IsAndroidSpecialFileUrl(request->url()); |
| 212 } | 208 } |
| 213 | 209 |
| 214 // ContentSchemeRequestInterceptor -------------------------------------------- | 210 // ContentSchemeRequestInterceptor -------------------------------------------- |
| 215 | 211 |
| 216 ContentSchemeRequestInterceptor::ContentSchemeRequestInterceptor() { | 212 ContentSchemeRequestInterceptor::ContentSchemeRequestInterceptor() {} |
| 217 } | |
| 218 | 213 |
| 219 bool ContentSchemeRequestInterceptor::ShouldHandleRequest( | 214 bool ContentSchemeRequestInterceptor::ShouldHandleRequest( |
| 220 const net::URLRequest* request) const { | 215 const net::URLRequest* request) const { |
| 221 return request->url().SchemeIs(url::kContentScheme); | 216 return request->url().SchemeIs(url::kContentScheme); |
| 222 } | 217 } |
| 223 | 218 |
| 224 } // namespace | 219 } // namespace |
| 225 | 220 |
| 226 namespace android_webview { | 221 namespace android_webview { |
| 227 | 222 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 248 return ConvertUTF8ToJavaString(env, android_webview::kAndroidAssetPath); | 243 return ConvertUTF8ToJavaString(env, android_webview::kAndroidAssetPath); |
| 249 } | 244 } |
| 250 | 245 |
| 251 static ScopedJavaLocalRef<jstring> GetAndroidResourcePath( | 246 static ScopedJavaLocalRef<jstring> GetAndroidResourcePath( |
| 252 JNIEnv* env, | 247 JNIEnv* env, |
| 253 const JavaParamRef<jclass>& /*clazz*/) { | 248 const JavaParamRef<jclass>& /*clazz*/) { |
| 254 return ConvertUTF8ToJavaString(env, android_webview::kAndroidResourcePath); | 249 return ConvertUTF8ToJavaString(env, android_webview::kAndroidResourcePath); |
| 255 } | 250 } |
| 256 | 251 |
| 257 } // namespace android_webview | 252 } // namespace android_webview |
| OLD | NEW |