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/browsingdata/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/permissions/permissions_api.h" | |
24 #include "chrome/browser/extensions/api/serial/serial_api.h" | |
25 #include "chrome/browser/extensions/api/socket/socket_api.h" | |
26 #include "chrome/browser/extensions/api/webrequest/webrequest_api.h" | |
27 #include "chrome/browser/extensions/execute_code_in_tab_function.h" | |
28 #include "chrome/browser/extensions/extension_activity_log.h" | 14 #include "chrome/browser/extensions/extension_activity_log.h" |
29 #include "chrome/browser/extensions/extension_browser_actions_api.h" | |
30 #include "chrome/browser/extensions/extension_chrome_auth_private_api.h" | |
31 #include "chrome/browser/extensions/extension_content_settings_api.h" | |
32 #include "chrome/browser/extensions/extension_context_menu_api.h" | |
33 #include "chrome/browser/extensions/extension_cookies_api.h" | |
34 #include "chrome/browser/extensions/extension_debugger_api.h" | |
35 #include "chrome/browser/extensions/extension_font_settings_api.h" | |
36 #include "chrome/browser/extensions/extension_function.h" | 15 #include "chrome/browser/extensions/extension_function.h" |
37 #include "chrome/browser/extensions/extension_i18n_api.h" | 16 #include "chrome/browser/extensions/extension_function_registry.h" |
38 #include "chrome/browser/extensions/extension_idle_api.h" | |
39 #include "chrome/browser/extensions/extension_managed_mode_api.h" | |
40 #include "chrome/browser/extensions/extension_management_api.h" | |
41 #include "chrome/browser/extensions/extension_metrics_module.h" | |
42 #include "chrome/browser/extensions/extension_module.h" | |
43 #include "chrome/browser/extensions/extension_omnibox_api.h" | |
44 #include "chrome/browser/extensions/extension_page_actions_module.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 | |
186 // Browser Actions. | |
187 RegisterFunction<BrowserActionSetIconFunction>(); | |
188 RegisterFunction<BrowserActionSetTitleFunction>(); | |
189 RegisterFunction<BrowserActionSetBadgeTextFunction>(); | |
190 RegisterFunction<BrowserActionSetBadgeBackgroundColorFunction>(); | |
191 RegisterFunction<BrowserActionSetPopupFunction>(); | |
192 | |
193 // Browsing Data. | |
194 RegisterFunction<RemoveBrowsingDataFunction>(); | |
195 RegisterFunction<RemoveAppCacheFunction>(); | |
196 RegisterFunction<RemoveCacheFunction>(); | |
197 RegisterFunction<RemoveCookiesFunction>(); | |
198 RegisterFunction<RemoveDownloadsFunction>(); | |
199 RegisterFunction<RemoveFileSystemsFunction>(); | |
200 RegisterFunction<RemoveFormDataFunction>(); | |
201 RegisterFunction<RemoveHistoryFunction>(); | |
202 RegisterFunction<RemoveIndexedDBFunction>(); | |
203 RegisterFunction<RemoveLocalStorageFunction>(); | |
204 RegisterFunction<RemoveOriginBoundCertsFunction>(); | |
205 RegisterFunction<RemovePluginDataFunction>(); | |
206 RegisterFunction<RemovePasswordsFunction>(); | |
207 RegisterFunction<RemoveWebSQLFunction>(); | |
208 | |
209 // Bookmarks. | |
210 RegisterFunction<GetBookmarksFunction>(); | |
211 RegisterFunction<GetBookmarkChildrenFunction>(); | |
212 RegisterFunction<GetBookmarkRecentFunction>(); | |
213 RegisterFunction<GetBookmarkTreeFunction>(); | |
214 RegisterFunction<GetBookmarkSubTreeFunction>(); | |
215 RegisterFunction<SearchBookmarksFunction>(); | |
216 RegisterFunction<RemoveBookmarkFunction>(); | |
217 RegisterFunction<RemoveTreeBookmarkFunction>(); | |
218 RegisterFunction<CreateBookmarkFunction>(); | |
219 RegisterFunction<MoveBookmarkFunction>(); | |
220 RegisterFunction<UpdateBookmarkFunction>(); | |
221 | |
222 // Infobars. | |
223 RegisterFunction<ShowInfoBarFunction>(); | |
224 | |
225 // BookmarkManager | |
226 RegisterFunction<CopyBookmarkManagerFunction>(); | |
227 RegisterFunction<CutBookmarkManagerFunction>(); | |
228 RegisterFunction<PasteBookmarkManagerFunction>(); | |
229 RegisterFunction<CanPasteBookmarkManagerFunction>(); | |
230 RegisterFunction<ImportBookmarksFunction>(); | |
231 RegisterFunction<ExportBookmarksFunction>(); | |
232 RegisterFunction<SortChildrenBookmarkManagerFunction>(); | |
233 RegisterFunction<BookmarkManagerGetStringsFunction>(); | |
234 RegisterFunction<StartDragBookmarkManagerFunction>(); | |
235 RegisterFunction<DropBookmarkManagerFunction>(); | |
236 RegisterFunction<GetSubtreeBookmarkManagerFunction>(); | |
237 RegisterFunction<CanEditBookmarkManagerFunction>(); | |
238 | |
239 // History | |
240 RegisterFunction<AddUrlHistoryFunction>(); | |
241 RegisterFunction<DeleteAllHistoryFunction>(); | |
242 RegisterFunction<DeleteRangeHistoryFunction>(); | |
243 RegisterFunction<DeleteUrlHistoryFunction>(); | |
244 RegisterFunction<GetVisitsHistoryFunction>(); | |
245 RegisterFunction<SearchHistoryFunction>(); | |
246 | |
247 // Idle | |
248 RegisterFunction<ExtensionIdleQueryStateFunction>(); | |
249 | |
250 // I18N. | |
251 RegisterFunction<GetAcceptLanguagesFunction>(); | |
252 | |
253 // Processes. | |
254 RegisterFunction<GetProcessIdForTabFunction>(); | |
255 | |
256 // Metrics. | |
257 RegisterFunction<MetricsRecordUserActionFunction>(); | |
258 RegisterFunction<MetricsRecordValueFunction>(); | |
259 RegisterFunction<MetricsRecordPercentageFunction>(); | |
260 RegisterFunction<MetricsRecordCountFunction>(); | |
261 RegisterFunction<MetricsRecordSmallCountFunction>(); | |
262 RegisterFunction<MetricsRecordMediumCountFunction>(); | |
263 RegisterFunction<MetricsRecordTimeFunction>(); | |
264 RegisterFunction<MetricsRecordMediumTimeFunction>(); | |
265 RegisterFunction<MetricsRecordLongTimeFunction>(); | |
266 | |
267 // RLZ. | |
268 #if defined(OS_WIN) | |
269 RegisterFunction<RlzRecordProductEventFunction>(); | |
270 RegisterFunction<RlzGetAccessPointRlzFunction>(); | |
271 RegisterFunction<RlzSendFinancialPingFunction>(); | |
272 RegisterFunction<RlzClearProductStateFunction>(); | |
273 #endif | |
274 | |
275 // Cookies. | |
276 RegisterFunction<GetCookieFunction>(); | |
277 RegisterFunction<GetAllCookiesFunction>(); | |
278 RegisterFunction<SetCookieFunction>(); | |
279 RegisterFunction<RemoveCookieFunction>(); | |
280 RegisterFunction<GetAllCookieStoresFunction>(); | |
281 | |
282 // Test. | |
283 RegisterFunction<ExtensionTestPassFunction>(); | |
284 RegisterFunction<ExtensionTestFailFunction>(); | |
285 RegisterFunction<ExtensionTestLogFunction>(); | |
286 RegisterFunction<ExtensionTestQuotaResetFunction>(); | |
287 RegisterFunction<ExtensionTestCreateIncognitoTabFunction>(); | |
288 RegisterFunction<ExtensionTestSendMessageFunction>(); | |
289 RegisterFunction<ExtensionTestGetConfigFunction>(); | |
290 | |
291 // Accessibility. | |
292 RegisterFunction<GetFocusedControlFunction>(); | |
293 RegisterFunction<SetAccessibilityEnabledFunction>(); | |
294 RegisterFunction<GetAlertsForTabFunction>(); | |
295 | |
296 // Text-to-speech. | |
297 RegisterFunction<ExtensionTtsEngineSendTtsEventFunction>(); | |
298 RegisterFunction<ExtensionTtsGetVoicesFunction>(); | |
299 RegisterFunction<ExtensionTtsIsSpeakingFunction>(); | |
300 RegisterFunction<ExtensionTtsSpeakFunction>(); | |
301 RegisterFunction<ExtensionTtsStopSpeakingFunction>(); | |
302 | |
303 // Context Menus. | |
304 RegisterFunction<CreateContextMenuFunction>(); | |
305 RegisterFunction<UpdateContextMenuFunction>(); | |
306 RegisterFunction<RemoveContextMenuFunction>(); | |
307 RegisterFunction<RemoveAllContextMenusFunction>(); | |
308 | |
309 // Omnibox. | |
310 RegisterFunction<OmniboxSendSuggestionsFunction>(); | |
311 RegisterFunction<OmniboxSetDefaultSuggestionFunction>(); | |
312 | |
313 // Speech input. | |
314 RegisterFunction<StartSpeechInputFunction>(); | |
315 RegisterFunction<StopSpeechInputFunction>(); | |
316 RegisterFunction<IsRecordingSpeechInputFunction>(); | |
317 | |
318 #if defined(TOOLKIT_VIEWS) | |
319 // Input. | |
320 RegisterFunction<SendKeyboardEventInputFunction>(); | |
321 #endif | |
322 | |
323 #if defined(USE_VIRTUAL_KEYBOARD) | |
324 RegisterFunction<HideKeyboardFunction>(); | |
325 RegisterFunction<SetKeyboardHeightFunction>(); | |
326 #endif | |
327 | |
328 #if defined(OS_CHROMEOS) | |
329 // IME | |
330 RegisterFunction<SetCompositionFunction>(); | |
331 RegisterFunction<ClearCompositionFunction>(); | |
332 RegisterFunction<CommitTextFunction>(); | |
333 RegisterFunction<SetCandidateWindowPropertiesFunction>(); | |
334 RegisterFunction<SetCandidatesFunction>(); | |
335 RegisterFunction<SetCursorPositionFunction>(); | |
336 RegisterFunction<SetMenuItemsFunction>(); | |
337 RegisterFunction<UpdateMenuItemsFunction>(); | |
338 | |
339 RegisterFunction<InputEventHandled>(); | |
340 #if defined(USE_VIRTUAL_KEYBOARD) | |
341 RegisterFunction<CandidateClickedInputUiFunction>(); | |
342 RegisterFunction<CursorUpInputUiFunction>(); | |
343 RegisterFunction<CursorDownInputUiFunction>(); | |
344 RegisterFunction<PageUpInputUiFunction>(); | |
345 RegisterFunction<PageDownInputUiFunction>(); | |
346 RegisterFunction<RegisterInputUiFunction>(); | |
347 RegisterFunction<PageUpInputUiFunction>(); | |
348 RegisterFunction<PageDownInputUiFunction>(); | |
349 #endif | |
350 #endif | |
351 | |
352 // Managed mode. | |
353 RegisterFunction<GetManagedModeFunction>(); | |
354 RegisterFunction<EnterManagedModeFunction>(); | |
355 | |
356 // Management. | |
357 RegisterFunction<GetAllExtensionsFunction>(); | |
358 RegisterFunction<GetExtensionByIdFunction>(); | |
359 RegisterFunction<GetPermissionWarningsByIdFunction>(); | |
360 RegisterFunction<GetPermissionWarningsByManifestFunction>(); | |
361 RegisterFunction<LaunchAppFunction>(); | |
362 RegisterFunction<SetEnabledFunction>(); | |
363 RegisterFunction<UninstallFunction>(); | |
364 | |
365 // Extension module. | |
366 RegisterFunction<SetUpdateUrlDataFunction>(); | |
367 RegisterFunction<IsAllowedIncognitoAccessFunction>(); | |
368 RegisterFunction<IsAllowedFileSchemeAccessFunction>(); | |
369 | |
370 // WebstorePrivate. | |
371 RegisterFunction<GetBrowserLoginFunction>(); | |
372 RegisterFunction<GetStoreLoginFunction>(); | |
373 RegisterFunction<SetStoreLoginFunction>(); | |
374 RegisterFunction<InstallBundleFunction>(); | |
375 RegisterFunction<BeginInstallWithManifestFunction>(); | |
376 RegisterFunction<CompleteInstallFunction>(); | |
377 RegisterFunction<SilentlyInstallFunction>(); | |
378 RegisterFunction<GetWebGLStatusFunction>(); | |
379 | |
380 // WebNavigation. | |
381 RegisterFunction<GetFrameFunction>(); | |
382 RegisterFunction<GetAllFramesFunction>(); | |
383 | |
384 // WebRequest. | |
385 RegisterFunction<WebRequestAddEventListener>(); | |
386 RegisterFunction<WebRequestEventHandled>(); | |
387 RegisterFunction<WebRequestHandlerBehaviorChanged>(); | |
388 | |
389 // Preferences. | |
390 RegisterFunction<GetPreferenceFunction>(); | |
391 RegisterFunction<SetPreferenceFunction>(); | |
392 RegisterFunction<ClearPreferenceFunction>(); | |
393 | |
394 // ChromeOS-specific part of the API. | |
395 #if defined(OS_CHROMEOS) | |
396 // Device Customization. | |
397 RegisterFunction<GetChromeosInfoFunction>(); | |
398 | |
399 // FileBrowserPrivate functions. | |
400 // TODO(jamescook): Expose these on non-ChromeOS platforms so we can use | |
401 // the extension-based file picker on Aura. crbug.com/97424 | |
402 RegisterFunction<CancelFileDialogFunction>(); | |
403 RegisterFunction<ExecuteTasksFileBrowserFunction>(); | |
404 RegisterFunction<FileDialogStringsFunction>(); | |
405 RegisterFunction<GetFileTasksFileBrowserFunction>(); | |
406 RegisterFunction<GetVolumeMetadataFunction>(); | |
407 RegisterFunction<RequestLocalFileSystemFunction>(); | |
408 RegisterFunction<AddFileWatchBrowserFunction>(); | |
409 RegisterFunction<RemoveFileWatchBrowserFunction>(); | |
410 RegisterFunction<SelectFileFunction>(); | |
411 RegisterFunction<SelectFilesFunction>(); | |
412 RegisterFunction<AddMountFunction>(); | |
413 RegisterFunction<RemoveMountFunction>(); | |
414 RegisterFunction<GetMountPointsFunction>(); | |
415 RegisterFunction<GetSizeStatsFunction>(); | |
416 RegisterFunction<FormatDeviceFunction>(); | |
417 RegisterFunction<ViewFilesFunction>(); | |
418 RegisterFunction<ToggleFullscreenFunction>(); | |
419 RegisterFunction<IsFullscreenFunction>(); | |
420 RegisterFunction<GetGDataFilePropertiesFunction>(); | |
421 RegisterFunction<PinGDataFileFunction>(); | |
422 RegisterFunction<GetFileLocationsFunction>(); | |
423 RegisterFunction<GetGDataFilesFunction>(); | |
424 | |
425 // Mediaplayer | |
426 RegisterFunction<PlayMediaplayerFunction>(); | |
427 RegisterFunction<GetPlaylistMediaplayerFunction>(); | |
428 RegisterFunction<SetWindowHeightMediaplayerFunction>(); | |
429 RegisterFunction<CloseWindowMediaplayerFunction>(); | |
430 | |
431 // InputMethod | |
432 RegisterFunction<GetInputMethodFunction>(); | |
433 | |
434 // Terminal | |
435 RegisterFunction<OpenTerminalProcessFunction>(); | |
436 RegisterFunction<SendInputToTerminalProcessFunction>(); | |
437 RegisterFunction<CloseTerminalProcessFunction>(); | |
438 RegisterFunction<OnTerminalResizeFunction>(); | |
439 | |
440 #if defined(USE_VIRTUAL_KEYBOARD) | |
441 // Input | |
442 RegisterFunction<SendHandwritingStrokeFunction>(); | |
443 RegisterFunction<CancelHandwritingStrokesFunction>(); | |
444 #endif | |
445 #endif | |
446 | |
447 // Websocket to TCP proxy. Currently noop on anything other than ChromeOS. | |
448 RegisterFunction<WebSocketProxyPrivateGetPassportForTCPFunction>(); | |
449 RegisterFunction<WebSocketProxyPrivateGetURLForTCPFunction>(); | |
450 | |
451 // Debugger | |
452 RegisterFunction<AttachDebuggerFunction>(); | |
453 RegisterFunction<DetachDebuggerFunction>(); | |
454 RegisterFunction<SendCommandDebuggerFunction>(); | |
455 | |
456 // Settings | |
457 RegisterFunction<extensions::GetSettingsFunction>(); | |
458 RegisterFunction<extensions::SetSettingsFunction>(); | |
459 RegisterFunction<extensions::RemoveSettingsFunction>(); | |
460 RegisterFunction<extensions::ClearSettingsFunction>(); | |
461 RegisterFunction<extensions::GetBytesInUseSettingsFunction>(); | |
462 | |
463 // Content settings. | |
464 RegisterFunction<GetResourceIdentifiersFunction>(); | |
465 RegisterFunction<ClearContentSettingsFunction>(); | |
466 RegisterFunction<GetContentSettingFunction>(); | |
467 RegisterFunction<SetContentSettingFunction>(); | |
468 | |
469 // Font settings. | |
470 RegisterFunction<GetFontListFunction>(); | |
471 RegisterFunction<GetFontNameFunction>(); | |
472 RegisterFunction<SetFontNameFunction>(); | |
473 | |
474 // ChromeAuth settings. | |
475 RegisterFunction<SetCloudPrintCredentialsFunction>(); | |
476 | |
477 // Experimental App API. | |
478 RegisterFunction<AppNotifyFunction>(); | |
479 RegisterFunction<AppClearAllNotificationsFunction>(); | |
480 | |
481 // Permissions | |
482 RegisterFunction<ContainsPermissionsFunction>(); | |
483 RegisterFunction<GetAllPermissionsFunction>(); | |
484 RegisterFunction<RemovePermissionsFunction>(); | |
485 RegisterFunction<RequestPermissionsFunction>(); | |
486 | |
487 // Downloads | |
488 RegisterFunction<DownloadsDownloadFunction>(); | |
489 RegisterFunction<DownloadsSearchFunction>(); | |
490 RegisterFunction<DownloadsPauseFunction>(); | |
491 RegisterFunction<DownloadsResumeFunction>(); | |
492 RegisterFunction<DownloadsCancelFunction>(); | |
493 RegisterFunction<DownloadsEraseFunction>(); | |
494 RegisterFunction<DownloadsSetDestinationFunction>(); | |
495 RegisterFunction<DownloadsAcceptDangerFunction>(); | |
496 RegisterFunction<DownloadsShowFunction>(); | |
497 RegisterFunction<DownloadsDragFunction>(); | |
498 RegisterFunction<DownloadsGetFileIconFunction>(); | |
499 | |
500 // PageCapture | |
501 RegisterFunction<PageCaptureSaveAsMHTMLFunction>(); | |
502 | |
503 // TopSites | |
504 RegisterFunction<GetTopSitesFunction>(); | |
505 | |
506 // Serial | |
507 RegisterFunction<extensions::SerialOpenFunction>(); | |
508 RegisterFunction<extensions::SerialCloseFunction>(); | |
509 RegisterFunction<extensions::SerialReadFunction>(); | |
510 RegisterFunction<extensions::SerialWriteFunction>(); | |
511 | |
512 // Sockets | |
513 RegisterFunction<extensions::SocketCreateFunction>(); | |
514 RegisterFunction<extensions::SocketDestroyFunction>(); | |
515 RegisterFunction<extensions::SocketConnectFunction>(); | |
516 RegisterFunction<extensions::SocketDisconnectFunction>(); | |
517 RegisterFunction<extensions::SocketReadFunction>(); | |
518 RegisterFunction<extensions::SocketWriteFunction>(); | |
519 | |
520 // DNS | |
521 RegisterFunction<extensions::DNSResolveFunction>(); | |
522 | |
523 // System | |
524 RegisterFunction<extensions::GetIncognitoModeAvailabilityFunction>(); | |
525 RegisterFunction<extensions::GetUpdateStatusFunction>(); | |
526 | |
527 // Net | |
528 RegisterFunction<extensions::AddRulesFunction>(); | |
529 RegisterFunction<extensions::RemoveRulesFunction>(); | |
530 RegisterFunction<extensions::GetRulesFunction>(); | |
531 } | |
532 | |
533 void FactoryRegistry::GetAllNames(std::vector<std::string>* names) { | |
534 for (FactoryMap::iterator iter = factories_.begin(); | |
535 iter != factories_.end(); ++iter) { | |
536 names->push_back(iter->first); | |
537 } | |
538 } | |
539 | |
540 bool FactoryRegistry::OverrideFunction(const std::string& name, | |
541 ExtensionFunctionFactory factory) { | |
542 FactoryMap::iterator iter = factories_.find(name); | |
543 if (iter == factories_.end()) { | |
544 return false; | |
545 } else { | |
546 iter->second = factory; | |
547 return true; | |
548 } | |
549 } | |
550 | |
551 ExtensionFunction* FactoryRegistry::NewFunction(const std::string& name) { | |
552 FactoryMap::iterator iter = factories_.find(name); | |
553 DCHECK(iter != factories_.end()); | |
554 ExtensionFunction* function = iter->second(); | |
555 function->set_name(name); | |
556 return function; | |
557 } | |
558 | |
559 const char kAccessDenied[] = "access denied"; | 42 const char kAccessDenied[] = "access denied"; |
560 const char kQuotaExceeded[] = "quota exceeded"; | 43 const char kQuotaExceeded[] = "quota exceeded"; |
561 | 44 |
562 void LogSuccess(const Extension* extension, | 45 void LogSuccess(const Extension* extension, |
563 const ExtensionHostMsg_Request_Params& params) { | 46 const ExtensionHostMsg_Request_Params& params) { |
564 ExtensionActivityLog* extension_activity_log = | 47 ExtensionActivityLog* extension_activity_log = |
565 ExtensionActivityLog::GetInstance(); | 48 ExtensionActivityLog::GetInstance(); |
566 if (extension_activity_log->HasObservers(extension)) { | 49 if (extension_activity_log->HasObservers(extension)) { |
567 std::string call_signature = params.name + "("; | 50 std::string call_signature = params.name + "("; |
568 ListValue::const_iterator it = params.arguments.begin(); | 51 ListValue::const_iterator it = params.arguments.begin(); |
(...skipping 21 matching lines...) Expand all Loading... |
590 ExtensionActivityLog* extension_activity_log = | 73 ExtensionActivityLog* extension_activity_log = |
591 ExtensionActivityLog::GetInstance(); | 74 ExtensionActivityLog::GetInstance(); |
592 if (extension_activity_log->HasObservers(extension)) { | 75 if (extension_activity_log->HasObservers(extension)) { |
593 extension_activity_log->Log( | 76 extension_activity_log->Log( |
594 extension, | 77 extension, |
595 ExtensionActivityLog::ACTIVITY_EXTENSION_API_BLOCK, | 78 ExtensionActivityLog::ACTIVITY_EXTENSION_API_BLOCK, |
596 func_name + ": " + reason); | 79 func_name + ": " + reason); |
597 } | 80 } |
598 } | 81 } |
599 | 82 |
600 }; // namespace | |
601 | |
602 // ExtensionFunctionDispatcher ------------------------------------------------- | |
603 | |
604 void ExtensionFunctionDispatcher::GetAllFunctionNames( | 83 void ExtensionFunctionDispatcher::GetAllFunctionNames( |
605 std::vector<std::string>* names) { | 84 std::vector<std::string>* names) { |
606 FactoryRegistry::GetInstance()->GetAllNames(names); | 85 ExtensionFunctionRegistry::GetInstance()->GetAllNames(names); |
607 } | 86 } |
608 | 87 |
609 bool ExtensionFunctionDispatcher::OverrideFunction( | 88 bool ExtensionFunctionDispatcher::OverrideFunction( |
610 const std::string& name, ExtensionFunctionFactory factory) { | 89 const std::string& name, ExtensionFunctionFactory factory) { |
611 return FactoryRegistry::GetInstance()->OverrideFunction(name, factory); | 90 return ExtensionFunctionRegistry::GetInstance()->OverrideFunction(name, |
| 91 factory); |
612 } | 92 } |
613 | 93 |
614 void ExtensionFunctionDispatcher::ResetFunctions() { | 94 void ExtensionFunctionDispatcher::ResetFunctions() { |
615 FactoryRegistry::GetInstance()->ResetFunctions(); | 95 ExtensionFunctionRegistry::GetInstance()->ResetFunctions(); |
616 } | 96 } |
617 | 97 |
618 // static | 98 // static |
619 void ExtensionFunctionDispatcher::DispatchOnIOThread( | 99 void ExtensionFunctionDispatcher::DispatchOnIOThread( |
620 ExtensionInfoMap* extension_info_map, | 100 ExtensionInfoMap* extension_info_map, |
621 void* profile, | 101 void* profile, |
622 int render_process_id, | 102 int render_process_id, |
623 base::WeakPtr<ChromeRenderMessageFilter> ipc_sender, | 103 base::WeakPtr<ChromeRenderMessageFilter> ipc_sender, |
624 int routing_id, | 104 int routing_id, |
625 const ExtensionHostMsg_Request_Params& params) { | 105 const ExtensionHostMsg_Request_Params& params) { |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
781 } | 261 } |
782 | 262 |
783 if (!extension->HasAPIPermission(params.name)) { | 263 if (!extension->HasAPIPermission(params.name)) { |
784 LOG(ERROR) << "Extension " << extension->id() << " does not have " | 264 LOG(ERROR) << "Extension " << extension->id() << " does not have " |
785 << "permission to function: " << params.name; | 265 << "permission to function: " << params.name; |
786 SendAccessDenied(ipc_sender, routing_id, params.request_id); | 266 SendAccessDenied(ipc_sender, routing_id, params.request_id); |
787 return NULL; | 267 return NULL; |
788 } | 268 } |
789 | 269 |
790 ExtensionFunction* function = | 270 ExtensionFunction* function = |
791 FactoryRegistry::GetInstance()->NewFunction(params.name); | 271 ExtensionFunctionRegistry::GetInstance()->NewFunction(params.name); |
792 function->SetArgs(¶ms.arguments); | 272 function->SetArgs(¶ms.arguments); |
793 function->set_source_url(params.source_url); | 273 function->set_source_url(params.source_url); |
794 function->set_request_id(params.request_id); | 274 function->set_request_id(params.request_id); |
795 function->set_has_callback(params.has_callback); | 275 function->set_has_callback(params.has_callback); |
796 function->set_user_gesture(params.user_gesture); | 276 function->set_user_gesture(params.user_gesture); |
797 function->set_extension(extension); | 277 function->set_extension(extension); |
798 function->set_profile_id(profile); | 278 function->set_profile_id(profile); |
799 return function; | 279 return function; |
800 } | 280 } |
801 | 281 |
802 // static | 282 // static |
803 void ExtensionFunctionDispatcher::SendAccessDenied( | 283 void ExtensionFunctionDispatcher::SendAccessDenied( |
804 IPC::Message::Sender* ipc_sender, int routing_id, int request_id) { | 284 IPC::Message::Sender* ipc_sender, int routing_id, int request_id) { |
805 ipc_sender->Send(new ExtensionMsg_Response( | 285 ipc_sender->Send(new ExtensionMsg_Response( |
806 routing_id, request_id, false, std::string(), | 286 routing_id, request_id, false, std::string(), |
807 "Access to extension API denied.")); | 287 "Access to extension API denied.")); |
808 } | 288 } |
OLD | NEW |