| OLD | NEW | 
|---|
| 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  Loading... | 
| 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_functions; | 
| 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  Loading... | 
| 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  Loading... | 
| 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   // TODO(erikkay) should we do something for these errors in Release? | 
|  | 200   DCHECK(url.SchemeIs(chrome::kExtensionScheme)); | 
|  | 201   DCHECK(profile()->GetExtensionsService()->GetExtensionByURL(url)); | 
|  | 202 | 
| 190   all_instances()->insert(this); | 203   all_instances()->insert(this); | 
| 191 | 204 | 
| 192   // Notify the ExtensionProcessManager that the view was created. | 205   // Notify the ExtensionProcessManager that the view was created. | 
| 193   ExtensionProcessManager* epm = profile()->GetExtensionProcessManager(); | 206   ExtensionProcessManager* epm = profile()->GetExtensionProcessManager(); | 
| 194   epm->RegisterExtensionProcess(extension_id(), | 207   epm->RegisterExtensionProcess(extension_id(), | 
| 195                                 render_view_host->process()->pid()); | 208                                 render_view_host->process()->pid()); | 
| 196 } | 209 } | 
| 197 | 210 | 
| 198 ExtensionFunctionDispatcher::~ExtensionFunctionDispatcher() { | 211 ExtensionFunctionDispatcher::~ExtensionFunctionDispatcher() { | 
| 199   all_instances()->erase(this); | 212   all_instances()->erase(this); | 
| 200   peer_->dispatcher_ = NULL; | 213   peer_->dispatcher_ = NULL; | 
| 201 } | 214 } | 
| 202 | 215 | 
| 203 Browser* ExtensionFunctionDispatcher::GetBrowser() { | 216 Browser* ExtensionFunctionDispatcher::GetBrowser() { | 
| 204   DCHECK(delegate_); | 217   DCHECK(delegate_); | 
| 205 | 218 | 
| 206   Browser* retval = delegate_->GetBrowser(); | 219   Browser* retval = delegate_->GetBrowser(); | 
| 207   return retval; | 220   return retval; | 
| 208 } | 221 } | 
| 209 | 222 | 
|  | 223 ExtensionHost* ExtensionFunctionDispatcher::GetExtensionHost() { | 
|  | 224   DCHECK(delegate_); | 
|  | 225   return delegate_->GetExtensionHost(); | 
|  | 226 } | 
|  | 227 | 
| 210 void ExtensionFunctionDispatcher::HandleRequest(const std::string& name, | 228 void ExtensionFunctionDispatcher::HandleRequest(const std::string& name, | 
| 211                                                 const std::string& args, | 229                                                 const std::string& args, | 
| 212                                                 int request_id, | 230                                                 int request_id, | 
| 213                                                 bool has_callback) { | 231                                                 bool has_callback) { | 
| 214   scoped_refptr<ExtensionFunction> function( | 232   scoped_refptr<ExtensionFunction> function( | 
| 215       FactoryRegistry::instance()->NewFunction(name)); | 233       FactoryRegistry::instance()->NewFunction(name)); | 
| 216   function->set_dispatcher_peer(peer_); | 234   function->set_dispatcher_peer(peer_); | 
| 217   function->SetArgs(args); | 235   function->SetArgs(args); | 
| 218   function->set_request_id(request_id); | 236   function->set_request_id(request_id); | 
| 219   function->set_has_callback(has_callback); | 237   function->set_has_callback(has_callback); | 
| (...skipping 15 matching lines...) Expand all  Loading... | 
| 235   } else { | 253   } else { | 
| 236     NOTREACHED(); | 254     NOTREACHED(); | 
| 237     base::KillProcess(render_view_host_->process()->process().handle(), | 255     base::KillProcess(render_view_host_->process()->process().handle(), | 
| 238                       ResultCodes::KILLED_BAD_MESSAGE, false); | 256                       ResultCodes::KILLED_BAD_MESSAGE, false); | 
| 239   } | 257   } | 
| 240 } | 258 } | 
| 241 | 259 | 
| 242 Profile* ExtensionFunctionDispatcher::profile() { | 260 Profile* ExtensionFunctionDispatcher::profile() { | 
| 243   return render_view_host_->process()->profile(); | 261   return render_view_host_->process()->profile(); | 
| 244 } | 262 } | 
| OLD | NEW | 
|---|