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/intercepted_request_data_impl.h" | 5 #include "android_webview/native/intercepted_request_data_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_string.h" | 10 #include "base/android/jni_string.h" |
10 #include "jni/InterceptedRequestData_jni.h" | 11 #include "jni/InterceptedRequestData_jni.h" |
| 12 #include "net/http/http_response_headers.h" |
11 #include "net/url_request/url_request.h" | 13 #include "net/url_request/url_request.h" |
12 #include "net/url_request/url_request_job.h" | 14 #include "net/url_request/url_request_job.h" |
13 | 15 |
14 using base::android::ScopedJavaLocalRef; | 16 using base::android::ScopedJavaLocalRef; |
| 17 using base::android::AppendJavaStringArrayToStringVector; |
15 | 18 |
16 namespace android_webview { | 19 namespace android_webview { |
17 | 20 |
18 InterceptedRequestDataImpl::InterceptedRequestDataImpl( | 21 InterceptedRequestDataImpl::InterceptedRequestDataImpl( |
19 const base::android::JavaRef<jobject>& obj) | 22 const base::android::JavaRef<jobject>& obj) |
20 : java_object_(obj) { | 23 : java_object_(obj) { |
21 } | 24 } |
22 | 25 |
23 InterceptedRequestDataImpl::~InterceptedRequestDataImpl() { | 26 InterceptedRequestDataImpl::~InterceptedRequestDataImpl() { |
24 } | 27 } |
(...skipping 20 matching lines...) Expand all Loading... |
45 bool InterceptedRequestDataImpl::GetCharset( | 48 bool InterceptedRequestDataImpl::GetCharset( |
46 JNIEnv* env, std::string* charset) const { | 49 JNIEnv* env, std::string* charset) const { |
47 ScopedJavaLocalRef<jstring> jstring_charset = | 50 ScopedJavaLocalRef<jstring> jstring_charset = |
48 Java_InterceptedRequestData_getCharset(env, java_object_.obj()); | 51 Java_InterceptedRequestData_getCharset(env, java_object_.obj()); |
49 if (jstring_charset.is_null()) | 52 if (jstring_charset.is_null()) |
50 return false; | 53 return false; |
51 *charset = ConvertJavaStringToUTF8(jstring_charset); | 54 *charset = ConvertJavaStringToUTF8(jstring_charset); |
52 return true; | 55 return true; |
53 } | 56 } |
54 | 57 |
| 58 bool InterceptedRequestDataImpl::GetStatusInfo( |
| 59 JNIEnv* env, |
| 60 int* status_code, |
| 61 std::string* reason_phrase) const { |
| 62 int status = |
| 63 Java_InterceptedRequestData_getStatusCode(env, java_object_.obj()); |
| 64 ScopedJavaLocalRef<jstring> jstring_reason_phrase = |
| 65 Java_InterceptedRequestData_getReasonPhrase(env, java_object_.obj()); |
| 66 if (status < 100 || status >= 600 || jstring_reason_phrase.is_null()) |
| 67 return false; |
| 68 *status_code = status; |
| 69 *reason_phrase = ConvertJavaStringToUTF8(jstring_reason_phrase); |
| 70 return true; |
| 71 } |
| 72 |
| 73 bool InterceptedRequestDataImpl::GetHeaders( |
| 74 JNIEnv* env, |
| 75 net::HttpResponseHeaders* headers) const { |
| 76 ScopedJavaLocalRef<jobjectArray> jstringArray_headerNames = |
| 77 Java_InterceptedRequestData_getHeaderNames(env, java_object_.obj()); |
| 78 ScopedJavaLocalRef<jobjectArray> jstringArray_headerValues = |
| 79 Java_InterceptedRequestData_getHeaderValues(env, java_object_.obj()); |
| 80 if (jstringArray_headerNames.is_null() || jstringArray_headerValues.is_null()) |
| 81 return false; |
| 82 std::vector<std::string> header_names; |
| 83 std::vector<std::string> header_values; |
| 84 AppendJavaStringArrayToStringVector( |
| 85 env, jstringArray_headerNames.obj(), &header_names); |
| 86 AppendJavaStringArrayToStringVector( |
| 87 env, jstringArray_headerValues.obj(), &header_values); |
| 88 DCHECK(header_names.size() == header_values.size()); |
| 89 for(size_t i = 0; i < header_names.size(); ++i) { |
| 90 std::string header_line(header_names[i]); |
| 91 header_line.append(": "); |
| 92 header_line.append(header_values[i]); |
| 93 headers->AddHeader(header_line); |
| 94 } |
| 95 return true; |
| 96 } |
| 97 |
55 bool RegisterInterceptedRequestData(JNIEnv* env) { | 98 bool RegisterInterceptedRequestData(JNIEnv* env) { |
56 return RegisterNativesImpl(env); | 99 return RegisterNativesImpl(env); |
57 } | 100 } |
58 | 101 |
59 } // namespace android_webview | 102 } // namespace android_webview |
OLD | NEW |