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/chromium_url_request.h" | 5 #include "components/cronet/android/chromium_url_request.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_adapter.h" | 10 #include "components/cronet/android/url_request_adapter.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 | 38 |
39 void SetPostContentType(JNIEnv* env, | 39 void SetPostContentType(JNIEnv* env, |
40 URLRequestAdapter* 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 std::string content_type_string( |
49 const char* content_type_utf8 = env->GetStringUTFChars(content_type, NULL); | 49 base::android::ConvertJavaStringToUTF8(env, content_type)); |
50 std::string content_type_string(content_type_utf8); | |
51 env->ReleaseStringUTFChars(content_type, content_type_utf8); | |
52 | 50 |
53 request->AddHeader(content_type_header, content_type_string); | 51 request->AddHeader(content_type_header, content_type_string); |
54 } | 52 } |
55 | 53 |
56 // A delegate of URLRequestAdapter that delivers callbacks to the Java layer. | 54 // A delegate of URLRequestAdapter that delivers callbacks to the Java layer. |
57 class JniURLRequestAdapterDelegate | 55 class JniURLRequestAdapterDelegate |
58 : public URLRequestAdapter::URLRequestAdapterDelegate { | 56 : public URLRequestAdapter::URLRequestAdapterDelegate { |
59 public: | 57 public: |
60 JniURLRequestAdapterDelegate(JNIEnv* env, jobject owner) { | 58 JniURLRequestAdapterDelegate(JNIEnv* env, jobject owner) { |
61 owner_ = env->NewGlobalRef(owner); | 59 owner_ = env->NewGlobalRef(owner); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 | 111 |
114 static jlong CreateRequestAdapter(JNIEnv* env, | 112 static jlong CreateRequestAdapter(JNIEnv* env, |
115 jobject object, | 113 jobject object, |
116 jlong urlRequestContextAdapter, | 114 jlong urlRequestContextAdapter, |
117 jstring url_string, | 115 jstring url_string, |
118 jint priority) { | 116 jint priority) { |
119 URLRequestContextAdapter* context = | 117 URLRequestContextAdapter* context = |
120 reinterpret_cast<URLRequestContextAdapter*>(urlRequestContextAdapter); | 118 reinterpret_cast<URLRequestContextAdapter*>(urlRequestContextAdapter); |
121 DCHECK(context != NULL); | 119 DCHECK(context != NULL); |
122 | 120 |
123 const char* url_utf8 = env->GetStringUTFChars(url_string, NULL); | 121 GURL url(base::android::ConvertJavaStringToUTF8(env, url_string)); |
124 | 122 |
125 VLOG(1) << "New chromium network request. URL:" << url_utf8; | 123 VLOG(1) << "New chromium network request: " << url.possibly_invalid_spec(); |
126 | |
127 GURL url(url_utf8); | |
128 | |
129 env->ReleaseStringUTFChars(url_string, url_utf8); | |
130 | 124 |
131 URLRequestAdapter* adapter = | 125 URLRequestAdapter* adapter = |
132 new URLRequestAdapter(context, | 126 new URLRequestAdapter(context, |
133 new JniURLRequestAdapterDelegate(env, object), | 127 new JniURLRequestAdapterDelegate(env, object), |
134 url, | 128 url, |
135 ConvertRequestPriority(priority)); | 129 ConvertRequestPriority(priority)); |
136 | 130 |
137 return reinterpret_cast<jlong>(adapter); | 131 return reinterpret_cast<jlong>(adapter); |
138 } | 132 } |
139 | 133 |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 | 381 |
388 // Some implementations (notably HttpURLConnection) include a mapping for the | 382 // Some implementations (notably HttpURLConnection) include a mapping for the |
389 // null key; in HTTP's case, this maps to the HTTP status line. | 383 // null key; in HTTP's case, this maps to the HTTP status line. |
390 ScopedJavaLocalRef<jstring> status_line = | 384 ScopedJavaLocalRef<jstring> status_line = |
391 ConvertUTF8ToJavaString(env, headers->GetStatusLine()); | 385 ConvertUTF8ToJavaString(env, headers->GetStatusLine()); |
392 Java_ChromiumUrlRequest_onAppendResponseHeader( | 386 Java_ChromiumUrlRequest_onAppendResponseHeader( |
393 env, object, headersMap, NULL, status_line.Release()); | 387 env, object, headersMap, NULL, status_line.Release()); |
394 } | 388 } |
395 | 389 |
396 } // namespace cronet | 390 } // namespace cronet |
OLD | NEW |