| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Patterns used in content setting rules. | 5 // Patterns used in content setting rules. |
| 6 | 6 |
| 7 #ifndef COMPONENTS_CONTENT_SETTINGS_CORE_COMMON_CONTENT_SETTINGS_PATTERN_H_ | 7 #ifndef COMPONENTS_CONTENT_SETTINGS_CORE_COMMON_CONTENT_SETTINGS_PATTERN_H_ |
| 8 #define COMPONENTS_CONTENT_SETTINGS_CORE_COMMON_CONTENT_SETTINGS_PATTERN_H_ | 8 #define COMPONENTS_CONTENT_SETTINGS_CORE_COMMON_CONTENT_SETTINGS_PATTERN_H_ |
| 9 | 9 |
| 10 #include <string> | 10 #include <string> |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 // Valid patterns specifications are: | 138 // Valid patterns specifications are: |
| 139 // - [*.]domain.tld (matches domain.tld and all sub-domains) | 139 // - [*.]domain.tld (matches domain.tld and all sub-domains) |
| 140 // - host (matches an exact hostname) | 140 // - host (matches an exact hostname) |
| 141 // - scheme://host:port (supported schemes: http,https) | 141 // - scheme://host:port (supported schemes: http,https) |
| 142 // - scheme://[*.]domain.tld:port (supported schemes: http,https) | 142 // - scheme://[*.]domain.tld:port (supported schemes: http,https) |
| 143 // - file://path (The path has to be an absolute path and start with a '/') | 143 // - file://path (The path has to be an absolute path and start with a '/') |
| 144 // - a.b.c.d (matches an exact IPv4 ip) | 144 // - a.b.c.d (matches an exact IPv4 ip) |
| 145 // - [a:b:c:d:e:f:g:h] (matches an exact IPv6 ip) | 145 // - [a:b:c:d:e:f:g:h] (matches an exact IPv6 ip) |
| 146 static ContentSettingsPattern FromString(const std::string& pattern_spec); | 146 static ContentSettingsPattern FromString(const std::string& pattern_spec); |
| 147 | 147 |
| 148 static ContentSettingsPattern FromDomainToOrigin( |
| 149 const ContentSettingsPattern domain_pattern); |
| 150 |
| 148 // Sets the scheme that doesn't support domain wildcard and port. | 151 // Sets the scheme that doesn't support domain wildcard and port. |
| 149 // Needs to be called by the embedder before using ContentSettingsPattern. | 152 // Needs to be called by the embedder before using ContentSettingsPattern. |
| 150 // |scheme| can't be NULL, and the pointed string must remain alive until the | 153 // |scheme| can't be NULL, and the pointed string must remain alive until the |
| 151 // app terminates. | 154 // app terminates. |
| 152 static void SetNonWildcardDomainNonPortScheme(const char* scheme); | 155 static void SetNonWildcardDomainNonPortScheme(const char* scheme); |
| 153 | 156 |
| 154 // Compares |scheme| against the scheme set by the embedder. | 157 // Compares |scheme| against the scheme set by the embedder. |
| 155 static bool IsNonWildcardDomainNonPortScheme(const std::string& scheme); | 158 static bool IsNonWildcardDomainNonPortScheme(const std::string& scheme); |
| 156 | 159 |
| 157 // Constructs an empty pattern. Empty patterns are invalid patterns. Invalid | 160 // Constructs an empty pattern. Empty patterns are invalid patterns. Invalid |
| 158 // patterns match nothing. | 161 // patterns match nothing. |
| 159 ContentSettingsPattern(); | 162 ContentSettingsPattern(); |
| 160 | 163 |
| 161 // True if this is a valid pattern. | 164 // True if this is a valid pattern. |
| 162 bool IsValid() const { return is_valid_; } | 165 bool IsValid() const { return is_valid_; } |
| 163 | 166 |
| 164 // True if |url| matches this pattern. | 167 // True if |url| matches this pattern. |
| 165 bool Matches(const GURL& url) const; | 168 bool Matches(const GURL& url) const; |
| 166 | 169 |
| 167 // True if this pattern matches all hosts (i.e. it has a host wildcard). | 170 // True if this pattern matches all hosts (i.e. it has a host wildcard). |
| 168 bool MatchesAllHosts() const; | 171 bool MatchesAllHosts() const; |
| 169 | 172 |
| 173 // True if this pattern is generated from FromURL(). |
| 174 bool IsGeneratedFromURLDomainScoped() const; |
| 175 |
| 170 // Returns a std::string representation of this pattern. | 176 // Returns a std::string representation of this pattern. |
| 171 std::string ToString() const; | 177 std::string ToString() const; |
| 172 | 178 |
| 173 // Compares the pattern with a given |other| pattern and returns the | 179 // Compares the pattern with a given |other| pattern and returns the |
| 174 // |Relation| of the two patterns. | 180 // |Relation| of the two patterns. |
| 175 Relation Compare(const ContentSettingsPattern& other) const; | 181 Relation Compare(const ContentSettingsPattern& other) const; |
| 176 | 182 |
| 177 // Returns true if the pattern and the |other| pattern are identical. | 183 // Returns true if the pattern and the |other| pattern are identical. |
| 178 bool operator==(const ContentSettingsPattern& other) const; | 184 bool operator==(const ContentSettingsPattern& other) const; |
| 179 | 185 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 210 const ContentSettingsPattern::PatternParts& other_parts); | 216 const ContentSettingsPattern::PatternParts& other_parts); |
| 211 | 217 |
| 212 ContentSettingsPattern(const PatternParts& parts, bool valid); | 218 ContentSettingsPattern(const PatternParts& parts, bool valid); |
| 213 | 219 |
| 214 PatternParts parts_; | 220 PatternParts parts_; |
| 215 | 221 |
| 216 bool is_valid_; | 222 bool is_valid_; |
| 217 }; | 223 }; |
| 218 | 224 |
| 219 #endif // COMPONENTS_CONTENT_SETTINGS_CORE_COMMON_CONTENT_SETTINGS_PATTERN_H_ | 225 #endif // COMPONENTS_CONTENT_SETTINGS_CORE_COMMON_CONTENT_SETTINGS_PATTERN_H_ |
| OLD | NEW |