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: |
30 // - IDENTITY : Pattern A and B are identical. The patterns are equal. | 30 // - IDENTITY : |
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_DISPLAY_PRE : |
Bernhard Bauer
2011/06/01 20:18:25
It's called _ORDER_ below.
markusheintz_
2011/06/03 13:08:54
Done. In forked CL
| |
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_DISPLAY_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 and the |other| pattern are disjoint. | |
137 bool operator!=(const ContentSettingsPattern& other) const; | |
Bernhard Bauer
2011/06/01 20:18:25
That seems like it could cause very subtle problem
markusheintz_
2011/06/03 13:08:54
I also have a bad feeling about his. So I removed
| |
138 | |
139 // Returns true if the pattern has a lower priority than the |other| pattern. | |
140 bool operator<(const ContentSettingsPattern& other) const; | |
141 | |
142 // Returns true if the pattern has a higher priority than the |other| pattern. | |
143 bool operator>(const ContentSettingsPattern& other) const; | |
124 | 144 |
125 private: | 145 private: |
126 friend class content_settings::PatternParser; | 146 friend class content_settings::PatternParser; |
127 friend class ContentSettingsPatternParserTest_SerializePatterns_Test; | 147 friend class ContentSettingsPatternParserTest_SerializePatterns_Test; |
128 friend class Builder; | 148 friend class Builder; |
129 | 149 |
130 struct PatternParts { | 150 struct PatternParts { |
131 PatternParts(); | 151 PatternParts(); |
132 ~PatternParts(); | 152 ~PatternParts(); |
133 | 153 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
218 }; | 238 }; |
219 | 239 |
220 // Stream operator so ContentSettingsPattern can be used in assertion | 240 // Stream operator so ContentSettingsPattern can be used in assertion |
221 // statements. | 241 // statements. |
222 inline std::ostream& operator<<( | 242 inline std::ostream& operator<<( |
223 std::ostream& out, const ContentSettingsPattern& pattern) { | 243 std::ostream& out, const ContentSettingsPattern& pattern) { |
224 return out << pattern.ToString(); | 244 return out << pattern.ToString(); |
225 } | 245 } |
226 | 246 |
227 #endif // CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_PATTERN_H_ | 247 #endif // CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_PATTERN_H_ |
OLD | NEW |