Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_PATTERN_H_ | 7 #ifndef CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_PATTERN_H_ |
| 8 #define CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_PATTERN_H_ | 8 #define CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_PATTERN_H_ |
| 9 #pragma once | 9 #pragma once |
| 10 | 10 |
| 11 #include <ostream> | 11 #include <ostream> |
| 12 #include <string> | 12 #include <string> |
| 13 | 13 |
| 14 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
| 15 | 15 |
| 16 class GURL; | 16 class GURL; |
| 17 | 17 |
| 18 namespace content_settings { | 18 namespace content_settings { |
| 19 class PatternParser; | 19 class PatternParser; |
| 20 } | 20 } |
| 21 | 21 |
| 22 // A pattern used in content setting rules. See |IsValid| for a description of | 22 // A pattern used in content setting rules. See |IsValid| for a description of |
| 23 // possible patterns. | 23 // possible patterns. |
| 24 class ContentSettingsPattern { | 24 class ContentSettingsPattern { |
| 25 public: | 25 public: |
| 26 // Each content settings pattern describes a set of origins. Patterns, and the | 26 // Each content settings pattern describes a set of origins. Patterns, and the |
| 27 // sets they describe, have specific relations. |Relation| describes the | 27 // sets they describe, have specific relations. |Relation| describes the |
| 28 // relation of two patterns A and B. When pattern A is compared with pattern B | 28 // relation of two patterns A and B. When pattern A is compared with pattern B |
| 29 // (A compare B) interessting relations are: | 29 // (A compare B) interessting relations are: |
|
Bernhard Bauer
2011/06/02 18:39:29
Nit: "interesting", while you're at it :-)
markusheintz_
2011/06/03 15:20:36
Done.
| |
| 30 // - IDENTITY : Pattern A and B are identical. The patterns are equal. | 30 // - IDENTITY : |
|
Bernhard Bauer
2011/06/02 18:39:29
Nit: no space before :
markusheintz_
2011/06/03 15:20:36
Done. Also below.
| |
| 31 // - DISJOINT : Pattern A and B have no intersection. A and B never match | 31 // Pattern A and B are identical. The patterns are equal. |
| 32 // a the origin of a URL at the same time. | 32 // |
| 33 // - SUCCESSOR : Pattern A and B have an intersection. But pattern B has a | 33 // - DISJOINT_ORDER_PRE : |
| 34 // higher precedence than pattern A for URLs that are matched | 34 // Pattern A and B have no intersection. A and B never match the origin of |
| 35 // by both pattern. | 35 // a URL at the same time. But pattern A has a higher precedence than |
| 36 // - PREDECESSOR : Pattern A and B have an intersection. But pattern A has a | 36 // pattern B when patterns are sorted. |
| 37 // higher precedence than pattern B for URLs that are matched | 37 // |
| 38 // by both pattern. | 38 // - DISJOINT_ORDER_POST : |
| 39 // Pattern A and B have no intersection. A and B never match the origin of | |
| 40 // a URL at the same time. But pattern A has a lower precedence than | |
| 41 // pattern B when patterns are sorted. | |
| 42 // | |
| 43 // - SUCCESSOR : | |
| 44 // Pattern A and B have an intersection. But pattern B has a higher | |
| 45 // precedence than pattern A for URLs that are matched by both pattern. | |
| 46 // | |
| 47 // - PREDECESSOR : | |
| 48 // Pattern A and B have an intersection. But pattern A has a higher | |
| 49 // precedence than pattern B for URLs that are matched by both pattern. | |
| 39 enum Relation { | 50 enum Relation { |
| 40 DISJOINT = -2, | 51 DISJOINT_ORDER_POST = -2, |
| 41 SUCCESSOR = -1, | 52 SUCCESSOR = -1, |
| 42 IDENTITY = 0, | 53 IDENTITY = 0, |
| 43 PREDECESSOR = 1, | 54 PREDECESSOR = 1, |
| 55 DISJOINT_ORDER_PRE = 2, | |
| 44 }; | 56 }; |
| 45 | 57 |
| 46 class BuilderInterface { | 58 class BuilderInterface { |
| 47 public: | 59 public: |
| 48 virtual ~BuilderInterface() {} | 60 virtual ~BuilderInterface() {} |
| 49 | 61 |
| 50 virtual BuilderInterface* WithPort(const std::string& port) = 0; | 62 virtual BuilderInterface* WithPort(const std::string& port) = 0; |
| 51 | 63 |
| 52 virtual BuilderInterface* WithPortWildcard() = 0; | 64 virtual BuilderInterface* WithPortWildcard() = 0; |
| 53 | 65 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 111 // True if |url| matches this pattern. | 123 // True if |url| matches this pattern. |
| 112 bool Matches(const GURL& url) const; | 124 bool Matches(const GURL& url) const; |
| 113 | 125 |
| 114 // Returns a std::string representation of this pattern. | 126 // Returns a std::string representation of this pattern. |
| 115 const std::string ToString() const; | 127 const std::string ToString() const; |
| 116 | 128 |
| 117 // Compares the pattern with a given |other| pattern and returns the | 129 // Compares the pattern with a given |other| pattern and returns the |
| 118 // |Relation| of the two patterns. | 130 // |Relation| of the two patterns. |
| 119 Relation Compare(const ContentSettingsPattern& other) const; | 131 Relation Compare(const ContentSettingsPattern& other) const; |
| 120 | 132 |
| 121 bool operator==(const ContentSettingsPattern& other) const { | 133 // Returns true if the pattern and the |other| pattern are identical. |
| 122 return Compare(other) == IDENTITY; | 134 bool operator==(const ContentSettingsPattern& other) const; |
| 123 } | 135 |
| 136 // Returns true if the pattern has a lower priority than the |other| pattern. | |
| 137 bool operator<(const ContentSettingsPattern& other) const; | |
| 138 | |
| 139 // Returns true if the pattern has a higher priority than the |other| pattern. | |
| 140 bool operator>(const ContentSettingsPattern& other) const; | |
| 124 | 141 |
| 125 private: | 142 private: |
| 126 friend class content_settings::PatternParser; | 143 friend class content_settings::PatternParser; |
| 127 friend class ContentSettingsPatternParserTest_SerializePatterns_Test; | 144 friend class ContentSettingsPatternParserTest_SerializePatterns_Test; |
| 128 friend class Builder; | 145 friend class Builder; |
| 129 | 146 |
| 130 struct PatternParts { | 147 struct PatternParts { |
| 131 PatternParts(); | 148 PatternParts(); |
| 132 ~PatternParts(); | 149 ~PatternParts(); |
| 133 | 150 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 218 }; | 235 }; |
| 219 | 236 |
| 220 // Stream operator so ContentSettingsPattern can be used in assertion | 237 // Stream operator so ContentSettingsPattern can be used in assertion |
| 221 // statements. | 238 // statements. |
| 222 inline std::ostream& operator<<( | 239 inline std::ostream& operator<<( |
| 223 std::ostream& out, const ContentSettingsPattern& pattern) { | 240 std::ostream& out, const ContentSettingsPattern& pattern) { |
| 224 return out << pattern.ToString(); | 241 return out << pattern.ToString(); |
| 225 } | 242 } |
| 226 | 243 |
| 227 #endif // CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_PATTERN_H_ | 244 #endif // CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_PATTERN_H_ |
| OLD | NEW |