Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / extensions / api / declarative_content / content_action.h
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_CONTENT_CONTENT_ACTION_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_CONTENT_CONTENT_ACTION_H_
7
8 #include <string>
9 #include <vector>
10
11 #include "base/memory/ref_counted.h"
12 #include "chrome/browser/extensions/api/declarative/declarative_rule.h"
13
14 class Profile;
15
16 namespace base {
17 class Time;
18 class Value;
19 }
20
21 namespace content {
22 class WebContents;
23 }
24
25 namespace extensions {
26 class Extension;
27
28 // Base class for all ContentActions of the declarative content API.
29 class ContentAction : public base::RefCounted<ContentAction> {
30  public:
31   // Type identifiers for concrete ContentActions.
32   enum Type {
33     ACTION_SHOW_PAGE_ACTION,
34     ACTION_REQUEST_CONTENT_SCRIPT,
35   };
36
37   struct ApplyInfo {
38     Profile* profile;
39     content::WebContents* tab;
40   };
41
42   ContentAction();
43
44   virtual Type GetType() const = 0;
45
46   // Applies or reverts this ContentAction on a particular tab for a particular
47   // extension.  Revert exists to keep the actions up to date as the page
48   // changes.
49   virtual void Apply(const std::string& extension_id,
50                      const base::Time& extension_install_time,
51                      ApplyInfo* apply_info) const = 0;
52   virtual void Revert(const std::string& extension_id,
53                       const base::Time& extension_install_time,
54                       ApplyInfo* apply_info) const = 0;
55
56   // Factory method that instantiates a concrete ContentAction
57   // implementation according to |json_action|, the representation of the
58   // ContentAction as received from the extension API.
59   // Sets |error| and returns NULL in case of a semantic error that cannot
60   // be caught by schema validation. Sets |bad_message| and returns NULL
61   // in case the input is syntactically unexpected.
62   static scoped_refptr<ContentAction> Create(const Extension* extension,
63                                              const base::Value& json_action,
64                                              std::string* error,
65                                              bool* bad_message);
66
67  protected:
68   friend class base::RefCounted<ContentAction>;
69   virtual ~ContentAction();
70 };
71
72 typedef DeclarativeActionSet<ContentAction> ContentActionSet;
73
74 }  // namespace extensions
75
76 #endif  // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_CONTENT_CONTENT_ACTION_H_