OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_RULE_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_RULE_H_ |
| 7 #pragma once |
| 8 |
| 9 #include <vector> |
| 10 |
| 11 #include "base/compiler_specific.h" |
| 12 #include "chrome/browser/extensions/api/declarative/rules_registry.h" |
| 13 |
| 14 namespace extensions { |
| 15 class URLMatcherConditionFactory; |
| 16 class WebRequestConditionSet; |
| 17 class WebRequestActionSet; |
| 18 } |
| 19 |
| 20 namespace extensions { |
| 21 |
| 22 // Representation of a rule of the declarative Web Request API |
| 23 class WebRequestRule { |
| 24 public: |
| 25 typedef std::string ExtensionId; |
| 26 typedef std::string RuleId; |
| 27 typedef std::pair<ExtensionId, RuleId> GlobalRuleId; |
| 28 |
| 29 WebRequestRule(const GlobalRuleId& id, |
| 30 scoped_ptr<WebRequestConditionSet> conditions, |
| 31 scoped_ptr<WebRequestActionSet> actions); |
| 32 virtual ~WebRequestRule(); |
| 33 |
| 34 // If |error| is empty, the translation was successful and the returned |
| 35 // rule is internally consistent. |
| 36 static scoped_ptr<WebRequestRule> Create( |
| 37 URLMatcherConditionFactory* url_matcher_condition_factory, |
| 38 const std::string& extension_id, |
| 39 linked_ptr<RulesRegistry::Rule> rule, |
| 40 std::string* error); |
| 41 |
| 42 const GlobalRuleId& id() const { return id_; } |
| 43 const WebRequestConditionSet& conditions() const { return *conditions_; } |
| 44 const WebRequestActionSet& actions() const { return *actions_; } |
| 45 |
| 46 private: |
| 47 // Checks whether the set of |conditions| and |actions| are consistent, |
| 48 // meaning for example that we do not allow combining an |action| that needs |
| 49 // to be executed before the |condition| can be fulfilled. |
| 50 // Returns true in case of consistency and MUST set |error| otherwise. |
| 51 static bool CheckConsistency(WebRequestConditionSet* conditions, |
| 52 WebRequestActionSet* actions, |
| 53 std::string* error); |
| 54 |
| 55 GlobalRuleId id_; |
| 56 scoped_ptr<WebRequestConditionSet> conditions_; |
| 57 scoped_ptr<WebRequestActionSet> actions_; |
| 58 |
| 59 DISALLOW_COPY_AND_ASSIGN(WebRequestRule); |
| 60 }; |
| 61 |
| 62 } // namespace extensions |
| 63 |
| 64 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_RULE_
H_ |
OLD | NEW |