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

Side by Side Diff: chrome/common/extensions/url_pattern.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/extensions/extension.cc ('k') | content/public/common/url_constants.h » ('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/extensions/url_pattern.h" 5 #include "chrome/common/extensions/url_pattern.h"
6 6
7 #include "base/string_number_conversions.h" 7 #include "base/string_number_conversions.h"
8 #include "base/string_piece.h" 8 #include "base/string_piece.h"
9 #include "base/string_split.h" 9 #include "base/string_split.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 SetMatchSubdomains(false); 137 SetMatchSubdomains(false);
138 SetPort("*"); 138 SetPort("*");
139 139
140 // Special case pattern to match every valid URL. 140 // Special case pattern to match every valid URL.
141 if (pattern == kAllUrlsPattern) { 141 if (pattern == kAllUrlsPattern) {
142 SetMatchAllURLs(true); 142 SetMatchAllURLs(true);
143 return PARSE_SUCCESS; 143 return PARSE_SUCCESS;
144 } 144 }
145 145
146 // Parse out the scheme. 146 // Parse out the scheme.
147 size_t scheme_end_pos = pattern.find(chrome::kStandardSchemeSeparator); 147 size_t scheme_end_pos = pattern.find(content::kStandardSchemeSeparator);
148 bool has_standard_scheme_separator = true; 148 bool has_standard_scheme_separator = true;
149 149
150 // Some urls also use ':' alone as the scheme separator. 150 // Some urls also use ':' alone as the scheme separator.
151 if (scheme_end_pos == std::string::npos) { 151 if (scheme_end_pos == std::string::npos) {
152 scheme_end_pos = pattern.find(':'); 152 scheme_end_pos = pattern.find(':');
153 has_standard_scheme_separator = false; 153 has_standard_scheme_separator = false;
154 } 154 }
155 155
156 if (scheme_end_pos == std::string::npos) 156 if (scheme_end_pos == std::string::npos)
157 return PARSE_ERROR_MISSING_SCHEME_SEPARATOR; 157 return PARSE_ERROR_MISSING_SCHEME_SEPARATOR;
158 158
159 if (!SetScheme(pattern.substr(0, scheme_end_pos))) 159 if (!SetScheme(pattern.substr(0, scheme_end_pos)))
160 return PARSE_ERROR_INVALID_SCHEME; 160 return PARSE_ERROR_INVALID_SCHEME;
161 161
162 bool standard_scheme = IsStandardScheme(scheme_); 162 bool standard_scheme = IsStandardScheme(scheme_);
163 if (standard_scheme != has_standard_scheme_separator) 163 if (standard_scheme != has_standard_scheme_separator)
164 return PARSE_ERROR_WRONG_SCHEME_SEPARATOR; 164 return PARSE_ERROR_WRONG_SCHEME_SEPARATOR;
165 165
166 // Advance past the scheme separator. 166 // Advance past the scheme separator.
167 scheme_end_pos += 167 scheme_end_pos +=
168 (standard_scheme ? strlen(chrome::kStandardSchemeSeparator) : 1); 168 (standard_scheme ? strlen(content::kStandardSchemeSeparator) : 1);
169 if (scheme_end_pos >= pattern.size()) 169 if (scheme_end_pos >= pattern.size())
170 return PARSE_ERROR_EMPTY_HOST; 170 return PARSE_ERROR_EMPTY_HOST;
171 171
172 // Parse out the host and path. 172 // Parse out the host and path.
173 size_t host_start_pos = scheme_end_pos; 173 size_t host_start_pos = scheme_end_pos;
174 size_t path_start_pos = 0; 174 size_t path_start_pos = 0;
175 175
176 if (!standard_scheme) { 176 if (!standard_scheme) {
177 path_start_pos = host_start_pos; 177 path_start_pos = host_start_pos;
178 } else if (scheme_ == chrome::kFileScheme) { 178 } else if (scheme_ == chrome::kFileScheme) {
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 333
334 bool URLPattern::MatchesScheme(const std::string& test) const { 334 bool URLPattern::MatchesScheme(const std::string& test) const {
335 if (!IsValidScheme(test)) 335 if (!IsValidScheme(test))
336 return false; 336 return false;
337 337
338 return scheme_ == "*" || test == scheme_; 338 return scheme_ == "*" || test == scheme_;
339 } 339 }
340 340
341 bool URLPattern::MatchesHost(const std::string& host) const { 341 bool URLPattern::MatchesHost(const std::string& host) const {
342 std::string test(chrome::kHttpScheme); 342 std::string test(chrome::kHttpScheme);
343 test += chrome::kStandardSchemeSeparator; 343 test += content::kStandardSchemeSeparator;
344 test += host; 344 test += host;
345 test += "/"; 345 test += "/";
346 return MatchesHost(GURL(test)); 346 return MatchesHost(GURL(test));
347 } 347 }
348 348
349 bool URLPattern::MatchesHost(const GURL& test) const { 349 bool URLPattern::MatchesHost(const GURL& test) const {
350 // If the hosts are exactly equal, we have a match. 350 // If the hosts are exactly equal, we have a match.
351 if (test.host() == host_) 351 if (test.host() == host_)
352 return true; 352 return true;
353 353
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 return spec_; 397 return spec_;
398 398
399 if (match_all_urls_) { 399 if (match_all_urls_) {
400 spec_ = kAllUrlsPattern; 400 spec_ = kAllUrlsPattern;
401 return spec_; 401 return spec_;
402 } 402 }
403 403
404 bool standard_scheme = IsStandardScheme(scheme_); 404 bool standard_scheme = IsStandardScheme(scheme_);
405 405
406 std::string spec = scheme_ + 406 std::string spec = scheme_ +
407 (standard_scheme ? chrome::kStandardSchemeSeparator : ":"); 407 (standard_scheme ? content::kStandardSchemeSeparator : ":");
408 408
409 if (scheme_ != chrome::kFileScheme && standard_scheme) { 409 if (scheme_ != chrome::kFileScheme && standard_scheme) {
410 if (match_subdomains_) { 410 if (match_subdomains_) {
411 spec += "*"; 411 spec += "*";
412 if (!host_.empty()) 412 if (!host_.empty())
413 spec += "."; 413 spec += ".";
414 } 414 }
415 415
416 if (!host_.empty()) 416 if (!host_.empty())
417 spec += host_; 417 spec += host_;
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 } 512 }
513 513
514 return result; 514 return result;
515 } 515 }
516 516
517 // static 517 // static
518 const char* URLPattern::GetParseResultString( 518 const char* URLPattern::GetParseResultString(
519 URLPattern::ParseResult parse_result) { 519 URLPattern::ParseResult parse_result) {
520 return kParseResultMessages[parse_result]; 520 return kParseResultMessages[parse_result];
521 } 521 }
OLDNEW
« no previous file with comments | « chrome/common/extensions/extension.cc ('k') | content/public/common/url_constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698