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

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

Issue 12792005: Allow extensions on chrome:// URLs, when flag is set and permission is explicitly requested (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More cleanup Created 7 years, 9 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 | « extensions/common/url_pattern.h ('k') | no next file » | 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/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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 size_t wildcard_index = path.find('*'); 104 size_t wildcard_index = path.find('*');
105 size_t path_last = path.size() - 1; 105 size_t path_last = path.size() - 1;
106 DCHECK(wildcard_index == std::string::npos || wildcard_index == path_last); 106 DCHECK(wildcard_index == std::string::npos || wildcard_index == path_last);
107 return wildcard_index == path_last ? path.substr(0, path_last) : path; 107 return wildcard_index == path_last ? path.substr(0, path_last) : path;
108 } 108 }
109 109
110 } // namespace 110 } // namespace
111 111
112 URLPattern::URLPattern() 112 URLPattern::URLPattern()
113 : valid_schemes_(SCHEME_NONE), 113 : valid_schemes_(SCHEME_NONE),
114 allowed_schemes_(SCHEME_NONE),
114 match_all_urls_(false), 115 match_all_urls_(false),
115 match_subdomains_(false), 116 match_subdomains_(false),
116 port_("*") {} 117 port_("*") {}
117 118
118 URLPattern::URLPattern(int valid_schemes) 119 URLPattern::URLPattern(int valid_schemes)
119 : valid_schemes_(valid_schemes), 120 : valid_schemes_(valid_schemes),
121 allowed_schemes_(valid_schemes),
120 match_all_urls_(false), 122 match_all_urls_(false),
121 match_subdomains_(false), 123 match_subdomains_(false),
122 port_("*") {} 124 port_("*") {}
123 125
124 URLPattern::URLPattern(int valid_schemes, const std::string& pattern) 126 URLPattern::URLPattern(int valid_schemes, const std::string& pattern)
125 // Strict error checking is used, because this constructor is only 127 // Strict error checking is used, because this constructor is only
126 // appropriate when we know |pattern| is valid. 128 // appropriate when we know |pattern| is valid.
127 : valid_schemes_(valid_schemes), 129 : valid_schemes_(valid_schemes),
130 allowed_schemes_(valid_schemes),
128 match_all_urls_(false), 131 match_all_urls_(false),
129 match_subdomains_(false), 132 match_subdomains_(false),
130 port_("*") { 133 port_("*") {
131 if (PARSE_SUCCESS != Parse(pattern)) 134 if (PARSE_SUCCESS != Parse(pattern))
132 NOTREACHED() << "URLPattern is invalid: " << pattern; 135 NOTREACHED() << "URLPattern is invalid: " << pattern;
133 } 136 }
134 137
135 URLPattern::~URLPattern() { 138 URLPattern::~URLPattern() {
136 } 139 }
137 140
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 return PARSE_ERROR_INVALID_PORT; 235 return PARSE_ERROR_INVALID_PORT;
233 host_ = host_.substr(0, port_pos); 236 host_ = host_.substr(0, port_pos);
234 } 237 }
235 238
236 // No other '*' can occur in the host, though. This isn't necessary, but is 239 // No other '*' can occur in the host, though. This isn't necessary, but is
237 // done as a convenience to developers who might otherwise be confused and 240 // done as a convenience to developers who might otherwise be confused and
238 // think '*' works as a glob in the host. 241 // think '*' works as a glob in the host.
239 if (host_.find('*') != std::string::npos) 242 if (host_.find('*') != std::string::npos)
240 return PARSE_ERROR_INVALID_HOST_WILDCARD; 243 return PARSE_ERROR_INVALID_HOST_WILDCARD;
241 244
245 SetAllowedSchemes(valid_schemes_);
246
242 return PARSE_SUCCESS; 247 return PARSE_SUCCESS;
243 } 248 }
244 249
245 void URLPattern::SetValidSchemes(int valid_schemes) { 250 void URLPattern::SetValidSchemes(int valid_schemes) {
246 spec_.clear(); 251 spec_.clear();
247 valid_schemes_ = valid_schemes; 252 valid_schemes_ = valid_schemes;
248 } 253 }
249 254
255 void URLPattern::SetAllowedSchemes(int allowed_schemes) {
256 spec_.clear();
257 allowed_schemes_ = allowed_schemes;
258 }
259
250 void URLPattern::SetHost(const std::string& host) { 260 void URLPattern::SetHost(const std::string& host) {
251 spec_.clear(); 261 spec_.clear();
252 host_ = host; 262 host_ = host;
253 } 263 }
254 264
255 void URLPattern::SetMatchAllURLs(bool val) { 265 void URLPattern::SetMatchAllURLs(bool val) {
256 spec_.clear(); 266 spec_.clear();
257 match_all_urls_ = val; 267 match_all_urls_ = val;
258 268
259 if (val) { 269 if (val) {
(...skipping 13 matching lines...) Expand all
273 spec_.clear(); 283 spec_.clear();
274 scheme_ = scheme; 284 scheme_ = scheme;
275 if (scheme_ == "*") { 285 if (scheme_ == "*") {
276 valid_schemes_ &= (SCHEME_HTTP | SCHEME_HTTPS); 286 valid_schemes_ &= (SCHEME_HTTP | SCHEME_HTTPS);
277 } else if (!IsValidScheme(scheme_)) { 287 } else if (!IsValidScheme(scheme_)) {
278 return false; 288 return false;
279 } 289 }
280 return true; 290 return true;
281 } 291 }
282 292
293 bool URLPattern::IsAllowedScheme(const std::string& scheme) const {
294 return URLPattern::IsSchemeBitSet(scheme, allowed_schemes_);
295 }
296
283 bool URLPattern::IsValidScheme(const std::string& scheme) const { 297 bool URLPattern::IsValidScheme(const std::string& scheme) const {
284 if (valid_schemes_ == SCHEME_ALL) 298 return URLPattern::IsSchemeBitSet(scheme, valid_schemes_);
299 }
300
301 bool URLPattern::IsSchemeBitSet(const std::string& scheme, const int mask) {
302 if (mask == SCHEME_ALL)
285 return true; 303 return true;
286 304
287 for (size_t i = 0; i < arraysize(kValidSchemes); ++i) { 305 for (size_t i = 0; i < arraysize(kValidSchemes); ++i) {
288 if (scheme == kValidSchemes[i] && (valid_schemes_ & kValidSchemeMasks[i])) 306 if (scheme == kValidSchemes[i] && (mask & kValidSchemeMasks[i]))
289 return true; 307 return true;
290 } 308 }
291 309
292 return false; 310 return false;
293 } 311 }
294 312
295 void URLPattern::SetPath(const std::string& path) { 313 void URLPattern::SetPath(const std::string& path) {
296 spec_.clear(); 314 spec_.clear();
297 path_ = path; 315 path_ = path;
298 path_escaped_ = path_; 316 path_escaped_ = path_;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 if (!MatchesScheme(test_url->scheme())) 364 if (!MatchesScheme(test_url->scheme()))
347 return false; 365 return false;
348 366
349 if (match_all_urls_) 367 if (match_all_urls_)
350 return true; 368 return true;
351 369
352 return MatchesSecurityOriginHelper(*test_url); 370 return MatchesSecurityOriginHelper(*test_url);
353 } 371 }
354 372
355 bool URLPattern::MatchesScheme(const std::string& test) const { 373 bool URLPattern::MatchesScheme(const std::string& test) const {
356 if (!IsValidScheme(test)) 374 if (!IsAllowedScheme(test))
357 return false; 375 return false;
358 376
359 return scheme_ == "*" || test == scheme_; 377 return scheme_ == "*" || test == scheme_;
360 } 378 }
361 379
362 bool URLPattern::MatchesHost(const std::string& host) const { 380 bool URLPattern::MatchesHost(const std::string& host) const {
363 std::string test(chrome::kHttpScheme); 381 std::string test(chrome::kHttpScheme);
364 test += content::kStandardSchemeSeparator; 382 test += content::kStandardSchemeSeparator;
365 test += host; 383 test += host;
366 test += "/"; 384 test += "/";
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 } 549 }
532 550
533 return result; 551 return result;
534 } 552 }
535 553
536 // static 554 // static
537 const char* URLPattern::GetParseResultString( 555 const char* URLPattern::GetParseResultString(
538 URLPattern::ParseResult parse_result) { 556 URLPattern::ParseResult parse_result) {
539 return kParseResultMessages[parse_result]; 557 return kParseResultMessages[parse_result];
540 } 558 }
OLDNEW
« no previous file with comments | « extensions/common/url_pattern.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698