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

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

Issue 7811006: Add full support for filesystem URLs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Style fixes, removed duplicate set of var Created 8 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
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),
100 match_subdomains_(false), 101 match_subdomains_(false),
101 port_("*") {} 102 port_("*") {}
102 103
103 URLPattern::URLPattern(int valid_schemes) 104 URLPattern::URLPattern(int valid_schemes)
104 : valid_schemes_(valid_schemes), 105 : valid_schemes_(valid_schemes),
105 match_all_urls_(false), 106 match_all_urls_(false),
107 partial_filesystem_support_hack_(false),
106 match_subdomains_(false), 108 match_subdomains_(false),
107 port_("*") {} 109 port_("*") {}
108 110
109 URLPattern::URLPattern(int valid_schemes, const std::string& pattern) 111 URLPattern::URLPattern(int valid_schemes, const std::string& pattern)
110 // Strict error checking is used, because this constructor is only 112 // Strict error checking is used, because this constructor is only
111 // appropriate when we know |pattern| is valid. 113 // appropriate when we know |pattern| is valid.
112 : valid_schemes_(valid_schemes), 114 : valid_schemes_(valid_schemes),
113 match_all_urls_(false), 115 match_all_urls_(false),
116 partial_filesystem_support_hack_(false),
114 match_subdomains_(false), 117 match_subdomains_(false),
115 port_("*") { 118 port_("*") {
116 if (PARSE_SUCCESS != Parse(pattern)) 119 if (PARSE_SUCCESS != Parse(pattern))
117 NOTREACHED() << "URLPattern is invalid: " << pattern; 120 NOTREACHED() << "URLPattern is invalid: " << pattern;
118 } 121 }
119 122
120 URLPattern::~URLPattern() { 123 URLPattern::~URLPattern() {
121 } 124 }
122 125
123 bool URLPattern::operator<(const URLPattern& other) const { 126 bool URLPattern::operator<(const URLPattern& other) const {
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 match_all_urls_ = val; 245 match_all_urls_ = val;
243 246
244 if (val) { 247 if (val) {
245 match_subdomains_ = true; 248 match_subdomains_ = true;
246 scheme_ = "*"; 249 scheme_ = "*";
247 host_.clear(); 250 host_.clear();
248 SetPath("/*"); 251 SetPath("/*");
249 } 252 }
250 } 253 }
251 254
255 void URLPattern::set_partial_filesystem_support_hack(bool val) {
Aaron Boodman 2012/03/23 21:48:32 Pure setters like this are typically in the .h fil
ericu 2012/03/23 22:47:15 Done.
256 partial_filesystem_support_hack_ = val;
257 }
258
252 void URLPattern::SetMatchSubdomains(bool val) { 259 void URLPattern::SetMatchSubdomains(bool val) {
253 spec_.clear(); 260 spec_.clear();
254 match_subdomains_ = val; 261 match_subdomains_ = val;
255 } 262 }
256 263
257 bool URLPattern::SetScheme(const std::string& scheme) { 264 bool URLPattern::SetScheme(const std::string& scheme) {
258 spec_.clear(); 265 spec_.clear();
259 scheme_ = scheme; 266 scheme_ = scheme;
260 if (scheme_ == "*") { 267 if (scheme_ == "*") {
261 valid_schemes_ &= (SCHEME_HTTP | SCHEME_HTTPS); 268 valid_schemes_ &= (SCHEME_HTTP | SCHEME_HTTPS);
(...skipping 26 matching lines...) Expand all
288 bool URLPattern::SetPort(const std::string& port) { 295 bool URLPattern::SetPort(const std::string& port) {
289 spec_.clear(); 296 spec_.clear();
290 if (IsValidPortForScheme(scheme_, port)) { 297 if (IsValidPortForScheme(scheme_, port)) {
291 port_ = port; 298 port_ = port;
292 return true; 299 return true;
293 } 300 }
294 return false; 301 return false;
295 } 302 }
296 303
297 bool URLPattern::MatchesURL(const GURL& test) const { 304 bool URLPattern::MatchesURL(const GURL& test) const {
298 if (!MatchesScheme(test.scheme())) 305 const GURL* test_url = &test;
306 bool has_inner_url = test.inner_url() != NULL;
307
308 if (partial_filesystem_support_hack_ != has_inner_url)
309 return false;
310
311 if (has_inner_url)
312 test_url = test.inner_url();
313
314 if (!MatchesScheme(test_url->scheme()))
299 return false; 315 return false;
300 316
301 if (match_all_urls_) 317 if (match_all_urls_)
302 return true; 318 return true;
303 319
304 return MatchesSecurityOriginHelper(test) && 320 std::string path_for_request = test.PathForRequest();
305 MatchesPath(test.PathForRequest()); 321 if (has_inner_url)
322 path_for_request = test_url->path() + path_for_request;
323
324 return MatchesSecurityOriginHelper(*test_url) &&
325 MatchesPath(path_for_request, has_inner_url);
306 } 326 }
307 327
308 bool URLPattern::MatchesSecurityOrigin(const GURL& test) const { 328 bool URLPattern::MatchesSecurityOrigin(const GURL& test) const {
309 if (!MatchesScheme(test.scheme())) 329 if (!MatchesScheme(test.scheme()))
310 return false; 330 return false;
311 331
312 if (match_all_urls_) 332 if (match_all_urls_)
313 return true; 333 return true;
314 334
315 return MatchesSecurityOriginHelper(test); 335 return MatchesSecurityOriginHelper(test);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 if (test.host().length() <= (host_.length() + 1)) 374 if (test.host().length() <= (host_.length() + 1))
355 return false; 375 return false;
356 376
357 if (test.host().compare(test.host().length() - host_.length(), 377 if (test.host().compare(test.host().length() - host_.length(),
358 host_.length(), host_) != 0) 378 host_.length(), host_) != 0)
359 return false; 379 return false;
360 380
361 return test.host()[test.host().length() - host_.length() - 1] == '.'; 381 return test.host()[test.host().length() - host_.length() - 1] == '.';
362 } 382 }
363 383
364 bool URLPattern::MatchesPath(const std::string& test) const { 384 bool URLPattern::MatchesPath(const std::string& test, bool nested_url)
Aaron Boodman 2012/03/23 21:48:32 I don't understand why the nested_url param is nec
ericu 2012/03/23 22:47:15 The caller is telling us where he got the path. I
ericu 2012/03/23 23:48:46 Param removed.
385 const {
386 if (nested_url != partial_filesystem_support_hack_)
387 return false;
365 if (!MatchPattern(test, path_escaped_)) 388 if (!MatchPattern(test, path_escaped_))
366 return false; 389 return false;
367 390
368 return true; 391 return true;
369 } 392 }
370 393
371 bool URLPattern::MatchesPort(int port) const { 394 bool URLPattern::MatchesPort(int port) const {
372 if (port == url_parse::PORT_INVALID) 395 if (port == url_parse::PORT_INVALID)
373 return false; 396 return false;
374 397
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 return false; 449 return false;
427 450
428 // We currently only use OverlapsWith() for the patterns inside 451 // We currently only use OverlapsWith() for the patterns inside
429 // URLPatternSet. In those cases, we know that the path will have only a 452 // URLPatternSet. In those cases, we know that the path will have only a
430 // single wildcard at the end. This makes figuring out overlap much easier. It 453 // single wildcard at the end. This makes figuring out overlap much easier. It
431 // seems like there is probably a computer-sciency way to solve the general 454 // seems like there is probably a computer-sciency way to solve the general
432 // case, but we don't need that yet. 455 // case, but we don't need that yet.
433 DCHECK(path_.find('*') == path_.size() - 1); 456 DCHECK(path_.find('*') == path_.size() - 1);
434 DCHECK(other.path().find('*') == other.path().size() - 1); 457 DCHECK(other.path().find('*') == other.path().size() - 1);
435 458
436 if (!MatchesPath(other.path().substr(0, other.path().size() - 1)) && 459 if (partial_filesystem_support_hack_ !=
437 !other.MatchesPath(path_.substr(0, path_.size() - 1))) 460 other.partial_filesystem_support_hack())
461 return false;
462
463 if (!MatchesPath(other.path().substr(0, other.path().size() - 1),
464 partial_filesystem_support_hack_) &&
465 !other.MatchesPath(path_.substr(0, path_.size() - 1),
466 partial_filesystem_support_hack_))
438 return false; 467 return false;
439 468
440 return true; 469 return true;
441 } 470 }
442 471
443 bool URLPattern::MatchesAnyScheme( 472 bool URLPattern::MatchesAnyScheme(
444 const std::vector<std::string>& schemes) const { 473 const std::vector<std::string>& schemes) const {
445 for (std::vector<std::string>::const_iterator i = schemes.begin(); 474 for (std::vector<std::string>::const_iterator i = schemes.begin();
446 i != schemes.end(); ++i) { 475 i != schemes.end(); ++i) {
447 if (MatchesScheme(*i)) 476 if (MatchesScheme(*i))
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 } 521 }
493 522
494 return result; 523 return result;
495 } 524 }
496 525
497 // static 526 // static
498 const char* URLPattern::GetParseResultString( 527 const char* URLPattern::GetParseResultString(
499 URLPattern::ParseResult parse_result) { 528 URLPattern::ParseResult parse_result) {
500 return kParseResultMessages[parse_result]; 529 return kParseResultMessages[parse_result];
501 } 530 }
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