OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include <string.h> |
| 6 |
| 7 #include "base/android/jni_android.h" |
| 8 #include "base/android/jni_string.h" |
| 9 #include "base/strings/string16.h" |
| 10 #include "base/strings/string_piece.h" |
| 11 #include "jni/IDNStringUtil_jni.h" |
| 12 #include "url/url_canon_internal.h" |
| 13 |
| 14 namespace url { |
| 15 |
| 16 bool IDNToASCII(const base::char16* src, int src_len, CanonOutputW* output) { |
| 17 DCHECK_EQ(0, output->length()); // Output buffer is assumed empty. |
| 18 |
| 19 // An empty string is returned from Java both in the case of error and when |
| 20 // the input string is of length 0. Handle the 0-length input case here to |
| 21 // avoid any confusion. |
| 22 if (src_len == 0) |
| 23 return true; |
| 24 |
| 25 JNIEnv* env = base::android::AttachCurrentThread(); |
| 26 base::android::ScopedJavaLocalRef<jstring> java_src = |
| 27 base::android::ConvertUTF16ToJavaString( |
| 28 env, base::StringPiece16(src, src_len)); |
| 29 ScopedJavaLocalRef<jstring> java_result = |
| 30 android::Java_IDNStringUtil_idnToASCII(env, java_src.obj()); |
| 31 base::string16 utf16_result = |
| 32 base::android::ConvertJavaStringToUTF16(java_result); |
| 33 output->Append(utf16_result.data(), static_cast<int>(utf16_result.size())); |
| 34 return output->length() != 0; |
| 35 } |
| 36 |
| 37 bool RegisterIcuAlternativesJni(JNIEnv* env) { |
| 38 return android::RegisterNativesImpl(env); |
| 39 } |
| 40 |
| 41 } // namespace url |
OLD | NEW |