Chromium Code Reviews| Index: chrome/browser/content_settings/content_settings_pattern.h |
| diff --git a/chrome/browser/content_settings/content_settings_pattern.h b/chrome/browser/content_settings/content_settings_pattern.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..a6e795e66b2e07e5ee070051f8986a1ef245b690 |
| --- /dev/null |
| +++ b/chrome/browser/content_settings/content_settings_pattern.h |
| @@ -0,0 +1,71 @@ |
| +// Copyright (c) 2010 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. |
| + |
| +// Patterns used in content setting rules. |
| + |
| +#ifndef CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_PATTERN_H_ |
| +#define CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_PATTERN_H_ |
| +#pragma once |
| + |
| +#include <string> |
| + |
| +class GURL; |
| + |
| +// A hostname pattern. See |IsValid| for a description of possible patterns. |
| +class ContentSettingsPattern { |
|
markusheintz_
2010/12/02 13:28:18
In order to prevent confusion or misunderstanding
jochen (gone - plz use gerrit)
2010/12/02 13:41:39
it doesn't describe content settings, but it also
markusheintz_
2010/12/02 13:50:56
I see. Pls change the comment then.
Hm... hard to
jochen (gone - plz use gerrit)
2010/12/02 13:55:40
Done.
|
| + public: |
| + // Returns a pattern that matches the host of this URL and all subdomains. |
| + static ContentSettingsPattern FromURL(const GURL& url); |
| + |
| + // Returns a pattern that matches exactly this URL. |
| + static ContentSettingsPattern FromURLNoWildcard(const GURL& url); |
| + |
| + ContentSettingsPattern() {} |
| + |
| + explicit ContentSettingsPattern(const std::string& pattern) |
| + : pattern_(pattern) {} |
| + |
| + // True if this is a valid pattern. Valid patterns are |
| + // - [*.]domain.tld (matches domain.tld and all sub-domains) |
| + // - host (matches an exact hostname) |
| + // - a.b.c.d (matches an exact IPv4 ip) |
| + // - [a:b:c:d:e:f:g:h] (matches an exact IPv6 ip) |
| + // TODO(jochen): should also return true for a complete URL without a host. |
| + bool IsValid() const; |
| + |
| + // True if |url| matches this pattern. |
| + bool Matches(const GURL& url) const; |
| + |
| + // Returns a std::string representation of this pattern. |
| + const std::string& AsString() const { return pattern_; } |
| + |
| + bool operator==(const ContentSettingsPattern& other) const { |
| + return pattern_ == other.pattern_; |
| + } |
| + |
| + // Canonicalizes the pattern so that it's ASCII only, either |
| + // in original or punycode form. |
|
markusheintz_
2010/12/02 13:28:18
In which case is it the original and in which case
jochen (gone - plz use gerrit)
2010/12/02 13:41:39
Done.
jochen (gone - plz use gerrit)
2010/12/02 13:41:39
Done.
|
| + std::string CanonicalizePattern() const; |
| + |
| + // The version of the pattern format implemented. |
| + static const int kContentSettingsPatternVersion; |
| + |
| + // The format of a domain wildcard. |
|
markusheintz_
2010/12/02 13:28:18
Ignore this comment if the following twi constants
jochen (gone - plz use gerrit)
2010/12/02 13:41:39
it's still used in the host content settings map.
|
| + static const char *kDomainWildcard; |
|
gfeher
2010/12/02 13:07:50
static const char* kDomainWildcard; ?
jochen (gone - plz use gerrit)
2010/12/02 13:18:43
Done.
|
| + |
| + // The length of kDomainWildcard (without the trailing '\0'). |
| + static const size_t kDomainWildcardLength; |
| + |
| + private: |
| + std::string pattern_; |
| +}; |
| + |
| +// Stream operator so ContentSettingsPattern can be used in assertion |
| +// statements. |
| +inline std::ostream& operator<<( |
| + std::ostream& out, const ContentSettingsPattern& pattern) { |
| + return out << pattern.AsString(); |
| +} |
| + |
| +#endif // CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_PATTERN_H_ |