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

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

Issue 10261003: content: Move kStandardSchemeSeparator into content namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 7 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
« no previous file with comments | « chrome/common/content_settings_pattern.cc ('k') | chrome/common/extensions/extension.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #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"
10 #include "googleurl/src/gurl.h" 9 #include "googleurl/src/gurl.h"
11 #include "googleurl/src/url_canon.h" 10 #include "googleurl/src/url_canon.h"
11 #include "net/base/net_util.h"
12 12
13 namespace { 13 namespace {
14 14
15 const char* kUrlPathSeparator = "/"; 15 const char* kUrlPathSeparator = "/";
16 const char* kUrlPortSeparator = ":"; 16 const char* kUrlPortSeparator = ":";
17 17
18 class Component { 18 class Component {
19 public: 19 public:
20 Component() : start(0), len(0) {} 20 Component() : start(0), len(0) {}
21 Component(size_t s, size_t l) : start(s), len(l) {} 21 Component(size_t s, size_t l) : start(s), len(l) {}
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 Component path_component; 62 Component path_component;
63 63
64 size_t start = 0; 64 size_t start = 0;
65 size_t current_pos = 0; 65 size_t current_pos = 0;
66 66
67 if (pattern_spec.empty()) 67 if (pattern_spec.empty())
68 return; 68 return;
69 69
70 // Test if a scheme pattern is in the spec. 70 // Test if a scheme pattern is in the spec.
71 current_pos = pattern_spec.find( 71 current_pos = pattern_spec.find(
72 std::string(chrome::kStandardSchemeSeparator), start); 72 std::string(content::kStandardSchemeSeparator), start);
73 if (current_pos != std::string::npos) { 73 if (current_pos != std::string::npos) {
74 scheme_component = Component(start, current_pos); 74 scheme_component = Component(start, current_pos);
75 start = current_pos + strlen(chrome::kStandardSchemeSeparator); 75 start = current_pos + strlen(content::kStandardSchemeSeparator);
76 current_pos = start; 76 current_pos = start;
77 } else { 77 } else {
78 current_pos = start; 78 current_pos = start;
79 } 79 }
80 80
81 if (start >= pattern_spec.size()) 81 if (start >= pattern_spec.size())
82 return; // Bad pattern spec. 82 return; // Bad pattern spec.
83 83
84 // Jump to the end of domain wildcards or an IPv6 addresses. IPv6 addresses 84 // Jump to the end of domain wildcards or an IPv6 addresses. IPv6 addresses
85 // contain ':'. So first move to the end of an IPv6 address befor searching 85 // contain ':'. So first move to the end of an IPv6 address befor searching
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 // 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
193 // strings. 193 // strings.
194 if (parts.is_scheme_wildcard && 194 if (parts.is_scheme_wildcard &&
195 parts.has_domain_wildcard && 195 parts.has_domain_wildcard &&
196 parts.host.empty() && 196 parts.host.empty() &&
197 parts.is_port_wildcard) 197 parts.is_port_wildcard)
198 return "*"; 198 return "*";
199 199
200 std::string str = ""; 200 std::string str = "";
201 if (!parts.is_scheme_wildcard) 201 if (!parts.is_scheme_wildcard)
202 str += parts.scheme + chrome::kStandardSchemeSeparator; 202 str += parts.scheme + content::kStandardSchemeSeparator;
203 203
204 if (parts.scheme == chrome::kFileScheme) { 204 if (parts.scheme == chrome::kFileScheme) {
205 if (parts.is_path_wildcard) 205 if (parts.is_path_wildcard)
206 return str + kUrlPathSeparator + kPathWildcard; 206 return str + kUrlPathSeparator + kPathWildcard;
207 else 207 else
208 return str + parts.path; 208 return str + parts.path;
209 } 209 }
210 210
211 if (parts.has_domain_wildcard) { 211 if (parts.has_domain_wildcard) {
212 if (parts.host.empty()) 212 if (parts.host.empty())
213 str += kHostWildcard; 213 str += kHostWildcard;
214 else 214 else
215 str += kDomainWildcard; 215 str += kDomainWildcard;
216 } 216 }
217 str += parts.host; 217 str += parts.host;
218 218
219 if (parts.scheme == std::string(chrome::kExtensionScheme)) { 219 if (parts.scheme == std::string(chrome::kExtensionScheme)) {
220 str += parts.path.empty() ? std::string(kUrlPathSeparator) : parts.path; 220 str += parts.path.empty() ? std::string(kUrlPathSeparator) : parts.path;
221 return str; 221 return str;
222 } 222 }
223 223
224 if (!parts.is_port_wildcard) { 224 if (!parts.is_port_wildcard) {
225 str += std::string(kUrlPortSeparator) + parts.port; 225 str += std::string(kUrlPortSeparator) + parts.port;
226 } 226 }
227 227
228 return str; 228 return str;
229 } 229 }
230 230
231 } // namespace content_settings 231 } // namespace content_settings
OLDNEW
« no previous file with comments | « chrome/common/content_settings_pattern.cc ('k') | chrome/common/extensions/extension.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698