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_adapter.h" |
11 #include "components/cronet/android/url_request_peer.h" | 11 #include "components/cronet/android/url_request_context_adapter.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 #include "net/http/http_response_headers.h" |
16 | 16 |
17 using base::android::ConvertUTF8ToJavaString; | 17 using base::android::ConvertUTF8ToJavaString; |
18 | 18 |
19 namespace cronet { | 19 namespace cronet { |
20 namespace { | 20 namespace { |
21 | 21 |
22 net::RequestPriority ConvertRequestPriority(jint request_priority) { | 22 net::RequestPriority ConvertRequestPriority(jint request_priority) { |
23 switch (request_priority) { | 23 switch (request_priority) { |
24 case REQUEST_PRIORITY_IDLE: | 24 case REQUEST_PRIORITY_IDLE: |
25 return net::IDLE; | 25 return net::IDLE; |
26 case REQUEST_PRIORITY_LOWEST: | 26 case REQUEST_PRIORITY_LOWEST: |
27 return net::LOWEST; | 27 return net::LOWEST; |
28 case REQUEST_PRIORITY_LOW: | 28 case REQUEST_PRIORITY_LOW: |
29 return net::LOW; | 29 return net::LOW; |
30 case REQUEST_PRIORITY_MEDIUM: | 30 case REQUEST_PRIORITY_MEDIUM: |
31 return net::MEDIUM; | 31 return net::MEDIUM; |
32 case REQUEST_PRIORITY_HIGHEST: | 32 case REQUEST_PRIORITY_HIGHEST: |
33 return net::HIGHEST; | 33 return net::HIGHEST; |
34 default: | 34 default: |
35 return net::LOWEST; | 35 return net::LOWEST; |
36 } | 36 } |
37 } | 37 } |
38 | 38 |
39 void SetPostContentType(JNIEnv* env, | 39 void SetPostContentType(JNIEnv* env, |
40 URLRequestPeer* request, | 40 URLRequestAdapter* request, |
41 jstring content_type) { | 41 jstring content_type) { |
42 DCHECK(request != NULL); | 42 DCHECK(request != NULL); |
43 | 43 |
44 std::string method_post("POST"); | 44 std::string method_post("POST"); |
45 request->SetMethod(method_post); | 45 request->SetMethod(method_post); |
46 | 46 |
47 std::string content_type_header("Content-Type"); | 47 std::string content_type_header("Content-Type"); |
48 | 48 |
49 const char* content_type_utf8 = env->GetStringUTFChars(content_type, NULL); | 49 const char* content_type_utf8 = env->GetStringUTFChars(content_type, NULL); |
50 std::string content_type_string(content_type_utf8); | 50 std::string content_type_string(content_type_utf8); |
51 env->ReleaseStringUTFChars(content_type, content_type_utf8); | 51 env->ReleaseStringUTFChars(content_type, content_type_utf8); |
52 | 52 |
53 request->AddHeader(content_type_header, content_type_string); | 53 request->AddHeader(content_type_header, content_type_string); |
54 } | 54 } |
55 | 55 |
56 // A delegate of URLRequestPeer that delivers callbacks to the Java layer. | 56 // A delegate of URLRequestAdapter that delivers callbacks to the Java layer. |
57 class JniURLRequestPeerDelegate | 57 class JniURLRequestAdapterDelegate |
58 : public URLRequestPeer::URLRequestPeerDelegate { | 58 : public URLRequestAdapter::URLRequestAdapterDelegate { |
59 public: | 59 public: |
60 JniURLRequestPeerDelegate(JNIEnv* env, jobject owner) { | 60 JniURLRequestAdapterDelegate(JNIEnv* env, jobject owner) { |
61 owner_ = env->NewGlobalRef(owner); | 61 owner_ = env->NewGlobalRef(owner); |
62 } | 62 } |
63 | 63 |
64 virtual void OnResponseStarted(URLRequestPeer* request) OVERRIDE { | 64 virtual void OnResponseStarted(URLRequestAdapter* request) OVERRIDE { |
65 JNIEnv* env = base::android::AttachCurrentThread(); | 65 JNIEnv* env = base::android::AttachCurrentThread(); |
66 cronet::Java_UrlRequest_onResponseStarted(env, owner_); | 66 cronet::Java_UrlRequest_onResponseStarted(env, owner_); |
67 } | 67 } |
68 | 68 |
69 virtual void OnBytesRead(URLRequestPeer* request) OVERRIDE { | 69 virtual void OnBytesRead(URLRequestAdapter* request) OVERRIDE { |
70 int bytes_read = request->bytes_read(); | 70 int bytes_read = request->bytes_read(); |
71 if (bytes_read != 0) { | 71 if (bytes_read != 0) { |
72 JNIEnv* env = base::android::AttachCurrentThread(); | 72 JNIEnv* env = base::android::AttachCurrentThread(); |
73 base::android::ScopedJavaLocalRef<jobject> java_buffer( | 73 base::android::ScopedJavaLocalRef<jobject> java_buffer( |
74 env, env->NewDirectByteBuffer(request->Data(), bytes_read)); | 74 env, env->NewDirectByteBuffer(request->Data(), bytes_read)); |
75 cronet::Java_UrlRequest_onBytesRead(env, owner_, java_buffer.obj()); | 75 cronet::Java_UrlRequest_onBytesRead(env, owner_, java_buffer.obj()); |
76 } | 76 } |
77 } | 77 } |
78 | 78 |
79 virtual void OnRequestFinished(URLRequestPeer* request) OVERRIDE { | 79 virtual void OnRequestFinished(URLRequestAdapter* request) OVERRIDE { |
80 JNIEnv* env = base::android::AttachCurrentThread(); | 80 JNIEnv* env = base::android::AttachCurrentThread(); |
81 cronet::Java_UrlRequest_finish(env, owner_); | 81 cronet::Java_UrlRequest_finish(env, owner_); |
82 } | 82 } |
83 | 83 |
84 virtual int ReadFromUploadChannel(net::IOBuffer* buf, | 84 virtual int ReadFromUploadChannel(net::IOBuffer* buf, |
85 int buf_length) OVERRIDE { | 85 int buf_length) OVERRIDE { |
86 JNIEnv* env = base::android::AttachCurrentThread(); | 86 JNIEnv* env = base::android::AttachCurrentThread(); |
87 base::android::ScopedJavaLocalRef<jobject> java_buffer( | 87 base::android::ScopedJavaLocalRef<jobject> java_buffer( |
88 env, env->NewDirectByteBuffer(buf->data(), buf_length)); | 88 env, env->NewDirectByteBuffer(buf->data(), buf_length)); |
89 jint bytes_read = cronet::Java_UrlRequest_readFromUploadChannel( | 89 jint bytes_read = cronet::Java_UrlRequest_readFromUploadChannel( |
90 env, owner_, java_buffer.obj()); | 90 env, owner_, java_buffer.obj()); |
91 return bytes_read; | 91 return bytes_read; |
92 } | 92 } |
93 | 93 |
94 protected: | 94 protected: |
95 virtual ~JniURLRequestPeerDelegate() { | 95 virtual ~JniURLRequestAdapterDelegate() { |
96 JNIEnv* env = base::android::AttachCurrentThread(); | 96 JNIEnv* env = base::android::AttachCurrentThread(); |
97 env->DeleteGlobalRef(owner_); | 97 env->DeleteGlobalRef(owner_); |
98 } | 98 } |
99 | 99 |
100 private: | 100 private: |
101 jobject owner_; | 101 jobject owner_; |
102 | 102 |
103 DISALLOW_COPY_AND_ASSIGN(JniURLRequestPeerDelegate); | 103 DISALLOW_COPY_AND_ASSIGN(JniURLRequestAdapterDelegate); |
104 }; | 104 }; |
105 | 105 |
106 } // namespace | 106 } // namespace |
107 | 107 |
108 // Explicitly register static JNI functions. | 108 // Explicitly register static JNI functions. |
109 bool UrlRequestRegisterJni(JNIEnv* env) { return RegisterNativesImpl(env); } | 109 bool UrlRequestRegisterJni(JNIEnv* env) { return RegisterNativesImpl(env); } |
110 | 110 |
111 static jlong CreateRequestPeer(JNIEnv* env, | 111 static jlong CreateRequestAdapter(JNIEnv* env, |
112 jobject object, | 112 jobject object, |
113 jlong urlRequestContextPeer, | 113 jlong urlRequestContextAdapter, |
114 jstring url_string, | 114 jstring url_string, |
115 jint priority) { | 115 jint priority) { |
116 URLRequestContextPeer* context = | 116 URLRequestContextAdapter* context = |
117 reinterpret_cast<URLRequestContextPeer*>(urlRequestContextPeer); | 117 reinterpret_cast<URLRequestContextAdapter*>(urlRequestContextAdapter); |
118 DCHECK(context != NULL); | 118 DCHECK(context != NULL); |
119 | 119 |
120 const char* url_utf8 = env->GetStringUTFChars(url_string, NULL); | 120 const char* url_utf8 = env->GetStringUTFChars(url_string, NULL); |
121 | 121 |
122 VLOG(1) << "New chromium network request. URL:" << url_utf8; | 122 VLOG(1) << "New chromium network request. URL:" << url_utf8; |
123 | 123 |
124 GURL url(url_utf8); | 124 GURL url(url_utf8); |
125 | 125 |
126 env->ReleaseStringUTFChars(url_string, url_utf8); | 126 env->ReleaseStringUTFChars(url_string, url_utf8); |
127 | 127 |
128 URLRequestPeer* peer = | 128 URLRequestAdapter* adapter = |
129 new URLRequestPeer(context, | 129 new URLRequestAdapter(context, |
130 new JniURLRequestPeerDelegate(env, object), | 130 new JniURLRequestAdapterDelegate(env, object), |
131 url, | 131 url, |
132 ConvertRequestPriority(priority)); | 132 ConvertRequestPriority(priority)); |
133 | 133 |
134 return reinterpret_cast<jlong>(peer); | 134 return reinterpret_cast<jlong>(adapter); |
135 } | 135 } |
136 | 136 |
137 // synchronized | 137 // synchronized |
138 static void AddHeader(JNIEnv* env, | 138 static void AddHeader(JNIEnv* env, |
139 jobject object, | 139 jobject object, |
140 jlong urlRequestPeer, | 140 jlong urlRequestAdapter, |
141 jstring name, | 141 jstring name, |
142 jstring value) { | 142 jstring value) { |
143 URLRequestPeer* request = reinterpret_cast<URLRequestPeer*>(urlRequestPeer); | 143 URLRequestAdapter* request = |
| 144 reinterpret_cast<URLRequestAdapter*>(urlRequestAdapter); |
144 DCHECK(request); | 145 DCHECK(request); |
145 | 146 |
146 std::string name_string(base::android::ConvertJavaStringToUTF8(env, name)); | 147 std::string name_string(base::android::ConvertJavaStringToUTF8(env, name)); |
147 std::string value_string(base::android::ConvertJavaStringToUTF8(env, value)); | 148 std::string value_string(base::android::ConvertJavaStringToUTF8(env, value)); |
148 | 149 |
149 request->AddHeader(name_string, value_string); | 150 request->AddHeader(name_string, value_string); |
150 } | 151 } |
151 | 152 |
152 static void SetMethod(JNIEnv* env, | 153 static void SetMethod(JNIEnv* env, |
153 jobject object, | 154 jobject object, |
154 jlong urlRequestPeer, | 155 jlong urlRequestAdapter, |
155 jstring method) { | 156 jstring method) { |
156 URLRequestPeer* request = reinterpret_cast<URLRequestPeer*>(urlRequestPeer); | 157 URLRequestAdapter* request = |
| 158 reinterpret_cast<URLRequestAdapter*>(urlRequestAdapter); |
157 DCHECK(request); | 159 DCHECK(request); |
158 | 160 |
159 std::string method_string( | 161 std::string method_string( |
160 base::android::ConvertJavaStringToUTF8(env, method)); | 162 base::android::ConvertJavaStringToUTF8(env, method)); |
161 | 163 |
162 request->SetMethod(method_string); | 164 request->SetMethod(method_string); |
163 } | 165 } |
164 | 166 |
165 static void SetUploadData(JNIEnv* env, | 167 static void SetUploadData(JNIEnv* env, |
166 jobject object, | 168 jobject object, |
167 jlong urlRequestPeer, | 169 jlong urlRequestAdapter, |
168 jstring content_type, | 170 jstring content_type, |
169 jbyteArray content) { | 171 jbyteArray content) { |
170 URLRequestPeer* request = reinterpret_cast<URLRequestPeer*>(urlRequestPeer); | 172 URLRequestAdapter* request = |
| 173 reinterpret_cast<URLRequestAdapter*>(urlRequestAdapter); |
171 SetPostContentType(env, request, content_type); | 174 SetPostContentType(env, request, content_type); |
172 | 175 |
173 if (content != NULL) { | 176 if (content != NULL) { |
174 jsize size = env->GetArrayLength(content); | 177 jsize size = env->GetArrayLength(content); |
175 if (size > 0) { | 178 if (size > 0) { |
176 jbyte* content_bytes = env->GetByteArrayElements(content, NULL); | 179 jbyte* content_bytes = env->GetByteArrayElements(content, NULL); |
177 request->SetUploadContent(reinterpret_cast<const char*>(content_bytes), | 180 request->SetUploadContent(reinterpret_cast<const char*>(content_bytes), |
178 size); | 181 size); |
179 env->ReleaseByteArrayElements(content, content_bytes, 0); | 182 env->ReleaseByteArrayElements(content, content_bytes, 0); |
180 } | 183 } |
181 } | 184 } |
182 } | 185 } |
183 | 186 |
184 static void SetUploadChannel(JNIEnv* env, | 187 static void SetUploadChannel(JNIEnv* env, |
185 jobject object, | 188 jobject object, |
186 jlong urlRequestPeer, | 189 jlong urlRequestAdapter, |
187 jstring content_type, | 190 jstring content_type, |
188 jlong content_length) { | 191 jlong content_length) { |
189 URLRequestPeer* request = reinterpret_cast<URLRequestPeer*>(urlRequestPeer); | 192 URLRequestAdapter* request = |
| 193 reinterpret_cast<URLRequestAdapter*>(urlRequestAdapter); |
190 SetPostContentType(env, request, content_type); | 194 SetPostContentType(env, request, content_type); |
191 | 195 |
192 request->SetUploadChannel(env, content_length); | 196 request->SetUploadChannel(env, content_length); |
193 } | 197 } |
194 | 198 |
195 | 199 |
196 /* synchronized */ | 200 /* synchronized */ |
197 static void Start(JNIEnv* env, jobject object, jlong urlRequestPeer) { | 201 static void Start(JNIEnv* env, jobject object, jlong urlRequestAdapter) { |
198 URLRequestPeer* request = reinterpret_cast<URLRequestPeer*>(urlRequestPeer); | 202 URLRequestAdapter* request = |
| 203 reinterpret_cast<URLRequestAdapter*>(urlRequestAdapter); |
199 if (request != NULL) { | 204 if (request != NULL) { |
200 request->Start(); | 205 request->Start(); |
201 } | 206 } |
202 } | 207 } |
203 | 208 |
204 /* synchronized */ | 209 /* synchronized */ |
205 static void DestroyRequestPeer(JNIEnv* env, | 210 static void DestroyRequestAdapter(JNIEnv* env, |
206 jobject object, | 211 jobject object, |
207 jlong urlRequestPeer) { | 212 jlong urlRequestAdapter) { |
208 URLRequestPeer* request = reinterpret_cast<URLRequestPeer*>(urlRequestPeer); | 213 URLRequestAdapter* request = |
| 214 reinterpret_cast<URLRequestAdapter*>(urlRequestAdapter); |
209 if (request != NULL) { | 215 if (request != NULL) { |
210 request->Destroy(); | 216 request->Destroy(); |
211 } | 217 } |
212 } | 218 } |
213 | 219 |
214 /* synchronized */ | 220 /* synchronized */ |
215 static void Cancel(JNIEnv* env, jobject object, jlong urlRequestPeer) { | 221 static void Cancel(JNIEnv* env, jobject object, jlong urlRequestAdapter) { |
216 URLRequestPeer* request = reinterpret_cast<URLRequestPeer*>(urlRequestPeer); | 222 URLRequestAdapter* request = |
| 223 reinterpret_cast<URLRequestAdapter*>(urlRequestAdapter); |
217 if (request != NULL) { | 224 if (request != NULL) { |
218 request->Cancel(); | 225 request->Cancel(); |
219 } | 226 } |
220 } | 227 } |
221 | 228 |
222 static jint GetErrorCode(JNIEnv* env, jobject object, jlong urlRequestPeer) { | 229 static jint GetErrorCode(JNIEnv* env, jobject object, jlong urlRequestAdapter) { |
223 URLRequestPeer* request = reinterpret_cast<URLRequestPeer*>(urlRequestPeer); | 230 URLRequestAdapter* request = |
| 231 reinterpret_cast<URLRequestAdapter*>(urlRequestAdapter); |
224 int error_code = request->error_code(); | 232 int error_code = request->error_code(); |
225 switch (error_code) { | 233 switch (error_code) { |
226 // TODO(mef): Investigate returning success on positive values, too, as | 234 // TODO(mef): Investigate returning success on positive values, too, as |
227 // they technically indicate success. | 235 // they technically indicate success. |
228 case net::OK: | 236 case net::OK: |
229 return REQUEST_ERROR_SUCCESS; | 237 return REQUEST_ERROR_SUCCESS; |
230 | 238 |
231 // TODO(mef): Investigate this. The fact is that Chrome does not do this, | 239 // TODO(mef): Investigate this. The fact is that Chrome does not do this, |
232 // and this library is not just being used for downloads. | 240 // and this library is not just being used for downloads. |
233 | 241 |
(...skipping 15 matching lines...) Expand all Loading... |
249 return REQUEST_ERROR_CONNECTION_TIMED_OUT; | 257 return REQUEST_ERROR_CONNECTION_TIMED_OUT; |
250 | 258 |
251 case net::ERR_NAME_NOT_RESOLVED: | 259 case net::ERR_NAME_NOT_RESOLVED: |
252 return REQUEST_ERROR_UNKNOWN_HOST; | 260 return REQUEST_ERROR_UNKNOWN_HOST; |
253 } | 261 } |
254 return REQUEST_ERROR_UNKNOWN; | 262 return REQUEST_ERROR_UNKNOWN; |
255 } | 263 } |
256 | 264 |
257 static jstring GetErrorString(JNIEnv* env, | 265 static jstring GetErrorString(JNIEnv* env, |
258 jobject object, | 266 jobject object, |
259 jlong urlRequestPeer) { | 267 jlong urlRequestAdapter) { |
260 URLRequestPeer* request = reinterpret_cast<URLRequestPeer*>(urlRequestPeer); | 268 URLRequestAdapter* request = |
| 269 reinterpret_cast<URLRequestAdapter*>(urlRequestAdapter); |
261 int error_code = request->error_code(); | 270 int error_code = request->error_code(); |
262 char buffer[200]; | 271 char buffer[200]; |
263 std::string error_string = net::ErrorToString(error_code); | 272 std::string error_string = net::ErrorToString(error_code); |
264 snprintf(buffer, | 273 snprintf(buffer, |
265 sizeof(buffer), | 274 sizeof(buffer), |
266 "System error: %s(%d)", | 275 "System error: %s(%d)", |
267 error_string.c_str(), | 276 error_string.c_str(), |
268 error_code); | 277 error_code); |
269 return ConvertUTF8ToJavaString(env, buffer).Release(); | 278 return ConvertUTF8ToJavaString(env, buffer).Release(); |
270 } | 279 } |
271 | 280 |
272 static jint GetHttpStatusCode(JNIEnv* env, | 281 static jint GetHttpStatusCode(JNIEnv* env, |
273 jobject object, | 282 jobject object, |
274 jlong urlRequestPeer) { | 283 jlong urlRequestAdapter) { |
275 URLRequestPeer* request = reinterpret_cast<URLRequestPeer*>(urlRequestPeer); | 284 URLRequestAdapter* request = |
| 285 reinterpret_cast<URLRequestAdapter*>(urlRequestAdapter); |
276 return request->http_status_code(); | 286 return request->http_status_code(); |
277 } | 287 } |
278 | 288 |
279 static jstring GetContentType(JNIEnv* env, | 289 static jstring GetContentType(JNIEnv* env, |
280 jobject object, | 290 jobject object, |
281 jlong urlRequestPeer) { | 291 jlong urlRequestAdapter) { |
282 URLRequestPeer* request = reinterpret_cast<URLRequestPeer*>(urlRequestPeer); | 292 URLRequestAdapter* request = |
| 293 reinterpret_cast<URLRequestAdapter*>(urlRequestAdapter); |
283 if (request == NULL) { | 294 if (request == NULL) { |
284 return NULL; | 295 return NULL; |
285 } | 296 } |
286 std::string type = request->content_type(); | 297 std::string type = request->content_type(); |
287 if (!type.empty()) { | 298 if (!type.empty()) { |
288 return ConvertUTF8ToJavaString(env, type.c_str()).Release(); | 299 return ConvertUTF8ToJavaString(env, type.c_str()).Release(); |
289 } else { | 300 } else { |
290 return NULL; | 301 return NULL; |
291 } | 302 } |
292 } | 303 } |
293 | 304 |
294 static jlong GetContentLength(JNIEnv* env, | 305 static jlong GetContentLength(JNIEnv* env, |
295 jobject object, | 306 jobject object, |
296 jlong urlRequestPeer) { | 307 jlong urlRequestAdapter) { |
297 URLRequestPeer* request = reinterpret_cast<URLRequestPeer*>(urlRequestPeer); | 308 URLRequestAdapter* request = |
| 309 reinterpret_cast<URLRequestAdapter*>(urlRequestAdapter); |
298 if (request == NULL) { | 310 if (request == NULL) { |
299 return 0; | 311 return 0; |
300 } | 312 } |
301 return request->content_length(); | 313 return request->content_length(); |
302 } | 314 } |
303 | 315 |
304 static jstring GetHeader( | 316 static jstring GetHeader(JNIEnv* env, |
305 JNIEnv* env, jobject object, jlong urlRequestPeer, jstring name) { | 317 jobject object, |
306 URLRequestPeer* request = reinterpret_cast<URLRequestPeer*>(urlRequestPeer); | 318 jlong urlRequestAdapter, |
| 319 jstring name) { |
| 320 URLRequestAdapter* request = |
| 321 reinterpret_cast<URLRequestAdapter*>(urlRequestAdapter); |
307 if (request == NULL) { | 322 if (request == NULL) { |
308 return NULL; | 323 return NULL; |
309 } | 324 } |
310 | 325 |
311 std::string name_string = base::android::ConvertJavaStringToUTF8(env, name); | 326 std::string name_string = base::android::ConvertJavaStringToUTF8(env, name); |
312 std::string value = request->GetHeader(name_string); | 327 std::string value = request->GetHeader(name_string); |
313 if (!value.empty()) { | 328 if (!value.empty()) { |
314 return ConvertUTF8ToJavaString(env, value.c_str()).Release(); | 329 return ConvertUTF8ToJavaString(env, value.c_str()).Release(); |
315 } else { | 330 } else { |
316 return NULL; | 331 return NULL; |
317 } | 332 } |
318 } | 333 } |
319 | 334 |
320 static void GetAllHeaders(JNIEnv* env, | 335 static void GetAllHeaders(JNIEnv* env, |
321 jobject object, | 336 jobject object, |
322 jlong urlRequestPeer, | 337 jlong urlRequestAdapter, |
323 jobject headersMap) { | 338 jobject headersMap) { |
324 URLRequestPeer* request = reinterpret_cast<URLRequestPeer*>(urlRequestPeer); | 339 URLRequestAdapter* request = |
| 340 reinterpret_cast<URLRequestAdapter*>(urlRequestAdapter); |
325 if (request == NULL) | 341 if (request == NULL) |
326 return; | 342 return; |
327 | 343 |
328 net::HttpResponseHeaders* headers = request->GetResponseHeaders(); | 344 net::HttpResponseHeaders* headers = request->GetResponseHeaders(); |
329 if (headers == NULL) | 345 if (headers == NULL) |
330 return; | 346 return; |
331 | 347 |
332 void* iter = NULL; | 348 void* iter = NULL; |
333 std::string header_name; | 349 std::string header_name; |
334 std::string header_value; | 350 std::string header_value; |
335 while (headers->EnumerateHeaderLines(&iter, &header_name, &header_value)) { | 351 while (headers->EnumerateHeaderLines(&iter, &header_name, &header_value)) { |
336 ScopedJavaLocalRef<jstring> name = | 352 ScopedJavaLocalRef<jstring> name = |
337 ConvertUTF8ToJavaString(env, header_name); | 353 ConvertUTF8ToJavaString(env, header_name); |
338 ScopedJavaLocalRef<jstring> value = | 354 ScopedJavaLocalRef<jstring> value = |
339 ConvertUTF8ToJavaString(env, header_value); | 355 ConvertUTF8ToJavaString(env, header_value); |
340 Java_UrlRequest_onAppendResponseHeader( | 356 Java_UrlRequest_onAppendResponseHeader( |
341 env, object, headersMap, name.Release(), value.Release()); | 357 env, object, headersMap, name.Release(), value.Release()); |
342 } | 358 } |
343 | 359 |
344 // Some implementations (notably HttpURLConnection) include a mapping for the | 360 // Some implementations (notably HttpURLConnection) include a mapping for the |
345 // null key; in HTTP's case, this maps to the HTTP status line. | 361 // null key; in HTTP's case, this maps to the HTTP status line. |
346 ScopedJavaLocalRef<jstring> status_line = | 362 ScopedJavaLocalRef<jstring> status_line = |
347 ConvertUTF8ToJavaString(env, headers->GetStatusLine()); | 363 ConvertUTF8ToJavaString(env, headers->GetStatusLine()); |
348 Java_UrlRequest_onAppendResponseHeader( | 364 Java_UrlRequest_onAppendResponseHeader( |
349 env, object, headersMap, NULL, status_line.Release()); | 365 env, object, headersMap, NULL, status_line.Release()); |
350 } | 366 } |
351 | 367 |
352 } // namespace cronet | 368 } // namespace cronet |
OLD | NEW |