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

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

Issue 160276: mole expand/collapse API (Closed)
Patch Set: mole API 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"
19 #include "chrome/browser/profile.h" 20 #include "chrome/browser/profile.h"
20 #include "chrome/browser/renderer_host/render_process_host.h" 21 #include "chrome/browser/renderer_host/render_process_host.h"
21 #include "chrome/browser/renderer_host/render_view_host.h" 22 #include "chrome/browser/renderer_host/render_view_host.h"
22 #include "chrome/common/result_codes.h" 23 #include "chrome/common/result_codes.h"
24 #include "chrome/common/url_constants.h"
23 25
24 // FactoryRegistry ------------------------------------------------------------- 26 // FactoryRegistry -------------------------------------------------------------
25 27
26 namespace { 28 namespace {
27 29
28 // Template for defining ExtensionFunctionFactory. 30 // Template for defining ExtensionFunctionFactory.
29 template<class T> 31 template<class T>
30 ExtensionFunction* NewExtensionFunction() { 32 ExtensionFunction* NewExtensionFunction() {
31 return new T(); 33 return new T();
32 } 34 }
(...skipping 27 matching lines...) Expand all
60 FactoryRegistry* FactoryRegistry::instance() { 62 FactoryRegistry* FactoryRegistry::instance() {
61 return Singleton<FactoryRegistry>::get(); 63 return Singleton<FactoryRegistry>::get();
62 } 64 }
63 65
64 void FactoryRegistry::ResetFunctions() { 66 void FactoryRegistry::ResetFunctions() {
65 // Register all functions here. 67 // Register all functions here.
66 68
67 namespace tabs = extension_tabs_module_constants; 69 namespace tabs = extension_tabs_module_constants;
68 namespace page_actions = extension_page_actions_module_constants; 70 namespace page_actions = extension_page_actions_module_constants;
69 namespace bookmarks = extension_bookmarks_module_constants; 71 namespace bookmarks = extension_bookmarks_module_constants;
72 namespace toolstrip = extension_toolstrip_api_constants;
70 73
71 // Windows 74 // Windows
72 factories_[tabs::kGetWindowFunction] = 75 factories_[tabs::kGetWindowFunction] =
73 &NewExtensionFunction<GetWindowFunction>; 76 &NewExtensionFunction<GetWindowFunction>;
74 factories_[tabs::kGetCurrentWindowFunction] = 77 factories_[tabs::kGetCurrentWindowFunction] =
75 &NewExtensionFunction<GetCurrentWindowFunction>; 78 &NewExtensionFunction<GetCurrentWindowFunction>;
76 factories_[tabs::kGetLastFocusedWindowFunction] = 79 factories_[tabs::kGetLastFocusedWindowFunction] =
77 &NewExtensionFunction<GetLastFocusedWindowFunction>; 80 &NewExtensionFunction<GetLastFocusedWindowFunction>;
78 factories_[tabs::kGetAllWindowsFunction] = 81 factories_[tabs::kGetAllWindowsFunction] =
79 &NewExtensionFunction<GetAllWindowsFunction>; 82 &NewExtensionFunction<GetAllWindowsFunction>;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 factories_[bookmarks::kRemoveBookmarkFunction] = 123 factories_[bookmarks::kRemoveBookmarkFunction] =
121 &NewExtensionFunction<RemoveBookmarkFunction>; 124 &NewExtensionFunction<RemoveBookmarkFunction>;
122 factories_[bookmarks::kRemoveBookmarkTreeFunction] = 125 factories_[bookmarks::kRemoveBookmarkTreeFunction] =
123 &NewExtensionFunction<RemoveBookmarkFunction>; 126 &NewExtensionFunction<RemoveBookmarkFunction>;
124 factories_[bookmarks::kCreateBookmarkFunction] = 127 factories_[bookmarks::kCreateBookmarkFunction] =
125 &NewExtensionFunction<CreateBookmarkFunction>; 128 &NewExtensionFunction<CreateBookmarkFunction>;
126 factories_[bookmarks::kMoveBookmarkFunction] = 129 factories_[bookmarks::kMoveBookmarkFunction] =
127 &NewExtensionFunction<MoveBookmarkFunction>; 130 &NewExtensionFunction<MoveBookmarkFunction>;
128 factories_[bookmarks::kSetBookmarkTitleFunction] = 131 factories_[bookmarks::kSetBookmarkTitleFunction] =
129 &NewExtensionFunction<SetBookmarkTitleFunction>; 132 &NewExtensionFunction<SetBookmarkTitleFunction>;
133
134 // Toolstrips.
135 factories_[toolstrip::kExpandFunction] =
136 &NewExtensionFunction<ToolstripExpandFunction>;
137 factories_[toolstrip::kCollapseFunction] =
138 &NewExtensionFunction<ToolstripCollapseFunction>;
130 } 139 }
131 140
132 void FactoryRegistry::GetAllNames(std::vector<std::string>* names) { 141 void FactoryRegistry::GetAllNames(std::vector<std::string>* names) {
133 for (FactoryMap::iterator iter = factories_.begin(); 142 for (FactoryMap::iterator iter = factories_.begin();
134 iter != factories_.end(); ++iter) { 143 iter != factories_.end(); ++iter) {
135 names->push_back(iter->first); 144 names->push_back(iter->first);
136 } 145 }
137 } 146 }
138 147
139 bool FactoryRegistry::OverrideFunction(const std::string& name, 148 bool FactoryRegistry::OverrideFunction(const std::string& name,
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 } 189 }
181 190
182 ExtensionFunctionDispatcher::ExtensionFunctionDispatcher( 191 ExtensionFunctionDispatcher::ExtensionFunctionDispatcher(
183 RenderViewHost* render_view_host, 192 RenderViewHost* render_view_host,
184 Delegate* delegate, 193 Delegate* delegate,
185 const GURL& url) 194 const GURL& url)
186 : render_view_host_(render_view_host), 195 : render_view_host_(render_view_host),
187 delegate_(delegate), 196 delegate_(delegate),
188 url_(url), 197 url_(url),
189 ALLOW_THIS_IN_INITIALIZER_LIST(peer_(new Peer(this))) { 198 ALLOW_THIS_IN_INITIALIZER_LIST(peer_(new Peer(this))) {
199 DCHECK(url.SchemeIs(chrome::kExtensionScheme));
200 // TODO(erikkay) also verify id is valid
201
190 all_instances()->insert(this); 202 all_instances()->insert(this);
191 203
192 // Notify the ExtensionProcessManager that the view was created. 204 // Notify the ExtensionProcessManager that the view was created.
193 ExtensionProcessManager* epm = profile()->GetExtensionProcessManager(); 205 ExtensionProcessManager* epm = profile()->GetExtensionProcessManager();
194 epm->RegisterExtensionProcess(extension_id(), 206 epm->RegisterExtensionProcess(extension_id(),
195 render_view_host->process()->pid()); 207 render_view_host->process()->pid());
196 } 208 }
197 209
198 ExtensionFunctionDispatcher::~ExtensionFunctionDispatcher() { 210 ExtensionFunctionDispatcher::~ExtensionFunctionDispatcher() {
199 all_instances()->erase(this); 211 all_instances()->erase(this);
200 peer_->dispatcher_ = NULL; 212 peer_->dispatcher_ = NULL;
201 } 213 }
202 214
203 Browser* ExtensionFunctionDispatcher::GetBrowser() { 215 Browser* ExtensionFunctionDispatcher::GetBrowser() {
204 DCHECK(delegate_); 216 DCHECK(delegate_);
205 217
206 Browser* retval = delegate_->GetBrowser(); 218 Browser* retval = delegate_->GetBrowser();
207 return retval; 219 return retval;
208 } 220 }
209 221
222 ExtensionHost* ExtensionFunctionDispatcher::GetHost() {
223 DCHECK(delegate_);
224 return delegate_->GetHost();
225 }
226
210 void ExtensionFunctionDispatcher::HandleRequest(const std::string& name, 227 void ExtensionFunctionDispatcher::HandleRequest(const std::string& name,
211 const std::string& args, 228 const std::string& args,
212 int request_id, 229 int request_id,
213 bool has_callback) { 230 bool has_callback) {
214 scoped_refptr<ExtensionFunction> function( 231 scoped_refptr<ExtensionFunction> function(
215 FactoryRegistry::instance()->NewFunction(name)); 232 FactoryRegistry::instance()->NewFunction(name));
216 function->set_dispatcher_peer(peer_); 233 function->set_dispatcher_peer(peer_);
217 function->SetArgs(args); 234 function->SetArgs(args);
218 function->set_request_id(request_id); 235 function->set_request_id(request_id);
219 function->set_has_callback(has_callback); 236 function->set_has_callback(has_callback);
(...skipping 15 matching lines...) Expand all
235 } else { 252 } else {
236 NOTREACHED(); 253 NOTREACHED();
237 base::KillProcess(render_view_host_->process()->process().handle(), 254 base::KillProcess(render_view_host_->process()->process().handle(),
238 ResultCodes::KILLED_BAD_MESSAGE, false); 255 ResultCodes::KILLED_BAD_MESSAGE, false);
239 } 256 }
240 } 257 }
241 258
242 Profile* ExtensionFunctionDispatcher::profile() { 259 Profile* ExtensionFunctionDispatcher::profile() {
243 return render_view_host_->process()->profile(); 260 return render_view_host_->process()->profile();
244 } 261 }
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