OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/extensions/extension_function_dispatcher.h" | 5 #include "chrome/browser/extensions/extension_function_dispatcher.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 | 8 |
9 #include "base/json/json_string_value_serializer.h" | 9 #include "base/json/json_string_value_serializer.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
11 #include "base/memory/singleton.h" | |
12 #include "base/process_util.h" | 11 #include "base/process_util.h" |
13 #include "base/values.h" | 12 #include "base/values.h" |
14 #include "build/build_config.h" | 13 #include "build/build_config.h" |
15 #include "chrome/browser/accessibility/accessibility_extension_api.h" | |
16 #include "chrome/browser/bookmarks/bookmark_extension_api.h" | |
17 #include "chrome/browser/bookmarks/bookmark_manager_extension_api.h" | |
18 #include "chrome/browser/download/download_extension_api.h" | |
19 #include "chrome/browser/extensions/api/app/app_api.h" | |
20 #include "chrome/browser/extensions/api/browsing_data/browsing_data_api.h" | |
21 #include "chrome/browser/extensions/api/declarative/declarative_api.h" | |
22 #include "chrome/browser/extensions/api/dns/dns_api.h" | |
23 #include "chrome/browser/extensions/api/extension_action/extension_browser_actio
ns_api.h" | |
24 #include "chrome/browser/extensions/api/extension_action/extension_page_actions_
api.h" | |
25 #include "chrome/browser/extensions/api/permissions/permissions_api.h" | |
26 #include "chrome/browser/extensions/api/serial/serial_api.h" | |
27 #include "chrome/browser/extensions/api/socket/socket_api.h" | |
28 #include "chrome/browser/extensions/api/web_request/web_request_api.h" | |
29 #include "chrome/browser/extensions/execute_code_in_tab_function.h" | |
30 #include "chrome/browser/extensions/extension_activity_log.h" | 14 #include "chrome/browser/extensions/extension_activity_log.h" |
31 #include "chrome/browser/extensions/extension_chrome_auth_private_api.h" | |
32 #include "chrome/browser/extensions/extension_content_settings_api.h" | |
33 #include "chrome/browser/extensions/extension_context_menu_api.h" | |
34 #include "chrome/browser/extensions/extension_cookies_api.h" | |
35 #include "chrome/browser/extensions/extension_debugger_api.h" | |
36 #include "chrome/browser/extensions/extension_font_settings_api.h" | |
37 #include "chrome/browser/extensions/extension_function.h" | 15 #include "chrome/browser/extensions/extension_function.h" |
38 #include "chrome/browser/extensions/extension_i18n_api.h" | 16 #include "chrome/browser/extensions/extension_function_registry.h" |
39 #include "chrome/browser/extensions/extension_idle_api.h" | |
40 #include "chrome/browser/extensions/extension_managed_mode_api.h" | |
41 #include "chrome/browser/extensions/extension_management_api.h" | |
42 #include "chrome/browser/extensions/extension_metrics_module.h" | |
43 #include "chrome/browser/extensions/extension_module.h" | |
44 #include "chrome/browser/extensions/extension_omnibox_api.h" | |
45 #include "chrome/browser/extensions/extension_page_capture_api.h" | |
46 #include "chrome/browser/extensions/extension_preference_api.h" | |
47 #include "chrome/browser/extensions/extension_processes_api.h" | |
48 #include "chrome/browser/extensions/extension_service.h" | 17 #include "chrome/browser/extensions/extension_service.h" |
49 #include "chrome/browser/extensions/extension_tabs_module.h" | |
50 #include "chrome/browser/extensions/extension_test_api.h" | |
51 #include "chrome/browser/extensions/extension_tts_api.h" | |
52 #include "chrome/browser/extensions/extension_tts_engine_api.h" | |
53 #include "chrome/browser/extensions/extension_web_socket_proxy_private_api.h" | |
54 #include "chrome/browser/extensions/extension_web_ui.h" | 18 #include "chrome/browser/extensions/extension_web_ui.h" |
55 #include "chrome/browser/extensions/extension_webnavigation_api.h" | |
56 #include "chrome/browser/extensions/extension_webstore_private_api.h" | |
57 #include "chrome/browser/extensions/extensions_quota_service.h" | 19 #include "chrome/browser/extensions/extensions_quota_service.h" |
58 #include "chrome/browser/extensions/process_map.h" | 20 #include "chrome/browser/extensions/process_map.h" |
59 #include "chrome/browser/extensions/settings/settings_api.h" | |
60 #include "chrome/browser/extensions/system/system_api.h" | |
61 #include "chrome/browser/external_protocol/external_protocol_handler.h" | 21 #include "chrome/browser/external_protocol/external_protocol_handler.h" |
62 #include "chrome/browser/history/history_extension_api.h" | |
63 #include "chrome/browser/history/top_sites_extension_api.h" | |
64 #include "chrome/browser/infobars/infobar_extension_api.h" | |
65 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
66 #include "chrome/browser/renderer_host/chrome_render_message_filter.h" | 23 #include "chrome/browser/renderer_host/chrome_render_message_filter.h" |
67 #include "chrome/browser/rlz/rlz_extension_api.h" | |
68 #include "chrome/browser/speech/speech_input_extension_api.h" | |
69 #include "chrome/browser/ui/browser_list.h" | 24 #include "chrome/browser/ui/browser_list.h" |
70 #include "chrome/browser/ui/browser_window.h" | 25 #include "chrome/browser/ui/browser_window.h" |
71 #include "chrome/common/extensions/api/extension_api.h" | 26 #include "chrome/common/extensions/api/extension_api.h" |
72 #include "chrome/common/extensions/extension_messages.h" | 27 #include "chrome/common/extensions/extension_messages.h" |
73 #include "chrome/common/extensions/extension_set.h" | 28 #include "chrome/common/extensions/extension_set.h" |
74 #include "chrome/common/url_constants.h" | 29 #include "chrome/common/url_constants.h" |
75 #include "content/public/browser/render_process_host.h" | 30 #include "content/public/browser/render_process_host.h" |
76 #include "content/public/browser/render_view_host.h" | 31 #include "content/public/browser/render_view_host.h" |
77 #include "ipc/ipc_message.h" | 32 #include "ipc/ipc_message.h" |
78 #include "ipc/ipc_message_macros.h" | 33 #include "ipc/ipc_message_macros.h" |
79 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" | 34 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" |
80 #include "third_party/skia/include/core/SkBitmap.h" | 35 #include "third_party/skia/include/core/SkBitmap.h" |
81 | 36 #include "webkit/glue/resource_type.h" |
82 #if defined(TOOLKIT_VIEWS) | |
83 #include "chrome/browser/extensions/extension_input_api.h" | |
84 #endif | |
85 | |
86 #if defined(OS_CHROMEOS) && defined(USE_VIRTUAL_KEYBOARD) | |
87 #include "chrome/browser/extensions/extension_input_ui_api.h" | |
88 #endif | |
89 | |
90 #if defined(OS_CHROMEOS) | |
91 #include "chrome/browser/chromeos/extensions/file_browser_private_api.h" | |
92 #include "chrome/browser/chromeos/media/media_player_extension_api.h" | |
93 #include "chrome/browser/extensions/api/terminal/terminal_private_api.h" | |
94 #include "chrome/browser/extensions/extension_info_private_api_chromeos.h" | |
95 #include "chrome/browser/extensions/extension_input_ime_api.h" | |
96 #include "chrome/browser/extensions/extension_input_method_api.h" | |
97 #endif | |
98 | 37 |
99 using extensions::ExtensionAPI; | 38 using extensions::ExtensionAPI; |
100 using content::RenderViewHost; | 39 using content::RenderViewHost; |
101 using WebKit::WebSecurityOrigin; | 40 using WebKit::WebSecurityOrigin; |
102 | 41 |
103 // FactoryRegistry ------------------------------------------------------------- | |
104 | |
105 namespace { | |
106 | |
107 // Template for defining ExtensionFunctionFactory. | |
108 template<class T> | |
109 ExtensionFunction* NewExtensionFunction() { | |
110 return new T(); | |
111 } | |
112 | |
113 // Contains a list of all known extension functions and allows clients to | |
114 // create instances of them. | |
115 class FactoryRegistry { | |
116 public: | |
117 static FactoryRegistry* GetInstance(); | |
118 FactoryRegistry() { ResetFunctions(); } | |
119 | |
120 // Resets all functions to their default values. | |
121 void ResetFunctions(); | |
122 | |
123 // Adds all function names to 'names'. | |
124 void GetAllNames(std::vector<std::string>* names); | |
125 | |
126 // Allows overriding of specific functions (e.g. for testing). Functions | |
127 // must be previously registered. Returns true if successful. | |
128 bool OverrideFunction(const std::string& name, | |
129 ExtensionFunctionFactory factory); | |
130 | |
131 // Factory method for the ExtensionFunction registered as 'name'. | |
132 ExtensionFunction* NewFunction(const std::string& name); | |
133 | |
134 private: | |
135 template<class T> | |
136 void RegisterFunction() { | |
137 factories_[T::function_name()] = &NewExtensionFunction<T>; | |
138 } | |
139 | |
140 typedef std::map<std::string, ExtensionFunctionFactory> FactoryMap; | |
141 FactoryMap factories_; | |
142 }; | |
143 | |
144 FactoryRegistry* FactoryRegistry::GetInstance() { | |
145 return Singleton<FactoryRegistry>::get(); | |
146 } | |
147 | |
148 void FactoryRegistry::ResetFunctions() { | |
149 // Register all functions here. | |
150 | |
151 // Windows | |
152 RegisterFunction<GetWindowFunction>(); | |
153 RegisterFunction<GetCurrentWindowFunction>(); | |
154 RegisterFunction<GetLastFocusedWindowFunction>(); | |
155 RegisterFunction<GetAllWindowsFunction>(); | |
156 RegisterFunction<CreateWindowFunction>(); | |
157 RegisterFunction<UpdateWindowFunction>(); | |
158 RegisterFunction<RemoveWindowFunction>(); | |
159 | |
160 // Tabs | |
161 RegisterFunction<GetTabFunction>(); | |
162 RegisterFunction<GetCurrentTabFunction>(); | |
163 RegisterFunction<GetSelectedTabFunction>(); | |
164 RegisterFunction<GetAllTabsInWindowFunction>(); | |
165 RegisterFunction<QueryTabsFunction>(); | |
166 RegisterFunction<HighlightTabsFunction>(); | |
167 RegisterFunction<CreateTabFunction>(); | |
168 RegisterFunction<UpdateTabFunction>(); | |
169 RegisterFunction<MoveTabsFunction>(); | |
170 RegisterFunction<ReloadTabFunction>(); | |
171 RegisterFunction<RemoveTabsFunction>(); | |
172 RegisterFunction<DetectTabLanguageFunction>(); | |
173 RegisterFunction<CaptureVisibleTabFunction>(); | |
174 RegisterFunction<TabsExecuteScriptFunction>(); | |
175 RegisterFunction<TabsInsertCSSFunction>(); | |
176 | |
177 // Page Actions. | |
178 RegisterFunction<EnablePageActionFunction>(); | |
179 RegisterFunction<DisablePageActionFunction>(); | |
180 RegisterFunction<PageActionShowFunction>(); | |
181 RegisterFunction<PageActionHideFunction>(); | |
182 RegisterFunction<PageActionSetIconFunction>(); | |
183 RegisterFunction<PageActionSetTitleFunction>(); | |
184 RegisterFunction<PageActionSetPopupFunction>(); | |
185 RegisterFunction<PageActionGetTitleFunction>(); | |
186 RegisterFunction<PageActionGetPopupFunction>(); | |
187 | |
188 // Browser Actions. | |
189 RegisterFunction<BrowserActionSetIconFunction>(); | |
190 RegisterFunction<BrowserActionSetTitleFunction>(); | |
191 RegisterFunction<BrowserActionSetBadgeTextFunction>(); | |
192 RegisterFunction<BrowserActionSetBadgeBackgroundColorFunction>(); | |
193 RegisterFunction<BrowserActionSetPopupFunction>(); | |
194 RegisterFunction<BrowserActionGetTitleFunction>(); | |
195 RegisterFunction<BrowserActionGetBadgeTextFunction>(); | |
196 RegisterFunction<BrowserActionGetBadgeBackgroundColorFunction>(); | |
197 RegisterFunction<BrowserActionGetPopupFunction>(); | |
198 | |
199 // Browsing Data. | |
200 RegisterFunction<RemoveBrowsingDataFunction>(); | |
201 RegisterFunction<RemoveAppCacheFunction>(); | |
202 RegisterFunction<RemoveCacheFunction>(); | |
203 RegisterFunction<RemoveCookiesFunction>(); | |
204 RegisterFunction<RemoveDownloadsFunction>(); | |
205 RegisterFunction<RemoveFileSystemsFunction>(); | |
206 RegisterFunction<RemoveFormDataFunction>(); | |
207 RegisterFunction<RemoveHistoryFunction>(); | |
208 RegisterFunction<RemoveIndexedDBFunction>(); | |
209 RegisterFunction<RemoveLocalStorageFunction>(); | |
210 RegisterFunction<RemoveOriginBoundCertsFunction>(); | |
211 RegisterFunction<RemovePluginDataFunction>(); | |
212 RegisterFunction<RemovePasswordsFunction>(); | |
213 RegisterFunction<RemoveWebSQLFunction>(); | |
214 | |
215 // Bookmarks. | |
216 RegisterFunction<GetBookmarksFunction>(); | |
217 RegisterFunction<GetBookmarkChildrenFunction>(); | |
218 RegisterFunction<GetBookmarkRecentFunction>(); | |
219 RegisterFunction<GetBookmarkTreeFunction>(); | |
220 RegisterFunction<GetBookmarkSubTreeFunction>(); | |
221 RegisterFunction<SearchBookmarksFunction>(); | |
222 RegisterFunction<RemoveBookmarkFunction>(); | |
223 RegisterFunction<RemoveTreeBookmarkFunction>(); | |
224 RegisterFunction<CreateBookmarkFunction>(); | |
225 RegisterFunction<MoveBookmarkFunction>(); | |
226 RegisterFunction<UpdateBookmarkFunction>(); | |
227 | |
228 // Infobars. | |
229 RegisterFunction<ShowInfoBarFunction>(); | |
230 | |
231 // BookmarkManager | |
232 RegisterFunction<CopyBookmarkManagerFunction>(); | |
233 RegisterFunction<CutBookmarkManagerFunction>(); | |
234 RegisterFunction<PasteBookmarkManagerFunction>(); | |
235 RegisterFunction<CanPasteBookmarkManagerFunction>(); | |
236 RegisterFunction<ImportBookmarksFunction>(); | |
237 RegisterFunction<ExportBookmarksFunction>(); | |
238 RegisterFunction<SortChildrenBookmarkManagerFunction>(); | |
239 RegisterFunction<BookmarkManagerGetStringsFunction>(); | |
240 RegisterFunction<StartDragBookmarkManagerFunction>(); | |
241 RegisterFunction<DropBookmarkManagerFunction>(); | |
242 RegisterFunction<GetSubtreeBookmarkManagerFunction>(); | |
243 RegisterFunction<CanEditBookmarkManagerFunction>(); | |
244 | |
245 // History | |
246 RegisterFunction<AddUrlHistoryFunction>(); | |
247 RegisterFunction<DeleteAllHistoryFunction>(); | |
248 RegisterFunction<DeleteRangeHistoryFunction>(); | |
249 RegisterFunction<DeleteUrlHistoryFunction>(); | |
250 RegisterFunction<GetVisitsHistoryFunction>(); | |
251 RegisterFunction<SearchHistoryFunction>(); | |
252 | |
253 // Idle | |
254 RegisterFunction<ExtensionIdleQueryStateFunction>(); | |
255 | |
256 // I18N. | |
257 RegisterFunction<GetAcceptLanguagesFunction>(); | |
258 | |
259 // Processes. | |
260 RegisterFunction<GetProcessIdForTabFunction>(); | |
261 | |
262 // Metrics. | |
263 RegisterFunction<MetricsRecordUserActionFunction>(); | |
264 RegisterFunction<MetricsRecordValueFunction>(); | |
265 RegisterFunction<MetricsRecordPercentageFunction>(); | |
266 RegisterFunction<MetricsRecordCountFunction>(); | |
267 RegisterFunction<MetricsRecordSmallCountFunction>(); | |
268 RegisterFunction<MetricsRecordMediumCountFunction>(); | |
269 RegisterFunction<MetricsRecordTimeFunction>(); | |
270 RegisterFunction<MetricsRecordMediumTimeFunction>(); | |
271 RegisterFunction<MetricsRecordLongTimeFunction>(); | |
272 | |
273 // RLZ. | |
274 #if defined(OS_WIN) | |
275 RegisterFunction<RlzRecordProductEventFunction>(); | |
276 RegisterFunction<RlzGetAccessPointRlzFunction>(); | |
277 RegisterFunction<RlzSendFinancialPingFunction>(); | |
278 RegisterFunction<RlzClearProductStateFunction>(); | |
279 #endif | |
280 | |
281 // Cookies. | |
282 RegisterFunction<GetCookieFunction>(); | |
283 RegisterFunction<GetAllCookiesFunction>(); | |
284 RegisterFunction<SetCookieFunction>(); | |
285 RegisterFunction<RemoveCookieFunction>(); | |
286 RegisterFunction<GetAllCookieStoresFunction>(); | |
287 | |
288 // Test. | |
289 RegisterFunction<ExtensionTestPassFunction>(); | |
290 RegisterFunction<ExtensionTestFailFunction>(); | |
291 RegisterFunction<ExtensionTestLogFunction>(); | |
292 RegisterFunction<ExtensionTestQuotaResetFunction>(); | |
293 RegisterFunction<ExtensionTestCreateIncognitoTabFunction>(); | |
294 RegisterFunction<ExtensionTestSendMessageFunction>(); | |
295 RegisterFunction<ExtensionTestGetConfigFunction>(); | |
296 | |
297 // Accessibility. | |
298 RegisterFunction<GetFocusedControlFunction>(); | |
299 RegisterFunction<SetAccessibilityEnabledFunction>(); | |
300 RegisterFunction<GetAlertsForTabFunction>(); | |
301 | |
302 // Text-to-speech. | |
303 RegisterFunction<ExtensionTtsEngineSendTtsEventFunction>(); | |
304 RegisterFunction<ExtensionTtsGetVoicesFunction>(); | |
305 RegisterFunction<ExtensionTtsIsSpeakingFunction>(); | |
306 RegisterFunction<ExtensionTtsSpeakFunction>(); | |
307 RegisterFunction<ExtensionTtsStopSpeakingFunction>(); | |
308 | |
309 // Context Menus. | |
310 RegisterFunction<CreateContextMenuFunction>(); | |
311 RegisterFunction<UpdateContextMenuFunction>(); | |
312 RegisterFunction<RemoveContextMenuFunction>(); | |
313 RegisterFunction<RemoveAllContextMenusFunction>(); | |
314 | |
315 // Omnibox. | |
316 RegisterFunction<OmniboxSendSuggestionsFunction>(); | |
317 RegisterFunction<OmniboxSetDefaultSuggestionFunction>(); | |
318 | |
319 // Speech input. | |
320 RegisterFunction<StartSpeechInputFunction>(); | |
321 RegisterFunction<StopSpeechInputFunction>(); | |
322 RegisterFunction<IsRecordingSpeechInputFunction>(); | |
323 | |
324 #if defined(TOOLKIT_VIEWS) | |
325 // Input. | |
326 RegisterFunction<SendKeyboardEventInputFunction>(); | |
327 #endif | |
328 | |
329 #if defined(USE_VIRTUAL_KEYBOARD) | |
330 RegisterFunction<HideKeyboardFunction>(); | |
331 RegisterFunction<SetKeyboardHeightFunction>(); | |
332 #endif | |
333 | |
334 #if defined(OS_CHROMEOS) | |
335 // IME | |
336 RegisterFunction<SetCompositionFunction>(); | |
337 RegisterFunction<ClearCompositionFunction>(); | |
338 RegisterFunction<CommitTextFunction>(); | |
339 RegisterFunction<SetCandidateWindowPropertiesFunction>(); | |
340 RegisterFunction<SetCandidatesFunction>(); | |
341 RegisterFunction<SetCursorPositionFunction>(); | |
342 RegisterFunction<SetMenuItemsFunction>(); | |
343 RegisterFunction<UpdateMenuItemsFunction>(); | |
344 | |
345 RegisterFunction<InputEventHandled>(); | |
346 #if defined(USE_VIRTUAL_KEYBOARD) | |
347 RegisterFunction<CandidateClickedInputUiFunction>(); | |
348 RegisterFunction<CursorUpInputUiFunction>(); | |
349 RegisterFunction<CursorDownInputUiFunction>(); | |
350 RegisterFunction<PageUpInputUiFunction>(); | |
351 RegisterFunction<PageDownInputUiFunction>(); | |
352 RegisterFunction<RegisterInputUiFunction>(); | |
353 RegisterFunction<PageUpInputUiFunction>(); | |
354 RegisterFunction<PageDownInputUiFunction>(); | |
355 #endif | |
356 #endif | |
357 | |
358 // Managed mode. | |
359 RegisterFunction<GetManagedModeFunction>(); | |
360 RegisterFunction<EnterManagedModeFunction>(); | |
361 | |
362 // Management. | |
363 RegisterFunction<GetAllExtensionsFunction>(); | |
364 RegisterFunction<GetExtensionByIdFunction>(); | |
365 RegisterFunction<GetPermissionWarningsByIdFunction>(); | |
366 RegisterFunction<GetPermissionWarningsByManifestFunction>(); | |
367 RegisterFunction<LaunchAppFunction>(); | |
368 RegisterFunction<SetEnabledFunction>(); | |
369 RegisterFunction<UninstallFunction>(); | |
370 | |
371 // Extension module. | |
372 RegisterFunction<SetUpdateUrlDataFunction>(); | |
373 RegisterFunction<IsAllowedIncognitoAccessFunction>(); | |
374 RegisterFunction<IsAllowedFileSchemeAccessFunction>(); | |
375 | |
376 // WebstorePrivate. | |
377 RegisterFunction<GetBrowserLoginFunction>(); | |
378 RegisterFunction<GetStoreLoginFunction>(); | |
379 RegisterFunction<SetStoreLoginFunction>(); | |
380 RegisterFunction<InstallBundleFunction>(); | |
381 RegisterFunction<BeginInstallWithManifestFunction>(); | |
382 RegisterFunction<CompleteInstallFunction>(); | |
383 RegisterFunction<SilentlyInstallFunction>(); | |
384 RegisterFunction<GetWebGLStatusFunction>(); | |
385 | |
386 // WebNavigation. | |
387 RegisterFunction<GetFrameFunction>(); | |
388 RegisterFunction<GetAllFramesFunction>(); | |
389 | |
390 // WebRequest. | |
391 RegisterFunction<WebRequestAddEventListener>(); | |
392 RegisterFunction<WebRequestEventHandled>(); | |
393 RegisterFunction<WebRequestHandlerBehaviorChanged>(); | |
394 | |
395 // Preferences. | |
396 RegisterFunction<GetPreferenceFunction>(); | |
397 RegisterFunction<SetPreferenceFunction>(); | |
398 RegisterFunction<ClearPreferenceFunction>(); | |
399 | |
400 // ChromeOS-specific part of the API. | |
401 #if defined(OS_CHROMEOS) | |
402 // Device Customization. | |
403 RegisterFunction<GetChromeosInfoFunction>(); | |
404 | |
405 // FileBrowserPrivate functions. | |
406 // TODO(jamescook): Expose these on non-ChromeOS platforms so we can use | |
407 // the extension-based file picker on Aura. crbug.com/97424 | |
408 RegisterFunction<CancelFileDialogFunction>(); | |
409 RegisterFunction<ExecuteTasksFileBrowserFunction>(); | |
410 RegisterFunction<FileDialogStringsFunction>(); | |
411 RegisterFunction<GetFileTasksFileBrowserFunction>(); | |
412 RegisterFunction<GetVolumeMetadataFunction>(); | |
413 RegisterFunction<RequestLocalFileSystemFunction>(); | |
414 RegisterFunction<AddFileWatchBrowserFunction>(); | |
415 RegisterFunction<RemoveFileWatchBrowserFunction>(); | |
416 RegisterFunction<SelectFileFunction>(); | |
417 RegisterFunction<SelectFilesFunction>(); | |
418 RegisterFunction<AddMountFunction>(); | |
419 RegisterFunction<RemoveMountFunction>(); | |
420 RegisterFunction<GetMountPointsFunction>(); | |
421 RegisterFunction<GetSizeStatsFunction>(); | |
422 RegisterFunction<FormatDeviceFunction>(); | |
423 RegisterFunction<ViewFilesFunction>(); | |
424 RegisterFunction<ToggleFullscreenFunction>(); | |
425 RegisterFunction<IsFullscreenFunction>(); | |
426 RegisterFunction<GetGDataFilePropertiesFunction>(); | |
427 RegisterFunction<PinGDataFileFunction>(); | |
428 RegisterFunction<GetFileLocationsFunction>(); | |
429 RegisterFunction<GetGDataFilesFunction>(); | |
430 | |
431 // Mediaplayer | |
432 RegisterFunction<PlayMediaplayerFunction>(); | |
433 RegisterFunction<GetPlaylistMediaplayerFunction>(); | |
434 RegisterFunction<SetWindowHeightMediaplayerFunction>(); | |
435 RegisterFunction<CloseWindowMediaplayerFunction>(); | |
436 | |
437 // InputMethod | |
438 RegisterFunction<GetInputMethodFunction>(); | |
439 | |
440 // Terminal | |
441 RegisterFunction<OpenTerminalProcessFunction>(); | |
442 RegisterFunction<SendInputToTerminalProcessFunction>(); | |
443 RegisterFunction<CloseTerminalProcessFunction>(); | |
444 RegisterFunction<OnTerminalResizeFunction>(); | |
445 | |
446 #if defined(USE_VIRTUAL_KEYBOARD) | |
447 // Input | |
448 RegisterFunction<SendHandwritingStrokeFunction>(); | |
449 RegisterFunction<CancelHandwritingStrokesFunction>(); | |
450 #endif | |
451 #endif | |
452 | |
453 // Websocket to TCP proxy. Currently noop on anything other than ChromeOS. | |
454 RegisterFunction<WebSocketProxyPrivateGetPassportForTCPFunction>(); | |
455 RegisterFunction<WebSocketProxyPrivateGetURLForTCPFunction>(); | |
456 | |
457 // Debugger | |
458 RegisterFunction<AttachDebuggerFunction>(); | |
459 RegisterFunction<DetachDebuggerFunction>(); | |
460 RegisterFunction<SendCommandDebuggerFunction>(); | |
461 | |
462 // Settings | |
463 RegisterFunction<extensions::GetSettingsFunction>(); | |
464 RegisterFunction<extensions::SetSettingsFunction>(); | |
465 RegisterFunction<extensions::RemoveSettingsFunction>(); | |
466 RegisterFunction<extensions::ClearSettingsFunction>(); | |
467 RegisterFunction<extensions::GetBytesInUseSettingsFunction>(); | |
468 | |
469 // Content settings. | |
470 RegisterFunction<GetResourceIdentifiersFunction>(); | |
471 RegisterFunction<ClearContentSettingsFunction>(); | |
472 RegisterFunction<GetContentSettingFunction>(); | |
473 RegisterFunction<SetContentSettingFunction>(); | |
474 | |
475 // Font settings. | |
476 RegisterFunction<GetFontListFunction>(); | |
477 RegisterFunction<GetFontNameFunction>(); | |
478 RegisterFunction<SetFontNameFunction>(); | |
479 | |
480 // ChromeAuth settings. | |
481 RegisterFunction<SetCloudPrintCredentialsFunction>(); | |
482 | |
483 // Experimental App API. | |
484 RegisterFunction<AppNotifyFunction>(); | |
485 RegisterFunction<AppClearAllNotificationsFunction>(); | |
486 | |
487 // Permissions | |
488 RegisterFunction<ContainsPermissionsFunction>(); | |
489 RegisterFunction<GetAllPermissionsFunction>(); | |
490 RegisterFunction<RemovePermissionsFunction>(); | |
491 RegisterFunction<RequestPermissionsFunction>(); | |
492 | |
493 // Downloads | |
494 RegisterFunction<DownloadsDownloadFunction>(); | |
495 RegisterFunction<DownloadsSearchFunction>(); | |
496 RegisterFunction<DownloadsPauseFunction>(); | |
497 RegisterFunction<DownloadsResumeFunction>(); | |
498 RegisterFunction<DownloadsCancelFunction>(); | |
499 RegisterFunction<DownloadsEraseFunction>(); | |
500 RegisterFunction<DownloadsSetDestinationFunction>(); | |
501 RegisterFunction<DownloadsAcceptDangerFunction>(); | |
502 RegisterFunction<DownloadsShowFunction>(); | |
503 RegisterFunction<DownloadsDragFunction>(); | |
504 RegisterFunction<DownloadsGetFileIconFunction>(); | |
505 | |
506 // PageCapture | |
507 RegisterFunction<PageCaptureSaveAsMHTMLFunction>(); | |
508 | |
509 // TopSites | |
510 RegisterFunction<GetTopSitesFunction>(); | |
511 | |
512 // Serial | |
513 RegisterFunction<extensions::SerialOpenFunction>(); | |
514 RegisterFunction<extensions::SerialCloseFunction>(); | |
515 RegisterFunction<extensions::SerialReadFunction>(); | |
516 RegisterFunction<extensions::SerialWriteFunction>(); | |
517 | |
518 // Sockets | |
519 RegisterFunction<extensions::SocketCreateFunction>(); | |
520 RegisterFunction<extensions::SocketDestroyFunction>(); | |
521 RegisterFunction<extensions::SocketConnectFunction>(); | |
522 RegisterFunction<extensions::SocketDisconnectFunction>(); | |
523 RegisterFunction<extensions::SocketReadFunction>(); | |
524 RegisterFunction<extensions::SocketWriteFunction>(); | |
525 | |
526 // DNS | |
527 RegisterFunction<extensions::DNSResolveFunction>(); | |
528 | |
529 // System | |
530 RegisterFunction<extensions::GetIncognitoModeAvailabilityFunction>(); | |
531 RegisterFunction<extensions::GetUpdateStatusFunction>(); | |
532 | |
533 // Net | |
534 RegisterFunction<extensions::AddRulesFunction>(); | |
535 RegisterFunction<extensions::RemoveRulesFunction>(); | |
536 RegisterFunction<extensions::GetRulesFunction>(); | |
537 } | |
538 | |
539 void FactoryRegistry::GetAllNames(std::vector<std::string>* names) { | |
540 for (FactoryMap::iterator iter = factories_.begin(); | |
541 iter != factories_.end(); ++iter) { | |
542 names->push_back(iter->first); | |
543 } | |
544 } | |
545 | |
546 bool FactoryRegistry::OverrideFunction(const std::string& name, | |
547 ExtensionFunctionFactory factory) { | |
548 FactoryMap::iterator iter = factories_.find(name); | |
549 if (iter == factories_.end()) { | |
550 return false; | |
551 } else { | |
552 iter->second = factory; | |
553 return true; | |
554 } | |
555 } | |
556 | |
557 ExtensionFunction* FactoryRegistry::NewFunction(const std::string& name) { | |
558 FactoryMap::iterator iter = factories_.find(name); | |
559 DCHECK(iter != factories_.end()); | |
560 ExtensionFunction* function = iter->second(); | |
561 function->set_name(name); | |
562 return function; | |
563 } | |
564 | |
565 const char kAccessDenied[] = "access denied"; | 42 const char kAccessDenied[] = "access denied"; |
566 const char kQuotaExceeded[] = "quota exceeded"; | 43 const char kQuotaExceeded[] = "quota exceeded"; |
567 | 44 |
568 void LogSuccess(const Extension* extension, | 45 void LogSuccess(const Extension* extension, |
569 const ExtensionHostMsg_Request_Params& params) { | 46 const ExtensionHostMsg_Request_Params& params) { |
570 ExtensionActivityLog* extension_activity_log = | 47 ExtensionActivityLog* extension_activity_log = |
571 ExtensionActivityLog::GetInstance(); | 48 ExtensionActivityLog::GetInstance(); |
572 if (extension_activity_log->HasObservers(extension)) { | 49 if (extension_activity_log->HasObservers(extension)) { |
573 std::string call_signature = params.name + "("; | 50 std::string call_signature = params.name + "("; |
574 ListValue::const_iterator it = params.arguments.begin(); | 51 ListValue::const_iterator it = params.arguments.begin(); |
(...skipping 21 matching lines...) Expand all Loading... |
596 ExtensionActivityLog* extension_activity_log = | 73 ExtensionActivityLog* extension_activity_log = |
597 ExtensionActivityLog::GetInstance(); | 74 ExtensionActivityLog::GetInstance(); |
598 if (extension_activity_log->HasObservers(extension)) { | 75 if (extension_activity_log->HasObservers(extension)) { |
599 extension_activity_log->Log( | 76 extension_activity_log->Log( |
600 extension, | 77 extension, |
601 ExtensionActivityLog::ACTIVITY_EXTENSION_API_BLOCK, | 78 ExtensionActivityLog::ACTIVITY_EXTENSION_API_BLOCK, |
602 func_name + ": " + reason); | 79 func_name + ": " + reason); |
603 } | 80 } |
604 } | 81 } |
605 | 82 |
606 }; // namespace | |
607 | |
608 // ExtensionFunctionDispatcher ------------------------------------------------- | |
609 | |
610 void ExtensionFunctionDispatcher::GetAllFunctionNames( | 83 void ExtensionFunctionDispatcher::GetAllFunctionNames( |
611 std::vector<std::string>* names) { | 84 std::vector<std::string>* names) { |
612 FactoryRegistry::GetInstance()->GetAllNames(names); | 85 ExtensionFunctionRegistry::GetInstance()->GetAllNames(names); |
613 } | 86 } |
614 | 87 |
615 bool ExtensionFunctionDispatcher::OverrideFunction( | 88 bool ExtensionFunctionDispatcher::OverrideFunction( |
616 const std::string& name, ExtensionFunctionFactory factory) { | 89 const std::string& name, ExtensionFunctionFactory factory) { |
617 return FactoryRegistry::GetInstance()->OverrideFunction(name, factory); | 90 return ExtensionFunctionRegistry::GetInstance()->OverrideFunction(name, |
| 91 factory); |
618 } | 92 } |
619 | 93 |
620 void ExtensionFunctionDispatcher::ResetFunctions() { | 94 void ExtensionFunctionDispatcher::ResetFunctions() { |
621 FactoryRegistry::GetInstance()->ResetFunctions(); | 95 ExtensionFunctionRegistry::GetInstance()->ResetFunctions(); |
622 } | 96 } |
623 | 97 |
624 // static | 98 // static |
625 void ExtensionFunctionDispatcher::DispatchOnIOThread( | 99 void ExtensionFunctionDispatcher::DispatchOnIOThread( |
626 ExtensionInfoMap* extension_info_map, | 100 ExtensionInfoMap* extension_info_map, |
627 void* profile, | 101 void* profile, |
628 int render_process_id, | 102 int render_process_id, |
629 base::WeakPtr<ChromeRenderMessageFilter> ipc_sender, | 103 base::WeakPtr<ChromeRenderMessageFilter> ipc_sender, |
630 int routing_id, | 104 int routing_id, |
631 const ExtensionHostMsg_Request_Params& params) { | 105 const ExtensionHostMsg_Request_Params& params) { |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
787 } | 261 } |
788 | 262 |
789 if (!extension->HasAPIPermission(params.name)) { | 263 if (!extension->HasAPIPermission(params.name)) { |
790 LOG(ERROR) << "Extension " << extension->id() << " does not have " | 264 LOG(ERROR) << "Extension " << extension->id() << " does not have " |
791 << "permission to function: " << params.name; | 265 << "permission to function: " << params.name; |
792 SendAccessDenied(ipc_sender, routing_id, params.request_id); | 266 SendAccessDenied(ipc_sender, routing_id, params.request_id); |
793 return NULL; | 267 return NULL; |
794 } | 268 } |
795 | 269 |
796 ExtensionFunction* function = | 270 ExtensionFunction* function = |
797 FactoryRegistry::GetInstance()->NewFunction(params.name); | 271 ExtensionFunctionRegistry::GetInstance()->NewFunction(params.name); |
798 function->SetArgs(¶ms.arguments); | 272 function->SetArgs(¶ms.arguments); |
799 function->set_source_url(params.source_url); | 273 function->set_source_url(params.source_url); |
800 function->set_request_id(params.request_id); | 274 function->set_request_id(params.request_id); |
801 function->set_has_callback(params.has_callback); | 275 function->set_has_callback(params.has_callback); |
802 function->set_user_gesture(params.user_gesture); | 276 function->set_user_gesture(params.user_gesture); |
803 function->set_extension(extension); | 277 function->set_extension(extension); |
804 function->set_profile_id(profile); | 278 function->set_profile_id(profile); |
805 return function; | 279 return function; |
806 } | 280 } |
807 | 281 |
808 // static | 282 // static |
809 void ExtensionFunctionDispatcher::SendAccessDenied( | 283 void ExtensionFunctionDispatcher::SendAccessDenied( |
810 IPC::Message::Sender* ipc_sender, int routing_id, int request_id) { | 284 IPC::Message::Sender* ipc_sender, int routing_id, int request_id) { |
811 ipc_sender->Send(new ExtensionMsg_Response( | 285 ipc_sender->Send(new ExtensionMsg_Response( |
812 routing_id, request_id, false, std::string(), | 286 routing_id, request_id, false, std::string(), |
813 "Access to extension API denied.")); | 287 "Access to extension API denied.")); |
814 } | 288 } |
OLD | NEW |