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

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

Issue 171032: end-to-end extension API tests (Closed)
Patch Set: a bit of refactoring and review feedback 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_test_api.h"
19 #include "chrome/browser/extensions/extension_toolstrip_api.h" 20 #include "chrome/browser/extensions/extension_toolstrip_api.h"
20 #include "chrome/browser/profile.h" 21 #include "chrome/browser/profile.h"
21 #include "chrome/browser/renderer_host/render_process_host.h" 22 #include "chrome/browser/renderer_host/render_process_host.h"
22 #include "chrome/browser/renderer_host/render_view_host.h" 23 #include "chrome/browser/renderer_host/render_view_host.h"
23 #include "chrome/common/render_messages.h" 24 #include "chrome/common/render_messages.h"
24 #include "chrome/common/result_codes.h" 25 #include "chrome/common/result_codes.h"
25 #include "chrome/common/url_constants.h" 26 #include "chrome/common/url_constants.h"
26 27
27 // FactoryRegistry ------------------------------------------------------------- 28 // FactoryRegistry -------------------------------------------------------------
28 29
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 FactoryMap factories_; 61 FactoryMap factories_;
61 }; 62 };
62 63
63 FactoryRegistry* FactoryRegistry::instance() { 64 FactoryRegistry* FactoryRegistry::instance() {
64 return Singleton<FactoryRegistry>::get(); 65 return Singleton<FactoryRegistry>::get();
65 } 66 }
66 67
67 void FactoryRegistry::ResetFunctions() { 68 void FactoryRegistry::ResetFunctions() {
68 // Register all functions here. 69 // Register all functions here.
69 70
71 namespace bookmarks = extension_bookmarks_module_constants;
72 namespace page_actions = extension_page_actions_module_constants;
70 namespace tabs = extension_tabs_module_constants; 73 namespace tabs = extension_tabs_module_constants;
71 namespace page_actions = extension_page_actions_module_constants; 74 namespace test = extension_test_api_functions;
72 namespace bookmarks = extension_bookmarks_module_constants;
73 namespace toolstrip = extension_toolstrip_api_functions; 75 namespace toolstrip = extension_toolstrip_api_functions;
74 76
75 // Windows 77 // Windows
76 factories_[tabs::kGetWindowFunction] = 78 factories_[tabs::kGetWindowFunction] =
77 &NewExtensionFunction<GetWindowFunction>; 79 &NewExtensionFunction<GetWindowFunction>;
78 factories_[tabs::kGetCurrentWindowFunction] = 80 factories_[tabs::kGetCurrentWindowFunction] =
79 &NewExtensionFunction<GetCurrentWindowFunction>; 81 &NewExtensionFunction<GetCurrentWindowFunction>;
80 factories_[tabs::kGetLastFocusedWindowFunction] = 82 factories_[tabs::kGetLastFocusedWindowFunction] =
81 &NewExtensionFunction<GetLastFocusedWindowFunction>; 83 &NewExtensionFunction<GetLastFocusedWindowFunction>;
82 factories_[tabs::kGetAllWindowsFunction] = 84 factories_[tabs::kGetAllWindowsFunction] =
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 factories_[bookmarks::kMoveBookmarkFunction] = 134 factories_[bookmarks::kMoveBookmarkFunction] =
133 &NewExtensionFunction<MoveBookmarkFunction>; 135 &NewExtensionFunction<MoveBookmarkFunction>;
134 factories_[bookmarks::kSetBookmarkTitleFunction] = 136 factories_[bookmarks::kSetBookmarkTitleFunction] =
135 &NewExtensionFunction<SetBookmarkTitleFunction>; 137 &NewExtensionFunction<SetBookmarkTitleFunction>;
136 138
137 // Toolstrips. 139 // Toolstrips.
138 factories_[toolstrip::kExpandFunction] = 140 factories_[toolstrip::kExpandFunction] =
139 &NewExtensionFunction<ToolstripExpandFunction>; 141 &NewExtensionFunction<ToolstripExpandFunction>;
140 factories_[toolstrip::kCollapseFunction] = 142 factories_[toolstrip::kCollapseFunction] =
141 &NewExtensionFunction<ToolstripCollapseFunction>; 143 &NewExtensionFunction<ToolstripCollapseFunction>;
144
145 // Test.
146 factories_[test::kPassFunction] =
147 &NewExtensionFunction<ExtensionTestPassFunction>;
148 factories_[test::kFailFunction] =
149 &NewExtensionFunction<ExtensionTestFailFunction>;
142 } 150 }
143 151
144 void FactoryRegistry::GetAllNames(std::vector<std::string>* names) { 152 void FactoryRegistry::GetAllNames(std::vector<std::string>* names) {
145 for (FactoryMap::iterator iter = factories_.begin(); 153 for (FactoryMap::iterator iter = factories_.begin();
146 iter != factories_.end(); ++iter) { 154 iter != factories_.end(); ++iter) {
147 names->push_back(iter->first); 155 names->push_back(iter->first);
148 } 156 }
149 } 157 }
150 158
151 bool FactoryRegistry::OverrideFunction(const std::string& name, 159 bool FactoryRegistry::OverrideFunction(const std::string& name,
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 function->Run(); 254 function->Run();
247 } 255 }
248 256
249 void ExtensionFunctionDispatcher::SendResponse(ExtensionFunction* function, 257 void ExtensionFunctionDispatcher::SendResponse(ExtensionFunction* function,
250 bool success) { 258 bool success) {
251 render_view_host_->SendExtensionResponse(function->request_id(), success, 259 render_view_host_->SendExtensionResponse(function->request_id(), success,
252 function->GetResult(), function->GetError()); 260 function->GetResult(), function->GetError());
253 } 261 }
254 262
255 void ExtensionFunctionDispatcher::HandleBadMessage(ExtensionFunction* api) { 263 void ExtensionFunctionDispatcher::HandleBadMessage(ExtensionFunction* api) {
256 LOG(ERROR) << "bad extension message " << // TODO(erikkay) name? 264 LOG(ERROR) << "bad extension message " <<
265 api->name() <<
257 " : terminating renderer."; 266 " : terminating renderer.";
258 if (RenderProcessHost::run_renderer_in_process()) { 267 if (RenderProcessHost::run_renderer_in_process()) {
259 // In single process mode it is better if we don't suicide but just crash. 268 // In single process mode it is better if we don't suicide but just crash.
260 CHECK(false); 269 CHECK(false);
261 } else { 270 } else {
262 NOTREACHED(); 271 NOTREACHED();
263 base::KillProcess(render_view_host_->process()->process().handle(), 272 base::KillProcess(render_view_host_->process()->process().handle(),
264 ResultCodes::KILLED_BAD_MESSAGE, false); 273 ResultCodes::KILLED_BAD_MESSAGE, false);
265 } 274 }
266 } 275 }
267 276
268 Profile* ExtensionFunctionDispatcher::profile() { 277 Profile* ExtensionFunctionDispatcher::profile() {
269 return render_view_host_->process()->profile(); 278 return render_view_host_->process()->profile();
270 } 279 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698