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