Chromium Code Reviews| Index: chrome/common/content_settings_pattern.cc |
| diff --git a/chrome/common/content_settings_pattern.cc b/chrome/common/content_settings_pattern.cc |
| index 03a746ee618ce49dcc44ffa2597aec36758b75f8..eb6a92d09c84c7efd3007a44e7c0c726f7eba698 100644 |
| --- a/chrome/common/content_settings_pattern.cc |
| +++ b/chrome/common/content_settings_pattern.cc |
| @@ -10,14 +10,10 @@ |
| #include "base/strings/string_split.h" |
| #include "base/strings/string_util.h" |
| #include "chrome/common/content_settings_pattern_parser.h" |
| -#include "chrome/common/render_messages.h" |
| -#include "chrome/common/url_constants.h" |
| -#include "extensions/common/constants.h" |
| -#include "ipc/ipc_message_utils.h" |
| +#include "components/content_settings/core/common/embedder_variables.h" |
| #include "net/base/dns_util.h" |
| #include "net/base/net_util.h" |
| #include "url/gurl.h" |
| -#include "url/url_canon.h" |
| namespace { |
| @@ -85,6 +81,44 @@ typedef ContentSettingsPattern::BuilderInterface BuilderInterface; |
| // //////////////////////////////////////////////////////////////////////////// |
| // ContentSettingsPattern::Builder |
| // |
| +class ContentSettingsPattern::Builder : |
| + public ContentSettingsPattern::BuilderInterface { |
| + public: |
| + explicit Builder(bool use_legacy_validate); |
| + virtual ~Builder(); |
| + |
| + // BuilderInterface: |
| + virtual BuilderInterface* WithPort(const std::string& port) OVERRIDE; |
| + virtual BuilderInterface* WithPortWildcard() OVERRIDE; |
| + virtual BuilderInterface* WithHost(const std::string& host) OVERRIDE; |
| + virtual BuilderInterface* WithDomainWildcard() OVERRIDE; |
| + virtual BuilderInterface* WithScheme(const std::string& scheme) OVERRIDE; |
| + virtual BuilderInterface* WithSchemeWildcard() OVERRIDE; |
| + virtual BuilderInterface* WithPath(const std::string& path) OVERRIDE; |
| + virtual BuilderInterface* WithPathWildcard() OVERRIDE; |
| + virtual BuilderInterface* Invalid() OVERRIDE; |
| + virtual ContentSettingsPattern Build() OVERRIDE; |
| + |
| + private: |
| + // Canonicalizes the pattern parts so that they are ASCII only, either |
| + // in original (if it was already ASCII) or punycode form. Returns true if |
| + // the canonicalization was successful. |
| + static bool Canonicalize(PatternParts* parts); |
| + |
| + // Returns true when the pattern |parts| represent a valid pattern. |
| + static bool Validate(const PatternParts& parts); |
| + |
| + static bool LegacyValidate(const PatternParts& parts); |
| + |
| + bool is_valid_; |
| + |
| + bool use_legacy_validate_; |
| + |
| + PatternParts parts_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(Builder); |
| +}; |
| + |
| ContentSettingsPattern::Builder::Builder(bool use_legacy_validate) |
| : is_valid_(true), |
| use_legacy_validate_(use_legacy_validate) {} |
| @@ -224,7 +258,7 @@ bool ContentSettingsPattern::Builder::Validate(const PatternParts& parts) { |
| } |
| // If the pattern is for an extension URL test if it is valid. |
| - if (parts.scheme == std::string(extensions::kExtensionScheme) && |
| + if (content_settings::IsNonWildcardDomainNonPortScheme(parts.scheme) && |
| parts.port.empty() && |
| !parts.is_port_wildcard) { |
| return true; |
| @@ -261,7 +295,7 @@ bool ContentSettingsPattern::Builder::LegacyValidate( |
| return true; |
| // If the pattern is for an extension URL test if it is valid. |
| - if (parts.scheme == std::string(extensions::kExtensionScheme) && |
| + if (content_settings::IsNonWildcardDomainNonPortScheme(parts.scheme) && |
| !parts.is_scheme_wildcard && |
| !parts.host.empty() && |
| !parts.has_domain_wildcard && |
| @@ -311,11 +345,6 @@ ContentSettingsPattern::PatternParts::~PatternParts() {} |
| // TODO(jochen): update once this feature is no longer behind a flag. |
| const int ContentSettingsPattern::kContentSettingsPatternVersion = 1; |
| -// TODO(markusheintz): These two constants were moved to the Pattern Parser. |
| -// Remove once the dependency of the ContentSettingsBaseProvider is removed. |
| -const char* ContentSettingsPattern::kDomainWildcard = "[*.]"; |
| -const size_t ContentSettingsPattern::kDomainWildcardLength = 4; |
| - |
| // static |
| BuilderInterface* ContentSettingsPattern::CreateBuilder( |
| bool validate) { |
| @@ -388,16 +417,8 @@ ContentSettingsPattern ContentSettingsPattern::FromString( |
| const std::string& pattern_spec) { |
| scoped_ptr<ContentSettingsPattern::BuilderInterface> builder( |
| ContentSettingsPattern::CreateBuilder(false)); |
| - content_settings::PatternParser::Parse(pattern_spec, builder.get()); |
| - return builder->Build(); |
| -} |
| - |
| -// static |
| -ContentSettingsPattern ContentSettingsPattern::LegacyFromString( |
| - const std::string& pattern_spec) { |
| - scoped_ptr<ContentSettingsPattern::BuilderInterface> builder( |
| - ContentSettingsPattern::CreateBuilder(true)); |
| - content_settings::PatternParser::Parse(pattern_spec, builder.get()); |
| + content_settings::PatternParser::Parse(pattern_spec, |
| + builder.get()); |
| return builder->Build(); |
| } |
| @@ -421,17 +442,6 @@ ContentSettingsPattern::ContentSettingsPattern( |
| is_valid_(valid) { |
| } |
| -void ContentSettingsPattern::WriteToMessage(IPC::Message* m) const { |
| - IPC::WriteParam(m, is_valid_); |
| - IPC::WriteParam(m, parts_); |
| -} |
| - |
| -bool ContentSettingsPattern::ReadFromMessage(const IPC::Message* m, |
| - PickleIterator* iter) { |
| - return IPC::ReadParam(m, iter, &is_valid_) && |
| - IPC::ReadParam(m, iter, &parts_); |
| -} |
| - |
| bool ContentSettingsPattern::Matches( |
| const GURL& url) const { |
| // An invalid pattern matches nothing. |
| @@ -472,7 +482,7 @@ bool ContentSettingsPattern::Matches( |
| } |
| // For chrome extensions URLs ignore the port. |
|
blundell
2014/08/26 09:16:57
This comment should be updated.
vasilii
2014/08/26 12:18:18
Done.
|
| - if (parts_.scheme == std::string(extensions::kExtensionScheme)) |
| + if (content_settings::IsNonWildcardDomainNonPortScheme(parts_.scheme)) |
| return true; |
| // Match the port part. |
| @@ -497,7 +507,7 @@ bool ContentSettingsPattern::MatchesAllHosts() const { |
| return parts_.has_domain_wildcard && parts_.host.empty(); |
| } |
| -const std::string ContentSettingsPattern::ToString() const { |
| +std::string ContentSettingsPattern::ToString() const { |
| if (IsValid()) |
| return content_settings::PatternParser::ToString(parts_); |
| else |