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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/api/declarative/url_matcher.cc
diff --git a/chrome/browser/extensions/api/declarative/url_matcher.cc b/chrome/browser/extensions/api/declarative/url_matcher.cc
index 816c890c499b2a5bfdd2ecd71ae7ce4ecb818e01..a366e1c7edf0e9ebb9c304118e531b9ca0b1fc6b 100644
--- a/chrome/browser/extensions/api/declarative/url_matcher.cc
+++ b/chrome/browser/extensions/api/declarative/url_matcher.cc
@@ -403,6 +403,37 @@ bool URLMatcherSchemeFilter::IsMatch(const GURL& url) const {
}
//
+// URLMatcherPortFilter
+//
+
+URLMatcherPortFilter::URLMatcherPortFilter(
+ const std::vector<URLMatcherPortFilter::Range>& ranges)
+ : ranges_(ranges) {}
+
+URLMatcherPortFilter::~URLMatcherPortFilter() {}
+
+bool URLMatcherPortFilter::IsMatch(const GURL& url) const {
+ int port = url.EffectiveIntPort();
+ for (std::vector<Range>::const_iterator i = ranges_.begin();
+ i != ranges_.end(); ++i) {
+ if (i->first <= port && port <= i->second)
+ return true;
+ }
+ return false;
+}
+
+// static
+URLMatcherPortFilter::Range URLMatcherPortFilter::CreateRange(int from,
+ int to) {
+ return Range(from, to);
+}
+
+// static
+URLMatcherPortFilter::Range URLMatcherPortFilter::CreateRange(int port) {
+ return Range(port, port);
+}
+
+//
// URLMatcherConditionSet
//
@@ -417,10 +448,12 @@ URLMatcherConditionSet::URLMatcherConditionSet(
URLMatcherConditionSet::URLMatcherConditionSet(
ID id,
const Conditions& conditions,
- scoped_ptr<URLMatcherSchemeFilter> scheme_filter)
+ scoped_ptr<URLMatcherSchemeFilter> scheme_filter,
+ scoped_ptr<URLMatcherPortFilter> port_filter)
: id_(id),
conditions_(conditions),
- scheme_filter_(scheme_filter.Pass()) {}
+ scheme_filter_(scheme_filter.Pass()),
+ port_filter_(port_filter.Pass()) {}
bool URLMatcherConditionSet::IsMatch(
const std::set<SubstringPattern::ID>& matching_substring_patterns,
@@ -432,6 +465,8 @@ bool URLMatcherConditionSet::IsMatch(
}
if (scheme_filter_.get() && !scheme_filter_->IsMatch(url))
return false;
+ if (port_filter_.get() && !port_filter_->IsMatch(url))
+ return false;
return true;
}

Powered by Google App Engine
This is Rietveld 408576698