OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/common/extensions/permissions/api_permission.h" |
| 6 |
| 7 #include "chrome/common/extensions/permissions/permissions_info.h" |
| 8 #include "grit/generated_resources.h" |
| 9 #include "ui/base/l10n/l10n_util.h" |
| 10 |
| 11 namespace { |
| 12 |
| 13 const char kOldUnlimitedStoragePermission[] = "unlimited_storage"; |
| 14 const char kWindowsPermission[] = "windows"; |
| 15 const char kTemporaryBackgroundAlias[] = "background_alias_do_not_use"; |
| 16 |
| 17 } // namespace |
| 18 |
| 19 namespace extensions { |
| 20 |
| 21 // |
| 22 // APIPermission |
| 23 // |
| 24 |
| 25 APIPermission::~APIPermission() {} |
| 26 |
| 27 PermissionMessage APIPermission::GetMessage() const { |
| 28 return PermissionMessage( |
| 29 message_id_, l10n_util::GetStringUTF16(l10n_message_id_)); |
| 30 } |
| 31 |
| 32 APIPermission::APIPermission( |
| 33 ID id, |
| 34 const char* name, |
| 35 int l10n_message_id, |
| 36 PermissionMessage::ID message_id, |
| 37 int flags) |
| 38 : id_(id), |
| 39 name_(name), |
| 40 flags_(flags), |
| 41 l10n_message_id_(l10n_message_id), |
| 42 message_id_(message_id) {} |
| 43 |
| 44 // static |
| 45 void APIPermission::RegisterAllPermissions( |
| 46 PermissionsInfo* info) { |
| 47 |
| 48 struct PermissionRegistration { |
| 49 APIPermission::ID id; |
| 50 const char* name; |
| 51 int flags; |
| 52 int l10n_message_id; |
| 53 PermissionMessage::ID message_id; |
| 54 } PermissionsToRegister[] = { |
| 55 // Register permissions for all extension types. |
| 56 { kBackground, "background" }, |
| 57 { kClipboardRead, "clipboardRead", kFlagNone, |
| 58 IDS_EXTENSION_PROMPT_WARNING_CLIPBOARD, |
| 59 PermissionMessage::kClipboard }, |
| 60 { kClipboardWrite, "clipboardWrite" }, |
| 61 { kDeclarative, "declarative" }, |
| 62 { kDeclarativeWebRequest, "declarativeWebRequest" }, |
| 63 { kDownloads, "downloads", kFlagNone, |
| 64 IDS_EXTENSION_PROMPT_WARNING_DOWNLOADS, |
| 65 PermissionMessage::kDownloads }, |
| 66 { kExperimental, "experimental", kFlagCannotBeOptional }, |
| 67 { kGeolocation, "geolocation", kFlagCannotBeOptional, |
| 68 IDS_EXTENSION_PROMPT_WARNING_GEOLOCATION, |
| 69 PermissionMessage::kGeolocation }, |
| 70 { kNotification, "notifications" }, |
| 71 { kUnlimitedStorage, "unlimitedStorage", kFlagCannotBeOptional }, |
| 72 |
| 73 // Register hosted and packaged app permissions. |
| 74 { kAppNotifications, "appNotifications" }, |
| 75 |
| 76 // Register extension permissions. |
| 77 { kActiveTab, "activeTab" }, |
| 78 { kAlarms, "alarms" }, |
| 79 { kBookmark, "bookmarks", kFlagNone, |
| 80 IDS_EXTENSION_PROMPT_WARNING_BOOKMARKS, |
| 81 PermissionMessage::kBookmarks }, |
| 82 { kBrowsingData, "browsingData" }, |
| 83 { kContentSettings, "contentSettings", kFlagNone, |
| 84 IDS_EXTENSION_PROMPT_WARNING_CONTENT_SETTINGS, |
| 85 PermissionMessage::kContentSettings }, |
| 86 { kContextMenus, "contextMenus" }, |
| 87 { kCookie, "cookies" }, |
| 88 { kFileBrowserHandler, "fileBrowserHandler", kFlagCannotBeOptional }, |
| 89 { kFileSystem, "fileSystem" }, |
| 90 { kHistory, "history", kFlagNone, |
| 91 IDS_EXTENSION_PROMPT_WARNING_BROWSING_HISTORY, |
| 92 PermissionMessage::kBrowsingHistory }, |
| 93 { kKeybinding, "keybinding" }, |
| 94 { kIdle, "idle" }, |
| 95 { kInput, "input", kFlagNone, |
| 96 IDS_EXTENSION_PROMPT_WARNING_INPUT, |
| 97 PermissionMessage::kInput }, |
| 98 { kManagement, "management", kFlagNone, |
| 99 IDS_EXTENSION_PROMPT_WARNING_MANAGEMENT, |
| 100 PermissionMessage::kManagement }, |
| 101 { kPageCapture, "pageCapture", kFlagNone, |
| 102 IDS_EXTENSION_PROMPT_WARNING_ALL_PAGES_CONTENT, |
| 103 PermissionMessage::kAllPageContent }, |
| 104 { kPrivacy, "privacy", kFlagNone, |
| 105 IDS_EXTENSION_PROMPT_WARNING_PRIVACY, |
| 106 PermissionMessage::kPrivacy }, |
| 107 { kStorage, "storage" }, |
| 108 { kTab, "tabs", kFlagNone, |
| 109 IDS_EXTENSION_PROMPT_WARNING_TABS, |
| 110 PermissionMessage::kTabs }, |
| 111 { kTopSites, "topSites", kFlagNone, |
| 112 IDS_EXTENSION_PROMPT_WARNING_BROWSING_HISTORY, |
| 113 PermissionMessage::kBrowsingHistory }, |
| 114 { kTts, "tts", 0, kFlagCannotBeOptional }, |
| 115 { kTtsEngine, "ttsEngine", kFlagCannotBeOptional, |
| 116 IDS_EXTENSION_PROMPT_WARNING_TTS_ENGINE, |
| 117 PermissionMessage::kTtsEngine }, |
| 118 { kUsb, "usb", kFlagNone, |
| 119 IDS_EXTENSION_PROMPT_WARNING_USB, |
| 120 PermissionMessage::kNone }, |
| 121 { kWebNavigation, "webNavigation", kFlagNone, |
| 122 IDS_EXTENSION_PROMPT_WARNING_TABS, PermissionMessage::kTabs }, |
| 123 { kWebRequest, "webRequest" }, |
| 124 { kWebRequestBlocking, "webRequestBlocking" }, |
| 125 |
| 126 // Register private permissions. |
| 127 { kChromeosInfoPrivate, "chromeosInfoPrivate", kFlagCannotBeOptional }, |
| 128 { kFileBrowserHandlerInternal, "fileBrowserHandlerInternal", |
| 129 kFlagCannotBeOptional }, |
| 130 { kFileBrowserPrivate, "fileBrowserPrivate", kFlagCannotBeOptional }, |
| 131 { kManagedModePrivate, "managedModePrivate", kFlagCannotBeOptional }, |
| 132 { kMediaPlayerPrivate, "mediaPlayerPrivate", kFlagCannotBeOptional }, |
| 133 { kMetricsPrivate, "metricsPrivate", kFlagCannotBeOptional }, |
| 134 { kSystemPrivate, "systemPrivate", kFlagCannotBeOptional }, |
| 135 { kChromeAuthPrivate, "chromeAuthPrivate", kFlagCannotBeOptional }, |
| 136 { kInputMethodPrivate, "inputMethodPrivate", kFlagCannotBeOptional }, |
| 137 { kEchoPrivate, "echoPrivate", kFlagCannotBeOptional }, |
| 138 { kTerminalPrivate, "terminalPrivate", kFlagCannotBeOptional }, |
| 139 { kWebRequestInternal, "webRequestInternal", kFlagCannotBeOptional }, |
| 140 { kWebSocketProxyPrivate, "webSocketProxyPrivate", kFlagCannotBeOptional }, |
| 141 { kWebstorePrivate, "webstorePrivate", kFlagCannotBeOptional }, |
| 142 |
| 143 // Full url access permissions. |
| 144 { kProxy, "proxy", kFlagImpliesFullURLAccess | kFlagCannotBeOptional }, |
| 145 { kDebugger, "debugger", kFlagImpliesFullURLAccess | kFlagCannotBeOptional, |
| 146 IDS_EXTENSION_PROMPT_WARNING_DEBUGGER, |
| 147 PermissionMessage::kDebugger }, |
| 148 { kDevtools, "devtools", |
| 149 kFlagImpliesFullURLAccess | kFlagCannotBeOptional }, |
| 150 { kPlugin, "plugin", |
| 151 kFlagImpliesFullURLAccess | kFlagImpliesFullAccess | |
| 152 kFlagCannotBeOptional, |
| 153 IDS_EXTENSION_PROMPT_WARNING_FULL_ACCESS, |
| 154 PermissionMessage::kFullAccess }, |
| 155 |
| 156 // Platform-app permissions. |
| 157 { kSocket, "socket", kFlagCannotBeOptional }, |
| 158 { kAudioCapture, "audioCapture", kFlagNone, |
| 159 IDS_EXTENSION_PROMPT_WARNING_AUDIO_CAPTURE, |
| 160 PermissionMessage::kAudioCapture }, |
| 161 { kVideoCapture, "videoCapture", kFlagNone, |
| 162 IDS_EXTENSION_PROMPT_WARNING_VIDEO_CAPTURE, |
| 163 PermissionMessage::kVideoCapture }, |
| 164 }; |
| 165 |
| 166 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(PermissionsToRegister); ++i) { |
| 167 const PermissionRegistration& pr = PermissionsToRegister[i]; |
| 168 info->RegisterPermission( |
| 169 pr.id, pr.name, pr.l10n_message_id, |
| 170 pr.message_id ? pr.message_id : PermissionMessage::kNone, |
| 171 pr.flags); |
| 172 } |
| 173 |
| 174 // Register aliases. |
| 175 info->RegisterAlias("unlimitedStorage", kOldUnlimitedStoragePermission); |
| 176 info->RegisterAlias("tabs", kWindowsPermission); |
| 177 // TODO(mihaip): Should be removed for the M20 branch, see |
| 178 // http://crbug.com/120447 for more details. |
| 179 info->RegisterAlias("background", kTemporaryBackgroundAlias); |
| 180 } |
| 181 |
| 182 } // namespace extensions |
OLD | NEW |