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

Side by Side Diff: chrome/browser/extensions/api/declarative_content/content_action.cc

Issue 344433003: Prepare declarativeContent API for new script injection feature. Added Javascript types and functio… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add note about what it means to revert RequestContentScript Created 6 years, 6 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
OLDNEW
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
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 {
Fady Samuel 2014/06/23 18:56:28 I feel like this should be called InjectContentScr
Mark Dittmer 2014/06/24 14:14:19 I agree, actually. What do you think kalman@?
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 }
Fady Samuel 2014/06/23 18:56:28 Add empty line after this.
Mark Dittmer 2014/06/24 14:14:19 Done.
113 virtual void Apply(const std::string& extension_id,
114 const base::Time& extension_install_time,
115 ApplyInfo* apply_info) const OVERRIDE {
116 // TODO(markdittmer): Invoke UserScriptMaster declarative script loader:
117 // load new user script.
118 }
Fady Samuel 2014/06/23 18:56:28 Add empty line after this.
Mark Dittmer 2014/06/24 14:14:19 Done.
119 virtual void Revert(const std::string& extension_id,
120 const base::Time& extension_install_time,
121 ApplyInfo* apply_info) const OVERRIDE {
122 // TODO(markdittmer): Invoke UserScriptMaster declarative script loader:
123 // unload user script.
124 }
125
126 private:
127 virtual ~RequestContentScript() {}
128
129 DISALLOW_COPY_AND_ASSIGN(RequestContentScript);
130 };
131
97 struct ContentActionFactory { 132 struct ContentActionFactory {
98 // Factory methods for ContentAction instances. |extension| is the extension 133 // Factory methods for ContentAction instances. |extension| is the extension
99 // for which the action is being created. |dict| contains the json dictionary 134 // 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 135 // that describes the action. |error| is used to return error messages in case
101 // the extension passed an action that was syntactically correct but 136 // the extension passed an action that was syntactically correct but
102 // semantically incorrect. |bad_message| is set to true in case |dict| does 137 // semantically incorrect. |bad_message| is set to true in case |dict| does
103 // not confirm to the validated JSON specification. 138 // not confirm to the validated JSON specification.
104 typedef scoped_refptr<ContentAction>(*FactoryMethod)( 139 typedef scoped_refptr<ContentAction>(*FactoryMethod)(
105 const Extension* /* extension */, 140 const Extension* /* extension */,
106 const base::DictionaryValue* /* dict */, 141 const base::DictionaryValue* /* dict */,
107 std::string* /* error */, 142 std::string* /* error */,
108 bool* /* bad_message */); 143 bool* /* bad_message */);
109 // Maps the name of a declarativeContent action type to the factory 144 // Maps the name of a declarativeContent action type to the factory
110 // function creating it. 145 // function creating it.
111 std::map<std::string, FactoryMethod> factory_methods; 146 std::map<std::string, FactoryMethod> factory_methods;
112 147
113 ContentActionFactory() { 148 ContentActionFactory() {
114 factory_methods[keys::kShowPageAction] = 149 factory_methods[keys::kShowPageAction] =
115 &ShowPageAction::Create; 150 &ShowPageAction::Create;
151 factory_methods[keys::kRequestContentScript] =
152 &RequestContentScript::Create;
116 } 153 }
117 }; 154 };
118 155
119 base::LazyInstance<ContentActionFactory>::Leaky 156 base::LazyInstance<ContentActionFactory>::Leaky
120 g_content_action_factory = LAZY_INSTANCE_INITIALIZER; 157 g_content_action_factory = LAZY_INSTANCE_INITIALIZER;
121 158
122 } // namespace 159 } // namespace
123 160
124 // 161 //
125 // ContentAction 162 // ContentAction
(...skipping 24 matching lines...) Expand all
150 factory_method_iter = factory.factory_methods.find(instance_type); 187 factory_method_iter = factory.factory_methods.find(instance_type);
151 if (factory_method_iter != factory.factory_methods.end()) 188 if (factory_method_iter != factory.factory_methods.end())
152 return (*factory_method_iter->second)( 189 return (*factory_method_iter->second)(
153 extension, action_dict, error, bad_message); 190 extension, action_dict, error, bad_message);
154 191
155 *error = base::StringPrintf(kInvalidInstanceTypeError, instance_type.c_str()); 192 *error = base::StringPrintf(kInvalidInstanceTypeError, instance_type.c_str());
156 return scoped_refptr<ContentAction>(); 193 return scoped_refptr<ContentAction>();
157 } 194 }
158 195
159 } // namespace extensions 196 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698