| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/aw_web_resource_response_impl.h" | 5 #include "android_webview/browser/aw_web_resource_response_impl.h" |
| 6 | 6 |
| 7 #include "android_webview/native/input_stream_impl.h" | 7 #include "android_webview/browser/input_stream_impl.h" |
| 8 #include "base/android/jni_android.h" | 8 #include "base/android/jni_android.h" |
| 9 #include "base/android/jni_array.h" | 9 #include "base/android/jni_array.h" |
| 10 #include "base/android/jni_string.h" | 10 #include "base/android/jni_string.h" |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "jni/AwWebResourceResponse_jni.h" | 12 #include "jni/AwWebResourceResponse_jni.h" |
| 13 #include "net/http/http_response_headers.h" | 13 #include "net/http/http_response_headers.h" |
| 14 #include "net/url_request/url_request.h" | 14 #include "net/url_request/url_request.h" |
| 15 #include "net/url_request/url_request_job.h" | 15 #include "net/url_request/url_request_job.h" |
| 16 | 16 |
| 17 using base::android::ScopedJavaLocalRef; | 17 using base::android::ScopedJavaLocalRef; |
| 18 using base::android::AppendJavaStringArrayToStringVector; | 18 using base::android::AppendJavaStringArrayToStringVector; |
| 19 | 19 |
| 20 namespace android_webview { | 20 namespace android_webview { |
| 21 | 21 |
| 22 AwWebResourceResponseImpl::AwWebResourceResponseImpl( | 22 AwWebResourceResponseImpl::AwWebResourceResponseImpl( |
| 23 const base::android::JavaRef<jobject>& obj) | 23 const base::android::JavaRef<jobject>& obj) |
| 24 : java_object_(obj) { | 24 : java_object_(obj) {} |
| 25 } | |
| 26 | 25 |
| 27 AwWebResourceResponseImpl::~AwWebResourceResponseImpl() { | 26 AwWebResourceResponseImpl::~AwWebResourceResponseImpl() {} |
| 28 } | |
| 29 | 27 |
| 30 std::unique_ptr<InputStream> AwWebResourceResponseImpl::GetInputStream( | 28 std::unique_ptr<InputStream> AwWebResourceResponseImpl::GetInputStream( |
| 31 JNIEnv* env) const { | 29 JNIEnv* env) const { |
| 32 ScopedJavaLocalRef<jobject> jstream = | 30 ScopedJavaLocalRef<jobject> jstream = |
| 33 Java_AwWebResourceResponse_getData(env, java_object_); | 31 Java_AwWebResourceResponse_getData(env, java_object_); |
| 34 if (jstream.is_null()) | 32 if (jstream.is_null()) |
| 35 return std::unique_ptr<InputStream>(); | 33 return std::unique_ptr<InputStream>(); |
| 36 return base::MakeUnique<InputStreamImpl>(jstream); | 34 return base::MakeUnique<InputStreamImpl>(jstream); |
| 37 } | 35 } |
| 38 | 36 |
| 39 bool AwWebResourceResponseImpl::GetMimeType(JNIEnv* env, | 37 bool AwWebResourceResponseImpl::GetMimeType(JNIEnv* env, |
| 40 std::string* mime_type) const { | 38 std::string* mime_type) const { |
| 41 ScopedJavaLocalRef<jstring> jstring_mime_type = | 39 ScopedJavaLocalRef<jstring> jstring_mime_type = |
| 42 Java_AwWebResourceResponse_getMimeType(env, java_object_); | 40 Java_AwWebResourceResponse_getMimeType(env, java_object_); |
| 43 if (jstring_mime_type.is_null()) | 41 if (jstring_mime_type.is_null()) |
| 44 return false; | 42 return false; |
| 45 *mime_type = ConvertJavaStringToUTF8(jstring_mime_type); | 43 *mime_type = ConvertJavaStringToUTF8(jstring_mime_type); |
| 46 return true; | 44 return true; |
| 47 } | 45 } |
| 48 | 46 |
| 49 bool AwWebResourceResponseImpl::GetCharset( | 47 bool AwWebResourceResponseImpl::GetCharset(JNIEnv* env, |
| 50 JNIEnv* env, std::string* charset) const { | 48 std::string* charset) const { |
| 51 ScopedJavaLocalRef<jstring> jstring_charset = | 49 ScopedJavaLocalRef<jstring> jstring_charset = |
| 52 Java_AwWebResourceResponse_getCharset(env, java_object_); | 50 Java_AwWebResourceResponse_getCharset(env, java_object_); |
| 53 if (jstring_charset.is_null()) | 51 if (jstring_charset.is_null()) |
| 54 return false; | 52 return false; |
| 55 *charset = ConvertJavaStringToUTF8(jstring_charset); | 53 *charset = ConvertJavaStringToUTF8(jstring_charset); |
| 56 return true; | 54 return true; |
| 57 } | 55 } |
| 58 | 56 |
| 59 bool AwWebResourceResponseImpl::GetStatusInfo( | 57 bool AwWebResourceResponseImpl::GetStatusInfo( |
| 60 JNIEnv* env, | 58 JNIEnv* env, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 74 JNIEnv* env, | 72 JNIEnv* env, |
| 75 net::HttpResponseHeaders* headers) const { | 73 net::HttpResponseHeaders* headers) const { |
| 76 ScopedJavaLocalRef<jobjectArray> jstringArray_headerNames = | 74 ScopedJavaLocalRef<jobjectArray> jstringArray_headerNames = |
| 77 Java_AwWebResourceResponse_getResponseHeaderNames(env, java_object_); | 75 Java_AwWebResourceResponse_getResponseHeaderNames(env, java_object_); |
| 78 ScopedJavaLocalRef<jobjectArray> jstringArray_headerValues = | 76 ScopedJavaLocalRef<jobjectArray> jstringArray_headerValues = |
| 79 Java_AwWebResourceResponse_getResponseHeaderValues(env, java_object_); | 77 Java_AwWebResourceResponse_getResponseHeaderValues(env, java_object_); |
| 80 if (jstringArray_headerNames.is_null() || jstringArray_headerValues.is_null()) | 78 if (jstringArray_headerNames.is_null() || jstringArray_headerValues.is_null()) |
| 81 return false; | 79 return false; |
| 82 std::vector<std::string> header_names; | 80 std::vector<std::string> header_names; |
| 83 std::vector<std::string> header_values; | 81 std::vector<std::string> header_values; |
| 84 AppendJavaStringArrayToStringVector( | 82 AppendJavaStringArrayToStringVector(env, jstringArray_headerNames.obj(), |
| 85 env, jstringArray_headerNames.obj(), &header_names); | 83 &header_names); |
| 86 AppendJavaStringArrayToStringVector( | 84 AppendJavaStringArrayToStringVector(env, jstringArray_headerValues.obj(), |
| 87 env, jstringArray_headerValues.obj(), &header_values); | 85 &header_values); |
| 88 DCHECK_EQ(header_values.size(), header_names.size()); | 86 DCHECK_EQ(header_values.size(), header_names.size()); |
| 89 for(size_t i = 0; i < header_names.size(); ++i) { | 87 for (size_t i = 0; i < header_names.size(); ++i) { |
| 90 std::string header_line(header_names[i]); | 88 std::string header_line(header_names[i]); |
| 91 header_line.append(": "); | 89 header_line.append(": "); |
| 92 header_line.append(header_values[i]); | 90 header_line.append(header_values[i]); |
| 93 headers->AddHeader(header_line); | 91 headers->AddHeader(header_line); |
| 94 } | 92 } |
| 95 return true; | 93 return true; |
| 96 } | 94 } |
| 97 | 95 |
| 98 } // namespace android_webview | 96 } // namespace android_webview |
| OLD | NEW |