Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(311)

Side by Side Diff: chrome/common/content_settings_pattern.h

Issue 8356010: Merge 106270 - Check for default content settings when requiring user authorization for plug-ins. (Closed) Base URL: svn://svn.chromium.org/chrome/branches/912/src
Patch Set: fix Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_COMMON_CONTENT_SETTINGS_PATTERN_H_ 7 #ifndef CHROME_COMMON_CONTENT_SETTINGS_PATTERN_H_
8 #define CHROME_COMMON_CONTENT_SETTINGS_PATTERN_H_ 8 #define CHROME_COMMON_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 #include "base/gtest_prod_util.h"
15 16
16 class GURL; 17 class GURL;
17 18
18 namespace content_settings { 19 namespace content_settings {
19 class PatternParser; 20 class PatternParser;
20 } 21 }
21 22
23 namespace IPC {
24 class Message;
25 }
26
22 // A pattern used in content setting rules. See |IsValid| for a description of 27 // A pattern used in content setting rules. See |IsValid| for a description of
23 // possible patterns. 28 // possible patterns.
24 class ContentSettingsPattern { 29 class ContentSettingsPattern {
25 public: 30 public:
26 // Each content settings pattern describes a set of origins. Patterns, and the 31 // Each content settings pattern describes a set of origins. Patterns, and the
27 // sets they describe, have specific relations. |Relation| describes the 32 // 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 33 // relation of two patterns A and B. When pattern A is compared with pattern B
29 // (A compare B) interesting relations are: 34 // (A compare B) interesting relations are:
30 // - IDENTITY: 35 // - IDENTITY:
31 // Pattern A and B are identical. The patterns are equal. 36 // Pattern A and B are identical. The patterns are equal.
(...skipping 16 matching lines...) Expand all
48 // Pattern A and B have an intersection. But pattern A has a higher 53 // 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. 54 // precedence than pattern B for URLs that are matched by both pattern.
50 enum Relation { 55 enum Relation {
51 DISJOINT_ORDER_POST = -2, 56 DISJOINT_ORDER_POST = -2,
52 SUCCESSOR = -1, 57 SUCCESSOR = -1,
53 IDENTITY = 0, 58 IDENTITY = 0,
54 PREDECESSOR = 1, 59 PREDECESSOR = 1,
55 DISJOINT_ORDER_PRE = 2, 60 DISJOINT_ORDER_PRE = 2,
56 }; 61 };
57 62
63 struct PatternParts {
64 PatternParts();
65 ~PatternParts();
66
67 // Lowercase string of the URL scheme to match. This string is empty if the
68 // |is_scheme_wildcard| flag is set.
69 std::string scheme;
70
71 // True if the scheme wildcard is set.
72 bool is_scheme_wildcard;
73
74 // Normalized string that is either of the following:
75 // - IPv4 or IPv6
76 // - hostname
77 // - domain
78 // - empty string if the |is_host_wildcard flag is set.
79 std::string host;
80
81 // True if the domain wildcard is set.
82 bool has_domain_wildcard;
83
84 // String with the port to match. This string is empty if the
85 // |is_port_wildcard| flag is set.
86 std::string port;
87
88 // True if the port wildcard is set.
89 bool is_port_wildcard;
90
91 // TODO(markusheintz): Needed for legacy reasons. Remove. Path
92 // specification. Only used for content settings pattern with a "file"
93 // scheme part.
94 std::string path;
95 };
96
58 class BuilderInterface { 97 class BuilderInterface {
59 public: 98 public:
60 virtual ~BuilderInterface() {} 99 virtual ~BuilderInterface() {}
61 100
62 virtual BuilderInterface* WithPort(const std::string& port) = 0; 101 virtual BuilderInterface* WithPort(const std::string& port) = 0;
63 102
64 virtual BuilderInterface* WithPortWildcard() = 0; 103 virtual BuilderInterface* WithPortWildcard() = 0;
65 104
66 virtual BuilderInterface* WithHost(const std::string& host) = 0; 105 virtual BuilderInterface* WithHost(const std::string& host) = 0;
67 106
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 // - [a:b:c:d:e:f:g:h] (matches an exact IPv6 ip) 152 // - [a:b:c:d:e:f:g:h] (matches an exact IPv6 ip)
114 static ContentSettingsPattern FromString(const std::string& pattern_spec); 153 static ContentSettingsPattern FromString(const std::string& pattern_spec);
115 154
116 static ContentSettingsPattern LegacyFromString( 155 static ContentSettingsPattern LegacyFromString(
117 const std::string& pattern_spec); 156 const std::string& pattern_spec);
118 157
119 // Constructs an empty pattern. Empty patterns are invalid patterns. Invalid 158 // Constructs an empty pattern. Empty patterns are invalid patterns. Invalid
120 // patterns match nothing. 159 // patterns match nothing.
121 ContentSettingsPattern(); 160 ContentSettingsPattern();
122 161
162 // Serializes the pattern to an IPC message or deserializes it.
163 void WriteToMessage(IPC::Message* m) const;
164 bool ReadFromMessage(const IPC::Message* m, void** iter);
165
123 // True if this is a valid pattern. 166 // True if this is a valid pattern.
124 bool IsValid() const { return is_valid_; } 167 bool IsValid() const { return is_valid_; }
125 168
126 // True if |url| matches this pattern. 169 // True if |url| matches this pattern.
127 bool Matches(const GURL& url) const; 170 bool Matches(const GURL& url) const;
128 171
129 // Returns a std::string representation of this pattern. 172 // Returns a std::string representation of this pattern.
130 const std::string ToString() const; 173 const std::string ToString() const;
131 174
132 // Compares the pattern with a given |other| pattern and returns the 175 // Compares the pattern with a given |other| pattern and returns the
133 // |Relation| of the two patterns. 176 // |Relation| of the two patterns.
134 Relation Compare(const ContentSettingsPattern& other) const; 177 Relation Compare(const ContentSettingsPattern& other) const;
135 178
136 // Returns true if the pattern and the |other| pattern are identical. 179 // Returns true if the pattern and the |other| pattern are identical.
137 bool operator==(const ContentSettingsPattern& other) const; 180 bool operator==(const ContentSettingsPattern& other) const;
138 181
139 // Returns true if the pattern and the |other| pattern are not identical. 182 // Returns true if the pattern and the |other| pattern are not identical.
140 bool operator!=(const ContentSettingsPattern& other) const; 183 bool operator!=(const ContentSettingsPattern& other) const;
141 184
142 // Returns true if the pattern has a lower priority than the |other| pattern. 185 // Returns true if the pattern has a lower priority than the |other| pattern.
143 bool operator<(const ContentSettingsPattern& other) const; 186 bool operator<(const ContentSettingsPattern& other) const;
144 187
145 // Returns true if the pattern has a higher priority than the |other| pattern. 188 // Returns true if the pattern has a higher priority than the |other| pattern.
146 bool operator>(const ContentSettingsPattern& other) const; 189 bool operator>(const ContentSettingsPattern& other) const;
147 190
148 private: 191 private:
149 friend class content_settings::PatternParser; 192 friend class content_settings::PatternParser;
150 friend class ContentSettingsPatternParserTest_SerializePatterns_Test;
151 friend class Builder; 193 friend class Builder;
152 194 FRIEND_TEST_ALL_PREFIXES(ContentSettingsPatternParserTest, SerializePatterns);
153 struct PatternParts {
154 PatternParts();
155 ~PatternParts();
156
157 // Lowercase string of the URL scheme to match. This string is empty if the
158 // |is_scheme_wildcard| flag is set.
159 std::string scheme;
160
161 // True if the scheme wildcard is set.
162 bool is_scheme_wildcard;
163
164 // Normalized string that is either of the following:
165 // - IPv4 or IPv6
166 // - hostname
167 // - domain
168 // - empty string if the |is_host_wildcard flag is set.
169 std::string host;
170
171 // True if the domain wildcard is set.
172 bool has_domain_wildcard;
173
174 // String with the port to match. This string is empty if the
175 // |is_port_wildcard| flag is set.
176 std::string port;
177
178 // True if the port wildcard is set.
179 bool is_port_wildcard;
180
181 // TODO(markusheintz): Needed for legacy reasons. Remove. Path
182 // specification. Only used for content settings pattern with a "file"
183 // scheme part.
184 std::string path;
185 };
186 195
187 class Builder : public BuilderInterface { 196 class Builder : public BuilderInterface {
188 public: 197 public:
189 explicit Builder(bool use_legacy_validate); 198 explicit Builder(bool use_legacy_validate);
190 virtual ~Builder(); 199 virtual ~Builder();
191 200
192 // Overrides BuilderInterface 201 // Overrides BuilderInterface
193 virtual BuilderInterface* WithPort(const std::string& port); 202 virtual BuilderInterface* WithPort(const std::string& port);
194 203
195 virtual BuilderInterface* WithPortWildcard(); 204 virtual BuilderInterface* WithPortWildcard();
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 }; 257 };
249 258
250 // Stream operator so ContentSettingsPattern can be used in assertion 259 // Stream operator so ContentSettingsPattern can be used in assertion
251 // statements. 260 // statements.
252 inline std::ostream& operator<<( 261 inline std::ostream& operator<<(
253 std::ostream& out, const ContentSettingsPattern& pattern) { 262 std::ostream& out, const ContentSettingsPattern& pattern) {
254 return out << pattern.ToString(); 263 return out << pattern.ToString();
255 } 264 }
256 265
257 #endif // CHROME_COMMON_CONTENT_SETTINGS_PATTERN_H_ 266 #endif // CHROME_COMMON_CONTENT_SETTINGS_PATTERN_H_
OLDNEW
« no previous file with comments | « chrome/browser/tab_contents/tab_contents_ssl_helper.cc ('k') | chrome/common/content_settings_pattern.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698