| 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 // URL request job for reading from resources and assets. | 5 // URL request job for reading from resources and assets. |
| 6 | 6 |
| 7 #include "chrome/browser/android/android_protocol_adapter.h" | 7 #include "chrome/browser/android/android_protocol_adapter.h" |
| 8 | 8 |
| 9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
| 10 #include "base/android/jni_helper.h" | 10 #include "base/android/jni_helper.h" |
| 11 #include "base/android/jni_string.h" | 11 #include "base/android/jni_string.h" |
| 12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
| 13 #include "chrome/browser/android/android_stream_reader_url_request_job.h" | 13 #include "chrome/browser/android/android_stream_reader_url_request_job.h" |
| 14 #include "chrome/common/url_constants.h" | 14 #include "chrome/common/url_constants.h" |
| 15 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
| 16 #include "jni/AndroidProtocolAdapter_jni.h" | 16 #include "jni/AndroidProtocolAdapter_jni.h" |
| 17 #include "net/base/io_buffer.h" | 17 #include "net/base/io_buffer.h" |
| 18 #include "net/base/mime_util.h" | 18 #include "net/base/mime_util.h" |
| 19 #include "net/base/net_errors.h" | 19 #include "net/base/net_errors.h" |
| 20 #include "net/base/net_util.h" | 20 #include "net/base/net_util.h" |
| 21 #include "net/http/http_util.h" | 21 #include "net/http/http_util.h" |
| 22 #include "net/url_request/url_request.h" |
| 23 #include "net/url_request/url_request_context.h" |
| 24 #include "net/url_request/file_protocol_handler.h" |
| 22 #include "net/url_request/url_request_error_job.h" | 25 #include "net/url_request/url_request_error_job.h" |
| 23 #include "net/url_request/url_request_file_job.h" | |
| 24 #include "net/url_request/url_request_job_manager.h" | 26 #include "net/url_request/url_request_job_manager.h" |
| 25 | 27 |
| 26 using base::android::AttachCurrentThread; | 28 using base::android::AttachCurrentThread; |
| 27 using base::android::ClearException; | 29 using base::android::ClearException; |
| 28 using base::android::ConvertUTF8ToJavaString; | 30 using base::android::ConvertUTF8ToJavaString; |
| 29 using base::android::ScopedJavaGlobalRef; | 31 using base::android::ScopedJavaGlobalRef; |
| 30 using base::android::ScopedJavaLocalRef; | 32 using base::android::ScopedJavaLocalRef; |
| 31 | 33 |
| 32 namespace { | 34 namespace { |
| 33 | 35 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 // handler. | 85 // handler. |
| 84 const std::string& url = request->url().spec(); | 86 const std::string& url = request->url().spec(); |
| 85 std::string assetPrefix = std::string(chrome::kFileScheme) + "://" + | 87 std::string assetPrefix = std::string(chrome::kFileScheme) + "://" + |
| 86 chrome::kAndroidAssetPath; | 88 chrome::kAndroidAssetPath; |
| 87 std::string resourcePrefix = std::string(chrome::kFileScheme) + "://" + | 89 std::string resourcePrefix = std::string(chrome::kFileScheme) + "://" + |
| 88 chrome::kAndroidResourcePath; | 90 chrome::kAndroidResourcePath; |
| 89 | 91 |
| 90 if (scheme == chrome::kFileScheme && | 92 if (scheme == chrome::kFileScheme && |
| 91 !StartsWithASCII(url, assetPrefix, /*case_sensitive=*/ true) && | 93 !StartsWithASCII(url, assetPrefix, /*case_sensitive=*/ true) && |
| 92 !StartsWithASCII(url, resourcePrefix, /*case_sensitive=*/ true)) { | 94 !StartsWithASCII(url, resourcePrefix, /*case_sensitive=*/ true)) { |
| 93 return net::URLRequestFileJob::Factory(request, scheme); | 95 net::FileProtocolHandler file_protocol_handler( |
| 96 request->context()->network_delegate()); |
| 97 return file_protocol_handler.MaybeCreateJob(request); |
| 94 } | 98 } |
| 95 | 99 |
| 96 return new AndroidStreamReaderURLRequestJob( | 100 return new AndroidStreamReaderURLRequestJob( |
| 97 request, | 101 request, |
| 98 scoped_ptr<AndroidStreamReaderURLRequestJob::Delegate>( | 102 scoped_ptr<AndroidStreamReaderURLRequestJob::Delegate>( |
| 99 new AndroidStreamReaderURLRequestJobDelegateImpl())); | 103 new AndroidStreamReaderURLRequestJobDelegateImpl())); |
| 100 } | 104 } |
| 101 | 105 |
| 102 // static | 106 // static |
| 103 bool AndroidProtocolAdapter::RegisterProtocols(JNIEnv* env) { | 107 bool AndroidProtocolAdapter::RegisterProtocols(JNIEnv* env) { |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 } | 219 } |
| 216 | 220 |
| 217 bool AndroidStreamReaderURLRequestJobDelegateImpl::GetCharset( | 221 bool AndroidStreamReaderURLRequestJobDelegateImpl::GetCharset( |
| 218 JNIEnv* env, | 222 JNIEnv* env, |
| 219 net::URLRequest* request, | 223 net::URLRequest* request, |
| 220 jobject stream, | 224 jobject stream, |
| 221 std::string* charset) { | 225 std::string* charset) { |
| 222 // TODO: We should probably be getting this from the managed side. | 226 // TODO: We should probably be getting this from the managed side. |
| 223 return false; | 227 return false; |
| 224 } | 228 } |
| OLD | NEW |