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

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

Issue 8312005: Ignore paths when matching patterns for extensions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 9 years, 1 month 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/common/extensions/url_pattern.h ('k') | chrome/common/extensions/url_pattern_set.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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 300
301 bool URLPattern::SetPort(const std::string& port) { 301 bool URLPattern::SetPort(const std::string& port) {
302 spec_.clear(); 302 spec_.clear();
303 if (IsValidPortForScheme(scheme_, port)) { 303 if (IsValidPortForScheme(scheme_, port)) {
304 port_ = port; 304 port_ = port;
305 return true; 305 return true;
306 } 306 }
307 return false; 307 return false;
308 } 308 }
309 309
310 bool URLPattern::MatchesURL(const GURL &test) const { 310 bool URLPattern::MatchesURL(const GURL& test) const {
311 if (!MatchesScheme(test.scheme())) 311 if (!MatchesScheme(test.scheme()))
312 return false; 312 return false;
313 313
314 if (match_all_urls_) 314 if (match_all_urls_)
315 return true; 315 return true;
316 316
317 // Ignore hostname if scheme is file://. 317 return MatchesSecurityOriginHelper(test) &&
318 if (scheme_ != chrome::kFileScheme && !MatchesHost(test)) 318 MatchesPath(test.PathForRequest());
319 }
320
321 bool URLPattern::MatchesSecurityOrigin(const GURL& test) const {
322 if (!MatchesScheme(test.scheme()))
319 return false; 323 return false;
320 324
321 if (!MatchesPath(test.PathForRequest())) 325 if (match_all_urls_)
322 return false; 326 return true;
323 327
324 if (!MatchesPort(test.EffectiveIntPort())) 328 return MatchesSecurityOriginHelper(test);
325 return false;
326
327 return true;
328 } 329 }
329 330
330 bool URLPattern::MatchesScheme(const std::string& test) const { 331 bool URLPattern::MatchesScheme(const std::string& test) const {
331 if (!IsValidScheme(test)) 332 if (!IsValidScheme(test))
332 return false; 333 return false;
333 334
334 return scheme_ == "*" || test == scheme_; 335 return scheme_ == "*" || test == scheme_;
335 } 336 }
336 337
337 bool URLPattern::MatchesHost(const std::string& host) const { 338 bool URLPattern::MatchesHost(const std::string& host) const {
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 const std::vector<std::string>& schemes) const { 457 const std::vector<std::string>& schemes) const {
457 for (std::vector<std::string>::const_iterator i = schemes.begin(); 458 for (std::vector<std::string>::const_iterator i = schemes.begin();
458 i != schemes.end(); ++i) { 459 i != schemes.end(); ++i) {
459 if (MatchesScheme(*i)) 460 if (MatchesScheme(*i))
460 return true; 461 return true;
461 } 462 }
462 463
463 return false; 464 return false;
464 } 465 }
465 466
467 bool URLPattern::MatchesSecurityOriginHelper(const GURL& test) const {
468 // Ignore hostname if scheme is file://.
469 if (scheme_ != chrome::kFileScheme && !MatchesHost(test))
470 return false;
471
472 if (!MatchesPort(test.EffectiveIntPort()))
473 return false;
474
475 return true;
476 }
477
466 std::vector<std::string> URLPattern::GetExplicitSchemes() const { 478 std::vector<std::string> URLPattern::GetExplicitSchemes() const {
467 std::vector<std::string> result; 479 std::vector<std::string> result;
468 480
469 if (scheme_ != "*" && !match_all_urls_ && IsValidScheme(scheme_)) { 481 if (scheme_ != "*" && !match_all_urls_ && IsValidScheme(scheme_)) {
470 result.push_back(scheme_); 482 result.push_back(scheme_);
471 return result; 483 return result;
472 } 484 }
473 485
474 for (size_t i = 0; i < arraysize(kValidSchemes); ++i) { 486 for (size_t i = 0; i < arraysize(kValidSchemes); ++i) {
475 if (MatchesScheme(kValidSchemes[i])) { 487 if (MatchesScheme(kValidSchemes[i])) {
(...skipping 17 matching lines...) Expand all
493 } 505 }
494 506
495 return result; 507 return result;
496 } 508 }
497 509
498 // static 510 // static
499 const char* URLPattern::GetParseResultString( 511 const char* URLPattern::GetParseResultString(
500 URLPattern::ParseResult parse_result) { 512 URLPattern::ParseResult parse_result) {
501 return kParseResultMessages[parse_result]; 513 return kParseResultMessages[parse_result];
502 } 514 }
OLDNEW
« no previous file with comments | « chrome/common/extensions/url_pattern.h ('k') | chrome/common/extensions/url_pattern_set.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698