| OLD | NEW |
| 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/browser/extensions/api/declarative/url_matcher.h" | 5 #include "chrome/browser/extensions/api/declarative/url_matcher.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <iterator> | 8 #include <iterator> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 SubstringPattern* lhs, | 376 SubstringPattern* lhs, |
| 377 SubstringPattern* rhs) const { | 377 SubstringPattern* rhs) const { |
| 378 if (lhs == NULL && rhs != NULL) return true; | 378 if (lhs == NULL && rhs != NULL) return true; |
| 379 if (lhs != NULL && rhs != NULL) | 379 if (lhs != NULL && rhs != NULL) |
| 380 return lhs->pattern() < rhs->pattern(); | 380 return lhs->pattern() < rhs->pattern(); |
| 381 // Either both are NULL or only rhs is NULL. | 381 // Either both are NULL or only rhs is NULL. |
| 382 return false; | 382 return false; |
| 383 } | 383 } |
| 384 | 384 |
| 385 // | 385 // |
| 386 // URLMatcherSchemeFilter |
| 387 // |
| 388 |
| 389 URLMatcherSchemeFilter::URLMatcherSchemeFilter(const std::string& filter) |
| 390 : filters_(1) { |
| 391 filters_.push_back(filter); |
| 392 } |
| 393 |
| 394 URLMatcherSchemeFilter::URLMatcherSchemeFilter( |
| 395 const std::vector<std::string>& filters) |
| 396 : filters_(filters) {} |
| 397 |
| 398 URLMatcherSchemeFilter::~URLMatcherSchemeFilter() {} |
| 399 |
| 400 bool URLMatcherSchemeFilter::IsMatch(const GURL& url) const { |
| 401 return std::find(filters_.begin(), filters_.end(), url.scheme()) != |
| 402 filters_.end(); |
| 403 } |
| 404 |
| 405 // |
| 386 // URLMatcherConditionSet | 406 // URLMatcherConditionSet |
| 387 // | 407 // |
| 388 | 408 |
| 389 URLMatcherConditionSet::~URLMatcherConditionSet() {} | 409 URLMatcherConditionSet::~URLMatcherConditionSet() {} |
| 390 | 410 |
| 391 URLMatcherConditionSet::URLMatcherConditionSet( | 411 URLMatcherConditionSet::URLMatcherConditionSet( |
| 392 ID id, | 412 ID id, |
| 393 const Conditions& conditions) | 413 const Conditions& conditions) |
| 394 : id_(id), | 414 : id_(id), |
| 395 conditions_(conditions) {} | 415 conditions_(conditions) {} |
| 396 | 416 |
| 417 URLMatcherConditionSet::URLMatcherConditionSet( |
| 418 ID id, |
| 419 const Conditions& conditions, |
| 420 scoped_ptr<URLMatcherSchemeFilter> scheme_filter) |
| 421 : id_(id), |
| 422 conditions_(conditions), |
| 423 scheme_filter_(scheme_filter.Pass()) {} |
| 424 |
| 397 bool URLMatcherConditionSet::IsMatch( | 425 bool URLMatcherConditionSet::IsMatch( |
| 398 const std::set<SubstringPattern::ID>& matching_substring_patterns, | 426 const std::set<SubstringPattern::ID>& matching_substring_patterns, |
| 399 const GURL& url) const { | 427 const GURL& url) const { |
| 400 for (Conditions::const_iterator i = conditions_.begin(); | 428 for (Conditions::const_iterator i = conditions_.begin(); |
| 401 i != conditions_.end(); ++i) { | 429 i != conditions_.end(); ++i) { |
| 402 if (!i->IsMatch(matching_substring_patterns, url)) | 430 if (!i->IsMatch(matching_substring_patterns, url)) |
| 403 return false; | 431 return false; |
| 404 } | 432 } |
| 433 if (scheme_filter_.get() && !scheme_filter_->IsMatch(url)) |
| 434 return false; |
| 405 return true; | 435 return true; |
| 406 } | 436 } |
| 407 | 437 |
| 408 | 438 |
| 409 // | 439 // |
| 410 // URLMatcher | 440 // URLMatcher |
| 411 // | 441 // |
| 412 | 442 |
| 413 URLMatcher::URLMatcher() {} | 443 URLMatcher::URLMatcher() {} |
| 414 | 444 |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 605 } | 635 } |
| 606 | 636 |
| 607 void URLMatcher::UpdateInternalDatastructures() { | 637 void URLMatcher::UpdateInternalDatastructures() { |
| 608 UpdateSubstringSetMatcher(false); | 638 UpdateSubstringSetMatcher(false); |
| 609 UpdateSubstringSetMatcher(true); | 639 UpdateSubstringSetMatcher(true); |
| 610 UpdateTriggers(); | 640 UpdateTriggers(); |
| 611 UpdateConditionFactory(); | 641 UpdateConditionFactory(); |
| 612 } | 642 } |
| 613 | 643 |
| 614 } // namespace extensions | 644 } // namespace extensions |
| OLD | NEW |