diff options
author | markusheintz@chromium.org <markusheintz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-23 17:52:08 +0000 |
---|---|---|
committer | markusheintz@chromium.org <markusheintz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-23 17:52:08 +0000 |
commit | ae689aab246d7763cb04ecba1bd382749c599ee7 (patch) | |
tree | 28c10be46648b3327e04b9a3ef78d312851013cd /chrome/common/content_settings_pattern.cc | |
parent | aff8b47835f1f9faa471fd23b8db782cdb492ddd (diff) | |
download | chromium_src-ae689aab246d7763cb04ecba1bd382749c599ee7.zip chromium_src-ae689aab246d7763cb04ecba1bd382749c599ee7.tar.gz chromium_src-ae689aab246d7763cb04ecba1bd382749c599ee7.tar.bz2 |
Added support for file URI path wildcards in content settings
patterns. I.e. "file:///*" matches all file URIs.
Full/explicit/absolute paths (e.g. "file:///foo/bar.html") are still supported.
contributed by Francois Kritzinger (francoisk777@gmail.com)
BUG=77149
TEST=ContentSettingsPattern*
Review URL: http://codereview.chromium.org/9254028
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@118696 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/content_settings_pattern.cc')
-rw-r--r-- | chrome/common/content_settings_pattern.cc | 53 |
1 files changed, 30 insertions, 23 deletions
diff --git a/chrome/common/content_settings_pattern.cc b/chrome/common/content_settings_pattern.cc index 16ec56f..bf00802 100644 --- a/chrome/common/content_settings_pattern.cc +++ b/chrome/common/content_settings_pattern.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. @@ -130,6 +130,13 @@ BuilderInterface* ContentSettingsPattern::Builder::WithSchemeWildcard() { BuilderInterface* ContentSettingsPattern::Builder::WithPath( const std::string& path) { parts_.path = path; + parts_.is_path_wildcard = false; + return this; +} + +BuilderInterface* ContentSettingsPattern::Builder::WithPathWildcard() { + parts_.path = ""; + parts_.is_path_wildcard = true; return this; } @@ -157,10 +164,11 @@ bool ContentSettingsPattern::Builder::Canonicalize(PatternParts* parts) { const std::string scheme(StringToLowerASCII(parts->scheme)); parts->scheme = scheme; - if (parts->scheme == std::string(chrome::kFileScheme)) { - GURL url(std::string(chrome::kFileScheme) + - std::string(chrome::kStandardSchemeSeparator) + parts->path); - parts->path = url.path(); + if (parts->scheme == std::string(chrome::kFileScheme) && + !parts->is_path_wildcard) { + GURL url(std::string(chrome::kFileScheme) + + std::string(chrome::kStandardSchemeSeparator) + parts->path); + parts->path = url.path(); } // Canonicalize the host part. @@ -190,12 +198,15 @@ bool ContentSettingsPattern::Builder::Validate(const PatternParts& parts) { } // file:// URL patterns have an empty host and port. - if (parts.scheme == std::string(chrome::kFileScheme)) - return parts.host.empty() && - parts.port.empty() && - !parts.path.empty() && - parts.path != std::string("/") && - parts.path.find("*") == std::string::npos; + if (parts.scheme == std::string(chrome::kFileScheme)) { + if (parts.has_domain_wildcard || !parts.host.empty() || !parts.port.empty()) + return false; + if (parts.is_path_wildcard) + return parts.path.empty(); + return (!parts.path.empty() && + parts.path != "/" && + parts.path.find("*") == std::string::npos); + } // If the pattern is for an extension URL test if it is valid. if (parts.scheme == std::string(chrome::kExtensionScheme) && @@ -267,7 +278,8 @@ bool ContentSettingsPattern::Builder::LegacyValidate( ContentSettingsPattern::PatternParts::PatternParts() : is_scheme_wildcard(false), has_domain_wildcard(false), - is_port_wildcard(false) {} + is_port_wildcard(false), + is_path_wildcard(false) {} ContentSettingsPattern::PatternParts::~PatternParts() {} @@ -371,7 +383,8 @@ ContentSettingsPattern ContentSettingsPattern::LegacyFromString( ContentSettingsPattern ContentSettingsPattern::Wildcard() { scoped_ptr<ContentSettingsPattern::BuilderInterface> builder( ContentSettingsPattern::CreateBuilder(true)); - builder->WithSchemeWildcard()->WithDomainWildcard()->WithPortWildcard(); + builder->WithSchemeWildcard()->WithDomainWildcard()->WithPortWildcard()-> + WithPathWildcard(); return builder->Build(); } @@ -410,16 +423,10 @@ bool ContentSettingsPattern::Matches( return false; } - // File URLs have no host. For file URLs check if the url path matches the - // path in the pattern. - // TODO(markusheintz): This should change in the future. There should be only - // one setting for all file URLs. So the path should be ignored. - if (!parts_.is_scheme_wildcard && - scheme == std::string(chrome::kFileScheme)) { - if (parts_.path == std::string(url.path())) - return true; - return false; - } + // 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. + if (!parts_.is_scheme_wildcard && scheme == chrome::kFileScheme) + return parts_.is_path_wildcard || parts_.path == std::string(url.path()); // Match the host part. const std::string host(net::TrimEndingDot(url.host())); |