| 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" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 | 67 |
| 68 } // namespace | 68 } // namespace |
| 69 | 69 |
| 70 static bool InitJNIBindings(JNIEnv* env) { | 70 static bool InitJNIBindings(JNIEnv* env) { |
| 71 return RegisterNativesImpl(env) && | 71 return RegisterNativesImpl(env) && |
| 72 AndroidStreamReaderURLRequestJob::InitJNIBindings(env); | 72 AndroidStreamReaderURLRequestJob::InitJNIBindings(env); |
| 73 } | 73 } |
| 74 | 74 |
| 75 // static | 75 // static |
| 76 net::URLRequestJob* AndroidProtocolAdapter::Factory( | 76 net::URLRequestJob* AndroidProtocolAdapter::Factory( |
| 77 net::URLRequest* request, const std::string& scheme) { | 77 net::URLRequest* request, |
| 78 net::NetworkDelegate* network_delegate, |
| 79 const std::string& scheme) { |
| 78 DCHECK(scheme == chrome::kFileScheme || | 80 DCHECK(scheme == chrome::kFileScheme || |
| 79 scheme == chrome::kContentScheme); | 81 scheme == chrome::kContentScheme); |
| 80 JNIEnv* env = AttachCurrentThread(); | 82 JNIEnv* env = AttachCurrentThread(); |
| 81 DCHECK(env); | 83 DCHECK(env); |
| 82 // If this is a file:// URL we cannot handle, fall back to the default | 84 // If this is a file:// URL we cannot handle, fall back to the default |
| 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 return net::URLRequestFileJob::Factory(request, network_delegate, scheme); |
| 94 } | 96 } |
| 95 | 97 |
| 96 return new AndroidStreamReaderURLRequestJob( | 98 return new AndroidStreamReaderURLRequestJob( |
| 97 request, | 99 request, |
| 100 network_delegate, |
| 98 scoped_ptr<AndroidStreamReaderURLRequestJob::Delegate>( | 101 scoped_ptr<AndroidStreamReaderURLRequestJob::Delegate>( |
| 99 new AndroidStreamReaderURLRequestJobDelegateImpl())); | 102 new AndroidStreamReaderURLRequestJobDelegateImpl())); |
| 100 } | 103 } |
| 101 | 104 |
| 102 // static | 105 // static |
| 103 bool AndroidProtocolAdapter::RegisterProtocols(JNIEnv* env) { | 106 bool AndroidProtocolAdapter::RegisterProtocols(JNIEnv* env) { |
| 104 DCHECK(env); | 107 DCHECK(env); |
| 105 | 108 |
| 106 if (!InitJNIBindings(env)) | 109 if (!InitJNIBindings(env)) |
| 107 return false; | 110 return false; |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 } | 218 } |
| 216 | 219 |
| 217 bool AndroidStreamReaderURLRequestJobDelegateImpl::GetCharset( | 220 bool AndroidStreamReaderURLRequestJobDelegateImpl::GetCharset( |
| 218 JNIEnv* env, | 221 JNIEnv* env, |
| 219 net::URLRequest* request, | 222 net::URLRequest* request, |
| 220 jobject stream, | 223 jobject stream, |
| 221 std::string* charset) { | 224 std::string* charset) { |
| 222 // TODO: We should probably be getting this from the managed side. | 225 // TODO: We should probably be getting this from the managed side. |
| 223 return false; | 226 return false; |
| 224 } | 227 } |
| OLD | NEW |