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

Side by Side Diff: chrome/browser/extensions/api/declarative/url_matcher.cc

Issue 10052035: Implemented port filter for URLMatcher (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comment Created 8 years, 8 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/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 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 : filters_(filters) {} 396 : filters_(filters) {}
397 397
398 URLMatcherSchemeFilter::~URLMatcherSchemeFilter() {} 398 URLMatcherSchemeFilter::~URLMatcherSchemeFilter() {}
399 399
400 bool URLMatcherSchemeFilter::IsMatch(const GURL& url) const { 400 bool URLMatcherSchemeFilter::IsMatch(const GURL& url) const {
401 return std::find(filters_.begin(), filters_.end(), url.scheme()) != 401 return std::find(filters_.begin(), filters_.end(), url.scheme()) !=
402 filters_.end(); 402 filters_.end();
403 } 403 }
404 404
405 // 405 //
406 // URLMatcherPortFilter
407 //
408
409 URLMatcherPortFilter::URLMatcherPortFilter(
410 const std::vector<URLMatcherPortFilter::Range>& ranges)
411 : ranges_(ranges) {}
412
413 URLMatcherPortFilter::~URLMatcherPortFilter() {}
414
415 bool URLMatcherPortFilter::IsMatch(const GURL& url) const {
416 int port = url.EffectiveIntPort();
417 for (std::vector<Range>::const_iterator i = ranges_.begin();
418 i != ranges_.end(); ++i) {
419 if (i->first <= port && port <= i->second)
420 return true;
421 }
422 return false;
423 }
424
425 // static
426 URLMatcherPortFilter::Range URLMatcherPortFilter::CreateRange(int from,
427 int to) {
428 return Range(from, to);
429 }
430
431 // static
432 URLMatcherPortFilter::Range URLMatcherPortFilter::CreateRange(int port) {
433 return Range(port, port);
434 }
435
436 //
406 // URLMatcherConditionSet 437 // URLMatcherConditionSet
407 // 438 //
408 439
409 URLMatcherConditionSet::~URLMatcherConditionSet() {} 440 URLMatcherConditionSet::~URLMatcherConditionSet() {}
410 441
411 URLMatcherConditionSet::URLMatcherConditionSet( 442 URLMatcherConditionSet::URLMatcherConditionSet(
412 ID id, 443 ID id,
413 const Conditions& conditions) 444 const Conditions& conditions)
414 : id_(id), 445 : id_(id),
415 conditions_(conditions) {} 446 conditions_(conditions) {}
416 447
417 URLMatcherConditionSet::URLMatcherConditionSet( 448 URLMatcherConditionSet::URLMatcherConditionSet(
418 ID id, 449 ID id,
419 const Conditions& conditions, 450 const Conditions& conditions,
420 scoped_ptr<URLMatcherSchemeFilter> scheme_filter) 451 scoped_ptr<URLMatcherSchemeFilter> scheme_filter,
452 scoped_ptr<URLMatcherPortFilter> port_filter)
421 : id_(id), 453 : id_(id),
422 conditions_(conditions), 454 conditions_(conditions),
423 scheme_filter_(scheme_filter.Pass()) {} 455 scheme_filter_(scheme_filter.Pass()),
456 port_filter_(port_filter.Pass()) {}
424 457
425 bool URLMatcherConditionSet::IsMatch( 458 bool URLMatcherConditionSet::IsMatch(
426 const std::set<SubstringPattern::ID>& matching_substring_patterns, 459 const std::set<SubstringPattern::ID>& matching_substring_patterns,
427 const GURL& url) const { 460 const GURL& url) const {
428 for (Conditions::const_iterator i = conditions_.begin(); 461 for (Conditions::const_iterator i = conditions_.begin();
429 i != conditions_.end(); ++i) { 462 i != conditions_.end(); ++i) {
430 if (!i->IsMatch(matching_substring_patterns, url)) 463 if (!i->IsMatch(matching_substring_patterns, url))
431 return false; 464 return false;
432 } 465 }
433 if (scheme_filter_.get() && !scheme_filter_->IsMatch(url)) 466 if (scheme_filter_.get() && !scheme_filter_->IsMatch(url))
434 return false; 467 return false;
468 if (port_filter_.get() && !port_filter_->IsMatch(url))
469 return false;
435 return true; 470 return true;
436 } 471 }
437 472
438 473
439 // 474 //
440 // URLMatcher 475 // URLMatcher
441 // 476 //
442 477
443 URLMatcher::URLMatcher() {} 478 URLMatcher::URLMatcher() {}
444 479
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
635 } 670 }
636 671
637 void URLMatcher::UpdateInternalDatastructures() { 672 void URLMatcher::UpdateInternalDatastructures() {
638 UpdateSubstringSetMatcher(false); 673 UpdateSubstringSetMatcher(false);
639 UpdateSubstringSetMatcher(true); 674 UpdateSubstringSetMatcher(true);
640 UpdateTriggers(); 675 UpdateTriggers();
641 UpdateConditionFactory(); 676 UpdateConditionFactory();
642 } 677 }
643 678
644 } // namespace extensions 679 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698