summaryrefslogtreecommitdiff
path: root/chromium/url
diff options
context:
space:
mode:
authorAndras Becsi <andras.becsi@digia.com>2013-12-11 21:33:03 +0100
committerAndras Becsi <andras.becsi@digia.com>2013-12-13 12:34:07 +0100
commitf2a33ff9cbc6d19943f1c7fbddd1f23d23975577 (patch)
tree0586a32aa390ade8557dfd6b4897f43a07449578 /chromium/url
parent5362912cdb5eea702b68ebe23702468d17c3017a (diff)
downloadqtwebengine-chromium-f2a33ff9cbc6d19943f1c7fbddd1f23d23975577.tar.gz
Update Chromium to branch 1650 (31.0.1650.63)
Change-Id: I57d8c832eaec1eb2364e0a8e7352a6dd354db99f Reviewed-by: Jocelyn Turcotte <jocelyn.turcotte@digia.com>
Diffstat (limited to 'chromium/url')
-rw-r--r--chromium/url/gurl.cc4
-rw-r--r--chromium/url/gurl.h3
-rw-r--r--chromium/url/gurl_test_main.cc77
-rw-r--r--chromium/url/url_canon_icu.h3
-rw-r--r--chromium/url/url_canon_relative.cc11
-rw-r--r--chromium/url/url_canon_stdstring.h3
-rw-r--r--chromium/url/url_canon_unittest.cc5
-rw-r--r--chromium/url/url_parse_file.cc18
-rw-r--r--chromium/url/url_parse_unittest.cc96
-rw-r--r--chromium/url/url_util_unittest.cc22
10 files changed, 130 insertions, 112 deletions
diff --git a/chromium/url/gurl.cc b/chromium/url/gurl.cc
index 09b8abbcc23..229df5dca2d 100644
--- a/chromium/url/gurl.cc
+++ b/chromium/url/gurl.cc
@@ -367,6 +367,10 @@ bool GURL::SchemeIs(const char* lower_ascii_scheme) const {
lower_ascii_scheme);
}
+bool GURL::SchemeIsHTTPOrHTTPS() const {
+ return SchemeIs("http") || SchemeIs("https");
+}
+
int GURL::IntPort() const {
if (parsed_.port.is_nonempty())
return url_parse::ParsePort(spec_.data(), parsed_.port);
diff --git a/chromium/url/gurl.h b/chromium/url/gurl.h
index da5f73602e3..4b986a6a4de 100644
--- a/chromium/url/gurl.h
+++ b/chromium/url/gurl.h
@@ -203,6 +203,9 @@ class URL_EXPORT GURL {
// object constructions are done.
bool SchemeIs(const char* lower_ascii_scheme) const;
+ // Returns true if the scheme is "http" or "https".
+ bool SchemeIsHTTPOrHTTPS() const;
+
// We often need to know if this is a file URL. File URLs are "standard", but
// are often treated separately by some programs.
bool SchemeIsFile() const {
diff --git a/chromium/url/gurl_test_main.cc b/chromium/url/gurl_test_main.cc
deleted file mode 100644
index d35e5d4df60..00000000000
--- a/chromium/url/gurl_test_main.cc
+++ /dev/null
@@ -1,77 +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.
-
-#include "build/build_config.h"
-
-#if defined(OS_WIN)
-#include <windows.h>
-#endif
-
-#include <string>
-
-#include "testing/gtest/include/gtest/gtest.h"
-#include "third_party/icu/source/common/unicode/putil.h"
-#include "third_party/icu/source/common/unicode/udata.h"
-
-#define ICU_UTIL_DATA_SHARED 1
-#define ICU_UTIL_DATA_STATIC 2
-
-#ifndef ICU_UTIL_DATA_IMPL
-
-#if defined(OS_WIN)
-#define ICU_UTIL_DATA_IMPL ICU_UTIL_DATA_SHARED
-#elif defined(OS_MACOSX)
-#define ICU_UTIL_DATA_IMPL ICU_UTIL_DATA_STATIC
-#elif defined(OS_LINUX)
-#define ICU_UTIL_DATA_IMPL ICU_UTIL_DATA_FILE
-#endif
-
-#endif // ICU_UTIL_DATA_IMPL
-
-#if defined(OS_WIN)
-#define ICU_UTIL_DATA_SYMBOL "icudt" U_ICU_VERSION_SHORT "_dat"
-#define ICU_UTIL_DATA_SHARED_MODULE_NAME "icudt" U_ICU_VERSION_SHORT ".dll"
-#endif
-
-bool InitializeICU() {
-#if (ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_SHARED)
- // We expect to find the ICU data module alongside the current module.
- // Because the module name is ASCII-only, "A" API should be safe.
- // Chrome's copy of ICU dropped a version number XX from icudt dll,
- // but 3rd-party embedders may need it. So, we try both.
- HMODULE module = LoadLibraryA("icudt.dll");
- if (!module) {
- module = LoadLibraryA(ICU_UTIL_DATA_SHARED_MODULE_NAME);
- if (!module)
- return false;
- }
-
- FARPROC addr = GetProcAddress(module, ICU_UTIL_DATA_SYMBOL);
- if (!addr)
- return false;
-
- UErrorCode err = U_ZERO_ERROR;
- udata_setCommonData(reinterpret_cast<void*>(addr), &err);
- return err == U_ZERO_ERROR;
-#elif (ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_STATIC)
- // Mac bundles the ICU data in.
- return true;
-#elif (ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE)
- // We expect to find the ICU data module alongside the current module.
- u_setDataDirectory(".");
- // Only look for the packaged data file;
- // the default behavior is to look for individual files.
- UErrorCode err = U_ZERO_ERROR;
- udata_setFileAccess(UDATA_ONLY_PACKAGES, &err);
- return err == U_ZERO_ERROR;
-#endif
-}
-
-int main(int argc, char **argv) {
- ::testing::InitGoogleTest(&argc, argv);
-
- InitializeICU();
-
- return RUN_ALL_TESTS();
-}
diff --git a/chromium/url/url_canon_icu.h b/chromium/url/url_canon_icu.h
index 9bfd643eb21..11597685876 100644
--- a/chromium/url/url_canon_icu.h
+++ b/chromium/url/url_canon_icu.h
@@ -7,6 +7,7 @@
// ICU integration functions.
+#include "base/compiler_specific.h"
#include "url/url_canon.h"
#include "url/url_export.h"
@@ -27,7 +28,7 @@ class URL_EXPORT ICUCharsetConverter : public CharsetConverter {
virtual void ConvertFromUTF16(const base::char16* input,
int input_len,
- CanonOutput* output);
+ CanonOutput* output) OVERRIDE;
private:
// The ICU converter, not owned by this class.
diff --git a/chromium/url/url_canon_relative.cc b/chromium/url/url_canon_relative.cc
index 84317f80094..4edd6cedd68 100644
--- a/chromium/url/url_canon_relative.cc
+++ b/chromium/url/url_canon_relative.cc
@@ -475,11 +475,14 @@ bool DoResolveRelativeURL(const char* base_url,
#else
// Other platforms need explicit handling for file: URLs with multiple
// slashes because the generic scheme parsing always extracts a host, but a
- // file: URL only has a host if it has exactly 2 slashes. This also
- // handles the special case where the URL is only slashes, since that
- // doesn't have a host part either.
+ // file: URL only has a host if it has exactly 2 slashes. Even if it does
+ // have a host, we want to use the special host detection logic for file
+ // URLs provided by DoResolveAbsoluteFile(), as opposed to the generic host
+ // detection logic, for consistency with parsing file URLs from scratch.
+ // This also handles the special case where the URL is only slashes,
+ // since that doesn't have a host part either.
if (base_is_file &&
- (num_slashes > 2 || num_slashes == relative_component.len)) {
+ (num_slashes >= 2 || num_slashes == relative_component.len)) {
return DoResolveAbsoluteFile(relative_url, relative_component,
query_converter, output, out_parsed);
}
diff --git a/chromium/url/url_canon_stdstring.h b/chromium/url/url_canon_stdstring.h
index 7450f156ac7..9b4a6c2a3b5 100644
--- a/chromium/url/url_canon_stdstring.h
+++ b/chromium/url/url_canon_stdstring.h
@@ -11,6 +11,7 @@
#include <string>
+#include "base/compiler_specific.h"
#include "url/url_canon.h"
namespace url_canon {
@@ -51,7 +52,7 @@ class StdStringCanonOutput : public CanonOutput {
buffer_len_ = cur_len_;
}
- virtual void Resize(int sz) {
+ virtual void Resize(int sz) OVERRIDE {
str_->resize(sz);
buffer_ = str_->empty() ? NULL : &(*str_)[0];
buffer_len_ = sz;
diff --git a/chromium/url/url_canon_unittest.cc b/chromium/url/url_canon_unittest.cc
index f6cd3a207e1..2e93f9244ae 100644
--- a/chromium/url/url_canon_unittest.cc
+++ b/chromium/url/url_canon_unittest.cc
@@ -2001,6 +2001,11 @@ TEST(URLCanonTest, ResolveRelativeURL) {
// is not file.
{"http://host/a", true, false, "/c:\\foo", true, true, true, "http://host/c:/foo"},
{"http://host/a", true, false, "//c:\\foo", true, true, true, "http://c/foo"},
+ // Ensure that ports aren't allowed for hosts relative to a file url.
+ // Although the result string shows a host:port portion, the call to
+ // resolve the relative URL returns false, indicating parse failure,
+ // which is what is required.
+ {"file:///foo.txt", true, true, "//host:80/bar.txt", true, true, false, "file://host:80/bar.txt"},
// Filesystem URL tests; filesystem URLs are only valid and relative if
// they have no scheme, e.g. "./index.html". There's no valid equivalent
// to http:index.html.
diff --git a/chromium/url/url_parse_file.cc b/chromium/url/url_parse_file.cc
index a8907e7195b..a2f7ce3f511 100644
--- a/chromium/url/url_parse_file.cc
+++ b/chromium/url/url_parse_file.cc
@@ -110,8 +110,9 @@ void DoParseLocalFile(const CHAR* spec,
}
// Backend for the external functions that operates on either char type.
-// We are handed the character after the "file:" at the beginning of the spec.
-// Usually this is a slash, but needn't be; we allow paths like "file:c:\foo".
+// Handles cases where there is a scheme, but also when handed the first
+// character following the "file:" at the beginning of the spec. If so,
+// this is usually a slash, but needn't be; we allow paths like "file:c:\foo".
template<typename CHAR>
void DoParseFileURL(const CHAR* spec, int spec_len, Parsed* parsed) {
DCHECK(spec_len >= 0);
@@ -130,8 +131,8 @@ void DoParseFileURL(const CHAR* spec, int spec_len, Parsed* parsed) {
int begin = 0;
TrimURL(spec, &begin, &spec_len);
- // Find the scheme.
- int num_slashes;
+ // Find the scheme, if any.
+ int num_slashes = CountConsecutiveSlashes(spec, begin, spec_len);
int after_scheme;
int after_slashes;
#ifdef WIN32
@@ -140,7 +141,6 @@ void DoParseFileURL(const CHAR* spec, int spec_len, Parsed* parsed) {
// links like "c:/foo/bar" or "//foo/bar". This is also called by the
// relative URL resolver when it determines there is an absolute URL, which
// may give us input like "/c:/foo".
- num_slashes = CountConsecutiveSlashes(spec, begin, spec_len);
after_slashes = begin + num_slashes;
if (DoesBeginWindowsDriveSpec(spec, after_slashes, spec_len)) {
// Windows path, don't try to extract the scheme (for example, "c:\foo").
@@ -153,7 +153,12 @@ void DoParseFileURL(const CHAR* spec, int spec_len, Parsed* parsed) {
} else
#endif
{
- if (ExtractScheme(&spec[begin], spec_len - begin, &parsed->scheme)) {
+ // ExtractScheme doesn't understand the possibility of filenames with
+ // colons in them, in which case it returns the entire spec up to the
+ // colon as the scheme. So handle /foo.c:5 as a file but foo.c:5 as
+ // the foo.c: scheme.
+ if (!num_slashes &&
+ ExtractScheme(&spec[begin], spec_len - begin, &parsed->scheme)) {
// Offset the results since we gave ExtractScheme a substring.
parsed->scheme.begin += begin;
after_scheme = parsed->scheme.end() + 1;
@@ -173,7 +178,6 @@ void DoParseFileURL(const CHAR* spec, int spec_len, Parsed* parsed) {
}
num_slashes = CountConsecutiveSlashes(spec, after_scheme, spec_len);
-
after_slashes = after_scheme + num_slashes;
#ifdef WIN32
// Check whether the input is a drive again. We checked above for windows
diff --git a/chromium/url/url_parse_unittest.cc b/chromium/url/url_parse_unittest.cc
index a65ff858b46..ad47616128d 100644
--- a/chromium/url/url_parse_unittest.cc
+++ b/chromium/url/url_parse_unittest.cc
@@ -371,12 +371,9 @@ TEST(URLParser, PathURL) {
}
}
-#ifdef WIN32
-
-// WindowsFile ----------------------------------------------------------------
-
-// Various incarnations of file URLs. These are for Windows only.
+// Various incarnations of file URLs.
static URLParseCase file_cases[] = {
+#ifdef WIN32
{"file:server", "file", NULL, NULL, "server", -1, NULL, NULL, NULL},
{" file: server \t", "file", NULL, NULL, " server",-1, NULL, NULL, NULL},
{"FiLe:c|", "FiLe", NULL, NULL, NULL, -1, "c|", NULL, NULL},
@@ -404,29 +401,96 @@ static URLParseCase file_cases[] = {
// Queries and refs are valid for file URLs as well.
{"file:///C:/foo.html?#", "file", NULL, NULL, NULL, -1, "/C:/foo.html", "", ""},
{"file:///C:/foo.html?query=yes#ref", "file", NULL, NULL, NULL, -1, "/C:/foo.html", "query=yes", "ref"},
+#else // WIN32
+ // No slashes.
+ {"file:", "file", NULL, NULL, NULL, -1, NULL, NULL, NULL},
+ {"file:path", "file", NULL, NULL, NULL, -1, "path", NULL, NULL},
+ {"file:path/", "file", NULL, NULL, NULL, -1, "path/", NULL, NULL},
+ {"file:path/f.txt", "file", NULL, NULL, NULL, -1, "path/f.txt", NULL, NULL},
+ // One slash.
+ {"file:/", "file", NULL, NULL, NULL, -1, "/", NULL, NULL},
+ {"file:/path", "file", NULL, NULL, NULL, -1, "/path", NULL, NULL},
+ {"file:/path/", "file", NULL, NULL, NULL, -1, "/path/", NULL, NULL},
+ {"file:/path/f.txt", "file", NULL, NULL, NULL, -1, "/path/f.txt", NULL, NULL},
+ // Two slashes.
+ {"file://", "file", NULL, NULL, NULL, -1, NULL, NULL, NULL},
+ {"file://server", "file", NULL, NULL, "server", -1, NULL, NULL, NULL},
+ {"file://server/", "file", NULL, NULL, "server", -1, "/", NULL, NULL},
+ {"file://server/f.txt", "file", NULL, NULL, "server", -1, "/f.txt", NULL, NULL},
+ // Three slashes.
+ {"file:///", "file", NULL, NULL, NULL, -1, "/", NULL, NULL},
+ {"file:///path", "file", NULL, NULL, NULL, -1, "/path", NULL, NULL},
+ {"file:///path/", "file", NULL, NULL, NULL, -1, "/path/", NULL, NULL},
+ {"file:///path/f.txt", "file", NULL, NULL, NULL, -1, "/path/f.txt", NULL, NULL},
+ // More than three slashes.
+ {"file:////", "file", NULL, NULL, NULL, -1, "/", NULL, NULL},
+ {"file:////path", "file", NULL, NULL, NULL, -1, "/path", NULL, NULL},
+ {"file:////path/", "file", NULL, NULL, NULL, -1, "/path/", NULL, NULL},
+ {"file:////path/f.txt", "file", NULL, NULL, NULL, -1, "/path/f.txt", NULL, NULL},
+ // Schemeless URLs
+ {"path/f.txt", NULL, NULL, NULL, NULL, -1, "path/f.txt", NULL, NULL},
+ {"path:80/f.txt", "path", NULL, NULL, NULL, -1, "80/f.txt", NULL, NULL},
+ {"path/f.txt:80", "path/f.txt",NULL, NULL, NULL, -1, "80", NULL, NULL}, // Wrong.
+ {"/path/f.txt", NULL, NULL, NULL, NULL, -1, "/path/f.txt", NULL, NULL},
+ {"/path:80/f.txt", NULL, NULL, NULL, NULL, -1, "/path:80/f.txt",NULL, NULL},
+ {"/path/f.txt:80", NULL, NULL, NULL, NULL, -1, "/path/f.txt:80",NULL, NULL},
+ {"//server/f.txt", NULL, NULL, NULL, "server", -1, "/f.txt", NULL, NULL},
+ {"//server:80/f.txt", NULL, NULL, NULL, "server:80",-1, "/f.txt", NULL, NULL},
+ {"//server/f.txt:80", NULL, NULL, NULL, "server", -1, "/f.txt:80", NULL, NULL},
+ {"///path/f.txt", NULL, NULL, NULL, NULL, -1, "/path/f.txt", NULL, NULL},
+ {"///path:80/f.txt", NULL, NULL, NULL, NULL, -1, "/path:80/f.txt",NULL, NULL},
+ {"///path/f.txt:80", NULL, NULL, NULL, NULL, -1, "/path/f.txt:80",NULL, NULL},
+ {"////path/f.txt", NULL, NULL, NULL, NULL, -1, "/path/f.txt", NULL, NULL},
+ {"////path:80/f.txt", NULL, NULL, NULL, NULL, -1, "/path:80/f.txt",NULL, NULL},
+ {"////path/f.txt:80", NULL, NULL, NULL, NULL, -1, "/path/f.txt:80",NULL, NULL},
+ // Queries and refs are valid for file URLs as well.
+ {"file:///foo.html?#", "file", NULL, NULL, NULL, -1, "/foo.html", "", ""},
+ {"file:///foo.html?q=y#ref", "file", NULL, NULL, NULL, -1, "/foo.html", "q=y", "ref"},
+#endif // WIN32
};
-TEST(URLParser, WindowsFile) {
+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.
url_parse::Parsed parsed;
- for (int i = 0; i < arraysize(file_cases); i++) {
+ for (size_t i = 0; i < arraysize(file_cases); i++) {
const char* url = file_cases[i].input;
url_parse::ParseFileURL(url, static_cast<int>(strlen(url)), &parsed);
int port = url_parse::ParsePort(url, parsed.port);
- EXPECT_TRUE(ComponentMatches(url, file_cases[i].scheme, parsed.scheme));
- EXPECT_TRUE(ComponentMatches(url, file_cases[i].username, parsed.username));
- EXPECT_TRUE(ComponentMatches(url, file_cases[i].password, parsed.password));
- EXPECT_TRUE(ComponentMatches(url, file_cases[i].host, parsed.host));
- EXPECT_EQ(file_cases[i].port, port);
- EXPECT_TRUE(ComponentMatches(url, file_cases[i].path, parsed.path));
- EXPECT_TRUE(ComponentMatches(url, file_cases[i].query, parsed.query));
- EXPECT_TRUE(ComponentMatches(url, file_cases[i].ref, parsed.ref));
+ EXPECT_TRUE(ComponentMatches(url, file_cases[i].scheme, parsed.scheme))
+ << " for case #" << i << " [" << url << "] "
+ << parsed.scheme.begin << ", " << parsed.scheme.len;
+
+ EXPECT_TRUE(ComponentMatches(url, file_cases[i].username, parsed.username))
+ << " for case #" << i << " [" << url << "] "
+ << parsed.username.begin << ", " << parsed.username.len;
+
+ EXPECT_TRUE(ComponentMatches(url, file_cases[i].password, parsed.password))
+ << " for case #" << i << " [" << url << "] "
+ << parsed.password.begin << ", " << parsed.password.len;
+
+ EXPECT_TRUE(ComponentMatches(url, file_cases[i].host, parsed.host))
+ << " for case #" << i << " [" << url << "] "
+ << parsed.host.begin << ", " << parsed.host.len;
+
+ EXPECT_EQ(file_cases[i].port, port)
+ << " for case #" << i << " [ " << url << "] " << port;
+
+ EXPECT_TRUE(ComponentMatches(url, file_cases[i].path, parsed.path))
+ << " for case #" << i << " [" << url << "] "
+ << parsed.path.begin << ", " << parsed.path.len;
+
+ EXPECT_TRUE(ComponentMatches(url, file_cases[i].query, parsed.query))
+ << " for case #" << i << " [" << url << "] "
+ << parsed.query.begin << ", " << parsed.query.len;
+
+ EXPECT_TRUE(ComponentMatches(url, file_cases[i].ref, parsed.ref))
+ << " for case #" << i << " [ "<< url << "] "
+ << parsed.query.begin << ", " << parsed.scheme.len;
}
}
-#endif // WIN32
TEST(URLParser, ExtractFileName) {
struct FileCase {
diff --git a/chromium/url/url_util_unittest.cc b/chromium/url/url_util_unittest.cc
index 26d4dc707c6..8b16d796cf1 100644
--- a/chromium/url/url_util_unittest.cc
+++ b/chromium/url/url_util_unittest.cc
@@ -241,22 +241,32 @@ TEST(URLUtilTest, TestResolveRelativeWithNonStandardBase) {
// A non-standard hierarchical base is resolved with path URL
// canoncialization rules.
{"data:/Blah:Blah/", "file.html", true, "data:/Blah:Blah/file.html"},
- {"data:/Path/../part/part2", "file.html", true, "data:/Path/../part/file.html"},
+ {"data:/Path/../part/part2", "file.html", true,
+ "data:/Path/../part/file.html"},
// Path URL canonicalization rules also apply to non-standard authority-
// based URLs.
- {"custom://Authority/", "file.html", true, "custom://Authority/file.html"},
+ {"custom://Authority/", "file.html", true,
+ "custom://Authority/file.html"},
{"custom://Authority/", "other://Auth/", true, "other://Auth/"},
- {"custom://Authority/", "../../file.html", true, "custom://Authority/file.html"},
- {"custom://Authority/path/", "file.html", true, "custom://Authority/path/file.html"},
- {"custom://Authority:NoCanon/path/", "file.html", true, "custom://Authority:NoCanon/path/file.html"},
+ {"custom://Authority/", "../../file.html", true,
+ "custom://Authority/file.html"},
+ {"custom://Authority/path/", "file.html", true,
+ "custom://Authority/path/file.html"},
+ {"custom://Authority:NoCanon/path/", "file.html", true,
+ "custom://Authority:NoCanon/path/file.html"},
// It's still possible to get an invalid path URL.
{"custom://Invalid:!#Auth/", "file.html", false, ""},
// A path with an authority section gets canonicalized under standard URL
// rules, even though the base was non-standard.
- {"content://content.Provider/", "//other.Provider", true, "content://other.provider/"},
+ {"content://content.Provider/", "//other.Provider", true,
+ "content://other.provider/"},
// Resolving an absolute URL doesn't cause canonicalization of the
// result.
{"about:blank", "custom://Authority", true, "custom://Authority"},
+ // Fragment URLs can be resolved against a non-standard base.
+ {"scheme://Authority/path", "#fragment", true,
+ "scheme://Authority/path#fragment"},
+ {"scheme://Authority/", "#fragment", true, "scheme://Authority/#fragment"},
// Resolving should fail if the base URL is authority-based but is
// missing a path component (the '/' at the end).
{"scheme://Authority", "path", false, ""},