Atomic: Notify Watcher to observe device fd
[chromium-blink-merge.git] / extensions / common / permissions / extensions_api_permissions.cc
blob3b21c61aecb2567f7f00c36f7dbc0690c6a2bd6b
1 // Copyright 2014 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.
5 #include "extensions/common/permissions/extensions_api_permissions.h"
7 #include <vector>
9 #include "extensions/common/permissions/api_permission.h"
10 #include "extensions/common/permissions/permission_message.h"
11 #include "extensions/common/permissions/socket_permission.h"
12 #include "extensions/common/permissions/usb_device_permission.h"
13 #include "grit/extensions_strings.h"
15 namespace extensions {
17 namespace {
19 const char kOldAlwaysOnTopWindowsPermission[] = "alwaysOnTopWindows";
20 const char kOldFullscreenPermission[] = "fullscreen";
21 const char kOldOverrideEscFullscreenPermission[] = "overrideEscFullscreen";
22 const char kOldUnlimitedStoragePermission[] = "unlimited_storage";
24 template <typename T>
25 APIPermission* CreateAPIPermission(const APIPermissionInfo* permission) {
26 return new T(permission);
29 } // namespace
31 std::vector<APIPermissionInfo*> ExtensionsAPIPermissions::GetAllPermissions()
32 const {
33 // WARNING: If you are modifying a permission message in this list, be sure to
34 // add the corresponding permission message rule to
35 // ChromePermissionMessageProvider::GetCoalescedPermissionMessages as well.
36 // TODO(sashab): Remove all permission messages from this list, once
37 // GetCoalescedPermissionMessages() is the only way of generating permission
38 // messages.
39 APIPermissionInfo::InitInfo permissions_to_register[] = {
40 {APIPermission::kAlarms, "alarms"},
41 {APIPermission::kAlphaEnabled, "app.window.alpha"},
42 {APIPermission::kAlwaysOnTopWindows, "app.window.alwaysOnTop"},
43 {APIPermission::kAppView,
44 "appview",
45 APIPermissionInfo::kFlagCannotBeOptional},
46 {APIPermission::kAudio, "audio"},
47 {APIPermission::kAudioCapture,
48 "audioCapture",
49 APIPermissionInfo::kFlagNone,
50 IDS_EXTENSION_PROMPT_WARNING_AUDIO_CAPTURE,
51 PermissionMessage::kAudioCapture},
52 {APIPermission::kBluetoothPrivate,
53 "bluetoothPrivate",
54 APIPermissionInfo::kFlagCannotBeOptional,
55 IDS_EXTENSION_PROMPT_WARNING_BLUETOOTH_PRIVATE,
56 PermissionMessage::kBluetoothPrivate},
57 {APIPermission::kClipboardRead,
58 "clipboardRead",
59 APIPermissionInfo::kFlagSupportsContentCapabilities,
60 IDS_EXTENSION_PROMPT_WARNING_CLIPBOARD,
61 PermissionMessage::kClipboard},
62 {APIPermission::kClipboardWrite,
63 "clipboardWrite",
64 APIPermissionInfo::kFlagSupportsContentCapabilities},
65 {APIPermission::kDeclarativeWebRequest,
66 "declarativeWebRequest",
67 APIPermissionInfo::kFlagNone,
68 IDS_EXTENSION_PROMPT_WARNING_DECLARATIVE_WEB_REQUEST,
69 PermissionMessage::kDeclarativeWebRequest},
70 {APIPermission::kDiagnostics,
71 "diagnostics",
72 APIPermissionInfo::kFlagCannotBeOptional},
73 {APIPermission::kDns, "dns"},
74 {APIPermission::kDocumentScan,
75 "documentScan",
76 APIPermissionInfo::kFlagNone,
77 IDS_EXTENSION_PROMPT_WARNING_DOCUMENT_SCAN,
78 PermissionMessage::kDocumentScan},
79 {APIPermission::kExtensionView,
80 "extensionview",
81 APIPermissionInfo::kFlagCannotBeOptional},
82 {APIPermission::kExternallyConnectableAllUrls,
83 "externally_connectable.all_urls"},
84 {APIPermission::kFullscreen, "app.window.fullscreen"},
85 {APIPermission::kHid, "hid", APIPermissionInfo::kFlagNone},
86 {APIPermission::kImeWindowEnabled, "app.window.ime"},
87 {APIPermission::kOverrideEscFullscreen,
88 "app.window.fullscreen.overrideEsc"},
89 {APIPermission::kIdle, "idle"},
90 {APIPermission::kNetworkingConfig,
91 "networking.config",
92 APIPermissionInfo::kFlagNone,
93 IDS_EXTENSION_PROMPT_WARNING_NETWORKING_CONFIG,
94 PermissionMessage::kNetworkingConfig},
95 {APIPermission::kNetworkingPrivate,
96 "networkingPrivate",
97 APIPermissionInfo::kFlagCannotBeOptional,
98 IDS_EXTENSION_PROMPT_WARNING_NETWORKING_PRIVATE,
99 PermissionMessage::kNetworkingPrivate},
100 {APIPermission::kPower, "power"},
101 {APIPermission::kPrinterProvider, "printerProvider"},
102 {APIPermission::kSerial,
103 "serial",
104 APIPermissionInfo::kFlagNone,
105 IDS_EXTENSION_PROMPT_WARNING_SERIAL,
106 PermissionMessage::kSerial},
107 // Because warning messages for the "socket" permission vary based
108 // on the permissions parameters, no message ID or message text is
109 // specified here. The message ID and text used will be
110 // determined at run-time in the |SocketPermission| class.
111 {APIPermission::kSocket,
112 "socket",
113 APIPermissionInfo::kFlagCannotBeOptional,
115 PermissionMessage::kNone,
116 &CreateAPIPermission<SocketPermission>},
117 {APIPermission::kStorage, "storage"},
118 {APIPermission::kSystemCpu, "system.cpu"},
119 {APIPermission::kSystemMemory, "system.memory"},
120 {APIPermission::kSystemNetwork, "system.network"},
121 {APIPermission::kSystemDisplay, "system.display"},
122 {APIPermission::kSystemStorage, "system.storage"},
123 {APIPermission::kU2fDevices,
124 "u2fDevices",
125 APIPermissionInfo::kFlagNone,
126 IDS_EXTENSION_PROMPT_WARNING_U2F_DEVICES,
127 PermissionMessage::kU2fDevices},
128 {APIPermission::kUnlimitedStorage,
129 "unlimitedStorage",
130 APIPermissionInfo::kFlagCannotBeOptional |
131 APIPermissionInfo::kFlagSupportsContentCapabilities},
132 {APIPermission::kUsb, "usb", APIPermissionInfo::kFlagNone},
133 {APIPermission::kUsbDevice,
134 "usbDevices",
135 APIPermissionInfo::kFlagNone,
137 PermissionMessage::kNone,
138 &CreateAPIPermission<UsbDevicePermission>},
139 {APIPermission::kVideoCapture,
140 "videoCapture",
141 APIPermissionInfo::kFlagNone,
142 IDS_EXTENSION_PROMPT_WARNING_VIDEO_CAPTURE,
143 PermissionMessage::kVideoCapture},
144 {APIPermission::kVpnProvider,
145 "vpnProvider",
146 APIPermissionInfo::kFlagCannotBeOptional,
147 IDS_EXTENSION_PROMPT_WARNING_VPN,
148 PermissionMessage::kVpnProvider},
149 // NOTE(kalman): This is provided by a manifest property but needs to
150 // appear in the install permission dialogue, so we need a fake
151 // permission for it. See http://crbug.com/247857.
152 {APIPermission::kWebConnectable,
153 "webConnectable",
154 APIPermissionInfo::kFlagCannotBeOptional |
155 APIPermissionInfo::kFlagInternal,
156 IDS_EXTENSION_PROMPT_WARNING_WEB_CONNECTABLE,
157 PermissionMessage::kWebConnectable},
158 {APIPermission::kWebRequest, "webRequest"},
159 {APIPermission::kWebRequestBlocking, "webRequestBlocking"},
160 {APIPermission::kWebView,
161 "webview",
162 APIPermissionInfo::kFlagCannotBeOptional},
163 {APIPermission::kWindowShape, "app.window.shape"},
166 std::vector<APIPermissionInfo*> permissions;
167 for (size_t i = 0; i < arraysize(permissions_to_register); ++i)
168 permissions.push_back(new APIPermissionInfo(permissions_to_register[i]));
169 return permissions;
172 std::vector<PermissionsProvider::AliasInfo>
173 ExtensionsAPIPermissions::GetAllAliases() const {
174 std::vector<PermissionsProvider::AliasInfo> aliases;
175 aliases.push_back(PermissionsProvider::AliasInfo(
176 "app.window.alwaysOnTop", kOldAlwaysOnTopWindowsPermission));
177 aliases.push_back(PermissionsProvider::AliasInfo("app.window.fullscreen",
178 kOldFullscreenPermission));
179 aliases.push_back(
180 PermissionsProvider::AliasInfo("app.window.fullscreen.overrideEsc",
181 kOldOverrideEscFullscreenPermission));
182 aliases.push_back(PermissionsProvider::AliasInfo(
183 "unlimitedStorage", kOldUnlimitedStoragePermission));
184 return aliases;
187 } // namespace extensions