| 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/native/aw_web_resource_response_impl.h" |
| 6 | 6 |
| 7 #include "android_webview/native/input_stream_impl.h" | 7 #include "android_webview/native/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" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 const base::android::JavaRef<jobject>& obj) | 23 const base::android::JavaRef<jobject>& obj) |
| 24 : java_object_(obj) { | 24 : java_object_(obj) { |
| 25 } | 25 } |
| 26 | 26 |
| 27 AwWebResourceResponseImpl::~AwWebResourceResponseImpl() { | 27 AwWebResourceResponseImpl::~AwWebResourceResponseImpl() { |
| 28 } | 28 } |
| 29 | 29 |
| 30 std::unique_ptr<InputStream> AwWebResourceResponseImpl::GetInputStream( | 30 std::unique_ptr<InputStream> AwWebResourceResponseImpl::GetInputStream( |
| 31 JNIEnv* env) const { | 31 JNIEnv* env) const { |
| 32 ScopedJavaLocalRef<jobject> jstream = | 32 ScopedJavaLocalRef<jobject> jstream = |
| 33 Java_AwWebResourceResponse_getData(env, java_object_.obj()); | 33 Java_AwWebResourceResponse_getData(env, java_object_); |
| 34 if (jstream.is_null()) | 34 if (jstream.is_null()) |
| 35 return std::unique_ptr<InputStream>(); | 35 return std::unique_ptr<InputStream>(); |
| 36 return base::WrapUnique(new InputStreamImpl(jstream)); | 36 return base::WrapUnique(new InputStreamImpl(jstream)); |
| 37 } | 37 } |
| 38 | 38 |
| 39 bool AwWebResourceResponseImpl::GetMimeType(JNIEnv* env, | 39 bool AwWebResourceResponseImpl::GetMimeType(JNIEnv* env, |
| 40 std::string* mime_type) const { | 40 std::string* mime_type) const { |
| 41 ScopedJavaLocalRef<jstring> jstring_mime_type = | 41 ScopedJavaLocalRef<jstring> jstring_mime_type = |
| 42 Java_AwWebResourceResponse_getMimeType(env, java_object_.obj()); | 42 Java_AwWebResourceResponse_getMimeType(env, java_object_); |
| 43 if (jstring_mime_type.is_null()) | 43 if (jstring_mime_type.is_null()) |
| 44 return false; | 44 return false; |
| 45 *mime_type = ConvertJavaStringToUTF8(jstring_mime_type); | 45 *mime_type = ConvertJavaStringToUTF8(jstring_mime_type); |
| 46 return true; | 46 return true; |
| 47 } | 47 } |
| 48 | 48 |
| 49 bool AwWebResourceResponseImpl::GetCharset( | 49 bool AwWebResourceResponseImpl::GetCharset( |
| 50 JNIEnv* env, std::string* charset) const { | 50 JNIEnv* env, std::string* charset) const { |
| 51 ScopedJavaLocalRef<jstring> jstring_charset = | 51 ScopedJavaLocalRef<jstring> jstring_charset = |
| 52 Java_AwWebResourceResponse_getCharset(env, java_object_.obj()); | 52 Java_AwWebResourceResponse_getCharset(env, java_object_); |
| 53 if (jstring_charset.is_null()) | 53 if (jstring_charset.is_null()) |
| 54 return false; | 54 return false; |
| 55 *charset = ConvertJavaStringToUTF8(jstring_charset); | 55 *charset = ConvertJavaStringToUTF8(jstring_charset); |
| 56 return true; | 56 return true; |
| 57 } | 57 } |
| 58 | 58 |
| 59 bool AwWebResourceResponseImpl::GetStatusInfo( | 59 bool AwWebResourceResponseImpl::GetStatusInfo( |
| 60 JNIEnv* env, | 60 JNIEnv* env, |
| 61 int* status_code, | 61 int* status_code, |
| 62 std::string* reason_phrase) const { | 62 std::string* reason_phrase) const { |
| 63 int status = | 63 int status = Java_AwWebResourceResponse_getStatusCode(env, java_object_); |
| 64 Java_AwWebResourceResponse_getStatusCode(env, java_object_.obj()); | |
| 65 ScopedJavaLocalRef<jstring> jstring_reason_phrase = | 64 ScopedJavaLocalRef<jstring> jstring_reason_phrase = |
| 66 Java_AwWebResourceResponse_getReasonPhrase(env, java_object_.obj()); | 65 Java_AwWebResourceResponse_getReasonPhrase(env, java_object_); |
| 67 if (status < 100 || status >= 600 || jstring_reason_phrase.is_null()) | 66 if (status < 100 || status >= 600 || jstring_reason_phrase.is_null()) |
| 68 return false; | 67 return false; |
| 69 *status_code = status; | 68 *status_code = status; |
| 70 *reason_phrase = ConvertJavaStringToUTF8(jstring_reason_phrase); | 69 *reason_phrase = ConvertJavaStringToUTF8(jstring_reason_phrase); |
| 71 return true; | 70 return true; |
| 72 } | 71 } |
| 73 | 72 |
| 74 bool AwWebResourceResponseImpl::GetResponseHeaders( | 73 bool AwWebResourceResponseImpl::GetResponseHeaders( |
| 75 JNIEnv* env, | 74 JNIEnv* env, |
| 76 net::HttpResponseHeaders* headers) const { | 75 net::HttpResponseHeaders* headers) const { |
| 77 ScopedJavaLocalRef<jobjectArray> jstringArray_headerNames = | 76 ScopedJavaLocalRef<jobjectArray> jstringArray_headerNames = |
| 78 Java_AwWebResourceResponse_getResponseHeaderNames(env, | 77 Java_AwWebResourceResponse_getResponseHeaderNames(env, java_object_); |
| 79 java_object_.obj()); | |
| 80 ScopedJavaLocalRef<jobjectArray> jstringArray_headerValues = | 78 ScopedJavaLocalRef<jobjectArray> jstringArray_headerValues = |
| 81 Java_AwWebResourceResponse_getResponseHeaderValues(env, | 79 Java_AwWebResourceResponse_getResponseHeaderValues(env, java_object_); |
| 82 java_object_.obj()); | |
| 83 if (jstringArray_headerNames.is_null() || jstringArray_headerValues.is_null()) | 80 if (jstringArray_headerNames.is_null() || jstringArray_headerValues.is_null()) |
| 84 return false; | 81 return false; |
| 85 std::vector<std::string> header_names; | 82 std::vector<std::string> header_names; |
| 86 std::vector<std::string> header_values; | 83 std::vector<std::string> header_values; |
| 87 AppendJavaStringArrayToStringVector( | 84 AppendJavaStringArrayToStringVector( |
| 88 env, jstringArray_headerNames.obj(), &header_names); | 85 env, jstringArray_headerNames.obj(), &header_names); |
| 89 AppendJavaStringArrayToStringVector( | 86 AppendJavaStringArrayToStringVector( |
| 90 env, jstringArray_headerValues.obj(), &header_values); | 87 env, jstringArray_headerValues.obj(), &header_values); |
| 91 DCHECK_EQ(header_values.size(), header_names.size()); | 88 DCHECK_EQ(header_values.size(), header_names.size()); |
| 92 for(size_t i = 0; i < header_names.size(); ++i) { | 89 for(size_t i = 0; i < header_names.size(); ++i) { |
| 93 std::string header_line(header_names[i]); | 90 std::string header_line(header_names[i]); |
| 94 header_line.append(": "); | 91 header_line.append(": "); |
| 95 header_line.append(header_values[i]); | 92 header_line.append(header_values[i]); |
| 96 headers->AddHeader(header_line); | 93 headers->AddHeader(header_line); |
| 97 } | 94 } |
| 98 return true; | 95 return true; |
| 99 } | 96 } |
| 100 | 97 |
| 101 } // namespace android_webview | 98 } // namespace android_webview |
| OLD | NEW |