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

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

Issue 10224011: Add transparent support for filesystem URLs in URLPatterns. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Updated MatchesSecurityOrigin and added a comment, as discussed in IM. 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
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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 if (!base::StringToInt(port, &parsed_port)) 90 if (!base::StringToInt(port, &parsed_port))
91 return false; 91 return false;
92 return (parsed_port >= 0) && (parsed_port < 65536); 92 return (parsed_port >= 0) && (parsed_port < 65536);
93 } 93 }
94 94
95 } // namespace 95 } // namespace
96 96
97 URLPattern::URLPattern() 97 URLPattern::URLPattern()
98 : valid_schemes_(SCHEME_NONE), 98 : valid_schemes_(SCHEME_NONE),
99 match_all_urls_(false), 99 match_all_urls_(false),
100 partial_filesystem_support_hack_(false),
101 match_subdomains_(false), 100 match_subdomains_(false),
102 port_("*") {} 101 port_("*") {}
103 102
104 URLPattern::URLPattern(int valid_schemes) 103 URLPattern::URLPattern(int valid_schemes)
105 : valid_schemes_(valid_schemes), 104 : valid_schemes_(valid_schemes),
106 match_all_urls_(false), 105 match_all_urls_(false),
107 partial_filesystem_support_hack_(false),
108 match_subdomains_(false), 106 match_subdomains_(false),
109 port_("*") {} 107 port_("*") {}
110 108
111 URLPattern::URLPattern(int valid_schemes, const std::string& pattern) 109 URLPattern::URLPattern(int valid_schemes, const std::string& pattern)
112 // Strict error checking is used, because this constructor is only 110 // Strict error checking is used, because this constructor is only
113 // appropriate when we know |pattern| is valid. 111 // appropriate when we know |pattern| is valid.
114 : valid_schemes_(valid_schemes), 112 : valid_schemes_(valid_schemes),
115 match_all_urls_(false), 113 match_all_urls_(false),
116 partial_filesystem_support_hack_(false),
117 match_subdomains_(false), 114 match_subdomains_(false),
118 port_("*") { 115 port_("*") {
119 if (PARSE_SUCCESS != Parse(pattern)) 116 if (PARSE_SUCCESS != Parse(pattern))
120 NOTREACHED() << "URLPattern is invalid: " << pattern; 117 NOTREACHED() << "URLPattern is invalid: " << pattern;
121 } 118 }
122 119
123 URLPattern::~URLPattern() { 120 URLPattern::~URLPattern() {
124 } 121 }
125 122
126 bool URLPattern::operator<(const URLPattern& other) const { 123 bool URLPattern::operator<(const URLPattern& other) const {
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 port_ = port; 291 port_ = port;
295 return true; 292 return true;
296 } 293 }
297 return false; 294 return false;
298 } 295 }
299 296
300 bool URLPattern::MatchesURL(const GURL& test) const { 297 bool URLPattern::MatchesURL(const GURL& test) const {
301 const GURL* test_url = &test; 298 const GURL* test_url = &test;
302 bool has_inner_url = test.inner_url() != NULL; 299 bool has_inner_url = test.inner_url() != NULL;
303 300
304 if (partial_filesystem_support_hack_ != has_inner_url) 301 if (has_inner_url) {
305 return false; 302 if (!test.SchemeIsFileSystem())
306 303 return false; // The only nested URLs we handle are filesystem URLs.
307 if (has_inner_url)
308 test_url = test.inner_url(); 304 test_url = test.inner_url();
305 }
309 306
310 if (!MatchesScheme(test_url->scheme())) 307 if (!MatchesScheme(test_url->scheme()))
311 return false; 308 return false;
312 309
313 if (match_all_urls_) 310 if (match_all_urls_)
314 return true; 311 return true;
315 312
316 std::string path_for_request = test.PathForRequest(); 313 std::string path_for_request = test.PathForRequest();
317 if (has_inner_url) 314 if (has_inner_url)
318 path_for_request = test_url->path() + path_for_request; 315 path_for_request = test_url->path() + path_for_request;
319 316
320 return MatchesSecurityOriginHelper(*test_url) && 317 return MatchesSecurityOriginHelper(*test_url) &&
321 MatchesPath(path_for_request); 318 MatchesPath(path_for_request);
322 } 319 }
323 320
324 bool URLPattern::MatchesSecurityOrigin(const GURL& test) const { 321 bool URLPattern::MatchesSecurityOrigin(const GURL& test) const {
325 if (!MatchesScheme(test.scheme())) 322 const GURL* test_url = &test;
323 bool has_inner_url = test.inner_url() != NULL;
324
325 if (has_inner_url) {
326 if (!test.SchemeIsFileSystem())
327 return false; // The only nested URLs we handle are filesystem URLs.
328 test_url = test.inner_url();
329 }
330
331 if (!MatchesScheme(test_url->scheme()))
326 return false; 332 return false;
327 333
328 if (match_all_urls_) 334 if (match_all_urls_)
329 return true; 335 return true;
330 336
331 return MatchesSecurityOriginHelper(test); 337 return MatchesSecurityOriginHelper(*test_url);
332 } 338 }
333 339
334 bool URLPattern::MatchesScheme(const std::string& test) const { 340 bool URLPattern::MatchesScheme(const std::string& test) const {
335 if (!IsValidScheme(test)) 341 if (!IsValidScheme(test))
336 return false; 342 return false;
337 343
338 return scheme_ == "*" || test == scheme_; 344 return scheme_ == "*" || test == scheme_;
339 } 345 }
340 346
341 bool URLPattern::MatchesHost(const std::string& host) const { 347 bool URLPattern::MatchesHost(const std::string& host) const {
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 return false; 448 return false;
443 449
444 // We currently only use OverlapsWith() for the patterns inside 450 // We currently only use OverlapsWith() for the patterns inside
445 // URLPatternSet. In those cases, we know that the path will have only a 451 // URLPatternSet. In those cases, we know that the path will have only a
446 // single wildcard at the end. This makes figuring out overlap much easier. It 452 // single wildcard at the end. This makes figuring out overlap much easier. It
447 // seems like there is probably a computer-sciency way to solve the general 453 // seems like there is probably a computer-sciency way to solve the general
448 // case, but we don't need that yet. 454 // case, but we don't need that yet.
449 DCHECK(path_.find('*') == path_.size() - 1); 455 DCHECK(path_.find('*') == path_.size() - 1);
450 DCHECK(other.path().find('*') == other.path().size() - 1); 456 DCHECK(other.path().find('*') == other.path().size() - 1);
451 457
452 if (partial_filesystem_support_hack_ !=
453 other.partial_filesystem_support_hack())
454 return false;
455
456 if (!MatchesPath(other.path().substr(0, other.path().size() - 1)) && 458 if (!MatchesPath(other.path().substr(0, other.path().size() - 1)) &&
457 !other.MatchesPath(path_.substr(0, path_.size() - 1))) 459 !other.MatchesPath(path_.substr(0, path_.size() - 1)))
458 return false; 460 return false;
459 461
460 return true; 462 return true;
461 } 463 }
462 464
463 bool URLPattern::MatchesAnyScheme( 465 bool URLPattern::MatchesAnyScheme(
464 const std::vector<std::string>& schemes) const { 466 const std::vector<std::string>& schemes) const {
465 for (std::vector<std::string>::const_iterator i = schemes.begin(); 467 for (std::vector<std::string>::const_iterator i = schemes.begin();
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 } 514 }
513 515
514 return result; 516 return result;
515 } 517 }
516 518
517 // static 519 // static
518 const char* URLPattern::GetParseResultString( 520 const char* URLPattern::GetParseResultString(
519 URLPattern::ParseResult parse_result) { 521 URLPattern::ParseResult parse_result) {
520 return kParseResultMessages[parse_result]; 522 return kParseResultMessages[parse_result];
521 } 523 }
OLDNEW
« no previous file with comments | « chrome/common/extensions/url_pattern.h ('k') | chrome/common/extensions/url_pattern_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698