| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // Patterns used in content setting rules. |
| 6 |
| 7 #ifndef CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_PATTERN_H_ |
| 8 #define CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_PATTERN_H_ |
| 9 #pragma once |
| 10 |
| 11 #include <string> |
| 12 |
| 13 class GURL; |
| 14 |
| 15 // A pattern used in content setting rules. See |IsValid| for a description of |
| 16 // possible patterns. |
| 17 class ContentSettingsPattern { |
| 18 public: |
| 19 // Returns a pattern that matches the host of this URL and all subdomains. |
| 20 static ContentSettingsPattern FromURL(const GURL& url); |
| 21 |
| 22 // Returns a pattern that matches exactly this URL. |
| 23 static ContentSettingsPattern FromURLNoWildcard(const GURL& url); |
| 24 |
| 25 ContentSettingsPattern() {} |
| 26 |
| 27 explicit ContentSettingsPattern(const std::string& pattern) |
| 28 : pattern_(pattern) {} |
| 29 |
| 30 // True if this is a valid pattern. Valid patterns are |
| 31 // - [*.]domain.tld (matches domain.tld and all sub-domains) |
| 32 // - host (matches an exact hostname) |
| 33 // - a.b.c.d (matches an exact IPv4 ip) |
| 34 // - [a:b:c:d:e:f:g:h] (matches an exact IPv6 ip) |
| 35 // TODO(jochen): should also return true for a complete URL without a host. |
| 36 bool IsValid() const; |
| 37 |
| 38 // True if |url| matches this pattern. |
| 39 bool Matches(const GURL& url) const; |
| 40 |
| 41 // Returns a std::string representation of this pattern. |
| 42 const std::string& AsString() const { return pattern_; } |
| 43 |
| 44 bool operator==(const ContentSettingsPattern& other) const { |
| 45 return pattern_ == other.pattern_; |
| 46 } |
| 47 |
| 48 // Canonicalizes the pattern so that it's ASCII only, either |
| 49 // in original (if it was already ASCII) or punycode form. |
| 50 std::string CanonicalizePattern() const; |
| 51 |
| 52 // The version of the pattern format implemented. |
| 53 static const int kContentSettingsPatternVersion; |
| 54 |
| 55 // The format of a domain wildcard. |
| 56 static const char* kDomainWildcard; |
| 57 |
| 58 // The length of kDomainWildcard (without the trailing '\0'). |
| 59 static const size_t kDomainWildcardLength; |
| 60 |
| 61 private: |
| 62 std::string pattern_; |
| 63 }; |
| 64 |
| 65 // Stream operator so ContentSettingsPattern can be used in assertion |
| 66 // statements. |
| 67 inline std::ostream& operator<<( |
| 68 std::ostream& out, const ContentSettingsPattern& pattern) { |
| 69 return out << pattern.AsString(); |
| 70 } |
| 71 |
| 72 #endif // CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_PATTERN_H_ |
| OLD | NEW |