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 #include "chrome/browser/extensions/api/declarative_content/content_action.h" | 5 #include "chrome/browser/extensions/api/declarative_content/content_action.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 | 8 |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
87 ->GetExtensionById(extension_id, ExtensionRegistry::EVERYTHING); | 87 ->GetExtensionById(extension_id, ExtensionRegistry::EVERYTHING); |
88 if (!extension) | 88 if (!extension) |
89 return NULL; | 89 return NULL; |
90 return ExtensionActionManager::Get(profile)->GetPageAction(*extension); | 90 return ExtensionActionManager::Get(profile)->GetPageAction(*extension); |
91 } | 91 } |
92 virtual ~ShowPageAction() {} | 92 virtual ~ShowPageAction() {} |
93 | 93 |
94 DISALLOW_COPY_AND_ASSIGN(ShowPageAction); | 94 DISALLOW_COPY_AND_ASSIGN(ShowPageAction); |
95 }; | 95 }; |
96 | 96 |
97 // Action that injects a content script. | |
98 class RequestContentScript : public ContentAction { | |
99 public: | |
100 RequestContentScript() {} | |
101 | |
102 static scoped_refptr<ContentAction> Create(const Extension* extension, | |
103 const base::DictionaryValue* dict, | |
104 std::string* error, | |
105 bool* bad_message) { | |
106 return scoped_refptr<ContentAction>(new RequestContentScript); | |
107 } | |
108 | |
109 // Implementation of ContentAction: | |
110 virtual Type GetType() const OVERRIDE { | |
111 return ACTION_REQUEST_CONTENT_SCRIPT; | |
112 } | |
113 | |
114 virtual void Apply(const std::string& extension_id, | |
115 const base::Time& extension_install_time, | |
116 ApplyInfo* apply_info) const OVERRIDE { | |
117 // TODO(markdittmer): Invoke UserScriptMaster declarative script loader: | |
118 // load new user script. | |
119 } | |
120 | |
121 virtual void Revert(const std::string& extension_id, | |
122 const base::Time& extension_install_time, | |
123 ApplyInfo* apply_info) const OVERRIDE { | |
124 // TODO(markdittmer): Invoke UserScriptMaster declarative script loader: | |
125 // unload user script. | |
Jeffrey Yasskin
2014/06/27 22:03:41
It's impossible to unload a user script. These act
Mark Dittmer
2014/06/30 11:50:35
Perhaps this comment should say "stop future loads
| |
126 } | |
127 | |
128 private: | |
129 virtual ~RequestContentScript() {} | |
130 | |
131 DISALLOW_COPY_AND_ASSIGN(RequestContentScript); | |
132 }; | |
133 | |
97 struct ContentActionFactory { | 134 struct ContentActionFactory { |
98 // Factory methods for ContentAction instances. |extension| is the extension | 135 // Factory methods for ContentAction instances. |extension| is the extension |
99 // for which the action is being created. |dict| contains the json dictionary | 136 // for which the action is being created. |dict| contains the json dictionary |
100 // that describes the action. |error| is used to return error messages in case | 137 // that describes the action. |error| is used to return error messages in case |
101 // the extension passed an action that was syntactically correct but | 138 // the extension passed an action that was syntactically correct but |
102 // semantically incorrect. |bad_message| is set to true in case |dict| does | 139 // semantically incorrect. |bad_message| is set to true in case |dict| does |
103 // not confirm to the validated JSON specification. | 140 // not confirm to the validated JSON specification. |
104 typedef scoped_refptr<ContentAction>(*FactoryMethod)( | 141 typedef scoped_refptr<ContentAction>(*FactoryMethod)( |
105 const Extension* /* extension */, | 142 const Extension* /* extension */, |
106 const base::DictionaryValue* /* dict */, | 143 const base::DictionaryValue* /* dict */, |
107 std::string* /* error */, | 144 std::string* /* error */, |
108 bool* /* bad_message */); | 145 bool* /* bad_message */); |
109 // Maps the name of a declarativeContent action type to the factory | 146 // Maps the name of a declarativeContent action type to the factory |
110 // function creating it. | 147 // function creating it. |
111 std::map<std::string, FactoryMethod> factory_methods; | 148 std::map<std::string, FactoryMethod> factory_methods; |
112 | 149 |
113 ContentActionFactory() { | 150 ContentActionFactory() { |
114 factory_methods[keys::kShowPageAction] = | 151 factory_methods[keys::kShowPageAction] = |
115 &ShowPageAction::Create; | 152 &ShowPageAction::Create; |
153 factory_methods[keys::kRequestContentScript] = | |
154 &RequestContentScript::Create; | |
116 } | 155 } |
117 }; | 156 }; |
118 | 157 |
119 base::LazyInstance<ContentActionFactory>::Leaky | 158 base::LazyInstance<ContentActionFactory>::Leaky |
120 g_content_action_factory = LAZY_INSTANCE_INITIALIZER; | 159 g_content_action_factory = LAZY_INSTANCE_INITIALIZER; |
121 | 160 |
122 } // namespace | 161 } // namespace |
123 | 162 |
124 // | 163 // |
125 // ContentAction | 164 // ContentAction |
(...skipping 24 matching lines...) Expand all Loading... | |
150 factory_method_iter = factory.factory_methods.find(instance_type); | 189 factory_method_iter = factory.factory_methods.find(instance_type); |
151 if (factory_method_iter != factory.factory_methods.end()) | 190 if (factory_method_iter != factory.factory_methods.end()) |
152 return (*factory_method_iter->second)( | 191 return (*factory_method_iter->second)( |
153 extension, action_dict, error, bad_message); | 192 extension, action_dict, error, bad_message); |
154 | 193 |
155 *error = base::StringPrintf(kInvalidInstanceTypeError, instance_type.c_str()); | 194 *error = base::StringPrintf(kInvalidInstanceTypeError, instance_type.c_str()); |
156 return scoped_refptr<ContentAction>(); | 195 return scoped_refptr<ContentAction>(); |
157 } | 196 } |
158 | 197 |
159 } // namespace extensions | 198 } // namespace extensions |
OLD | NEW |