[email protected] | e0813a39 | 2011-02-01 22:57:25 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 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] | 745feedb | 2010-08-02 04:08:07 | [diff] [blame] | 7 | #include <map> |
| 8 | |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 9 | #include "base/memory/ref_counted.h" |
| 10 | #include "base/memory/singleton.h" |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 11 | #include "base/process_util.h" |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 12 | #include "base/values.h" |
[email protected] | 17d40f0 | 2010-07-01 01:18:06 | [diff] [blame] | 13 | #include "build/build_config.h" |
[email protected] | 912256b3 | 2009-09-18 09:47:35 | [diff] [blame] | 14 | #include "chrome/browser/extensions/execute_code_in_tab_function.h" |
[email protected] | 5cbe1e2 | 2010-01-30 01:18:56 | [diff] [blame] | 15 | #include "chrome/browser/extensions/extension_accessibility_api.h" |
[email protected] | c1d05aa | 2011-06-28 02:07:30 | [diff] [blame] | 16 | #include "chrome/browser/extensions/extension_app_api.h" |
[email protected] | 9dd97bc | 2010-01-14 01:40:04 | [diff] [blame] | 17 | #include "chrome/browser/extensions/extension_bookmark_manager_api.h" |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 18 | #include "chrome/browser/extensions/extension_bookmarks_module.h" |
[email protected] | ec9ac0df | 2009-10-01 18:06:47 | [diff] [blame] | 19 | #include "chrome/browser/extensions/extension_browser_actions_api.h" |
[email protected] | 6093d74 | 2011-08-26 16:37:18 | [diff] [blame] | 20 | #include "chrome/browser/extensions/extension_clear_api.h" |
[email protected] | 6a16dc9b | 2011-10-17 18:28:16 | [diff] [blame] | 21 | #include "chrome/browser/extensions/extension_clipboard_api.h" |
[email protected] | be9d9c8 | 2011-07-13 04:17:31 | [diff] [blame] | 22 | #include "chrome/browser/extensions/extension_chrome_auth_private_api.h" |
[email protected] | fa062426 | 2011-06-09 14:17:38 | [diff] [blame] | 23 | #include "chrome/browser/extensions/extension_content_settings_api.h" |
[email protected] | 2e3b520 | 2010-03-23 06:52:41 | [diff] [blame] | 24 | #include "chrome/browser/extensions/extension_context_menu_api.h" |
[email protected] | 898bbd3 | 2010-05-18 18:52:29 | [diff] [blame] | 25 | #include "chrome/browser/extensions/extension_cookies_api.h" |
[email protected] | 91ba331 | 2011-03-17 20:39:22 | [diff] [blame] | 26 | #include "chrome/browser/extensions/extension_debugger_api.h" |
[email protected] | 21d7a4e30 | 2011-08-15 16:17:12 | [diff] [blame] | 27 | #include "chrome/browser/extensions/extension_downloads_api.h" |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 28 | #include "chrome/browser/extensions/extension_function.h" |
[email protected] | 2bb5130 | 2011-02-18 22:39:27 | [diff] [blame] | 29 | #include "chrome/browser/extensions/extension_i18n_api.h" |
[email protected] | 2f69b38 | 2011-02-19 00:34:25 | [diff] [blame] | 30 | #include "chrome/browser/extensions/extension_idle_api.h" |
[email protected] | cffd789 | 2010-08-26 17:43:28 | [diff] [blame] | 31 | #include "chrome/browser/extensions/extension_management_api.h" |
[email protected] | 438772df | 2010-02-26 18:08:43 | [diff] [blame] | 32 | #include "chrome/browser/extensions/extension_metrics_module.h" |
[email protected] | a65882c | 2010-11-12 15:15:09 | [diff] [blame] | 33 | #include "chrome/browser/extensions/extension_module.h" |
[email protected] | 56ad379 | 2010-05-28 17:45:33 | [diff] [blame] | 34 | #include "chrome/browser/extensions/extension_omnibox_api.h" |
[email protected] | f7f3a5f | 2009-05-01 22:02:34 | [diff] [blame] | 35 | #include "chrome/browser/extensions/extension_page_actions_module.h" |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 36 | #include "chrome/browser/extensions/extension_permissions_api.h" |
[email protected] | 598bbcc | 2011-02-24 10:03:25 | [diff] [blame] | 37 | #include "chrome/browser/extensions/extension_preference_api.h" |
[email protected] | 381162b | 2010-01-28 17:29:35 | [diff] [blame] | 38 | #include "chrome/browser/extensions/extension_processes_api.h" |
[email protected] | a9c23a5 | 2010-08-04 09:13:44 | [diff] [blame] | 39 | #include "chrome/browser/extensions/extension_proxy_api.h" |
[email protected] | 17d40f0 | 2010-07-01 01:18:06 | [diff] [blame] | 40 | #include "chrome/browser/extensions/extension_rlz_module.h" |
[email protected] | 3a605e8 | 2011-09-26 17:26:16 | [diff] [blame] | 41 | #include "chrome/browser/extensions/extension_save_page_api.h" |
[email protected] | 2f69b38 | 2011-02-19 00:34:25 | [diff] [blame] | 42 | #include "chrome/browser/extensions/extension_service.h" |
[email protected] | b7f853e28 | 2011-08-10 09:24:20 | [diff] [blame] | 43 | #include "chrome/browser/extensions/extension_settings_api.h" |
[email protected] | 8b8e7c9 | 2010-08-19 18:05:56 | [diff] [blame] | 44 | #include "chrome/browser/extensions/extension_sidebar_api.h" |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 45 | #include "chrome/browser/extensions/extension_tabs_module.h" |
[email protected] | 25fd1b2e | 2009-08-17 20:57:14 | [diff] [blame] | 46 | #include "chrome/browser/extensions/extension_test_api.h" |
[email protected] | 8abe0a3 | 2010-08-12 00:40:22 | [diff] [blame] | 47 | #include "chrome/browser/extensions/extension_tts_api.h" |
[email protected] | c63f2b7 | 2011-07-07 05:25:00 | [diff] [blame] | 48 | #include "chrome/browser/extensions/extension_tts_engine_api.h" |
[email protected] | c6e584c | 2011-05-18 11:58:44 | [diff] [blame] | 49 | #include "chrome/browser/extensions/extension_web_socket_proxy_private_api.h" |
[email protected] | 8f9d4eb | 2011-02-05 01:39:10 | [diff] [blame] | 50 | #include "chrome/browser/extensions/extension_web_ui.h" |
[email protected] | 557a51dd | 2011-07-26 12:17:11 | [diff] [blame] | 51 | #include "chrome/browser/extensions/extension_webnavigation_api.h" |
[email protected] | c41fe66 | 2011-02-15 01:19:26 | [diff] [blame] | 52 | #include "chrome/browser/extensions/extension_webrequest_api.h" |
[email protected] | 63cda0c | 2010-09-01 04:41:23 | [diff] [blame] | 53 | #include "chrome/browser/extensions/extension_webstore_private_api.h" |
[email protected] | d13950e | 2009-12-04 01:43:02 | [diff] [blame] | 54 | #include "chrome/browser/extensions/extensions_quota_service.h" |
[email protected] | 7c216711 | 2011-10-13 10:48:16 | [diff] [blame] | 55 | #include "chrome/browser/extensions/speech_input/extension_speech_input_api.h" |
[email protected] | ed2b100 | 2011-05-25 14:12:10 | [diff] [blame] | 56 | #include "chrome/browser/external_protocol/external_protocol_handler.h" |
[email protected] | c583f5f | 2011-10-24 17:03:52 | [diff] [blame] | 57 | #include "chrome/browser/infobars/infobar_extension_api.h" |
[email protected] | d2e6bd6 | 2011-10-24 20:29:07 | [diff] [blame^] | 58 | #include "chrome/browser/history/history_extension_api.h" |
[email protected] | 8ecad5e | 2010-12-02 21:18:33 | [diff] [blame] | 59 | #include "chrome/browser/profiles/profile.h" |
[email protected] | c357acb4 | 2011-06-09 20:52:42 | [diff] [blame] | 60 | #include "chrome/browser/renderer_host/chrome_render_message_filter.h" |
[email protected] | 71b73f0 | 2011-04-06 15:57:29 | [diff] [blame] | 61 | #include "chrome/browser/ui/browser_list.h" |
[email protected] | 00070c73 | 2011-04-09 15:31:33 | [diff] [blame] | 62 | #include "chrome/browser/ui/browser_window.h" |
[email protected] | 44c49c9 | 2011-03-28 16:17:23 | [diff] [blame] | 63 | #include "chrome/common/extensions/extension_messages.h" |
[email protected] | 9c45b718 | 2009-08-04 16:44:43 | [diff] [blame] | 64 | #include "chrome/common/url_constants.h" |
[email protected] | 5de63471 | 2011-03-02 00:20:19 | [diff] [blame] | 65 | #include "content/browser/renderer_host/render_process_host.h" |
| 66 | #include "content/browser/renderer_host/render_view_host.h" |
[email protected] | f82d57b5 | 2011-04-27 19:13:17 | [diff] [blame] | 67 | #include "ipc/ipc_message.h" |
| 68 | #include "ipc/ipc_message_macros.h" |
[email protected] | 939856a | 2010-08-24 20:29:02 | [diff] [blame] | 69 | #include "third_party/skia/include/core/SkBitmap.h" |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 70 | |
[email protected] | 8f9d4eb | 2011-02-05 01:39:10 | [diff] [blame] | 71 | #if defined(TOOLKIT_VIEWS) |
| 72 | #include "chrome/browser/extensions/extension_input_api.h" |
| 73 | #endif |
[email protected] | d683385 | 2010-08-20 18:00:45 | [diff] [blame] | 74 | |
[email protected] | 27072cad | 2011-05-09 19:46:40 | [diff] [blame] | 75 | #if defined(OS_CHROMEOS) && defined(TOUCH_UI) |
| 76 | #include "chrome/browser/extensions/extension_input_ui_api.h" |
| 77 | #endif |
| 78 | |
[email protected] | 61b55b6 | 2011-03-24 09:03:10 | [diff] [blame] | 79 | #if defined(OS_CHROMEOS) |
[email protected] | b6b805e9 | 2011-04-16 09:24:14 | [diff] [blame] | 80 | #include "chrome/browser/extensions/extension_file_browser_private_api.h" |
[email protected] | 61b55b6 | 2011-03-24 09:03:10 | [diff] [blame] | 81 | #include "chrome/browser/extensions/extension_info_private_api_chromeos.h" |
[email protected] | 14da67b0 | 2011-08-02 05:49:13 | [diff] [blame] | 82 | #include "chrome/browser/extensions/extension_input_ime_api.h" |
[email protected] | be5bd574 | 2011-07-14 07:21:01 | [diff] [blame] | 83 | #include "chrome/browser/extensions/extension_input_method_api.h" |
[email protected] | ce980204 | 2011-05-27 10:11:40 | [diff] [blame] | 84 | #include "chrome/browser/extensions/extension_mediaplayer_private_api.h" |
[email protected] | 61b55b6 | 2011-03-24 09:03:10 | [diff] [blame] | 85 | #endif |
| 86 | |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 87 | // FactoryRegistry ------------------------------------------------------------- |
| 88 | |
| 89 | namespace { |
| 90 | |
[email protected] | b83e460 | 2009-05-15 22:58:33 | [diff] [blame] | 91 | // Template for defining ExtensionFunctionFactory. |
| 92 | template<class T> |
| 93 | ExtensionFunction* NewExtensionFunction() { |
| 94 | return new T(); |
| 95 | } |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 96 | |
[email protected] | b83e460 | 2009-05-15 22:58:33 | [diff] [blame] | 97 | // Contains a list of all known extension functions and allows clients to |
| 98 | // create instances of them. |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 99 | class FactoryRegistry { |
| 100 | public: |
[email protected] | 8e8bb6d | 2010-12-13 08:18:55 | [diff] [blame] | 101 | static FactoryRegistry* GetInstance(); |
[email protected] | b83e460 | 2009-05-15 22:58:33 | [diff] [blame] | 102 | FactoryRegistry() { ResetFunctions(); } |
| 103 | |
| 104 | // Resets all functions to their default values. |
| 105 | void ResetFunctions(); |
| 106 | |
| 107 | // Adds all function names to 'names'. |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 108 | void GetAllNames(std::vector<std::string>* names); |
[email protected] | b83e460 | 2009-05-15 22:58:33 | [diff] [blame] | 109 | |
| 110 | // Allows overriding of specific functions (e.g. for testing). Functions |
| 111 | // must be previously registered. Returns true if successful. |
| 112 | bool OverrideFunction(const std::string& name, |
| 113 | ExtensionFunctionFactory factory); |
| 114 | |
| 115 | // Factory method for the ExtensionFunction registered as 'name'. |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 116 | ExtensionFunction* NewFunction(const std::string& name); |
| 117 | |
| 118 | private: |
[email protected] | 61424c06 | 2009-10-14 23:14:59 | [diff] [blame] | 119 | template<class T> |
| 120 | void RegisterFunction() { |
| 121 | factories_[T::function_name()] = &NewExtensionFunction<T>; |
| 122 | } |
| 123 | |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 124 | typedef std::map<std::string, ExtensionFunctionFactory> FactoryMap; |
| 125 | FactoryMap factories_; |
| 126 | }; |
| 127 | |
[email protected] | 8e8bb6d | 2010-12-13 08:18:55 | [diff] [blame] | 128 | FactoryRegistry* FactoryRegistry::GetInstance() { |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 129 | return Singleton<FactoryRegistry>::get(); |
| 130 | } |
| 131 | |
[email protected] | b83e460 | 2009-05-15 22:58:33 | [diff] [blame] | 132 | void FactoryRegistry::ResetFunctions() { |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 133 | // Register all functions here. |
| 134 | |
[email protected] | e515f5d | 2009-05-05 03:05:00 | [diff] [blame] | 135 | // Windows |
[email protected] | 61424c06 | 2009-10-14 23:14:59 | [diff] [blame] | 136 | RegisterFunction<GetWindowFunction>(); |
| 137 | RegisterFunction<GetCurrentWindowFunction>(); |
| 138 | RegisterFunction<GetLastFocusedWindowFunction>(); |
| 139 | RegisterFunction<GetAllWindowsFunction>(); |
| 140 | RegisterFunction<CreateWindowFunction>(); |
| 141 | RegisterFunction<UpdateWindowFunction>(); |
| 142 | RegisterFunction<RemoveWindowFunction>(); |
[email protected] | b83e460 | 2009-05-15 22:58:33 | [diff] [blame] | 143 | |
[email protected] | e515f5d | 2009-05-05 03:05:00 | [diff] [blame] | 144 | // Tabs |
[email protected] | 61424c06 | 2009-10-14 23:14:59 | [diff] [blame] | 145 | RegisterFunction<GetTabFunction>(); |
[email protected] | e3eafb29 | 2010-04-14 21:30:41 | [diff] [blame] | 146 | RegisterFunction<GetCurrentTabFunction>(); |
[email protected] | 61424c06 | 2009-10-14 23:14:59 | [diff] [blame] | 147 | RegisterFunction<GetSelectedTabFunction>(); |
| 148 | RegisterFunction<GetAllTabsInWindowFunction>(); |
[email protected] | 8c3495c | 2011-09-28 03:32:30 | [diff] [blame] | 149 | RegisterFunction<QueryTabsFunction>(); |
| 150 | RegisterFunction<HighlightTabsFunction>(); |
[email protected] | 61424c06 | 2009-10-14 23:14:59 | [diff] [blame] | 151 | RegisterFunction<CreateTabFunction>(); |
| 152 | RegisterFunction<UpdateTabFunction>(); |
[email protected] | 8c3495c | 2011-09-28 03:32:30 | [diff] [blame] | 153 | RegisterFunction<MoveTabsFunction>(); |
[email protected] | 5d93511 | 2011-09-07 09:24:54 | [diff] [blame] | 154 | RegisterFunction<ReloadTabFunction>(); |
[email protected] | 8c3495c | 2011-09-28 03:32:30 | [diff] [blame] | 155 | RegisterFunction<RemoveTabsFunction>(); |
[email protected] | 61424c06 | 2009-10-14 23:14:59 | [diff] [blame] | 156 | RegisterFunction<DetectTabLanguageFunction>(); |
| 157 | RegisterFunction<CaptureVisibleTabFunction>(); |
| 158 | RegisterFunction<TabsExecuteScriptFunction>(); |
| 159 | RegisterFunction<TabsInsertCSSFunction>(); |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 160 | |
[email protected] | f7f3a5f | 2009-05-01 22:02:34 | [diff] [blame] | 161 | // Page Actions. |
[email protected] | 61424c06 | 2009-10-14 23:14:59 | [diff] [blame] | 162 | RegisterFunction<EnablePageActionFunction>(); |
| 163 | RegisterFunction<DisablePageActionFunction>(); |
[email protected] | 744ef17 | 2009-10-16 21:53:46 | [diff] [blame] | 164 | RegisterFunction<PageActionShowFunction>(); |
| 165 | RegisterFunction<PageActionHideFunction>(); |
| 166 | RegisterFunction<PageActionSetIconFunction>(); |
| 167 | RegisterFunction<PageActionSetTitleFunction>(); |
[email protected] | e478d670 | 2010-01-28 00:10:29 | [diff] [blame] | 168 | RegisterFunction<PageActionSetPopupFunction>(); |
[email protected] | f7f3a5f | 2009-05-01 22:02:34 | [diff] [blame] | 169 | |
[email protected] | ec9ac0df | 2009-10-01 18:06:47 | [diff] [blame] | 170 | // Browser Actions. |
[email protected] | 61424c06 | 2009-10-14 23:14:59 | [diff] [blame] | 171 | RegisterFunction<BrowserActionSetIconFunction>(); |
[email protected] | 1288ba0 | 2009-10-15 00:02:24 | [diff] [blame] | 172 | RegisterFunction<BrowserActionSetTitleFunction>(); |
[email protected] | 61424c06 | 2009-10-14 23:14:59 | [diff] [blame] | 173 | RegisterFunction<BrowserActionSetBadgeTextFunction>(); |
| 174 | RegisterFunction<BrowserActionSetBadgeBackgroundColorFunction>(); |
[email protected] | 85ae959 | 2010-02-03 20:58:50 | [diff] [blame] | 175 | RegisterFunction<BrowserActionSetPopupFunction>(); |
[email protected] | ec9ac0df | 2009-10-01 18:06:47 | [diff] [blame] | 176 | |
[email protected] | 6093d74 | 2011-08-26 16:37:18 | [diff] [blame] | 177 | // Browsing Data. |
| 178 | RegisterFunction<ClearBrowsingDataFunction>(); |
| 179 | RegisterFunction<ClearCacheFunction>(); |
| 180 | RegisterFunction<ClearCookiesFunction>(); |
| 181 | RegisterFunction<ClearDownloadsFunction>(); |
| 182 | RegisterFunction<ClearFormDataFunction>(); |
| 183 | RegisterFunction<ClearHistoryFunction>(); |
| 184 | RegisterFunction<ClearPasswordsFunction>(); |
| 185 | |
[email protected] | f7f3a5f | 2009-05-01 22:02:34 | [diff] [blame] | 186 | // Bookmarks. |
[email protected] | 61424c06 | 2009-10-14 23:14:59 | [diff] [blame] | 187 | RegisterFunction<GetBookmarksFunction>(); |
| 188 | RegisterFunction<GetBookmarkChildrenFunction>(); |
[email protected] | a3c94c71 | 2009-12-18 19:23:55 | [diff] [blame] | 189 | RegisterFunction<GetBookmarkRecentFunction>(); |
[email protected] | 61424c06 | 2009-10-14 23:14:59 | [diff] [blame] | 190 | RegisterFunction<GetBookmarkTreeFunction>(); |
[email protected] | 532a8c6 | 2011-06-03 21:30:01 | [diff] [blame] | 191 | RegisterFunction<GetBookmarkSubTreeFunction>(); |
[email protected] | 61424c06 | 2009-10-14 23:14:59 | [diff] [blame] | 192 | RegisterFunction<SearchBookmarksFunction>(); |
| 193 | RegisterFunction<RemoveBookmarkFunction>(); |
| 194 | RegisterFunction<RemoveTreeBookmarkFunction>(); |
| 195 | RegisterFunction<CreateBookmarkFunction>(); |
| 196 | RegisterFunction<MoveBookmarkFunction>(); |
| 197 | RegisterFunction<UpdateBookmarkFunction>(); |
[email protected] | 9c45b718 | 2009-08-04 16:44:43 | [diff] [blame] | 198 | |
[email protected] | f34e7963 | 2010-03-17 02:34:08 | [diff] [blame] | 199 | // Infobars. |
| 200 | RegisterFunction<ShowInfoBarFunction>(); |
| 201 | |
[email protected] | 9dd97bc | 2010-01-14 01:40:04 | [diff] [blame] | 202 | // BookmarkManager |
| 203 | RegisterFunction<CopyBookmarkManagerFunction>(); |
| 204 | RegisterFunction<CutBookmarkManagerFunction>(); |
| 205 | RegisterFunction<PasteBookmarkManagerFunction>(); |
[email protected] | 03b3bbf | 2010-01-29 23:54:57 | [diff] [blame] | 206 | RegisterFunction<CanPasteBookmarkManagerFunction>(); |
[email protected] | cb6cf79 | 2010-01-28 00:04:56 | [diff] [blame] | 207 | RegisterFunction<ImportBookmarksFunction>(); |
| 208 | RegisterFunction<ExportBookmarksFunction>(); |
[email protected] | d406e2e | 2010-01-30 21:45:18 | [diff] [blame] | 209 | RegisterFunction<SortChildrenBookmarkManagerFunction>(); |
[email protected] | 9dd97bc | 2010-01-14 01:40:04 | [diff] [blame] | 210 | RegisterFunction<BookmarkManagerGetStringsFunction>(); |
[email protected] | ced90ae1 | 2010-02-20 02:06:16 | [diff] [blame] | 211 | RegisterFunction<StartDragBookmarkManagerFunction>(); |
| 212 | RegisterFunction<DropBookmarkManagerFunction>(); |
[email protected] | 9b07185 | 2010-04-02 06:45:31 | [diff] [blame] | 213 | RegisterFunction<GetSubtreeBookmarkManagerFunction>(); |
[email protected] | 933ebbe | 2011-06-30 12:24:01 | [diff] [blame] | 214 | RegisterFunction<CanEditBookmarkManagerFunction>(); |
[email protected] | 9dd97bc | 2010-01-14 01:40:04 | [diff] [blame] | 215 | |
[email protected] | de768a83 | 2009-10-30 05:25:01 | [diff] [blame] | 216 | // History |
| 217 | RegisterFunction<AddUrlHistoryFunction>(); |
| 218 | RegisterFunction<DeleteAllHistoryFunction>(); |
| 219 | RegisterFunction<DeleteRangeHistoryFunction>(); |
| 220 | RegisterFunction<DeleteUrlHistoryFunction>(); |
| 221 | RegisterFunction<GetVisitsHistoryFunction>(); |
| 222 | RegisterFunction<SearchHistoryFunction>(); |
| 223 | |
[email protected] | f520541 | 2010-03-16 00:19:34 | [diff] [blame] | 224 | // Idle |
| 225 | RegisterFunction<ExtensionIdleQueryStateFunction>(); |
| 226 | |
[email protected] | 198bcfe | 2009-09-09 22:56:28 | [diff] [blame] | 227 | // I18N. |
[email protected] | 61424c06 | 2009-10-14 23:14:59 | [diff] [blame] | 228 | RegisterFunction<GetAcceptLanguagesFunction>(); |
[email protected] | 198bcfe | 2009-09-09 22:56:28 | [diff] [blame] | 229 | |
[email protected] | 381162b | 2010-01-28 17:29:35 | [diff] [blame] | 230 | // Processes. |
[email protected] | 8a661f8 | 2010-10-19 21:47:11 | [diff] [blame] | 231 | RegisterFunction<GetProcessIdForTabFunction>(); |
[email protected] | 381162b | 2010-01-28 17:29:35 | [diff] [blame] | 232 | |
[email protected] | 438772df | 2010-02-26 18:08:43 | [diff] [blame] | 233 | // Metrics. |
[email protected] | e93d2d0 | 2011-01-12 21:41:03 | [diff] [blame] | 234 | RegisterFunction<MetricsGetEnabledFunction>(); |
| 235 | RegisterFunction<MetricsSetEnabledFunction>(); |
[email protected] | cf25e4d | 2010-03-12 21:19:34 | [diff] [blame] | 236 | RegisterFunction<MetricsRecordUserActionFunction>(); |
| 237 | RegisterFunction<MetricsRecordValueFunction>(); |
| 238 | RegisterFunction<MetricsRecordPercentageFunction>(); |
| 239 | RegisterFunction<MetricsRecordCountFunction>(); |
| 240 | RegisterFunction<MetricsRecordSmallCountFunction>(); |
| 241 | RegisterFunction<MetricsRecordMediumCountFunction>(); |
| 242 | RegisterFunction<MetricsRecordTimeFunction>(); |
| 243 | RegisterFunction<MetricsRecordMediumTimeFunction>(); |
| 244 | RegisterFunction<MetricsRecordLongTimeFunction>(); |
[email protected] | 438772df | 2010-02-26 18:08:43 | [diff] [blame] | 245 | |
[email protected] | 17d40f0 | 2010-07-01 01:18:06 | [diff] [blame] | 246 | // RLZ. |
| 247 | #if defined(OS_WIN) |
| 248 | RegisterFunction<RlzRecordProductEventFunction>(); |
| 249 | RegisterFunction<RlzGetAccessPointRlzFunction>(); |
[email protected] | 3a612be | 2010-07-17 03:11:21 | [diff] [blame] | 250 | RegisterFunction<RlzSendFinancialPingFunction>(); |
[email protected] | 17d40f0 | 2010-07-01 01:18:06 | [diff] [blame] | 251 | RegisterFunction<RlzClearProductStateFunction>(); |
| 252 | #endif |
| 253 | |
[email protected] | 898bbd3 | 2010-05-18 18:52:29 | [diff] [blame] | 254 | // Cookies. |
| 255 | RegisterFunction<GetCookieFunction>(); |
| 256 | RegisterFunction<GetAllCookiesFunction>(); |
| 257 | RegisterFunction<SetCookieFunction>(); |
| 258 | RegisterFunction<RemoveCookieFunction>(); |
| 259 | RegisterFunction<GetAllCookieStoresFunction>(); |
| 260 | |
[email protected] | 25fd1b2e | 2009-08-17 20:57:14 | [diff] [blame] | 261 | // Test. |
[email protected] | 61424c06 | 2009-10-14 23:14:59 | [diff] [blame] | 262 | RegisterFunction<ExtensionTestPassFunction>(); |
| 263 | RegisterFunction<ExtensionTestFailFunction>(); |
| 264 | RegisterFunction<ExtensionTestLogFunction>(); |
[email protected] | d13950e | 2009-12-04 01:43:02 | [diff] [blame] | 265 | RegisterFunction<ExtensionTestQuotaResetFunction>(); |
[email protected] | db7331a | 2010-02-25 22:10:50 | [diff] [blame] | 266 | RegisterFunction<ExtensionTestCreateIncognitoTabFunction>(); |
[email protected] | 745feedb | 2010-08-02 04:08:07 | [diff] [blame] | 267 | RegisterFunction<ExtensionTestSendMessageFunction>(); |
[email protected] | 761e716 | 2010-10-18 19:26:39 | [diff] [blame] | 268 | RegisterFunction<ExtensionTestGetConfigFunction>(); |
[email protected] | 5cbe1e2 | 2010-01-30 01:18:56 | [diff] [blame] | 269 | |
| 270 | // Accessibility. |
| 271 | RegisterFunction<GetFocusedControlFunction>(); |
| 272 | RegisterFunction<SetAccessibilityEnabledFunction>(); |
[email protected] | 44625595 | 2010-03-17 20:41:58 | [diff] [blame] | 273 | |
[email protected] | 8abe0a3 | 2010-08-12 00:40:22 | [diff] [blame] | 274 | // Text-to-speech. |
[email protected] | c63f2b7 | 2011-07-07 05:25:00 | [diff] [blame] | 275 | RegisterFunction<ExtensionTtsEngineSendTtsEventFunction>(); |
| 276 | RegisterFunction<ExtensionTtsGetVoicesFunction>(); |
| 277 | RegisterFunction<ExtensionTtsIsSpeakingFunction>(); |
[email protected] | 8abe0a3 | 2010-08-12 00:40:22 | [diff] [blame] | 278 | RegisterFunction<ExtensionTtsSpeakFunction>(); |
| 279 | RegisterFunction<ExtensionTtsStopSpeakingFunction>(); |
[email protected] | 8abe0a3 | 2010-08-12 00:40:22 | [diff] [blame] | 280 | |
[email protected] | 2e3b520 | 2010-03-23 06:52:41 | [diff] [blame] | 281 | // Context Menus. |
| 282 | RegisterFunction<CreateContextMenuFunction>(); |
[email protected] | 66dbfb2c | 2010-05-12 20:20:15 | [diff] [blame] | 283 | RegisterFunction<UpdateContextMenuFunction>(); |
[email protected] | 2e3b520 | 2010-03-23 06:52:41 | [diff] [blame] | 284 | RegisterFunction<RemoveContextMenuFunction>(); |
[email protected] | 66dbfb2c | 2010-05-12 20:20:15 | [diff] [blame] | 285 | RegisterFunction<RemoveAllContextMenusFunction>(); |
[email protected] | 56ad379 | 2010-05-28 17:45:33 | [diff] [blame] | 286 | |
| 287 | // Omnibox. |
| 288 | RegisterFunction<OmniboxSendSuggestionsFunction>(); |
[email protected] | 1bead071 | 2010-11-27 17:41:53 | [diff] [blame] | 289 | RegisterFunction<OmniboxSetDefaultSuggestionFunction>(); |
[email protected] | a9c23a5 | 2010-08-04 09:13:44 | [diff] [blame] | 290 | |
[email protected] | 8b8e7c9 | 2010-08-19 18:05:56 | [diff] [blame] | 291 | // Sidebar. |
| 292 | RegisterFunction<CollapseSidebarFunction>(); |
| 293 | RegisterFunction<ExpandSidebarFunction>(); |
| 294 | RegisterFunction<GetStateSidebarFunction>(); |
| 295 | RegisterFunction<HideSidebarFunction>(); |
| 296 | RegisterFunction<NavigateSidebarFunction>(); |
| 297 | RegisterFunction<SetBadgeTextSidebarFunction>(); |
| 298 | RegisterFunction<SetIconSidebarFunction>(); |
| 299 | RegisterFunction<SetTitleSidebarFunction>(); |
| 300 | RegisterFunction<ShowSidebarFunction>(); |
[email protected] | d683385 | 2010-08-20 18:00:45 | [diff] [blame] | 301 | |
[email protected] | e06a1fe | 2011-09-29 21:20:44 | [diff] [blame] | 302 | // Speech input. |
| 303 | RegisterFunction<StartSpeechInputFunction>(); |
| 304 | RegisterFunction<StopSpeechInputFunction>(); |
| 305 | RegisterFunction<IsRecordingSpeechInputFunction>(); |
| 306 | |
[email protected] | d683385 | 2010-08-20 18:00:45 | [diff] [blame] | 307 | #if defined(TOOLKIT_VIEWS) |
| 308 | // Input. |
| 309 | RegisterFunction<SendKeyboardEventInputFunction>(); |
| 310 | #endif |
[email protected] | cffd789 | 2010-08-26 17:43:28 | [diff] [blame] | 311 | |
[email protected] | 2cc81d3 | 2011-10-04 17:03:18 | [diff] [blame] | 312 | #if defined(USE_VIRTUAL_KEYBOARD) |
[email protected] | bcde748 | 2011-05-23 19:29:12 | [diff] [blame] | 313 | RegisterFunction<HideKeyboardFunction>(); |
[email protected] | 3c8faef | 2011-06-09 22:56:51 | [diff] [blame] | 314 | RegisterFunction<SetKeyboardHeightFunction>(); |
[email protected] | bcde748 | 2011-05-23 19:29:12 | [diff] [blame] | 315 | #endif |
| 316 | |
[email protected] | 14da67b0 | 2011-08-02 05:49:13 | [diff] [blame] | 317 | #if defined(OS_CHROMEOS) |
[email protected] | 27072cad | 2011-05-09 19:46:40 | [diff] [blame] | 318 | // IME |
[email protected] | 14da67b0 | 2011-08-02 05:49:13 | [diff] [blame] | 319 | RegisterFunction<SetCompositionFunction>(); |
| 320 | RegisterFunction<ClearCompositionFunction>(); |
| 321 | RegisterFunction<CommitTextFunction>(); |
| 322 | RegisterFunction<SetCandidateWindowPropertiesFunction>(); |
| 323 | RegisterFunction<SetCandidatesFunction>(); |
| 324 | RegisterFunction<SetCursorPositionFunction>(); |
| 325 | RegisterFunction<SetMenuItemsFunction>(); |
| 326 | RegisterFunction<UpdateMenuItemsFunction>(); |
[email protected] | cd0b04c9 | 2011-09-08 05:18:06 | [diff] [blame] | 327 | |
| 328 | RegisterFunction<InputEventHandled>(); |
[email protected] | 14da67b0 | 2011-08-02 05:49:13 | [diff] [blame] | 329 | #if defined(TOUCH_UI) |
[email protected] | 27072cad | 2011-05-09 19:46:40 | [diff] [blame] | 330 | RegisterFunction<CandidateClickedInputUiFunction>(); |
| 331 | RegisterFunction<CursorUpInputUiFunction>(); |
| 332 | RegisterFunction<CursorDownInputUiFunction>(); |
| 333 | RegisterFunction<PageUpInputUiFunction>(); |
| 334 | RegisterFunction<PageDownInputUiFunction>(); |
| 335 | RegisterFunction<RegisterInputUiFunction>(); |
| 336 | RegisterFunction<PageUpInputUiFunction>(); |
| 337 | RegisterFunction<PageDownInputUiFunction>(); |
| 338 | #endif |
[email protected] | 14da67b0 | 2011-08-02 05:49:13 | [diff] [blame] | 339 | #endif |
[email protected] | 27072cad | 2011-05-09 19:46:40 | [diff] [blame] | 340 | |
[email protected] | cffd789 | 2010-08-26 17:43:28 | [diff] [blame] | 341 | // Management. |
| 342 | RegisterFunction<GetAllExtensionsFunction>(); |
[email protected] | e78543c | 2010-11-08 22:05:23 | [diff] [blame] | 343 | RegisterFunction<GetExtensionByIdFunction>(); |
[email protected] | 925a54d | 2011-07-29 17:21:00 | [diff] [blame] | 344 | RegisterFunction<GetPermissionWarningsByIdFunction>(); |
| 345 | RegisterFunction<GetPermissionWarningsByManifestFunction>(); |
[email protected] | e558ff8 | 2010-09-23 20:19:56 | [diff] [blame] | 346 | RegisterFunction<LaunchAppFunction>(); |
[email protected] | cffd789 | 2010-08-26 17:43:28 | [diff] [blame] | 347 | RegisterFunction<SetEnabledFunction>(); |
[email protected] | cffd789 | 2010-08-26 17:43:28 | [diff] [blame] | 348 | RegisterFunction<UninstallFunction>(); |
[email protected] | 63cda0c | 2010-09-01 04:41:23 | [diff] [blame] | 349 | |
[email protected] | a65882c | 2010-11-12 15:15:09 | [diff] [blame] | 350 | // Extension module. |
| 351 | RegisterFunction<SetUpdateUrlDataFunction>(); |
[email protected] | c7c401d | 2011-03-16 10:20:01 | [diff] [blame] | 352 | RegisterFunction<IsAllowedIncognitoAccessFunction>(); |
| 353 | RegisterFunction<IsAllowedFileSchemeAccessFunction>(); |
[email protected] | a65882c | 2010-11-12 15:15:09 | [diff] [blame] | 354 | |
[email protected] | 63cda0c | 2010-09-01 04:41:23 | [diff] [blame] | 355 | // WebstorePrivate. |
[email protected] | d688559 | 2010-10-11 19:38:24 | [diff] [blame] | 356 | RegisterFunction<GetBrowserLoginFunction>(); |
[email protected] | 63cda0c | 2010-09-01 04:41:23 | [diff] [blame] | 357 | RegisterFunction<GetStoreLoginFunction>(); |
| 358 | RegisterFunction<SetStoreLoginFunction>(); |
[email protected] | 5349ac6d | 2011-04-05 22:20:17 | [diff] [blame] | 359 | RegisterFunction<BeginInstallWithManifestFunction>(); |
[email protected] | b1f04cc | 2010-11-10 22:59:30 | [diff] [blame] | 360 | RegisterFunction<CompleteInstallFunction>(); |
[email protected] | c41fe66 | 2011-02-15 01:19:26 | [diff] [blame] | 361 | |
[email protected] | 557a51dd | 2011-07-26 12:17:11 | [diff] [blame] | 362 | // WebNavigation. |
| 363 | RegisterFunction<GetFrameFunction>(); |
[email protected] | 5a13067 | 2011-09-09 08:42:29 | [diff] [blame] | 364 | RegisterFunction<GetAllFramesFunction>(); |
[email protected] | 557a51dd | 2011-07-26 12:17:11 | [diff] [blame] | 365 | |
[email protected] | c41fe66 | 2011-02-15 01:19:26 | [diff] [blame] | 366 | // WebRequest. |
| 367 | RegisterFunction<WebRequestAddEventListener>(); |
[email protected] | 05cc4e7 | 2011-03-08 21:29:48 | [diff] [blame] | 368 | RegisterFunction<WebRequestEventHandled>(); |
[email protected] | e81d4d7 | 2011-09-29 16:54:31 | [diff] [blame] | 369 | RegisterFunction<WebRequestHandlerBehaviorChanged>(); |
[email protected] | 598bbcc | 2011-02-24 10:03:25 | [diff] [blame] | 370 | |
| 371 | // Preferences. |
| 372 | RegisterFunction<GetPreferenceFunction>(); |
| 373 | RegisterFunction<SetPreferenceFunction>(); |
[email protected] | c433bcb | 2011-02-24 13:10:27 | [diff] [blame] | 374 | RegisterFunction<ClearPreferenceFunction>(); |
[email protected] | 91ba331 | 2011-03-17 20:39:22 | [diff] [blame] | 375 | |
[email protected] | b6b805e9 | 2011-04-16 09:24:14 | [diff] [blame] | 376 | // ChromeOS-specific part of the API. |
| 377 | #if defined(OS_CHROMEOS) |
| 378 | // Device Customization. |
| 379 | RegisterFunction<GetChromeosInfoFunction>(); |
| 380 | |
| 381 | // FileBrowserPrivate functions. |
[email protected] | 94bda20 | 2011-04-18 23:31:00 | [diff] [blame] | 382 | RegisterFunction<CancelFileDialogFunction>(); |
[email protected] | b6b805e9 | 2011-04-16 09:24:14 | [diff] [blame] | 383 | RegisterFunction<ExecuteTasksFileBrowserFunction>(); |
[email protected] | 94bda20 | 2011-04-18 23:31:00 | [diff] [blame] | 384 | RegisterFunction<FileDialogStringsFunction>(); |
[email protected] | b6b805e9 | 2011-04-16 09:24:14 | [diff] [blame] | 385 | RegisterFunction<GetFileTasksFileBrowserFunction>(); |
[email protected] | 61334fa | 2011-06-16 01:01:40 | [diff] [blame] | 386 | RegisterFunction<GetVolumeMetadataFunction>(); |
[email protected] | b6b805e9 | 2011-04-16 09:24:14 | [diff] [blame] | 387 | RegisterFunction<RequestLocalFileSystemFunction>(); |
[email protected] | a6d0664 | 2011-06-02 05:55:23 | [diff] [blame] | 388 | RegisterFunction<AddFileWatchBrowserFunction>(); |
| 389 | RegisterFunction<RemoveFileWatchBrowserFunction>(); |
[email protected] | 9d4c2c5 | 2011-04-07 18:53:10 | [diff] [blame] | 390 | RegisterFunction<SelectFileFunction>(); |
| 391 | RegisterFunction<SelectFilesFunction>(); |
[email protected] | 928ae885 | 2011-07-26 01:15:03 | [diff] [blame] | 392 | RegisterFunction<AddMountFunction>(); |
| 393 | RegisterFunction<RemoveMountFunction>(); |
| 394 | RegisterFunction<GetMountPointsFunction>(); |
[email protected] | 694cafac | 2011-09-21 17:41:53 | [diff] [blame] | 395 | RegisterFunction<GetSizeStatsFunction>(); |
[email protected] | 3fd9004c | 2011-08-12 00:58:46 | [diff] [blame] | 396 | RegisterFunction<FormatDeviceFunction>(); |
[email protected] | 94bda20 | 2011-04-18 23:31:00 | [diff] [blame] | 397 | RegisterFunction<ViewFilesFunction>(); |
[email protected] | f1852b5 | 2011-05-17 04:58:08 | [diff] [blame] | 398 | |
[email protected] | ce980204 | 2011-05-27 10:11:40 | [diff] [blame] | 399 | // Mediaplayer |
| 400 | RegisterFunction<PlayAtMediaplayerFunction>(); |
| 401 | RegisterFunction<SetPlaybackErrorMediaplayerFunction>(); |
| 402 | RegisterFunction<GetPlaylistMediaplayerFunction>(); |
| 403 | RegisterFunction<TogglePlaylistPanelMediaplayerFunction>(); |
| 404 | RegisterFunction<ToggleFullscreenMediaplayerFunction>(); |
[email protected] | be5bd574 | 2011-07-14 07:21:01 | [diff] [blame] | 405 | |
| 406 | // InputMethod |
| 407 | RegisterFunction<GetInputMethodFunction>(); |
| 408 | |
[email protected] | f1852b5 | 2011-05-17 04:58:08 | [diff] [blame] | 409 | #if defined(TOUCH_UI) |
| 410 | // Input |
| 411 | RegisterFunction<SendHandwritingStrokeFunction>(); |
| 412 | RegisterFunction<CancelHandwritingStrokesFunction>(); |
| 413 | #endif |
[email protected] | 61b55b6 | 2011-03-24 09:03:10 | [diff] [blame] | 414 | #endif |
| 415 | |
[email protected] | c6e584c | 2011-05-18 11:58:44 | [diff] [blame] | 416 | // Websocket to TCP proxy. Currently noop on anything other than ChromeOS. |
| 417 | RegisterFunction<WebSocketProxyPrivateGetPassportForTCPFunction>(); |
[email protected] | 5ddffb8 | 2011-10-14 17:48:07 | [diff] [blame] | 418 | RegisterFunction<WebSocketProxyPrivateGetURLForTCPFunction>(); |
[email protected] | c6e584c | 2011-05-18 11:58:44 | [diff] [blame] | 419 | |
[email protected] | 91ba331 | 2011-03-17 20:39:22 | [diff] [blame] | 420 | // Debugger |
| 421 | RegisterFunction<AttachDebuggerFunction>(); |
| 422 | RegisterFunction<DetachDebuggerFunction>(); |
[email protected] | ac31010 | 2011-04-08 14:08:33 | [diff] [blame] | 423 | RegisterFunction<SendRequestDebuggerFunction>(); |
[email protected] | fa062426 | 2011-06-09 14:17:38 | [diff] [blame] | 424 | |
[email protected] | b7f853e28 | 2011-08-10 09:24:20 | [diff] [blame] | 425 | // Settings |
| 426 | RegisterFunction<GetSettingsFunction>(); |
| 427 | RegisterFunction<SetSettingsFunction>(); |
| 428 | RegisterFunction<RemoveSettingsFunction>(); |
| 429 | RegisterFunction<ClearSettingsFunction>(); |
| 430 | |
[email protected] | fa062426 | 2011-06-09 14:17:38 | [diff] [blame] | 431 | // Content settings. |
[email protected] | 49ba482 | 2011-06-15 18:41:56 | [diff] [blame] | 432 | RegisterFunction<GetResourceIdentifiersFunction>(); |
[email protected] | fa062426 | 2011-06-09 14:17:38 | [diff] [blame] | 433 | RegisterFunction<ClearContentSettingsFunction>(); |
| 434 | RegisterFunction<GetContentSettingFunction>(); |
| 435 | RegisterFunction<SetContentSettingFunction>(); |
[email protected] | c1d05aa | 2011-06-28 02:07:30 | [diff] [blame] | 436 | |
[email protected] | be9d9c8 | 2011-07-13 04:17:31 | [diff] [blame] | 437 | // ChromeAuth settings. |
| 438 | RegisterFunction<SetCloudPrintCredentialsFunction>(); |
| 439 | |
[email protected] | c1d05aa | 2011-06-28 02:07:30 | [diff] [blame] | 440 | // Experimental App API. |
| 441 | RegisterFunction<AppNotifyFunction>(); |
| 442 | RegisterFunction<AppClearAllNotificationsFunction>(); |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 443 | |
| 444 | // Permissions |
| 445 | RegisterFunction<ContainsPermissionsFunction>(); |
| 446 | RegisterFunction<GetAllPermissionsFunction>(); |
| 447 | RegisterFunction<RemovePermissionsFunction>(); |
| 448 | RegisterFunction<RequestPermissionsFunction>(); |
[email protected] | 21d7a4e30 | 2011-08-15 16:17:12 | [diff] [blame] | 449 | |
| 450 | // Downloads |
| 451 | RegisterFunction<DownloadsDownloadFunction>(); |
| 452 | RegisterFunction<DownloadsSearchFunction>(); |
| 453 | RegisterFunction<DownloadsPauseFunction>(); |
| 454 | RegisterFunction<DownloadsResumeFunction>(); |
| 455 | RegisterFunction<DownloadsCancelFunction>(); |
| 456 | RegisterFunction<DownloadsEraseFunction>(); |
| 457 | RegisterFunction<DownloadsSetDestinationFunction>(); |
| 458 | RegisterFunction<DownloadsAcceptDangerFunction>(); |
| 459 | RegisterFunction<DownloadsShowFunction>(); |
| 460 | RegisterFunction<DownloadsDragFunction>(); |
[email protected] | 3a605e8 | 2011-09-26 17:26:16 | [diff] [blame] | 461 | |
| 462 | // SavePage |
| 463 | RegisterFunction<SavePageAsMHTMLFunction>(); |
[email protected] | 6a16dc9b | 2011-10-17 18:28:16 | [diff] [blame] | 464 | |
| 465 | // Clipboard |
| 466 | RegisterFunction<WriteDataClipboardFunction>(); |
| 467 | RegisterFunction<ReadDataClipboardFunction>(); |
| 468 | RegisterFunction<GetAvailableMimeTypesClipboardFunction>(); |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 469 | } |
| 470 | |
[email protected] | b83e460 | 2009-05-15 22:58:33 | [diff] [blame] | 471 | void FactoryRegistry::GetAllNames(std::vector<std::string>* names) { |
| 472 | for (FactoryMap::iterator iter = factories_.begin(); |
| 473 | iter != factories_.end(); ++iter) { |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 474 | names->push_back(iter->first); |
| 475 | } |
| 476 | } |
| 477 | |
[email protected] | b83e460 | 2009-05-15 22:58:33 | [diff] [blame] | 478 | bool FactoryRegistry::OverrideFunction(const std::string& name, |
| 479 | ExtensionFunctionFactory factory) { |
| 480 | FactoryMap::iterator iter = factories_.find(name); |
| 481 | if (iter == factories_.end()) { |
| 482 | return false; |
| 483 | } else { |
| 484 | iter->second = factory; |
| 485 | return true; |
| 486 | } |
| 487 | } |
| 488 | |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 489 | ExtensionFunction* FactoryRegistry::NewFunction(const std::string& name) { |
| 490 | FactoryMap::iterator iter = factories_.find(name); |
| 491 | DCHECK(iter != factories_.end()); |
[email protected] | b83e460 | 2009-05-15 22:58:33 | [diff] [blame] | 492 | ExtensionFunction* function = iter->second(); |
[email protected] | 76a3db85 | 2009-07-24 02:14:56 | [diff] [blame] | 493 | function->set_name(name); |
[email protected] | b83e460 | 2009-05-15 22:58:33 | [diff] [blame] | 494 | return function; |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 495 | } |
| 496 | |
[email protected] | b83e460 | 2009-05-15 22:58:33 | [diff] [blame] | 497 | }; // namespace |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 498 | |
| 499 | // ExtensionFunctionDispatcher ------------------------------------------------- |
| 500 | |
| 501 | void ExtensionFunctionDispatcher::GetAllFunctionNames( |
| 502 | std::vector<std::string>* names) { |
[email protected] | 8e8bb6d | 2010-12-13 08:18:55 | [diff] [blame] | 503 | FactoryRegistry::GetInstance()->GetAllNames(names); |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 504 | } |
| 505 | |
[email protected] | b83e460 | 2009-05-15 22:58:33 | [diff] [blame] | 506 | bool ExtensionFunctionDispatcher::OverrideFunction( |
| 507 | const std::string& name, ExtensionFunctionFactory factory) { |
[email protected] | 8e8bb6d | 2010-12-13 08:18:55 | [diff] [blame] | 508 | return FactoryRegistry::GetInstance()->OverrideFunction(name, factory); |
[email protected] | b83e460 | 2009-05-15 22:58:33 | [diff] [blame] | 509 | } |
| 510 | |
| 511 | void ExtensionFunctionDispatcher::ResetFunctions() { |
[email protected] | 8e8bb6d | 2010-12-13 08:18:55 | [diff] [blame] | 512 | FactoryRegistry::GetInstance()->ResetFunctions(); |
[email protected] | b83e460 | 2009-05-15 22:58:33 | [diff] [blame] | 513 | } |
| 514 | |
[email protected] | c357acb4 | 2011-06-09 20:52:42 | [diff] [blame] | 515 | // static |
| 516 | void ExtensionFunctionDispatcher::DispatchOnIOThread( |
| 517 | const ExtensionInfoMap* extension_info_map, |
[email protected] | 67351452 | 2011-07-13 18:17:18 | [diff] [blame] | 518 | void* profile, |
[email protected] | c357acb4 | 2011-06-09 20:52:42 | [diff] [blame] | 519 | int render_process_id, |
| 520 | base::WeakPtr<ChromeRenderMessageFilter> ipc_sender, |
| 521 | int routing_id, |
| 522 | const ExtensionHostMsg_Request_Params& params) { |
| 523 | const Extension* extension = |
| 524 | extension_info_map->extensions().GetByURL(params.source_url); |
| 525 | |
[email protected] | 2cce7ae | 2011-10-23 15:54:36 | [diff] [blame] | 526 | if (!extension_info_map->IsExtensionInProcess(extension->id(), |
| 527 | render_process_id)) { |
[email protected] | 8add541 | 2011-10-01 21:02:14 | [diff] [blame] | 528 | // TODO(aa): Allow content scripts access to low-threat extension APIs. |
| 529 | // See: crbug.com/80308. |
| 530 | LOG(ERROR) << "Extension API called from non-extension process."; |
| 531 | SendAccessDenied(ipc_sender, routing_id, params.request_id); |
| 532 | return; |
| 533 | } |
| 534 | |
| 535 | scoped_refptr<ExtensionFunction> function(CreateExtensionFunction( |
| 536 | params, extension, profile, ipc_sender, routing_id)); |
[email protected] | c357acb4 | 2011-06-09 20:52:42 | [diff] [blame] | 537 | if (!function) |
| 538 | return; |
| 539 | |
| 540 | IOThreadExtensionFunction* function_io = |
| 541 | function->AsIOThreadExtensionFunction(); |
| 542 | if (!function_io) { |
| 543 | NOTREACHED(); |
| 544 | return; |
| 545 | } |
| 546 | function_io->set_ipc_sender(ipc_sender, routing_id); |
| 547 | function_io->set_extension_info_map(extension_info_map); |
| 548 | function->set_include_incognito( |
| 549 | extension_info_map->IsIncognitoEnabled(extension->id())); |
| 550 | function->Run(); |
| 551 | } |
| 552 | |
[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 553 | ExtensionFunctionDispatcher::ExtensionFunctionDispatcher(Profile* profile, |
| 554 | Delegate* delegate) |
| 555 | : profile_(profile), |
[email protected] | 55ce33071 | 2011-05-24 19:04:27 | [diff] [blame] | 556 | delegate_(delegate) { |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 557 | } |
| 558 | |
[email protected] | 32dda36 | 2009-06-05 19:07:01 | [diff] [blame] | 559 | ExtensionFunctionDispatcher::~ExtensionFunctionDispatcher() { |
[email protected] | 32dda36 | 2009-06-05 19:07:01 | [diff] [blame] | 560 | } |
| 561 | |
[email protected] | 0ec9203 | 2010-03-24 19:59:41 | [diff] [blame] | 562 | Browser* ExtensionFunctionDispatcher::GetCurrentBrowser( |
[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 563 | RenderViewHost* render_view_host, bool include_incognito) { |
[email protected] | 0ec9203 | 2010-03-24 19:59:41 | [diff] [blame] | 564 | Browser* browser = delegate_->GetBrowser(); |
[email protected] | 7eecaed5 | 2009-05-07 21:44:12 | [diff] [blame] | 565 | |
[email protected] | bc535ee5 | 2010-08-31 18:40:32 | [diff] [blame] | 566 | // If the delegate has an associated browser, that is always the right answer. |
| 567 | if (browser) |
| 568 | return browser; |
[email protected] | 9c45b718 | 2009-08-04 16:44:43 | [diff] [blame] | 569 | |
[email protected] | bc535ee5 | 2010-08-31 18:40:32 | [diff] [blame] | 570 | // Otherwise, try to default to a reasonable browser. If |include_incognito| |
| 571 | // is true, we will also search browsers in the incognito version of this |
| 572 | // profile. Note that the profile may already be incognito, in which case |
| 573 | // we will search the incognito version only, regardless of the value of |
| 574 | // |include_incognito|. |
[email protected] | 9b62ecf | 2011-07-27 20:23:08 | [diff] [blame] | 575 | Profile* profile = Profile::FromBrowserContext( |
| 576 | render_view_host->process()->browser_context()); |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 577 | browser = BrowserList::FindTabbedBrowser(profile, include_incognito); |
[email protected] | 0ec9203 | 2010-03-24 19:59:41 | [diff] [blame] | 578 | |
[email protected] | 0ec9203 | 2010-03-24 19:59:41 | [diff] [blame] | 579 | // NOTE(rafaelw): This can return NULL in some circumstances. In particular, |
[email protected] | 6d7a604 | 2010-08-12 20:12:42 | [diff] [blame] | 580 | // a background_page onload chrome.tabs api call can make it into here |
| 581 | // before the browser is sufficiently initialized to return here. |
[email protected] | 0ec9203 | 2010-03-24 19:59:41 | [diff] [blame] | 582 | // A similar situation may arise during shutdown. |
| 583 | // TODO(rafaelw): Delay creation of background_page until the browser |
| 584 | // is available. http://code.google.com/p/chromium/issues/detail?id=13284 |
| 585 | return browser; |
[email protected] | b2725756 | 2009-11-16 23:28:26 | [diff] [blame] | 586 | } |
| 587 | |
[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 588 | void ExtensionFunctionDispatcher::Dispatch( |
| 589 | const ExtensionHostMsg_Request_Params& params, |
| 590 | RenderViewHost* render_view_host) { |
[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 591 | ExtensionService* service = profile()->GetExtensionService(); |
[email protected] | 8add541 | 2011-10-01 21:02:14 | [diff] [blame] | 592 | ExtensionProcessManager* extension_process_manager = |
| 593 | profile()->GetExtensionProcessManager(); |
| 594 | if (!service || !extension_process_manager) |
[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 595 | return; |
| 596 | |
| 597 | if (!service->ExtensionBindingsAllowed(params.source_url)) { |
| 598 | LOG(ERROR) << "Extension bindings not allowed for URL: " |
| 599 | << params.source_url.spec(); |
[email protected] | c357acb4 | 2011-06-09 20:52:42 | [diff] [blame] | 600 | SendAccessDenied(render_view_host, render_view_host->routing_id(), |
| 601 | params.request_id); |
[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 602 | return; |
| 603 | } |
[email protected] | 8add541 | 2011-10-01 21:02:14 | [diff] [blame] | 604 | if (!extension_process_manager->AreBindingsEnabledForProcess( |
| 605 | render_view_host->process()->id())) { |
| 606 | // TODO(aa): Allow content scripts access to low-threat extension APIs. |
| 607 | // See: crbug.com/80308. |
| 608 | LOG(ERROR) << "Extension API called from non-extension process."; |
| 609 | SendAccessDenied(render_view_host, render_view_host->routing_id(), |
| 610 | params.request_id); |
| 611 | return; |
| 612 | } |
[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 613 | |
| 614 | // TODO(aa): When we allow content scripts to call extension APIs, we will |
| 615 | // have to pass the extension ID explicitly here, not use the source URL. |
| 616 | const Extension* extension = service->GetExtensionByURL(params.source_url); |
| 617 | if (!extension) |
| 618 | extension = service->GetExtensionByWebExtent(params.source_url); |
[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 619 | |
[email protected] | 8add541 | 2011-10-01 21:02:14 | [diff] [blame] | 620 | scoped_refptr<ExtensionFunction> function( |
| 621 | CreateExtensionFunction(params, extension, profile(), render_view_host, |
| 622 | render_view_host->routing_id())); |
[email protected] | c357acb4 | 2011-06-09 20:52:42 | [diff] [blame] | 623 | if (!function) |
[email protected] | f82d57b5 | 2011-04-27 19:13:17 | [diff] [blame] | 624 | return; |
[email protected] | f82d57b5 | 2011-04-27 19:13:17 | [diff] [blame] | 625 | |
[email protected] | a2aef2e | 2011-05-26 22:48:12 | [diff] [blame] | 626 | UIThreadExtensionFunction* function_ui = |
| 627 | function->AsUIThreadExtensionFunction(); |
| 628 | if (!function_ui) { |
| 629 | NOTREACHED(); |
| 630 | return; |
| 631 | } |
| 632 | function_ui->SetRenderViewHost(render_view_host); |
| 633 | function_ui->set_dispatcher(AsWeakPtr()); |
| 634 | function_ui->set_profile(profile_); |
[email protected] | 2a8f24e | 2010-11-03 21:37:05 | [diff] [blame] | 635 | function->set_include_incognito(service->CanCrossIncognito(extension)); |
[email protected] | cb0ce1e02 | 2010-03-10 19:54:41 | [diff] [blame] | 636 | |
[email protected] | d13950e | 2009-12-04 01:43:02 | [diff] [blame] | 637 | ExtensionsQuotaService* quota = service->quota_service(); |
[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 638 | if (quota->Assess(extension->id(), function, ¶ms.arguments, |
[email protected] | 8b8e7c9 | 2010-08-19 18:05:56 | [diff] [blame] | 639 | base::TimeTicks::Now())) { |
[email protected] | d070ec6 | 2010-07-27 21:28:26 | [diff] [blame] | 640 | // See crbug.com/39178. |
| 641 | ExternalProtocolHandler::PermitLaunchUrl(); |
| 642 | |
[email protected] | d13950e | 2009-12-04 01:43:02 | [diff] [blame] | 643 | function->Run(); |
| 644 | } else { |
[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 645 | render_view_host->Send(new ExtensionMsg_Response( |
| 646 | render_view_host->routing_id(), function->request_id(), false, |
[email protected] | 553602e1 | 2011-04-05 17:01:18 | [diff] [blame] | 647 | std::string(), QuotaLimitHeuristic::kGenericOverQuotaError)); |
[email protected] | d13950e | 2009-12-04 01:43:02 | [diff] [blame] | 648 | } |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 649 | } |
| 650 | |
[email protected] | c357acb4 | 2011-06-09 20:52:42 | [diff] [blame] | 651 | // static |
| 652 | ExtensionFunction* ExtensionFunctionDispatcher::CreateExtensionFunction( |
| 653 | const ExtensionHostMsg_Request_Params& params, |
| 654 | const Extension* extension, |
[email protected] | 67351452 | 2011-07-13 18:17:18 | [diff] [blame] | 655 | void* profile, |
[email protected] | c357acb4 | 2011-06-09 20:52:42 | [diff] [blame] | 656 | IPC::Message::Sender* ipc_sender, |
| 657 | int routing_id) { |
[email protected] | c357acb4 | 2011-06-09 20:52:42 | [diff] [blame] | 658 | if (!extension) { |
| 659 | LOG(ERROR) << "Extension does not exist for URL: " |
| 660 | << params.source_url.spec(); |
| 661 | SendAccessDenied(ipc_sender, routing_id, params.request_id); |
| 662 | return NULL; |
| 663 | } |
| 664 | |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 665 | if (!extension->HasAPIPermission(params.name)) { |
[email protected] | c357acb4 | 2011-06-09 20:52:42 | [diff] [blame] | 666 | LOG(ERROR) << "Extension " << extension->id() << " does not have " |
| 667 | << "permission to function: " << params.name; |
| 668 | SendAccessDenied(ipc_sender, routing_id, params.request_id); |
| 669 | return NULL; |
| 670 | } |
| 671 | |
| 672 | ExtensionFunction* function = |
| 673 | FactoryRegistry::GetInstance()->NewFunction(params.name); |
| 674 | function->SetArgs(¶ms.arguments); |
| 675 | function->set_source_url(params.source_url); |
| 676 | function->set_request_id(params.request_id); |
| 677 | function->set_has_callback(params.has_callback); |
| 678 | function->set_user_gesture(params.user_gesture); |
| 679 | function->set_extension(extension); |
[email protected] | 637bf32 | 2011-10-01 20:46:32 | [diff] [blame] | 680 | function->set_profile_id(profile); |
[email protected] | c357acb4 | 2011-06-09 20:52:42 | [diff] [blame] | 681 | return function; |
| 682 | } |
| 683 | |
| 684 | // static |
[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 685 | void ExtensionFunctionDispatcher::SendAccessDenied( |
[email protected] | c357acb4 | 2011-06-09 20:52:42 | [diff] [blame] | 686 | IPC::Message::Sender* ipc_sender, int routing_id, int request_id) { |
| 687 | ipc_sender->Send(new ExtensionMsg_Response( |
| 688 | routing_id, request_id, false, std::string(), |
[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 689 | "Access to extension API denied.")); |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 690 | } |