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 }; 35 36 struct ApplyInfo { 37 Profile* profile; 38 content::WebContents* tab; 39 }; 40 41 ContentAction(); 42 43 virtual Type GetType() const = 0; 44 45 // Applies or reverts this ContentAction on a particular tab for a particular 46 // extension. Revert exists to keep the actions up to date as the page 47 // changes. 48 virtual void Apply(const std::string& extension_id, 49 const base::Time& extension_install_time, 50 ApplyInfo* apply_info) const = 0; 51 virtual void Revert(const std::string& extension_id, 52 const base::Time& extension_install_time, 53 ApplyInfo* apply_info) const = 0; 54 55 // Factory method that instantiates a concrete ContentAction 56 // implementation according to |json_action|, the representation of the 57 // ContentAction as received from the extension API. 58 // Sets |error| and returns NULL in case of a semantic error that cannot 59 // be caught by schema validation. Sets |bad_message| and returns NULL 60 // in case the input is syntactically unexpected. 61 static scoped_refptr<ContentAction> Create(const Extension* extension, 62 const base::Value& json_action, 63 std::string* error, 64 bool* bad_message); 65 66 protected: 67 friend class base::RefCounted<ContentAction>; 68 virtual ~ContentAction(); 69 }; 70 71 typedef DeclarativeActionSet<ContentAction> ContentActionSet; 72 73 } // namespace extensions 74 75 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_CONTENT_CONTENT_ACTION_H_ 76