[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "chrome/browser/extensions/extension_function_dispatcher.h" |
| 6 | |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 7 | #include "base/process_util.h" |
| 8 | #include "base/singleton.h" |
| 9 | #include "base/values.h" |
| 10 | #include "chrome/browser/extensions/extension_bookmarks_module.h" |
[email protected] | f9391485 | 2009-05-26 06:05:40 | [diff] [blame] | 11 | #include "chrome/browser/extensions/extension_bookmarks_module_constants.h" |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 12 | #include "chrome/browser/extensions/extension_function.h" |
[email protected] | 198bcfe | 2009-09-09 22:56:28 | [diff] [blame^] | 13 | #include "chrome/browser/extensions/extension_i18n_api.h" |
[email protected] | e916901c | 2009-05-07 00:14:31 | [diff] [blame] | 14 | #include "chrome/browser/extensions/extension_message_service.h" |
[email protected] | f7f3a5f | 2009-05-01 22:02:34 | [diff] [blame] | 15 | #include "chrome/browser/extensions/extension_page_actions_module.h" |
[email protected] | f9391485 | 2009-05-26 06:05:40 | [diff] [blame] | 16 | #include "chrome/browser/extensions/extension_page_actions_module_constants.h" |
[email protected] | 4577622 | 2009-07-15 20:21:58 | [diff] [blame] | 17 | #include "chrome/browser/extensions/extension_process_manager.h" |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 18 | #include "chrome/browser/extensions/extension_tabs_module.h" |
[email protected] | f9391485 | 2009-05-26 06:05:40 | [diff] [blame] | 19 | #include "chrome/browser/extensions/extension_tabs_module_constants.h" |
[email protected] | 25fd1b2e | 2009-08-17 20:57:14 | [diff] [blame] | 20 | #include "chrome/browser/extensions/extension_test_api.h" |
[email protected] | 9c45b718 | 2009-08-04 16:44:43 | [diff] [blame] | 21 | #include "chrome/browser/extensions/extension_toolstrip_api.h" |
[email protected] | e916901c | 2009-05-07 00:14:31 | [diff] [blame] | 22 | #include "chrome/browser/profile.h" |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 23 | #include "chrome/browser/renderer_host/render_process_host.h" |
| 24 | #include "chrome/browser/renderer_host/render_view_host.h" |
[email protected] | 3550635 | 2009-08-07 18:58:19 | [diff] [blame] | 25 | #include "chrome/common/render_messages.h" |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 26 | #include "chrome/common/result_codes.h" |
[email protected] | 9c45b718 | 2009-08-04 16:44:43 | [diff] [blame] | 27 | #include "chrome/common/url_constants.h" |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 28 | |
| 29 | // FactoryRegistry ------------------------------------------------------------- |
| 30 | |
| 31 | namespace { |
| 32 | |
[email protected] | b83e460 | 2009-05-15 22:58:33 | [diff] [blame] | 33 | // Template for defining ExtensionFunctionFactory. |
| 34 | template<class T> |
| 35 | ExtensionFunction* NewExtensionFunction() { |
| 36 | return new T(); |
| 37 | } |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 38 | |
[email protected] | b83e460 | 2009-05-15 22:58:33 | [diff] [blame] | 39 | // Contains a list of all known extension functions and allows clients to |
| 40 | // create instances of them. |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 41 | class FactoryRegistry { |
| 42 | public: |
| 43 | static FactoryRegistry* instance(); |
[email protected] | b83e460 | 2009-05-15 22:58:33 | [diff] [blame] | 44 | FactoryRegistry() { ResetFunctions(); } |
| 45 | |
| 46 | // Resets all functions to their default values. |
| 47 | void ResetFunctions(); |
| 48 | |
| 49 | // Adds all function names to 'names'. |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 50 | void GetAllNames(std::vector<std::string>* names); |
[email protected] | b83e460 | 2009-05-15 22:58:33 | [diff] [blame] | 51 | |
| 52 | // Allows overriding of specific functions (e.g. for testing). Functions |
| 53 | // must be previously registered. Returns true if successful. |
| 54 | bool OverrideFunction(const std::string& name, |
| 55 | ExtensionFunctionFactory factory); |
| 56 | |
| 57 | // Factory method for the ExtensionFunction registered as 'name'. |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 58 | ExtensionFunction* NewFunction(const std::string& name); |
| 59 | |
| 60 | private: |
| 61 | typedef std::map<std::string, ExtensionFunctionFactory> FactoryMap; |
| 62 | FactoryMap factories_; |
| 63 | }; |
| 64 | |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 65 | FactoryRegistry* FactoryRegistry::instance() { |
| 66 | return Singleton<FactoryRegistry>::get(); |
| 67 | } |
| 68 | |
[email protected] | b83e460 | 2009-05-15 22:58:33 | [diff] [blame] | 69 | void FactoryRegistry::ResetFunctions() { |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 70 | // Register all functions here. |
| 71 | |
[email protected] | f9391485 | 2009-05-26 06:05:40 | [diff] [blame] | 72 | namespace bookmarks = extension_bookmarks_module_constants; |
[email protected] | 198bcfe | 2009-09-09 22:56:28 | [diff] [blame^] | 73 | namespace i18n = extension_i18n_api_functions; |
[email protected] | 25fd1b2e | 2009-08-17 20:57:14 | [diff] [blame] | 74 | namespace page_actions = extension_page_actions_module_constants; |
| 75 | namespace tabs = extension_tabs_module_constants; |
| 76 | namespace test = extension_test_api_functions; |
[email protected] | 9c45b718 | 2009-08-04 16:44:43 | [diff] [blame] | 77 | namespace toolstrip = extension_toolstrip_api_functions; |
[email protected] | f9391485 | 2009-05-26 06:05:40 | [diff] [blame] | 78 | |
[email protected] | e515f5d | 2009-05-05 03:05:00 | [diff] [blame] | 79 | // Windows |
[email protected] | afac6fe | 2009-06-04 14:58:18 | [diff] [blame] | 80 | factories_[tabs::kGetWindowFunction] = |
[email protected] | f9391485 | 2009-05-26 06:05:40 | [diff] [blame] | 81 | &NewExtensionFunction<GetWindowFunction>; |
| 82 | factories_[tabs::kGetCurrentWindowFunction] = |
[email protected] | e515f5d | 2009-05-05 03:05:00 | [diff] [blame] | 83 | &NewExtensionFunction<GetCurrentWindowFunction>; |
[email protected] | f9391485 | 2009-05-26 06:05:40 | [diff] [blame] | 84 | factories_[tabs::kGetLastFocusedWindowFunction] = |
[email protected] | c661918 | 2009-05-12 14:59:32 | [diff] [blame] | 85 | &NewExtensionFunction<GetLastFocusedWindowFunction>; |
[email protected] | f9391485 | 2009-05-26 06:05:40 | [diff] [blame] | 86 | factories_[tabs::kGetAllWindowsFunction] = |
| 87 | &NewExtensionFunction<GetAllWindowsFunction>; |
[email protected] | afac6fe | 2009-06-04 14:58:18 | [diff] [blame] | 88 | factories_[tabs::kCreateWindowFunction] = |
[email protected] | f9391485 | 2009-05-26 06:05:40 | [diff] [blame] | 89 | &NewExtensionFunction<CreateWindowFunction>; |
[email protected] | afac6fe | 2009-06-04 14:58:18 | [diff] [blame] | 90 | factories_[tabs::kUpdateWindowFunction] = |
[email protected] | f9391485 | 2009-05-26 06:05:40 | [diff] [blame] | 91 | &NewExtensionFunction<UpdateWindowFunction>; |
[email protected] | afac6fe | 2009-06-04 14:58:18 | [diff] [blame] | 92 | factories_[tabs::kRemoveWindowFunction] = |
[email protected] | f9391485 | 2009-05-26 06:05:40 | [diff] [blame] | 93 | &NewExtensionFunction<RemoveWindowFunction>; |
[email protected] | b83e460 | 2009-05-15 22:58:33 | [diff] [blame] | 94 | |
[email protected] | e515f5d | 2009-05-05 03:05:00 | [diff] [blame] | 95 | // Tabs |
[email protected] | afac6fe | 2009-06-04 14:58:18 | [diff] [blame] | 96 | factories_[tabs::kGetTabFunction] = |
[email protected] | f9391485 | 2009-05-26 06:05:40 | [diff] [blame] | 97 | &NewExtensionFunction<GetTabFunction>; |
| 98 | factories_[tabs::kGetSelectedTabFunction] = |
[email protected] | b83e460 | 2009-05-15 22:58:33 | [diff] [blame] | 99 | &NewExtensionFunction<GetSelectedTabFunction>; |
[email protected] | f9391485 | 2009-05-26 06:05:40 | [diff] [blame] | 100 | factories_[tabs::kGetAllTabsInWindowFunction] = |
[email protected] | e515f5d | 2009-05-05 03:05:00 | [diff] [blame] | 101 | &NewExtensionFunction<GetAllTabsInWindowFunction>; |
[email protected] | afac6fe | 2009-06-04 14:58:18 | [diff] [blame] | 102 | factories_[tabs::kCreateTabFunction] = |
[email protected] | f9391485 | 2009-05-26 06:05:40 | [diff] [blame] | 103 | &NewExtensionFunction<CreateTabFunction>; |
[email protected] | afac6fe | 2009-06-04 14:58:18 | [diff] [blame] | 104 | factories_[tabs::kUpdateTabFunction] = |
[email protected] | f9391485 | 2009-05-26 06:05:40 | [diff] [blame] | 105 | &NewExtensionFunction<UpdateTabFunction>; |
[email protected] | afac6fe | 2009-06-04 14:58:18 | [diff] [blame] | 106 | factories_[tabs::kMoveTabFunction] = |
[email protected] | f9391485 | 2009-05-26 06:05:40 | [diff] [blame] | 107 | &NewExtensionFunction<MoveTabFunction>; |
[email protected] | afac6fe | 2009-06-04 14:58:18 | [diff] [blame] | 108 | factories_[tabs::kRemoveTabFunction] = |
[email protected] | f9391485 | 2009-05-26 06:05:40 | [diff] [blame] | 109 | &NewExtensionFunction<RemoveTabFunction>; |
[email protected] | 5bf3935 | 2009-07-16 20:43:01 | [diff] [blame] | 110 | factories_[tabs::kDetectTabLanguageFunction] = |
| 111 | &NewExtensionFunction<DetectTabLanguageFunction>; |
[email protected] | 3947c4d | 2009-08-13 00:04:06 | [diff] [blame] | 112 | factories_[tabs::kCaptureVisibleTabFunction] = |
| 113 | &NewExtensionFunction<CaptureVisibleTabFunction>; |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 114 | |
[email protected] | f7f3a5f | 2009-05-01 22:02:34 | [diff] [blame] | 115 | // Page Actions. |
[email protected] | f9391485 | 2009-05-26 06:05:40 | [diff] [blame] | 116 | factories_[page_actions::kEnablePageActionFunction] = |
[email protected] | f7f3a5f | 2009-05-01 22:02:34 | [diff] [blame] | 117 | &NewExtensionFunction<EnablePageActionFunction>; |
[email protected] | f9b1a7b | 2009-06-22 17:26:38 | [diff] [blame] | 118 | factories_[page_actions::kDisablePageActionFunction] = |
| 119 | &NewExtensionFunction<DisablePageActionFunction>; |
[email protected] | f7f3a5f | 2009-05-01 22:02:34 | [diff] [blame] | 120 | |
| 121 | // Bookmarks. |
[email protected] | f9391485 | 2009-05-26 06:05:40 | [diff] [blame] | 122 | factories_[bookmarks::kGetBookmarksFunction] = |
| 123 | &NewExtensionFunction<GetBookmarksFunction>; |
| 124 | factories_[bookmarks::kGetBookmarkChildrenFunction] = |
[email protected] | 309934c4 | 2009-04-29 20:28:46 | [diff] [blame] | 125 | &NewExtensionFunction<GetBookmarkChildrenFunction>; |
[email protected] | f9391485 | 2009-05-26 06:05:40 | [diff] [blame] | 126 | factories_[bookmarks::kGetBookmarkTreeFunction] = |
[email protected] | 309934c4 | 2009-04-29 20:28:46 | [diff] [blame] | 127 | &NewExtensionFunction<GetBookmarkTreeFunction>; |
[email protected] | f9391485 | 2009-05-26 06:05:40 | [diff] [blame] | 128 | factories_[bookmarks::kSearchBookmarksFunction] = |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 129 | &NewExtensionFunction<SearchBookmarksFunction>; |
[email protected] | f9391485 | 2009-05-26 06:05:40 | [diff] [blame] | 130 | factories_[bookmarks::kRemoveBookmarkFunction] = |
[email protected] | b83e460 | 2009-05-15 22:58:33 | [diff] [blame] | 131 | &NewExtensionFunction<RemoveBookmarkFunction>; |
[email protected] | 434c21e | 2009-07-16 22:20:00 | [diff] [blame] | 132 | factories_[bookmarks::kRemoveBookmarkTreeFunction] = |
| 133 | &NewExtensionFunction<RemoveBookmarkFunction>; |
[email protected] | f9391485 | 2009-05-26 06:05:40 | [diff] [blame] | 134 | factories_[bookmarks::kCreateBookmarkFunction] = |
[email protected] | b83e460 | 2009-05-15 22:58:33 | [diff] [blame] | 135 | &NewExtensionFunction<CreateBookmarkFunction>; |
[email protected] | f9391485 | 2009-05-26 06:05:40 | [diff] [blame] | 136 | factories_[bookmarks::kMoveBookmarkFunction] = |
| 137 | &NewExtensionFunction<MoveBookmarkFunction>; |
[email protected] | ea7c4fb | 2009-09-01 15:49:37 | [diff] [blame] | 138 | factories_[bookmarks::kUpdateBookmarkFunction] = |
| 139 | &NewExtensionFunction<UpdateBookmarkFunction>; |
[email protected] | 9c45b718 | 2009-08-04 16:44:43 | [diff] [blame] | 140 | |
| 141 | // Toolstrips. |
| 142 | factories_[toolstrip::kExpandFunction] = |
| 143 | &NewExtensionFunction<ToolstripExpandFunction>; |
| 144 | factories_[toolstrip::kCollapseFunction] = |
| 145 | &NewExtensionFunction<ToolstripCollapseFunction>; |
[email protected] | 25fd1b2e | 2009-08-17 20:57:14 | [diff] [blame] | 146 | |
[email protected] | 198bcfe | 2009-09-09 22:56:28 | [diff] [blame^] | 147 | // I18N. |
| 148 | factories_[i18n::kGetAcceptLanguagesFunction] = |
| 149 | &NewExtensionFunction<GetAcceptLanguagesFunction>; |
| 150 | |
[email protected] | 25fd1b2e | 2009-08-17 20:57:14 | [diff] [blame] | 151 | // Test. |
| 152 | factories_[test::kPassFunction] = |
| 153 | &NewExtensionFunction<ExtensionTestPassFunction>; |
| 154 | factories_[test::kFailFunction] = |
| 155 | &NewExtensionFunction<ExtensionTestFailFunction>; |
[email protected] | 9b6d31d | 2009-09-01 01:44:03 | [diff] [blame] | 156 | factories_[test::kLogFunction] = |
| 157 | &NewExtensionFunction<ExtensionTestLogFunction>; |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 158 | } |
| 159 | |
[email protected] | b83e460 | 2009-05-15 22:58:33 | [diff] [blame] | 160 | void FactoryRegistry::GetAllNames(std::vector<std::string>* names) { |
| 161 | for (FactoryMap::iterator iter = factories_.begin(); |
| 162 | iter != factories_.end(); ++iter) { |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 163 | names->push_back(iter->first); |
| 164 | } |
| 165 | } |
| 166 | |
[email protected] | b83e460 | 2009-05-15 22:58:33 | [diff] [blame] | 167 | bool FactoryRegistry::OverrideFunction(const std::string& name, |
| 168 | ExtensionFunctionFactory factory) { |
| 169 | FactoryMap::iterator iter = factories_.find(name); |
| 170 | if (iter == factories_.end()) { |
| 171 | return false; |
| 172 | } else { |
| 173 | iter->second = factory; |
| 174 | return true; |
| 175 | } |
| 176 | } |
| 177 | |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 178 | ExtensionFunction* FactoryRegistry::NewFunction(const std::string& name) { |
| 179 | FactoryMap::iterator iter = factories_.find(name); |
| 180 | DCHECK(iter != factories_.end()); |
[email protected] | b83e460 | 2009-05-15 22:58:33 | [diff] [blame] | 181 | ExtensionFunction* function = iter->second(); |
[email protected] | 76a3db85 | 2009-07-24 02:14:56 | [diff] [blame] | 182 | function->set_name(name); |
[email protected] | b83e460 | 2009-05-15 22:58:33 | [diff] [blame] | 183 | return function; |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 184 | } |
| 185 | |
[email protected] | b83e460 | 2009-05-15 22:58:33 | [diff] [blame] | 186 | }; // namespace |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 187 | |
| 188 | // ExtensionFunctionDispatcher ------------------------------------------------- |
| 189 | |
| 190 | void ExtensionFunctionDispatcher::GetAllFunctionNames( |
| 191 | std::vector<std::string>* names) { |
| 192 | FactoryRegistry::instance()->GetAllNames(names); |
| 193 | } |
| 194 | |
[email protected] | b83e460 | 2009-05-15 22:58:33 | [diff] [blame] | 195 | bool ExtensionFunctionDispatcher::OverrideFunction( |
| 196 | const std::string& name, ExtensionFunctionFactory factory) { |
| 197 | return FactoryRegistry::instance()->OverrideFunction(name, factory); |
| 198 | } |
| 199 | |
| 200 | void ExtensionFunctionDispatcher::ResetFunctions() { |
| 201 | FactoryRegistry::instance()->ResetFunctions(); |
| 202 | } |
| 203 | |
[email protected] | 811bfe3 | 2009-07-01 08:46:25 | [diff] [blame] | 204 | std::set<ExtensionFunctionDispatcher*>* |
| 205 | ExtensionFunctionDispatcher::all_instances() { |
| 206 | static std::set<ExtensionFunctionDispatcher*> instances; |
| 207 | return &instances; |
| 208 | } |
| 209 | |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 210 | ExtensionFunctionDispatcher::ExtensionFunctionDispatcher( |
| 211 | RenderViewHost* render_view_host, |
[email protected] | 7eecaed5 | 2009-05-07 21:44:12 | [diff] [blame] | 212 | Delegate* delegate, |
[email protected] | 811bfe3 | 2009-07-01 08:46:25 | [diff] [blame] | 213 | const GURL& url) |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 214 | : render_view_host_(render_view_host), |
[email protected] | 7eecaed5 | 2009-05-07 21:44:12 | [diff] [blame] | 215 | delegate_(delegate), |
[email protected] | 811bfe3 | 2009-07-01 08:46:25 | [diff] [blame] | 216 | url_(url), |
[email protected] | 32dda36 | 2009-06-05 19:07:01 | [diff] [blame] | 217 | ALLOW_THIS_IN_INITIALIZER_LIST(peer_(new Peer(this))) { |
[email protected] | 9c45b718 | 2009-08-04 16:44:43 | [diff] [blame] | 218 | // TODO(erikkay) should we do something for these errors in Release? |
| 219 | DCHECK(url.SchemeIs(chrome::kExtensionScheme)); |
[email protected] | 3550635 | 2009-08-07 18:58:19 | [diff] [blame] | 220 | |
| 221 | Extension* extension = |
| 222 | profile()->GetExtensionsService()->GetExtensionByURL(url); |
| 223 | DCHECK(extension); |
[email protected] | 9c45b718 | 2009-08-04 16:44:43 | [diff] [blame] | 224 | |
[email protected] | 811bfe3 | 2009-07-01 08:46:25 | [diff] [blame] | 225 | all_instances()->insert(this); |
[email protected] | 0f605396 | 2009-07-09 19:26:35 | [diff] [blame] | 226 | |
[email protected] | 4577622 | 2009-07-15 20:21:58 | [diff] [blame] | 227 | // Notify the ExtensionProcessManager that the view was created. |
| 228 | ExtensionProcessManager* epm = profile()->GetExtensionProcessManager(); |
| 229 | epm->RegisterExtensionProcess(extension_id(), |
[email protected] | 76543b9 | 2009-08-31 17:27:45 | [diff] [blame] | 230 | render_view_host->process()->id()); |
[email protected] | 3550635 | 2009-08-07 18:58:19 | [diff] [blame] | 231 | |
| 232 | // Update the extension permissions. Doing this each time we create an EFD |
| 233 | // ensures that new processes are informed of permissions for newly installed |
| 234 | // extensions. |
[email protected] | cccf9093 | 2009-08-23 17:56:25 | [diff] [blame] | 235 | render_view_host->Send(new ViewMsg_Extension_SetAPIPermissions( |
[email protected] | 3550635 | 2009-08-07 18:58:19 | [diff] [blame] | 236 | extension->id(), extension->api_permissions())); |
[email protected] | cccf9093 | 2009-08-23 17:56:25 | [diff] [blame] | 237 | render_view_host->Send(new ViewMsg_Extension_SetHostPermissions( |
| 238 | extension->url(), extension->host_permissions())); |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 239 | } |
| 240 | |
[email protected] | 32dda36 | 2009-06-05 19:07:01 | [diff] [blame] | 241 | ExtensionFunctionDispatcher::~ExtensionFunctionDispatcher() { |
[email protected] | 811bfe3 | 2009-07-01 08:46:25 | [diff] [blame] | 242 | all_instances()->erase(this); |
[email protected] | 32dda36 | 2009-06-05 19:07:01 | [diff] [blame] | 243 | peer_->dispatcher_ = NULL; |
| 244 | } |
| 245 | |
[email protected] | 7eecaed5 | 2009-05-07 21:44:12 | [diff] [blame] | 246 | Browser* ExtensionFunctionDispatcher::GetBrowser() { |
[email protected] | 4ba60e2 | 2009-08-14 21:02:11 | [diff] [blame] | 247 | return delegate_->GetBrowser(); |
[email protected] | 7eecaed5 | 2009-05-07 21:44:12 | [diff] [blame] | 248 | } |
| 249 | |
[email protected] | 9c45b718 | 2009-08-04 16:44:43 | [diff] [blame] | 250 | ExtensionHost* ExtensionFunctionDispatcher::GetExtensionHost() { |
[email protected] | 9c45b718 | 2009-08-04 16:44:43 | [diff] [blame] | 251 | return delegate_->GetExtensionHost(); |
| 252 | } |
| 253 | |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 254 | void ExtensionFunctionDispatcher::HandleRequest(const std::string& name, |
| 255 | const std::string& args, |
[email protected] | c661918 | 2009-05-12 14:59:32 | [diff] [blame] | 256 | int request_id, |
| 257 | bool has_callback) { |
[email protected] | 32dda36 | 2009-06-05 19:07:01 | [diff] [blame] | 258 | scoped_refptr<ExtensionFunction> function( |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 259 | FactoryRegistry::instance()->NewFunction(name)); |
[email protected] | 32dda36 | 2009-06-05 19:07:01 | [diff] [blame] | 260 | function->set_dispatcher_peer(peer_); |
[email protected] | b83e460 | 2009-05-15 22:58:33 | [diff] [blame] | 261 | function->SetArgs(args); |
[email protected] | c661918 | 2009-05-12 14:59:32 | [diff] [blame] | 262 | function->set_request_id(request_id); |
| 263 | function->set_has_callback(has_callback); |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 264 | function->Run(); |
| 265 | } |
| 266 | |
[email protected] | c661918 | 2009-05-12 14:59:32 | [diff] [blame] | 267 | void ExtensionFunctionDispatcher::SendResponse(ExtensionFunction* function, |
| 268 | bool success) { |
[email protected] | c661918 | 2009-05-12 14:59:32 | [diff] [blame] | 269 | render_view_host_->SendExtensionResponse(function->request_id(), success, |
[email protected] | b83e460 | 2009-05-15 22:58:33 | [diff] [blame] | 270 | function->GetResult(), function->GetError()); |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | void ExtensionFunctionDispatcher::HandleBadMessage(ExtensionFunction* api) { |
[email protected] | 25fd1b2e | 2009-08-17 20:57:14 | [diff] [blame] | 274 | LOG(ERROR) << "bad extension message " << |
[email protected] | 76543b9 | 2009-08-31 17:27:45 | [diff] [blame] | 275 | api->name() << |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 276 | " : terminating renderer."; |
| 277 | if (RenderProcessHost::run_renderer_in_process()) { |
| 278 | // In single process mode it is better if we don't suicide but just crash. |
| 279 | CHECK(false); |
| 280 | } else { |
| 281 | NOTREACHED(); |
| 282 | base::KillProcess(render_view_host_->process()->process().handle(), |
| 283 | ResultCodes::KILLED_BAD_MESSAGE, false); |
| 284 | } |
| 285 | } |
| 286 | |
| 287 | Profile* ExtensionFunctionDispatcher::profile() { |
| 288 | return render_view_host_->process()->profile(); |
| 289 | } |