1 // Copyright (c) 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // APIs must also be registered in
6 // libcef/common/extensions/api/_*_features.json files and possibly
7 // CefExtensionsDispatcherDelegate::PopulateSourceMap. See
8 // libcef/common/extensions/api/README.txt for additional details.
9
10 #include "libcef/browser/extensions/chrome_api_registration.h"
11
12 #include "libcef/browser/extensions/api/tabs/tabs_api.h"
13
14 #include "chrome/browser/extensions/api/content_settings/content_settings_api.h"
15 #include "chrome/browser/extensions/api/resources_private/resources_private_api.h"
16 #include "extensions/browser/api/alarms/alarms_api.h"
17 #include "extensions/browser/api/storage/storage_api.h"
18 #include "extensions/browser/extension_function_registry.h"
19
20 namespace extensions {
21 namespace api {
22 namespace cef {
23
24 namespace cefimpl = extensions::cef;
25
26 #define EXTENSION_FUNCTION_NAME(classname) classname::static_function_name()
27
28 // Maintain the same order as https://developer.chrome.com/extensions/api_index
29 // so chrome://extensions-support looks nice.
30 const char* const kSupportedAPIs[] = {
31 "resourcesPrivate",
32 EXTENSION_FUNCTION_NAME(ResourcesPrivateGetStringsFunction),
33 "alarms",
34 EXTENSION_FUNCTION_NAME(AlarmsCreateFunction),
35 EXTENSION_FUNCTION_NAME(AlarmsGetFunction),
36 EXTENSION_FUNCTION_NAME(AlarmsGetAllFunction),
37 EXTENSION_FUNCTION_NAME(AlarmsClearFunction),
38 EXTENSION_FUNCTION_NAME(AlarmsClearAllFunction),
39 "contentSettings",
40 EXTENSION_FUNCTION_NAME(ContentSettingsContentSettingClearFunction),
41 EXTENSION_FUNCTION_NAME(ContentSettingsContentSettingGetFunction),
42 EXTENSION_FUNCTION_NAME(ContentSettingsContentSettingSetFunction),
43 EXTENSION_FUNCTION_NAME(
44 ContentSettingsContentSettingGetResourceIdentifiersFunction),
45 "storage",
46 EXTENSION_FUNCTION_NAME(StorageStorageAreaGetFunction),
47 EXTENSION_FUNCTION_NAME(StorageStorageAreaSetFunction),
48 EXTENSION_FUNCTION_NAME(StorageStorageAreaRemoveFunction),
49 EXTENSION_FUNCTION_NAME(StorageStorageAreaClearFunction),
50 EXTENSION_FUNCTION_NAME(StorageStorageAreaGetBytesInUseFunction),
51 "tabs",
52 EXTENSION_FUNCTION_NAME(cefimpl::TabsGetFunction),
53 EXTENSION_FUNCTION_NAME(cefimpl::TabsCreateFunction),
54 EXTENSION_FUNCTION_NAME(cefimpl::TabsUpdateFunction),
55 EXTENSION_FUNCTION_NAME(cefimpl::TabsExecuteScriptFunction),
56 EXTENSION_FUNCTION_NAME(cefimpl::TabsInsertCSSFunction),
57 EXTENSION_FUNCTION_NAME(cefimpl::TabsRemoveCSSFunction),
58 EXTENSION_FUNCTION_NAME(cefimpl::TabsSetZoomFunction),
59 EXTENSION_FUNCTION_NAME(cefimpl::TabsGetZoomFunction),
60 EXTENSION_FUNCTION_NAME(cefimpl::TabsSetZoomSettingsFunction),
61 EXTENSION_FUNCTION_NAME(cefimpl::TabsGetZoomSettingsFunction),
62 nullptr, // Indicates end of array.
63 };
64
65 // Only add APIs to this list that have been tested in CEF.
66 // static
IsSupported(const std::string & name)67 bool ChromeFunctionRegistry::IsSupported(const std::string& name) {
68 for (size_t i = 0; kSupportedAPIs[i] != nullptr; ++i) {
69 if (name == kSupportedAPIs[i])
70 return true;
71 }
72 return false;
73 }
74
75 // Only add APIs to this list that have been tested in CEF.
76 // static
RegisterAll(ExtensionFunctionRegistry * registry)77 void ChromeFunctionRegistry::RegisterAll(ExtensionFunctionRegistry* registry) {
78 registry->RegisterFunction<ResourcesPrivateGetStringsFunction>();
79 registry->RegisterFunction<AlarmsCreateFunction>();
80 registry->RegisterFunction<AlarmsGetFunction>();
81 registry->RegisterFunction<AlarmsGetAllFunction>();
82 registry->RegisterFunction<AlarmsClearFunction>();
83 registry->RegisterFunction<AlarmsClearAllFunction>();
84 registry->RegisterFunction<ContentSettingsContentSettingClearFunction>();
85 registry->RegisterFunction<ContentSettingsContentSettingGetFunction>();
86 registry->RegisterFunction<ContentSettingsContentSettingSetFunction>();
87 registry->RegisterFunction<
88 ContentSettingsContentSettingGetResourceIdentifiersFunction>();
89 registry->RegisterFunction<StorageStorageAreaGetFunction>();
90 registry->RegisterFunction<StorageStorageAreaSetFunction>();
91 registry->RegisterFunction<StorageStorageAreaRemoveFunction>();
92 registry->RegisterFunction<StorageStorageAreaClearFunction>();
93 registry->RegisterFunction<StorageStorageAreaGetBytesInUseFunction>();
94 registry->RegisterFunction<cefimpl::TabsExecuteScriptFunction>();
95 registry->RegisterFunction<cefimpl::TabsInsertCSSFunction>();
96 registry->RegisterFunction<cefimpl::TabsRemoveCSSFunction>();
97 registry->RegisterFunction<cefimpl::TabsGetFunction>();
98 registry->RegisterFunction<cefimpl::TabsCreateFunction>();
99 registry->RegisterFunction<cefimpl::TabsUpdateFunction>();
100 registry->RegisterFunction<cefimpl::TabsSetZoomFunction>();
101 registry->RegisterFunction<cefimpl::TabsGetZoomFunction>();
102 registry->RegisterFunction<cefimpl::TabsSetZoomSettingsFunction>();
103 registry->RegisterFunction<cefimpl::TabsGetZoomSettingsFunction>();
104 }
105
106 } // namespace cef
107 } // namespace api
108 } // namespace extensions
109