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

Side by Side Diff: components/content_settings/core/common/content_settings_pattern.h

Issue 1895993003: Add migration code to change existing domain scoped content settings to be origin scoped (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address review comments and split the CL Created 4 years, 6 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
OLDNEW
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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 122
123 // The version of the pattern format implemented. 123 // The version of the pattern format implemented.
124 static const int kContentSettingsPatternVersion; 124 static const int kContentSettingsPatternVersion;
125 125
126 // Returns a wildcard content settings pattern that matches all possible valid 126 // Returns a wildcard content settings pattern that matches all possible valid
127 // origins. 127 // origins.
128 static ContentSettingsPattern Wildcard(); 128 static ContentSettingsPattern Wildcard();
129 129
130 // Returns a pattern that matches the scheme and host of this URL, as well as 130 // Returns a pattern that matches the scheme and host of this URL, as well as
131 // all subdomains and ports. 131 // all subdomains and ports.
132 static ContentSettingsPattern FromURL(const GURL& url); 132 static ContentSettingsPattern FromURL(const GURL& url);
raymes 2016/06/20 04:03:26 We should remove this at some point (when we've fi
lshang 2016/06/23 01:32:32 Done. I added a TODO here.
133 133
134 // Returns a pattern that matches exactly this URL. 134 // Returns a pattern that matches exactly this URL.
135 static ContentSettingsPattern FromURLNoWildcard(const GURL& url); 135 static ContentSettingsPattern FromURLNoWildcard(const GURL& url);
136 136
137 // Returns a pattern that matches the given pattern specification. 137 // Returns a pattern that matches the given pattern specification.
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);
raymes 2016/06/20 04:03:26 Could we get away with just having one new functio
lshang 2016/06/23 01:32:31 Done.
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 using FromURL().
174 bool IsGeneratedUsingFromURL() 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
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_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698