Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(818)

Side by Side Diff: chrome/browser/extensions/api/declarative_webrequest/webrequest_action.h

Issue 9820003: Implementation of beginning of Declarative Web Request API backend (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Pacify clang Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 GetType() 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,
47 std::string* error);
48 };
49
50 // Immutable container for multiple actions.
51 //
52 // TODO(battre): As WebRequestActionSet can become the single owner of all
53 // actions, we can optimize here by making some of them singletons (e.g. Cancel
54 // actions).
55 //
56 // TODO(battre): Add method that corresponds to executing the action.
57 class WebRequestActionSet {
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 WebRequestActionSet(const Actions& actions);
63 virtual ~WebRequestActionSet();
64
65 // Factory method that instantiates a WebRequestActionSet according to
66 // |actions| which represents the array of actions received from the
67 // extension API.
68 static scoped_ptr<WebRequestActionSet> Create(const AnyVector& actions,
69 std::string* error);
70
71 const Actions& actions() const { return actions_; }
72
73 private:
74 Actions actions_;
75
76 DISALLOW_COPY_AND_ASSIGN(WebRequestActionSet);
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 GetType() 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_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698