blob: c664dc2638e0e0b2f5e0f91cdcdbf82902ca96f0 [file] [log] [blame]
[email protected]64c820732012-01-05 20:50:341// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]bfdffe2b2009-04-24 22:05:352// 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]745feedb2010-08-02 04:08:077#include <map>
8
[email protected]efd75992011-12-15 22:42:429#include "base/json/json_value_serializer.h"
[email protected]3b63f8f42011-03-28 01:54:1510#include "base/memory/ref_counted.h"
11#include "base/memory/singleton.h"
[email protected]bfdffe2b2009-04-24 22:05:3512#include "base/process_util.h"
[email protected]bfdffe2b2009-04-24 22:05:3513#include "base/values.h"
[email protected]17d40f02010-07-01 01:18:0614#include "build/build_config.h"
[email protected]a692a952011-11-28 08:23:5415#include "chrome/browser/accessibility/accessibility_extension_api.h"
[email protected]23d5f172011-10-25 05:49:5316#include "chrome/browser/bookmarks/bookmark_extension_api.h"
17#include "chrome/browser/bookmarks/bookmark_manager_extension_api.h"
[email protected]cdcf60242011-11-04 15:53:4318#include "chrome/browser/download/download_extension_api.h"
[email protected]b7309da2012-01-23 16:03:5119#include "chrome/browser/extensions/api/app/app_api.h"
[email protected]8ef650e2012-02-08 10:20:5920#include "chrome/browser/extensions/api/declarative/declarative_api.h"
[email protected]14a38f3f2012-01-12 16:16:5121#include "chrome/browser/extensions/api/dns/dns_api.h"
[email protected]76aeb1772012-01-20 22:14:1622#include "chrome/browser/extensions/api/permissions/permissions_api.h"
[email protected]223a93f12012-01-18 21:17:5323#include "chrome/browser/extensions/api/serial/serial_api.h"
[email protected]55afeb52011-12-06 00:15:3924#include "chrome/browser/extensions/api/socket/socket_api.h"
[email protected]6e672df2012-01-25 10:39:4725#include "chrome/browser/extensions/api/webrequest/webrequest_api.h"
[email protected]912256b32009-09-18 09:47:3526#include "chrome/browser/extensions/execute_code_in_tab_function.h"
[email protected]efd75992011-12-15 22:42:4227#include "chrome/browser/extensions/extension_activity_log.h"
[email protected]ec9ac0df2009-10-01 18:06:4728#include "chrome/browser/extensions/extension_browser_actions_api.h"
[email protected]8f5090a52012-02-10 11:36:2129#include "chrome/browser/extensions/extension_browsing_data_api.h"
[email protected]cdcf60242011-11-04 15:53:4330#include "chrome/browser/extensions/extension_chrome_auth_private_api.h"
[email protected]fa0624262011-06-09 14:17:3831#include "chrome/browser/extensions/extension_content_settings_api.h"
[email protected]2e3b5202010-03-23 06:52:4132#include "chrome/browser/extensions/extension_context_menu_api.h"
[email protected]898bbd32010-05-18 18:52:2933#include "chrome/browser/extensions/extension_cookies_api.h"
[email protected]91ba3312011-03-17 20:39:2234#include "chrome/browser/extensions/extension_debugger_api.h"
[email protected]bfdffe2b2009-04-24 22:05:3535#include "chrome/browser/extensions/extension_function.h"
[email protected]2bb51302011-02-18 22:39:2736#include "chrome/browser/extensions/extension_i18n_api.h"
[email protected]2f69b382011-02-19 00:34:2537#include "chrome/browser/extensions/extension_idle_api.h"
[email protected]cffd7892010-08-26 17:43:2838#include "chrome/browser/extensions/extension_management_api.h"
[email protected]438772df2010-02-26 18:08:4339#include "chrome/browser/extensions/extension_metrics_module.h"
[email protected]a65882c2010-11-12 15:15:0940#include "chrome/browser/extensions/extension_module.h"
[email protected]56ad3792010-05-28 17:45:3341#include "chrome/browser/extensions/extension_omnibox_api.h"
[email protected]f7f3a5f2009-05-01 22:02:3442#include "chrome/browser/extensions/extension_page_actions_module.h"
[email protected]9e4430f2011-11-28 07:43:2943#include "chrome/browser/extensions/extension_page_capture_api.h"
[email protected]598bbcc2011-02-24 10:03:2544#include "chrome/browser/extensions/extension_preference_api.h"
[email protected]381162b2010-01-28 17:29:3545#include "chrome/browser/extensions/extension_processes_api.h"
[email protected]a9c23a52010-08-04 09:13:4446#include "chrome/browser/extensions/extension_proxy_api.h"
[email protected]2f69b382011-02-19 00:34:2547#include "chrome/browser/extensions/extension_service.h"
[email protected]bfdffe2b2009-04-24 22:05:3548#include "chrome/browser/extensions/extension_tabs_module.h"
[email protected]25fd1b2e2009-08-17 20:57:1449#include "chrome/browser/extensions/extension_test_api.h"
[email protected]8abe0a32010-08-12 00:40:2250#include "chrome/browser/extensions/extension_tts_api.h"
[email protected]c63f2b72011-07-07 05:25:0051#include "chrome/browser/extensions/extension_tts_engine_api.h"
[email protected]c6e584c2011-05-18 11:58:4452#include "chrome/browser/extensions/extension_web_socket_proxy_private_api.h"
[email protected]8f9d4eb2011-02-05 01:39:1053#include "chrome/browser/extensions/extension_web_ui.h"
[email protected]557a51dd2011-07-26 12:17:1154#include "chrome/browser/extensions/extension_webnavigation_api.h"
[email protected]63cda0c2010-09-01 04:41:2355#include "chrome/browser/extensions/extension_webstore_private_api.h"
[email protected]d13950e2009-12-04 01:43:0256#include "chrome/browser/extensions/extensions_quota_service.h"
[email protected]a4f98922011-12-06 11:32:2357#include "chrome/browser/extensions/system/system_api.h"
[email protected]83820d42011-11-12 22:03:1158#include "chrome/browser/extensions/process_map.h"
[email protected]ae7f1ba2011-11-28 23:07:3159#include "chrome/browser/extensions/settings/settings_api.h"
[email protected]ed2b1002011-05-25 14:12:1060#include "chrome/browser/external_protocol/external_protocol_handler.h"
[email protected]d2e6bd62011-10-24 20:29:0761#include "chrome/browser/history/history_extension_api.h"
[email protected]5eddc3e2011-10-26 04:33:3162#include "chrome/browser/history/top_sites_extension_api.h"
[email protected]cdcf60242011-11-04 15:53:4363#include "chrome/browser/infobars/infobar_extension_api.h"
[email protected]8ecad5e2010-12-02 21:18:3364#include "chrome/browser/profiles/profile.h"
[email protected]c357acb42011-06-09 20:52:4265#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
[email protected]792556c2011-10-25 05:01:0766#include "chrome/browser/rlz/rlz_extension_api.h"
[email protected]b9971dc2011-11-11 15:50:4367#include "chrome/browser/speech/speech_input_extension_api.h"
[email protected]71b73f02011-04-06 15:57:2968#include "chrome/browser/ui/browser_list.h"
[email protected]00070c732011-04-09 15:31:3369#include "chrome/browser/ui/browser_window.h"
[email protected]83820d42011-11-12 22:03:1170#include "chrome/common/extensions/api/extension_api.h"
[email protected]44c49c92011-03-28 16:17:2371#include "chrome/common/extensions/extension_messages.h"
[email protected]615d88f2011-12-13 01:47:4472#include "chrome/common/extensions/extension_set.h"
[email protected]9c45b7182009-08-04 16:44:4373#include "chrome/common/url_constants.h"
[email protected]5de634712011-03-02 00:20:1974#include "content/browser/renderer_host/render_view_host.h"
[email protected]c333e792012-01-06 16:57:3975#include "content/public/browser/render_process_host.h"
[email protected]f82d57b52011-04-27 19:13:1776#include "ipc/ipc_message.h"
77#include "ipc/ipc_message_macros.h"
[email protected]939856a2010-08-24 20:29:0278#include "third_party/skia/include/core/SkBitmap.h"
[email protected]615d88f2011-12-13 01:47:4479#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h"
[email protected]bfdffe2b2009-04-24 22:05:3580
[email protected]8f9d4eb2011-02-05 01:39:1081#if defined(TOOLKIT_VIEWS)
82#include "chrome/browser/extensions/extension_input_api.h"
83#endif
[email protected]d6833852010-08-20 18:00:4584
[email protected]9a2aebe02011-12-02 21:54:1485#if defined(OS_CHROMEOS) && defined(USE_VIRTUAL_KEYBOARD)
[email protected]27072cad2011-05-09 19:46:4086#include "chrome/browser/extensions/extension_input_ui_api.h"
87#endif
88
[email protected]61b55b62011-03-24 09:03:1089#if defined(OS_CHROMEOS)
[email protected]8f427982011-12-13 23:40:2390#include "chrome/browser/extensions/api/terminal/terminal_private_api.h"
[email protected]8baf0dbb2011-11-27 22:47:0291#include "chrome/browser/extensions/extension_file_browser_private_api.h"
92#include "chrome/browser/extensions/extension_info_private_api_chromeos.h"
93#include "chrome/browser/extensions/extension_input_ime_api.h"
94#include "chrome/browser/extensions/extension_input_method_api.h"
95#include "chrome/browser/extensions/extension_mediaplayer_private_api.h"
[email protected]61b55b62011-03-24 09:03:1096#endif
97
[email protected]83820d42011-11-12 22:03:1198using extensions::ExtensionAPI;
[email protected]615d88f2011-12-13 01:47:4499using WebKit::WebSecurityOrigin;
[email protected]83820d42011-11-12 22:03:11100
[email protected]bfdffe2b2009-04-24 22:05:35101// FactoryRegistry -------------------------------------------------------------
102
103namespace {
104
[email protected]b83e4602009-05-15 22:58:33105// Template for defining ExtensionFunctionFactory.
106template<class T>
107ExtensionFunction* NewExtensionFunction() {
108 return new T();
109}
[email protected]bfdffe2b2009-04-24 22:05:35110
[email protected]b83e4602009-05-15 22:58:33111// Contains a list of all known extension functions and allows clients to
112// create instances of them.
[email protected]bfdffe2b2009-04-24 22:05:35113class FactoryRegistry {
114 public:
[email protected]8e8bb6d2010-12-13 08:18:55115 static FactoryRegistry* GetInstance();
[email protected]b83e4602009-05-15 22:58:33116 FactoryRegistry() { ResetFunctions(); }
117
118 // Resets all functions to their default values.
119 void ResetFunctions();
120
121 // Adds all function names to 'names'.
[email protected]bfdffe2b2009-04-24 22:05:35122 void GetAllNames(std::vector<std::string>* names);
[email protected]b83e4602009-05-15 22:58:33123
124 // Allows overriding of specific functions (e.g. for testing). Functions
125 // must be previously registered. Returns true if successful.
126 bool OverrideFunction(const std::string& name,
127 ExtensionFunctionFactory factory);
128
129 // Factory method for the ExtensionFunction registered as 'name'.
[email protected]bfdffe2b2009-04-24 22:05:35130 ExtensionFunction* NewFunction(const std::string& name);
131
132 private:
[email protected]61424c062009-10-14 23:14:59133 template<class T>
134 void RegisterFunction() {
135 factories_[T::function_name()] = &NewExtensionFunction<T>;
136 }
137
[email protected]bfdffe2b2009-04-24 22:05:35138 typedef std::map<std::string, ExtensionFunctionFactory> FactoryMap;
139 FactoryMap factories_;
140};
141
[email protected]8e8bb6d2010-12-13 08:18:55142FactoryRegistry* FactoryRegistry::GetInstance() {
[email protected]bfdffe2b2009-04-24 22:05:35143 return Singleton<FactoryRegistry>::get();
144}
145
[email protected]b83e4602009-05-15 22:58:33146void FactoryRegistry::ResetFunctions() {
[email protected]bfdffe2b2009-04-24 22:05:35147 // Register all functions here.
148
[email protected]e515f5d2009-05-05 03:05:00149 // Windows
[email protected]61424c062009-10-14 23:14:59150 RegisterFunction<GetWindowFunction>();
151 RegisterFunction<GetCurrentWindowFunction>();
152 RegisterFunction<GetLastFocusedWindowFunction>();
153 RegisterFunction<GetAllWindowsFunction>();
154 RegisterFunction<CreateWindowFunction>();
155 RegisterFunction<UpdateWindowFunction>();
156 RegisterFunction<RemoveWindowFunction>();
[email protected]b83e4602009-05-15 22:58:33157
[email protected]e515f5d2009-05-05 03:05:00158 // Tabs
[email protected]61424c062009-10-14 23:14:59159 RegisterFunction<GetTabFunction>();
[email protected]e3eafb292010-04-14 21:30:41160 RegisterFunction<GetCurrentTabFunction>();
[email protected]61424c062009-10-14 23:14:59161 RegisterFunction<GetSelectedTabFunction>();
162 RegisterFunction<GetAllTabsInWindowFunction>();
[email protected]8c3495c2011-09-28 03:32:30163 RegisterFunction<QueryTabsFunction>();
164 RegisterFunction<HighlightTabsFunction>();
[email protected]61424c062009-10-14 23:14:59165 RegisterFunction<CreateTabFunction>();
166 RegisterFunction<UpdateTabFunction>();
[email protected]8c3495c2011-09-28 03:32:30167 RegisterFunction<MoveTabsFunction>();
[email protected]5d935112011-09-07 09:24:54168 RegisterFunction<ReloadTabFunction>();
[email protected]8c3495c2011-09-28 03:32:30169 RegisterFunction<RemoveTabsFunction>();
[email protected]61424c062009-10-14 23:14:59170 RegisterFunction<DetectTabLanguageFunction>();
171 RegisterFunction<CaptureVisibleTabFunction>();
172 RegisterFunction<TabsExecuteScriptFunction>();
173 RegisterFunction<TabsInsertCSSFunction>();
[email protected]bfdffe2b2009-04-24 22:05:35174
[email protected]f7f3a5f2009-05-01 22:02:34175 // Page Actions.
[email protected]61424c062009-10-14 23:14:59176 RegisterFunction<EnablePageActionFunction>();
177 RegisterFunction<DisablePageActionFunction>();
[email protected]744ef172009-10-16 21:53:46178 RegisterFunction<PageActionShowFunction>();
179 RegisterFunction<PageActionHideFunction>();
180 RegisterFunction<PageActionSetIconFunction>();
181 RegisterFunction<PageActionSetTitleFunction>();
[email protected]e478d6702010-01-28 00:10:29182 RegisterFunction<PageActionSetPopupFunction>();
[email protected]f7f3a5f2009-05-01 22:02:34183
[email protected]ec9ac0df2009-10-01 18:06:47184 // Browser Actions.
[email protected]61424c062009-10-14 23:14:59185 RegisterFunction<BrowserActionSetIconFunction>();
[email protected]1288ba02009-10-15 00:02:24186 RegisterFunction<BrowserActionSetTitleFunction>();
[email protected]61424c062009-10-14 23:14:59187 RegisterFunction<BrowserActionSetBadgeTextFunction>();
188 RegisterFunction<BrowserActionSetBadgeBackgroundColorFunction>();
[email protected]85ae9592010-02-03 20:58:50189 RegisterFunction<BrowserActionSetPopupFunction>();
[email protected]ec9ac0df2009-10-01 18:06:47190
[email protected]6093d742011-08-26 16:37:18191 // Browsing Data.
[email protected]8f5090a52012-02-10 11:36:21192 RegisterFunction<RemoveBrowsingDataFunction>();
193 RegisterFunction<RemoveAppCacheFunction>();
194 RegisterFunction<RemoveCacheFunction>();
195 RegisterFunction<RemoveCookiesFunction>();
196 RegisterFunction<RemoveDownloadsFunction>();
197 RegisterFunction<RemoveFileSystemsFunction>();
198 RegisterFunction<RemoveFormDataFunction>();
199 RegisterFunction<RemoveHistoryFunction>();
200 RegisterFunction<RemoveIndexedDBFunction>();
201 RegisterFunction<RemoveLocalStorageFunction>();
202 RegisterFunction<RemoveOriginBoundCertsFunction>();
203 RegisterFunction<RemovePluginDataFunction>();
204 RegisterFunction<RemovePasswordsFunction>();
205 RegisterFunction<RemoveWebSQLFunction>();
[email protected]6093d742011-08-26 16:37:18206
[email protected]f7f3a5f2009-05-01 22:02:34207 // Bookmarks.
[email protected]61424c062009-10-14 23:14:59208 RegisterFunction<GetBookmarksFunction>();
209 RegisterFunction<GetBookmarkChildrenFunction>();
[email protected]a3c94c712009-12-18 19:23:55210 RegisterFunction<GetBookmarkRecentFunction>();
[email protected]61424c062009-10-14 23:14:59211 RegisterFunction<GetBookmarkTreeFunction>();
[email protected]532a8c62011-06-03 21:30:01212 RegisterFunction<GetBookmarkSubTreeFunction>();
[email protected]61424c062009-10-14 23:14:59213 RegisterFunction<SearchBookmarksFunction>();
214 RegisterFunction<RemoveBookmarkFunction>();
215 RegisterFunction<RemoveTreeBookmarkFunction>();
216 RegisterFunction<CreateBookmarkFunction>();
217 RegisterFunction<MoveBookmarkFunction>();
218 RegisterFunction<UpdateBookmarkFunction>();
[email protected]9c45b7182009-08-04 16:44:43219
[email protected]f34e79632010-03-17 02:34:08220 // Infobars.
221 RegisterFunction<ShowInfoBarFunction>();
222
[email protected]9dd97bc2010-01-14 01:40:04223 // BookmarkManager
224 RegisterFunction<CopyBookmarkManagerFunction>();
225 RegisterFunction<CutBookmarkManagerFunction>();
226 RegisterFunction<PasteBookmarkManagerFunction>();
[email protected]03b3bbf2010-01-29 23:54:57227 RegisterFunction<CanPasteBookmarkManagerFunction>();
[email protected]cb6cf792010-01-28 00:04:56228 RegisterFunction<ImportBookmarksFunction>();
229 RegisterFunction<ExportBookmarksFunction>();
[email protected]d406e2e2010-01-30 21:45:18230 RegisterFunction<SortChildrenBookmarkManagerFunction>();
[email protected]9dd97bc2010-01-14 01:40:04231 RegisterFunction<BookmarkManagerGetStringsFunction>();
[email protected]ced90ae12010-02-20 02:06:16232 RegisterFunction<StartDragBookmarkManagerFunction>();
233 RegisterFunction<DropBookmarkManagerFunction>();
[email protected]9b071852010-04-02 06:45:31234 RegisterFunction<GetSubtreeBookmarkManagerFunction>();
[email protected]933ebbe2011-06-30 12:24:01235 RegisterFunction<CanEditBookmarkManagerFunction>();
[email protected]9dd97bc2010-01-14 01:40:04236
[email protected]de768a832009-10-30 05:25:01237 // History
238 RegisterFunction<AddUrlHistoryFunction>();
239 RegisterFunction<DeleteAllHistoryFunction>();
240 RegisterFunction<DeleteRangeHistoryFunction>();
241 RegisterFunction<DeleteUrlHistoryFunction>();
242 RegisterFunction<GetVisitsHistoryFunction>();
243 RegisterFunction<SearchHistoryFunction>();
244
[email protected]f5205412010-03-16 00:19:34245 // Idle
246 RegisterFunction<ExtensionIdleQueryStateFunction>();
247
[email protected]198bcfe2009-09-09 22:56:28248 // I18N.
[email protected]61424c062009-10-14 23:14:59249 RegisterFunction<GetAcceptLanguagesFunction>();
[email protected]198bcfe2009-09-09 22:56:28250
[email protected]381162b2010-01-28 17:29:35251 // Processes.
[email protected]8a661f82010-10-19 21:47:11252 RegisterFunction<GetProcessIdForTabFunction>();
[email protected]381162b2010-01-28 17:29:35253
[email protected]438772df2010-02-26 18:08:43254 // Metrics.
[email protected]cf25e4d2010-03-12 21:19:34255 RegisterFunction<MetricsRecordUserActionFunction>();
256 RegisterFunction<MetricsRecordValueFunction>();
257 RegisterFunction<MetricsRecordPercentageFunction>();
258 RegisterFunction<MetricsRecordCountFunction>();
259 RegisterFunction<MetricsRecordSmallCountFunction>();
260 RegisterFunction<MetricsRecordMediumCountFunction>();
261 RegisterFunction<MetricsRecordTimeFunction>();
262 RegisterFunction<MetricsRecordMediumTimeFunction>();
263 RegisterFunction<MetricsRecordLongTimeFunction>();
[email protected]438772df2010-02-26 18:08:43264
[email protected]17d40f02010-07-01 01:18:06265 // RLZ.
266#if defined(OS_WIN)
267 RegisterFunction<RlzRecordProductEventFunction>();
268 RegisterFunction<RlzGetAccessPointRlzFunction>();
[email protected]3a612be2010-07-17 03:11:21269 RegisterFunction<RlzSendFinancialPingFunction>();
[email protected]17d40f02010-07-01 01:18:06270 RegisterFunction<RlzClearProductStateFunction>();
271#endif
272
[email protected]898bbd32010-05-18 18:52:29273 // Cookies.
274 RegisterFunction<GetCookieFunction>();
275 RegisterFunction<GetAllCookiesFunction>();
276 RegisterFunction<SetCookieFunction>();
277 RegisterFunction<RemoveCookieFunction>();
278 RegisterFunction<GetAllCookieStoresFunction>();
279
[email protected]25fd1b2e2009-08-17 20:57:14280 // Test.
[email protected]61424c062009-10-14 23:14:59281 RegisterFunction<ExtensionTestPassFunction>();
282 RegisterFunction<ExtensionTestFailFunction>();
283 RegisterFunction<ExtensionTestLogFunction>();
[email protected]d13950e2009-12-04 01:43:02284 RegisterFunction<ExtensionTestQuotaResetFunction>();
[email protected]db7331a2010-02-25 22:10:50285 RegisterFunction<ExtensionTestCreateIncognitoTabFunction>();
[email protected]745feedb2010-08-02 04:08:07286 RegisterFunction<ExtensionTestSendMessageFunction>();
[email protected]761e7162010-10-18 19:26:39287 RegisterFunction<ExtensionTestGetConfigFunction>();
[email protected]5cbe1e22010-01-30 01:18:56288
289 // Accessibility.
290 RegisterFunction<GetFocusedControlFunction>();
291 RegisterFunction<SetAccessibilityEnabledFunction>();
[email protected]cde158b2011-12-21 10:22:49292 RegisterFunction<GetAlertsForTabFunction>();
[email protected]446255952010-03-17 20:41:58293
[email protected]8abe0a32010-08-12 00:40:22294 // Text-to-speech.
[email protected]c63f2b72011-07-07 05:25:00295 RegisterFunction<ExtensionTtsEngineSendTtsEventFunction>();
296 RegisterFunction<ExtensionTtsGetVoicesFunction>();
297 RegisterFunction<ExtensionTtsIsSpeakingFunction>();
[email protected]8abe0a32010-08-12 00:40:22298 RegisterFunction<ExtensionTtsSpeakFunction>();
299 RegisterFunction<ExtensionTtsStopSpeakingFunction>();
[email protected]8abe0a32010-08-12 00:40:22300
[email protected]2e3b5202010-03-23 06:52:41301 // Context Menus.
302 RegisterFunction<CreateContextMenuFunction>();
[email protected]66dbfb2c2010-05-12 20:20:15303 RegisterFunction<UpdateContextMenuFunction>();
[email protected]2e3b5202010-03-23 06:52:41304 RegisterFunction<RemoveContextMenuFunction>();
[email protected]66dbfb2c2010-05-12 20:20:15305 RegisterFunction<RemoveAllContextMenusFunction>();
[email protected]56ad3792010-05-28 17:45:33306
307 // Omnibox.
308 RegisterFunction<OmniboxSendSuggestionsFunction>();
[email protected]1bead0712010-11-27 17:41:53309 RegisterFunction<OmniboxSetDefaultSuggestionFunction>();
[email protected]a9c23a52010-08-04 09:13:44310
[email protected]e06a1fe2011-09-29 21:20:44311 // Speech input.
312 RegisterFunction<StartSpeechInputFunction>();
313 RegisterFunction<StopSpeechInputFunction>();
314 RegisterFunction<IsRecordingSpeechInputFunction>();
315
[email protected]d6833852010-08-20 18:00:45316#if defined(TOOLKIT_VIEWS)
317 // Input.
318 RegisterFunction<SendKeyboardEventInputFunction>();
319#endif
[email protected]cffd7892010-08-26 17:43:28320
[email protected]2cc81d32011-10-04 17:03:18321#if defined(USE_VIRTUAL_KEYBOARD)
[email protected]bcde7482011-05-23 19:29:12322 RegisterFunction<HideKeyboardFunction>();
[email protected]3c8faef2011-06-09 22:56:51323 RegisterFunction<SetKeyboardHeightFunction>();
[email protected]bcde7482011-05-23 19:29:12324#endif
325
[email protected]14da67b02011-08-02 05:49:13326#if defined(OS_CHROMEOS)
[email protected]27072cad2011-05-09 19:46:40327 // IME
[email protected]14da67b02011-08-02 05:49:13328 RegisterFunction<SetCompositionFunction>();
329 RegisterFunction<ClearCompositionFunction>();
330 RegisterFunction<CommitTextFunction>();
331 RegisterFunction<SetCandidateWindowPropertiesFunction>();
332 RegisterFunction<SetCandidatesFunction>();
333 RegisterFunction<SetCursorPositionFunction>();
334 RegisterFunction<SetMenuItemsFunction>();
335 RegisterFunction<UpdateMenuItemsFunction>();
[email protected]cd0b04c92011-09-08 05:18:06336
337 RegisterFunction<InputEventHandled>();
[email protected]9a2aebe02011-12-02 21:54:14338#if defined(USE_VIRTUAL_KEYBOARD)
[email protected]27072cad2011-05-09 19:46:40339 RegisterFunction<CandidateClickedInputUiFunction>();
340 RegisterFunction<CursorUpInputUiFunction>();
341 RegisterFunction<CursorDownInputUiFunction>();
342 RegisterFunction<PageUpInputUiFunction>();
343 RegisterFunction<PageDownInputUiFunction>();
344 RegisterFunction<RegisterInputUiFunction>();
345 RegisterFunction<PageUpInputUiFunction>();
346 RegisterFunction<PageDownInputUiFunction>();
347#endif
[email protected]14da67b02011-08-02 05:49:13348#endif
[email protected]27072cad2011-05-09 19:46:40349
[email protected]cffd7892010-08-26 17:43:28350 // Management.
351 RegisterFunction<GetAllExtensionsFunction>();
[email protected]e78543c2010-11-08 22:05:23352 RegisterFunction<GetExtensionByIdFunction>();
[email protected]925a54d2011-07-29 17:21:00353 RegisterFunction<GetPermissionWarningsByIdFunction>();
354 RegisterFunction<GetPermissionWarningsByManifestFunction>();
[email protected]e558ff82010-09-23 20:19:56355 RegisterFunction<LaunchAppFunction>();
[email protected]cffd7892010-08-26 17:43:28356 RegisterFunction<SetEnabledFunction>();
[email protected]cffd7892010-08-26 17:43:28357 RegisterFunction<UninstallFunction>();
[email protected]63cda0c2010-09-01 04:41:23358
[email protected]a65882c2010-11-12 15:15:09359 // Extension module.
360 RegisterFunction<SetUpdateUrlDataFunction>();
[email protected]c7c401d2011-03-16 10:20:01361 RegisterFunction<IsAllowedIncognitoAccessFunction>();
362 RegisterFunction<IsAllowedFileSchemeAccessFunction>();
[email protected]a65882c2010-11-12 15:15:09363
[email protected]63cda0c2010-09-01 04:41:23364 // WebstorePrivate.
[email protected]d6885592010-10-11 19:38:24365 RegisterFunction<GetBrowserLoginFunction>();
[email protected]63cda0c2010-09-01 04:41:23366 RegisterFunction<GetStoreLoginFunction>();
367 RegisterFunction<SetStoreLoginFunction>();
[email protected]5349ac6d2011-04-05 22:20:17368 RegisterFunction<BeginInstallWithManifestFunction>();
[email protected]b1f04cc2010-11-10 22:59:30369 RegisterFunction<CompleteInstallFunction>();
[email protected]f66a50a2011-11-02 23:53:46370 RegisterFunction<SilentlyInstallFunction>();
[email protected]979b69c2011-12-08 23:19:55371 RegisterFunction<GetWebGLStatusFunction>();
[email protected]c41fe662011-02-15 01:19:26372
[email protected]557a51dd2011-07-26 12:17:11373 // WebNavigation.
374 RegisterFunction<GetFrameFunction>();
[email protected]5a130672011-09-09 08:42:29375 RegisterFunction<GetAllFramesFunction>();
[email protected]557a51dd2011-07-26 12:17:11376
[email protected]c41fe662011-02-15 01:19:26377 // WebRequest.
378 RegisterFunction<WebRequestAddEventListener>();
[email protected]05cc4e72011-03-08 21:29:48379 RegisterFunction<WebRequestEventHandled>();
[email protected]e81d4d72011-09-29 16:54:31380 RegisterFunction<WebRequestHandlerBehaviorChanged>();
[email protected]598bbcc2011-02-24 10:03:25381
382 // Preferences.
383 RegisterFunction<GetPreferenceFunction>();
384 RegisterFunction<SetPreferenceFunction>();
[email protected]c433bcb2011-02-24 13:10:27385 RegisterFunction<ClearPreferenceFunction>();
[email protected]91ba3312011-03-17 20:39:22386
[email protected]b6b805e92011-04-16 09:24:14387 // ChromeOS-specific part of the API.
388#if defined(OS_CHROMEOS)
389 // Device Customization.
390 RegisterFunction<GetChromeosInfoFunction>();
391
392 // FileBrowserPrivate functions.
[email protected]04ef5152011-11-18 04:05:25393 // TODO(jamescook): Expose these on non-ChromeOS platforms so we can use
394 // the extension-based file picker on Aura. crbug.com/97424
[email protected]94bda202011-04-18 23:31:00395 RegisterFunction<CancelFileDialogFunction>();
[email protected]b6b805e92011-04-16 09:24:14396 RegisterFunction<ExecuteTasksFileBrowserFunction>();
[email protected]94bda202011-04-18 23:31:00397 RegisterFunction<FileDialogStringsFunction>();
[email protected]b6b805e92011-04-16 09:24:14398 RegisterFunction<GetFileTasksFileBrowserFunction>();
[email protected]61334fa2011-06-16 01:01:40399 RegisterFunction<GetVolumeMetadataFunction>();
[email protected]b6b805e92011-04-16 09:24:14400 RegisterFunction<RequestLocalFileSystemFunction>();
[email protected]a6d06642011-06-02 05:55:23401 RegisterFunction<AddFileWatchBrowserFunction>();
402 RegisterFunction<RemoveFileWatchBrowserFunction>();
[email protected]9d4c2c52011-04-07 18:53:10403 RegisterFunction<SelectFileFunction>();
404 RegisterFunction<SelectFilesFunction>();
[email protected]928ae8852011-07-26 01:15:03405 RegisterFunction<AddMountFunction>();
406 RegisterFunction<RemoveMountFunction>();
407 RegisterFunction<GetMountPointsFunction>();
[email protected]694cafac2011-09-21 17:41:53408 RegisterFunction<GetSizeStatsFunction>();
[email protected]3fd9004c2011-08-12 00:58:46409 RegisterFunction<FormatDeviceFunction>();
[email protected]94bda202011-04-18 23:31:00410 RegisterFunction<ViewFilesFunction>();
[email protected]f1852b52011-05-17 04:58:08411
[email protected]ce9802042011-05-27 10:11:40412 // Mediaplayer
413 RegisterFunction<PlayAtMediaplayerFunction>();
414 RegisterFunction<SetPlaybackErrorMediaplayerFunction>();
415 RegisterFunction<GetPlaylistMediaplayerFunction>();
416 RegisterFunction<TogglePlaylistPanelMediaplayerFunction>();
417 RegisterFunction<ToggleFullscreenMediaplayerFunction>();
[email protected]be5bd5742011-07-14 07:21:01418
419 // InputMethod
420 RegisterFunction<GetInputMethodFunction>();
421
[email protected]8f427982011-12-13 23:40:23422 // Terminal
423 RegisterFunction<OpenTerminalProcessFunction>();
424 RegisterFunction<SendInputToTerminalProcessFunction>();
425 RegisterFunction<CloseTerminalProcessFunction>();
[email protected]0d2786c2012-02-14 02:36:31426 RegisterFunction<OnTerminalResizeFunction>();
[email protected]8f427982011-12-13 23:40:23427
[email protected]9a2aebe02011-12-02 21:54:14428#if defined(USE_VIRTUAL_KEYBOARD)
[email protected]f1852b52011-05-17 04:58:08429 // Input
430 RegisterFunction<SendHandwritingStrokeFunction>();
431 RegisterFunction<CancelHandwritingStrokesFunction>();
432#endif
[email protected]61b55b62011-03-24 09:03:10433#endif
434
[email protected]c6e584c2011-05-18 11:58:44435 // Websocket to TCP proxy. Currently noop on anything other than ChromeOS.
436 RegisterFunction<WebSocketProxyPrivateGetPassportForTCPFunction>();
[email protected]5ddffb82011-10-14 17:48:07437 RegisterFunction<WebSocketProxyPrivateGetURLForTCPFunction>();
[email protected]c6e584c2011-05-18 11:58:44438
[email protected]91ba3312011-03-17 20:39:22439 // Debugger
440 RegisterFunction<AttachDebuggerFunction>();
441 RegisterFunction<DetachDebuggerFunction>();
[email protected]c7580b62011-10-26 08:46:30442 RegisterFunction<SendCommandDebuggerFunction>();
[email protected]fa0624262011-06-09 14:17:38443
[email protected]b7f853e282011-08-10 09:24:20444 // Settings
[email protected]0d9a2202011-11-09 13:48:41445 RegisterFunction<extensions::GetSettingsFunction>();
446 RegisterFunction<extensions::SetSettingsFunction>();
447 RegisterFunction<extensions::RemoveSettingsFunction>();
448 RegisterFunction<extensions::ClearSettingsFunction>();
[email protected]7b4989f2012-01-29 11:19:11449 RegisterFunction<extensions::GetBytesInUseSettingsFunction>();
[email protected]b7f853e282011-08-10 09:24:20450
[email protected]fa0624262011-06-09 14:17:38451 // Content settings.
[email protected]49ba4822011-06-15 18:41:56452 RegisterFunction<GetResourceIdentifiersFunction>();
[email protected]fa0624262011-06-09 14:17:38453 RegisterFunction<ClearContentSettingsFunction>();
454 RegisterFunction<GetContentSettingFunction>();
455 RegisterFunction<SetContentSettingFunction>();
[email protected]c1d05aa2011-06-28 02:07:30456
[email protected]be9d9c82011-07-13 04:17:31457 // ChromeAuth settings.
458 RegisterFunction<SetCloudPrintCredentialsFunction>();
459
[email protected]c1d05aa2011-06-28 02:07:30460 // Experimental App API.
461 RegisterFunction<AppNotifyFunction>();
462 RegisterFunction<AppClearAllNotificationsFunction>();
[email protected]902fd7b2011-07-27 18:42:31463
464 // Permissions
465 RegisterFunction<ContainsPermissionsFunction>();
466 RegisterFunction<GetAllPermissionsFunction>();
467 RegisterFunction<RemovePermissionsFunction>();
468 RegisterFunction<RequestPermissionsFunction>();
[email protected]21d7a4e302011-08-15 16:17:12469
470 // Downloads
471 RegisterFunction<DownloadsDownloadFunction>();
472 RegisterFunction<DownloadsSearchFunction>();
473 RegisterFunction<DownloadsPauseFunction>();
474 RegisterFunction<DownloadsResumeFunction>();
475 RegisterFunction<DownloadsCancelFunction>();
476 RegisterFunction<DownloadsEraseFunction>();
477 RegisterFunction<DownloadsSetDestinationFunction>();
478 RegisterFunction<DownloadsAcceptDangerFunction>();
479 RegisterFunction<DownloadsShowFunction>();
480 RegisterFunction<DownloadsDragFunction>();
[email protected]45e4fab22012-01-09 19:38:02481 RegisterFunction<DownloadsGetFileIconFunction>();
[email protected]3a605e82011-09-26 17:26:16482
[email protected]9e4430f2011-11-28 07:43:29483 // PageCapture
484 RegisterFunction<PageCaptureSaveAsMHTMLFunction>();
[email protected]6a16dc9b2011-10-17 18:28:16485
[email protected]5eddc3e2011-10-26 04:33:31486 // TopSites
487 RegisterFunction<GetTopSitesFunction>();
[email protected]ae7f1ba2011-11-28 23:07:31488
[email protected]223a93f12012-01-18 21:17:53489 // Serial
490 RegisterFunction<extensions::SerialOpenFunction>();
491 RegisterFunction<extensions::SerialCloseFunction>();
[email protected]58edca52012-02-16 21:51:38492 RegisterFunction<extensions::SerialReadFunction>();
493 RegisterFunction<extensions::SerialWriteFunction>();
[email protected]223a93f12012-01-18 21:17:53494
[email protected]ae7f1ba2011-11-28 23:07:31495 // Sockets
496 RegisterFunction<extensions::SocketCreateFunction>();
[email protected]55afeb52011-12-06 00:15:39497 RegisterFunction<extensions::SocketDestroyFunction>();
[email protected]ae7f1ba2011-11-28 23:07:31498 RegisterFunction<extensions::SocketConnectFunction>();
[email protected]d47c11f2012-01-26 18:15:04499 RegisterFunction<extensions::SocketDisconnectFunction>();
[email protected]64c820732012-01-05 20:50:34500 RegisterFunction<extensions::SocketReadFunction>();
[email protected]55afeb52011-12-06 00:15:39501 RegisterFunction<extensions::SocketWriteFunction>();
[email protected]a4f98922011-12-06 11:32:23502
[email protected]14a38f3f2012-01-12 16:16:51503 // DNS
504 RegisterFunction<extensions::DNSResolveFunction>();
505
[email protected]a4f98922011-12-06 11:32:23506 // System
507 RegisterFunction<extensions::GetIncognitoModeAvailabilityFunction>();
[email protected]1723bdc22011-12-15 05:04:18508 RegisterFunction<extensions::GetUpdateStatusFunction>();
[email protected]8ef650e2012-02-08 10:20:59509
510 // Net
511 RegisterFunction<extensions::AddRulesFunction>();
512 RegisterFunction<extensions::RemoveRulesFunction>();
513 RegisterFunction<extensions::GetRulesFunction>();
[email protected]bfdffe2b2009-04-24 22:05:35514}
515
[email protected]b83e4602009-05-15 22:58:33516void FactoryRegistry::GetAllNames(std::vector<std::string>* names) {
517 for (FactoryMap::iterator iter = factories_.begin();
518 iter != factories_.end(); ++iter) {
[email protected]bfdffe2b2009-04-24 22:05:35519 names->push_back(iter->first);
520 }
521}
522
[email protected]b83e4602009-05-15 22:58:33523bool FactoryRegistry::OverrideFunction(const std::string& name,
524 ExtensionFunctionFactory factory) {
525 FactoryMap::iterator iter = factories_.find(name);
526 if (iter == factories_.end()) {
527 return false;
528 } else {
529 iter->second = factory;
530 return true;
531 }
532}
533
[email protected]bfdffe2b2009-04-24 22:05:35534ExtensionFunction* FactoryRegistry::NewFunction(const std::string& name) {
535 FactoryMap::iterator iter = factories_.find(name);
536 DCHECK(iter != factories_.end());
[email protected]b83e4602009-05-15 22:58:33537 ExtensionFunction* function = iter->second();
[email protected]76a3db852009-07-24 02:14:56538 function->set_name(name);
[email protected]b83e4602009-05-15 22:58:33539 return function;
[email protected]bfdffe2b2009-04-24 22:05:35540}
541
[email protected]efd75992011-12-15 22:42:42542const char kAccessDenied[] = "access denied";
543const char kQuotaExceeded[] = "quota exceeded";
544
545void LogSuccess(const Extension* extension,
546 const ExtensionHostMsg_Request_Params& params) {
547 ExtensionActivityLog* extension_activity_log =
548 ExtensionActivityLog::GetInstance();
549 if (extension_activity_log->HasObservers(extension)) {
550 std::string call_signature = params.name + "(";
551 ListValue::const_iterator it = params.arguments.begin();
552 for (; it != params.arguments.end(); ++it) {
553 std::string arg;
554 JSONStringValueSerializer serializer(&arg);
555 if (serializer.SerializeAndOmitBinaryValues(**it)) {
556 if (it != params.arguments.begin())
557 call_signature += ", ";
558 call_signature += arg;
559 }
560 }
561 call_signature += ")";
562
563 extension_activity_log->Log(
564 extension,
565 ExtensionActivityLog::ACTIVITY_EXTENSION_API_CALL,
566 call_signature);
567 }
568}
569
570void LogFailure(const Extension* extension,
571 const std::string& func_name,
572 const char* reason) {
573 ExtensionActivityLog* extension_activity_log =
574 ExtensionActivityLog::GetInstance();
575 if (extension_activity_log->HasObservers(extension)) {
576 extension_activity_log->Log(
577 extension,
578 ExtensionActivityLog::ACTIVITY_EXTENSION_API_BLOCK,
579 func_name + ": " + reason);
580 }
581}
582
[email protected]b83e4602009-05-15 22:58:33583}; // namespace
[email protected]bfdffe2b2009-04-24 22:05:35584
585// ExtensionFunctionDispatcher -------------------------------------------------
586
587void ExtensionFunctionDispatcher::GetAllFunctionNames(
588 std::vector<std::string>* names) {
[email protected]8e8bb6d2010-12-13 08:18:55589 FactoryRegistry::GetInstance()->GetAllNames(names);
[email protected]bfdffe2b2009-04-24 22:05:35590}
591
[email protected]b83e4602009-05-15 22:58:33592bool ExtensionFunctionDispatcher::OverrideFunction(
593 const std::string& name, ExtensionFunctionFactory factory) {
[email protected]8e8bb6d2010-12-13 08:18:55594 return FactoryRegistry::GetInstance()->OverrideFunction(name, factory);
[email protected]b83e4602009-05-15 22:58:33595}
596
597void ExtensionFunctionDispatcher::ResetFunctions() {
[email protected]8e8bb6d2010-12-13 08:18:55598 FactoryRegistry::GetInstance()->ResetFunctions();
[email protected]b83e4602009-05-15 22:58:33599}
600
[email protected]c357acb42011-06-09 20:52:42601// static
602void ExtensionFunctionDispatcher::DispatchOnIOThread(
[email protected]fd50e7b2011-11-03 09:20:25603 ExtensionInfoMap* extension_info_map,
[email protected]673514522011-07-13 18:17:18604 void* profile,
[email protected]c357acb42011-06-09 20:52:42605 int render_process_id,
606 base::WeakPtr<ChromeRenderMessageFilter> ipc_sender,
607 int routing_id,
608 const ExtensionHostMsg_Request_Params& params) {
609 const Extension* extension =
[email protected]83820d42011-11-12 22:03:11610 extension_info_map->extensions().GetByID(params.extension_id);
[email protected]c357acb42011-06-09 20:52:42611
[email protected]6f371442011-11-09 06:45:46612 scoped_refptr<ExtensionFunction> function(
613 CreateExtensionFunction(params, extension, render_process_id,
614 extension_info_map->process_map(), profile,
615 ipc_sender, routing_id));
[email protected]efd75992011-12-15 22:42:42616 if (!function) {
617 LogFailure(extension, params.name, kAccessDenied);
[email protected]c357acb42011-06-09 20:52:42618 return;
[email protected]efd75992011-12-15 22:42:42619 }
[email protected]c357acb42011-06-09 20:52:42620
621 IOThreadExtensionFunction* function_io =
622 function->AsIOThreadExtensionFunction();
623 if (!function_io) {
624 NOTREACHED();
625 return;
626 }
627 function_io->set_ipc_sender(ipc_sender, routing_id);
628 function_io->set_extension_info_map(extension_info_map);
629 function->set_include_incognito(
630 extension_info_map->IsIncognitoEnabled(extension->id()));
[email protected]fd50e7b2011-11-03 09:20:25631
632 ExtensionsQuotaService* quota = extension_info_map->quota_service();
633 if (quota->Assess(extension->id(), function, &params.arguments,
634 base::TimeTicks::Now())) {
635 function->Run();
[email protected]efd75992011-12-15 22:42:42636 LogSuccess(extension, params);
[email protected]fd50e7b2011-11-03 09:20:25637 } else {
638 function->OnQuotaExceeded();
[email protected]efd75992011-12-15 22:42:42639 LogFailure(extension, params.name, kQuotaExceeded);
[email protected]fd50e7b2011-11-03 09:20:25640 }
[email protected]c357acb42011-06-09 20:52:42641}
642
[email protected]c5dbef02011-05-13 05:06:09643ExtensionFunctionDispatcher::ExtensionFunctionDispatcher(Profile* profile,
644 Delegate* delegate)
645 : profile_(profile),
[email protected]55ce330712011-05-24 19:04:27646 delegate_(delegate) {
[email protected]bfdffe2b2009-04-24 22:05:35647}
648
[email protected]32dda362009-06-05 19:07:01649ExtensionFunctionDispatcher::~ExtensionFunctionDispatcher() {
[email protected]32dda362009-06-05 19:07:01650}
651
[email protected]0ec92032010-03-24 19:59:41652Browser* ExtensionFunctionDispatcher::GetCurrentBrowser(
[email protected]c5dbef02011-05-13 05:06:09653 RenderViewHost* render_view_host, bool include_incognito) {
[email protected]0ec92032010-03-24 19:59:41654 Browser* browser = delegate_->GetBrowser();
[email protected]7eecaed52009-05-07 21:44:12655
[email protected]bc535ee52010-08-31 18:40:32656 // If the delegate has an associated browser, that is always the right answer.
657 if (browser)
658 return browser;
[email protected]9c45b7182009-08-04 16:44:43659
[email protected]bc535ee52010-08-31 18:40:32660 // Otherwise, try to default to a reasonable browser. If |include_incognito|
661 // is true, we will also search browsers in the incognito version of this
662 // profile. Note that the profile may already be incognito, in which case
663 // we will search the incognito version only, regardless of the value of
664 // |include_incognito|.
[email protected]9b62ecf2011-07-27 20:23:08665 Profile* profile = Profile::FromBrowserContext(
[email protected]f3b1a082011-11-18 00:34:30666 render_view_host->process()->GetBrowserContext());
[email protected]8ecca492012-01-19 17:29:42667 browser = BrowserList::FindAnyBrowser(profile, include_incognito);
[email protected]0ec92032010-03-24 19:59:41668
[email protected]0ec92032010-03-24 19:59:41669 // NOTE(rafaelw): This can return NULL in some circumstances. In particular,
[email protected]6d7a6042010-08-12 20:12:42670 // a background_page onload chrome.tabs api call can make it into here
671 // before the browser is sufficiently initialized to return here.
[email protected]0ec92032010-03-24 19:59:41672 // A similar situation may arise during shutdown.
673 // TODO(rafaelw): Delay creation of background_page until the browser
674 // is available. http://code.google.com/p/chromium/issues/detail?id=13284
675 return browser;
[email protected]b27257562009-11-16 23:28:26676}
677
[email protected]c5dbef02011-05-13 05:06:09678void ExtensionFunctionDispatcher::Dispatch(
679 const ExtensionHostMsg_Request_Params& params,
680 RenderViewHost* render_view_host) {
[email protected]c5dbef02011-05-13 05:06:09681 ExtensionService* service = profile()->GetExtensionService();
[email protected]6f371442011-11-09 06:45:46682 extensions::ProcessMap* process_map = service->process_map();
683 if (!service || !process_map)
[email protected]c5dbef02011-05-13 05:06:09684 return;
685
[email protected]615d88f2011-12-13 01:47:44686 const Extension* extension = service->extensions()->GetByID(
687 params.extension_id);
[email protected]c5dbef02011-05-13 05:06:09688 if (!extension)
[email protected]615d88f2011-12-13 01:47:44689 extension = service->extensions()->GetHostedAppByURL(ExtensionURLInfo(
690 WebSecurityOrigin::createFromString(params.source_origin),
691 params.source_url));
[email protected]c5dbef02011-05-13 05:06:09692
[email protected]8add5412011-10-01 21:02:14693 scoped_refptr<ExtensionFunction> function(
[email protected]6f371442011-11-09 06:45:46694 CreateExtensionFunction(params, extension,
[email protected]f3b1a082011-11-18 00:34:30695 render_view_host->process()->GetID(),
[email protected]6f371442011-11-09 06:45:46696 *(service->process_map()),
697 profile(), render_view_host,
[email protected]8add5412011-10-01 21:02:14698 render_view_host->routing_id()));
[email protected]efd75992011-12-15 22:42:42699 if (!function) {
700 LogFailure(extension, params.name, kAccessDenied);
[email protected]f82d57b52011-04-27 19:13:17701 return;
[email protected]efd75992011-12-15 22:42:42702 }
[email protected]f82d57b52011-04-27 19:13:17703
[email protected]a2aef2e2011-05-26 22:48:12704 UIThreadExtensionFunction* function_ui =
705 function->AsUIThreadExtensionFunction();
706 if (!function_ui) {
707 NOTREACHED();
708 return;
709 }
710 function_ui->SetRenderViewHost(render_view_host);
711 function_ui->set_dispatcher(AsWeakPtr());
712 function_ui->set_profile(profile_);
[email protected]2a8f24e2010-11-03 21:37:05713 function->set_include_incognito(service->CanCrossIncognito(extension));
[email protected]cb0ce1e022010-03-10 19:54:41714
[email protected]d13950e2009-12-04 01:43:02715 ExtensionsQuotaService* quota = service->quota_service();
[email protected]c5dbef02011-05-13 05:06:09716 if (quota->Assess(extension->id(), function, &params.arguments,
[email protected]8b8e7c92010-08-19 18:05:56717 base::TimeTicks::Now())) {
[email protected]d070ec62010-07-27 21:28:26718 // See crbug.com/39178.
719 ExternalProtocolHandler::PermitLaunchUrl();
720
[email protected]d13950e2009-12-04 01:43:02721 function->Run();
[email protected]efd75992011-12-15 22:42:42722 LogSuccess(extension, params);
[email protected]d13950e2009-12-04 01:43:02723 } else {
[email protected]fd50e7b2011-11-03 09:20:25724 function->OnQuotaExceeded();
[email protected]efd75992011-12-15 22:42:42725 LogFailure(extension, params.name, kQuotaExceeded);
[email protected]d13950e2009-12-04 01:43:02726 }
[email protected]bfdffe2b2009-04-24 22:05:35727}
728
[email protected]c357acb42011-06-09 20:52:42729// static
730ExtensionFunction* ExtensionFunctionDispatcher::CreateExtensionFunction(
731 const ExtensionHostMsg_Request_Params& params,
732 const Extension* extension,
[email protected]6f371442011-11-09 06:45:46733 int requesting_process_id,
734 const extensions::ProcessMap& process_map,
[email protected]673514522011-07-13 18:17:18735 void* profile,
[email protected]c357acb42011-06-09 20:52:42736 IPC::Message::Sender* ipc_sender,
737 int routing_id) {
[email protected]c357acb42011-06-09 20:52:42738 if (!extension) {
[email protected]6f371442011-11-09 06:45:46739 LOG(ERROR) << "Specified extension does not exist.";
740 SendAccessDenied(ipc_sender, routing_id, params.request_id);
741 return NULL;
742 }
743
[email protected]83820d42011-11-12 22:03:11744 if (ExtensionAPI::GetInstance()->IsPrivileged(params.name) &&
745 !process_map.Contains(extension->id(), requesting_process_id)) {
[email protected]6f371442011-11-09 06:45:46746 LOG(ERROR) << "Extension API called from incorrect process "
747 << requesting_process_id
748 << " from URL " << params.source_url.spec();
[email protected]c357acb42011-06-09 20:52:42749 SendAccessDenied(ipc_sender, routing_id, params.request_id);
750 return NULL;
751 }
752
[email protected]0d3e4a22011-06-23 19:02:52753 if (!extension->HasAPIPermission(params.name)) {
[email protected]c357acb42011-06-09 20:52:42754 LOG(ERROR) << "Extension " << extension->id() << " does not have "
755 << "permission to function: " << params.name;
756 SendAccessDenied(ipc_sender, routing_id, params.request_id);
757 return NULL;
758 }
759
760 ExtensionFunction* function =
761 FactoryRegistry::GetInstance()->NewFunction(params.name);
762 function->SetArgs(&params.arguments);
763 function->set_source_url(params.source_url);
764 function->set_request_id(params.request_id);
765 function->set_has_callback(params.has_callback);
766 function->set_user_gesture(params.user_gesture);
767 function->set_extension(extension);
[email protected]637bf322011-10-01 20:46:32768 function->set_profile_id(profile);
[email protected]c357acb42011-06-09 20:52:42769 return function;
770}
771
772// static
[email protected]c5dbef02011-05-13 05:06:09773void ExtensionFunctionDispatcher::SendAccessDenied(
[email protected]c357acb42011-06-09 20:52:42774 IPC::Message::Sender* ipc_sender, int routing_id, int request_id) {
775 ipc_sender->Send(new ExtensionMsg_Response(
776 routing_id, request_id, false, std::string(),
[email protected]c5dbef02011-05-13 05:06:09777 "Access to extension API denied."));
[email protected]bfdffe2b2009-04-24 22:05:35778}