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_ACTION_H
_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_ACTION_H
_ |
| 7 #pragma once |
| 8 |
| 9 #include <string> |
| 10 #include <vector> |
| 11 |
| 12 #include "base/compiler_specific.h" |
| 13 #include "base/memory/linked_ptr.h" |
| 14 #include "tools/json_schema_compiler/any.h" |
| 15 |
| 16 namespace base { |
| 17 class Value; |
| 18 } |
| 19 |
| 20 namespace extensions { |
| 21 namespace declarative_webrequest { |
| 22 |
| 23 // Base class for all WebRequestActions of the declarative Web Request API. |
| 24 class WebRequestAction { |
| 25 public: |
| 26 enum Types { |
| 27 ACTION_CANCEL_REQUEST |
| 28 }; |
| 29 |
| 30 WebRequestAction(); |
| 31 virtual ~WebRequestAction(); |
| 32 |
| 33 // Returns a bit vector representing extensions::RequestStages. The bit vector |
| 34 // contains a 1 for each request stage during which the condition can be |
| 35 // tested. |
| 36 virtual int GetStages() const = 0; |
| 37 |
| 38 virtual Types type() const = 0; |
| 39 |
| 40 // TODO(battre): Add method that corresponds to executing the action. |
| 41 }; |
| 42 |
| 43 // Immutable container for multiple actions. |
| 44 class WebRequestActionCollection { |
| 45 public: |
| 46 // TODO(battre): As WebRequestActionCollection can become the single |
| 47 // owner of all actions, we can optimize here by making some of them |
| 48 // singletons (e.g. Cancel actions). |
| 49 typedef std::vector<linked_ptr<WebRequestAction> > Actions; |
| 50 |
| 51 explicit WebRequestActionCollection(const Actions& actions); |
| 52 virtual ~WebRequestActionCollection(); |
| 53 |
| 54 const Actions& actions() const { return actions_; } |
| 55 |
| 56 // TODO(battre): Add method that corresponds to executing the action. |
| 57 |
| 58 private: |
| 59 Actions actions_; |
| 60 |
| 61 DISALLOW_COPY_AND_ASSIGN(WebRequestActionCollection); |
| 62 }; |
| 63 |
| 64 // Factory for easy instantiation of various WebRequestAction types. |
| 65 class WebRequestActionFactory { |
| 66 public: |
| 67 typedef std::vector<linked_ptr<json_schema_compiler::any::Any> > AnyVector; |
| 68 |
| 69 static bool IsHandledByThisFactory(const std::string& action_name); |
| 70 |
| 71 static scoped_ptr<WebRequestAction> CreateAction( |
| 72 const base::Value& json_action, |
| 73 std::string* error); |
| 74 static scoped_ptr<WebRequestActionCollection> CreateActionCollection( |
| 75 const AnyVector& actions, |
| 76 std::string* error); |
| 77 |
| 78 private: |
| 79 DISALLOW_IMPLICIT_CONSTRUCTORS(WebRequestActionFactory); |
| 80 }; |
| 81 |
| 82 // Action that instructs to cancel a network request. |
| 83 class WebRequestCancelAction : public WebRequestAction { |
| 84 public: |
| 85 WebRequestCancelAction(); |
| 86 virtual ~WebRequestCancelAction(); |
| 87 |
| 88 // Implementation of WebRequestAction: |
| 89 virtual int GetStages() const OVERRIDE; |
| 90 virtual Types type() const OVERRIDE { |
| 91 return WebRequestAction::ACTION_CANCEL_REQUEST; |
| 92 } |
| 93 |
| 94 private: |
| 95 DISALLOW_COPY_AND_ASSIGN(WebRequestCancelAction); |
| 96 }; |
| 97 |
| 98 // TODO(battre) Implement further actions: |
| 99 // Redirect to constant url, Redirect by RegEx, Set header, Remove header, ... |
| 100 |
| 101 } // namespace declarative_webrequest |
| 102 } // namespace extensions |
| 103 |
| 104 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_ACTIO
N_H_ |
OLD | NEW |