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 | |
22 // Base class for all WebRequestActions of the declarative Web Request API. | |
23 // | |
24 // TODO(battre): Add method that corresponds to executing the action. | |
25 class WebRequestAction { | |
26 public: | |
27 // Type identifiers for concrete WebRequestActions. | |
28 enum Type { | |
29 ACTION_CANCEL_REQUEST | |
30 }; | |
31 | |
32 WebRequestAction(); | |
33 virtual ~WebRequestAction(); | |
34 | |
35 // Returns a bit vector representing extensions::RequestStages. The bit vector | |
36 // contains a 1 for each request stage during which the condition can be | |
37 // tested. | |
38 virtual int GetStages() const = 0; | |
39 | |
40 virtual Type type() const = 0; | |
41 | |
42 // Factory method that instantiates a concrete WebRequestAction | |
43 // implementation according to |json_action|, the representation of the | |
44 // WebRequestAction as received from the extension API. | |
45 // Sets |error| and returns NULL in case of an error. | |
46 static scoped_ptr<WebRequestAction> Create(const base::Value& json_action, | |
Matt Perry
2012/03/26 20:21:20
optional: I generally put factory methods right af
battre
2012/03/26 20:38:10
Done.
| |
47 std::string* error); | |
48 }; | |
49 | |
50 // Immutable container for multiple actions. | |
51 // | |
52 // TODO(battre): As WebRequestActionCollection can become the single | |
53 // owner of all actions, we can optimize here by making some of them | |
54 // singletons (e.g. Cancel actions). | |
55 // | |
56 // TODO(battre): Add method that corresponds to executing the action. | |
57 class WebRequestActionCollection { | |
58 public: | |
59 typedef std::vector<linked_ptr<json_schema_compiler::any::Any> > AnyVector; | |
60 typedef std::vector<linked_ptr<WebRequestAction> > Actions; | |
61 | |
62 explicit WebRequestActionCollection(const Actions& actions); | |
63 virtual ~WebRequestActionCollection(); | |
64 | |
65 const Actions& actions() const { return actions_; } | |
66 | |
67 // Factory method that instantiates a WebRequestActionCollection according | |
68 // to |actions| which represents the array of actions received from the | |
69 // extension API. | |
70 static scoped_ptr<WebRequestActionCollection> Create(const AnyVector& actions, | |
71 std::string* error); | |
72 | |
73 private: | |
74 Actions actions_; | |
75 | |
76 DISALLOW_COPY_AND_ASSIGN(WebRequestActionCollection); | |
77 }; | |
78 | |
79 // | |
80 // The following are concrete actions. | |
81 // | |
82 | |
83 // Action that instructs to cancel a network request. | |
84 class WebRequestCancelAction : public WebRequestAction { | |
85 public: | |
86 WebRequestCancelAction(); | |
87 virtual ~WebRequestCancelAction(); | |
88 | |
89 // Implementation of WebRequestAction: | |
90 virtual int GetStages() const OVERRIDE; | |
91 virtual Type type() const OVERRIDE; | |
92 | |
93 private: | |
94 DISALLOW_COPY_AND_ASSIGN(WebRequestCancelAction); | |
95 }; | |
96 | |
97 // TODO(battre) Implement further actions: | |
98 // Redirect to constant url, Redirect by RegEx, Set header, Remove header, ... | |
99 | |
100 } // namespace extensions | |
101 | |
102 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_ACTIO N_H_ | |
OLD | NEW |