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 "components/cronet/android/org_chromium_net_UrlRequest.h" | 5 #include "components/cronet/android/org_chromium_net_UrlRequest.h" |
6 | 6 |
7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
8 #include "base/android/jni_string.h" | 8 #include "base/android/jni_string.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "components/cronet/android/url_request_context_peer.h" | 10 #include "components/cronet/android/url_request_context_peer.h" |
11 #include "components/cronet/android/url_request_peer.h" | 11 #include "components/cronet/android/url_request_peer.h" |
12 #include "jni/UrlRequest_jni.h" | 12 #include "jni/UrlRequest_jni.h" |
13 #include "net/base/net_errors.h" | 13 #include "net/base/net_errors.h" |
14 #include "net/base/request_priority.h" | 14 #include "net/base/request_priority.h" |
| 15 #include "net/http/http_response_headers.h" |
15 | 16 |
16 using base::android::ConvertUTF8ToJavaString; | 17 using base::android::ConvertUTF8ToJavaString; |
17 | 18 |
18 namespace cronet { | 19 namespace cronet { |
19 namespace { | 20 namespace { |
20 | 21 |
21 net::RequestPriority ConvertRequestPriority(jint request_priority) { | 22 net::RequestPriority ConvertRequestPriority(jint request_priority) { |
22 switch (request_priority) { | 23 switch (request_priority) { |
23 case REQUEST_PRIORITY_IDLE: | 24 case REQUEST_PRIORITY_IDLE: |
24 return net::IDLE; | 25 return net::IDLE; |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 | 301 |
301 std::string name_string = base::android::ConvertJavaStringToUTF8(env, name); | 302 std::string name_string = base::android::ConvertJavaStringToUTF8(env, name); |
302 std::string value = request->GetHeader(name_string); | 303 std::string value = request->GetHeader(name_string); |
303 if (!value.empty()) { | 304 if (!value.empty()) { |
304 return ConvertUTF8ToJavaString(env, value.c_str()).Release(); | 305 return ConvertUTF8ToJavaString(env, value.c_str()).Release(); |
305 } else { | 306 } else { |
306 return NULL; | 307 return NULL; |
307 } | 308 } |
308 } | 309 } |
309 | 310 |
| 311 static void GetAllHeaders(JNIEnv* env, |
| 312 jobject object, |
| 313 jlong urlRequestPeer, |
| 314 jobject headersMap) { |
| 315 URLRequestPeer* request = reinterpret_cast<URLRequestPeer*>(urlRequestPeer); |
| 316 if (request == NULL) |
| 317 return; |
| 318 |
| 319 net::HttpResponseHeaders* headers = request->GetResponseHeaders(); |
| 320 if (headers == NULL) |
| 321 return; |
| 322 |
| 323 void* iter = NULL; |
| 324 std::string header_name; |
| 325 std::string header_value; |
| 326 while (headers->EnumerateHeaderLines(&iter, &header_name, &header_value)) { |
| 327 ScopedJavaLocalRef<jstring> name = |
| 328 ConvertUTF8ToJavaString(env, header_name); |
| 329 ScopedJavaLocalRef<jstring> value = |
| 330 ConvertUTF8ToJavaString(env, header_value); |
| 331 Java_UrlRequest_onAppendResponseHeader( |
| 332 env, object, headersMap, name.Release(), value.Release()); |
| 333 } |
| 334 |
| 335 // Some implementations (notably HttpURLConnection) include a mapping for the |
| 336 // null key; in HTTP's case, this maps to the HTTP status line. |
| 337 ScopedJavaLocalRef<jstring> status_line = |
| 338 ConvertUTF8ToJavaString(env, headers->GetStatusLine()); |
| 339 Java_UrlRequest_onAppendResponseHeader( |
| 340 env, object, headersMap, NULL, status_line.Release()); |
| 341 } |
| 342 |
310 } // namespace cronet | 343 } // namespace cronet |
OLD | NEW |