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

Side by Side Diff: chrome/browser/extensions/extension_function_dispatcher.cc

Issue 159763: Rolling back change 22245. (Closed) Base URL: svn://chrome-svn.corp.google.com/chrome/trunk/src/
Patch Set: Created 11 years, 4 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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/extension_function_dispatcher.h" 5 #include "chrome/browser/extensions/extension_function_dispatcher.h"
6 6
7 #include "base/process_util.h" 7 #include "base/process_util.h"
8 #include "base/singleton.h" 8 #include "base/singleton.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "chrome/browser/extensions/extension_bookmarks_module.h" 10 #include "chrome/browser/extensions/extension_bookmarks_module.h"
11 #include "chrome/browser/extensions/extension_bookmarks_module_constants.h" 11 #include "chrome/browser/extensions/extension_bookmarks_module_constants.h"
12 #include "chrome/browser/extensions/extension_function.h" 12 #include "chrome/browser/extensions/extension_function.h"
13 #include "chrome/browser/extensions/extension_message_service.h" 13 #include "chrome/browser/extensions/extension_message_service.h"
14 #include "chrome/browser/extensions/extension_page_actions_module.h" 14 #include "chrome/browser/extensions/extension_page_actions_module.h"
15 #include "chrome/browser/extensions/extension_page_actions_module_constants.h" 15 #include "chrome/browser/extensions/extension_page_actions_module_constants.h"
16 #include "chrome/browser/extensions/extension_process_manager.h" 16 #include "chrome/browser/extensions/extension_process_manager.h"
17 #include "chrome/browser/extensions/extension_tabs_module.h" 17 #include "chrome/browser/extensions/extension_tabs_module.h"
18 #include "chrome/browser/extensions/extension_tabs_module_constants.h" 18 #include "chrome/browser/extensions/extension_tabs_module_constants.h"
19 #include "chrome/browser/extensions/extension_toolstrip_api.h"
20 #include "chrome/browser/profile.h" 19 #include "chrome/browser/profile.h"
21 #include "chrome/browser/renderer_host/render_process_host.h" 20 #include "chrome/browser/renderer_host/render_process_host.h"
22 #include "chrome/browser/renderer_host/render_view_host.h" 21 #include "chrome/browser/renderer_host/render_view_host.h"
23 #include "chrome/common/result_codes.h" 22 #include "chrome/common/result_codes.h"
24 #include "chrome/common/url_constants.h"
25 23
26 // FactoryRegistry ------------------------------------------------------------- 24 // FactoryRegistry -------------------------------------------------------------
27 25
28 namespace { 26 namespace {
29 27
30 // Template for defining ExtensionFunctionFactory. 28 // Template for defining ExtensionFunctionFactory.
31 template<class T> 29 template<class T>
32 ExtensionFunction* NewExtensionFunction() { 30 ExtensionFunction* NewExtensionFunction() {
33 return new T(); 31 return new T();
34 } 32 }
(...skipping 27 matching lines...) Expand all
62 FactoryRegistry* FactoryRegistry::instance() { 60 FactoryRegistry* FactoryRegistry::instance() {
63 return Singleton<FactoryRegistry>::get(); 61 return Singleton<FactoryRegistry>::get();
64 } 62 }
65 63
66 void FactoryRegistry::ResetFunctions() { 64 void FactoryRegistry::ResetFunctions() {
67 // Register all functions here. 65 // Register all functions here.
68 66
69 namespace tabs = extension_tabs_module_constants; 67 namespace tabs = extension_tabs_module_constants;
70 namespace page_actions = extension_page_actions_module_constants; 68 namespace page_actions = extension_page_actions_module_constants;
71 namespace bookmarks = extension_bookmarks_module_constants; 69 namespace bookmarks = extension_bookmarks_module_constants;
72 namespace toolstrip = extension_toolstrip_api_functions;
73 70
74 // Windows 71 // Windows
75 factories_[tabs::kGetWindowFunction] = 72 factories_[tabs::kGetWindowFunction] =
76 &NewExtensionFunction<GetWindowFunction>; 73 &NewExtensionFunction<GetWindowFunction>;
77 factories_[tabs::kGetCurrentWindowFunction] = 74 factories_[tabs::kGetCurrentWindowFunction] =
78 &NewExtensionFunction<GetCurrentWindowFunction>; 75 &NewExtensionFunction<GetCurrentWindowFunction>;
79 factories_[tabs::kGetLastFocusedWindowFunction] = 76 factories_[tabs::kGetLastFocusedWindowFunction] =
80 &NewExtensionFunction<GetLastFocusedWindowFunction>; 77 &NewExtensionFunction<GetLastFocusedWindowFunction>;
81 factories_[tabs::kGetAllWindowsFunction] = 78 factories_[tabs::kGetAllWindowsFunction] =
82 &NewExtensionFunction<GetAllWindowsFunction>; 79 &NewExtensionFunction<GetAllWindowsFunction>;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 factories_[bookmarks::kRemoveBookmarkFunction] = 120 factories_[bookmarks::kRemoveBookmarkFunction] =
124 &NewExtensionFunction<RemoveBookmarkFunction>; 121 &NewExtensionFunction<RemoveBookmarkFunction>;
125 factories_[bookmarks::kRemoveBookmarkTreeFunction] = 122 factories_[bookmarks::kRemoveBookmarkTreeFunction] =
126 &NewExtensionFunction<RemoveBookmarkFunction>; 123 &NewExtensionFunction<RemoveBookmarkFunction>;
127 factories_[bookmarks::kCreateBookmarkFunction] = 124 factories_[bookmarks::kCreateBookmarkFunction] =
128 &NewExtensionFunction<CreateBookmarkFunction>; 125 &NewExtensionFunction<CreateBookmarkFunction>;
129 factories_[bookmarks::kMoveBookmarkFunction] = 126 factories_[bookmarks::kMoveBookmarkFunction] =
130 &NewExtensionFunction<MoveBookmarkFunction>; 127 &NewExtensionFunction<MoveBookmarkFunction>;
131 factories_[bookmarks::kSetBookmarkTitleFunction] = 128 factories_[bookmarks::kSetBookmarkTitleFunction] =
132 &NewExtensionFunction<SetBookmarkTitleFunction>; 129 &NewExtensionFunction<SetBookmarkTitleFunction>;
133
134 // Toolstrips.
135 factories_[toolstrip::kExpandFunction] =
136 &NewExtensionFunction<ToolstripExpandFunction>;
137 factories_[toolstrip::kCollapseFunction] =
138 &NewExtensionFunction<ToolstripCollapseFunction>;
139 } 130 }
140 131
141 void FactoryRegistry::GetAllNames(std::vector<std::string>* names) { 132 void FactoryRegistry::GetAllNames(std::vector<std::string>* names) {
142 for (FactoryMap::iterator iter = factories_.begin(); 133 for (FactoryMap::iterator iter = factories_.begin();
143 iter != factories_.end(); ++iter) { 134 iter != factories_.end(); ++iter) {
144 names->push_back(iter->first); 135 names->push_back(iter->first);
145 } 136 }
146 } 137 }
147 138
148 bool FactoryRegistry::OverrideFunction(const std::string& name, 139 bool FactoryRegistry::OverrideFunction(const std::string& name,
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 } 180 }
190 181
191 ExtensionFunctionDispatcher::ExtensionFunctionDispatcher( 182 ExtensionFunctionDispatcher::ExtensionFunctionDispatcher(
192 RenderViewHost* render_view_host, 183 RenderViewHost* render_view_host,
193 Delegate* delegate, 184 Delegate* delegate,
194 const GURL& url) 185 const GURL& url)
195 : render_view_host_(render_view_host), 186 : render_view_host_(render_view_host),
196 delegate_(delegate), 187 delegate_(delegate),
197 url_(url), 188 url_(url),
198 ALLOW_THIS_IN_INITIALIZER_LIST(peer_(new Peer(this))) { 189 ALLOW_THIS_IN_INITIALIZER_LIST(peer_(new Peer(this))) {
199 // TODO(erikkay) should we do something for these errors in Release?
200 DCHECK(url.SchemeIs(chrome::kExtensionScheme));
201 DCHECK(profile()->GetExtensionsService()->GetExtensionByURL(url));
202
203 all_instances()->insert(this); 190 all_instances()->insert(this);
204 191
205 // Notify the ExtensionProcessManager that the view was created. 192 // Notify the ExtensionProcessManager that the view was created.
206 ExtensionProcessManager* epm = profile()->GetExtensionProcessManager(); 193 ExtensionProcessManager* epm = profile()->GetExtensionProcessManager();
207 epm->RegisterExtensionProcess(extension_id(), 194 epm->RegisterExtensionProcess(extension_id(),
208 render_view_host->process()->pid()); 195 render_view_host->process()->pid());
209 } 196 }
210 197
211 ExtensionFunctionDispatcher::~ExtensionFunctionDispatcher() { 198 ExtensionFunctionDispatcher::~ExtensionFunctionDispatcher() {
212 all_instances()->erase(this); 199 all_instances()->erase(this);
213 peer_->dispatcher_ = NULL; 200 peer_->dispatcher_ = NULL;
214 } 201 }
215 202
216 Browser* ExtensionFunctionDispatcher::GetBrowser() { 203 Browser* ExtensionFunctionDispatcher::GetBrowser() {
217 DCHECK(delegate_); 204 DCHECK(delegate_);
218 205
219 Browser* retval = delegate_->GetBrowser(); 206 Browser* retval = delegate_->GetBrowser();
220 return retval; 207 return retval;
221 } 208 }
222 209
223 ExtensionHost* ExtensionFunctionDispatcher::GetExtensionHost() {
224 DCHECK(delegate_);
225 return delegate_->GetExtensionHost();
226 }
227
228 void ExtensionFunctionDispatcher::HandleRequest(const std::string& name, 210 void ExtensionFunctionDispatcher::HandleRequest(const std::string& name,
229 const std::string& args, 211 const std::string& args,
230 int request_id, 212 int request_id,
231 bool has_callback) { 213 bool has_callback) {
232 scoped_refptr<ExtensionFunction> function( 214 scoped_refptr<ExtensionFunction> function(
233 FactoryRegistry::instance()->NewFunction(name)); 215 FactoryRegistry::instance()->NewFunction(name));
234 function->set_dispatcher_peer(peer_); 216 function->set_dispatcher_peer(peer_);
235 function->SetArgs(args); 217 function->SetArgs(args);
236 function->set_request_id(request_id); 218 function->set_request_id(request_id);
237 function->set_has_callback(has_callback); 219 function->set_has_callback(has_callback);
(...skipping 15 matching lines...) Expand all
253 } else { 235 } else {
254 NOTREACHED(); 236 NOTREACHED();
255 base::KillProcess(render_view_host_->process()->process().handle(), 237 base::KillProcess(render_view_host_->process()->process().handle(),
256 ResultCodes::KILLED_BAD_MESSAGE, false); 238 ResultCodes::KILLED_BAD_MESSAGE, false);
257 } 239 }
258 } 240 }
259 241
260 Profile* ExtensionFunctionDispatcher::profile() { 242 Profile* ExtensionFunctionDispatcher::profile() {
261 return render_view_host_->process()->profile(); 243 return render_view_host_->process()->profile();
262 } 244 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_function_dispatcher.h ('k') | chrome/browser/extensions/extension_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698