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 "base/android/jni_android.h" | 5 #include "base/android/jni_android.h" |
6 #include "base/android/jni_string.h" | 6 #include "base/android/jni_string.h" |
7 #include "base/strings/string16.h" | 7 #include "base/strings/string16.h" |
8 #include "base/strings/string_piece.h" | 8 #include "base/strings/string_piece.h" |
9 #include "jni/NetStringUtil_jni.h" | 9 #include "jni/NetStringUtil_jni.h" |
10 #include "net/base/net_string_util.h" | 10 #include "net/base/net_string_util.h" |
11 | 11 |
| 12 using base::android::ScopedJavaLocalRef; |
| 13 |
12 namespace net { | 14 namespace net { |
13 | 15 |
14 namespace { | 16 namespace { |
15 | 17 |
16 // Attempts to convert |text| encoded in |charset| to a jstring (Java unicode | 18 // Attempts to convert |text| encoded in |charset| to a jstring (Java unicode |
17 // string). Returns the result jstring, or NULL on failure. | 19 // string). Returns the result jstring, or NULL on failure. |
18 ScopedJavaLocalRef<jstring> ConvertToJstring(const std::string& text, | 20 ScopedJavaLocalRef<jstring> ConvertToJstring(const std::string& text, |
19 const char* charset) { | 21 const char* charset) { |
20 JNIEnv* env = base::android::AttachCurrentThread(); | 22 JNIEnv* env = base::android::AttachCurrentThread(); |
21 ScopedJavaLocalRef<jobject> java_byte_buffer( | 23 ScopedJavaLocalRef<jobject> java_byte_buffer( |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 output->clear(); | 107 output->clear(); |
106 ScopedJavaLocalRef<jstring> java_result = | 108 ScopedJavaLocalRef<jstring> java_result = |
107 ConvertToJstringWithSubstitutions(text, charset); | 109 ConvertToJstringWithSubstitutions(text, charset); |
108 if (java_result.is_null()) | 110 if (java_result.is_null()) |
109 return false; | 111 return false; |
110 *output = base::android::ConvertJavaStringToUTF16(java_result); | 112 *output = base::android::ConvertJavaStringToUTF16(java_result); |
111 return true; | 113 return true; |
112 } | 114 } |
113 | 115 |
114 } // namespace net | 116 } // namespace net |
OLD | NEW |