[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] | 0ec9203 | 2010-03-24 19:59:41 | [diff] [blame] | 14 | #include "chrome/browser/browser_list.h" |
[email protected] | a95631cb | 2009-12-10 01:59:11 | [diff] [blame] | 15 | #include "chrome/browser/browser_window.h" |
[email protected] | 912256b3 | 2009-09-18 09:47:35 | [diff] [blame] | 16 | #include "chrome/browser/extensions/execute_code_in_tab_function.h" |
[email protected] | 5cbe1e2 | 2010-01-30 01:18:56 | [diff] [blame] | 17 | #include "chrome/browser/extensions/extension_accessibility_api.h" |
[email protected] | 9dd97bc | 2010-01-14 01:40:04 | [diff] [blame] | 18 | #include "chrome/browser/extensions/extension_bookmark_manager_api.h" |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 19 | #include "chrome/browser/extensions/extension_bookmarks_module.h" |
[email protected] | ec9ac0df | 2009-10-01 18:06:47 | [diff] [blame] | 20 | #include "chrome/browser/extensions/extension_browser_actions_api.h" |
[email protected] | 44625595 | 2010-03-17 20:41:58 | [diff] [blame] | 21 | #include "chrome/browser/extensions/extension_clipboard_api.h" |
[email protected] | 2e3b520 | 2010-03-23 06:52:41 | [diff] [blame] | 22 | #include "chrome/browser/extensions/extension_context_menu_api.h" |
[email protected] | 898bbd3 | 2010-05-18 18:52:29 | [diff] [blame] | 23 | #include "chrome/browser/extensions/extension_cookies_api.h" |
[email protected] | 91ba331 | 2011-03-17 20:39:22 | [diff] [blame] | 24 | #include "chrome/browser/extensions/extension_debugger_api.h" |
[email protected] | 55d9bed | 2011-03-25 20:37:59 | [diff] [blame] | 25 | #include "chrome/browser/extensions/extension_file_browser_private_api.h" |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 26 | #include "chrome/browser/extensions/extension_function.h" |
[email protected] | de768a83 | 2009-10-30 05:25:01 | [diff] [blame] | 27 | #include "chrome/browser/extensions/extension_history_api.h" |
[email protected] | 2bb5130 | 2011-02-18 22:39:27 | [diff] [blame] | 28 | #include "chrome/browser/extensions/extension_i18n_api.h" |
[email protected] | 2f69b38 | 2011-02-19 00:34:25 | [diff] [blame] | 29 | #include "chrome/browser/extensions/extension_idle_api.h" |
[email protected] | f34e7963 | 2010-03-17 02:34:08 | [diff] [blame] | 30 | #include "chrome/browser/extensions/extension_infobar_module.h" |
[email protected] | cffd789 | 2010-08-26 17:43:28 | [diff] [blame] | 31 | #include "chrome/browser/extensions/extension_management_api.h" |
[email protected] | e916901c | 2009-05-07 00:14:31 | [diff] [blame] | 32 | #include "chrome/browser/extensions/extension_message_service.h" |
[email protected] | 438772df | 2010-02-26 18:08:43 | [diff] [blame] | 33 | #include "chrome/browser/extensions/extension_metrics_module.h" |
[email protected] | a65882c | 2010-11-12 15:15:09 | [diff] [blame] | 34 | #include "chrome/browser/extensions/extension_module.h" |
[email protected] | 56ad379 | 2010-05-28 17:45:33 | [diff] [blame] | 35 | #include "chrome/browser/extensions/extension_omnibox_api.h" |
[email protected] | f7f3a5f | 2009-05-01 22:02:34 | [diff] [blame] | 36 | #include "chrome/browser/extensions/extension_page_actions_module.h" |
[email protected] | 598bbcc | 2011-02-24 10:03:25 | [diff] [blame] | 37 | #include "chrome/browser/extensions/extension_preference_api.h" |
[email protected] | 4577622 | 2009-07-15 20:21:58 | [diff] [blame] | 38 | #include "chrome/browser/extensions/extension_process_manager.h" |
[email protected] | 381162b | 2010-01-28 17:29:35 | [diff] [blame] | 39 | #include "chrome/browser/extensions/extension_processes_api.h" |
[email protected] | a9c23a5 | 2010-08-04 09:13:44 | [diff] [blame] | 40 | #include "chrome/browser/extensions/extension_proxy_api.h" |
[email protected] | 17d40f0 | 2010-07-01 01:18:06 | [diff] [blame] | 41 | #include "chrome/browser/extensions/extension_rlz_module.h" |
[email protected] | 2f69b38 | 2011-02-19 00:34:25 | [diff] [blame] | 42 | #include "chrome/browser/extensions/extension_service.h" |
[email protected] | 8b8e7c9 | 2010-08-19 18:05:56 | [diff] [blame] | 43 | #include "chrome/browser/extensions/extension_sidebar_api.h" |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 44 | #include "chrome/browser/extensions/extension_tabs_module.h" |
[email protected] | 25fd1b2e | 2009-08-17 20:57:14 | [diff] [blame] | 45 | #include "chrome/browser/extensions/extension_test_api.h" |
[email protected] | 8abe0a3 | 2010-08-12 00:40:22 | [diff] [blame] | 46 | #include "chrome/browser/extensions/extension_tts_api.h" |
[email protected] | 8f9d4eb | 2011-02-05 01:39:10 | [diff] [blame] | 47 | #include "chrome/browser/extensions/extension_web_ui.h" |
[email protected] | c41fe66 | 2011-02-15 01:19:26 | [diff] [blame] | 48 | #include "chrome/browser/extensions/extension_webrequest_api.h" |
[email protected] | 63cda0c | 2010-09-01 04:41:23 | [diff] [blame] | 49 | #include "chrome/browser/extensions/extension_webstore_private_api.h" |
[email protected] | d13950e | 2009-12-04 01:43:02 | [diff] [blame] | 50 | #include "chrome/browser/extensions/extensions_quota_service.h" |
[email protected] | 2f69b38 | 2011-02-19 00:34:25 | [diff] [blame] | 51 | #include "chrome/browser/external_protocol_handler.h" |
[email protected] | c6602763 | 2010-12-22 21:26:30 | [diff] [blame] | 52 | #include "chrome/browser/metrics/user_metrics.h" |
[email protected] | 8ecad5e | 2010-12-02 21:18:33 | [diff] [blame] | 53 | #include "chrome/browser/profiles/profile.h" |
[email protected] | fd42ac30f | 2011-02-27 19:33:36 | [diff] [blame] | 54 | #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
| 55 | #include "chrome/browser/ui/webui/favicon_source.h" |
[email protected] | 44c49c9 | 2011-03-28 16:17:23 | [diff] [blame] | 56 | #include "chrome/common/extensions/extension_messages.h" |
[email protected] | 9c45b718 | 2009-08-04 16:44:43 | [diff] [blame] | 57 | #include "chrome/common/url_constants.h" |
[email protected] | 5de63471 | 2011-03-02 00:20:19 | [diff] [blame] | 58 | #include "content/browser/renderer_host/render_process_host.h" |
| 59 | #include "content/browser/renderer_host/render_view_host.h" |
[email protected] | f20d733 | 2011-03-08 21:11:53 | [diff] [blame] | 60 | #include "content/common/notification_service.h" |
[email protected] | 4dd5793 | 2011-03-17 06:06:12 | [diff] [blame] | 61 | #include "content/common/result_codes.h" |
[email protected] | 939856a | 2010-08-24 20:29:02 | [diff] [blame] | 62 | #include "third_party/skia/include/core/SkBitmap.h" |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 63 | |
[email protected] | 8f9d4eb | 2011-02-05 01:39:10 | [diff] [blame] | 64 | #if defined(TOOLKIT_VIEWS) |
| 65 | #include "chrome/browser/extensions/extension_input_api.h" |
| 66 | #endif |
[email protected] | d683385 | 2010-08-20 18:00:45 | [diff] [blame] | 67 | |
[email protected] | 61b55b6 | 2011-03-24 09:03:10 | [diff] [blame] | 68 | #if defined(OS_CHROMEOS) |
| 69 | #include "chrome/browser/extensions/extension_info_private_api_chromeos.h" |
| 70 | #endif |
| 71 | |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 72 | // FactoryRegistry ------------------------------------------------------------- |
| 73 | |
| 74 | namespace { |
| 75 | |
[email protected] | b83e460 | 2009-05-15 22:58:33 | [diff] [blame] | 76 | // Template for defining ExtensionFunctionFactory. |
| 77 | template<class T> |
| 78 | ExtensionFunction* NewExtensionFunction() { |
| 79 | return new T(); |
| 80 | } |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 81 | |
[email protected] | b83e460 | 2009-05-15 22:58:33 | [diff] [blame] | 82 | // Contains a list of all known extension functions and allows clients to |
| 83 | // create instances of them. |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 84 | class FactoryRegistry { |
| 85 | public: |
[email protected] | 8e8bb6d | 2010-12-13 08:18:55 | [diff] [blame] | 86 | static FactoryRegistry* GetInstance(); |
[email protected] | b83e460 | 2009-05-15 22:58:33 | [diff] [blame] | 87 | FactoryRegistry() { ResetFunctions(); } |
| 88 | |
| 89 | // Resets all functions to their default values. |
| 90 | void ResetFunctions(); |
| 91 | |
| 92 | // Adds all function names to 'names'. |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 93 | void GetAllNames(std::vector<std::string>* names); |
[email protected] | b83e460 | 2009-05-15 22:58:33 | [diff] [blame] | 94 | |
| 95 | // Allows overriding of specific functions (e.g. for testing). Functions |
| 96 | // must be previously registered. Returns true if successful. |
| 97 | bool OverrideFunction(const std::string& name, |
| 98 | ExtensionFunctionFactory factory); |
| 99 | |
| 100 | // Factory method for the ExtensionFunction registered as 'name'. |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 101 | ExtensionFunction* NewFunction(const std::string& name); |
| 102 | |
| 103 | private: |
[email protected] | 61424c06 | 2009-10-14 23:14:59 | [diff] [blame] | 104 | template<class T> |
| 105 | void RegisterFunction() { |
| 106 | factories_[T::function_name()] = &NewExtensionFunction<T>; |
| 107 | } |
| 108 | |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 109 | typedef std::map<std::string, ExtensionFunctionFactory> FactoryMap; |
| 110 | FactoryMap factories_; |
| 111 | }; |
| 112 | |
[email protected] | 8e8bb6d | 2010-12-13 08:18:55 | [diff] [blame] | 113 | FactoryRegistry* FactoryRegistry::GetInstance() { |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 114 | return Singleton<FactoryRegistry>::get(); |
| 115 | } |
| 116 | |
[email protected] | b83e460 | 2009-05-15 22:58:33 | [diff] [blame] | 117 | void FactoryRegistry::ResetFunctions() { |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 118 | // Register all functions here. |
| 119 | |
[email protected] | e515f5d | 2009-05-05 03:05:00 | [diff] [blame] | 120 | // Windows |
[email protected] | 61424c06 | 2009-10-14 23:14:59 | [diff] [blame] | 121 | RegisterFunction<GetWindowFunction>(); |
| 122 | RegisterFunction<GetCurrentWindowFunction>(); |
| 123 | RegisterFunction<GetLastFocusedWindowFunction>(); |
| 124 | RegisterFunction<GetAllWindowsFunction>(); |
| 125 | RegisterFunction<CreateWindowFunction>(); |
| 126 | RegisterFunction<UpdateWindowFunction>(); |
| 127 | RegisterFunction<RemoveWindowFunction>(); |
[email protected] | b83e460 | 2009-05-15 22:58:33 | [diff] [blame] | 128 | |
[email protected] | e515f5d | 2009-05-05 03:05:00 | [diff] [blame] | 129 | // Tabs |
[email protected] | 61424c06 | 2009-10-14 23:14:59 | [diff] [blame] | 130 | RegisterFunction<GetTabFunction>(); |
[email protected] | e3eafb29 | 2010-04-14 21:30:41 | [diff] [blame] | 131 | RegisterFunction<GetCurrentTabFunction>(); |
[email protected] | 61424c06 | 2009-10-14 23:14:59 | [diff] [blame] | 132 | RegisterFunction<GetSelectedTabFunction>(); |
| 133 | RegisterFunction<GetAllTabsInWindowFunction>(); |
| 134 | RegisterFunction<CreateTabFunction>(); |
| 135 | RegisterFunction<UpdateTabFunction>(); |
| 136 | RegisterFunction<MoveTabFunction>(); |
| 137 | RegisterFunction<RemoveTabFunction>(); |
| 138 | RegisterFunction<DetectTabLanguageFunction>(); |
| 139 | RegisterFunction<CaptureVisibleTabFunction>(); |
| 140 | RegisterFunction<TabsExecuteScriptFunction>(); |
| 141 | RegisterFunction<TabsInsertCSSFunction>(); |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 142 | |
[email protected] | f7f3a5f | 2009-05-01 22:02:34 | [diff] [blame] | 143 | // Page Actions. |
[email protected] | 61424c06 | 2009-10-14 23:14:59 | [diff] [blame] | 144 | RegisterFunction<EnablePageActionFunction>(); |
| 145 | RegisterFunction<DisablePageActionFunction>(); |
[email protected] | 744ef17 | 2009-10-16 21:53:46 | [diff] [blame] | 146 | RegisterFunction<PageActionShowFunction>(); |
| 147 | RegisterFunction<PageActionHideFunction>(); |
| 148 | RegisterFunction<PageActionSetIconFunction>(); |
| 149 | RegisterFunction<PageActionSetTitleFunction>(); |
[email protected] | e478d670 | 2010-01-28 00:10:29 | [diff] [blame] | 150 | RegisterFunction<PageActionSetPopupFunction>(); |
[email protected] | f7f3a5f | 2009-05-01 22:02:34 | [diff] [blame] | 151 | |
[email protected] | ec9ac0df | 2009-10-01 18:06:47 | [diff] [blame] | 152 | // Browser Actions. |
[email protected] | 61424c06 | 2009-10-14 23:14:59 | [diff] [blame] | 153 | RegisterFunction<BrowserActionSetIconFunction>(); |
[email protected] | 1288ba0 | 2009-10-15 00:02:24 | [diff] [blame] | 154 | RegisterFunction<BrowserActionSetTitleFunction>(); |
[email protected] | 61424c06 | 2009-10-14 23:14:59 | [diff] [blame] | 155 | RegisterFunction<BrowserActionSetBadgeTextFunction>(); |
| 156 | RegisterFunction<BrowserActionSetBadgeBackgroundColorFunction>(); |
[email protected] | 85ae959 | 2010-02-03 20:58:50 | [diff] [blame] | 157 | RegisterFunction<BrowserActionSetPopupFunction>(); |
[email protected] | ec9ac0df | 2009-10-01 18:06:47 | [diff] [blame] | 158 | |
[email protected] | f7f3a5f | 2009-05-01 22:02:34 | [diff] [blame] | 159 | // Bookmarks. |
[email protected] | 61424c06 | 2009-10-14 23:14:59 | [diff] [blame] | 160 | RegisterFunction<GetBookmarksFunction>(); |
| 161 | RegisterFunction<GetBookmarkChildrenFunction>(); |
[email protected] | a3c94c71 | 2009-12-18 19:23:55 | [diff] [blame] | 162 | RegisterFunction<GetBookmarkRecentFunction>(); |
[email protected] | 61424c06 | 2009-10-14 23:14:59 | [diff] [blame] | 163 | RegisterFunction<GetBookmarkTreeFunction>(); |
| 164 | RegisterFunction<SearchBookmarksFunction>(); |
| 165 | RegisterFunction<RemoveBookmarkFunction>(); |
| 166 | RegisterFunction<RemoveTreeBookmarkFunction>(); |
| 167 | RegisterFunction<CreateBookmarkFunction>(); |
| 168 | RegisterFunction<MoveBookmarkFunction>(); |
| 169 | RegisterFunction<UpdateBookmarkFunction>(); |
[email protected] | 9c45b718 | 2009-08-04 16:44:43 | [diff] [blame] | 170 | |
[email protected] | f34e7963 | 2010-03-17 02:34:08 | [diff] [blame] | 171 | // Infobars. |
| 172 | RegisterFunction<ShowInfoBarFunction>(); |
| 173 | |
[email protected] | 9dd97bc | 2010-01-14 01:40:04 | [diff] [blame] | 174 | // BookmarkManager |
| 175 | RegisterFunction<CopyBookmarkManagerFunction>(); |
| 176 | RegisterFunction<CutBookmarkManagerFunction>(); |
| 177 | RegisterFunction<PasteBookmarkManagerFunction>(); |
[email protected] | 03b3bbf | 2010-01-29 23:54:57 | [diff] [blame] | 178 | RegisterFunction<CanPasteBookmarkManagerFunction>(); |
[email protected] | cb6cf79 | 2010-01-28 00:04:56 | [diff] [blame] | 179 | RegisterFunction<ImportBookmarksFunction>(); |
| 180 | RegisterFunction<ExportBookmarksFunction>(); |
[email protected] | d406e2e | 2010-01-30 21:45:18 | [diff] [blame] | 181 | RegisterFunction<SortChildrenBookmarkManagerFunction>(); |
[email protected] | 9dd97bc | 2010-01-14 01:40:04 | [diff] [blame] | 182 | RegisterFunction<BookmarkManagerGetStringsFunction>(); |
[email protected] | ced90ae1 | 2010-02-20 02:06:16 | [diff] [blame] | 183 | RegisterFunction<StartDragBookmarkManagerFunction>(); |
| 184 | RegisterFunction<DropBookmarkManagerFunction>(); |
[email protected] | 9b07185 | 2010-04-02 06:45:31 | [diff] [blame] | 185 | RegisterFunction<GetSubtreeBookmarkManagerFunction>(); |
[email protected] | 9dd97bc | 2010-01-14 01:40:04 | [diff] [blame] | 186 | |
[email protected] | de768a83 | 2009-10-30 05:25:01 | [diff] [blame] | 187 | // History |
| 188 | RegisterFunction<AddUrlHistoryFunction>(); |
| 189 | RegisterFunction<DeleteAllHistoryFunction>(); |
| 190 | RegisterFunction<DeleteRangeHistoryFunction>(); |
| 191 | RegisterFunction<DeleteUrlHistoryFunction>(); |
| 192 | RegisterFunction<GetVisitsHistoryFunction>(); |
| 193 | RegisterFunction<SearchHistoryFunction>(); |
| 194 | |
[email protected] | f520541 | 2010-03-16 00:19:34 | [diff] [blame] | 195 | // Idle |
| 196 | RegisterFunction<ExtensionIdleQueryStateFunction>(); |
| 197 | |
[email protected] | 198bcfe | 2009-09-09 22:56:28 | [diff] [blame] | 198 | // I18N. |
[email protected] | 61424c06 | 2009-10-14 23:14:59 | [diff] [blame] | 199 | RegisterFunction<GetAcceptLanguagesFunction>(); |
[email protected] | 198bcfe | 2009-09-09 22:56:28 | [diff] [blame] | 200 | |
[email protected] | 381162b | 2010-01-28 17:29:35 | [diff] [blame] | 201 | // Processes. |
[email protected] | 8a661f8 | 2010-10-19 21:47:11 | [diff] [blame] | 202 | RegisterFunction<GetProcessIdForTabFunction>(); |
[email protected] | 381162b | 2010-01-28 17:29:35 | [diff] [blame] | 203 | |
[email protected] | 55d9bed | 2011-03-25 20:37:59 | [diff] [blame] | 204 | // Local filesystem. |
| 205 | RegisterFunction<RequestLocalFileSystemFunction>(); |
| 206 | |
[email protected] | 438772df | 2010-02-26 18:08:43 | [diff] [blame] | 207 | // Metrics. |
[email protected] | e93d2d0 | 2011-01-12 21:41:03 | [diff] [blame] | 208 | RegisterFunction<MetricsGetEnabledFunction>(); |
| 209 | RegisterFunction<MetricsSetEnabledFunction>(); |
[email protected] | cf25e4d | 2010-03-12 21:19:34 | [diff] [blame] | 210 | RegisterFunction<MetricsRecordUserActionFunction>(); |
| 211 | RegisterFunction<MetricsRecordValueFunction>(); |
| 212 | RegisterFunction<MetricsRecordPercentageFunction>(); |
| 213 | RegisterFunction<MetricsRecordCountFunction>(); |
| 214 | RegisterFunction<MetricsRecordSmallCountFunction>(); |
| 215 | RegisterFunction<MetricsRecordMediumCountFunction>(); |
| 216 | RegisterFunction<MetricsRecordTimeFunction>(); |
| 217 | RegisterFunction<MetricsRecordMediumTimeFunction>(); |
| 218 | RegisterFunction<MetricsRecordLongTimeFunction>(); |
[email protected] | 438772df | 2010-02-26 18:08:43 | [diff] [blame] | 219 | |
[email protected] | 17d40f0 | 2010-07-01 01:18:06 | [diff] [blame] | 220 | // RLZ. |
| 221 | #if defined(OS_WIN) |
| 222 | RegisterFunction<RlzRecordProductEventFunction>(); |
| 223 | RegisterFunction<RlzGetAccessPointRlzFunction>(); |
[email protected] | 3a612be | 2010-07-17 03:11:21 | [diff] [blame] | 224 | RegisterFunction<RlzSendFinancialPingFunction>(); |
[email protected] | 17d40f0 | 2010-07-01 01:18:06 | [diff] [blame] | 225 | RegisterFunction<RlzClearProductStateFunction>(); |
| 226 | #endif |
| 227 | |
[email protected] | 898bbd3 | 2010-05-18 18:52:29 | [diff] [blame] | 228 | // Cookies. |
| 229 | RegisterFunction<GetCookieFunction>(); |
| 230 | RegisterFunction<GetAllCookiesFunction>(); |
| 231 | RegisterFunction<SetCookieFunction>(); |
| 232 | RegisterFunction<RemoveCookieFunction>(); |
| 233 | RegisterFunction<GetAllCookieStoresFunction>(); |
| 234 | |
[email protected] | 25fd1b2e | 2009-08-17 20:57:14 | [diff] [blame] | 235 | // Test. |
[email protected] | 61424c06 | 2009-10-14 23:14:59 | [diff] [blame] | 236 | RegisterFunction<ExtensionTestPassFunction>(); |
| 237 | RegisterFunction<ExtensionTestFailFunction>(); |
| 238 | RegisterFunction<ExtensionTestLogFunction>(); |
[email protected] | d13950e | 2009-12-04 01:43:02 | [diff] [blame] | 239 | RegisterFunction<ExtensionTestQuotaResetFunction>(); |
[email protected] | db7331a | 2010-02-25 22:10:50 | [diff] [blame] | 240 | RegisterFunction<ExtensionTestCreateIncognitoTabFunction>(); |
[email protected] | 745feedb | 2010-08-02 04:08:07 | [diff] [blame] | 241 | RegisterFunction<ExtensionTestSendMessageFunction>(); |
[email protected] | 761e716 | 2010-10-18 19:26:39 | [diff] [blame] | 242 | RegisterFunction<ExtensionTestGetConfigFunction>(); |
[email protected] | 5cbe1e2 | 2010-01-30 01:18:56 | [diff] [blame] | 243 | |
| 244 | // Accessibility. |
| 245 | RegisterFunction<GetFocusedControlFunction>(); |
| 246 | RegisterFunction<SetAccessibilityEnabledFunction>(); |
[email protected] | 44625595 | 2010-03-17 20:41:58 | [diff] [blame] | 247 | |
[email protected] | 8abe0a3 | 2010-08-12 00:40:22 | [diff] [blame] | 248 | // Text-to-speech. |
| 249 | RegisterFunction<ExtensionTtsSpeakFunction>(); |
| 250 | RegisterFunction<ExtensionTtsStopSpeakingFunction>(); |
| 251 | RegisterFunction<ExtensionTtsIsSpeakingFunction>(); |
[email protected] | a4a38c1 | 2010-12-23 16:43:56 | [diff] [blame] | 252 | RegisterFunction<ExtensionTtsSpeakCompletedFunction>(); |
[email protected] | 8abe0a3 | 2010-08-12 00:40:22 | [diff] [blame] | 253 | |
[email protected] | 44625595 | 2010-03-17 20:41:58 | [diff] [blame] | 254 | // Clipboard. |
| 255 | RegisterFunction<ExecuteCopyClipboardFunction>(); |
| 256 | RegisterFunction<ExecuteCutClipboardFunction>(); |
| 257 | RegisterFunction<ExecutePasteClipboardFunction>(); |
[email protected] | 2e3b520 | 2010-03-23 06:52:41 | [diff] [blame] | 258 | |
| 259 | // Context Menus. |
| 260 | RegisterFunction<CreateContextMenuFunction>(); |
[email protected] | 66dbfb2c | 2010-05-12 20:20:15 | [diff] [blame] | 261 | RegisterFunction<UpdateContextMenuFunction>(); |
[email protected] | 2e3b520 | 2010-03-23 06:52:41 | [diff] [blame] | 262 | RegisterFunction<RemoveContextMenuFunction>(); |
[email protected] | 66dbfb2c | 2010-05-12 20:20:15 | [diff] [blame] | 263 | RegisterFunction<RemoveAllContextMenusFunction>(); |
[email protected] | 56ad379 | 2010-05-28 17:45:33 | [diff] [blame] | 264 | |
| 265 | // Omnibox. |
| 266 | RegisterFunction<OmniboxSendSuggestionsFunction>(); |
[email protected] | 1bead071 | 2010-11-27 17:41:53 | [diff] [blame] | 267 | RegisterFunction<OmniboxSetDefaultSuggestionFunction>(); |
[email protected] | a9c23a5 | 2010-08-04 09:13:44 | [diff] [blame] | 268 | |
[email protected] | 8b8e7c9 | 2010-08-19 18:05:56 | [diff] [blame] | 269 | // Sidebar. |
| 270 | RegisterFunction<CollapseSidebarFunction>(); |
| 271 | RegisterFunction<ExpandSidebarFunction>(); |
| 272 | RegisterFunction<GetStateSidebarFunction>(); |
| 273 | RegisterFunction<HideSidebarFunction>(); |
| 274 | RegisterFunction<NavigateSidebarFunction>(); |
| 275 | RegisterFunction<SetBadgeTextSidebarFunction>(); |
| 276 | RegisterFunction<SetIconSidebarFunction>(); |
| 277 | RegisterFunction<SetTitleSidebarFunction>(); |
| 278 | RegisterFunction<ShowSidebarFunction>(); |
[email protected] | d683385 | 2010-08-20 18:00:45 | [diff] [blame] | 279 | |
| 280 | #if defined(TOOLKIT_VIEWS) |
| 281 | // Input. |
| 282 | RegisterFunction<SendKeyboardEventInputFunction>(); |
| 283 | #endif |
[email protected] | cffd789 | 2010-08-26 17:43:28 | [diff] [blame] | 284 | |
| 285 | // Management. |
| 286 | RegisterFunction<GetAllExtensionsFunction>(); |
[email protected] | e78543c | 2010-11-08 22:05:23 | [diff] [blame] | 287 | RegisterFunction<GetExtensionByIdFunction>(); |
[email protected] | e558ff8 | 2010-09-23 20:19:56 | [diff] [blame] | 288 | RegisterFunction<LaunchAppFunction>(); |
[email protected] | cffd789 | 2010-08-26 17:43:28 | [diff] [blame] | 289 | RegisterFunction<SetEnabledFunction>(); |
[email protected] | cffd789 | 2010-08-26 17:43:28 | [diff] [blame] | 290 | RegisterFunction<UninstallFunction>(); |
[email protected] | 63cda0c | 2010-09-01 04:41:23 | [diff] [blame] | 291 | |
[email protected] | a65882c | 2010-11-12 15:15:09 | [diff] [blame] | 292 | // Extension module. |
| 293 | RegisterFunction<SetUpdateUrlDataFunction>(); |
[email protected] | c7c401d | 2011-03-16 10:20:01 | [diff] [blame] | 294 | RegisterFunction<IsAllowedIncognitoAccessFunction>(); |
| 295 | RegisterFunction<IsAllowedFileSchemeAccessFunction>(); |
[email protected] | a65882c | 2010-11-12 15:15:09 | [diff] [blame] | 296 | |
[email protected] | 63cda0c | 2010-09-01 04:41:23 | [diff] [blame] | 297 | // WebstorePrivate. |
[email protected] | d688559 | 2010-10-11 19:38:24 | [diff] [blame] | 298 | RegisterFunction<GetBrowserLoginFunction>(); |
[email protected] | 63cda0c | 2010-09-01 04:41:23 | [diff] [blame] | 299 | RegisterFunction<GetStoreLoginFunction>(); |
| 300 | RegisterFunction<SetStoreLoginFunction>(); |
[email protected] | d688559 | 2010-10-11 19:38:24 | [diff] [blame] | 301 | RegisterFunction<PromptBrowserLoginFunction>(); |
[email protected] | b1f04cc | 2010-11-10 22:59:30 | [diff] [blame] | 302 | RegisterFunction<BeginInstallFunction>(); |
| 303 | RegisterFunction<CompleteInstallFunction>(); |
[email protected] | c41fe66 | 2011-02-15 01:19:26 | [diff] [blame] | 304 | |
| 305 | // WebRequest. |
| 306 | RegisterFunction<WebRequestAddEventListener>(); |
[email protected] | 05cc4e7 | 2011-03-08 21:29:48 | [diff] [blame] | 307 | RegisterFunction<WebRequestEventHandled>(); |
[email protected] | 598bbcc | 2011-02-24 10:03:25 | [diff] [blame] | 308 | |
| 309 | // Preferences. |
| 310 | RegisterFunction<GetPreferenceFunction>(); |
| 311 | RegisterFunction<SetPreferenceFunction>(); |
[email protected] | c433bcb | 2011-02-24 13:10:27 | [diff] [blame] | 312 | RegisterFunction<ClearPreferenceFunction>(); |
[email protected] | 91ba331 | 2011-03-17 20:39:22 | [diff] [blame] | 313 | |
[email protected] | 61b55b6 | 2011-03-24 09:03:10 | [diff] [blame] | 314 | #if defined(OS_CHROMEOS) |
| 315 | // Device Customization. |
| 316 | RegisterFunction<GetChromeosInfoFunction>(); |
| 317 | #endif |
| 318 | |
[email protected] | 91ba331 | 2011-03-17 20:39:22 | [diff] [blame] | 319 | // Debugger |
| 320 | RegisterFunction<AttachDebuggerFunction>(); |
| 321 | RegisterFunction<DetachDebuggerFunction>(); |
[email protected] | ff31a8a | 2011-03-30 14:13:59 | [diff] [blame] | 322 | RegisterFunction<SendCommandDebuggerFunction>(); |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 323 | } |
| 324 | |
[email protected] | b83e460 | 2009-05-15 22:58:33 | [diff] [blame] | 325 | void FactoryRegistry::GetAllNames(std::vector<std::string>* names) { |
| 326 | for (FactoryMap::iterator iter = factories_.begin(); |
| 327 | iter != factories_.end(); ++iter) { |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 328 | names->push_back(iter->first); |
| 329 | } |
| 330 | } |
| 331 | |
[email protected] | b83e460 | 2009-05-15 22:58:33 | [diff] [blame] | 332 | bool FactoryRegistry::OverrideFunction(const std::string& name, |
| 333 | ExtensionFunctionFactory factory) { |
| 334 | FactoryMap::iterator iter = factories_.find(name); |
| 335 | if (iter == factories_.end()) { |
| 336 | return false; |
| 337 | } else { |
| 338 | iter->second = factory; |
| 339 | return true; |
| 340 | } |
| 341 | } |
| 342 | |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 343 | ExtensionFunction* FactoryRegistry::NewFunction(const std::string& name) { |
| 344 | FactoryMap::iterator iter = factories_.find(name); |
| 345 | DCHECK(iter != factories_.end()); |
[email protected] | b83e460 | 2009-05-15 22:58:33 | [diff] [blame] | 346 | ExtensionFunction* function = iter->second(); |
[email protected] | 76a3db85 | 2009-07-24 02:14:56 | [diff] [blame] | 347 | function->set_name(name); |
[email protected] | b83e460 | 2009-05-15 22:58:33 | [diff] [blame] | 348 | return function; |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 349 | } |
| 350 | |
[email protected] | b83e460 | 2009-05-15 22:58:33 | [diff] [blame] | 351 | }; // namespace |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 352 | |
| 353 | // ExtensionFunctionDispatcher ------------------------------------------------- |
| 354 | |
| 355 | void ExtensionFunctionDispatcher::GetAllFunctionNames( |
| 356 | std::vector<std::string>* names) { |
[email protected] | 8e8bb6d | 2010-12-13 08:18:55 | [diff] [blame] | 357 | FactoryRegistry::GetInstance()->GetAllNames(names); |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 358 | } |
| 359 | |
[email protected] | b83e460 | 2009-05-15 22:58:33 | [diff] [blame] | 360 | bool ExtensionFunctionDispatcher::OverrideFunction( |
| 361 | const std::string& name, ExtensionFunctionFactory factory) { |
[email protected] | 8e8bb6d | 2010-12-13 08:18:55 | [diff] [blame] | 362 | return FactoryRegistry::GetInstance()->OverrideFunction(name, factory); |
[email protected] | b83e460 | 2009-05-15 22:58:33 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | void ExtensionFunctionDispatcher::ResetFunctions() { |
[email protected] | 8e8bb6d | 2010-12-13 08:18:55 | [diff] [blame] | 366 | FactoryRegistry::GetInstance()->ResetFunctions(); |
[email protected] | b83e460 | 2009-05-15 22:58:33 | [diff] [blame] | 367 | } |
| 368 | |
[email protected] | a91afcb | 2010-03-25 21:15:02 | [diff] [blame] | 369 | ExtensionFunctionDispatcher* ExtensionFunctionDispatcher::Create( |
| 370 | RenderViewHost* render_view_host, |
| 371 | Delegate* delegate, |
| 372 | const GURL& url) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 373 | ExtensionService* service = |
| 374 | render_view_host->process()->profile()->GetExtensionService(); |
[email protected] | a91afcb | 2010-03-25 21:15:02 | [diff] [blame] | 375 | DCHECK(service); |
| 376 | |
[email protected] | 583d45c1 | 2010-08-31 02:48:12 | [diff] [blame] | 377 | if (!service->ExtensionBindingsAllowed(url)) |
| 378 | return NULL; |
| 379 | |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 380 | const Extension* extension = service->GetExtensionByURL(url); |
[email protected] | 583d45c1 | 2010-08-31 02:48:12 | [diff] [blame] | 381 | if (!extension) |
| 382 | extension = service->GetExtensionByWebExtent(url); |
| 383 | |
[email protected] | a91afcb | 2010-03-25 21:15:02 | [diff] [blame] | 384 | if (extension) |
| 385 | return new ExtensionFunctionDispatcher(render_view_host, delegate, |
| 386 | extension, url); |
| 387 | else |
| 388 | return NULL; |
| 389 | } |
| 390 | |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 391 | ExtensionFunctionDispatcher::ExtensionFunctionDispatcher( |
| 392 | RenderViewHost* render_view_host, |
[email protected] | 7eecaed5 | 2009-05-07 21:44:12 | [diff] [blame] | 393 | Delegate* delegate, |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 394 | const Extension* extension, |
[email protected] | 811bfe3 | 2009-07-01 08:46:25 | [diff] [blame] | 395 | const GURL& url) |
[email protected] | ebc1b68 | 2010-03-06 00:22:30 | [diff] [blame] | 396 | : profile_(render_view_host->process()->profile()), |
[email protected] | 68f0791 | 2010-03-05 18:33:58 | [diff] [blame] | 397 | render_view_host_(render_view_host), |
[email protected] | 7eecaed5 | 2009-05-07 21:44:12 | [diff] [blame] | 398 | delegate_(delegate), |
[email protected] | 811bfe3 | 2009-07-01 08:46:25 | [diff] [blame] | 399 | url_(url), |
[email protected] | 583d45c1 | 2010-08-31 02:48:12 | [diff] [blame] | 400 | extension_id_(extension->id()), |
[email protected] | 32dda36 | 2009-06-05 19:07:01 | [diff] [blame] | 401 | ALLOW_THIS_IN_INITIALIZER_LIST(peer_(new Peer(this))) { |
[email protected] | 9c45b718 | 2009-08-04 16:44:43 | [diff] [blame] | 402 | // TODO(erikkay) should we do something for these errors in Release? |
[email protected] | 3550635 | 2009-08-07 18:58:19 | [diff] [blame] | 403 | DCHECK(extension); |
[email protected] | 583d45c1 | 2010-08-31 02:48:12 | [diff] [blame] | 404 | DCHECK(url.SchemeIs(chrome::kExtensionScheme) || |
| 405 | extension->location() == Extension::COMPONENT); |
[email protected] | 9c45b718 | 2009-08-04 16:44:43 | [diff] [blame] | 406 | |
[email protected] | 4577622 | 2009-07-15 20:21:58 | [diff] [blame] | 407 | // Notify the ExtensionProcessManager that the view was created. |
| 408 | ExtensionProcessManager* epm = profile()->GetExtensionProcessManager(); |
| 409 | epm->RegisterExtensionProcess(extension_id(), |
[email protected] | 76543b9 | 2009-08-31 17:27:45 | [diff] [blame] | 410 | render_view_host->process()->id()); |
[email protected] | 3550635 | 2009-08-07 18:58:19 | [diff] [blame] | 411 | |
[email protected] | 584b8e3f | 2010-04-10 00:23:37 | [diff] [blame] | 412 | // If the extension has permission to load chrome://favicon/ resources we need |
[email protected] | 16835e6 | 2011-03-16 14:13:08 | [diff] [blame] | 413 | // to make sure that the FaviconSource is registered with the |
[email protected] | 584b8e3f | 2010-04-10 00:23:37 | [diff] [blame] | 414 | // ChromeURLDataManager. |
[email protected] | f16039d2 | 2011-03-16 18:54:05 | [diff] [blame] | 415 | if (extension->HasHostPermission(GURL(chrome::kChromeUIFaviconURL))) { |
[email protected] | 16835e6 | 2011-03-16 14:13:08 | [diff] [blame] | 416 | FaviconSource* favicon_source = new FaviconSource(profile_); |
[email protected] | 248ce19 | 2011-02-10 15:26:34 | [diff] [blame] | 417 | profile_->GetChromeURLDataManager()->AddDataSource(favicon_source); |
[email protected] | 584b8e3f | 2010-04-10 00:23:37 | [diff] [blame] | 418 | } |
| 419 | |
[email protected] | 3550635 | 2009-08-07 18:58:19 | [diff] [blame] | 420 | // Update the extension permissions. Doing this each time we create an EFD |
| 421 | // ensures that new processes are informed of permissions for newly installed |
| 422 | // extensions. |
[email protected] | 44c49c9 | 2011-03-28 16:17:23 | [diff] [blame] | 423 | render_view_host->Send(new ExtensionMsg_SetAPIPermissions( |
[email protected] | 3550635 | 2009-08-07 18:58:19 | [diff] [blame] | 424 | extension->id(), extension->api_permissions())); |
[email protected] | 44c49c9 | 2011-03-28 16:17:23 | [diff] [blame] | 425 | render_view_host->Send(new ExtensionMsg_SetHostPermissions( |
[email protected] | cccf9093 | 2009-08-23 17:56:25 | [diff] [blame] | 426 | extension->url(), extension->host_permissions())); |
[email protected] | 68f0791 | 2010-03-05 18:33:58 | [diff] [blame] | 427 | |
| 428 | NotificationService::current()->Notify( |
| 429 | NotificationType::EXTENSION_FUNCTION_DISPATCHER_CREATED, |
| 430 | Source<Profile>(profile_), |
| 431 | Details<ExtensionFunctionDispatcher>(this)); |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 432 | } |
| 433 | |
[email protected] | 32dda36 | 2009-06-05 19:07:01 | [diff] [blame] | 434 | ExtensionFunctionDispatcher::~ExtensionFunctionDispatcher() { |
| 435 | peer_->dispatcher_ = NULL; |
[email protected] | 68f0791 | 2010-03-05 18:33:58 | [diff] [blame] | 436 | |
| 437 | NotificationService::current()->Notify( |
| 438 | NotificationType::EXTENSION_FUNCTION_DISPATCHER_DESTROYED, |
| 439 | Source<Profile>(profile_), |
| 440 | Details<ExtensionFunctionDispatcher>(this)); |
[email protected] | 32dda36 | 2009-06-05 19:07:01 | [diff] [blame] | 441 | } |
| 442 | |
[email protected] | 0ec9203 | 2010-03-24 19:59:41 | [diff] [blame] | 443 | Browser* ExtensionFunctionDispatcher::GetCurrentBrowser( |
| 444 | bool include_incognito) { |
| 445 | Browser* browser = delegate_->GetBrowser(); |
[email protected] | 7eecaed5 | 2009-05-07 21:44:12 | [diff] [blame] | 446 | |
[email protected] | bc535ee5 | 2010-08-31 18:40:32 | [diff] [blame] | 447 | // If the delegate has an associated browser, that is always the right answer. |
| 448 | if (browser) |
| 449 | return browser; |
[email protected] | 9c45b718 | 2009-08-04 16:44:43 | [diff] [blame] | 450 | |
[email protected] | bc535ee5 | 2010-08-31 18:40:32 | [diff] [blame] | 451 | // Otherwise, try to default to a reasonable browser. If |include_incognito| |
| 452 | // is true, we will also search browsers in the incognito version of this |
| 453 | // profile. Note that the profile may already be incognito, in which case |
| 454 | // we will search the incognito version only, regardless of the value of |
| 455 | // |include_incognito|. |
[email protected] | 0ec9203 | 2010-03-24 19:59:41 | [diff] [blame] | 456 | Profile* profile = render_view_host()->process()->profile(); |
[email protected] | aa916d57 | 2010-08-13 02:59:31 | [diff] [blame] | 457 | browser = BrowserList::FindBrowserWithType(profile, Browser::TYPE_NORMAL, |
[email protected] | 62b0b53 | 2010-03-26 22:44:31 | [diff] [blame] | 458 | include_incognito); |
[email protected] | 0ec9203 | 2010-03-24 19:59:41 | [diff] [blame] | 459 | |
[email protected] | 0ec9203 | 2010-03-24 19:59:41 | [diff] [blame] | 460 | // NOTE(rafaelw): This can return NULL in some circumstances. In particular, |
[email protected] | 6d7a604 | 2010-08-12 20:12:42 | [diff] [blame] | 461 | // a background_page onload chrome.tabs api call can make it into here |
| 462 | // before the browser is sufficiently initialized to return here. |
[email protected] | 0ec9203 | 2010-03-24 19:59:41 | [diff] [blame] | 463 | // A similar situation may arise during shutdown. |
| 464 | // TODO(rafaelw): Delay creation of background_page until the browser |
| 465 | // is available. http://code.google.com/p/chromium/issues/detail?id=13284 |
| 466 | return browser; |
[email protected] | b2725756 | 2009-11-16 23:28:26 | [diff] [blame] | 467 | } |
| 468 | |
[email protected] | 8b8e7c9 | 2010-08-19 18:05:56 | [diff] [blame] | 469 | void ExtensionFunctionDispatcher::HandleRequest( |
[email protected] | 44c49c9 | 2011-03-28 16:17:23 | [diff] [blame] | 470 | const ExtensionHostMsg_DomMessage_Params& params) { |
[email protected] | 32dda36 | 2009-06-05 19:07:01 | [diff] [blame] | 471 | scoped_refptr<ExtensionFunction> function( |
[email protected] | 8e8bb6d | 2010-12-13 08:18:55 | [diff] [blame] | 472 | FactoryRegistry::GetInstance()->NewFunction(params.name)); |
[email protected] | 32dda36 | 2009-06-05 19:07:01 | [diff] [blame] | 473 | function->set_dispatcher_peer(peer_); |
[email protected] | a7664e1 | 2010-04-08 20:37:43 | [diff] [blame] | 474 | function->set_profile(profile_); |
| 475 | function->set_extension_id(extension_id()); |
[email protected] | 8b8e7c9 | 2010-08-19 18:05:56 | [diff] [blame] | 476 | function->SetArgs(¶ms.arguments); |
| 477 | function->set_source_url(params.source_url); |
| 478 | function->set_request_id(params.request_id); |
| 479 | function->set_has_callback(params.has_callback); |
| 480 | function->set_user_gesture(params.user_gesture); |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 481 | ExtensionService* service = profile()->GetExtensionService(); |
[email protected] | d13950e | 2009-12-04 01:43:02 | [diff] [blame] | 482 | DCHECK(service); |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 483 | const Extension* extension = service->GetExtensionById(extension_id(), false); |
[email protected] | cb0ce1e02 | 2010-03-10 19:54:41 | [diff] [blame] | 484 | DCHECK(extension); |
[email protected] | 2a8f24e | 2010-11-03 21:37:05 | [diff] [blame] | 485 | function->set_include_incognito(service->CanCrossIncognito(extension)); |
[email protected] | cb0ce1e02 | 2010-03-10 19:54:41 | [diff] [blame] | 486 | |
[email protected] | 583d45c1 | 2010-08-31 02:48:12 | [diff] [blame] | 487 | if (!service->ExtensionBindingsAllowed(function->source_url()) || |
[email protected] | 246c05f | 2010-09-10 09:12:11 | [diff] [blame] | 488 | !extension->HasApiPermission(function->name())) { |
[email protected] | 553602e1 | 2011-04-05 17:01:18 | [diff] [blame^] | 489 | render_view_host_->Send(new ExtensionMsg_Response( |
| 490 | render_view_host_->routing_id(), function->request_id(), false, |
| 491 | std::string(), "Access to extension API denied.")); |
[email protected] | 583d45c1 | 2010-08-31 02:48:12 | [diff] [blame] | 492 | return; |
| 493 | } |
| 494 | |
[email protected] | d13950e | 2009-12-04 01:43:02 | [diff] [blame] | 495 | ExtensionsQuotaService* quota = service->quota_service(); |
[email protected] | 8b8e7c9 | 2010-08-19 18:05:56 | [diff] [blame] | 496 | if (quota->Assess(extension_id(), function, ¶ms.arguments, |
| 497 | base::TimeTicks::Now())) { |
[email protected] | d070ec6 | 2010-07-27 21:28:26 | [diff] [blame] | 498 | // See crbug.com/39178. |
| 499 | ExternalProtocolHandler::PermitLaunchUrl(); |
| 500 | |
[email protected] | d13950e | 2009-12-04 01:43:02 | [diff] [blame] | 501 | function->Run(); |
| 502 | } else { |
[email protected] | 553602e1 | 2011-04-05 17:01:18 | [diff] [blame^] | 503 | render_view_host_->Send(new ExtensionMsg_Response( |
| 504 | render_view_host_->routing_id(), function->request_id(), false, |
| 505 | std::string(), QuotaLimitHeuristic::kGenericOverQuotaError)); |
[email protected] | d13950e | 2009-12-04 01:43:02 | [diff] [blame] | 506 | } |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 507 | } |
| 508 | |
[email protected] | c661918 | 2009-05-12 14:59:32 | [diff] [blame] | 509 | void ExtensionFunctionDispatcher::SendResponse(ExtensionFunction* function, |
| 510 | bool success) { |
[email protected] | 553602e1 | 2011-04-05 17:01:18 | [diff] [blame^] | 511 | render_view_host_->Send(new ExtensionMsg_Response( |
| 512 | render_view_host_->routing_id(), function->request_id(), success, |
| 513 | function->GetResult(), function->GetError())); |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | void ExtensionFunctionDispatcher::HandleBadMessage(ExtensionFunction* api) { |
[email protected] | 25fd1b2e | 2009-08-17 20:57:14 | [diff] [blame] | 517 | LOG(ERROR) << "bad extension message " << |
[email protected] | 76543b9 | 2009-08-31 17:27:45 | [diff] [blame] | 518 | api->name() << |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 519 | " : terminating renderer."; |
| 520 | if (RenderProcessHost::run_renderer_in_process()) { |
| 521 | // In single process mode it is better if we don't suicide but just crash. |
| 522 | CHECK(false); |
| 523 | } else { |
| 524 | NOTREACHED(); |
[email protected] | c6602763 | 2010-12-22 21:26:30 | [diff] [blame] | 525 | UserMetrics::RecordAction(UserMetricsAction("BadMessageTerminate_EFD")); |
[email protected] | 201b273 | 2009-11-13 18:57:46 | [diff] [blame] | 526 | base::KillProcess(render_view_host_->process()->GetHandle(), |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 527 | ResultCodes::KILLED_BAD_MESSAGE, false); |
| 528 | } |
| 529 | } |
| 530 | |
| 531 | Profile* ExtensionFunctionDispatcher::profile() { |
[email protected] | 68f0791 | 2010-03-05 18:33:58 | [diff] [blame] | 532 | return profile_; |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 533 | } |