diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2019-02-13 16:23:34 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2019-02-14 10:37:21 +0000 |
commit | 38a9a29f4f9436cace7f0e7abf9c586057df8a4e (patch) | |
tree | c4e8c458dc595bc0ddb435708fa2229edfd00bd4 /chromium/url | |
parent | e684a3455bcc29a6e3e66a004e352dea4e1141e7 (diff) | |
download | qtwebengine-chromium-38a9a29f4f9436cace7f0e7abf9c586057df8a4e.tar.gz |
BASELINE: Update Chromium to 73.0.3683.37
Change-Id: I08c9af2948b645f671e5d933aca1f7a90ea372f2
Reviewed-by: Michael BrĂ¼ning <michael.bruning@qt.io>
Diffstat (limited to 'chromium/url')
27 files changed, 1136 insertions, 684 deletions
diff --git a/chromium/url/BUILD.gn b/chromium/url/BUILD.gn index 605ee82cad3..e7a43342929 100644 --- a/chromium/url/BUILD.gn +++ b/chromium/url/BUILD.gn @@ -3,16 +3,16 @@ # found in the LICENSE file. import("//build/buildflag_header.gni") -import("//testing/test.gni") import("//testing/libfuzzer/fuzzer_test.gni") +import("//testing/test.gni") import("features.gni") if (is_android) { import("//build/config/android/rules.gni") } -buildflag_header("url_features") { - header = "url_features.h" +buildflag_header("buildflags") { + header = "buildflags.h" flags = [ "USE_PLATFORM_ICU_ALTERNATIVES=$use_platform_icu_alternatives" ] } @@ -47,7 +47,6 @@ component("url") { "url_canon_stdurl.cc", "url_constants.cc", "url_constants.h", - "url_export.h", "url_file.h", "url_parse_file.cc", "url_parse_internal.h", @@ -56,12 +55,7 @@ component("url") { "url_util_internal.h", ] - defines = [ "URL_IMPLEMENTATION" ] - - configs += [ - # TODO(jschuh): crbug.com/167187 fix size_t to int truncations. - "//build/config/compiler:no_size_t_to_int_warning", - ] + defines = [ "IS_URL_IMPL" ] deps = [ "//base", @@ -79,7 +73,7 @@ component("url") { if (is_android) { sources += [ "url_idna_icu_alternatives_android.cc" ] deps += [ - ":url_features", + ":buildflags", ":url_java", ":url_jni_headers", "//base", @@ -165,9 +159,6 @@ test("url_unittests") { deps += [ "//third_party/icu:icuuc" ] } - # TODO(jschuh): crbug.com/167187 fix size_t to int truncations. - configs += [ "//build/config/compiler:no_size_t_to_int_warning" ] - if (!is_ios) { deps += [ "//mojo/core/embedder", @@ -176,6 +167,20 @@ test("url_unittests") { } } +test("url_perftests") { + sources = [ + "run_all_perftests.cc", + "url_parse_perftest.cc", + ] + + deps = [ + ":url", + "//base", + "//base/test:test_support", + "//testing/gtest", + ] +} + fuzzer_test("gurl_fuzzer") { sources = [ "gurl_fuzzer.cc", diff --git a/chromium/url/gurl.h b/chromium/url/gurl.h index bd1b93a80b8..5bfa17f85bc 100644 --- a/chromium/url/gurl.h +++ b/chromium/url/gurl.h @@ -11,6 +11,7 @@ #include <memory> #include <string> +#include "base/component_export.h" #include "base/debug/alias.h" #include "base/strings/string16.h" #include "base/strings/string_piece.h" @@ -18,7 +19,6 @@ #include "url/url_canon.h" #include "url/url_canon_stdstring.h" #include "url/url_constants.h" -#include "url/url_export.h" // Represents a URL. GURL is Google's URL parsing library. // @@ -43,7 +43,7 @@ // path that contains a literal '#'. Using string concatenation will generate a // URL with a truncated path and a reference fragment, while ReplaceComponents // will know to escape this and produce the desired result. -class URL_EXPORT GURL { +class COMPONENT_EXPORT(URL) GURL { public: typedef url::StringPieceReplacements<std::string> Replacements; typedef url::StringPieceReplacements<base::string16> ReplacementsW; @@ -472,18 +472,23 @@ class URL_EXPORT GURL { }; // Stream operator so GURL can be used in assertion statements. -URL_EXPORT std::ostream& operator<<(std::ostream& out, const GURL& url); +COMPONENT_EXPORT(URL) +std::ostream& operator<<(std::ostream& out, const GURL& url); -URL_EXPORT bool operator==(const GURL& x, const GURL& y); -URL_EXPORT bool operator!=(const GURL& x, const GURL& y); +COMPONENT_EXPORT(URL) bool operator==(const GURL& x, const GURL& y); +COMPONENT_EXPORT(URL) bool operator!=(const GURL& x, const GURL& y); // Equality operator for comparing raw spec_. This should be used in place of // url == GURL(spec) where |spec| is known (i.e. constants). This is to prevent // needlessly re-parsing |spec| into a temporary GURL. -URL_EXPORT bool operator==(const GURL& x, const base::StringPiece& spec); -URL_EXPORT bool operator==(const base::StringPiece& spec, const GURL& x); -URL_EXPORT bool operator!=(const GURL& x, const base::StringPiece& spec); -URL_EXPORT bool operator!=(const base::StringPiece& spec, const GURL& x); +COMPONENT_EXPORT(URL) +bool operator==(const GURL& x, const base::StringPiece& spec); +COMPONENT_EXPORT(URL) +bool operator==(const base::StringPiece& spec, const GURL& x); +COMPONENT_EXPORT(URL) +bool operator!=(const GURL& x, const base::StringPiece& spec); +COMPONENT_EXPORT(URL) +bool operator!=(const base::StringPiece& spec, const GURL& x); // DEBUG_ALIAS_FOR_GURL(var_name, url) copies |url| into a new stack-allocated // variable named |<var_name>|. This helps ensure that the value of |url| gets diff --git a/chromium/url/gurl_unittest.cc b/chromium/url/gurl_unittest.cc index 6f876aee22a..caf5dd4e1b3 100644 --- a/chromium/url/gurl_unittest.cc +++ b/chromium/url/gurl_unittest.cc @@ -4,7 +4,7 @@ #include <stddef.h> -#include "base/macros.h" +#include "base/stl_util.h" #include "base/strings/utf_string_conversions.h" #include "testing/gtest/include/gtest/gtest.h" #include "url/gurl.h" @@ -234,7 +234,7 @@ TEST(GURLTest, IsValid) { "http:/path", "http:path", }; - for (size_t i = 0; i < arraysize(valid_cases); i++) { + for (size_t i = 0; i < base::size(valid_cases); i++) { EXPECT_TRUE(GURL(valid_cases[i]).is_valid()) << "Case: " << valid_cases[i]; } @@ -247,7 +247,7 @@ TEST(GURLTest, IsValid) { "://google.com", "path", }; - for (size_t i = 0; i < arraysize(invalid_cases); i++) { + for (size_t i = 0; i < base::size(invalid_cases); i++) { EXPECT_FALSE(GURL(invalid_cases[i]).is_valid()) << "Case: " << invalid_cases[i]; } @@ -306,7 +306,7 @@ TEST(GURLTest, Resolve) { {"filesystem:http://www.google.com/type/", "../foo.html", true, "filesystem:http://www.google.com/type/foo.html"}, }; - for (size_t i = 0; i < arraysize(resolve_cases); i++) { + for (size_t i = 0; i < base::size(resolve_cases); i++) { // 8-bit code path. GURL input(resolve_cases[i].base); GURL output = input.Resolve(resolve_cases[i].relative); @@ -343,7 +343,7 @@ TEST(GURLTest, GetOrigin) { {"blob:null/guid-goes-here", ""}, {"blob:http://origin/guid-goes-here", "" /* should be http://origin/ */}, }; - for (size_t i = 0; i < arraysize(cases); i++) { + for (size_t i = 0; i < base::size(cases); i++) { GURL url(cases[i].input); GURL origin = url.GetOrigin(); EXPECT_EQ(cases[i].expected, origin.spec()); @@ -366,7 +366,7 @@ TEST(GURLTest, GetAsReferrer) { {"file:///tmp/test.html", ""}, {"https://www.google.com", "https://www.google.com/"}, }; - for (size_t i = 0; i < arraysize(cases); i++) { + for (size_t i = 0; i < base::size(cases); i++) { GURL url(cases[i].input); GURL origin = url.GetAsReferrer(); EXPECT_EQ(cases[i].expected, origin.spec()); @@ -385,7 +385,7 @@ TEST(GURLTest, GetWithEmptyPath) { {"filesystem:file:///temporary/bar.html?baz=22", "filesystem:file:///temporary/"}, }; - for (size_t i = 0; i < arraysize(cases); i++) { + for (size_t i = 0; i < base::size(cases); i++) { GURL url(cases[i].input); GURL empty_path = url.GetWithEmptyPath(); EXPECT_EQ(cases[i].expected, empty_path.spec()); @@ -431,7 +431,7 @@ TEST(GURLTest, GetWithoutFilename) { {"foobar", ""}, }; - for (size_t i = 0; i < arraysize(cases); i++) { + for (size_t i = 0; i < base::size(cases); i++) { GURL url(cases[i].input); GURL without_filename = url.GetWithoutFilename(); EXPECT_EQ(cases[i].expected, without_filename.spec()) << i; @@ -473,7 +473,7 @@ TEST(GURLTest, Replacements) { "filesystem:http://www.google.com/foo/bar.html?foo#bar"}, }; - for (size_t i = 0; i < arraysize(replace_cases); i++) { + for (size_t i = 0; i < base::size(replace_cases); i++) { const ReplaceCase& cur = replace_cases[i]; GURL url(cur.base); GURL::Replacements repl; @@ -537,7 +537,7 @@ TEST(GURLTest, PathForRequest) { {"filesystem:http://www.google.com/temporary/foo/bar.html?query", "/foo/bar.html?query", "/temporary"}, }; - for (size_t i = 0; i < arraysize(cases); i++) { + for (size_t i = 0; i < base::size(cases); i++) { GURL url(cases[i].input); std::string path_request = url.PathForRequest(); EXPECT_EQ(cases[i].expected, path_request); @@ -585,7 +585,7 @@ TEST(GURLTest, EffectiveIntPort) { {"filesystem:file:///t/foo", PORT_UNSPECIFIED}, }; - for (size_t i = 0; i < arraysize(port_tests); i++) { + for (size_t i = 0; i < base::size(port_tests); i++) { GURL url(port_tests[i].spec); EXPECT_EQ(port_tests[i].expected_int_port, url.EffectiveIntPort()); } @@ -606,7 +606,7 @@ TEST(GURLTest, IPAddress) { {"some random input!", false}, }; - for (size_t i = 0; i < arraysize(ip_tests); i++) { + for (size_t i = 0; i < base::size(ip_tests); i++) { GURL url(ip_tests[i].spec); EXPECT_EQ(ip_tests[i].expected_ip, url.HostIsIPAddress()); } @@ -631,7 +631,7 @@ TEST(GURLTest, HostNoBrackets) { {"http://]/", "]", "]"}, {"", "", ""}, }; - for (size_t i = 0; i < arraysize(cases); i++) { + for (size_t i = 0; i < base::size(cases); i++) { GURL url(cases[i].input); EXPECT_EQ(cases[i].expected_host, url.host()); EXPECT_EQ(cases[i].expected_plainhost, url.HostNoBrackets()); diff --git a/chromium/url/ipc/url_param_traits_unittest.cc b/chromium/url/ipc/url_param_traits_unittest.cc index 16eeab0372f..0fbddc70c93 100644 --- a/chromium/url/ipc/url_param_traits_unittest.cc +++ b/chromium/url/ipc/url_param_traits_unittest.cc @@ -4,6 +4,7 @@ #include <string> +#include "base/stl_util.h" #include "ipc/ipc_message.h" #include "ipc/ipc_message_utils.h" #include "testing/gtest/include/gtest/gtest.h" @@ -17,7 +18,7 @@ TEST(IPCMessageTest, Serialize) { "http://user:pass@host.com:888/foo;bar?baz#nop", }; - for (size_t i = 0; i < arraysize(serialize_cases); i++) { + for (size_t i = 0; i < base::size(serialize_cases); i++) { GURL input(serialize_cases[i]); IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); IPC::ParamTraits<GURL>::Write(&msg, input); diff --git a/chromium/url/mojom/url_gurl_mojom_traits_unittest.cc b/chromium/url/mojom/url_gurl_mojom_traits_unittest.cc index a331ba2622b..d0f50a0c003 100644 --- a/chromium/url/mojom/url_gurl_mojom_traits_unittest.cc +++ b/chromium/url/mojom/url_gurl_mojom_traits_unittest.cc @@ -5,8 +5,8 @@ #include <utility> #include "base/logging.h" -#include "base/macros.h" #include "base/message_loop/message_loop.h" +#include "base/stl_util.h" #include "mojo/public/cpp/bindings/binding.h" #include "testing/gtest/include/gtest/gtest.h" #include "url/mojom/url_test.mojom.h" @@ -42,7 +42,7 @@ TEST(MojoGURLStructTraitsTest, Basic) { "http://www.google.com/", "http://user:pass@host.com:888/foo;bar?baz#nop", }; - for (size_t i = 0; i < arraysize(serialize_cases); i++) { + for (size_t i = 0; i < base::size(serialize_cases); i++) { GURL input(serialize_cases[i]); GURL output; EXPECT_TRUE(proxy->BounceUrl(input, &output)); diff --git a/chromium/url/origin.cc b/chromium/url/origin.cc index f6403f58b6d..916ad368404 100644 --- a/chromium/url/origin.cc +++ b/chromium/url/origin.cc @@ -52,7 +52,7 @@ Origin Origin::Create(const GURL& url) { } Origin Origin::Resolve(const GURL& url, const Origin& base_origin) { - if (url.IsAboutBlank()) + if (url.SchemeIs(kAboutScheme)) return base_origin; Origin result = Origin::Create(url); if (!result.opaque()) @@ -155,6 +155,78 @@ bool Origin::IsSameOriginWith(const Origin& other) const { return std::tie(tuple_, nonce_) == std::tie(other.tuple_, other.nonce_); } +bool Origin::CanBeDerivedFrom(const GURL& url) const { + DCHECK(url.is_valid()); + + // For "no access" schemes, blink's SecurityOrigin will always create an + // opaque unique one. However, about: scheme is also registered as such but + // does not behave this way, therefore exclude it from this check. + if (base::ContainsValue(url::GetNoAccessSchemes(), url.scheme()) && + !url.SchemeIs(kAboutScheme)) { + // If |this| is not opaque, definitely return false as the expectation + // is for opaque origin. + if (!opaque()) + return false; + + // And if it is unique opaque origin, it definitely is fine. But if there + // is a precursor stored, we should fall through to compare the tuples. + if (tuple_.IsInvalid()) + return true; + } + + SchemeHostPort url_tuple; + + // Optimization for the common, success case: Scheme/Host/Port match on the + // precursor, and the URL is standard. Opaqueness does not matter as a tuple + // origin can always create an opaque tuple origin. + if (url.IsStandard()) { + // Note: if extra copies of the scheme and host are undesirable, this check + // can be implemented using StringPiece comparisons, but it has to account + // explicitly checks on port numbers. + if (url.SchemeIsFileSystem()) { + url_tuple = SchemeHostPort(*url.inner_url()); + } else { + url_tuple = SchemeHostPort(url); + } + return url_tuple == tuple_; + + // Blob URLs still contain an inner origin, however it is not accessible + // through inner_url(), therefore it requires specific case to handle it. + } else if (url.SchemeIsBlob()) { + // If |this| doesn't contain any precursor information, it is an unique + // opaque origin. It is valid case, as any browser-initiated navigation + // to about:blank or data: URL will result in a document with such + // origin and it is valid for it to create blob: URLs. + if (tuple_.IsInvalid()) + return true; + + url_tuple = SchemeHostPort(GURL(url.GetContent())); + return url_tuple == tuple_; + } + + // At this point, the URL has non-standard scheme. + DCHECK(!url.IsStandard()); + + // All about: URLs (about:blank, about:srcdoc) inherit their origin from + // the context which navigated them, which means that they can be in any + // type of origin. + if (url.SchemeIs(kAboutScheme)) + return true; + + // All data: URLs commit in opaque origins, therefore |this| must be opaque + // if |url| has data: scheme. + if (url.SchemeIs(kDataScheme)) + return opaque(); + + // If |this| does not have valid precursor tuple, it is unique opaque origin, + // which is what we expect non-standard schemes to get. + if (tuple_.IsInvalid()) + return true; + + // However, when there is precursor present, the schemes must match. + return url.scheme() == tuple_.scheme(); +} + bool Origin::DomainIs(base::StringPiece canonical_domain) const { return !opaque() && url::DomainIs(tuple_.host(), canonical_domain); } diff --git a/chromium/url/origin.h b/chromium/url/origin.h index 894cb0bf4dd..08332541ab2 100644 --- a/chromium/url/origin.h +++ b/chromium/url/origin.h @@ -9,6 +9,7 @@ #include <string> +#include "base/component_export.h" #include "base/debug/alias.h" #include "base/optional.h" #include "base/strings/string16.h" @@ -20,7 +21,6 @@ #include "url/third_party/mozilla/url_parse.h" #include "url/url_canon.h" #include "url/url_constants.h" -#include "url/url_export.h" class GURL; @@ -117,7 +117,7 @@ class OriginDataView; // if (this.IsSameOriginWith(that)) { // // Amazingness goes here. // } -class URL_EXPORT Origin { +class COMPONENT_EXPORT(URL) Origin { public: // Creates an opaque Origin with a nonce that is different from all previously // existing origins. @@ -199,6 +199,10 @@ class URL_EXPORT Origin { return !IsSameOriginWith(other); } + // This method returns true for any |url| which if navigated to could result + // in an origin compatible with |this|. + bool CanBeDerivedFrom(const GURL& url) const; + // Get the scheme, host, and port from which this origin derives. For // a tuple Origin, this gives the same values as calling scheme(), host() // and port(). For an opaque Origin that was created by calling @@ -264,8 +268,8 @@ class URL_EXPORT Origin { friend struct ipc_fuzzer::FuzzTraits<Origin>; friend struct mojo::StructTraits<url::mojom::OriginDataView, url::Origin>; friend IPC::ParamTraits<url::Origin>; - friend URL_EXPORT std::ostream& operator<<(std::ostream& out, - const Origin& origin); + friend COMPONENT_EXPORT(URL) std::ostream& operator<<(std::ostream& out, + const Origin& origin); // Origin::Nonce is a wrapper around base::UnguessableToken that generates // the random value only when the value is first accessed. The lazy generation @@ -274,7 +278,7 @@ class URL_EXPORT Origin { // // TODO(nick): Should this optimization move into UnguessableToken, once it no // longer treats the Null case specially? - class URL_EXPORT Nonce { + class COMPONENT_EXPORT(URL) Nonce { public: // Creates a nonce to hold a newly-generated UnguessableToken. The actual // token value will be generated lazily. @@ -315,8 +319,8 @@ class URL_EXPORT Origin { // This needs to be friended within Origin as well, since Nonce is a private // nested class of Origin. - friend URL_EXPORT std::ostream& operator<<(std::ostream& out, - const Nonce& nonce); + friend COMPONENT_EXPORT(URL) std::ostream& operator<<(std::ostream& out, + const Nonce& nonce); // Creates an origin without sanity checking that the host is canonicalized. // This should only be used when converting between already normalized types, @@ -366,11 +370,12 @@ class URL_EXPORT Origin { }; // Pretty-printers for logging. These expose the internal state of the nonce. -URL_EXPORT std::ostream& operator<<(std::ostream& out, const Origin& origin); -URL_EXPORT std::ostream& operator<<(std::ostream& out, - const Origin::Nonce& origin); +COMPONENT_EXPORT(URL) +std::ostream& operator<<(std::ostream& out, const Origin& origin); +COMPONENT_EXPORT(URL) +std::ostream& operator<<(std::ostream& out, const Origin::Nonce& origin); -URL_EXPORT bool IsSameOriginWith(const GURL& a, const GURL& b); +COMPONENT_EXPORT(URL) bool IsSameOriginWith(const GURL& a, const GURL& b); // DEBUG_ALIAS_FOR_ORIGIN(var_name, origin) copies |origin| into a new // stack-allocated variable named |<var_name>|. This helps ensure that the diff --git a/chromium/url/origin_unittest.cc b/chromium/url/origin_unittest.cc index 5f889c09a14..36f2f5167e2 100644 --- a/chromium/url/origin_unittest.cc +++ b/chromium/url/origin_unittest.cc @@ -178,6 +178,7 @@ TEST_F(OriginTest, OpaqueOriginComparison) { EXPECT_LT(opaque_b, url::Origin::Create(GURL("http://www.google.com"))); EXPECT_EQ(opaque_b, url::Origin::Resolve(GURL("about:blank"), opaque_b)); + EXPECT_EQ(opaque_b, url::Origin::Resolve(GURL("about:srcdoc"), opaque_b)); EXPECT_EQ(opaque_b, url::Origin::Resolve(GURL("about:blank?hello#whee"), opaque_b)); @@ -668,4 +669,166 @@ TEST_F(OriginTest, NonStandardSchemeWithAndroidWebViewHack) { Shutdown(); } +TEST_F(OriginTest, CanBeDerivedFrom) { + Origin opaque_unique_origin = Origin(); + + Origin regular_origin = Origin::Create(GURL("https://a.com/")); + Origin opaque_precursor_origin = regular_origin.DeriveNewOpaqueOrigin(); + + Origin file_origin = Origin::Create(GURL("file:///foo/bar")); + Origin file_opaque_precursor_origin = file_origin.DeriveNewOpaqueOrigin(); + Origin file_host_origin = Origin::Create(GURL("file://a.com/foo/bar")); + Origin file_host_opaque_precursor_origin = + file_host_origin.DeriveNewOpaqueOrigin(); + + Origin non_standard_scheme_origin = + Origin::Create(GURL("non-standard-scheme:foo")); + Origin non_standard_opaque_precursor_origin = + non_standard_scheme_origin.DeriveNewOpaqueOrigin(); + + // Also, add new standard scheme that is local to the test. + AddStandardScheme("new-standard", SchemeType::SCHEME_WITH_HOST); + Origin new_standard_origin = Origin::Create(GURL("new-standard://host/")); + Origin new_standard_opaque_precursor_origin = + new_standard_origin.DeriveNewOpaqueOrigin(); + + // No access schemes always get unique opaque origins. + Origin no_access_origin = + Origin::Create(GURL("standard-but-noaccess://b.com")); + Origin no_access_opaque_precursor_origin = + no_access_origin.DeriveNewOpaqueOrigin(); + + Origin local_non_standard_origin = + Origin::Create(GURL("local-but-nonstandard://a.com")); + Origin local_non_standard_opaque_precursor_origin = + local_non_standard_origin.DeriveNewOpaqueOrigin(); + + // Call origin.CanBeDerivedFrom(url) for each of the following test cases + // and ensure that it returns |expected_value| + const struct { + const char* url; + Origin* origin; + bool expected_value; + } kTestCases[] = { + {"https://a.com", ®ular_origin, true}, + // Web URL can commit in an opaque origin with precursor information. + // Example: iframe sandbox navigated to a.com. + {"https://a.com", &opaque_precursor_origin, true}, + // URL that comes from the web can never commit in an opaque unique + // origin. It must have precursor information. + {"https://a.com", &opaque_unique_origin, false}, + + // Cross-origin URLs should never work. + {"https://b.com", ®ular_origin, false}, + {"https://b.com", &opaque_precursor_origin, false}, + + // data: URL can never commit in a regular, non-opaque origin. + {"data:text/html,foo", ®ular_origin, false}, + // This is the default case: data: URLs commit in opaque origin carrying + // precursor information for the origin that created them. + {"data:text/html,foo", &opaque_precursor_origin, true}, + // Browser-initiated navigations can result in data: URL committing in + // opaque unique origin. + {"data:text/html,foo", &opaque_unique_origin, true}, + + // about:blank can commit in regular origin (default case for iframes). + {"about:blank", ®ular_origin, true}, + // This can happen if data: URL that originated at a.com creates an + // about:blank iframe. + {"about:blank", &opaque_precursor_origin, true}, + // Browser-initiated navigations can result in about:blank URL committing + // in opaque unique origin. + {"about:blank", &opaque_unique_origin, true}, + + // Default behavior of srcdoc is to inherit the origin of the parent + // document. + {"about:srcdoc", ®ular_origin, true}, + // This happens for sandboxed srcdoc iframe. + {"about:srcdoc", &opaque_precursor_origin, true}, + // This can happen with browser-initiated navigation to about:blank or + // data: URL, which in turn add srcdoc iframe. + {"about:srcdoc", &opaque_unique_origin, true}, + + // Just like srcdoc, blob: URLs can be created in all the cases. + {"blob:https://a.com/foo", ®ular_origin, true}, + {"blob:https://a.com/foo", &opaque_precursor_origin, true}, + {"blob:https://a.com/foo", &opaque_unique_origin, true}, + + {"filesystem:https://a.com/foo", ®ular_origin, true}, + {"filesystem:https://a.com/foo", &opaque_precursor_origin, true}, + // Unlike blob: URLs, filesystem: ones cannot be created in an unique + // opaque origin. + {"filesystem:https://a.com/foo", &opaque_unique_origin, false}, + + // file: URLs cannot result in regular web origins, regardless of + // opaqueness. + {"file:///etc/passwd", ®ular_origin, false}, + {"file:///etc/passwd", &opaque_precursor_origin, false}, + // However, they can result in regular file: origin and an opaque one + // containing another file: origin as precursor. + {"file:///etc/passwd", &file_origin, true}, + {"file:///etc/passwd", &file_opaque_precursor_origin, true}, + // It should not be possible to get an opaque unique origin for file: + // as it is a standard scheme and will always result in a tuple origin + // or will always be derived by other origin. + // Note: file:// URLs should become unique opaque origins at some point. + {"file:///etc/passwd", &opaque_unique_origin, false}, + + // The same set as above, but including a host. + {"file://a.com/etc/passwd", ®ular_origin, false}, + {"file://a.com/etc/passwd", &opaque_precursor_origin, false}, + {"file://a.com/etc/passwd", &file_host_origin, true}, + {"file://a.com/etc/passwd", &file_host_opaque_precursor_origin, true}, + {"file://a.com/etc/passwd", &opaque_unique_origin, false}, + + // Locally registered standard scheme should behave the same way + // as built-in standard schemes. + {"new-standard://host/foo", &new_standard_origin, true}, + {"new-standard://host/foo", &new_standard_opaque_precursor_origin, true}, + {"new-standard://host/foo", &opaque_unique_origin, false}, + {"new-standard://host2/foo", &new_standard_origin, false}, + {"new-standard://host2/foo", &new_standard_opaque_precursor_origin, + false}, + + // A non-standard scheme should never commit in an standard origin or + // opaque origin with standard precursor information. + {"non-standard-scheme://a.com/foo", ®ular_origin, false}, + {"non-standard-scheme://a.com/foo", &opaque_precursor_origin, false}, + // However, it should be fine to commit in unique opaque origins or in its + // own origin. + // Note: since non-standard scheme URLs don't parse out anything + // but the scheme, using a random different hostname here would work. + {"non-standard-scheme://b.com/foo2", &opaque_unique_origin, true}, + {"non-standard-scheme://b.com/foo3", &non_standard_scheme_origin, true}, + {"non-standard-scheme://b.com/foo4", + &non_standard_opaque_precursor_origin, true}, + + // No access scheme can only commit in opaque origin. + {"standard-but-noaccess://a.com/foo", ®ular_origin, false}, + {"standard-but-noaccess://a.com/foo", &opaque_precursor_origin, false}, + {"standard-but-noaccess://a.com/foo", &opaque_unique_origin, true}, + {"standard-but-noaccess://a.com/foo", &no_access_origin, false}, + {"standard-but-noaccess://a.com/foo", &no_access_opaque_precursor_origin, + false}, + {"standard-but-noaccess://b.com/foo", &no_access_origin, false}, + {"standard-but-noaccess://b.com/foo", &no_access_opaque_precursor_origin, + true}, + + // Local schemes can be non-standard, verify they also work as expected. + {"local-but-nonstandard://a.com", ®ular_origin, false}, + {"local-but-nonstandard://a.com", &opaque_precursor_origin, false}, + {"local-but-nonstandard://a.com", &opaque_unique_origin, true}, + {"local-but-nonstandard://a.com", &local_non_standard_origin, true}, + {"local-but-nonstandard://a.com", + &local_non_standard_opaque_precursor_origin, true}, + }; + + for (const auto& test_case : kTestCases) { + SCOPED_TRACE(testing::Message() << "(origin, url): (" << *test_case.origin + << ", " << test_case.url << ")"); + EXPECT_EQ(test_case.expected_value, + test_case.origin->CanBeDerivedFrom(GURL(test_case.url))); + } +} + } // namespace url diff --git a/chromium/url/run_all_perftests.cc b/chromium/url/run_all_perftests.cc new file mode 100644 index 00000000000..4fe3675b1b5 --- /dev/null +++ b/chromium/url/run_all_perftests.cc @@ -0,0 +1,14 @@ +// Copyright 2019 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/bind.h" +#include "base/test/launcher/unit_test_launcher.h" +#include "base/test/perf_test_suite.h" + +int main(int argc, char** argv) { + base::PerfTestSuite test_suite(argc, argv); + return base::LaunchUnitTestsSerially( + argc, argv, + base::BindOnce(&base::TestSuite::Run, base::Unretained(&test_suite))); +} diff --git a/chromium/url/scheme_host_port.h b/chromium/url/scheme_host_port.h index c36df4b07b8..cf88cb1ea90 100644 --- a/chromium/url/scheme_host_port.h +++ b/chromium/url/scheme_host_port.h @@ -9,8 +9,8 @@ #include <string> +#include "base/component_export.h" #include "base/strings/string_piece.h" -#include "url/url_export.h" class GURL; @@ -72,7 +72,7 @@ struct Parsed; // // GURL url("https://example.com/"); // tuple == url::SchemeHostPort(url); // true -class URL_EXPORT SchemeHostPort { +class COMPONENT_EXPORT(URL) SchemeHostPort { public: // Creates an invalid (scheme, host, port) tuple, which represents an invalid // or non-standard URL. @@ -161,8 +161,9 @@ class URL_EXPORT SchemeHostPort { uint16_t port_; }; -URL_EXPORT std::ostream& operator<<(std::ostream& out, - const SchemeHostPort& scheme_host_port); +COMPONENT_EXPORT(URL) +std::ostream& operator<<(std::ostream& out, + const SchemeHostPort& scheme_host_port); } // namespace url diff --git a/chromium/url/scheme_host_port_unittest.cc b/chromium/url/scheme_host_port_unittest.cc index 7b00f4fc76d..ed1aaec9339 100644 --- a/chromium/url/scheme_host_port_unittest.cc +++ b/chromium/url/scheme_host_port_unittest.cc @@ -5,7 +5,7 @@ #include <stddef.h> #include <stdint.h> -#include "base/macros.h" +#include "base/stl_util.h" #include "testing/gtest/include/gtest/gtest.h" #include "url/gurl.h" #include "url/scheme_host_port.h" @@ -253,10 +253,10 @@ TEST_F(SchemeHostPortTest, Comparison) { {"https", "b", 81}, }; - for (size_t i = 0; i < arraysize(tuples); i++) { + for (size_t i = 0; i < base::size(tuples); i++) { url::SchemeHostPort current(tuples[i].scheme, tuples[i].host, tuples[i].port); - for (size_t j = i; j < arraysize(tuples); j++) { + for (size_t j = i; j < base::size(tuples); j++) { url::SchemeHostPort to_compare(tuples[j].scheme, tuples[j].host, tuples[j].port); EXPECT_EQ(i < j, current < to_compare) << i << " < " << j; diff --git a/chromium/url/third_party/mozilla/url_parse.h b/chromium/url/third_party/mozilla/url_parse.h index 6d40d3f9971..8a1c823d4f8 100644 --- a/chromium/url/third_party/mozilla/url_parse.h +++ b/chromium/url/third_party/mozilla/url_parse.h @@ -5,8 +5,8 @@ #ifndef URL_THIRD_PARTY_MOZILLA_URL_PARSE_H_ #define URL_THIRD_PARTY_MOZILLA_URL_PARSE_H_ +#include "base/component_export.h" #include "base/strings/string16.h" -#include "url/url_export.h" namespace url { @@ -74,7 +74,7 @@ inline Component MakeRange(int begin, int end) { // else // ParsePathURL(url, url_len, &parsed); // -struct URL_EXPORT Parsed { +struct COMPONENT_EXPORT(URL) Parsed { // Identifies different components. enum ComponentType { SCHEME, @@ -227,46 +227,44 @@ struct URL_EXPORT Parsed { // StandardURL is for when the scheme is known to be one that has an // authority (host) like "http". This function will not handle weird ones // like "about:" and "javascript:", or do the right thing for "file:" URLs. -URL_EXPORT void ParseStandardURL(const char* url, - int url_len, - Parsed* parsed); -URL_EXPORT void ParseStandardURL(const base::char16* url, - int url_len, - Parsed* parsed); +COMPONENT_EXPORT(URL) +void ParseStandardURL(const char* url, int url_len, Parsed* parsed); +COMPONENT_EXPORT(URL) +void ParseStandardURL(const base::char16* url, int url_len, Parsed* parsed); // PathURL is for when the scheme is known not to have an authority (host) // section but that aren't file URLs either. The scheme is parsed, and // everything after the scheme is considered as the path. This is used for // things like "about:" and "javascript:" -URL_EXPORT void ParsePathURL(const char* url, - int url_len, - bool trim_path_end, - Parsed* parsed); -URL_EXPORT void ParsePathURL(const base::char16* url, - int url_len, - bool trim_path_end, - Parsed* parsed); +COMPONENT_EXPORT(URL) +void ParsePathURL(const char* url, + int url_len, + bool trim_path_end, + Parsed* parsed); +COMPONENT_EXPORT(URL) +void ParsePathURL(const base::char16* url, + int url_len, + bool trim_path_end, + Parsed* parsed); // FileURL is for file URLs. There are some special rules for interpreting // these. -URL_EXPORT void ParseFileURL(const char* url, int url_len, Parsed* parsed); -URL_EXPORT void ParseFileURL(const base::char16* url, - int url_len, - Parsed* parsed); +COMPONENT_EXPORT(URL) +void ParseFileURL(const char* url, int url_len, Parsed* parsed); +COMPONENT_EXPORT(URL) +void ParseFileURL(const base::char16* url, int url_len, Parsed* parsed); // Filesystem URLs are structured differently than other URLs. -URL_EXPORT void ParseFileSystemURL(const char* url, - int url_len, - Parsed* parsed); -URL_EXPORT void ParseFileSystemURL(const base::char16* url, - int url_len, - Parsed* parsed); +COMPONENT_EXPORT(URL) +void ParseFileSystemURL(const char* url, int url_len, Parsed* parsed); +COMPONENT_EXPORT(URL) +void ParseFileSystemURL(const base::char16* url, int url_len, Parsed* parsed); // MailtoURL is for mailto: urls. They are made up scheme,path,query -URL_EXPORT void ParseMailtoURL(const char* url, int url_len, Parsed* parsed); -URL_EXPORT void ParseMailtoURL(const base::char16* url, - int url_len, - Parsed* parsed); +COMPONENT_EXPORT(URL) +void ParseMailtoURL(const char* url, int url_len, Parsed* parsed); +COMPONENT_EXPORT(URL) +void ParseMailtoURL(const base::char16* url, int url_len, Parsed* parsed); // Helper functions ----------------------------------------------------------- @@ -290,31 +288,31 @@ URL_EXPORT void ParseMailtoURL(const base::char16* url, // end of the string). // // The 8-bit version requires UTF-8 encoding. -URL_EXPORT bool ExtractScheme(const char* url, - int url_len, - Component* scheme); -URL_EXPORT bool ExtractScheme(const base::char16* url, - int url_len, - Component* scheme); +COMPONENT_EXPORT(URL) +bool ExtractScheme(const char* url, int url_len, Component* scheme); +COMPONENT_EXPORT(URL) +bool ExtractScheme(const base::char16* url, int url_len, Component* scheme); // Returns true if ch is a character that terminates the authority segment // of a URL. -URL_EXPORT bool IsAuthorityTerminator(base::char16 ch); +COMPONENT_EXPORT(URL) bool IsAuthorityTerminator(base::char16 ch); // Does a best effort parse of input |spec|, in range |auth|. If a particular // component is not found, it will be set to invalid. -URL_EXPORT void ParseAuthority(const char* spec, - const Component& auth, - Component* username, - Component* password, - Component* hostname, - Component* port_num); -URL_EXPORT void ParseAuthority(const base::char16* spec, - const Component& auth, - Component* username, - Component* password, - Component* hostname, - Component* port_num); +COMPONENT_EXPORT(URL) +void ParseAuthority(const char* spec, + const Component& auth, + Component* username, + Component* password, + Component* hostname, + Component* port_num); +COMPONENT_EXPORT(URL) +void ParseAuthority(const base::char16* spec, + const Component& auth, + Component* username, + Component* password, + Component* hostname, + Component* port_num); // Computes the integer port value from the given port component. The port // component should have been identified by one of the init functions on @@ -323,8 +321,9 @@ URL_EXPORT void ParseAuthority(const base::char16* spec, // The return value will be a positive integer between 0 and 64K, or one of // the two special values below. enum SpecialPort { PORT_UNSPECIFIED = -1, PORT_INVALID = -2 }; -URL_EXPORT int ParsePort(const char* url, const Component& port); -URL_EXPORT int ParsePort(const base::char16* url, const Component& port); +COMPONENT_EXPORT(URL) int ParsePort(const char* url, const Component& port); +COMPONENT_EXPORT(URL) +int ParsePort(const base::char16* url, const Component& port); // Extracts the range of the file name in the given url. The path must // already have been computed by the parse function, and the matching URL @@ -336,12 +335,14 @@ URL_EXPORT int ParsePort(const base::char16* url, const Component& port); // following the last slash. // // The 8-bit version requires UTF-8 encoding. -URL_EXPORT void ExtractFileName(const char* url, - const Component& path, - Component* file_name); -URL_EXPORT void ExtractFileName(const base::char16* url, - const Component& path, - Component* file_name); +COMPONENT_EXPORT(URL) +void ExtractFileName(const char* url, + const Component& path, + Component* file_name); +COMPONENT_EXPORT(URL) +void ExtractFileName(const base::char16* url, + const Component& path, + Component* file_name); // Extract the first key/value from the range defined by |*query|. Updates // |*query| to start at the end of the extracted key/value pair. This is @@ -358,14 +359,16 @@ URL_EXPORT void ExtractFileName(const base::char16* url, // // If no key/value are found |*key| and |*value| will be unchanged and it will // return false. -URL_EXPORT bool ExtractQueryKeyValue(const char* url, - Component* query, - Component* key, - Component* value); -URL_EXPORT bool ExtractQueryKeyValue(const base::char16* url, - Component* query, - Component* key, - Component* value); +COMPONENT_EXPORT(URL) +bool ExtractQueryKeyValue(const char* url, + Component* query, + Component* key, + Component* value); +COMPONENT_EXPORT(URL) +bool ExtractQueryKeyValue(const base::char16* url, + Component* query, + Component* key, + Component* value); } // namespace url diff --git a/chromium/url/url_canon.cc b/chromium/url/url_canon.cc index d51a3179e10..cde280d2be3 100644 --- a/chromium/url/url_canon.cc +++ b/chromium/url/url_canon.cc @@ -4,9 +4,12 @@ #include "url/url_canon.h" +#include "base/component_export.h" + namespace url { -template class EXPORT_TEMPLATE_DEFINE(URL_EXPORT) CanonOutputT<char>; -template class EXPORT_TEMPLATE_DEFINE(URL_EXPORT) CanonOutputT<base::char16>; +template class EXPORT_TEMPLATE_DEFINE(COMPONENT_EXPORT(URL)) CanonOutputT<char>; +template class EXPORT_TEMPLATE_DEFINE(COMPONENT_EXPORT(URL)) + CanonOutputT<base::char16>; } // namespace url diff --git a/chromium/url/url_canon.h b/chromium/url/url_canon.h index f779961e3a2..273f0568414 100644 --- a/chromium/url/url_canon.h +++ b/chromium/url/url_canon.h @@ -8,10 +8,10 @@ #include <stdlib.h> #include <string.h> +#include "base/component_export.h" #include "base/export_template.h" #include "base/strings/string16.h" #include "url/third_party/mozilla/url_parse.h" -#include "url/url_export.h" namespace url { @@ -176,8 +176,9 @@ class RawCanonOutputT : public CanonOutputT<T> { }; // Explicitely instantiate commonly used instatiations. -extern template class EXPORT_TEMPLATE_DECLARE(URL_EXPORT) CanonOutputT<char>; -extern template class EXPORT_TEMPLATE_DECLARE(URL_EXPORT) +extern template class EXPORT_TEMPLATE_DECLARE(COMPONENT_EXPORT(URL)) + CanonOutputT<char>; +extern template class EXPORT_TEMPLATE_DECLARE(COMPONENT_EXPORT(URL)) CanonOutputT<base::char16>; // Normally, all canonicalization output is in narrow characters. We support @@ -199,7 +200,7 @@ class RawCanonOutputW : public RawCanonOutputT<base::char16, fixed_capacity> {}; // // Embedders will want to see the unit test for the ICU version. -class URL_EXPORT CharsetConverter { +class COMPONENT_EXPORT(URL) CharsetConverter { public: CharsetConverter() {} virtual ~CharsetConverter() {} @@ -266,17 +267,18 @@ enum SchemeType { // If |input| contained both removable whitespace and a raw `<` character, // |potentially_dangling_markup| will be set to `true`. Otherwise, it will be // left untouched. -URL_EXPORT const char* RemoveURLWhitespace(const char* input, - int input_len, - CanonOutputT<char>* buffer, - int* output_len, - bool* potentially_dangling_markup); -URL_EXPORT const base::char16* RemoveURLWhitespace( - const base::char16* input, - int input_len, - CanonOutputT<base::char16>* buffer, - int* output_len, - bool* potentially_dangling_markup); +COMPONENT_EXPORT(URL) +const char* RemoveURLWhitespace(const char* input, + int input_len, + CanonOutputT<char>* buffer, + int* output_len, + bool* potentially_dangling_markup); +COMPONENT_EXPORT(URL) +const base::char16* RemoveURLWhitespace(const base::char16* input, + int input_len, + CanonOutputT<base::char16>* buffer, + int* output_len, + bool* potentially_dangling_markup); // IDN ------------------------------------------------------------------------ @@ -289,9 +291,8 @@ URL_EXPORT const base::char16* RemoveURLWhitespace( // the length of the output will be set to the length of the new host name. // // On error, returns false. The output in this case is undefined. -URL_EXPORT bool IDNToASCII(const base::char16* src, - int src_len, - CanonOutputW* output); +COMPONENT_EXPORT(URL) +bool IDNToASCII(const base::char16* src, int src_len, CanonOutputW* output); // Piece-by-piece canonicalizers ---------------------------------------------- // @@ -317,14 +318,16 @@ URL_EXPORT bool IDNToASCII(const base::char16* src, // URLs. // // The 8-bit version requires UTF-8 encoding. -URL_EXPORT bool CanonicalizeScheme(const char* spec, - const Component& scheme, - CanonOutput* output, - Component* out_scheme); -URL_EXPORT bool CanonicalizeScheme(const base::char16* spec, - const Component& scheme, - CanonOutput* output, - Component* out_scheme); +COMPONENT_EXPORT(URL) +bool CanonicalizeScheme(const char* spec, + const Component& scheme, + CanonOutput* output, + Component* out_scheme); +COMPONENT_EXPORT(URL) +bool CanonicalizeScheme(const base::char16* spec, + const Component& scheme, + CanonOutput* output, + Component* out_scheme); // User info: username/password. If present, this will add the delimiters so // the output will be "<username>:<password>@" or "<username>@". Empty @@ -336,20 +339,22 @@ URL_EXPORT bool CanonicalizeScheme(const base::char16* spec, // is legal as long as the two components don't overlap. // // The 8-bit version requires UTF-8 encoding. -URL_EXPORT bool CanonicalizeUserInfo(const char* username_source, - const Component& username, - const char* password_source, - const Component& password, - CanonOutput* output, - Component* out_username, - Component* out_password); -URL_EXPORT bool CanonicalizeUserInfo(const base::char16* username_source, - const Component& username, - const base::char16* password_source, - const Component& password, - CanonOutput* output, - Component* out_username, - Component* out_password); +COMPONENT_EXPORT(URL) +bool CanonicalizeUserInfo(const char* username_source, + const Component& username, + const char* password_source, + const Component& password, + CanonOutput* output, + Component* out_username, + Component* out_password); +COMPONENT_EXPORT(URL) +bool CanonicalizeUserInfo(const base::char16* username_source, + const Component& username, + const base::char16* password_source, + const Component& password, + CanonOutput* output, + Component* out_username, + Component* out_password); // This structure holds detailed state exported from the IP/Host canonicalizers. // Additional fields may be added as callers require them. @@ -401,27 +406,31 @@ struct CanonHostInfo { // // The 8-bit version requires UTF-8 encoding. Use this version when you only // need to know whether canonicalization succeeded. -URL_EXPORT bool CanonicalizeHost(const char* spec, - const Component& host, - CanonOutput* output, - Component* out_host); -URL_EXPORT bool CanonicalizeHost(const base::char16* spec, - const Component& host, - CanonOutput* output, - Component* out_host); +COMPONENT_EXPORT(URL) +bool CanonicalizeHost(const char* spec, + const Component& host, + CanonOutput* output, + Component* out_host); +COMPONENT_EXPORT(URL) +bool CanonicalizeHost(const base::char16* spec, + const Component& host, + CanonOutput* output, + Component* out_host); // Extended version of CanonicalizeHost, which returns additional information. // Use this when you need to know whether the hostname was an IP address. // A successful return is indicated by host_info->family != BROKEN. See the // definition of CanonHostInfo above for details. -URL_EXPORT void CanonicalizeHostVerbose(const char* spec, - const Component& host, - CanonOutput* output, - CanonHostInfo* host_info); -URL_EXPORT void CanonicalizeHostVerbose(const base::char16* spec, - const Component& host, - CanonOutput* output, - CanonHostInfo* host_info); +COMPONENT_EXPORT(URL) +void CanonicalizeHostVerbose(const char* spec, + const Component& host, + CanonOutput* output, + CanonHostInfo* host_info); +COMPONENT_EXPORT(URL) +void CanonicalizeHostVerbose(const base::char16* spec, + const Component& host, + CanonOutput* output, + CanonHostInfo* host_info); // Canonicalizes a string according to the host canonicalization rules. Unlike // CanonicalizeHost, this will not check for IP addresses which can change the @@ -443,12 +452,14 @@ URL_EXPORT void CanonicalizeHostVerbose(const base::char16* spec, // Returns true if the host was valid. This function will treat a 0-length // host as valid (because it's designed to be used for substrings) while the // full version above will mark empty hosts as broken. -URL_EXPORT bool CanonicalizeHostSubstring(const char* spec, - const Component& host, - CanonOutput* output); -URL_EXPORT bool CanonicalizeHostSubstring(const base::char16* spec, - const Component& host, - CanonOutput* output); +COMPONENT_EXPORT(URL) +bool CanonicalizeHostSubstring(const char* spec, + const Component& host, + CanonOutput* output); +COMPONENT_EXPORT(URL) +bool CanonicalizeHostSubstring(const base::char16* spec, + const Component& host, + CanonOutput* output); // IP addresses. // @@ -460,34 +471,39 @@ URL_EXPORT bool CanonicalizeHostSubstring(const base::char16* spec, // This is called AUTOMATICALLY from the host canonicalizer, which ensures that // the input is unescaped and name-prepped, etc. It should not normally be // necessary or wise to call this directly. -URL_EXPORT void CanonicalizeIPAddress(const char* spec, - const Component& host, - CanonOutput* output, - CanonHostInfo* host_info); -URL_EXPORT void CanonicalizeIPAddress(const base::char16* spec, - const Component& host, - CanonOutput* output, - CanonHostInfo* host_info); +COMPONENT_EXPORT(URL) +void CanonicalizeIPAddress(const char* spec, + const Component& host, + CanonOutput* output, + CanonHostInfo* host_info); +COMPONENT_EXPORT(URL) +void CanonicalizeIPAddress(const base::char16* spec, + const Component& host, + CanonOutput* output, + CanonHostInfo* host_info); // Port: this function will add the colon for the port if a port is present. // The caller can pass PORT_UNSPECIFIED as the // default_port_for_scheme argument if there is no default port. // // The 8-bit version requires UTF-8 encoding. -URL_EXPORT bool CanonicalizePort(const char* spec, - const Component& port, - int default_port_for_scheme, - CanonOutput* output, - Component* out_port); -URL_EXPORT bool CanonicalizePort(const base::char16* spec, - const Component& port, - int default_port_for_scheme, - CanonOutput* output, - Component* out_port); +COMPONENT_EXPORT(URL) +bool CanonicalizePort(const char* spec, + const Component& port, + int default_port_for_scheme, + CanonOutput* output, + Component* out_port); +COMPONENT_EXPORT(URL) +bool CanonicalizePort(const base::char16* spec, + const Component& port, + int default_port_for_scheme, + CanonOutput* output, + Component* out_port); // Returns the default port for the given canonical scheme, or PORT_UNSPECIFIED // if the scheme is unknown. -URL_EXPORT int DefaultPortForScheme(const char* scheme, int scheme_len); +COMPONENT_EXPORT(URL) +int DefaultPortForScheme(const char* scheme, int scheme_len); // Path. If the input does not begin in a slash (including if the input is // empty), we'll prepend a slash to the path to make it canonical. @@ -498,14 +514,16 @@ URL_EXPORT int DefaultPortForScheme(const char* scheme, int scheme_len); // an issue. Somebody giving us an 8-bit path is responsible for generating // the path that the server expects (we'll escape high-bit characters), so // if something is invalid, it's their problem. -URL_EXPORT bool CanonicalizePath(const char* spec, - const Component& path, - CanonOutput* output, - Component* out_path); -URL_EXPORT bool CanonicalizePath(const base::char16* spec, - const Component& path, - CanonOutput* output, - Component* out_path); +COMPONENT_EXPORT(URL) +bool CanonicalizePath(const char* spec, + const Component& path, + CanonOutput* output, + Component* out_path); +COMPONENT_EXPORT(URL) +bool CanonicalizePath(const base::char16* spec, + const Component& path, + CanonOutput* output, + Component* out_path); // Canonicalizes the input as a file path. This is like CanonicalizePath except // that it also handles Windows drive specs. For example, the path can begin @@ -513,14 +531,16 @@ URL_EXPORT bool CanonicalizePath(const base::char16* spec, // The string will be appended to |*output| and |*out_path| will be updated. // // The 8-bit version requires UTF-8 encoding. -URL_EXPORT bool FileCanonicalizePath(const char* spec, - const Component& path, - CanonOutput* output, - Component* out_path); -URL_EXPORT bool FileCanonicalizePath(const base::char16* spec, - const Component& path, - CanonOutput* output, - Component* out_path); +COMPONENT_EXPORT(URL) +bool FileCanonicalizePath(const char* spec, + const Component& path, + CanonOutput* output, + Component* out_path); +COMPONENT_EXPORT(URL) +bool FileCanonicalizePath(const base::char16* spec, + const Component& path, + CanonOutput* output, + Component* out_path); // Query: Prepends the ? if needed. // @@ -534,16 +554,18 @@ URL_EXPORT bool FileCanonicalizePath(const base::char16* spec, // if necessary, for ASCII input, no conversions are necessary. // // The converter can be NULL. In this case, the output encoding will be UTF-8. -URL_EXPORT void CanonicalizeQuery(const char* spec, - const Component& query, - CharsetConverter* converter, - CanonOutput* output, - Component* out_query); -URL_EXPORT void CanonicalizeQuery(const base::char16* spec, - const Component& query, - CharsetConverter* converter, - CanonOutput* output, - Component* out_query); +COMPONENT_EXPORT(URL) +void CanonicalizeQuery(const char* spec, + const Component& query, + CharsetConverter* converter, + CanonOutput* output, + Component* out_query); +COMPONENT_EXPORT(URL) +void CanonicalizeQuery(const base::char16* spec, + const Component& query, + CharsetConverter* converter, + CanonOutput* output, + Component* out_query); // Ref: Prepends the # if needed. The output will be UTF-8 (this is the only // canonicalizer that does not produce ASCII output). The output is @@ -551,14 +573,16 @@ URL_EXPORT void CanonicalizeQuery(const base::char16* spec, // // This function will not fail. If the input is invalid UTF-8/UTF-16, we'll use // the "Unicode replacement character" for the confusing bits and copy the rest. -URL_EXPORT void CanonicalizeRef(const char* spec, - const Component& path, - CanonOutput* output, - Component* out_path); -URL_EXPORT void CanonicalizeRef(const base::char16* spec, - const Component& path, - CanonOutput* output, - Component* out_path); +COMPONENT_EXPORT(URL) +void CanonicalizeRef(const char* spec, + const Component& path, + CanonOutput* output, + Component* out_path); +COMPONENT_EXPORT(URL) +void CanonicalizeRef(const base::char16* spec, + const Component& path, + CanonOutput* output, + Component* out_path); // Full canonicalizer --------------------------------------------------------- // @@ -571,77 +595,87 @@ URL_EXPORT void CanonicalizeRef(const base::char16* spec, // The 8-bit versions require UTF-8 encoding. // Use for standard URLs with authorities and paths. -URL_EXPORT bool CanonicalizeStandardURL(const char* spec, - int spec_len, - const Parsed& parsed, - SchemeType scheme_type, - CharsetConverter* query_converter, - CanonOutput* output, - Parsed* new_parsed); -URL_EXPORT bool CanonicalizeStandardURL(const base::char16* spec, - int spec_len, - const Parsed& parsed, - SchemeType scheme_type, - CharsetConverter* query_converter, - CanonOutput* output, - Parsed* new_parsed); +COMPONENT_EXPORT(URL) +bool CanonicalizeStandardURL(const char* spec, + int spec_len, + const Parsed& parsed, + SchemeType scheme_type, + CharsetConverter* query_converter, + CanonOutput* output, + Parsed* new_parsed); +COMPONENT_EXPORT(URL) +bool CanonicalizeStandardURL(const base::char16* spec, + int spec_len, + const Parsed& parsed, + SchemeType scheme_type, + CharsetConverter* query_converter, + CanonOutput* output, + Parsed* new_parsed); // Use for file URLs. -URL_EXPORT bool CanonicalizeFileURL(const char* spec, - int spec_len, - const Parsed& parsed, - CharsetConverter* query_converter, - CanonOutput* output, - Parsed* new_parsed); -URL_EXPORT bool CanonicalizeFileURL(const base::char16* spec, - int spec_len, - const Parsed& parsed, - CharsetConverter* query_converter, - CanonOutput* output, - Parsed* new_parsed); +COMPONENT_EXPORT(URL) +bool CanonicalizeFileURL(const char* spec, + int spec_len, + const Parsed& parsed, + CharsetConverter* query_converter, + CanonOutput* output, + Parsed* new_parsed); +COMPONENT_EXPORT(URL) +bool CanonicalizeFileURL(const base::char16* spec, + int spec_len, + const Parsed& parsed, + CharsetConverter* query_converter, + CanonOutput* output, + Parsed* new_parsed); // Use for filesystem URLs. -URL_EXPORT bool CanonicalizeFileSystemURL(const char* spec, - int spec_len, - const Parsed& parsed, - CharsetConverter* query_converter, - CanonOutput* output, - Parsed* new_parsed); -URL_EXPORT bool CanonicalizeFileSystemURL(const base::char16* spec, - int spec_len, - const Parsed& parsed, - CharsetConverter* query_converter, - CanonOutput* output, - Parsed* new_parsed); +COMPONENT_EXPORT(URL) +bool CanonicalizeFileSystemURL(const char* spec, + int spec_len, + const Parsed& parsed, + CharsetConverter* query_converter, + CanonOutput* output, + Parsed* new_parsed); +COMPONENT_EXPORT(URL) +bool CanonicalizeFileSystemURL(const base::char16* spec, + int spec_len, + const Parsed& parsed, + CharsetConverter* query_converter, + CanonOutput* output, + Parsed* new_parsed); // Use for path URLs such as javascript. This does not modify the path in any // way, for example, by escaping it. -URL_EXPORT bool CanonicalizePathURL(const char* spec, - int spec_len, - const Parsed& parsed, - CanonOutput* output, - Parsed* new_parsed); -URL_EXPORT bool CanonicalizePathURL(const base::char16* spec, - int spec_len, - const Parsed& parsed, - CanonOutput* output, - Parsed* new_parsed); +COMPONENT_EXPORT(URL) +bool CanonicalizePathURL(const char* spec, + int spec_len, + const Parsed& parsed, + CanonOutput* output, + Parsed* new_parsed); +COMPONENT_EXPORT(URL) +bool CanonicalizePathURL(const base::char16* spec, + int spec_len, + const Parsed& parsed, + CanonOutput* output, + Parsed* new_parsed); // Use for mailto URLs. This "canonicalizes" the URL into a path and query // component. It does not attempt to merge "to" fields. It uses UTF-8 for // the query encoding if there is a query. This is because a mailto URL is // really intended for an external mail program, and the encoding of a page, // etc. which would influence a query encoding normally are irrelevant. -URL_EXPORT bool CanonicalizeMailtoURL(const char* spec, - int spec_len, - const Parsed& parsed, - CanonOutput* output, - Parsed* new_parsed); -URL_EXPORT bool CanonicalizeMailtoURL(const base::char16* spec, - int spec_len, - const Parsed& parsed, - CanonOutput* output, - Parsed* new_parsed); +COMPONENT_EXPORT(URL) +bool CanonicalizeMailtoURL(const char* spec, + int spec_len, + const Parsed& parsed, + CanonOutput* output, + Parsed* new_parsed); +COMPONENT_EXPORT(URL) +bool CanonicalizeMailtoURL(const base::char16* spec, + int spec_len, + const Parsed& parsed, + CanonOutput* output, + Parsed* new_parsed); // Part replacer -------------------------------------------------------------- @@ -826,78 +860,86 @@ class Replacements { }; // The base must be an 8-bit canonical URL. -URL_EXPORT bool ReplaceStandardURL(const char* base, - const Parsed& base_parsed, - const Replacements<char>& replacements, - SchemeType scheme_type, - CharsetConverter* query_converter, - CanonOutput* output, - Parsed* new_parsed); -URL_EXPORT bool ReplaceStandardURL( - const char* base, - const Parsed& base_parsed, - const Replacements<base::char16>& replacements, - SchemeType scheme_type, - CharsetConverter* query_converter, - CanonOutput* output, - Parsed* new_parsed); +COMPONENT_EXPORT(URL) +bool ReplaceStandardURL(const char* base, + const Parsed& base_parsed, + const Replacements<char>& replacements, + SchemeType scheme_type, + CharsetConverter* query_converter, + CanonOutput* output, + Parsed* new_parsed); +COMPONENT_EXPORT(URL) +bool ReplaceStandardURL(const char* base, + const Parsed& base_parsed, + const Replacements<base::char16>& replacements, + SchemeType scheme_type, + CharsetConverter* query_converter, + CanonOutput* output, + Parsed* new_parsed); // Filesystem URLs can only have the path, query, or ref replaced. // All other components will be ignored. -URL_EXPORT bool ReplaceFileSystemURL(const char* base, - const Parsed& base_parsed, - const Replacements<char>& replacements, - CharsetConverter* query_converter, - CanonOutput* output, - Parsed* new_parsed); -URL_EXPORT bool ReplaceFileSystemURL( - const char* base, - const Parsed& base_parsed, - const Replacements<base::char16>& replacements, - CharsetConverter* query_converter, - CanonOutput* output, - Parsed* new_parsed); +COMPONENT_EXPORT(URL) +bool ReplaceFileSystemURL(const char* base, + const Parsed& base_parsed, + const Replacements<char>& replacements, + CharsetConverter* query_converter, + CanonOutput* output, + Parsed* new_parsed); +COMPONENT_EXPORT(URL) +bool ReplaceFileSystemURL(const char* base, + const Parsed& base_parsed, + const Replacements<base::char16>& replacements, + CharsetConverter* query_converter, + CanonOutput* output, + Parsed* new_parsed); // Replacing some parts of a file URL is not permitted. Everything except // the host, path, query, and ref will be ignored. -URL_EXPORT bool ReplaceFileURL(const char* base, - const Parsed& base_parsed, - const Replacements<char>& replacements, - CharsetConverter* query_converter, - CanonOutput* output, - Parsed* new_parsed); -URL_EXPORT bool ReplaceFileURL(const char* base, - const Parsed& base_parsed, - const Replacements<base::char16>& replacements, - CharsetConverter* query_converter, - CanonOutput* output, - Parsed* new_parsed); +COMPONENT_EXPORT(URL) +bool ReplaceFileURL(const char* base, + const Parsed& base_parsed, + const Replacements<char>& replacements, + CharsetConverter* query_converter, + CanonOutput* output, + Parsed* new_parsed); +COMPONENT_EXPORT(URL) +bool ReplaceFileURL(const char* base, + const Parsed& base_parsed, + const Replacements<base::char16>& replacements, + CharsetConverter* query_converter, + CanonOutput* output, + Parsed* new_parsed); // Path URLs can only have the scheme and path replaced. All other components // will be ignored. -URL_EXPORT bool ReplacePathURL(const char* base, - const Parsed& base_parsed, - const Replacements<char>& replacements, - CanonOutput* output, - Parsed* new_parsed); -URL_EXPORT bool ReplacePathURL(const char* base, - const Parsed& base_parsed, - const Replacements<base::char16>& replacements, - CanonOutput* output, - Parsed* new_parsed); +COMPONENT_EXPORT(URL) +bool ReplacePathURL(const char* base, + const Parsed& base_parsed, + const Replacements<char>& replacements, + CanonOutput* output, + Parsed* new_parsed); +COMPONENT_EXPORT(URL) +bool ReplacePathURL(const char* base, + const Parsed& base_parsed, + const Replacements<base::char16>& replacements, + CanonOutput* output, + Parsed* new_parsed); // Mailto URLs can only have the scheme, path, and query replaced. // All other components will be ignored. -URL_EXPORT bool ReplaceMailtoURL(const char* base, - const Parsed& base_parsed, - const Replacements<char>& replacements, - CanonOutput* output, - Parsed* new_parsed); -URL_EXPORT bool ReplaceMailtoURL(const char* base, - const Parsed& base_parsed, - const Replacements<base::char16>& replacements, - CanonOutput* output, - Parsed* new_parsed); +COMPONENT_EXPORT(URL) +bool ReplaceMailtoURL(const char* base, + const Parsed& base_parsed, + const Replacements<char>& replacements, + CanonOutput* output, + Parsed* new_parsed); +COMPONENT_EXPORT(URL) +bool ReplaceMailtoURL(const char* base, + const Parsed& base_parsed, + const Replacements<base::char16>& replacements, + CanonOutput* output, + Parsed* new_parsed); // Relative URL --------------------------------------------------------------- @@ -912,20 +954,22 @@ URL_EXPORT bool ReplaceMailtoURL(const char* base, // not). Failure means that the combination of URLs doesn't make any sense. // // The base URL should always be canonical, therefore is ASCII. -URL_EXPORT bool IsRelativeURL(const char* base, - const Parsed& base_parsed, - const char* fragment, - int fragment_len, - bool is_base_hierarchical, - bool* is_relative, - Component* relative_component); -URL_EXPORT bool IsRelativeURL(const char* base, - const Parsed& base_parsed, - const base::char16* fragment, - int fragment_len, - bool is_base_hierarchical, - bool* is_relative, - Component* relative_component); +COMPONENT_EXPORT(URL) +bool IsRelativeURL(const char* base, + const Parsed& base_parsed, + const char* fragment, + int fragment_len, + bool is_base_hierarchical, + bool* is_relative, + Component* relative_component); +COMPONENT_EXPORT(URL) +bool IsRelativeURL(const char* base, + const Parsed& base_parsed, + const base::char16* fragment, + int fragment_len, + bool is_base_hierarchical, + bool* is_relative, + Component* relative_component); // Given a canonical parsed source URL, a URL fragment known to be relative, // and the identified relevant portion of the relative URL (computed by @@ -945,22 +989,24 @@ URL_EXPORT bool IsRelativeURL(const char* base, // Returns true on success. On failure, the output will be "something // reasonable" that will be consistent and valid, just probably not what // was intended by the web page author or caller. -URL_EXPORT bool ResolveRelativeURL(const char* base_url, - const Parsed& base_parsed, - bool base_is_file, - const char* relative_url, - const Component& relative_component, - CharsetConverter* query_converter, - CanonOutput* output, - Parsed* out_parsed); -URL_EXPORT bool ResolveRelativeURL(const char* base_url, - const Parsed& base_parsed, - bool base_is_file, - const base::char16* relative_url, - const Component& relative_component, - CharsetConverter* query_converter, - CanonOutput* output, - Parsed* out_parsed); +COMPONENT_EXPORT(URL) +bool ResolveRelativeURL(const char* base_url, + const Parsed& base_parsed, + bool base_is_file, + const char* relative_url, + const Component& relative_component, + CharsetConverter* query_converter, + CanonOutput* output, + Parsed* out_parsed); +COMPONENT_EXPORT(URL) +bool ResolveRelativeURL(const char* base_url, + const Parsed& base_parsed, + bool base_is_file, + const base::char16* relative_url, + const Component& relative_component, + CharsetConverter* query_converter, + CanonOutput* output, + Parsed* out_parsed); } // namespace url diff --git a/chromium/url/url_canon_icu.h b/chromium/url/url_canon_icu.h index 80d79539074..367715119d2 100644 --- a/chromium/url/url_canon_icu.h +++ b/chromium/url/url_canon_icu.h @@ -8,8 +8,8 @@ // ICU integration functions. #include "base/compiler_specific.h" +#include "base/component_export.h" #include "url/url_canon.h" -#include "url/url_export.h" typedef struct UConverter UConverter; @@ -17,7 +17,7 @@ namespace url { // An implementation of CharsetConverter that implementations can use to // interface the canonicalizer with ICU's conversion routines. -class URL_EXPORT ICUCharsetConverter : public CharsetConverter { +class COMPONENT_EXPORT(URL) ICUCharsetConverter : public CharsetConverter { public: // Constructs a converter using an already-existing ICU character set // converter. This converter is NOT owned by this object; the lifetime must diff --git a/chromium/url/url_canon_icu_unittest.cc b/chromium/url/url_canon_icu_unittest.cc index af320f9bf93..62ec1a9661e 100644 --- a/chromium/url/url_canon_icu_unittest.cc +++ b/chromium/url/url_canon_icu_unittest.cc @@ -4,7 +4,7 @@ #include <stddef.h> -#include "base/macros.h" +#include "base/stl_util.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/icu/source/common/unicode/ucnv.h" #include "url/url_canon.h" @@ -54,7 +54,7 @@ TEST(URLCanonIcuTest, ICUCharsetConverter) { "hello\xa7\x41%26%231758%3B\xa6\x6eworld"}, }; - for (size_t i = 0; i < arraysize(icu_cases); i++) { + for (size_t i = 0; i < base::size(icu_cases); i++) { UConvScoper conv(icu_cases[i].encoding); ASSERT_TRUE(conv.converter() != NULL); ICUCharsetConverter converter(conv.converter()); @@ -112,7 +112,7 @@ TEST(URLCanonIcuTest, QueryWithConverter) { "?q=Chinese%26%2365319%3B"}, }; - for (size_t i = 0; i < arraysize(query_cases); i++) { + for (size_t i = 0; i < base::size(query_cases); i++) { Component out_comp; UConvScoper conv(query_cases[i].encoding); diff --git a/chromium/url/url_canon_internal.h b/chromium/url/url_canon_internal.h index e651e0ce837..ba8b9ee9d00 100644 --- a/chromium/url/url_canon_internal.h +++ b/chromium/url/url_canon_internal.h @@ -13,6 +13,7 @@ #include <stddef.h> #include <stdlib.h> +#include "base/component_export.h" #include "base/logging.h" #include "url/url_canon.h" @@ -84,7 +85,7 @@ void AppendStringOfType(const base::char16* source, int length, // Maps the hex numerical values 0x0 to 0xf to the corresponding ASCII digit // that will be used to represent it. -URL_EXPORT extern const char kHexCharLookup[0x10]; +COMPONENT_EXPORT(URL) extern const char kHexCharLookup[0x10]; // This lookup table allows fast conversion between ASCII hex letters and their // corresponding numerical value. The 8-bit range is divided up into 8 @@ -149,8 +150,11 @@ extern const base::char16 kUnicodeReplacementCharacter; // |*begin| will be updated to point to the last character consumed so it // can be incremented in a loop and will be ready for the next character. // (for a single-byte ASCII character, it will not be changed). -URL_EXPORT bool ReadUTFChar(const char* str, int* begin, int length, - unsigned* code_point_out); +COMPONENT_EXPORT(URL) +bool ReadUTFChar(const char* str, + int* begin, + int length, + unsigned* code_point_out); // Generic To-UTF-8 converter. This will call the given append method for each // character that should be appended, with the given output method. Wrappers @@ -224,8 +228,11 @@ inline void AppendUTF8EscapedValue(unsigned char_value, CanonOutput* output) { // |*begin| will be updated to point to the last character consumed so it // can be incremented in a loop and will be ready for the next character. // (for a single-16-bit-word character, it will not be changed). -URL_EXPORT bool ReadUTFChar(const base::char16* str, int* begin, int length, - unsigned* code_point_out); +COMPONENT_EXPORT(URL) +bool ReadUTFChar(const base::char16* str, + int* begin, + int length, + unsigned* code_point_out); // Equivalent to U16_APPEND_UNSAFE in ICU but uses our output method. inline void AppendUTF16Value(unsigned code_point, @@ -343,10 +350,14 @@ void AppendInvalidNarrowString(const base::char16* spec, int begin, int end, // replacing the invalid characters with the "invalid character". It will // return false in the failure case, and the caller should not continue as // normal. -URL_EXPORT bool ConvertUTF16ToUTF8(const base::char16* input, int input_len, - CanonOutput* output); -URL_EXPORT bool ConvertUTF8ToUTF16(const char* input, int input_len, - CanonOutputT<base::char16>* output); +COMPONENT_EXPORT(URL) +bool ConvertUTF16ToUTF8(const base::char16* input, + int input_len, + CanonOutput* output); +COMPONENT_EXPORT(URL) +bool ConvertUTF8ToUTF16(const char* input, + int input_len, + CanonOutputT<base::char16>* output); // Converts from UTF-16 to 8-bit using the character set converter. If the // converter is NULL, this will use UTF-8. @@ -405,10 +416,10 @@ bool CanonicalizePartialPath(const base::char16* spec, #ifndef WIN32 // Implementations of Windows' int-to-string conversions -URL_EXPORT int _itoa_s(int value, char* buffer, size_t size_in_chars, - int radix); -URL_EXPORT int _itow_s(int value, base::char16* buffer, size_t size_in_chars, - int radix); +COMPONENT_EXPORT(URL) +int _itoa_s(int value, char* buffer, size_t size_in_chars, int radix); +COMPONENT_EXPORT(URL) +int _itow_s(int value, base::char16* buffer, size_t size_in_chars, int radix); // Secure template overloads for these functions template<size_t N> diff --git a/chromium/url/url_canon_ip.h b/chromium/url/url_canon_ip.h index 937bd460f10..d3cad367ff2 100644 --- a/chromium/url/url_canon_ip.h +++ b/chromium/url/url_canon_ip.h @@ -5,20 +5,20 @@ #ifndef URL_URL_CANON_IP_H_ #define URL_URL_CANON_IP_H_ +#include "base/component_export.h" #include "base/strings/string16.h" #include "url/third_party/mozilla/url_parse.h" #include "url/url_canon.h" -#include "url/url_export.h" namespace url { // Writes the given IPv4 address to |output|. -URL_EXPORT void AppendIPv4Address(const unsigned char address[4], - CanonOutput* output); +COMPONENT_EXPORT(URL) +void AppendIPv4Address(const unsigned char address[4], CanonOutput* output); // Writes the given IPv6 address to |output|. -URL_EXPORT void AppendIPv6Address(const unsigned char address[16], - CanonOutput* output); +COMPONENT_EXPORT(URL) +void AppendIPv6Address(const unsigned char address[16], CanonOutput* output); // Searches the host name for the portions of the IPv4 address. On success, // each component will be placed into |components| and it will return true. @@ -38,12 +38,14 @@ URL_EXPORT void AppendIPv6Address(const unsigned char address[16], // so this code path never gets hit. Our host canonicalization will notice // these spaces and escape them, which will make IP address finding fail. This // seems like better behavior than stripping after a space. -URL_EXPORT bool FindIPv4Components(const char* spec, - const Component& host, - Component components[4]); -URL_EXPORT bool FindIPv4Components(const base::char16* spec, - const Component& host, - Component components[4]); +COMPONENT_EXPORT(URL) +bool FindIPv4Components(const char* spec, + const Component& host, + Component components[4]); +COMPONENT_EXPORT(URL) +bool FindIPv4Components(const base::char16* spec, + const Component& host, + Component components[4]); // Converts an IPv4 address to a 32-bit number (network byte order). // @@ -56,26 +58,30 @@ URL_EXPORT bool FindIPv4Components(const base::char16* spec, // // On success, |num_ipv4_components| will be populated with the number of // components in the IPv4 address. -URL_EXPORT CanonHostInfo::Family IPv4AddressToNumber(const char* spec, - const Component& host, - unsigned char address[4], - int* num_ipv4_components); -URL_EXPORT CanonHostInfo::Family IPv4AddressToNumber(const base::char16* spec, - const Component& host, - unsigned char address[4], - int* num_ipv4_components); +COMPONENT_EXPORT(URL) +CanonHostInfo::Family IPv4AddressToNumber(const char* spec, + const Component& host, + unsigned char address[4], + int* num_ipv4_components); +COMPONENT_EXPORT(URL) +CanonHostInfo::Family IPv4AddressToNumber(const base::char16* spec, + const Component& host, + unsigned char address[4], + int* num_ipv4_components); // Converts an IPv6 address to a 128-bit number (network byte order), returning // true on success. False means that the input was not a valid IPv6 address. // // NOTE that |host| is expected to be surrounded by square brackets. // i.e. "[::1]" rather than "::1". -URL_EXPORT bool IPv6AddressToNumber(const char* spec, - const Component& host, - unsigned char address[16]); -URL_EXPORT bool IPv6AddressToNumber(const base::char16* spec, - const Component& host, - unsigned char address[16]); +COMPONENT_EXPORT(URL) +bool IPv6AddressToNumber(const char* spec, + const Component& host, + unsigned char address[16]); +COMPONENT_EXPORT(URL) +bool IPv6AddressToNumber(const base::char16* spec, + const Component& host, + unsigned char address[16]); } // namespace url diff --git a/chromium/url/url_canon_stdstring.h b/chromium/url/url_canon_stdstring.h index f36f3a9bfa2..f693bd08f43 100644 --- a/chromium/url/url_canon_stdstring.h +++ b/chromium/url/url_canon_stdstring.h @@ -12,9 +12,9 @@ #include <string> #include "base/compiler_specific.h" +#include "base/component_export.h" #include "base/strings/string_piece.h" #include "url/url_canon.h" -#include "url/url_export.h" namespace url { @@ -33,7 +33,7 @@ namespace url { // // Therefore, the user should call Complete() before using the string that // this class wrote into. -class URL_EXPORT StdStringCanonOutput : public CanonOutput { +class COMPONENT_EXPORT(URL) StdStringCanonOutput : public CanonOutput { public: StdStringCanonOutput(std::string* str); ~StdStringCanonOutput() override; diff --git a/chromium/url/url_canon_unittest.cc b/chromium/url/url_canon_unittest.cc index a29db7f9cff..3f80036bf5f 100644 --- a/chromium/url/url_canon_unittest.cc +++ b/chromium/url/url_canon_unittest.cc @@ -5,7 +5,7 @@ #include <errno.h> #include <stddef.h> -#include "base/macros.h" +#include "base/stl_util.h" #include "base/strings/utf_string_conversions.h" #include "testing/gtest/include/gtest/gtest.h" #include "url/third_party/mozilla/url_parse.h" @@ -114,7 +114,7 @@ TEST(URLCanonTest, DoAppendUTF8) { {0x10FFFF, "\xF4\x8F\xBF\xBF"}, }; std::string out_str; - for (size_t i = 0; i < arraysize(utf_cases); i++) { + for (size_t i = 0; i < base::size(utf_cases); i++) { out_str.clear(); StdStringCanonOutput output(&out_str); AppendUTF8Value(utf_cases[i].input, &output); @@ -177,7 +177,7 @@ TEST(URLCanonTest, UTF) { }; std::string out_str; - for (size_t i = 0; i < arraysize(utf_cases); i++) { + for (size_t i = 0; i < base::size(utf_cases); i++) { if (utf_cases[i].input8) { out_str.clear(); StdStringCanonOutput output(&out_str); @@ -248,7 +248,7 @@ TEST(URLCanonTest, Scheme) { std::string out_str; - for (size_t i = 0; i < arraysize(scheme_cases); i++) { + for (size_t i = 0; i < base::size(scheme_cases); i++) { int url_len = static_cast<int>(strlen(scheme_cases[i].input)); Component in_comp(0, url_len); Component out_comp; @@ -513,7 +513,7 @@ TEST(URLCanonTest, Host) { // CanonicalizeHost() non-verbose. std::string out_str; - for (size_t i = 0; i < arraysize(host_cases); i++) { + for (size_t i = 0; i < base::size(host_cases); i++) { // Narrow version. if (host_cases[i].input8) { int host_len = static_cast<int>(strlen(host_cases[i].input8)); @@ -561,7 +561,7 @@ TEST(URLCanonTest, Host) { } // CanonicalizeHostVerbose() - for (size_t i = 0; i < arraysize(host_cases); i++) { + for (size_t i = 0; i < base::size(host_cases); i++) { // Narrow version. if (host_cases[i].input8) { int host_len = static_cast<int>(strlen(host_cases[i].input8)); @@ -691,7 +691,7 @@ TEST(URLCanonTest, IPv4) { {"0.00.0x.0x0", L"0.00.0x.0x0", "0.0.0.0", Component(0, 7), CanonHostInfo::IPV4, 4, "00000000"}, }; - for (size_t i = 0; i < arraysize(cases); i++) { + for (size_t i = 0; i < base::size(cases); i++) { // 8-bit version. Component component(0, static_cast<int>(strlen(cases[i].input8))); @@ -845,7 +845,7 @@ TEST(URLCanonTest, IPv6) { {"[::1 hello]", L"[::1 hello]", "", Component(), CanonHostInfo::BROKEN, -1, ""}, }; - for (size_t i = 0; i < arraysize(cases); i++) { + for (size_t i = 0; i < base::size(cases); i++) { // 8-bit version. Component component(0, static_cast<int>(strlen(cases[i].input8))); @@ -971,7 +971,7 @@ TEST(URLCanonTest, UserInfo) { {"ftp://me\\mydomain:pass@foo.com/", "", Component(0, -1), Component(0, -1), true}, }; - for (size_t i = 0; i < arraysize(user_info_cases); i++) { + for (size_t i = 0; i < base::size(user_info_cases); i++) { int url_len = static_cast<int>(strlen(user_info_cases[i].input)); Parsed parsed; ParseStandardURL(user_info_cases[i].input, url_len, &parsed); @@ -1040,7 +1040,7 @@ TEST(URLCanonTest, Port) { {"80", PORT_UNSPECIFIED, ":80", Component(1, 2), true}, }; - for (size_t i = 0; i < arraysize(port_cases); i++) { + for (size_t i = 0; i < base::size(port_cases); i++) { int url_len = static_cast<int>(strlen(port_cases[i].input)); Component in_comp(0, url_len); Component out_comp; @@ -1163,7 +1163,7 @@ TEST(URLCanonTest, Path) { {NULL, L"/\xfdd0zyx", "/%EF%BF%BDzyx", Component(0, 13), false}, }; - for (size_t i = 0; i < arraysize(path_cases); i++) { + for (size_t i = 0; i < base::size(path_cases); i++) { if (path_cases[i].input8) { int len = static_cast<int>(strlen(path_cases[i].input8)); Component in_comp(0, len); @@ -1240,7 +1240,7 @@ TEST(URLCanonTest, Query) { {"q=\"asdf\"", L"q=\"asdf\"", "?q=%22asdf%22"}, }; - for (size_t i = 0; i < arraysize(query_cases); i++) { + for (size_t i = 0; i < base::size(query_cases); i++) { Component out_comp; if (query_cases[i].input8) { @@ -1312,7 +1312,7 @@ TEST(URLCanonTest, Ref) { {"#asdf", L"#asdf", "##asdf", Component(1, 5), true}, }; - for (size_t i = 0; i < arraysize(ref_cases); i++) { + for (size_t i = 0; i < base::size(ref_cases); i++) { // 8-bit input if (ref_cases[i].input8) { int len = static_cast<int>(strlen(ref_cases[i].input8)); @@ -1424,7 +1424,7 @@ TEST(URLCanonTest, CanonicalizeStandardURL) { "ws://%29w%1ew%81/", false}, }; - for (size_t i = 0; i < arraysize(cases); i++) { + for (size_t i = 0; i < base::size(cases); i++) { int url_len = static_cast<int>(strlen(cases[i].input)); Parsed parsed; ParseStandardURL(cases[i].input, url_len, &parsed); @@ -1457,7 +1457,7 @@ TEST(URLCanonTest, ReplaceStandardURL) { {"http://a:b@google.com:22/foo?baz@cat", "filesystem", NULL, NULL, NULL, NULL, NULL, NULL, NULL, "filesystem://a:b@google.com:22/foo?baz@cat"}, }; - for (size_t i = 0; i < arraysize(replace_cases); i++) { + for (size_t i = 0; i < base::size(replace_cases); i++) { const ReplaceCase& cur = replace_cases[i]; int base_len = static_cast<int>(strlen(cur.base)); Parsed parsed; @@ -1540,7 +1540,7 @@ TEST(URLCanonTest, ReplaceFileURL) { {"file:///C:/gaba?query#ref", "http", NULL, NULL, NULL, NULL, NULL, NULL, NULL, "file:///C:/gaba?query#ref"}, }; - for (size_t i = 0; i < arraysize(replace_cases); i++) { + for (size_t i = 0; i < base::size(replace_cases); i++) { const ReplaceCase& cur = replace_cases[i]; int base_len = static_cast<int>(strlen(cur.base)); Parsed parsed; @@ -1605,7 +1605,7 @@ TEST(URLCanonTest, ReplaceFileSystemURL) { "filesystem:http://bar.com:40/t/gaba?query#ref"}, }; - for (size_t i = 0; i < arraysize(replace_cases); i++) { + for (size_t i = 0; i < base::size(replace_cases); i++) { const ReplaceCase& cur = replace_cases[i]; int base_len = static_cast<int>(strlen(cur.base)); Parsed parsed; @@ -1644,7 +1644,7 @@ TEST(URLCanonTest, ReplacePathURL) { {"data:foo", NULL, NULL, NULL, NULL, NULL, kDeleteComp, NULL, NULL, "data:"}, }; - for (size_t i = 0; i < arraysize(replace_cases); i++) { + for (size_t i = 0; i < base::size(replace_cases); i++) { const ReplaceCase& cur = replace_cases[i]; int base_len = static_cast<int>(strlen(cur.base)); Parsed parsed; @@ -1695,7 +1695,7 @@ TEST(URLCanonTest, ReplaceMailtoURL) { {"mailto:addr1", NULL, NULL, NULL, NULL, NULL, NULL, NULL, "BLAH", "mailto:addr1"}, }; - for (size_t i = 0; i < arraysize(replace_cases); i++) { + for (size_t i = 0; i < base::size(replace_cases); i++) { const ReplaceCase& cur = replace_cases[i]; int base_len = static_cast<int>(strlen(cur.base)); Parsed parsed; @@ -1800,7 +1800,7 @@ TEST(URLCanonTest, CanonicalizeFileURL) { #endif // _WIN32 }; - for (size_t i = 0; i < arraysize(cases); i++) { + for (size_t i = 0; i < base::size(cases); i++) { int url_len = static_cast<int>(strlen(cases[i].input)); Parsed parsed; ParseFileURL(cases[i].input, url_len, &parsed); @@ -1843,7 +1843,7 @@ TEST(URLCanonTest, CanonicalizeFileSystemURL) { {"filesystem:File:///temporary/Bob?qUery#reF", "filesystem:file:///temporary/Bob?qUery#reF", true}, }; - for (size_t i = 0; i < arraysize(cases); i++) { + for (size_t i = 0; i < base::size(cases); i++) { int url_len = static_cast<int>(strlen(cases[i].input)); Parsed parsed; ParseFileSystemURL(cases[i].input, url_len, &parsed); @@ -1878,7 +1878,7 @@ TEST(URLCanonTest, CanonicalizePathURL) { {"Foo:\":This /is interesting;?#", "foo:\":This /is interesting;?#"}, }; - for (size_t i = 0; i < arraysize(path_cases); i++) { + for (size_t i = 0; i < base::size(path_cases); i++) { int url_len = static_cast<int>(strlen(path_cases[i].input)); Parsed parsed; ParsePathURL(path_cases[i].input, url_len, true, &parsed); @@ -1963,7 +1963,7 @@ TEST(URLCanonTest, CanonicalizeMailtoURL) { Parsed parsed; Parsed out_parsed; - for (size_t i = 0; i < arraysize(cases); i++) { + for (size_t i = 0; i < base::size(cases); i++) { int url_len = static_cast<int>(strlen(cases[i].input)); if (i == 0) { // The first test case purposely has a '\0' in it -- don't count it @@ -2229,7 +2229,7 @@ TEST(URLCanonTest, ResolveRelativeURL) { {"about:blank", false, false, "content://content.Provider/", true, false, true, ""}, }; - for (size_t i = 0; i < arraysize(rel_cases); i++) { + for (size_t i = 0; i < base::size(rel_cases); i++) { const RelativeCase& cur_case = rel_cases[i]; Parsed parsed; diff --git a/chromium/url/url_constants.h b/chromium/url/url_constants.h index e06af29979f..38a0e38ce8a 100644 --- a/chromium/url/url_constants.h +++ b/chromium/url/url_constants.h @@ -7,36 +7,36 @@ #include <stddef.h> -#include "url/url_export.h" +#include "base/component_export.h" namespace url { -URL_EXPORT extern const char kAboutBlankURL[]; +COMPONENT_EXPORT(URL) extern const char kAboutBlankURL[]; -URL_EXPORT extern const char kAboutBlankPath[]; -URL_EXPORT extern const char kAboutBlankWithHashPath[]; +COMPONENT_EXPORT(URL) extern const char kAboutBlankPath[]; +COMPONENT_EXPORT(URL) extern const char kAboutBlankWithHashPath[]; -URL_EXPORT extern const char kAboutScheme[]; -URL_EXPORT extern const char kBlobScheme[]; +COMPONENT_EXPORT(URL) extern const char kAboutScheme[]; +COMPONENT_EXPORT(URL) extern const char kBlobScheme[]; // The content scheme is specific to Android for identifying a stored file. -URL_EXPORT extern const char kContentScheme[]; -URL_EXPORT extern const char kContentIDScheme[]; -URL_EXPORT extern const char kDataScheme[]; -URL_EXPORT extern const char kFileScheme[]; -URL_EXPORT extern const char kFileSystemScheme[]; -URL_EXPORT extern const char kFtpScheme[]; -URL_EXPORT extern const char kGopherScheme[]; -URL_EXPORT extern const char kHttpScheme[]; -URL_EXPORT extern const char kHttpsScheme[]; -URL_EXPORT extern const char kJavaScriptScheme[]; -URL_EXPORT extern const char kMailToScheme[]; -URL_EXPORT extern const char kWsScheme[]; -URL_EXPORT extern const char kWssScheme[]; +COMPONENT_EXPORT(URL) extern const char kContentScheme[]; +COMPONENT_EXPORT(URL) extern const char kContentIDScheme[]; +COMPONENT_EXPORT(URL) extern const char kDataScheme[]; +COMPONENT_EXPORT(URL) extern const char kFileScheme[]; +COMPONENT_EXPORT(URL) extern const char kFileSystemScheme[]; +COMPONENT_EXPORT(URL) extern const char kFtpScheme[]; +COMPONENT_EXPORT(URL) extern const char kGopherScheme[]; +COMPONENT_EXPORT(URL) extern const char kHttpScheme[]; +COMPONENT_EXPORT(URL) extern const char kHttpsScheme[]; +COMPONENT_EXPORT(URL) extern const char kJavaScriptScheme[]; +COMPONENT_EXPORT(URL) extern const char kMailToScheme[]; +COMPONENT_EXPORT(URL) extern const char kWsScheme[]; +COMPONENT_EXPORT(URL) extern const char kWssScheme[]; // Used to separate a standard scheme and the hostname: "://". -URL_EXPORT extern const char kStandardSchemeSeparator[]; +COMPONENT_EXPORT(URL) extern const char kStandardSchemeSeparator[]; -URL_EXPORT extern const size_t kMaxURLChars; +COMPONENT_EXPORT(URL) extern const size_t kMaxURLChars; } // namespace url diff --git a/chromium/url/url_export.h b/chromium/url/url_export.h deleted file mode 100644 index 15ef19e23d8..00000000000 --- a/chromium/url/url_export.h +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2013 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_EXPORT_H_ -#define URL_URL_EXPORT_H_ - -#if defined(COMPONENT_BUILD) -#if defined(WIN32) - -#if defined(URL_IMPLEMENTATION) -#define URL_EXPORT __declspec(dllexport) -#else -#define URL_EXPORT __declspec(dllimport) -#endif // defined(URL_IMPLEMENTATION) - -#else // !defined(WIN32) - -#if defined(URL_IMPLEMENTATION) -#define URL_EXPORT __attribute__((visibility("default"))) -#else -#define URL_EXPORT -#endif // defined(URL_IMPLEMENTATION) - -#endif // defined(WIN32) - -#else // !defined(COMPONENT_BUILD) - -#define URL_EXPORT - -#endif // define(COMPONENT_BUILD) - -#endif // URL_URL_EXPORT_H_ diff --git a/chromium/url/url_parse_perftest.cc b/chromium/url/url_parse_perftest.cc new file mode 100644 index 00000000000..6f972cdb572 --- /dev/null +++ b/chromium/url/url_parse_perftest.cc @@ -0,0 +1,135 @@ +// Copyright (c) 2006-2008 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/strings/string_piece.h" +#include "base/test/perf_time_logger.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "url/gurl.h" +#include "url/third_party/mozilla/url_parse.h" +#include "url/url_canon.h" +#include "url/url_canon_stdstring.h" + +namespace { + +TEST(URLParse, FullURL) { + constexpr base::StringPiece kUrl = + "http://me:pass@host/foo/bar.html;param?query=yes#ref"; + + url::Parsed parsed; + base::PerfTimeLogger timer("Full_URL_Parse_AMillion"); + + for (int i = 0; i < 1000000; i++) + url::ParseStandardURL(kUrl.data(), kUrl.size(), &parsed); + timer.Done(); +} + +constexpr base::StringPiece kTypicalUrl1 = + "http://www.google.com/" + "search?q=url+parsing&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:" + "official&client=firefox-a"; + +constexpr base::StringPiece kTypicalUrl2 = + "http://www.amazon.com/Stephen-King-Thrillers-Horror-People/dp/0766012336/" + "ref=sr_1_2/133-4144931-4505264?ie=UTF8&s=books&qid=2144880915&sr=8-2"; + +constexpr base::StringPiece kTypicalUrl3 = + "http://store.apple.com/1-800-MY-APPLE/WebObjects/AppleStore.woa/wa/" + "RSLID?nnmm=browse&mco=578E9744&node=home/desktop/mac_pro"; + +TEST(URLParse, TypicalURLParse) { + url::Parsed parsed1; + url::Parsed parsed2; + url::Parsed parsed3; + + // Do this 1/3 of a million times since we do 3 different URLs. + base::PerfTimeLogger parse_timer("Typical_URL_Parse_AMillion"); + for (int i = 0; i < 333333; i++) { + url::ParseStandardURL(kTypicalUrl1.data(), kTypicalUrl1.size(), &parsed1); + url::ParseStandardURL(kTypicalUrl2.data(), kTypicalUrl2.size(), &parsed2); + url::ParseStandardURL(kTypicalUrl3.data(), kTypicalUrl3.size(), &parsed3); + } + parse_timer.Done(); +} + +// Includes both parsing and canonicalization with no mallocs. +TEST(URLParse, TypicalURLParseCanon) { + url::Parsed parsed1; + url::Parsed parsed2; + url::Parsed parsed3; + + base::PerfTimeLogger canon_timer("Typical_Parse_Canon_AMillion"); + url::Parsed out_parsed; + url::RawCanonOutput<1024> output; + for (int i = 0; i < 333333; i++) { // divide by 3 so we get 1M + url::ParseStandardURL(kTypicalUrl1.data(), kTypicalUrl1.size(), &parsed1); + output.set_length(0); + url::CanonicalizeStandardURL( + kTypicalUrl1.data(), kTypicalUrl1.size(), parsed1, + url::SCHEME_WITH_HOST_PORT_AND_USER_INFORMATION, nullptr, &output, + &out_parsed); + + url::ParseStandardURL(kTypicalUrl2.data(), kTypicalUrl2.size(), &parsed2); + output.set_length(0); + url::CanonicalizeStandardURL( + kTypicalUrl2.data(), kTypicalUrl2.size(), parsed2, + url::SCHEME_WITH_HOST_PORT_AND_USER_INFORMATION, nullptr, &output, + &out_parsed); + + url::ParseStandardURL(kTypicalUrl3.data(), kTypicalUrl3.size(), &parsed3); + output.set_length(0); + url::CanonicalizeStandardURL( + kTypicalUrl3.data(), kTypicalUrl3.size(), parsed3, + url::SCHEME_WITH_HOST_PORT_AND_USER_INFORMATION, nullptr, &output, + &out_parsed); + } + canon_timer.Done(); +} + +// Includes both parsing and canonicalization, and mallocs for the output. +TEST(URLParse, TypicalURLParseCanonStdString) { + url::Parsed parsed1; + url::Parsed parsed2; + url::Parsed parsed3; + + base::PerfTimeLogger canon_timer("Typical_Parse_Canon_AMillion"); + url::Parsed out_parsed; + for (int i = 0; i < 333333; i++) { // divide by 3 so we get 1M + url::ParseStandardURL(kTypicalUrl1.data(), kTypicalUrl1.size(), &parsed1); + std::string out1; + url::StdStringCanonOutput output1(&out1); + url::CanonicalizeStandardURL( + kTypicalUrl1.data(), kTypicalUrl1.size(), parsed1, + url::SCHEME_WITH_HOST_PORT_AND_USER_INFORMATION, nullptr, &output1, + &out_parsed); + + url::ParseStandardURL(kTypicalUrl2.data(), kTypicalUrl2.size(), &parsed2); + std::string out2; + url::StdStringCanonOutput output2(&out2); + url::CanonicalizeStandardURL( + kTypicalUrl2.data(), kTypicalUrl2.size(), parsed2, + url::SCHEME_WITH_HOST_PORT_AND_USER_INFORMATION, nullptr, &output2, + &out_parsed); + + url::ParseStandardURL(kTypicalUrl3.data(), kTypicalUrl3.size(), &parsed3); + std::string out3; + url::StdStringCanonOutput output3(&out3); + url::CanonicalizeStandardURL( + kTypicalUrl3.data(), kTypicalUrl3.size(), parsed3, + url::SCHEME_WITH_HOST_PORT_AND_USER_INFORMATION, nullptr, &output3, + &out_parsed); + } + canon_timer.Done(); +} + +TEST(URLParse, GURL) { + base::PerfTimeLogger gurl_timer("Typical_GURL_AMillion"); + for (int i = 0; i < 333333; i++) { // divide by 3 so we get 1M + GURL gurl1(kTypicalUrl1); + GURL gurl2(kTypicalUrl2); + GURL gurl3(kTypicalUrl3); + } + gurl_timer.Done(); +} + +} // namespace diff --git a/chromium/url/url_parse_unittest.cc b/chromium/url/url_parse_unittest.cc index b80e865661a..4160e49ca00 100644 --- a/chromium/url/url_parse_unittest.cc +++ b/chromium/url/url_parse_unittest.cc @@ -6,7 +6,7 @@ #include <stddef.h> -#include "base/macros.h" +#include "base/stl_util.h" #include "testing/gtest/include/gtest/gtest.h" #include "url/third_party/mozilla/url_parse.h" @@ -137,7 +137,7 @@ TEST(URLParser, Length) { "http://user@", "http:", }; - for (size_t i = 0; i < arraysize(length_cases); i++) { + for (size_t i = 0; i < base::size(length_cases); i++) { int true_length = static_cast<int>(strlen(length_cases[i])); Parsed parsed; @@ -196,7 +196,7 @@ TEST(URLParser, CountCharactersBefore) { {"file:///c:/foo", Parsed::HOST, true, 7}, {"file:///c:/foo", Parsed::PATH, true, 7}, }; - for (size_t i = 0; i < arraysize(count_cases); i++) { + for (size_t i = 0; i < base::size(count_cases); i++) { int length = static_cast<int>(strlen(count_cases[i].url)); // Simple test to distinguish file and standard URLs. @@ -314,7 +314,7 @@ TEST(URLParser, Standard) { // Declared outside for loop to try to catch cases in init() where we forget // to reset something that is reset by the constructor. Parsed parsed; - for (size_t i = 0; i < arraysize(cases); i++) { + for (size_t i = 0; i < base::size(cases); i++) { const char* url = cases[i].input; ParseStandardURL(url, static_cast<int>(strlen(url)), &parsed); int port = ParsePort(url, parsed.port); @@ -349,7 +349,7 @@ TEST(URLParser, PathURL) { // Declared outside for loop to try to catch cases in init() where we forget // to reset something that is reset by the constructor. Parsed parsed; - for (size_t i = 0; i < arraysize(path_cases); i++) { + for (size_t i = 0; i < base::size(path_cases); i++) { const char* url = path_cases[i].input; ParsePathURL(url, static_cast<int>(strlen(url)), false, &parsed); @@ -448,7 +448,7 @@ TEST(URLParser, ParseFileURL) { // Declared outside for loop to try to catch cases in init() where we forget // to reset something that is reset by the construtor. Parsed parsed; - for (size_t i = 0; i < arraysize(file_cases); i++) { + for (size_t i = 0; i < base::size(file_cases); i++) { const char* url = file_cases[i].input; ParseFileURL(url, static_cast<int>(strlen(url)), &parsed); int port = ParsePort(url, parsed.port); @@ -509,7 +509,7 @@ TEST(URLParser, ExtractFileName) { {"http://www.google.com/foo;bar;html", "foo"}, }; - for (size_t i = 0; i < arraysize(file_cases); i++) { + for (size_t i = 0; i < base::size(file_cases); i++) { const char* url = file_cases[i].input; int len = static_cast<int>(strlen(url)); @@ -617,7 +617,7 @@ TEST(URLParser, MailtoUrl) { // Declared outside for loop to try to catch cases in init() where we forget // to reset something that is reset by the constructor. Parsed parsed; - for (size_t i = 0; i < arraysize(mailto_cases); ++i) { + for (size_t i = 0; i < base::size(mailto_cases); ++i) { const char* url = mailto_cases[i].input; ParseMailtoURL(url, static_cast<int>(strlen(url)), &parsed); int port = ParsePort(url, parsed.port); @@ -649,7 +649,7 @@ TEST(URLParser, FileSystemURL) { // Declared outside for loop to try to catch cases in init() where we forget // to reset something that is reset by the constructor. Parsed parsed; - for (size_t i = 0; i < arraysize(filesystem_cases); i++) { + for (size_t i = 0; i < base::size(filesystem_cases); i++) { const FileSystemURLParseCase* parsecase = &filesystem_cases[i]; const char* url = parsecase->input; ParseFileSystemURL(url, static_cast<int>(strlen(url)), &parsed); diff --git a/chromium/url/url_util.cc b/chromium/url/url_util.cc index 29cebf96899..d56d0410457 100644 --- a/chromium/url/url_util.cc +++ b/chromium/url/url_util.cc @@ -799,9 +799,10 @@ bool ReplaceComponents(const char* spec, charset_converter, output, out_parsed); } -DecodeURLResult DecodeURLEscapeSequences(const char* input, - int length, - CanonOutputW* output) { +void DecodeURLEscapeSequences(const char* input, + int length, + DecodeURLMode mode, + CanonOutputW* output) { RawCanonOutputT<char> unescaped_chars; for (int i = 0; i < length; i++) { if (input[i] == '%') { @@ -819,8 +820,6 @@ DecodeURLResult DecodeURLEscapeSequences(const char* input, } int output_initial_length = output->length(); - bool did_utf8_decode = false; - bool did_isomorphic_decode = false; // Convert that 8-bit to UTF-16. It's not clear IE does this at all to // JavaScript URLs, but Firefox and Safari do. for (int i = 0; i < unescaped_chars.length(); i++) { @@ -838,28 +837,22 @@ DecodeURLResult DecodeURLEscapeSequences(const char* input, // Valid UTF-8 character, convert to UTF-16. AppendUTF16Value(code_point, output); i = next_character; - did_utf8_decode = true; + } else if (mode == DecodeURLMode::kUTF8) { + DCHECK_EQ(code_point, 0xFFFDU); + AppendUTF16Value(code_point, output); + i = next_character; } else { // If there are any sequences that are not valid UTF-8, we // revert |output| changes, and promote any bytes to UTF-16. We // copy all characters from the beginning to the end of the // identified sequence. output->set_length(output_initial_length); - did_utf8_decode = false; for (int j = 0; j < unescaped_chars.length(); ++j) output->push_back(static_cast<unsigned char>(unescaped_chars.at(j))); - did_isomorphic_decode = true; break; } } } - - DCHECK(!(did_utf8_decode && did_isomorphic_decode)); - if (did_isomorphic_decode) - return DecodeURLResult::kIsomorphic; - if (did_utf8_decode) - return DecodeURLResult::kUTF8; - return DecodeURLResult::kAsciiOnly; } void EncodeURIComponent(const char* input, int length, CanonOutput* output) { diff --git a/chromium/url/url_util.h b/chromium/url/url_util.h index ee456a02cc0..0bd9f40718d 100644 --- a/chromium/url/url_util.h +++ b/chromium/url/url_util.h @@ -8,12 +8,12 @@ #include <string> #include <vector> +#include "base/component_export.h" #include "base/strings/string16.h" #include "base/strings/string_piece.h" #include "url/third_party/mozilla/url_parse.h" #include "url/url_canon.h" #include "url/url_constants.h" -#include "url/url_export.h" namespace url { @@ -29,13 +29,13 @@ namespace url { // It is OK to call this function more than once, subsequent calls will be // no-ops, unless Shutdown was called in the mean time. This will also be a // no-op if other calls to the library have forced an initialization beforehand. -URL_EXPORT void Initialize(); +COMPONENT_EXPORT(URL) void Initialize(); // Cleanup is not required, except some strings may leak. For most user // applications, this is fine. If you're using it in a library that may get // loaded and unloaded, you'll want to unload to properly clean up your // library. -URL_EXPORT void Shutdown(); +COMPONENT_EXPORT(URL) void Shutdown(); // Schemes --------------------------------------------------------------------- @@ -45,13 +45,13 @@ URL_EXPORT void Shutdown(); // compatibility, which allows the use of custom schemes: content hosted in // Android WebView assumes that one URL with a non-standard scheme will be // same-origin to another URL with the same non-standard scheme. -URL_EXPORT void EnableNonStandardSchemesForAndroidWebView(); +COMPONENT_EXPORT(URL) void EnableNonStandardSchemesForAndroidWebView(); // Whether or not SchemeHostPort and Origin allow non-standard schemes. -URL_EXPORT bool AllowNonStandardSchemesForAndroidWebView(); +COMPONENT_EXPORT(URL) bool AllowNonStandardSchemesForAndroidWebView(); // A pair for representing a standard scheme name and the SchemeType for it. -struct URL_EXPORT SchemeWithType { +struct COMPONENT_EXPORT(URL) SchemeWithType { const char* scheme; SchemeType type; }; @@ -64,53 +64,53 @@ struct URL_EXPORT SchemeWithType { // URL schemes. A standard-format scheme adheres to what RFC 3986 calls "generic // URI syntax" (https://tools.ietf.org/html/rfc3986#section-3). -URL_EXPORT void AddStandardScheme(const char* new_scheme, - SchemeType scheme_type); +COMPONENT_EXPORT(URL) +void AddStandardScheme(const char* new_scheme, SchemeType scheme_type); // Adds an application-defined scheme to the internal list of schemes allowed // for referrers. -URL_EXPORT void AddReferrerScheme(const char* new_scheme, - SchemeType scheme_type); +COMPONENT_EXPORT(URL) +void AddReferrerScheme(const char* new_scheme, SchemeType scheme_type); // Adds an application-defined scheme to the list of schemes that do not trigger // mixed content warnings. -URL_EXPORT void AddSecureScheme(const char* new_scheme); -URL_EXPORT const std::vector<std::string>& GetSecureSchemes(); +COMPONENT_EXPORT(URL) void AddSecureScheme(const char* new_scheme); +COMPONENT_EXPORT(URL) const std::vector<std::string>& GetSecureSchemes(); // Adds an application-defined scheme to the list of schemes that normal pages // cannot link to or access (i.e., with the same security rules as those applied // to "file" URLs). -URL_EXPORT void AddLocalScheme(const char* new_scheme); -URL_EXPORT const std::vector<std::string>& GetLocalSchemes(); +COMPONENT_EXPORT(URL) void AddLocalScheme(const char* new_scheme); +COMPONENT_EXPORT(URL) const std::vector<std::string>& GetLocalSchemes(); // Adds an application-defined scheme to the list of schemes that cause pages // loaded with them to not have access to pages loaded with any other URL // scheme. -URL_EXPORT void AddNoAccessScheme(const char* new_scheme); -URL_EXPORT const std::vector<std::string>& GetNoAccessSchemes(); +COMPONENT_EXPORT(URL) void AddNoAccessScheme(const char* new_scheme); +COMPONENT_EXPORT(URL) const std::vector<std::string>& GetNoAccessSchemes(); // Adds an application-defined scheme to the list of schemes that can be sent // CORS requests. -URL_EXPORT void AddCorsEnabledScheme(const char* new_scheme); -URL_EXPORT const std::vector<std::string>& GetCorsEnabledSchemes(); +COMPONENT_EXPORT(URL) void AddCorsEnabledScheme(const char* new_scheme); +COMPONENT_EXPORT(URL) const std::vector<std::string>& GetCorsEnabledSchemes(); // Adds an application-defined scheme to the list of web schemes that can be // used by web to store data (e.g. cookies, local storage, ...). This is // to differentiate them from schemes that can store data but are not used on // web (e.g. application's internal schemes) or schemes that are used on web but // cannot store data. -URL_EXPORT void AddWebStorageScheme(const char* new_scheme); -URL_EXPORT const std::vector<std::string>& GetWebStorageSchemes(); +COMPONENT_EXPORT(URL) void AddWebStorageScheme(const char* new_scheme); +COMPONENT_EXPORT(URL) const std::vector<std::string>& GetWebStorageSchemes(); // Adds an application-defined scheme to the list of schemes that can bypass the // Content-Security-Policy(CSP) checks. -URL_EXPORT void AddCSPBypassingScheme(const char* new_scheme); -URL_EXPORT const std::vector<std::string>& GetCSPBypassingSchemes(); +COMPONENT_EXPORT(URL) void AddCSPBypassingScheme(const char* new_scheme); +COMPONENT_EXPORT(URL) const std::vector<std::string>& GetCSPBypassingSchemes(); // Adds an application-defined scheme to the list of schemes that are strictly // empty documents, allowing them to commit synchronously. -URL_EXPORT void AddEmptyDocumentScheme(const char* new_scheme); -URL_EXPORT const std::vector<std::string>& GetEmptyDocumentSchemes(); +COMPONENT_EXPORT(URL) void AddEmptyDocumentScheme(const char* new_scheme); +COMPONENT_EXPORT(URL) const std::vector<std::string>& GetEmptyDocumentSchemes(); // Sets a flag to prevent future calls to Add*Scheme from succeeding. // @@ -124,7 +124,7 @@ URL_EXPORT const std::vector<std::string>& GetEmptyDocumentSchemes(); // We could have had Add*Scheme use a lock instead, but that would add // some platform-specific dependencies we don't otherwise have now, and is // overkill considering the normal usage is so simple. -URL_EXPORT void LockSchemeRegistries(); +COMPONENT_EXPORT(URL) void LockSchemeRegistries(); // Locates the scheme in the given string and places it into |found_scheme|, // which may be NULL to indicate the caller does not care about the range. @@ -132,14 +132,16 @@ URL_EXPORT void LockSchemeRegistries(); // Returns whether the given |compare| scheme matches the scheme found in the // input (if any). The |compare| scheme must be a valid canonical scheme or // the result of the comparison is undefined. -URL_EXPORT bool FindAndCompareScheme(const char* str, - int str_len, - const char* compare, - Component* found_scheme); -URL_EXPORT bool FindAndCompareScheme(const base::char16* str, - int str_len, - const char* compare, - Component* found_scheme); +COMPONENT_EXPORT(URL) +bool FindAndCompareScheme(const char* str, + int str_len, + const char* compare, + Component* found_scheme); +COMPONENT_EXPORT(URL) +bool FindAndCompareScheme(const base::char16* str, + int str_len, + const char* compare, + Component* found_scheme); inline bool FindAndCompareScheme(const std::string& str, const char* compare, Component* found_scheme) { @@ -155,22 +157,27 @@ inline bool FindAndCompareScheme(const base::string16& str, // Returns true if the given scheme identified by |scheme| within |spec| is in // the list of known standard-format schemes (see AddStandardScheme). -URL_EXPORT bool IsStandard(const char* spec, const Component& scheme); -URL_EXPORT bool IsStandard(const base::char16* spec, const Component& scheme); +COMPONENT_EXPORT(URL) +bool IsStandard(const char* spec, const Component& scheme); +COMPONENT_EXPORT(URL) +bool IsStandard(const base::char16* spec, const Component& scheme); // Returns true if the given scheme identified by |scheme| within |spec| is in // the list of allowed schemes for referrers (see AddReferrerScheme). -URL_EXPORT bool IsReferrerScheme(const char* spec, const Component& scheme); +COMPONENT_EXPORT(URL) +bool IsReferrerScheme(const char* spec, const Component& scheme); // Returns true and sets |type| to the SchemeType of the given scheme // identified by |scheme| within |spec| if the scheme is in the list of known // standard-format schemes (see AddStandardScheme). -URL_EXPORT bool GetStandardSchemeType(const char* spec, - const Component& scheme, - SchemeType* type); -URL_EXPORT bool GetStandardSchemeType(const base::char16* spec, - const Component& scheme, - SchemeType* type); +COMPONENT_EXPORT(URL) +bool GetStandardSchemeType(const char* spec, + const Component& scheme, + SchemeType* type); +COMPONENT_EXPORT(URL) +bool GetStandardSchemeType(const base::char16* spec, + const Component& scheme, + SchemeType* type); // Hosts ---------------------------------------------------------------------- @@ -182,12 +189,13 @@ URL_EXPORT bool GetStandardSchemeType(const base::char16* spec, // If either of the input StringPieces is empty, the return value is false. The // input domain should match host canonicalization rules. i.e. it should be // lowercase except for escape chars. -URL_EXPORT bool DomainIs(base::StringPiece canonical_host, - base::StringPiece canonical_domain); +COMPONENT_EXPORT(URL) +bool DomainIs(base::StringPiece canonical_host, + base::StringPiece canonical_domain); // Returns true if the hostname is an IP address. Note: this function isn't very // cheap, as it must re-parse the host to verify. -URL_EXPORT bool HostIsIPAddress(base::StringPiece host); +COMPONENT_EXPORT(URL) bool HostIsIPAddress(base::StringPiece host); // URL library wrappers -------------------------------------------------------- @@ -201,18 +209,20 @@ URL_EXPORT bool HostIsIPAddress(base::StringPiece host); // Returns true if a valid URL was produced, false if not. On failure, the // output and parsed structures will still be filled and will be consistent, // but they will not represent a loadable URL. -URL_EXPORT bool Canonicalize(const char* spec, - int spec_len, - bool trim_path_end, - CharsetConverter* charset_converter, - CanonOutput* output, - Parsed* output_parsed); -URL_EXPORT bool Canonicalize(const base::char16* spec, - int spec_len, - bool trim_path_end, - CharsetConverter* charset_converter, - CanonOutput* output, - Parsed* output_parsed); +COMPONENT_EXPORT(URL) +bool Canonicalize(const char* spec, + int spec_len, + bool trim_path_end, + CharsetConverter* charset_converter, + CanonOutput* output, + Parsed* output_parsed); +COMPONENT_EXPORT(URL) +bool Canonicalize(const base::char16* spec, + int spec_len, + bool trim_path_end, + CharsetConverter* charset_converter, + CanonOutput* output, + Parsed* output_parsed); // Resolves a potentially relative URL relative to the given parsed base URL. // The base MUST be valid. The resulting canonical URL and parsed information @@ -224,67 +234,67 @@ URL_EXPORT bool Canonicalize(const base::char16* spec, // // Returns true if the output is valid, false if the input could not produce // a valid URL. -URL_EXPORT bool ResolveRelative(const char* base_spec, - int base_spec_len, - const Parsed& base_parsed, - const char* relative, - int relative_length, - CharsetConverter* charset_converter, - CanonOutput* output, - Parsed* output_parsed); -URL_EXPORT bool ResolveRelative(const char* base_spec, - int base_spec_len, - const Parsed& base_parsed, - const base::char16* relative, - int relative_length, - CharsetConverter* charset_converter, - CanonOutput* output, - Parsed* output_parsed); +COMPONENT_EXPORT(URL) +bool ResolveRelative(const char* base_spec, + int base_spec_len, + const Parsed& base_parsed, + const char* relative, + int relative_length, + CharsetConverter* charset_converter, + CanonOutput* output, + Parsed* output_parsed); +COMPONENT_EXPORT(URL) +bool ResolveRelative(const char* base_spec, + int base_spec_len, + const Parsed& base_parsed, + const base::char16* relative, + int relative_length, + CharsetConverter* charset_converter, + CanonOutput* output, + Parsed* output_parsed); // Replaces components in the given VALID input URL. The new canonical URL info // is written to output and out_parsed. // // Returns true if the resulting URL is valid. -URL_EXPORT bool ReplaceComponents(const char* spec, - int spec_len, - const Parsed& parsed, - const Replacements<char>& replacements, - CharsetConverter* charset_converter, - CanonOutput* output, - Parsed* out_parsed); -URL_EXPORT bool ReplaceComponents( - const char* spec, - int spec_len, - const Parsed& parsed, - const Replacements<base::char16>& replacements, - CharsetConverter* charset_converter, - CanonOutput* output, - Parsed* out_parsed); +COMPONENT_EXPORT(URL) +bool ReplaceComponents(const char* spec, + int spec_len, + const Parsed& parsed, + const Replacements<char>& replacements, + CharsetConverter* charset_converter, + CanonOutput* output, + Parsed* out_parsed); +COMPONENT_EXPORT(URL) +bool ReplaceComponents(const char* spec, + int spec_len, + const Parsed& parsed, + const Replacements<base::char16>& replacements, + CharsetConverter* charset_converter, + CanonOutput* output, + Parsed* out_parsed); // String helper functions ----------------------------------------------------- -enum class DecodeURLResult { - // Did not contain code points greater than 0x7F. - kAsciiOnly, - // Did UTF-8 decode only. +enum class DecodeURLMode { + // UTF-8 decode only. Invalid byte sequences are replaced with U+FFFD. kUTF8, - // Did byte to Unicode mapping only. - // https://infra.spec.whatwg.org/#isomorphic-decode - kIsomorphic, + // Try UTF-8 decoding. If the input contains byte sequences invalid + // for UTF-8, apply byte to Unicode mapping. + kUTF8OrIsomorphic, }; // Unescapes the given string using URL escaping rules. -// This function tries to decode non-ASCII characters in UTF-8 first, -// then in isomorphic encoding if UTF-8 decoding failed. -URL_EXPORT DecodeURLResult DecodeURLEscapeSequences(const char* input, - int length, - CanonOutputW* output); +COMPONENT_EXPORT(URL) +void DecodeURLEscapeSequences(const char* input, + int length, + DecodeURLMode mode, + CanonOutputW* output); // Escapes the given string as defined by the JS method encodeURIComponent. See // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/encodeURIComponent -URL_EXPORT void EncodeURIComponent(const char* input, - int length, - CanonOutput* output); +COMPONENT_EXPORT(URL) +void EncodeURIComponent(const char* input, int length, CanonOutput* output); } // namespace url diff --git a/chromium/url/url_util_unittest.cc b/chromium/url/url_util_unittest.cc index 65f3435e9d1..13036af8498 100644 --- a/chromium/url/url_util_unittest.cc +++ b/chromium/url/url_util_unittest.cc @@ -4,7 +4,7 @@ #include <stddef.h> -#include "base/macros.h" +#include "base/stl_util.h" #include "testing/gtest/include/gtest/gtest.h" #include "url/third_party/mozilla/url_parse.h" #include "url/url_canon.h" @@ -199,71 +199,83 @@ TEST_F(URLUtilTest, DecodeURLEscapeSequences) { struct DecodeCase { const char* input; const char* output; - DecodeURLResult result; } decode_cases[] = { - {"hello, world", "hello, world", DecodeURLResult::kAsciiOnly}, + {"hello, world", "hello, world"}, {"%01%02%03%04%05%06%07%08%09%0a%0B%0C%0D%0e%0f/", - "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0B\x0C\x0D\x0e\x0f/", - DecodeURLResult::kAsciiOnly}, + "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0B\x0C\x0D\x0e\x0f/"}, {"%10%11%12%13%14%15%16%17%18%19%1a%1B%1C%1D%1e%1f/", - "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1B\x1C\x1D\x1e\x1f/", - DecodeURLResult::kAsciiOnly}, + "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1B\x1C\x1D\x1e\x1f/"}, {"%20%21%22%23%24%25%26%27%28%29%2a%2B%2C%2D%2e%2f/", - " !\"#$%&'()*+,-.//", DecodeURLResult::kAsciiOnly}, - {"%30%31%32%33%34%35%36%37%38%39%3a%3B%3C%3D%3e%3f/", "0123456789:;<=>?/", - DecodeURLResult::kAsciiOnly}, - {"%40%41%42%43%44%45%46%47%48%49%4a%4B%4C%4D%4e%4f/", "@ABCDEFGHIJKLMNO/", - DecodeURLResult::kAsciiOnly}, + " !\"#$%&'()*+,-.//"}, + {"%30%31%32%33%34%35%36%37%38%39%3a%3B%3C%3D%3e%3f/", + "0123456789:;<=>?/"}, + {"%40%41%42%43%44%45%46%47%48%49%4a%4B%4C%4D%4e%4f/", + "@ABCDEFGHIJKLMNO/"}, {"%50%51%52%53%54%55%56%57%58%59%5a%5B%5C%5D%5e%5f/", - "PQRSTUVWXYZ[\\]^_/", DecodeURLResult::kAsciiOnly}, - {"%60%61%62%63%64%65%66%67%68%69%6a%6B%6C%6D%6e%6f/", "`abcdefghijklmno/", - DecodeURLResult::kAsciiOnly}, + "PQRSTUVWXYZ[\\]^_/"}, + {"%60%61%62%63%64%65%66%67%68%69%6a%6B%6C%6D%6e%6f/", + "`abcdefghijklmno/"}, {"%70%71%72%73%74%75%76%77%78%79%7a%7B%7C%7D%7e%7f/", - "pqrstuvwxyz{|}~\x7f/", DecodeURLResult::kAsciiOnly}, - // Test un-UTF-8-ization. - {"%e4%bd%a0%e5%a5%bd", "\xe4\xbd\xa0\xe5\xa5\xbd", - DecodeURLResult::kUTF8}, + "pqrstuvwxyz{|}~\x7f/"}, + {"%e4%bd%a0%e5%a5%bd", "\xe4\xbd\xa0\xe5\xa5\xbd"}, }; - for (size_t i = 0; i < arraysize(decode_cases); i++) { + for (size_t i = 0; i < base::size(decode_cases); i++) { const char* input = decode_cases[i].input; RawCanonOutputT<base::char16> output; - EXPECT_EQ(decode_cases[i].result, - DecodeURLEscapeSequences(input, strlen(input), &output)); + DecodeURLEscapeSequences(input, strlen(input), + DecodeURLMode::kUTF8OrIsomorphic, &output); EXPECT_EQ(decode_cases[i].output, base::UTF16ToUTF8(base::string16(output.data(), output.length()))); + + RawCanonOutputT<base::char16> output_utf8; + DecodeURLEscapeSequences(input, strlen(input), DecodeURLMode::kUTF8, + &output_utf8); + EXPECT_EQ(decode_cases[i].output, + base::UTF16ToUTF8( + base::string16(output_utf8.data(), output_utf8.length()))); } // Our decode should decode %00 const char zero_input[] = "%00"; RawCanonOutputT<base::char16> zero_output; - DecodeURLEscapeSequences(zero_input, strlen(zero_input), &zero_output); + DecodeURLEscapeSequences(zero_input, strlen(zero_input), DecodeURLMode::kUTF8, + &zero_output); EXPECT_NE("%00", base::UTF16ToUTF8( base::string16(zero_output.data(), zero_output.length()))); // Test the error behavior for invalid UTF-8. - { - const char invalid_input[] = "%e4%a0%e5%a5%bd"; - const base::char16 invalid_expected[6] = {0x00e4, 0x00a0, 0x00e5, - 0x00a5, 0x00bd, 0}; - RawCanonOutputT<base::char16> invalid_output; - EXPECT_EQ(DecodeURLResult::kIsomorphic, - DecodeURLEscapeSequences(invalid_input, strlen(invalid_input), - &invalid_output)); - EXPECT_EQ(base::string16(invalid_expected), - base::string16(invalid_output.data(), invalid_output.length())); - } - { - const char invalid_input[] = "%e4%a0%e5%bd"; - const base::char16 invalid_expected[5] = {0x00e4, 0x00a0, 0x00e5, 0x00bd, - 0}; - RawCanonOutputT<base::char16> invalid_output; - EXPECT_EQ(DecodeURLResult::kIsomorphic, - DecodeURLEscapeSequences(invalid_input, strlen(invalid_input), - &invalid_output)); - EXPECT_EQ(base::string16(invalid_expected), - base::string16(invalid_output.data(), invalid_output.length())); + struct Utf8DecodeCase { + const char* input; + std::vector<base::char16> expected_iso; + std::vector<base::char16> expected_utf8; + } utf8_decode_cases[] = { + // %e5%a5%bd is a valid UTF-8 sequence. U+597D + {"%e4%a0%e5%a5%bd", + {0x00e4, 0x00a0, 0x00e5, 0x00a5, 0x00bd, 0}, + {0xfffd, 0x597d, 0}}, + {"%e5%a5%bd%e4%a0", + {0x00e5, 0x00a5, 0x00bd, 0x00e4, 0x00a0, 0}, + {0x597d, 0xfffd, 0}}, + {"%e4%a0%e5%bd", + {0x00e4, 0x00a0, 0x00e5, 0x00bd, 0}, + {0xfffd, 0xfffd, 0}}, + }; + + for (const auto& test : utf8_decode_cases) { + const char* input = test.input; + RawCanonOutputT<base::char16> output_iso; + DecodeURLEscapeSequences(input, strlen(input), + DecodeURLMode::kUTF8OrIsomorphic, &output_iso); + EXPECT_EQ(base::string16(test.expected_iso.data()), + base::string16(output_iso.data(), output_iso.length())); + + RawCanonOutputT<base::char16> output_utf8; + DecodeURLEscapeSequences(input, strlen(input), DecodeURLMode::kUTF8, + &output_utf8); + EXPECT_EQ(base::string16(test.expected_utf8.data()), + base::string16(output_utf8.data(), output_utf8.length())); } } @@ -291,7 +303,7 @@ TEST_F(URLUtilTest, TestEncodeURIComponent) { "pqrstuvwxyz%7B%7C%7D~%7F"}, }; - for (size_t i = 0; i < arraysize(encode_cases); i++) { + for (size_t i = 0; i < base::size(encode_cases); i++) { const char* input = encode_cases[i].input; RawCanonOutputT<char> buffer; EncodeURIComponent(input, strlen(input), &buffer); @@ -368,7 +380,7 @@ TEST_F(URLUtilTest, TestResolveRelativeWithNonStandardBase) { // adding the requested dot doesn't seem wrong either. {"aaa://a\\", "aaa:.", true, "aaa://a\\."}}; - for (size_t i = 0; i < arraysize(resolve_non_standard_cases); i++) { + for (size_t i = 0; i < base::size(resolve_non_standard_cases); i++) { const ResolveRelativeCase& test_data = resolve_non_standard_cases[i]; Parsed base_parsed; ParsePathURL(test_data.base, strlen(test_data.base), false, &base_parsed); |