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 namespace declarative_webrequest { |
| 17 class WebRequestConditionCollection; |
| 18 class WebRequestActionCollection; |
| 19 } |
| 20 } |
| 21 |
| 22 namespace extensions { |
| 23 namespace declarative_webrequest { |
| 24 |
| 25 // Representation of a rule of the declarative Web Request API |
| 26 class WebRequestRule { |
| 27 public: |
| 28 WebRequestRule(scoped_ptr<WebRequestConditionCollection> conditions, |
| 29 scoped_ptr<WebRequestActionCollection> actions); |
| 30 virtual ~WebRequestRule(); |
| 31 |
| 32 const WebRequestConditionCollection& conditions_collection() const { |
| 33 return *conditions_; |
| 34 } |
| 35 |
| 36 const WebRequestActionCollection& actions() const { |
| 37 return *actions_; |
| 38 } |
| 39 |
| 40 private: |
| 41 scoped_ptr<WebRequestConditionCollection> conditions_; |
| 42 scoped_ptr<WebRequestActionCollection> actions_; |
| 43 |
| 44 DISALLOW_COPY_AND_ASSIGN(WebRequestRule); |
| 45 }; |
| 46 |
| 47 class WebRequestRuleFactory { |
| 48 public: |
| 49 // If |error| is empty, the translation was successful and the returned |
| 50 // rule is internally consistent. |
| 51 static scoped_ptr<WebRequestRule> CreateRule( |
| 52 URLMatcherConditionFactory* url_matcher_condition_factory, |
| 53 linked_ptr<RulesRegistry::Rule> rule, |
| 54 std::string* error); |
| 55 |
| 56 private: |
| 57 // Checks whether the set of |conditions| and |actions| are consistent, |
| 58 // meaning for example that we do not allow combining an |action| that needs |
| 59 // to be executed before the |condition| can be fulfilled. |
| 60 // Returns true in case of consistency and MUST set |error| otherwise. |
| 61 static bool CheckConsistency(WebRequestConditionCollection* conditions, |
| 62 WebRequestActionCollection* actions, |
| 63 std::string* error); |
| 64 |
| 65 DISALLOW_IMPLICIT_CONSTRUCTORS(WebRequestRuleFactory); |
| 66 }; |
| 67 |
| 68 } // namespace declarative_webrequest |
| 69 } // namespace extensions |
| 70 |
| 71 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_RULE_
H_ |
OLD | NEW |