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

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

Issue 11547033: Implement declarativeContent API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 922dba7f111ffdc12352c2e06703c3fa828e3197..921400ab9d2dfbf78a29758710150e8fb92524ba 100644
--- a/chrome/browser/extensions/api/declarative_webrequest/webrequest_condition.h
+++ b/chrome/browser/extensions/api/declarative_webrequest/webrequest_condition.h
@@ -10,12 +10,29 @@
#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 {
+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;
+ 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.
@@ -35,6 +52,8 @@ namespace extensions {
// WebRequestConditionSet::GetURLMatcherConditionSets.
class WebRequestCondition {
public:
+ typedef DeclarativeWebRequestData MatchData;
+
WebRequestCondition(
scoped_refptr<URLMatcherConditionSet> url_matcher_conditions,
const WebRequestConditionAttributes& condition_attributes);
@@ -49,7 +68,7 @@ class WebRequestCondition {
// Returns whether the request is a match, given that the URLMatcher found
// a match for |url_matcher_conditions_|.
- bool IsFulfilled(const WebRequestRule::RequestData& request_data) const;
+ bool IsFulfilled(const DeclarativeWebRequestData& request_data) const;
// Returns a URLMatcherConditionSet::ID which is the canonical representation
// for all URL patterns that need to be matched by this WebRequestCondition.
@@ -88,51 +107,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
- // based on a match |url_match| and the value of |request_data.request|.
- // This function should be called for each URLMatcherConditionSet::ID
- // that was found by the URLMatcher to ensure that the each trigger in
- // |match_triggers_| is found.
- bool IsFulfilled(
- URLMatcherConditionSet::ID url_match,
- const WebRequestRule::RequestData& request_data) const;
-
- // Appends the URLMatcherConditionSet from all conditions to |condition_sets|.
- void GetURLMatcherConditionSets(
- URLMatcherConditionSet::Vector* condition_sets) const;
-
- private:
- Conditions conditions_;
-
- typedef std::map<URLMatcherConditionSet::ID, WebRequestCondition*>
- MatchTriggers;
- MatchTriggers match_triggers_;
-
- DISALLOW_COPY_AND_ASSIGN(WebRequestConditionSet);
-};
+typedef DeclarativeConditionSet<WebRequestCondition> WebRequestConditionSet;
} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698