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

Side by Side Diff: extensions/common/url_pattern.cc

Issue 273193004: Move some content url constants to /url. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add missing files. Created 6 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
« no previous file with comments | « extensions/common/permissions/permissions_data.cc ('k') | extensions/common/url_pattern_set.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 "extensions/common/url_pattern.h" 5 #include "extensions/common/url_pattern.h"
6 6
7 #include "base/strings/string_number_conversions.h" 7 #include "base/strings/string_number_conversions.h"
8 #include "base/strings/string_piece.h" 8 #include "base/strings/string_piece.h"
9 #include "base/strings/string_split.h" 9 #include "base/strings/string_split.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
11 #include "content/public/common/url_constants.h" 11 #include "content/public/common/url_constants.h"
12 #include "extensions/common/constants.h" 12 #include "extensions/common/constants.h"
13 #include "url/gurl.h" 13 #include "url/gurl.h"
14 #include "url/url_util.h" 14 #include "url/url_util.h"
15 15
16 const char URLPattern::kAllUrlsPattern[] = "<all_urls>"; 16 const char URLPattern::kAllUrlsPattern[] = "<all_urls>";
17 17
18 namespace { 18 namespace {
19 19
20 // TODO(aa): What about more obscure schemes like data: and javascript: ? 20 // TODO(aa): What about more obscure schemes like data: and javascript: ?
21 // Note: keep this array in sync with kValidSchemeMasks. 21 // Note: keep this array in sync with kValidSchemeMasks.
22 const char* kValidSchemes[] = { 22 const char* kValidSchemes[] = {
23 url::kHttpScheme, 23 url::kHttpScheme,
24 url::kHttpsScheme, 24 url::kHttpsScheme,
25 content::kFileScheme, 25 url::kFileScheme,
26 content::kFtpScheme, 26 url::kFtpScheme,
27 content::kChromeUIScheme, 27 content::kChromeUIScheme,
28 extensions::kExtensionScheme, 28 extensions::kExtensionScheme,
29 content::kFileSystemScheme, 29 url::kFileSystemScheme,
30 }; 30 };
31 31
32 const int kValidSchemeMasks[] = { 32 const int kValidSchemeMasks[] = {
33 URLPattern::SCHEME_HTTP, 33 URLPattern::SCHEME_HTTP,
34 URLPattern::SCHEME_HTTPS, 34 URLPattern::SCHEME_HTTPS,
35 URLPattern::SCHEME_FILE, 35 URLPattern::SCHEME_FILE,
36 URLPattern::SCHEME_FTP, 36 URLPattern::SCHEME_FTP,
37 URLPattern::SCHEME_CHROMEUI, 37 URLPattern::SCHEME_CHROMEUI,
38 URLPattern::SCHEME_EXTENSION, 38 URLPattern::SCHEME_EXTENSION,
39 URLPattern::SCHEME_FILESYSTEM, 39 URLPattern::SCHEME_FILESYSTEM,
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 (standard_scheme ? strlen(content::kStandardSchemeSeparator) : 1); 185 (standard_scheme ? strlen(content::kStandardSchemeSeparator) : 1);
186 if (scheme_end_pos >= pattern.size()) 186 if (scheme_end_pos >= pattern.size())
187 return PARSE_ERROR_EMPTY_HOST; 187 return PARSE_ERROR_EMPTY_HOST;
188 188
189 // Parse out the host and path. 189 // Parse out the host and path.
190 size_t host_start_pos = scheme_end_pos; 190 size_t host_start_pos = scheme_end_pos;
191 size_t path_start_pos = 0; 191 size_t path_start_pos = 0;
192 192
193 if (!standard_scheme) { 193 if (!standard_scheme) {
194 path_start_pos = host_start_pos; 194 path_start_pos = host_start_pos;
195 } else if (scheme_ == content::kFileScheme) { 195 } else if (scheme_ == url::kFileScheme) {
196 size_t host_end_pos = pattern.find(kPathSeparator, host_start_pos); 196 size_t host_end_pos = pattern.find(kPathSeparator, host_start_pos);
197 if (host_end_pos == std::string::npos) { 197 if (host_end_pos == std::string::npos) {
198 // Allow hostname omission. 198 // Allow hostname omission.
199 // e.g. file://* is interpreted as file:///*, 199 // e.g. file://* is interpreted as file:///*,
200 // file://foo* is interpreted as file:///foo*. 200 // file://foo* is interpreted as file:///foo*.
201 path_start_pos = host_start_pos - 1; 201 path_start_pos = host_start_pos - 1;
202 } else { 202 } else {
203 // Ignore hostname if scheme is file://. 203 // Ignore hostname if scheme is file://.
204 // e.g. file://localhost/foo is equal to file:///foo. 204 // e.g. file://localhost/foo is equal to file:///foo.
205 path_start_pos = host_end_pos; 205 path_start_pos = host_end_pos;
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 if (match_all_urls_) { 419 if (match_all_urls_) {
420 spec_ = kAllUrlsPattern; 420 spec_ = kAllUrlsPattern;
421 return spec_; 421 return spec_;
422 } 422 }
423 423
424 bool standard_scheme = IsStandardScheme(scheme_); 424 bool standard_scheme = IsStandardScheme(scheme_);
425 425
426 std::string spec = scheme_ + 426 std::string spec = scheme_ +
427 (standard_scheme ? content::kStandardSchemeSeparator : ":"); 427 (standard_scheme ? content::kStandardSchemeSeparator : ":");
428 428
429 if (scheme_ != content::kFileScheme && standard_scheme) { 429 if (scheme_ != url::kFileScheme && standard_scheme) {
430 if (match_subdomains_) { 430 if (match_subdomains_) {
431 spec += "*"; 431 spec += "*";
432 if (!host_.empty()) 432 if (!host_.empty())
433 spec += "."; 433 spec += ".";
434 } 434 }
435 435
436 if (!host_.empty()) 436 if (!host_.empty())
437 spec += host_; 437 spec += host_;
438 438
439 if (port_ != "*") { 439 if (port_ != "*") {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 i != schemes.end(); ++i) { 486 i != schemes.end(); ++i) {
487 if (!MatchesScheme(*i)) 487 if (!MatchesScheme(*i))
488 return false; 488 return false;
489 } 489 }
490 490
491 return true; 491 return true;
492 } 492 }
493 493
494 bool URLPattern::MatchesSecurityOriginHelper(const GURL& test) const { 494 bool URLPattern::MatchesSecurityOriginHelper(const GURL& test) const {
495 // Ignore hostname if scheme is file://. 495 // Ignore hostname if scheme is file://.
496 if (scheme_ != content::kFileScheme && !MatchesHost(test)) 496 if (scheme_ != url::kFileScheme && !MatchesHost(test))
497 return false; 497 return false;
498 498
499 if (!MatchesPortPattern(base::IntToString(test.EffectiveIntPort()))) 499 if (!MatchesPortPattern(base::IntToString(test.EffectiveIntPort())))
500 return false; 500 return false;
501 501
502 return true; 502 return true;
503 } 503 }
504 504
505 bool URLPattern::MatchesPortPattern(const std::string& port) const { 505 bool URLPattern::MatchesPortPattern(const std::string& port) const {
506 return port_ == "*" || port_ == port; 506 return port_ == "*" || port_ == port;
(...skipping 29 matching lines...) Expand all
536 } 536 }
537 537
538 return result; 538 return result;
539 } 539 }
540 540
541 // static 541 // static
542 const char* URLPattern::GetParseResultString( 542 const char* URLPattern::GetParseResultString(
543 URLPattern::ParseResult parse_result) { 543 URLPattern::ParseResult parse_result) {
544 return kParseResultMessages[parse_result]; 544 return kParseResultMessages[parse_result];
545 } 545 }
OLDNEW
« no previous file with comments | « extensions/common/permissions/permissions_data.cc ('k') | extensions/common/url_pattern_set.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698