| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_CONTENT_CONTENT_ACTION_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_CONTENT_CONTENT_ACTION_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_CONTENT_CONTENT_ACTION_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_CONTENT_CONTENT_ACTION_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 ApplyInfo* apply_info) const = 0; | 60 ApplyInfo* apply_info) const = 0; |
| 61 | 61 |
| 62 // Factory method that instantiates a concrete ContentAction | 62 // Factory method that instantiates a concrete ContentAction |
| 63 // implementation according to |json_action|, the representation of the | 63 // implementation according to |json_action|, the representation of the |
| 64 // ContentAction as received from the extension API. | 64 // ContentAction as received from the extension API. |
| 65 // Sets |error| and returns NULL in case of a semantic error that cannot | 65 // Sets |error| and returns NULL in case of a semantic error that cannot |
| 66 // be caught by schema validation. Sets |bad_message| and returns NULL | 66 // be caught by schema validation. Sets |bad_message| and returns NULL |
| 67 // in case the input is syntactically unexpected. | 67 // in case the input is syntactically unexpected. |
| 68 static scoped_refptr<ContentAction> Create( | 68 static scoped_refptr<ContentAction> Create( |
| 69 content::BrowserContext* browser_context, | 69 content::BrowserContext* browser_context, |
| 70 const HostID& host_id, | |
| 71 const Extension* extension, | 70 const Extension* extension, |
| 72 const base::Value& json_action, | 71 const base::Value& json_action, |
| 73 std::string* error, | 72 std::string* error, |
| 74 bool* bad_message); | 73 bool* bad_message); |
| 75 | 74 |
| 76 // Shared procedure for resetting error state within factories. | 75 // Shared procedure for resetting error state within factories. |
| 77 static void ResetErrorData(std::string* error, bool* bad_message) { | 76 static void ResetErrorData(std::string* error, bool* bad_message) { |
| 78 *error = ""; | 77 *error = ""; |
| 79 *bad_message = false; | 78 *bad_message = false; |
| 80 } | 79 } |
| 81 | 80 |
| 82 // Shared procedure for validating JSON data. | 81 // Shared procedure for validating JSON data. |
| 83 static bool Validate(const base::Value& json_action, | 82 static bool Validate(const base::Value& json_action, |
| 84 std::string* error, | 83 std::string* error, |
| 85 bool* bad_message, | 84 bool* bad_message, |
| 86 const base::DictionaryValue** action_dict, | 85 const base::DictionaryValue** action_dict, |
| 87 std::string* instance_type); | 86 std::string* instance_type); |
| 88 | 87 |
| 89 protected: | 88 protected: |
| 90 friend class base::RefCounted<ContentAction>; | 89 friend class base::RefCounted<ContentAction>; |
| 91 virtual ~ContentAction(); | 90 virtual ~ContentAction(); |
| 92 }; | 91 }; |
| 93 | 92 |
| 94 // Action that injects a content script. | 93 // Action that injects a content script. |
| 95 class RequestContentScript : public ContentAction { | 94 class RequestContentScript : public ContentAction { |
| 96 public: | 95 public: |
| 97 struct ScriptData; | 96 struct ScriptData; |
| 98 | 97 |
| 99 // TODO(hanxi): remove the plumbing of |host_id| when introducing class | |
| 100 // Host/Consumer to de-couple extension from the ContentAction. | |
| 101 // |host_id| will be a part of Host/Consumer class. | |
| 102 RequestContentScript(content::BrowserContext* browser_context, | 98 RequestContentScript(content::BrowserContext* browser_context, |
| 103 const HostID& host_id, | |
| 104 const Extension* extension, | 99 const Extension* extension, |
| 105 const ScriptData& script_data); | 100 const ScriptData& script_data); |
| 106 RequestContentScript(DeclarativeUserScriptMaster* master, | 101 RequestContentScript(DeclarativeUserScriptMaster* master, |
| 107 const HostID& host_id, | |
| 108 const Extension* extension, | 102 const Extension* extension, |
| 109 const ScriptData& script_data); | 103 const ScriptData& script_data); |
| 110 | 104 |
| 111 static scoped_refptr<ContentAction> Create( | 105 static scoped_refptr<ContentAction> Create( |
| 112 content::BrowserContext* browser_context, | 106 content::BrowserContext* browser_context, |
| 113 const HostID& host_id, | |
| 114 const Extension* extension, | 107 const Extension* extension, |
| 115 const base::DictionaryValue* dict, | 108 const base::DictionaryValue* dict, |
| 116 std::string* error, | 109 std::string* error, |
| 117 bool* bad_message); | 110 bool* bad_message); |
| 118 | 111 |
| 119 static scoped_refptr<ContentAction> CreateForTest( | 112 static scoped_refptr<ContentAction> CreateForTest( |
| 120 DeclarativeUserScriptMaster* master, | 113 DeclarativeUserScriptMaster* master, |
| 121 const HostID& host_id, | |
| 122 const Extension* extension, | 114 const Extension* extension, |
| 123 const base::Value& json_action, | 115 const base::Value& json_action, |
| 124 std::string* error, | 116 std::string* error, |
| 125 bool* bad_message); | 117 bool* bad_message); |
| 126 | 118 |
| 127 static bool InitScriptData(const base::DictionaryValue* dict, | 119 static bool InitScriptData(const base::DictionaryValue* dict, |
| 128 std::string* error, | 120 std::string* error, |
| 129 bool* bad_message, | 121 bool* bad_message, |
| 130 ScriptData* script_data); | 122 ScriptData* script_data); |
| 131 | 123 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 DeclarativeUserScriptMaster* master_; | 155 DeclarativeUserScriptMaster* master_; |
| 164 | 156 |
| 165 DISALLOW_COPY_AND_ASSIGN(RequestContentScript); | 157 DISALLOW_COPY_AND_ASSIGN(RequestContentScript); |
| 166 }; | 158 }; |
| 167 | 159 |
| 168 typedef DeclarativeActionSet<ContentAction> ContentActionSet; | 160 typedef DeclarativeActionSet<ContentAction> ContentActionSet; |
| 169 | 161 |
| 170 } // namespace extensions | 162 } // namespace extensions |
| 171 | 163 |
| 172 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_CONTENT_CONTENT_ACTION_H_ | 164 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_CONTENT_CONTENT_ACTION_H_ |
| OLD | NEW |