diff options
author | mmenke@chromium.org <mmenke@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-07 14:05:46 +0000 |
---|---|---|
committer | mmenke@chromium.org <mmenke@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-07 14:05:46 +0000 |
commit | 847aaab8e8dfd869c620e7fa0772562ca46f52af (patch) | |
tree | 4b3d4cc054aaeafc2ceb4abda5457f09e59abf59 /url | |
parent | e83140a012c770fe4ac438ddc42d2095a982d220 (diff) | |
download | chromium_src-847aaab8e8dfd869c620e7fa0772562ca46f52af.zip chromium_src-847aaab8e8dfd869c620e7fa0772562ca46f52af.tar.gz chromium_src-847aaab8e8dfd869c620e7fa0772562ca46f52af.tar.bz2 |
Make it possible to build url/ without ICU on android.
This is needed to reduce binary size of net/ when build as a
library.
BUG=362608
Review URL: https://codereview.chromium.org/257673002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@268740 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'url')
-rw-r--r-- | url/BUILD.gn | 43 | ||||
-rw-r--r-- | url/DEPS | 13 | ||||
-rw-r--r-- | url/android/java/src/org/chromium/url/IDNStringUtil.java | 33 | ||||
-rw-r--r-- | url/android/url_jni_registrar.cc | 24 | ||||
-rw-r--r-- | url/android/url_jni_registrar.h | 21 | ||||
-rw-r--r-- | url/url.gyp | 62 | ||||
-rw-r--r-- | url/url_canon_icu_alternatives_android.cc | 41 | ||||
-rw-r--r-- | url/url_canon_icu_alternatives_android.h | 18 | ||||
-rw-r--r-- | url/url_canon_icu_unittest.cc | 167 | ||||
-rw-r--r-- | url/url_canon_unittest.cc | 119 | ||||
-rw-r--r-- | url/url_srcs.gypi | 2 |
11 files changed, 435 insertions, 108 deletions
diff --git a/url/BUILD.gn b/url/BUILD.gn index 6445bfb..faf8dd8 100644 --- a/url/BUILD.gn +++ b/url/BUILD.gn @@ -2,12 +2,26 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. +declare_args() { + # Switches to using platform functions instead of ICU on Android. + use_icu_alternatives_on_android = false +} + +# Sets the USE_ICU_ALTERNATIVES_ON_ANDROID define based on the build flag. +config("url_icu_config") { + if (use_icu_alternatives_on_android) { + defines = [ "USE_ICU_ALTERNATIVES_ON_ANDROID=1" ] + } +} + component("url") { if (is_win) { # Don't conflict with Windows' "url.dll". output_name = "url_lib" } sources = [ + "android/url_jni_registrar.cc", + "android/url_jni_registrar.h", "gurl.cc", "gurl.h", "third_party/mozilla/url_parse.cc", @@ -42,6 +56,8 @@ component("url") { defines = [ "URL_IMPLEMENTATION" ] + configs += [ ":url_icu_config" ] + # if (is_win) { # TODO(jschuh): crbug.com/167187 fix size_t to int truncations. # 'msvs_disabled_warnings': [ 4267, ] @@ -52,6 +68,22 @@ component("url") { "//third_party/icu:icudata", "//third_party/icu", ] + + if (use_icu_alternatives_on_android) { + sources -= [ + "url_canon_icu.cc", + "url_canon_icu.h", + ] + deps -= [ + "//third_party/icu:icudata", + "//third_party/icu", + ] + + sources += [ + "url_canon_icu_alternatives_android.cc", + "url_canon_icu_alternatives_android.h", + ] + } } # TODO(dpranke): crbug.com/360936. Get this to build and run on Android. @@ -59,6 +91,7 @@ if (!is_android) { test("url_unittests") { sources = [ "gurl_unittest.cc", + "url_canon_icu_unittest.cc", "url_canon_unittest.cc", "url_parse_unittest.cc", "url_test_utils.h", @@ -79,10 +112,18 @@ if (!is_android) { deps = [ ":url", - "//base:i18n", "//base/test:run_all_unittests", "//testing/gtest", "//third_party/icu:icuuc", ] + + if (use_icu_alternatives_on_android) { + sources -= [ + "url_canon_icu_unittest.cc", + ] + deps -= [ + "//third_party/icu:icuuc", + ] + } } } diff --git a/url/DEPS b/url/DEPS new file mode 100644 index 0000000..9643291 --- /dev/null +++ b/url/DEPS @@ -0,0 +1,13 @@ +include_rules = [ + "+jni", + + # Limit files that can depend on icu. + "-base/i18n", + "-third_party/icu", +] + +specific_include_rules = { + "url_canon_icu(\.cc|_unittest\.cc)": [ + "+third_party/icu", + ], +} diff --git a/url/android/java/src/org/chromium/url/IDNStringUtil.java b/url/android/java/src/org/chromium/url/IDNStringUtil.java new file mode 100644 index 0000000..32000fd --- /dev/null +++ b/url/android/java/src/org/chromium/url/IDNStringUtil.java @@ -0,0 +1,33 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package org.chromium.url; + +import org.chromium.base.CalledByNative; +import org.chromium.base.JNINamespace; + +import java.net.IDN; + +/** + * This class is used to convert unicode IDN domain names to ASCII, when not + * building with ICU. + */ +@JNINamespace("url::android") +public class IDNStringUtil { + /** + * Attempts to convert a Unicode string to an ASCII string using IDN rules. + * As of May 2014, the underlying Java function IDNA2003. + * @param src String to convert. + * @return: String containing only ASCII characters on success, null on + * failure. + */ + @CalledByNative + private static String idnToASCII(String src) { + try { + return IDN.toASCII(src, IDN.USE_STD3_ASCII_RULES); + } catch (Exception e) { + return null; + } + } +}
\ No newline at end of file diff --git a/url/android/url_jni_registrar.cc b/url/android/url_jni_registrar.cc new file mode 100644 index 0000000..82a6e1b --- /dev/null +++ b/url/android/url_jni_registrar.cc @@ -0,0 +1,24 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "url/android/url_jni_registrar.h" + +#ifdef USE_ICU_ALTERNATIVES_ON_ANDROID +#include "url/url_canon_icu_alternatives_android.h" +#endif + +namespace url { +namespace android { + +bool RegisterJni(JNIEnv* env) { +#ifdef USE_ICU_ALTERNATIVES_ON_ANDROID + return RegisterIcuAlternativesJni(env); +#endif + + // Do nothing if USE_ICU_ALTERNATIVES_ON_ANDROID is not defined. + return true; +} + +} // namespace android +} // namespace url diff --git a/url/android/url_jni_registrar.h b/url/android/url_jni_registrar.h new file mode 100644 index 0000000..8fe7ded --- /dev/null +++ b/url/android/url_jni_registrar.h @@ -0,0 +1,21 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef URL_ANDROID_URL_JNI_REGISTRAR_H_ +#define URL_ANDROID_URL_JNI_REGISTRAR_H_ + +#include <jni.h> + +#include "url/url_export.h" + +namespace url { +namespace android { + +// Register all JNI bindings necessary for url. +URL_EXPORT bool RegisterJni(JNIEnv* env); + +} // namespace android +} // namespace url + +#endif // URL_ANDROID_URL_JNI_REGISTRAR_H_ diff --git a/url/url.gyp b/url/url.gyp index 93bbee2..d1c3bf1 100644 --- a/url/url.gyp +++ b/url/url.gyp @@ -33,6 +33,28 @@ 'defines': [ 'URL_IMPLEMENTATION', ], + 'conditions': [ + ['use_icu_alternatives_on_android==1', { + 'sources!': [ + 'url_canon_icu.cc', + 'url_canon_icu.h', + ], + 'dependencies!': [ + '../third_party/icu/icu.gyp:icui18n', + '../third_party/icu/icu.gyp:icuuc', + ], + }], + ['use_icu_alternatives_on_android==1 and OS=="android"', { + 'dependencies': [ + 'url_java', + 'url_jni_headers', + ], + 'sources': [ + 'url_canon_icu_alternatives_android.cc', + 'url_canon_icu_alternatives_android.h', + ], + }], + ], # TODO(jschuh): crbug.com/167187 fix size_t to int truncations. 'msvs_disabled_warnings': [4267, ], }, @@ -40,7 +62,6 @@ 'target_name': 'url_unittests', 'type': 'executable', 'dependencies': [ - '../base/base.gyp:base_i18n', '../base/base.gyp:run_all_unittests', '../testing/gtest.gyp:gtest', '../third_party/icu/icu.gyp:icuuc', @@ -49,6 +70,7 @@ 'sources': [ 'gurl_unittest.cc', 'origin_unittest.cc', + 'url_canon_icu_unittest.cc', 'url_canon_unittest.cc', 'url_parse_unittest.cc', 'url_test_utils.h', @@ -63,9 +85,47 @@ ], } ], + ['use_icu_alternatives_on_android==1', + { + 'sources!': [ + 'url_canon_icu_unittest.cc', + ], + 'dependencies!': [ + '../third_party/icu/icu.gyp:icuuc', + ], + } + ], ], # TODO(jschuh): crbug.com/167187 fix size_t to int truncations. 'msvs_disabled_warnings': [4267, ], }, ], + 'conditions': [ + ['use_icu_alternatives_on_android==1 and OS=="android"', { + 'targets': [ + { + 'target_name': 'url_jni_headers', + 'type': 'none', + 'sources': [ + 'android/java/src/org/chromium/url/IDNStringUtil.java' + ], + 'variables': { + 'jni_gen_package': 'url', + }, + 'includes': [ '../build/jni_generator.gypi' ], + }, + { + 'target_name': 'url_java', + 'type': 'none', + 'variables': { + 'java_in_dir': '../url/android/java', + }, + 'dependencies': [ + '../base/base.gyp:base', + ], + 'includes': [ '../build/java.gypi' ], + }, + ], + }], + ], } diff --git a/url/url_canon_icu_alternatives_android.cc b/url/url_canon_icu_alternatives_android.cc new file mode 100644 index 0000000..f43efce --- /dev/null +++ b/url/url_canon_icu_alternatives_android.cc @@ -0,0 +1,41 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include <string.h> + +#include "base/android/jni_android.h" +#include "base/android/jni_string.h" +#include "base/strings/string16.h" +#include "base/strings/string_piece.h" +#include "jni/IDNStringUtil_jni.h" +#include "url/url_canon_internal.h" + +namespace url { + +// This uses the JDK's conversion function, which uses IDNA 2003, unlike the +// ICU implementation. +bool IDNToASCII(const base::char16* src, int src_len, CanonOutputW* output) { + DCHECK_EQ(0, output->length()); // Output buffer is assumed empty. + + JNIEnv* env = base::android::AttachCurrentThread(); + base::android::ScopedJavaLocalRef<jstring> java_src = + base::android::ConvertUTF16ToJavaString( + env, base::StringPiece16(src, src_len)); + ScopedJavaLocalRef<jstring> java_result = + android::Java_IDNStringUtil_idnToASCII(env, java_src.obj()); + // NULL indicates failure. + if (java_result.is_null()) + return false; + + base::string16 utf16_result = + base::android::ConvertJavaStringToUTF16(java_result); + output->Append(utf16_result.data(), static_cast<int>(utf16_result.size())); + return true; +} + +bool RegisterIcuAlternativesJni(JNIEnv* env) { + return android::RegisterNativesImpl(env); +} + +} // namespace url diff --git a/url/url_canon_icu_alternatives_android.h b/url/url_canon_icu_alternatives_android.h new file mode 100644 index 0000000..67306db --- /dev/null +++ b/url/url_canon_icu_alternatives_android.h @@ -0,0 +1,18 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef URL_URL_CANON_ICU_ALTERNATIVES_ANDROID_H_ +#define URL_URL_CANON_ICU_ALTERNATIVES_ANDROID_H_ + +#include <jni.h> + +namespace url { + +// Explicitly register static JNI functions needed when not using ICU. +bool RegisterIcuAlternativesJni(JNIEnv* env); + +} // namespace url + +#endif // URL_URL_CANON_ICU_ALTERNATIVES_ANDROID_H_ + diff --git a/url/url_canon_icu_unittest.cc b/url/url_canon_icu_unittest.cc new file mode 100644 index 0000000..b28c30a --- /dev/null +++ b/url/url_canon_icu_unittest.cc @@ -0,0 +1,167 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "base/macros.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "third_party/icu/source/common/unicode/ucnv.h" +#include "url/url_canon.h" +#include "url/url_canon_icu.h" +#include "url/url_canon_stdstring.h" +#include "url/url_test_utils.h" + +// Some implementations of base/basictypes.h may define ARRAYSIZE. +// If it's not defined, we define it to the ARRAYSIZE_UNSAFE macro +// which is in our version of basictypes.h. +#ifndef ARRAYSIZE +#define ARRAYSIZE ARRAYSIZE_UNSAFE +#endif + +namespace url { + +using test_utils::WStringToUTF16; + +namespace { + +// Wrapper around a UConverter object that managers creation and destruction. +class UConvScoper { + public: + explicit UConvScoper(const char* charset_name) { + UErrorCode err = U_ZERO_ERROR; + converter_ = ucnv_open(charset_name, &err); + } + + ~UConvScoper() { + if (converter_) + ucnv_close(converter_); + } + + // Returns the converter object, may be NULL. + UConverter* converter() const { return converter_; } + + private: + UConverter* converter_; +}; + +TEST(URLCanonIcuTest, ICUCharsetConverter) { + struct ICUCase { + const wchar_t* input; + const char* encoding; + const char* expected; + } icu_cases[] = { + // UTF-8. + {L"Hello, world", "utf-8", "Hello, world"}, + {L"\x4f60\x597d", "utf-8", "\xe4\xbd\xa0\xe5\xa5\xbd"}, + // Non-BMP UTF-8. + {L"!\xd800\xdf00!", "utf-8", "!\xf0\x90\x8c\x80!"}, + // Big5 + {L"\x4f60\x597d", "big5", "\xa7\x41\xa6\x6e"}, + // Unrepresentable character in the destination set. + {L"hello\x4f60\x06de\x597dworld", "big5", + "hello\xa7\x41%26%231758%3B\xa6\x6eworld"}, + }; + + for (size_t i = 0; i < ARRAYSIZE(icu_cases); i++) { + UConvScoper conv(icu_cases[i].encoding); + ASSERT_TRUE(conv.converter() != NULL); + ICUCharsetConverter converter(conv.converter()); + + std::string str; + StdStringCanonOutput output(&str); + + base::string16 input_str(WStringToUTF16(icu_cases[i].input)); + int input_len = static_cast<int>(input_str.length()); + converter.ConvertFromUTF16(input_str.c_str(), input_len, &output); + output.Complete(); + + EXPECT_STREQ(icu_cases[i].expected, str.c_str()); + } + + // Test string sizes around the resize boundary for the output to make sure + // the converter resizes as needed. + const int static_size = 16; + UConvScoper conv("utf-8"); + ASSERT_TRUE(conv.converter()); + ICUCharsetConverter converter(conv.converter()); + for (int i = static_size - 2; i <= static_size + 2; i++) { + // Make a string with the appropriate length. + base::string16 input; + for (int ch = 0; ch < i; ch++) + input.push_back('a'); + + RawCanonOutput<static_size> output; + converter.ConvertFromUTF16(input.c_str(), static_cast<int>(input.length()), + &output); + EXPECT_EQ(input.length(), static_cast<size_t>(output.length())); + } +} + +TEST(URLCanonIcuTest, QueryWithConverter) { + struct QueryCase { + const char* input8; + const wchar_t* input16; + const char* encoding; + const char* expected; + } query_cases[] = { + // Regular ASCII case in some different encodings. + {"foo=bar", L"foo=bar", "utf-8", "?foo=bar"}, + {"foo=bar", L"foo=bar", "shift_jis", "?foo=bar"}, + {"foo=bar", L"foo=bar", "gb2312", "?foo=bar"}, + // Chinese input/output + {"q=\xe4\xbd\xa0\xe5\xa5\xbd", L"q=\x4f60\x597d", "gb2312", + "?q=%C4%E3%BA%C3"}, + {"q=\xe4\xbd\xa0\xe5\xa5\xbd", L"q=\x4f60\x597d", "big5", "?q=%A7A%A6n"}, + // Unencodable character in the destination character set should be + // escaped. The escape sequence unescapes to be the entity name: + // "?q=你" + {"q=Chinese\xef\xbc\xa7", L"q=Chinese\xff27", "iso-8859-1", + "?q=Chinese%26%2365319%3B"}, + }; + + for (size_t i = 0; i < ARRAYSIZE(query_cases); i++) { + Component out_comp; + + UConvScoper conv(query_cases[i].encoding); + ASSERT_TRUE(!query_cases[i].encoding || conv.converter()); + ICUCharsetConverter converter(conv.converter()); + + if (query_cases[i].input8) { + int len = static_cast<int>(strlen(query_cases[i].input8)); + Component in_comp(0, len); + std::string out_str; + + StdStringCanonOutput output(&out_str); + CanonicalizeQuery(query_cases[i].input8, in_comp, &converter, &output, + &out_comp); + output.Complete(); + + EXPECT_EQ(query_cases[i].expected, out_str); + } + + if (query_cases[i].input16) { + base::string16 input16(WStringToUTF16(query_cases[i].input16)); + int len = static_cast<int>(input16.length()); + Component in_comp(0, len); + std::string out_str; + + StdStringCanonOutput output(&out_str); + CanonicalizeQuery(input16.c_str(), in_comp, &converter, &output, + &out_comp); + output.Complete(); + + EXPECT_EQ(query_cases[i].expected, out_str); + } + } + + // Extra test for input with embedded NULL; + std::string out_str; + StdStringCanonOutput output(&out_str); + Component out_comp; + CanonicalizeQuery("a \x00z\x01", Component(0, 5), NULL, &output, &out_comp); + output.Complete(); + EXPECT_EQ("?a%20%00z%01", out_str); +} + +} // namespace + +} // namespace url diff --git a/url/url_canon_unittest.cc b/url/url_canon_unittest.cc index 55f9608..9a766e3 100644 --- a/url/url_canon_unittest.cc +++ b/url/url_canon_unittest.cc @@ -4,10 +4,9 @@ #include <errno.h> +#include "base/macros.h" #include "testing/gtest/include/gtest/gtest.h" -#include "third_party/icu/source/common/unicode/ucnv.h" #include "url/url_canon.h" -#include "url/url_canon_icu.h" #include "url/url_canon_internal.h" #include "url/url_canon_stdstring.h" #include "url/url_parse.h" @@ -84,26 +83,6 @@ struct ReplaceCase { const char* expected; }; -// Wrapper around a UConverter object that managers creation and destruction. -class UConvScoper { - public: - explicit UConvScoper(const char* charset_name) { - UErrorCode err = U_ZERO_ERROR; - converter_ = ucnv_open(charset_name, &err); - } - - ~UConvScoper() { - if (converter_) - ucnv_close(converter_); - } - - // Returns the converter object, may be NULL. - UConverter* converter() const { return converter_; } - - private: - UConverter* converter_; -}; - // Magic string used in the replacements code that tells SetupReplComp to // call the clear function. const char kDeleteComp[] = "|"; @@ -244,58 +223,6 @@ TEST(URLCanonTest, UTF) { } } -TEST(URLCanonTest, ICUCharsetConverter) { - struct ICUCase { - const wchar_t* input; - const char* encoding; - const char* expected; - } icu_cases[] = { - // UTF-8. - {L"Hello, world", "utf-8", "Hello, world"}, - {L"\x4f60\x597d", "utf-8", "\xe4\xbd\xa0\xe5\xa5\xbd"}, - // Non-BMP UTF-8. - {L"!\xd800\xdf00!", "utf-8", "!\xf0\x90\x8c\x80!"}, - // Big5 - {L"\x4f60\x597d", "big5", "\xa7\x41\xa6\x6e"}, - // Unrepresentable character in the destination set. - {L"hello\x4f60\x06de\x597dworld", "big5", "hello\xa7\x41%26%231758%3B\xa6\x6eworld"}, - }; - - for (size_t i = 0; i < ARRAYSIZE(icu_cases); i++) { - UConvScoper conv(icu_cases[i].encoding); - ASSERT_TRUE(conv.converter() != NULL); - ICUCharsetConverter converter(conv.converter()); - - std::string str; - StdStringCanonOutput output(&str); - - base::string16 input_str(WStringToUTF16(icu_cases[i].input)); - int input_len = static_cast<int>(input_str.length()); - converter.ConvertFromUTF16(input_str.c_str(), input_len, &output); - output.Complete(); - - EXPECT_STREQ(icu_cases[i].expected, str.c_str()); - } - - // Test string sizes around the resize boundary for the output to make sure - // the converter resizes as needed. - const int static_size = 16; - UConvScoper conv("utf-8"); - ASSERT_TRUE(conv.converter()); - ICUCharsetConverter converter(conv.converter()); - for (int i = static_size - 2; i <= static_size + 2; i++) { - // Make a string with the appropriate length. - base::string16 input; - for (int ch = 0; ch < i; ch++) - input.push_back('a'); - - RawCanonOutput<static_size> output; - converter.ConvertFromUTF16(input.c_str(), static_cast<int>(input.length()), - &output); - EXPECT_EQ(input.length(), static_cast<size_t>(output.length())); - } -} - TEST(URLCanonTest, Scheme) { // Here, we're mostly testing that unusual characters are handled properly. // The canonicalizer doesn't do any parsing or whitespace detection. It will @@ -1198,57 +1125,38 @@ TEST(URLCanonTest, Query) { struct QueryCase { const char* input8; const wchar_t* input16; - const char* encoding; const char* expected; } query_cases[] = { - // Regular ASCII case in some different encodings. - {"foo=bar", L"foo=bar", NULL, "?foo=bar"}, - {"foo=bar", L"foo=bar", "utf-8", "?foo=bar"}, - {"foo=bar", L"foo=bar", "shift_jis", "?foo=bar"}, - {"foo=bar", L"foo=bar", "gb2312", "?foo=bar"}, + // Regular ASCII case. + {"foo=bar", L"foo=bar", "?foo=bar"}, // Allow question marks in the query without escaping - {"as?df", L"as?df", NULL, "?as?df"}, + {"as?df", L"as?df", "?as?df"}, // Always escape '#' since it would mark the ref. - {"as#df", L"as#df", NULL, "?as%23df"}, + {"as#df", L"as#df", "?as%23df"}, // Escape some questionable 8-bit characters, but never unescape. - {"\x02hello\x7f bye", L"\x02hello\x7f bye", NULL, "?%02hello%7F%20bye"}, - {"%40%41123", L"%40%41123", NULL, "?%40%41123"}, + {"\x02hello\x7f bye", L"\x02hello\x7f bye", "?%02hello%7F%20bye"}, + {"%40%41123", L"%40%41123", "?%40%41123"}, // Chinese input/output - {"q=\xe4\xbd\xa0\xe5\xa5\xbd", L"q=\x4f60\x597d", NULL, "?q=%E4%BD%A0%E5%A5%BD"}, - {"q=\xe4\xbd\xa0\xe5\xa5\xbd", L"q=\x4f60\x597d", "gb2312", "?q=%C4%E3%BA%C3"}, - {"q=\xe4\xbd\xa0\xe5\xa5\xbd", L"q=\x4f60\x597d", "big5", "?q=%A7A%A6n"}, - // Unencodable character in the destination character set should be - // escaped. The escape sequence unescapes to be the entity name: - // "?q=你" - {"q=Chinese\xef\xbc\xa7", L"q=Chinese\xff27", "iso-8859-1", "?q=Chinese%26%2365319%3B"}, + {"q=\xe4\xbd\xa0\xe5\xa5\xbd", L"q=\x4f60\x597d", "?q=%E4%BD%A0%E5%A5%BD"}, // Invalid UTF-8/16 input should be replaced with invalid characters. - {"q=\xed\xed", L"q=\xd800\xd800", NULL, "?q=%EF%BF%BD%EF%BF%BD"}, + {"q=\xed\xed", L"q=\xd800\xd800", "?q=%EF%BF%BD%EF%BF%BD"}, // Don't allow < or > because sometimes they are used for XSS if the // URL is echoed in content. Firefox does this, IE doesn't. - {"q=<asdf>", L"q=<asdf>", NULL, "?q=%3Casdf%3E"}, + {"q=<asdf>", L"q=<asdf>", "?q=%3Casdf%3E"}, // Escape double quotemarks in the query. - {"q=\"asdf\"", L"q=\"asdf\"", NULL, "?q=%22asdf%22"}, + {"q=\"asdf\"", L"q=\"asdf\"", "?q=%22asdf%22"}, }; for (size_t i = 0; i < ARRAYSIZE(query_cases); i++) { Component out_comp; - UConvScoper conv(query_cases[i].encoding); - ASSERT_TRUE(!query_cases[i].encoding || conv.converter()); - ICUCharsetConverter converter(conv.converter()); - - // Map NULL to a NULL converter pointer. - ICUCharsetConverter* conv_pointer = &converter; - if (!query_cases[i].encoding) - conv_pointer = NULL; - if (query_cases[i].input8) { int len = static_cast<int>(strlen(query_cases[i].input8)); Component in_comp(0, len); std::string out_str; StdStringCanonOutput output(&out_str); - CanonicalizeQuery(query_cases[i].input8, in_comp, conv_pointer, &output, + CanonicalizeQuery(query_cases[i].input8, in_comp, NULL, &output, &out_comp); output.Complete(); @@ -1262,8 +1170,7 @@ TEST(URLCanonTest, Query) { std::string out_str; StdStringCanonOutput output(&out_str); - CanonicalizeQuery(input16.c_str(), in_comp, conv_pointer, &output, - &out_comp); + CanonicalizeQuery(input16.c_str(), in_comp, NULL, &output, &out_comp); output.Complete(); EXPECT_EQ(query_cases[i].expected, out_str); diff --git a/url/url_srcs.gypi b/url/url_srcs.gypi index 3114620..e8fa82e 100644 --- a/url/url_srcs.gypi +++ b/url/url_srcs.gypi @@ -5,6 +5,8 @@ { 'variables': { 'gurl_sources': [ + 'android/url_jni_registrar.cc', + 'android/url_jni_registrar.h', 'gurl.cc', 'gurl.h', 'origin.cc', |