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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
107 } // namespace | 105 } // namespace |
108 | 106 |
109 // Explicitly register static JNI functions. | 107 // Explicitly register static JNI functions. |
110 bool ChromiumUrlRequestRegisterJni(JNIEnv* env) { | 108 bool ChromiumUrlRequestRegisterJni(JNIEnv* env) { |
111 return RegisterNativesImpl(env); | 109 return RegisterNativesImpl(env); |
112 } | 110 } |
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_jstring, |
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 std::string url_string( |
122 base::android::ConvertJavaStringToUTF8(env, url_jstring)); | |
mmenke
2014/09/03 18:43:06
optional: Think it's cleaner to just do:
GURL url
mef
2014/09/03 18:56:04
Done. I haven't really used VLOGs either so far.
| |
124 | 123 |
125 VLOG(1) << "New chromium network request. URL:" << url_utf8; | 124 VLOG(1) << "New chromium network request. URL:" << url_string; |
126 | 125 |
127 GURL url(url_utf8); | 126 GURL url(url_string); |
128 | |
129 env->ReleaseStringUTFChars(url_string, url_utf8); | |
130 | 127 |
131 URLRequestAdapter* adapter = | 128 URLRequestAdapter* adapter = |
132 new URLRequestAdapter(context, | 129 new URLRequestAdapter(context, |
133 new JniURLRequestAdapterDelegate(env, object), | 130 new JniURLRequestAdapterDelegate(env, object), |
134 url, | 131 url, |
135 ConvertRequestPriority(priority)); | 132 ConvertRequestPriority(priority)); |
136 | 133 |
137 return reinterpret_cast<jlong>(adapter); | 134 return reinterpret_cast<jlong>(adapter); |
138 } | 135 } |
139 | 136 |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
387 | 384 |
388 // Some implementations (notably HttpURLConnection) include a mapping for the | 385 // Some implementations (notably HttpURLConnection) include a mapping for the |
389 // null key; in HTTP's case, this maps to the HTTP status line. | 386 // null key; in HTTP's case, this maps to the HTTP status line. |
390 ScopedJavaLocalRef<jstring> status_line = | 387 ScopedJavaLocalRef<jstring> status_line = |
391 ConvertUTF8ToJavaString(env, headers->GetStatusLine()); | 388 ConvertUTF8ToJavaString(env, headers->GetStatusLine()); |
392 Java_ChromiumUrlRequest_onAppendResponseHeader( | 389 Java_ChromiumUrlRequest_onAppendResponseHeader( |
393 env, object, headersMap, NULL, status_line.Release()); | 390 env, object, headersMap, NULL, status_line.Release()); |
394 } | 391 } |
395 | 392 |
396 } // namespace cronet | 393 } // namespace cronet |
OLD | NEW |