diff options
author | apavlov@chromium.org <apavlov@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-03 13:51:58 +0000 |
---|---|---|
committer | apavlov@chromium.org <apavlov@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-03 13:51:58 +0000 |
commit | f1f8639f531a3a919a13d8f8aa8008e8b88e3b1f (patch) | |
tree | 74fb091262f2850a55aa99bbedcdaa163f0c09d1 | |
parent | bd070e2f0795ef0661be6be7585a62c81fbf7459 (diff) | |
download | chromium_src-f1f8639f531a3a919a13d8f8aa8008e8b88e3b1f.zip chromium_src-f1f8639f531a3a919a13d8f8aa8008e8b88e3b1f.tar.gz chromium_src-f1f8639f531a3a919a13d8f8aa8008e8b88e3b1f.tar.bz2 |
Reapply 130248 - Add full support for filesystem URLs. Trying to get the build into the right state.
TBR=pfeldman
Review URL: https://chromiumcodereview.appspot.com/9956101
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@130363 0039d316-1c4b-4281-b951-d872f2087c98
28 files changed, 283 insertions, 117 deletions
diff --git a/build/temp_gyp/googleurl.gyp b/build/temp_gyp/googleurl.gyp index 3115ce6..66665bb 100644 --- a/build/temp_gyp/googleurl.gyp +++ b/build/temp_gyp/googleurl.gyp @@ -23,6 +23,7 @@ '../../googleurl/src/url_canon.h', '../../googleurl/src/url_canon_etc.cc', '../../googleurl/src/url_canon_fileurl.cc', + '../../googleurl/src/url_canon_filesystemurl.cc', '../../googleurl/src/url_canon_host.cc', '../../googleurl/src/url_canon_icu.cc', '../../googleurl/src/url_canon_icu.h', @@ -51,6 +52,9 @@ '../..', ], }, + 'defines': [ + 'FULL_FILESYSTEM_URL_SUPPORT=1', + ], 'conditions': [ ['component=="shared_library"', { 'defines': [ @@ -82,6 +86,9 @@ '../../googleurl/src/url_test_utils.h', '../../googleurl/src/url_util_unittest.cc', ], + 'defines': [ + 'FULL_FILESYSTEM_URL_SUPPORT=1', + ], 'conditions': [ ['os_posix==1 and OS!="mac"', { 'conditions': [ diff --git a/chrome/browser/autocomplete/autocomplete.cc b/chrome/browser/autocomplete/autocomplete.cc index 010617a..0efd16d 100644 --- a/chrome/browser/autocomplete/autocomplete.cc +++ b/chrome/browser/autocomplete/autocomplete.cc @@ -95,6 +95,7 @@ AutocompleteInput::AutocompleteInput(const string16& text, if (((type_ == UNKNOWN) || (type_ == REQUESTED_URL) || (type_ == URL)) && canonicalized_url.is_valid() && (!canonicalized_url.IsStandard() || canonicalized_url.SchemeIsFile() || + canonicalized_url.SchemeIsFileSystem() || !canonicalized_url.host().empty())) canonicalized_url_ = canonicalized_url; @@ -166,6 +167,14 @@ AutocompleteInput::Type AutocompleteInput::Parse( return URL; } + if (LowerCaseEqualsASCII(parsed_scheme, chrome::kFileSystemScheme)) { + // This could theoretically be a strange search, but let's check. + // If it's got an inner_url with a scheme, it's a URL, whether it's valid or + // not. + if (parts->inner_parsed() && parts->inner_parsed()->scheme.is_valid()) + return URL; + } + // If the user typed a scheme, and it's HTTP or HTTPS, we know how to parse it // well enough that we can fall through to the heuristics below. If it's // something else, we can just determine our action based on what we do with @@ -455,6 +464,9 @@ void AutocompleteInput::ParseForEmphasizeComponents( host->reset(); } } + } else if (LowerCaseEqualsASCII(scheme_str, chrome::kFileSystemScheme) && + parts.inner_parsed() && parts.inner_parsed()->scheme.is_valid()) { + *host = parts.inner_parsed()->host; } } diff --git a/chrome/browser/autocomplete/autocomplete_unittest.cc b/chrome/browser/autocomplete/autocomplete_unittest.cc index 5e2050f..9e45132 100644 --- a/chrome/browser/autocomplete/autocomplete_unittest.cc +++ b/chrome/browser/autocomplete/autocomplete_unittest.cc @@ -495,6 +495,12 @@ TEST_F(AutocompleteTest, InputType) { { ASCIIToUTF16("[2001:dB8::1]"), AutocompleteInput::URL }, { ASCIIToUTF16("192.168.0.256"), AutocompleteInput::QUERY }, { ASCIIToUTF16("[foo.com]"), AutocompleteInput::QUERY }, + { ASCIIToUTF16("filesystem:http://a.com/t/bar"), AutocompleteInput::URL }, + { ASCIIToUTF16("filesystem:http:foo"), AutocompleteInput::URL }, + { ASCIIToUTF16("filesystem:file://"), AutocompleteInput::URL }, + { ASCIIToUTF16("filesystem:http"), AutocompleteInput::URL }, + { ASCIIToUTF16("filesystem:"), AutocompleteInput::URL }, + { ASCIIToUTF16("ftp:"), AutocompleteInput::URL }, }; for (size_t i = 0; i < ARRAYSIZE_UNSAFE(input_cases); ++i) { diff --git a/chrome/browser/browsing_data_database_helper.cc b/chrome/browser/browsing_data_database_helper.cc index ccb5615..0bc331f 100644 --- a/chrome/browser/browsing_data_database_helper.cc +++ b/chrome/browser/browsing_data_database_helper.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -44,12 +44,6 @@ BrowsingDataDatabaseHelper::DatabaseInfo::DatabaseInfo( BrowsingDataDatabaseHelper::DatabaseInfo::~DatabaseInfo() {} -bool BrowsingDataDatabaseHelper::DatabaseInfo::IsFileSchemeData() { - return StartsWithASCII(origin_identifier, - std::string(chrome::kFileScheme), - true); -} - BrowsingDataDatabaseHelper::BrowsingDataDatabaseHelper(Profile* profile) : is_fetching_(false), tracker_(BrowserContext::GetDatabaseTracker(profile)) { diff --git a/chrome/browser/browsing_data_database_helper.h b/chrome/browser/browsing_data_database_helper.h index 2d3a853..3d974ee 100644 --- a/chrome/browser/browsing_data_database_helper.h +++ b/chrome/browser/browsing_data_database_helper.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -41,8 +41,6 @@ class BrowsingDataDatabaseHelper base::Time last_modified); ~DatabaseInfo(); - bool IsFileSchemeData(); - std::string host; std::string database_name; std::string origin_identifier; diff --git a/chrome/browser/browsing_data_indexed_db_helper.h b/chrome/browser/browsing_data_indexed_db_helper.h index 5d7177e50..5916b40 100644 --- a/chrome/browser/browsing_data_indexed_db_helper.h +++ b/chrome/browser/browsing_data_indexed_db_helper.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -38,10 +38,6 @@ class BrowsingDataIndexedDBHelper base::Time last_modified); ~IndexedDBInfo(); - bool IsFileSchemeData() { - return origin.SchemeIsFile(); - } - GURL origin; int64 size; base::Time last_modified; diff --git a/chrome/browser/browsing_data_local_storage_helper.h b/chrome/browser/browsing_data_local_storage_helper.h index 7f88985..359f14c 100644 --- a/chrome/browser/browsing_data_local_storage_helper.h +++ b/chrome/browser/browsing_data_local_storage_helper.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -49,10 +49,6 @@ class BrowsingDataLocalStorageHelper base::Time last_modified); ~LocalStorageInfo(); - bool IsFileSchemeData() { - return protocol == chrome::kFileScheme; - } - std::string protocol; std::string host; unsigned short port; diff --git a/chrome/browser/extensions/api/web_request/web_request_api.cc b/chrome/browser/extensions/api/web_request/web_request_api.cc index c4853a9..95d3723 100644 --- a/chrome/browser/extensions/api/web_request/web_request_api.cc +++ b/chrome/browser/extensions/api/web_request/web_request_api.cc @@ -160,6 +160,7 @@ bool IsSensitiveURL(const GURL& url) { bool HasWebRequestScheme(const GURL& url) { return (url.SchemeIs(chrome::kAboutScheme) || url.SchemeIs(chrome::kFileScheme) || + url.SchemeIs(chrome::kFileSystemScheme) || url.SchemeIs(chrome::kFtpScheme) || url.SchemeIs(chrome::kHttpScheme) || url.SchemeIs(chrome::kHttpsScheme) || diff --git a/chrome/browser/extensions/extension_webnavigation_api.cc b/chrome/browser/extensions/extension_webnavigation_api.cc index 485435d..b092a7c 100644 --- a/chrome/browser/extensions/extension_webnavigation_api.cc +++ b/chrome/browser/extensions/extension_webnavigation_api.cc @@ -49,6 +49,7 @@ const char* kValidSchemes[] = { chrome::kFtpScheme, chrome::kJavaScriptScheme, chrome::kDataScheme, + chrome::kFileSystemScheme, }; // Returns the frame ID as it will be passed to the extension: diff --git a/chrome/browser/history/url_index_private_data.cc b/chrome/browser/history/url_index_private_data.cc index de779f4..b35acf0f 100644 --- a/chrome/browser/history/url_index_private_data.cc +++ b/chrome/browser/history/url_index_private_data.cc @@ -912,6 +912,7 @@ void URLIndexPrivateData::InitializeSchemeWhitelist( whitelist->insert(std::string(chrome::kAboutScheme)); whitelist->insert(std::string(chrome::kChromeUIScheme)); whitelist->insert(std::string(chrome::kFileScheme)); + whitelist->insert(std::string(chrome::kFileSystemScheme)); whitelist->insert(std::string(chrome::kFtpScheme)); whitelist->insert(std::string(chrome::kHttpScheme)); whitelist->insert(std::string(chrome::kHttpsScheme)); diff --git a/chrome/browser/net/url_fixer_upper.cc b/chrome/browser/net/url_fixer_upper.cc index 2e025fc..4a4a883 100644 --- a/chrome/browser/net/url_fixer_upper.cc +++ b/chrome/browser/net/url_fixer_upper.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -412,6 +412,13 @@ std::string URLFixerUpper::SegmentURL(const std::string& text, url_parse::Component(0, static_cast<int>(scheme.length()))))) return scheme; + if (scheme == chrome::kFileSystemScheme) { + // Have the GURL parser do the heavy lifting for us. + url_parse::ParseFileSystemURL(text.data(), + static_cast<int>(text.length()), parts); + return scheme; + } + if (parts->scheme.is_valid()) { // Have the GURL parser do the heavy lifting for us. url_parse::ParseStandardURL(text.data(), static_cast<int>(text.length()), @@ -478,6 +485,13 @@ GURL URLFixerUpper::FixupURL(const std::string& text, if (scheme == chrome::kFileScheme) return GURL(parts.scheme.is_valid() ? text : FixupPath(text)); + // We handle the filesystem scheme separately. + if (scheme == chrome::kFileSystemScheme) { + if (parts.inner_parsed() && parts.inner_parsed()->scheme.is_valid()) + return GURL(text); + return GURL(); + } + // Parse and rebuild about: and chrome: URLs, except about:blank. bool chrome_url = !LowerCaseEqualsASCII(trimmed, chrome::kAboutBlankURL) && ((scheme == chrome::kAboutScheme) || (scheme == chrome::kChromeUIScheme)); diff --git a/chrome/browser/web_applications/web_app.cc b/chrome/browser/web_applications/web_app.cc index 4ff951f..575e72a 100644 --- a/chrome/browser/web_applications/web_app.cc +++ b/chrome/browser/web_applications/web_app.cc @@ -135,6 +135,7 @@ void CreateShortcut( bool IsValidUrl(const GURL& url) { static const char* const kValidUrlSchemes[] = { chrome::kFileScheme, + chrome::kFileSystemScheme, chrome::kFtpScheme, chrome::kHttpScheme, chrome::kHttpsScheme, diff --git a/chrome/common/content_settings_pattern.cc b/chrome/common/content_settings_pattern.cc index 8008cba..8feef19 100644 --- a/chrome/common/content_settings_pattern.cc +++ b/chrome/common/content_settings_pattern.cc @@ -313,28 +313,33 @@ ContentSettingsPattern ContentSettingsPattern::FromURL( scoped_ptr<ContentSettingsPattern::BuilderInterface> builder( ContentSettingsPattern::CreateBuilder(false)); - if (url.SchemeIsFile()) { - builder->WithScheme(url.scheme())->WithPath(url.path()); + const GURL* local_url = &url; + if (url.SchemeIsFileSystem() && url.inner_url()) { + local_url = url.inner_url(); + } + if (local_url->SchemeIsFile()) { + builder->WithScheme(local_url->scheme())->WithPath(local_url->path()); } else { // Please keep the order of the ifs below as URLs with an IP as host can // also have a "http" scheme. - if (url.HostIsIPAddress()) { - builder->WithScheme(url.scheme())->WithHost(url.host()); - } else if (url.SchemeIs(chrome::kHttpScheme)) { - builder->WithSchemeWildcard()->WithDomainWildcard()->WithHost(url.host()); - } else if (url.SchemeIs(chrome::kHttpsScheme)) { - builder->WithScheme(url.scheme())->WithDomainWildcard()->WithHost( - url.host()); + if (local_url->HostIsIPAddress()) { + builder->WithScheme(local_url->scheme())->WithHost(local_url->host()); + } else if (local_url->SchemeIs(chrome::kHttpScheme)) { + builder->WithSchemeWildcard()->WithDomainWildcard()->WithHost( + local_url->host()); + } else if (local_url->SchemeIs(chrome::kHttpsScheme)) { + builder->WithScheme(local_url->scheme())->WithDomainWildcard()->WithHost( + local_url->host()); } else { // Unsupported scheme } - if (url.port().empty()) { - if (url.SchemeIs(chrome::kHttpsScheme)) + if (local_url->port().empty()) { + if (local_url->SchemeIs(chrome::kHttpsScheme)) builder->WithPort(GetDefaultPort(chrome::kHttpsScheme)); else builder->WithPortWildcard(); } else { - builder->WithPort(url.port()); + builder->WithPort(local_url->port()); } } return builder->Build(); @@ -346,14 +351,18 @@ ContentSettingsPattern ContentSettingsPattern::FromURLNoWildcard( scoped_ptr<ContentSettingsPattern::BuilderInterface> builder( ContentSettingsPattern::CreateBuilder(false)); - if (url.SchemeIsFile()) { - builder->WithScheme(url.scheme())->WithPath(url.path()); + const GURL* local_url = &url; + if (url.SchemeIsFileSystem() && url.inner_url()) { + local_url = url.inner_url(); + } + if (local_url->SchemeIsFile()) { + builder->WithScheme(local_url->scheme())->WithPath(local_url->path()); } else { - builder->WithScheme(url.scheme())->WithHost(url.host()); - if (url.port().empty()) { - builder->WithPort(GetDefaultPort(url.scheme())); + builder->WithScheme(local_url->scheme())->WithHost(local_url->host()); + if (local_url->port().empty()) { + builder->WithPort(GetDefaultPort(local_url->scheme())); } else { - builder->WithPort(url.port()); + builder->WithPort(local_url->port()); } } return builder->Build(); @@ -414,8 +423,13 @@ bool ContentSettingsPattern::Matches( if (!is_valid_) return false; + const GURL* local_url = &url; + if (url.SchemeIsFileSystem() && url.inner_url()) { + local_url = url.inner_url(); + } + // Match the scheme part. - const std::string scheme(url.scheme()); + const std::string scheme(local_url->scheme()); if (!parts_.is_scheme_wildcard && parts_.scheme != scheme) { return false; @@ -423,11 +437,17 @@ bool ContentSettingsPattern::Matches( // File URLs have no host. Matches if the pattern has the path wildcard set, // or if the path in the URL is identical to the one in the pattern. + // For filesystem:file URLs, the path used is the filesystem type, so all + // filesystem:file:///temporary/... are equivalent. + // TODO(markusheintz): Content settings should be defined for all files on + // a machine. Unless there is a good use case for supporting paths for file + // patterns, stop supporting path for file patterns. if (!parts_.is_scheme_wildcard && scheme == chrome::kFileScheme) - return parts_.is_path_wildcard || parts_.path == std::string(url.path()); + return parts_.is_path_wildcard || + parts_.path == std::string(local_url->path()); // Match the host part. - const std::string host(net::TrimEndingDot(url.host())); + const std::string host(net::TrimEndingDot(local_url->host())); if (!parts_.has_domain_wildcard) { if (parts_.host != host) return false; @@ -441,7 +461,7 @@ bool ContentSettingsPattern::Matches( return true; // Match the port part. - std::string port(url.port()); + std::string port(local_url->port()); // Use the default port if the port string is empty. GURL returns an empty // string if no port at all was specified or if the default port was diff --git a/chrome/common/content_settings_pattern_unittest.cc b/chrome/common/content_settings_pattern_unittest.cc index f0eeca5..bd79338 100644 --- a/chrome/common/content_settings_pattern_unittest.cc +++ b/chrome/common/content_settings_pattern_unittest.cc @@ -73,6 +73,7 @@ TEST(ContentSettingsPatternTest, FromURL) { pattern = ContentSettingsPattern::FromURL(GURL("https://www.google.com:443")); EXPECT_TRUE(pattern.Matches(GURL("https://www.google.com"))); + EXPECT_TRUE(pattern.Matches(GURL("https://foo.www.google.com"))); EXPECT_TRUE(pattern.Matches(GURL("https://www.google.com:443"))); EXPECT_FALSE(pattern.Matches(GURL("https://www.google.com:444"))); EXPECT_FALSE(pattern.Matches(GURL("http://www.google.com:443"))); @@ -89,6 +90,49 @@ TEST(ContentSettingsPatternTest, FromURL) { EXPECT_EQ("file:///foo/bar.html", pattern.ToString()); } +TEST(ContentSettingsPatternTest, FilesystemUrls) { + ContentSettingsPattern pattern = + ContentSettingsPattern::FromURL(GURL("http://www.google.com")); + EXPECT_TRUE(pattern.Matches( + GURL("filesystem:http://www.google.com/temporary/"))); + EXPECT_TRUE(pattern.Matches( + GURL("filesystem:http://foo.www.google.com/temporary/"))); + EXPECT_TRUE(pattern.Matches( + GURL("filesystem:http://www.google.com:80/temporary/"))); + EXPECT_TRUE(pattern.Matches( + GURL("filesystem:http://www.google.com:81/temporary/"))); + + pattern = ContentSettingsPattern::FromURL(GURL("https://www.google.com")); + EXPECT_TRUE(pattern.Matches( + GURL("filesystem:https://www.google.com/temporary/"))); + EXPECT_TRUE(pattern.Matches( + GURL("filesystem:https://www.google.com:443/temporary/"))); + EXPECT_TRUE(pattern.Matches( + GURL("filesystem:https://foo.www.google.com/temporary/"))); + EXPECT_FALSE(pattern.Matches( + GURL("filesystem:https://www.google.com:81/temporary/"))); + + // A pattern from a filesystem URLs is equivalent to a pattern from the inner + // URL of the filesystem URL. + ContentSettingsPattern pattern2 = ContentSettingsPattern::FromURL( + GURL("filesystem:https://www.google.com/temporary/")); + EXPECT_EQ(ContentSettingsPattern::IDENTITY, pattern.Compare(pattern2)); + + EXPECT_STREQ("https://[*.]www.google.com:443", pattern2.ToString().c_str()); + + pattern = + ContentSettingsPattern::FromURL( + GURL("filesystem:file:///temporary/foo/bar")); + EXPECT_TRUE(pattern.Matches(GURL("filesystem:file:///temporary/"))); + EXPECT_TRUE(pattern.Matches(GURL("filesystem:file:///temporary/test.txt"))); + EXPECT_TRUE(pattern.Matches(GURL("file:///temporary"))); + EXPECT_FALSE(pattern.Matches(GURL("file://foo/bar"))); + pattern2 = + ContentSettingsPattern::FromURL( + GURL("filesystem:file:///persistent/foo2/bar2")); + EXPECT_EQ(ContentSettingsPattern::IDENTITY, pattern.Compare(pattern2)); +} + TEST(ContentSettingsPatternTest, FromURLNoWildcard) { // If no port is specifed GURLs always use the default port for the schemes // HTTP and HTTPS. Hence a GURL always carries a port specification either @@ -114,8 +158,21 @@ TEST(ContentSettingsPatternTest, FromURLNoWildcard) { EXPECT_TRUE(pattern.Matches(GURL("https://www.example.com"))); EXPECT_FALSE(pattern.Matches(GURL("http://foo.www.example.com"))); - pattern = ContentSettingsPattern::FromURLNoWildcard( - GURL("https://www.example.com")); + // Pattern for filesystem URLs + pattern = + ContentSettingsPattern::FromURLNoWildcard( + GURL("filesystem:http://www.google.com/temporary/")); + EXPECT_TRUE(pattern.IsValid()); + EXPECT_TRUE(pattern.Matches(GURL("http://www.google.com"))); + EXPECT_FALSE(pattern.Matches(GURL("http://foo.www.google.com"))); + EXPECT_TRUE(pattern.Matches( + GURL("filesystem:http://www.google.com/persistent/"))); + EXPECT_FALSE(pattern.Matches( + GURL("filesystem:https://www.google.com/persistent/"))); + EXPECT_FALSE(pattern.Matches( + GURL("filesystem:https://www.google.com:81/temporary/"))); + EXPECT_FALSE(pattern.Matches( + GURL("filesystem:https://foo.www.google.com/temporary/"))); } TEST(ContentSettingsPatternTest, Wildcard) { diff --git a/chrome/common/extensions/extension.cc b/chrome/common/extensions/extension.cc index 371c4fb..f8262b3 100644 --- a/chrome/common/extensions/extension.cc +++ b/chrome/common/extensions/extension.cc @@ -2477,16 +2477,27 @@ FileBrowserHandler* Extension::LoadFileBrowserHandler( return NULL; } StringToLowerASCII(&filter); - URLPattern pattern(URLPattern::SCHEME_FILESYSTEM); + if (!StartsWithASCII(filter, + std::string(chrome::kFileSystemScheme) + ':', + true)) { + *error = ExtensionErrorUtils::FormatErrorMessageUTF16( + errors::kInvalidURLPatternError, filter); + return NULL; + } + // The user inputs filesystem:*; we don't actually implement scheme + // wildcards in URLPattern, so transform to what will match correctly. + filter.replace(0, 11, "chrome-extension://*/"); + URLPattern pattern(URLPattern::SCHEME_EXTENSION); + pattern.set_partial_filesystem_support_hack(true); if (pattern.Parse(filter) != URLPattern::PARSE_SUCCESS) { *error = ExtensionErrorUtils::FormatErrorMessageUTF16( errors::kInvalidURLPatternError, filter); return NULL; } std::string path = pattern.path(); - bool allowed = path == "*" || path == "*.*" || - (path.compare(0, 2, "*.") == 0 && - path.find_first_of('*', 2) == std::string::npos); + bool allowed = path == "/*" || path == "/*.*" || + (path.compare(0, 3, "/*.") == 0 && + path.find_first_of('*', 3) == std::string::npos); if (!allowed) { *error = ExtensionErrorUtils::FormatErrorMessageUTF16( errors::kInvalidURLPatternError, filter); diff --git a/chrome/common/extensions/extension_manifests_unittest.cc b/chrome/common/extensions/extension_manifests_unittest.cc index 9f141b5..5d3ec71 100644 --- a/chrome/common/extensions/extension_manifests_unittest.cc +++ b/chrome/common/extensions/extension_manifests_unittest.cc @@ -1095,6 +1095,7 @@ TEST_F(ExtensionManifestTest, FileBrowserHandlers) { scoped_refptr<Extension> extension( LoadAndExpectSuccess("filebrowser_valid.json")); + ASSERT_TRUE(extension.get()); ASSERT_TRUE(extension->file_browser_handlers() != NULL); ASSERT_EQ(extension->file_browser_handlers()->size(), 1U); const FileBrowserHandler* action = diff --git a/chrome/common/extensions/url_pattern.cc b/chrome/common/extensions/url_pattern.cc index ac64811..c0b04b7 100644 --- a/chrome/common/extensions/url_pattern.cc +++ b/chrome/common/extensions/url_pattern.cc @@ -97,12 +97,14 @@ bool IsValidPortForScheme(const std::string scheme, const std::string& port) { URLPattern::URLPattern() : valid_schemes_(SCHEME_NONE), match_all_urls_(false), + partial_filesystem_support_hack_(false), match_subdomains_(false), port_("*") {} URLPattern::URLPattern(int valid_schemes) : valid_schemes_(valid_schemes), match_all_urls_(false), + partial_filesystem_support_hack_(false), match_subdomains_(false), port_("*") {} @@ -111,6 +113,7 @@ URLPattern::URLPattern(int valid_schemes, const std::string& pattern) // appropriate when we know |pattern| is valid. : valid_schemes_(valid_schemes), match_all_urls_(false), + partial_filesystem_support_hack_(false), match_subdomains_(false), port_("*") { if (PARSE_SUCCESS != Parse(pattern)) @@ -295,14 +298,27 @@ bool URLPattern::SetPort(const std::string& port) { } bool URLPattern::MatchesURL(const GURL& test) const { - if (!MatchesScheme(test.scheme())) + const GURL* test_url = &test; + bool has_inner_url = test.inner_url() != NULL; + + if (partial_filesystem_support_hack_ != has_inner_url) + return false; + + if (has_inner_url) + test_url = test.inner_url(); + + if (!MatchesScheme(test_url->scheme())) return false; if (match_all_urls_) return true; - return MatchesSecurityOriginHelper(test) && - MatchesPath(test.PathForRequest()); + std::string path_for_request = test.PathForRequest(); + if (has_inner_url) + path_for_request = test_url->path() + path_for_request; + + return MatchesSecurityOriginHelper(*test_url) && + MatchesPath(path_for_request); } bool URLPattern::MatchesSecurityOrigin(const GURL& test) const { @@ -433,6 +449,10 @@ bool URLPattern::OverlapsWith(const URLPattern& other) const { DCHECK(path_.find('*') == path_.size() - 1); DCHECK(other.path().find('*') == other.path().size() - 1); + if (partial_filesystem_support_hack_ != + other.partial_filesystem_support_hack()) + return false; + if (!MatchesPath(other.path().substr(0, other.path().size() - 1)) && !other.MatchesPath(path_.substr(0, path_.size() - 1))) return false; diff --git a/chrome/common/extensions/url_pattern.h b/chrome/common/extensions/url_pattern.h index 6a83c01..3cde957 100644 --- a/chrome/common/extensions/url_pattern.h +++ b/chrome/common/extensions/url_pattern.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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 CHROME_COMMON_EXTENSIONS_URL_PATTERN_H_ @@ -119,6 +119,15 @@ class URLPattern { bool match_all_urls() const { return match_all_urls_; } void SetMatchAllURLs(bool val); + // Returns true if this pattern matches inner URLs of filesystem: URLs only. + // Returns false if this pattern matches only non-filesystem URLs. + bool partial_filesystem_support_hack() const { + return partial_filesystem_support_hack_; + } + void set_partial_filesystem_support_hack(bool val) { + partial_filesystem_support_hack_ = val; + } + // Sets the scheme for pattern matches. This can be a single '*' if the // pattern matches all valid schemes (as defined by the valid_schemes_ // property). Returns false on failure (if the scheme is not valid). @@ -204,6 +213,11 @@ class URLPattern { // True if this is a special-case "<all_urls>" pattern. bool match_all_urls_; + // True if we're trying to match against the inner URL of a filesystem URL; + // this is a temporary hack so as not to break ChromeOS as we work on full + // support. + bool partial_filesystem_support_hack_; + // The scheme for the pattern. std::string scheme_; diff --git a/chrome/common/extensions/url_pattern_unittest.cc b/chrome/common/extensions/url_pattern_unittest.cc index 3996b99..10dff3d 100644 --- a/chrome/common/extensions/url_pattern_unittest.cc +++ b/chrome/common/extensions/url_pattern_unittest.cc @@ -110,6 +110,11 @@ TEST(ExtensionURLPatternTest, Match2) { EXPECT_TRUE(pattern.MatchesURL(GURL("https://www.google.com/foobar"))); EXPECT_FALSE(pattern.MatchesURL(GURL("http://www.google.com/foo"))); EXPECT_FALSE(pattern.MatchesURL(GURL("https://www.google.com/"))); + EXPECT_FALSE(pattern.MatchesURL( + GURL("filesystem:https://www.google.com/foobar/"))); + pattern.set_partial_filesystem_support_hack(true); + EXPECT_TRUE(pattern.MatchesURL( + GURL("filesystem:https://www.google.com/foobar/bas"))); } // subdomains @@ -127,6 +132,11 @@ TEST(URLPatternTest, Match3) { EXPECT_TRUE(pattern.MatchesURL( GURL("http://monkey.images.google.com/foooobar"))); EXPECT_FALSE(pattern.MatchesURL(GURL("http://yahoo.com/foobar"))); + EXPECT_FALSE(pattern.MatchesURL( + GURL("filesystem:http://google.com/foobar/"))); + pattern.set_partial_filesystem_support_hack(true); + EXPECT_FALSE(pattern.MatchesURL( + GURL("filesystem:http://google.com/temporary/foobar"))); } // glob escaping @@ -226,6 +236,7 @@ TEST(ExtensionURLPatternTest, Match11) { EXPECT_TRUE(pattern.MatchesScheme("http")); EXPECT_TRUE(pattern.MatchesScheme("https")); EXPECT_TRUE(pattern.MatchesScheme("file")); + EXPECT_TRUE(pattern.MatchesScheme("filesystem")); EXPECT_TRUE(pattern.MatchesScheme("chrome-extension")); EXPECT_TRUE(pattern.match_subdomains()); EXPECT_TRUE(pattern.match_all_urls()); @@ -257,6 +268,7 @@ TEST(ExtensionURLPatternTest, Match12) { EXPECT_TRUE(pattern.MatchesScheme("http")); EXPECT_TRUE(pattern.MatchesScheme("https")); EXPECT_TRUE(pattern.MatchesScheme("file")); + EXPECT_TRUE(pattern.MatchesScheme("filesystem")); EXPECT_TRUE(pattern.MatchesScheme("javascript")); EXPECT_TRUE(pattern.MatchesScheme("data")); EXPECT_TRUE(pattern.MatchesScheme("about")); @@ -368,6 +380,11 @@ TEST(ExtensionURLPatternTest, Match17) { EXPECT_TRUE(pattern.MatchesURL(GURL("http://www.example.com:80/foo"))); EXPECT_TRUE(pattern.MatchesURL(GURL("http://www.example.com/foo"))); EXPECT_FALSE(pattern.MatchesURL(GURL("http://www.example.com:8080/foo"))); + EXPECT_FALSE(pattern.MatchesURL( + GURL("filesystem:http://www.example.com:8080/foo/"))); + EXPECT_FALSE(pattern.MatchesURL(GURL("filesystem:http://www.example.com/f/foo"))); + pattern.set_partial_filesystem_support_hack(true); + EXPECT_FALSE(pattern.MatchesURL(GURL("filesystem:http://www.example.com/f/foo"))); } // Explicit port wildcard @@ -384,6 +401,8 @@ TEST(ExtensionURLPatternTest, Match18) { EXPECT_TRUE(pattern.MatchesURL(GURL("http://www.example.com:80/foo"))); EXPECT_TRUE(pattern.MatchesURL(GURL("http://www.example.com/foo"))); EXPECT_TRUE(pattern.MatchesURL(GURL("http://www.example.com:8080/foo"))); + EXPECT_FALSE(pattern.MatchesURL( + GURL("filesystem:http://www.example.com:8080/foo/"))); } // chrome-extension:// @@ -402,6 +421,11 @@ TEST(ExtensionURLPatternTest, Match19) { EXPECT_TRUE(pattern.MatchesURL( GURL("chrome-extension://ftw/https://google.com"))); EXPECT_FALSE(pattern.MatchesURL(GURL("chrome-extension://foobar"))); + EXPECT_FALSE(pattern.MatchesURL( + GURL("filesystem:chrome-extension://ftw/t/file.txt"))); + pattern.set_partial_filesystem_support_hack(true); + EXPECT_TRUE(pattern.MatchesURL( + GURL("filesystem:chrome-extension://ftw/t/file.txt"))); }; static const struct GetAsStringPatterns { diff --git a/chrome/test/data/extensions/api_test/filebrowser_component/main.js b/chrome/test/data/extensions/api_test/filebrowser_component/main.js index f3ca290..53fc279 100644 --- a/chrome/test/data/extensions/api_test/filebrowser_component/main.js +++ b/chrome/test/data/extensions/api_test/filebrowser_component/main.js @@ -14,7 +14,7 @@ This component extension test does the following: var cleanupError = 'Got unexpected error while cleaning up test directory.'; -// Class specified by the client runnig the TestRunner. +// Class specified by the client running the TestRunner. // |expectedTasks| should contain list of actions defined for abc files defined // by filesystem_handler part of the test. // |fileVerifierFunction| method that will verify test results received from the @@ -86,7 +86,9 @@ TestExpectations.prototype.verifyTasks = function(tasks, patterns = patterns.sort(); expectedPatterns = expectedPatterns.sort(); for (var j = 0; j < patterns.length; ++j) { - if (patterns[j] != expectedPatterns[j]) { + var translatedPattern = expectedPatterns[j].replace( + /^filesystem:/, "chrome-extension://*/"); + if (patterns[j] != translatedPattern) { errorCallback({message: 'Wrong patterns set for task ' + taskName + '. ' + 'Got: ' + patterns + diff --git a/content/browser/browser_url_handler_impl.cc b/content/browser/browser_url_handler_impl.cc index 7eef43f..2585844 100644 --- a/content/browser/browser_url_handler_impl.cc +++ b/content/browser/browser_url_handler_impl.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -24,7 +24,7 @@ static bool HandleViewSource(GURL* url, static const char* const allowed_sub_schemes[] = { chrome::kHttpScheme, chrome::kHttpsScheme, chrome::kFtpScheme, chrome::kChromeDevToolsScheme, chrome::kChromeUIScheme, - chrome::kFileScheme + chrome::kFileScheme, chrome::kFileSystemScheme }; bool is_sub_scheme_allowed = false; diff --git a/content/public/common/url_constants.cc b/content/public/common/url_constants.cc index 26dee8e..bbc5c2f 100644 --- a/content/public/common/url_constants.cc +++ b/content/public/common/url_constants.cc @@ -12,6 +12,7 @@ const char* kDefaultSavableSchemes[] = { chrome::kHttpScheme, chrome::kHttpsScheme, chrome::kFileScheme, + chrome::kFileSystemScheme, chrome::kFtpScheme, chrome::kChromeDevToolsScheme, chrome::kChromeUIScheme, diff --git a/net/base/mime_sniffer.cc b/net/base/mime_sniffer.cc index b0b6d03..a6f8198 100644 --- a/net/base/mime_sniffer.cc +++ b/net/base/mime_sniffer.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -567,12 +567,12 @@ bool ShouldSniffMimeType(const GURL& url, const std::string& mime_type) { if (!should_sniff_counter) should_sniff_counter = UMASnifferHistogramGet("mime_sniffer.ShouldSniffMimeType2", 3); - // We are willing to sniff the mime type for HTTP, HTTPS, and FTP bool sniffable_scheme = url.is_empty() || url.SchemeIs("http") || url.SchemeIs("https") || url.SchemeIs("ftp") || - url.SchemeIsFile(); + url.SchemeIsFile() || + url.SchemeIsFileSystem(); if (!sniffable_scheme) { should_sniff_counter->Add(1); return false; diff --git a/net/base/net_util.cc b/net/base/net_util.cc index 29b83a8..f2d22ae 100644 --- a/net/base/net_util.cc +++ b/net/base/net_util.cc @@ -1908,8 +1908,9 @@ string16 FormatUrl(const GURL& url, bool CanStripTrailingSlash(const GURL& url) { // Omit the path only for standard, non-file URLs with nothing but "/" after // the hostname. - return url.IsStandard() && !url.SchemeIsFile() && !url.has_query() && - !url.has_ref() && url.path() == "/"; + return url.IsStandard() && !url.SchemeIsFile() && + !url.SchemeIsFileSystem() && !url.has_query() && !url.has_ref() + && url.path() == "/"; } GURL SimplifyUrlForRequest(const GURL& url) { diff --git a/ui/base/text/text_elider.cc b/ui/base/text/text_elider.cc index 62ad7d0..bfd7f90 100644 --- a/ui/base/text/text_elider.cc +++ b/ui/base/text/text_elider.cc @@ -225,8 +225,8 @@ string16 ElideUrl(const GURL& url, if (available_pixel_width <= 0) return url_string; - // If non-standard or not file type, return plain eliding. - if (!(url.SchemeIsFile() || url.IsStandard())) + // If non-standard, return plain eliding. + if (!url.IsStandard()) return ElideText(url_string, font, available_pixel_width, ELIDE_AT_END); // Now start eliding url_string to fit within available pixel width. diff --git a/webkit/appcache/appcache_interfaces.cc b/webkit/appcache/appcache_interfaces.cc index aac9766..70de5ff 100644 --- a/webkit/appcache/appcache_interfaces.cc +++ b/webkit/appcache/appcache_interfaces.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -63,11 +63,11 @@ bool IsSchemeSupported(const GURL& url) { bool supported = url.SchemeIs(kHttpScheme) || url.SchemeIs(kHttpsScheme); #ifndef NDEBUG // TODO(michaeln): It would be really nice if this could optionally work for - // file urls too to help web developers experiment and test their apps, - // perhaps enabled via a cmd line flag or some other developer tool setting. - // Unfortunately file scheme net::URLRequest don't produce the same signalling - // (200 response codes, headers) as http URLRequests, so this doesn't work - // just yet. + // file and filesystem urls too to help web developers experiment and test + // their apps, perhaps enabled via a cmd line flag or some other developer + // tool setting. Unfortunately file scheme net::URLRequests don't produce the + // same signalling (200 response codes, headers) as http URLRequests, so this + // doesn't work just yet. // supported |= url.SchemeIsFile(); #endif return supported; diff --git a/webkit/fileapi/file_system_util.cc b/webkit/fileapi/file_system_util.cc index ed365c6..85e3512 100644 --- a/webkit/fileapi/file_system_util.cc +++ b/webkit/fileapi/file_system_util.cc @@ -20,10 +20,10 @@ namespace fileapi { -const char kPersistentDir[] = "/persistent/"; -const char kTemporaryDir[] = "/temporary/"; -const char kIsolatedDir[] = "/isolated/"; -const char kExternalDir[] = "/external/"; +const char kPersistentDir[] = "/persistent"; +const char kTemporaryDir[] = "/temporary"; +const char kIsolatedDir[] = "/isolated"; +const char kExternalDir[] = "/external"; const char kPersistentName[] = "Persistent"; const char kTemporaryName[] = "Temporary"; @@ -35,38 +35,11 @@ bool CrackFileSystemURL(const GURL& url, GURL* origin_url, FileSystemType* type, GURL origin; FileSystemType file_system_type = kFileSystemTypeUnknown; - if (url.scheme() != "filesystem") + if (!url.is_valid() || !url.SchemeIsFileSystem()) return false; + DCHECK(url.inner_url()); - std::string temp = url.path(); - // TODO(ericu): This should probably be done elsewhere after the stackable - // layers are properly in. We're supposed to reject any paths that contain - // '..' segments, but the GURL constructor is helpfully resolving them for us. - // Make sure there aren't any before we call it. - size_t pos = temp.find(".."); - for (; pos != std::string::npos; pos = temp.find("..", pos + 1)) { - if ((pos == 0 || temp[pos - 1] == '/') && - (pos == temp.length() - 2 || temp[pos + 2] == '/')) - return false; - } - - // bare_url will look something like: - // http://example.com/temporary/dir/file.txt. - GURL bare_url(temp); - - // The input URL was malformed, bail out early. - if (bare_url.path().empty()) - return false; - - origin = bare_url.GetOrigin(); - - // The input URL was malformed, bail out early. - if (origin.is_empty()) - return false; - - std::string path = net::UnescapeURLComponent(bare_url.path(), - net::UnescapeRule::SPACES | net::UnescapeRule::URL_SPECIAL_CHARS | - net::UnescapeRule::CONTROL_CHARS); + std::string inner_path = url.inner_url()->path(); const struct { FileSystemType type; @@ -78,9 +51,8 @@ bool CrackFileSystemURL(const GURL& url, GURL* origin_url, FileSystemType* type, { kFileSystemTypeExternal, kExternalDir }, }; for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kValidTypes); ++i) { - if (StartsWithASCII(path, kValidTypes[i].dir, true)) { + if (StartsWithASCII(inner_path, kValidTypes[i].dir, true)) { file_system_type = kValidTypes[i].type; - path = path.substr(strlen(kValidTypes[i].dir)); break; } } @@ -88,17 +60,27 @@ bool CrackFileSystemURL(const GURL& url, GURL* origin_url, FileSystemType* type, if (file_system_type == kFileSystemTypeUnknown) return false; + std::string path = net::UnescapeURLComponent(url.path(), + net::UnescapeRule::SPACES | net::UnescapeRule::URL_SPECIAL_CHARS | + net::UnescapeRule::CONTROL_CHARS); + // Ensure the path is relative. while (!path.empty() && path[0] == '/') path.erase(0, 1); + FilePath converted_path = FilePath::FromUTF8Unsafe(path); + + // All parent references should have been resolved in the renderer. + if (converted_path.ReferencesParent()) + return false; + if (origin_url) - *origin_url = origin; + *origin_url = url.GetOrigin(); if (type) *type = file_system_type; if (file_path) - *file_path = FilePath::FromUTF8Unsafe(path). - NormalizePathSeparators().StripTrailingSeparators(); + *file_path = converted_path.NormalizePathSeparators(). + StripTrailingSeparators(); return true; } @@ -149,18 +131,21 @@ void VirtualPath::GetComponents( } GURL GetFileSystemRootURI(const GURL& origin_url, FileSystemType type) { - std::string path("filesystem:"); - path += origin_url.spec(); + // origin_url is based on a security origin, so http://foo.com or file:/// + // instead of the corresponding filesystem URL. + DCHECK(!origin_url.SchemeIsFileSystem()); + + std::string url = "filesystem:" + origin_url.GetWithEmptyPath().spec(); switch (type) { case kFileSystemTypeTemporary: - path += (kTemporaryDir + 1); // We don't want the leading slash. - return GURL(path); + url += (kTemporaryDir + 1); // We don't want the leading slash. + return GURL(url + "/"); case kFileSystemTypePersistent: - path += (kPersistentDir + 1); // We don't want the leading slash. - return GURL(path); + url += (kPersistentDir + 1); // We don't want the leading slash. + return GURL(url + "/"); case kFileSystemTypeExternal: - path += (kExternalDir + 1); // We don't want the leading slash. - return GURL(path); + url += (kExternalDir + 1); // We don't want the leading slash. + return GURL(url + "/"); case kFileSystemTypeIsolated: // Falling through; we won't call this for isolated filesystems. case kFileSystemTypeUnknown: diff --git a/webkit/fileapi/sandbox_mount_point_provider.cc b/webkit/fileapi/sandbox_mount_point_provider.cc index ca54b99..138629c 100644 --- a/webkit/fileapi/sandbox_mount_point_provider.cc +++ b/webkit/fileapi/sandbox_mount_point_provider.cc @@ -654,6 +654,9 @@ bool SandboxMountPointProvider::IsAllowedScheme(const GURL& url) const { // only if --allow-file-access-from-files flag is given. if (url.SchemeIs("http") || url.SchemeIs("https")) return true; + if (url.SchemeIsFileSystem()) + return url.inner_url() && IsAllowedScheme(*url.inner_url()); + for (size_t i = 0; i < file_system_options_.additional_allowed_schemes().size(); ++i) { |