Chromium Code Reviews| 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 #ifndef CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_RULE_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_RULE_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_RULE_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_RULE_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <list> | 9 #include <list> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/time.h" | 13 #include "base/time.h" |
| 14 #include "chrome/browser/extensions/api/declarative/rules_registry.h" | 14 #include "chrome/browser/extensions/api/declarative/rules_registry.h" |
| 15 #include "chrome/browser/extensions/api/declarative_webrequest/request_stages.h" | 15 #include "chrome/browser/extensions/api/declarative_webrequest/request_stages.h" |
| 16 | 16 |
| 17 namespace extensions { | 17 namespace extensions { |
| 18 class URLMatcherConditionFactory; | 18 class URLMatcherConditionFactory; |
| 19 class WebRequestConditionSet; | 19 class WebRequestConditionSet; |
| 20 class WebRequestActionSet; | 20 class WebRequestActionSet; |
| 21 } | 21 } |
| 22 | 22 |
| 23 namespace extension_web_request_api_helpers { | 23 namespace extension_web_request_api_helpers { |
| 24 struct EventResponseDelta; | 24 struct EventResponseDelta; |
| 25 } | 25 } |
| 26 | 26 |
| 27 namespace net { | 27 namespace net { |
| 28 class HttpResponseHeaders; | |
| 28 class URLRequest; | 29 class URLRequest; |
| 29 } | 30 } |
| 30 | 31 |
| 31 namespace extensions { | 32 namespace extensions { |
| 32 | 33 |
| 33 typedef linked_ptr<extension_web_request_api_helpers::EventResponseDelta> | 34 typedef linked_ptr<extension_web_request_api_helpers::EventResponseDelta> |
| 34 LinkedPtrEventResponseDelta; | 35 LinkedPtrEventResponseDelta; |
| 35 | 36 |
| 36 // Representation of a rule of the declarative Web Request API | 37 // Representation of a rule of the declarative Web Request API |
| 37 class WebRequestRule { | 38 class WebRequestRule { |
| 38 public: | 39 public: |
| 39 typedef std::string ExtensionId; | 40 typedef std::string ExtensionId; |
| 40 typedef std::string RuleId; | 41 typedef std::string RuleId; |
| 41 typedef std::pair<ExtensionId, RuleId> GlobalRuleId; | 42 typedef std::pair<ExtensionId, RuleId> GlobalRuleId; |
| 42 typedef int Priority; | 43 typedef int Priority; |
| 43 | 44 |
| 45 // Container to pass additional information about requests that are not | |
| 46 // available in all request stages. | |
| 47 struct OptionalRequestData { | |
| 48 OptionalRequestData() : original_response_headers(0) {} | |
|
Matt Perry
2012/05/29 21:24:27
use NULL rather than 0
battre
2012/05/30 07:35:06
Done.
| |
| 49 net::HttpResponseHeaders* original_response_headers; | |
| 50 }; | |
| 51 | |
| 44 WebRequestRule(const GlobalRuleId& id, | 52 WebRequestRule(const GlobalRuleId& id, |
| 45 base::Time extension_installation_time, | 53 base::Time extension_installation_time, |
| 46 scoped_ptr<WebRequestConditionSet> conditions, | 54 scoped_ptr<WebRequestConditionSet> conditions, |
| 47 scoped_ptr<WebRequestActionSet> actions, | 55 scoped_ptr<WebRequestActionSet> actions, |
| 48 Priority priority); | 56 Priority priority); |
| 49 virtual ~WebRequestRule(); | 57 virtual ~WebRequestRule(); |
| 50 | 58 |
| 51 // If |error| is empty, the translation was successful and the returned | 59 // If |error| is empty, the translation was successful and the returned |
| 52 // rule is internally consistent. | 60 // rule is internally consistent. |
| 53 static scoped_ptr<WebRequestRule> Create( | 61 static scoped_ptr<WebRequestRule> Create( |
| 54 URLMatcherConditionFactory* url_matcher_condition_factory, | 62 URLMatcherConditionFactory* url_matcher_condition_factory, |
| 55 const std::string& extension_id, | 63 const std::string& extension_id, |
| 56 base::Time extension_installation_time, | 64 base::Time extension_installation_time, |
| 57 linked_ptr<RulesRegistry::Rule> rule, | 65 linked_ptr<RulesRegistry::Rule> rule, |
| 58 std::string* error); | 66 std::string* error); |
| 59 | 67 |
| 60 const GlobalRuleId& id() const { return id_; } | 68 const GlobalRuleId& id() const { return id_; } |
| 61 const WebRequestConditionSet& conditions() const { return *conditions_; } | 69 const WebRequestConditionSet& conditions() const { return *conditions_; } |
| 62 const WebRequestActionSet& actions() const { return *actions_; } | 70 const WebRequestActionSet& actions() const { return *actions_; } |
| 63 Priority priority() const { return priority_; } | 71 Priority priority() const { return priority_; } |
| 64 | 72 |
| 65 std::list<LinkedPtrEventResponseDelta> CreateDeltas( | 73 std::list<LinkedPtrEventResponseDelta> CreateDeltas( |
| 66 net::URLRequest* request, | 74 net::URLRequest* request, |
| 67 RequestStages request_stage) const; | 75 RequestStages request_stage, |
| 76 const OptionalRequestData& optional_request_data) const; | |
| 68 | 77 |
| 69 // Returns the minimum priority of rules that may be evaluated after | 78 // Returns the minimum priority of rules that may be evaluated after |
| 70 // this rule. Defaults to MAX_INT. Only valid if the conditions of this rule | 79 // this rule. Defaults to MAX_INT. Only valid if the conditions of this rule |
| 71 // are fulfilled. | 80 // are fulfilled. |
| 72 Priority GetMinimumPriority() const; | 81 Priority GetMinimumPriority() const; |
| 73 | 82 |
| 74 private: | 83 private: |
| 75 // Checks whether the set of |conditions| and |actions| are consistent, | 84 // Checks whether the set of |conditions| and |actions| are consistent, |
| 76 // meaning for example that we do not allow combining an |action| that needs | 85 // meaning for example that we do not allow combining an |action| that needs |
| 77 // to be executed before the |condition| can be fulfilled. | 86 // to be executed before the |condition| can be fulfilled. |
| 78 // Returns true in case of consistency and MUST set |error| otherwise. | 87 // Returns true in case of consistency and MUST set |error| otherwise. |
| 79 static bool CheckConsistency(WebRequestConditionSet* conditions, | 88 static bool CheckConsistency(WebRequestConditionSet* conditions, |
| 80 WebRequestActionSet* actions, | 89 WebRequestActionSet* actions, |
| 81 std::string* error); | 90 std::string* error); |
| 82 | 91 |
| 83 GlobalRuleId id_; | 92 GlobalRuleId id_; |
| 84 base::Time extension_installation_time_; // For precedences of rules. | 93 base::Time extension_installation_time_; // For precedences of rules. |
| 85 scoped_ptr<WebRequestConditionSet> conditions_; | 94 scoped_ptr<WebRequestConditionSet> conditions_; |
| 86 scoped_ptr<WebRequestActionSet> actions_; | 95 scoped_ptr<WebRequestActionSet> actions_; |
| 87 Priority priority_; | 96 Priority priority_; |
| 88 | 97 |
| 89 DISALLOW_COPY_AND_ASSIGN(WebRequestRule); | 98 DISALLOW_COPY_AND_ASSIGN(WebRequestRule); |
| 90 }; | 99 }; |
| 91 | 100 |
| 92 } // namespace extensions | 101 } // namespace extensions |
| 93 | 102 |
| 94 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_RULE_ H_ | 103 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_RULE_ H_ |
| OLD | NEW |