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

Side by Side Diff: chrome/common/content_settings_pattern_parser.cc

Issue 9254028: Added support for file URI path wildcards in content settings (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase on trunk Created 8 years, 11 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) 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 #include "chrome/common/content_settings_pattern_parser.h" 5 #include "chrome/common/content_settings_pattern_parser.h"
6 6
7 #include "base/string_util.h" 7 #include "base/string_util.h"
8 #include "chrome/common/url_constants.h" 8 #include "chrome/common/url_constants.h"
9 #include "net/base/net_util.h" 9 #include "net/base/net_util.h"
10 #include "googleurl/src/gurl.h" 10 #include "googleurl/src/gurl.h"
11 #include "googleurl/src/url_canon.h" 11 #include "googleurl/src/url_canon.h"
(...skipping 23 matching lines...) Expand all
35 const char* PatternParser::kDomainWildcard = "[*.]"; 35 const char* PatternParser::kDomainWildcard = "[*.]";
36 36
37 const size_t PatternParser::kDomainWildcardLength = 4; 37 const size_t PatternParser::kDomainWildcardLength = 4;
38 38
39 const char* PatternParser::kSchemeWildcard = "*"; 39 const char* PatternParser::kSchemeWildcard = "*";
40 40
41 const char* PatternParser::kHostWildcard = "*"; 41 const char* PatternParser::kHostWildcard = "*";
42 42
43 const char* PatternParser::kPortWildcard = "*"; 43 const char* PatternParser::kPortWildcard = "*";
44 44
45 const char* PatternParser::kPathWildcard = "*";
46
45 // static 47 // static
46 void PatternParser::Parse(const std::string& pattern_spec, 48 void PatternParser::Parse(const std::string& pattern_spec,
47 ContentSettingsPattern::BuilderInterface* builder) { 49 ContentSettingsPattern::BuilderInterface* builder) {
48 if (pattern_spec == "*") { 50 if (pattern_spec == "*") {
49 builder->WithSchemeWildcard(); 51 builder->WithSchemeWildcard();
50 builder->WithDomainWildcard(); 52 builder->WithDomainWildcard();
51 builder->WithPortWildcard(); 53 builder->WithPortWildcard();
52 return; 54 return;
53 } 55 }
54 56
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 for (size_t i = 0; i < port.size(); ++i) { 164 for (size_t i = 0; i < port.size(); ++i) {
163 if (!IsAsciiDigit(port[i])) { 165 if (!IsAsciiDigit(port[i])) {
164 builder->Invalid(); 166 builder->Invalid();
165 return; 167 return;
166 } 168 }
167 } 169 }
168 // TODO(markusheintz): Check port range. 170 // TODO(markusheintz): Check port range.
169 builder->WithPort(port); 171 builder->WithPort(port);
170 } 172 }
171 } else { 173 } else {
172 if (scheme != std::string(chrome::kExtensionScheme)) 174 if (scheme != std::string(chrome::kExtensionScheme) &&
175 scheme != std::string(chrome::kFileScheme))
173 builder->WithPortWildcard(); 176 builder->WithPortWildcard();
174 } 177 }
175 178
176 if (path_component.IsNonEmpty()) { 179 if (path_component.IsNonEmpty()) {
177 builder->WithPath(pattern_spec.substr(path_component.start, 180 const std::string path = pattern_spec.substr(path_component.start,
178 path_component.len)); 181 path_component.len);
182 if (path.substr(1) == kPathWildcard)
183 builder->WithPathWildcard();
184 else
185 builder->WithPath(path);
179 } 186 }
180 } 187 }
181 188
182 // static 189 // static
183 std::string PatternParser::ToString( 190 std::string PatternParser::ToString(
184 const ContentSettingsPattern::PatternParts& parts) { 191 const ContentSettingsPattern::PatternParts& parts) {
185 // Return the most compact form to support legacy code and legacy pattern 192 // Return the most compact form to support legacy code and legacy pattern
186 // strings. 193 // strings.
187 if (parts.is_scheme_wildcard && 194 if (parts.is_scheme_wildcard &&
188 parts.has_domain_wildcard && 195 parts.has_domain_wildcard &&
189 parts.host.empty() && 196 parts.host.empty() &&
190 parts.is_port_wildcard) 197 parts.is_port_wildcard)
191 return "*"; 198 return "*";
192 199
193 std::string str = ""; 200 std::string str = "";
194 if (!parts.is_scheme_wildcard) 201 if (!parts.is_scheme_wildcard)
195 str += parts.scheme + chrome::kStandardSchemeSeparator; 202 str += parts.scheme + chrome::kStandardSchemeSeparator;
196 203
197 if (parts.scheme == std::string(chrome::kFileScheme)) 204 if (parts.scheme == chrome::kFileScheme) {
198 return str + parts.path; 205 if (parts.is_path_wildcard)
206 return str + kUrlPathSeparator + kPathWildcard;
207 else
208 return str + parts.path;
209 }
199 210
200 if (parts.has_domain_wildcard) { 211 if (parts.has_domain_wildcard) {
201 if (parts.host.empty()) 212 if (parts.host.empty())
202 str += kHostWildcard; 213 str += kHostWildcard;
203 else 214 else
204 str += kDomainWildcard; 215 str += kDomainWildcard;
205 } 216 }
206 str += parts.host; 217 str += parts.host;
207 218
208 if (parts.scheme == std::string(chrome::kExtensionScheme)) { 219 if (parts.scheme == std::string(chrome::kExtensionScheme)) {
209 str += parts.path.empty() ? std::string(kUrlPathSeparator) : parts.path; 220 str += parts.path.empty() ? std::string(kUrlPathSeparator) : parts.path;
210 return str; 221 return str;
211 } 222 }
212 223
213 if (!parts.is_port_wildcard) { 224 if (!parts.is_port_wildcard) {
214 str += std::string(kUrlPortSeparator) + parts.port; 225 str += std::string(kUrlPortSeparator) + parts.port;
215 } 226 }
216 227
217 return str; 228 return str;
218 } 229 }
219 230
220 } // namespace content_settings 231 } // namespace content_settings
OLDNEW
« no previous file with comments | « chrome/common/content_settings_pattern_parser.h ('k') | chrome/common/content_settings_pattern_parser_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698