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

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

Issue 31008: Coalesce more hardcoded schemes to using predefined constants. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 10 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/browser/tabs/tab_strip_model_unittest.cc ('k') | chrome/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) 2006-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2009 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"
6
5 #include "base/string_piece.h" 7 #include "base/string_piece.h"
6 #include "base/string_util.h" 8 #include "base/string_util.h"
7 #include "chrome/common/extensions/url_pattern.h" 9 #include "chrome/common/url_constants.h"
8 10
9 // TODO(aa): Consider adding chrome-extension? What about more obscure ones 11 // TODO(aa): Consider adding chrome-extension? What about more obscure ones
10 // like data: and javascript: ? 12 // like data: and javascript: ?
11 static const char* kValidSchemes[] = { 13 static const char* kValidSchemes[] = {
12 "http", 14 chrome::kHttpScheme,
13 "https", 15 chrome::kHttpsScheme,
14 "file", 16 chrome::kFileScheme,
15 "ftp", 17 chrome::kFtpScheme,
16 "chrome-ui" 18 chrome::kChromeUIScheme,
17 }; 19 };
18 20
19 static const char kSchemeSeparator[] = "://";
20 static const char kPathSeparator[] = "/"; 21 static const char kPathSeparator[] = "/";
21 22
22 static bool IsValidScheme(const std::string& scheme) { 23 static bool IsValidScheme(const std::string& scheme) {
23 for (size_t i = 0; i < arraysize(kValidSchemes); ++i) { 24 for (size_t i = 0; i < arraysize(kValidSchemes); ++i) {
24 if (scheme == kValidSchemes[i]) 25 if (scheme == kValidSchemes[i])
25 return true; 26 return true;
26 } 27 }
27 28
28 return false; 29 return false;
29 } 30 }
30 31
31 bool URLPattern::Parse(const std::string& pattern) { 32 bool URLPattern::Parse(const std::string& pattern) {
32 size_t scheme_end_pos = pattern.find(kSchemeSeparator); 33 size_t scheme_end_pos = pattern.find(chrome::kStandardSchemeSeparator);
33 if (scheme_end_pos == std::string::npos) 34 if (scheme_end_pos == std::string::npos)
34 return false; 35 return false;
35 36
36 scheme_ = pattern.substr(0, scheme_end_pos); 37 scheme_ = pattern.substr(0, scheme_end_pos);
37 if (!IsValidScheme(scheme_)) 38 if (!IsValidScheme(scheme_))
38 return false; 39 return false;
39 40
40 size_t host_start_pos = scheme_end_pos + strlen(kSchemeSeparator); 41 size_t host_start_pos = scheme_end_pos +
42 strlen(chrome::kStandardSchemeSeparator);
41 if (host_start_pos >= pattern.length()) 43 if (host_start_pos >= pattern.length())
42 return false; 44 return false;
43 45
44 // Parse out the host and path. 46 // Parse out the host and path.
45 size_t path_start_pos = 0; 47 size_t path_start_pos = 0;
46 48
47 // File URLs are special because they have no host. There are other schemes 49 // File URLs are special because they have no host. There are other schemes
48 // with the same structure, but we don't support them (yet). 50 // with the same structure, but we don't support them (yet).
49 if (scheme_ == "file") { 51 if (scheme_ == "file") {
50 path_start_pos = host_start_pos; 52 path_start_pos = host_start_pos;
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 ReplaceSubstringsAfterOffset(&path_escaped_, 0, "?", "\\?"); 123 ReplaceSubstringsAfterOffset(&path_escaped_, 0, "?", "\\?");
122 } 124 }
123 125
124 if (!MatchPattern(test.PathForRequest(), path_escaped_)) 126 if (!MatchPattern(test.PathForRequest(), path_escaped_))
125 return false; 127 return false;
126 128
127 return true; 129 return true;
128 } 130 }
129 131
130 std::string URLPattern::GetAsString() const { 132 std::string URLPattern::GetAsString() const {
131 std::string spec = scheme_ + kSchemeSeparator; 133 std::string spec = scheme_ + chrome::kStandardSchemeSeparator;
132 134
133 if (match_subdomains_) { 135 if (match_subdomains_) {
134 spec += "*"; 136 spec += "*";
135 if (!host_.empty()) 137 if (!host_.empty())
136 spec += "."; 138 spec += ".";
137 } 139 }
138 140
139 if (!host_.empty()) 141 if (!host_.empty())
140 spec += host_; 142 spec += host_;
141 143
142 if (!path_.empty()) 144 if (!path_.empty())
143 spec += path_; 145 spec += path_;
144 146
145 return spec; 147 return spec;
146 } 148 }
OLDNEW
« no previous file with comments | « chrome/browser/tabs/tab_strip_model_unittest.cc ('k') | chrome/common/url_constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698