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

Unified Diff: chrome/browser/extensions/api/declarative_webrequest/webrequest_condition.h

Issue 11572061: Create DeclarativeConditionSet, DeclarativeActionSet, and DeclarativeRule templates (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase to Vaclav's CL and fix Dominic's comments Created 8 years 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_webrequest/webrequest_condition.h
diff --git a/chrome/browser/extensions/api/declarative_webrequest/webrequest_condition.h b/chrome/browser/extensions/api/declarative_webrequest/webrequest_condition.h
index d071ff4cbe2d44dd8dca4b1d102b9bf65bfffe49..b339b378c1885078416a1f004425bde4d3da031f 100644
--- a/chrome/browser/extensions/api/declarative_webrequest/webrequest_condition.h
+++ b/chrome/browser/extensions/api/declarative_webrequest/webrequest_condition.h
@@ -11,12 +11,34 @@
#include "base/basictypes.h"
#include "base/memory/linked_ptr.h"
+#include "chrome/browser/extensions/api/declarative/declarative_rule.h"
#include "chrome/browser/extensions/api/declarative_webrequest/webrequest_condition_attribute.h"
-#include "chrome/browser/extensions/api/declarative_webrequest/webrequest_rule.h"
#include "chrome/common/extensions/matcher/url_matcher.h"
+#include "net/http/http_response_headers.h"
namespace extensions {
+// Container for information about a URLRequest to determine which
+// rules apply to the request.
+struct DeclarativeWebRequestData {
+ DeclarativeWebRequestData(net::URLRequest* request, RequestStage stage)
+ : request(request), stage(stage),
+ original_response_headers(NULL) {}
+ DeclarativeWebRequestData(
+ net::URLRequest* request, RequestStage stage,
+ const net::HttpResponseHeaders* original_response_headers)
+ : request(request), stage(stage),
+ original_response_headers(original_response_headers) {}
+ net::URLRequest* request;
+ // The set of URLMatcherConditionSets (from all rules) that match
+ // request->url().
+ const std::set<URLMatcherConditionSet::ID>* url_matches;
+ RequestStage stage;
+ // Additional information about requests that is not
+ // available in all request stages.
+ const net::HttpResponseHeaders* original_response_headers;
+};
+
// Representation of a condition in the Declarative WebRequest API. A condition
// consists of several attributes. Each of these attributes needs to be
// fulfilled in order for the condition to be fulfilled.
@@ -36,6 +58,8 @@ namespace extensions {
// WebRequestConditionSet::GetURLMatcherConditionSets.
class WebRequestCondition {
public:
+ typedef DeclarativeWebRequestData MatchData;
+
WebRequestCondition(
scoped_refptr<URLMatcherConditionSet> url_matcher_conditions,
const WebRequestConditionAttributes& condition_attributes);
@@ -50,25 +74,18 @@ class WebRequestCondition {
// Returns whether the request matches this condition. |url_matches| lists
// the IDs that match the request's URL.
- bool IsFulfilled(
- const std::set<URLMatcherConditionSet::ID>& url_matches,
- const WebRequestRule::RequestData& request_data) const;
-
- // Returns a URLMatcherConditionSet::ID which is the canonical representation
- // for all URL patterns that need to be matched by this WebRequestCondition.
- // This ID is registered in a URLMatcher that can inform us in case of a
- // match.
- URLMatcherConditionSet::ID url_matcher_condition_set_id() const {
- DCHECK(url_matcher_conditions_.get());
- return url_matcher_conditions_->id();
+ bool IsFulfilled(const DeclarativeWebRequestData& request_data) const;
+
+ // True if this condition has a url filter.
+ bool has_url_matcher_condition_set() const {
+ return bool(url_matcher_conditions_);
}
- // Returns the set of conditions that are checked on the URL. This is the
- // primary trigger for WebRequestCondition and therefore never empty.
- // (If it was empty, the URLMatcher would never notify us about network
- // requests which might fulfill the entire WebRequestCondition).
- scoped_refptr<URLMatcherConditionSet> url_matcher_condition_set() const {
- return url_matcher_conditions_;
+ // If this Condition has a url filter, appends it to |condition_sets|.
+ void GetURLMatcherConditionSets(
+ URLMatcherConditionSet::Vector* condition_sets) const {
+ if (url_matcher_conditions_)
+ condition_sets->push_back(url_matcher_conditions_);
}
// Returns the condition attributes checked by this condition.
@@ -96,51 +113,7 @@ class WebRequestCondition {
DISALLOW_COPY_AND_ASSIGN(WebRequestCondition);
};
-// This class stores a set of conditions that may be part of a WebRequestRule.
-// If any condition is fulfilled, the WebRequestActions of the WebRequestRule
-// can be triggered.
-class WebRequestConditionSet {
- public:
- typedef std::vector<linked_ptr<json_schema_compiler::any::Any> > AnyVector;
- typedef std::vector<linked_ptr<WebRequestCondition> > Conditions;
-
- explicit WebRequestConditionSet(const Conditions& conditions);
- ~WebRequestConditionSet();
-
- // Factory method that creates an WebRequestConditionSet according to the JSON
- // array |conditions| passed by the extension API.
- // Sets |error| and returns NULL in case of an error.
- static scoped_ptr<WebRequestConditionSet> Create(
- URLMatcherConditionFactory* url_matcher_condition_factory,
- const AnyVector& conditions,
- std::string* error);
-
- const Conditions& conditions() const {
- return conditions_;
- }
-
- // Returns whether any condition in the condition set is fulfilled. Filters
- // out conditions which have UrlFilter attributes but are not listed in
- // |url_matches|, and tests the rest against |request_data.request|.
- bool IsFulfilled(
- const std::set<URLMatcherConditionSet::ID>& url_matches,
- const WebRequestRule::RequestData& request_data) const;
-
- // Appends the URLMatcherConditionSet from all conditions to |condition_sets|.
- void GetURLMatcherConditionSets(
- URLMatcherConditionSet::Vector* condition_sets) const;
-
- // Returns whether there are some conditions without UrlFilter attributes.
- bool has_conditions_without_urls() const {
- return has_conditions_without_urls_;
- }
-
- private:
- const Conditions conditions_;
- const bool has_conditions_without_urls_;
-
- DISALLOW_COPY_AND_ASSIGN(WebRequestConditionSet);
-};
+typedef DeclarativeConditionSet<WebRequestCondition> WebRequestConditionSet;
} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698