Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / chrome / browser / ui / webui / extensions / extension_settings_handler.cc
blobf6bfc5d672997f8c1a6c04871a7e993d1168c31d
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.
5 #include "chrome/browser/ui/webui/extensions/extension_settings_handler.h"
7 #include <vector>
9 #include "base/prefs/pref_service.h"
10 #include "base/strings/string_util.h"
11 #include "base/strings/utf_string_conversions.h"
12 #include "chrome/browser/browser_process.h"
13 #include "chrome/browser/extensions/extension_service.h"
14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/ui/apps/app_info_dialog.h"
16 #include "chrome/browser/ui/browser.h"
17 #include "chrome/common/pref_names.h"
18 #include "chrome/common/url_constants.h"
19 #include "chrome/grit/chromium_strings.h"
20 #include "chrome/grit/generated_resources.h"
21 #include "components/google/core/browser/google_util.h"
22 #include "components/pref_registry/pref_registry_syncable.h"
23 #include "content/public/browser/web_contents.h"
24 #include "content/public/browser/web_ui.h"
25 #include "content/public/browser/web_ui_data_source.h"
26 #include "extensions/browser/extension_registry.h"
27 #include "extensions/browser/extension_system.h"
28 #include "extensions/common/extension.h"
29 #include "extensions/common/extension_set.h"
30 #include "extensions/common/extension_urls.h"
31 #include "extensions/common/manifest.h"
32 #include "grit/browser_resources.h"
33 #include "grit/components_strings.h"
34 #include "grit/theme_resources.h"
35 #include "ui/base/l10n/l10n_util.h"
36 #include "url/gurl.h"
38 namespace extensions {
40 ExtensionSettingsHandler::ExtensionSettingsHandler()
41 : extension_service_(nullptr) {
44 ExtensionSettingsHandler::~ExtensionSettingsHandler() {
47 // static
48 void ExtensionSettingsHandler::RegisterProfilePrefs(
49 user_prefs::PrefRegistrySyncable* registry) {
50 registry->RegisterBooleanPref(
51 prefs::kExtensionsUIDeveloperMode,
52 false,
53 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
54 registry->RegisterBooleanPref(
55 prefs::kExtensionsUIDismissedADTPromo,
56 false,
57 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
60 void ExtensionSettingsHandler::GetLocalizedValues(
61 content::WebUIDataSource* source) {
62 source->AddString("extensionSettings",
63 l10n_util::GetStringUTF16(IDS_MANAGE_EXTENSIONS_SETTING_WINDOWS_TITLE));
65 source->AddString("extensionSettingsDeveloperMode",
66 l10n_util::GetStringUTF16(IDS_EXTENSIONS_DEVELOPER_MODE_LINK));
67 source->AddString("extensionSettingsNoExtensions",
68 l10n_util::GetStringUTF16(IDS_EXTENSIONS_NONE_INSTALLED));
69 source->AddString(
70 "extensionSettingsSuggestGallery",
71 l10n_util::GetStringFUTF16(
72 IDS_EXTENSIONS_NONE_INSTALLED_SUGGEST_GALLERY,
73 base::ASCIIToUTF16(
74 google_util::AppendGoogleLocaleParam(
75 GURL(extension_urls::GetWebstoreExtensionsCategoryURL()),
76 g_browser_process->GetApplicationLocale()).spec())));
77 source->AddString("extensionSettingsGetMoreExtensions",
78 l10n_util::GetStringUTF16(IDS_GET_MORE_EXTENSIONS));
79 source->AddString(
80 "extensionSettingsGetMoreExtensionsUrl",
81 base::ASCIIToUTF16(
82 google_util::AppendGoogleLocaleParam(
83 GURL(extension_urls::GetWebstoreExtensionsCategoryURL()),
84 g_browser_process->GetApplicationLocale()).spec()));
85 source->AddString("extensionSettingsExtensionId",
86 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ID));
87 source->AddString("extensionSettingsExtensionPath",
88 l10n_util::GetStringUTF16(IDS_EXTENSIONS_PATH));
89 source->AddString("extensionSettingsInspectViews",
90 l10n_util::GetStringUTF16(IDS_EXTENSIONS_INSPECT_VIEWS));
91 source->AddString("extensionSettingsInstallWarnings",
92 l10n_util::GetStringUTF16(IDS_EXTENSIONS_INSTALL_WARNINGS));
93 source->AddString("viewIncognito",
94 l10n_util::GetStringUTF16(IDS_EXTENSIONS_VIEW_INCOGNITO));
95 source->AddString("viewInactive",
96 l10n_util::GetStringUTF16(IDS_EXTENSIONS_VIEW_INACTIVE));
97 source->AddString("backgroundPage",
98 l10n_util::GetStringUTF16(IDS_EXTENSIONS_BACKGROUND_PAGE));
99 source->AddString("extensionSettingsEnable",
100 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ENABLE));
101 source->AddString("extensionSettingsEnabled",
102 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ENABLED));
103 source->AddString("extensionSettingsRemove",
104 l10n_util::GetStringUTF16(IDS_EXTENSIONS_REMOVE));
105 source->AddString("extensionSettingsEnableIncognito",
106 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ENABLE_INCOGNITO));
107 source->AddString("extensionSettingsEnableErrorCollection",
108 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ENABLE_ERROR_COLLECTION));
109 source->AddString("extensionSettingsAllowFileAccess",
110 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ALLOW_FILE_ACCESS));
111 source->AddString("extensionSettingsAllowOnAllUrls",
112 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ALLOW_ON_ALL_URLS));
113 source->AddString("extensionSettingsIncognitoWarning",
114 l10n_util::GetStringUTF16(IDS_EXTENSIONS_INCOGNITO_WARNING));
115 source->AddString("extensionSettingsReloadTerminated",
116 l10n_util::GetStringUTF16(IDS_EXTENSIONS_RELOAD_TERMINATED));
117 source->AddString("extensionSettingsRepairCorrupted",
118 l10n_util::GetStringUTF16(IDS_EXTENSIONS_REPAIR_CORRUPTED));
119 source->AddString("extensionSettingsLaunch",
120 l10n_util::GetStringUTF16(IDS_EXTENSIONS_LAUNCH));
121 source->AddString("extensionSettingsReloadUnpacked",
122 l10n_util::GetStringUTF16(IDS_EXTENSIONS_RELOAD_UNPACKED));
123 source->AddString("extensionSettingsOptions",
124 l10n_util::GetStringUTF16(IDS_EXTENSIONS_OPTIONS_LINK));
125 if (CanShowAppInfoDialog()) {
126 source->AddString("extensionSettingsPermissions",
127 l10n_util::GetStringUTF16(IDS_EXTENSIONS_INFO_LINK));
128 } else {
129 source->AddString(
130 "extensionSettingsPermissions",
131 l10n_util::GetStringUTF16(IDS_EXTENSIONS_PERMISSIONS_LINK));
133 source->AddString("extensionSettingsVisitWebsite",
134 l10n_util::GetStringUTF16(IDS_EXTENSIONS_VISIT_WEBSITE));
135 source->AddString("extensionSettingsVisitWebStore",
136 l10n_util::GetStringUTF16(IDS_EXTENSIONS_VISIT_WEBSTORE));
137 source->AddString("extensionSettingsPolicyControlled",
138 l10n_util::GetStringUTF16(IDS_EXTENSIONS_POLICY_CONTROLLED));
139 source->AddString("extensionSettingsPolicyRecommeneded",
140 l10n_util::GetStringUTF16(IDS_EXTENSIONS_POLICY_RECOMMENDED));
141 source->AddString("extensionSettingsDependentExtensions",
142 l10n_util::GetStringUTF16(IDS_EXTENSIONS_DEPENDENT_EXTENSIONS));
143 source->AddString("extensionSettingsSupervisedUser",
144 l10n_util::GetStringUTF16(IDS_EXTENSIONS_LOCKED_SUPERVISED_USER));
145 source->AddString("extensionSettingsCorruptInstall",
146 l10n_util::GetStringUTF16(
147 IDS_EXTENSIONS_CORRUPTED_EXTENSION));
148 source->AddString("extensionSettingsSuspiciousInstall",
149 l10n_util::GetStringFUTF16(
150 IDS_EXTENSIONS_ADDED_WITHOUT_KNOWLEDGE,
151 l10n_util::GetStringUTF16(IDS_EXTENSION_WEB_STORE_TITLE)));
152 source->AddString("extensionSettingsLearnMore",
153 l10n_util::GetStringUTF16(IDS_LEARN_MORE));
154 source->AddString("extensionSettingsSuspiciousInstallHelpUrl",
155 base::ASCIIToUTF16(
156 google_util::AppendGoogleLocaleParam(
157 GURL(chrome::kRemoveNonCWSExtensionURL),
158 g_browser_process->GetApplicationLocale()).spec()));
159 source->AddString("extensionSettingsShowButton",
160 l10n_util::GetStringUTF16(IDS_EXTENSIONS_SHOW_BUTTON));
161 source->AddString("extensionSettingsLoadUnpackedButton",
162 l10n_util::GetStringUTF16(IDS_EXTENSIONS_LOAD_UNPACKED_BUTTON));
163 source->AddString("extensionSettingsPackButton",
164 l10n_util::GetStringUTF16(IDS_EXTENSIONS_PACK_BUTTON));
165 source->AddString("extensionSettingsCommandsLink",
166 l10n_util::GetStringUTF16(IDS_EXTENSIONS_COMMANDS_CONFIGURE));
167 source->AddString("extensionSettingsUpdateButton",
168 l10n_util::GetStringUTF16(IDS_EXTENSIONS_UPDATE_BUTTON));
169 source->AddString("extensionSettingsCrashMessage",
170 l10n_util::GetStringUTF16(IDS_EXTENSIONS_CRASHED_EXTENSION));
171 source->AddString("extensionSettingsInDevelopment",
172 l10n_util::GetStringUTF16(IDS_EXTENSIONS_IN_DEVELOPMENT));
173 source->AddString("extensionSettingsWarningsTitle",
174 l10n_util::GetStringUTF16(IDS_EXTENSION_WARNINGS_TITLE));
175 source->AddString("extensionSettingsShowDetails",
176 l10n_util::GetStringUTF16(IDS_EXTENSIONS_SHOW_DETAILS));
177 source->AddString("extensionSettingsHideDetails",
178 l10n_util::GetStringUTF16(IDS_EXTENSIONS_HIDE_DETAILS));
179 source->AddString("extensionSettingsUpdateRequiredBePolicy",
180 l10n_util::GetStringUTF16(
181 IDS_EXTENSIONS_DISABLED_UPDATE_REQUIRED_BY_POLICY));
183 // TODO(estade): comb through the above strings to find ones no longer used in
184 // uber extensions.
185 source->AddString("extensionUninstall",
186 l10n_util::GetStringUTF16(IDS_EXTENSIONS_UNINSTALL));
188 // Pack Extension Overlay:
189 source->AddString("packExtensionOverlay",
190 l10n_util::GetStringUTF16(IDS_EXTENSION_PACK_DIALOG_TITLE));
191 source->AddString("packExtensionHeading",
192 l10n_util::GetStringUTF16(IDS_EXTENSION_PACK_DIALOG_HEADING));
193 source->AddString("packExtensionCommit",
194 l10n_util::GetStringUTF16(IDS_EXTENSION_PACK_BUTTON));
195 source->AddString("ok", l10n_util::GetStringUTF16(IDS_OK));
196 source->AddString("cancel", l10n_util::GetStringUTF16(IDS_CANCEL));
197 source->AddString("packExtensionRootDir",
198 l10n_util::GetStringUTF16(
199 IDS_EXTENSION_PACK_DIALOG_ROOT_DIRECTORY_LABEL));
200 source->AddString("packExtensionPrivateKey",
201 l10n_util::GetStringUTF16(IDS_EXTENSION_PACK_DIALOG_PRIVATE_KEY_LABEL));
202 source->AddString("packExtensionBrowseButton",
203 l10n_util::GetStringUTF16(IDS_EXTENSION_PACK_DIALOG_BROWSE));
204 source->AddString("packExtensionProceedAnyway",
205 l10n_util::GetStringUTF16(IDS_EXTENSION_PROCEED_ANYWAY));
206 source->AddString("packExtensionWarningTitle",
207 l10n_util::GetStringUTF16(IDS_EXTENSION_PACK_WARNING_TITLE));
208 source->AddString("packExtensionErrorTitle",
209 l10n_util::GetStringUTF16(IDS_EXTENSION_PACK_ERROR_TITLE));
211 // Extension Error and Extension Error Overlay:
212 source->AddString("extensionErrorHeading",
213 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ERROR_HEADING));
214 source->AddString("extensionErrorClearAll",
215 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ERROR_CLEAR_ALL));
216 source->AddString("extensionErrorNoErrors",
217 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ERROR_NO_ERRORS));
218 source->AddString(
219 "extensionErrorNoErrorsCodeMessage",
220 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ERROR_NO_ERRORS_CODE_MESSAGE));
221 source->AddString("extensionErrorOverlayDone",
222 l10n_util::GetStringUTF16(IDS_DONE));
223 source->AddString(
224 "extensionErrorOverlayContextUrl",
225 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ERROR_CONTEXT));
226 source->AddString(
227 "extensionErrorOverlayStackTrace",
228 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ERROR_STACK_TRACE));
229 source->AddString(
230 "extensionErrorOverlayAnonymousFunction",
231 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ERROR_ANONYMOUS_FUNCTION));
232 source->AddString(
233 "extensionErrorOverlayLaunchDevtools",
234 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ERROR_LAUNCH_DEVTOOLS));
235 source->AddString(
236 "extensionErrorOverlayContextUnknown",
237 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ERROR_CONTEXT_UNKNOWN));
238 source->AddString(
239 "extensionErrorOverlayNoCodeToDisplay",
240 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ERROR_NO_CODE_TO_DISPLAY));
242 // Extension Commands Overlay:
243 source->AddString("extensionCommandsOverlay",
244 l10n_util::GetStringUTF16(IDS_EXTENSION_COMMANDS_DIALOG_TITLE));
245 source->AddString("extensionCommandsEmpty",
246 l10n_util::GetStringUTF16(IDS_EXTENSION_COMMANDS_EMPTY));
247 source->AddString("extensionCommandsInactive",
248 l10n_util::GetStringUTF16(IDS_EXTENSION_COMMANDS_INACTIVE));
249 source->AddString("extensionCommandsStartTyping",
250 l10n_util::GetStringUTF16(IDS_EXTENSION_TYPE_SHORTCUT));
251 source->AddString("extensionCommandsDelete",
252 l10n_util::GetStringUTF16(IDS_EXTENSION_DELETE_SHORTCUT));
253 source->AddString("extensionCommandsGlobal",
254 l10n_util::GetStringUTF16(IDS_EXTENSION_COMMANDS_GLOBAL));
255 source->AddString("extensionCommandsRegular",
256 l10n_util::GetStringUTF16(IDS_EXTENSION_COMMANDS_NOT_GLOBAL));
257 source->AddString("ok", l10n_util::GetStringUTF16(IDS_OK));
260 void ExtensionSettingsHandler::DidStartNavigationToPendingEntry(
261 const GURL& url,
262 content::NavigationController::ReloadType reload_type) {
263 if (reload_type != content::NavigationController::NO_RELOAD)
264 ReloadUnpackedExtensions();
267 void ExtensionSettingsHandler::RegisterMessages() {
268 Profile* profile = Profile::FromWebUI(web_ui())->GetOriginalProfile();
269 extension_service_ =
270 extensions::ExtensionSystem::Get(profile)->extension_service();
271 // Clear the preference for the ADT Promo before fully removing it.
272 // TODO(devlin): Take this out when everyone's been updated.
273 Profile::FromWebUI(web_ui())->GetPrefs()->ClearPref(
274 prefs::kExtensionsUIDismissedADTPromo);
277 void ExtensionSettingsHandler::ReloadUnpackedExtensions() {
278 ExtensionRegistry* registry =
279 ExtensionRegistry::Get(extension_service_->profile());
280 std::vector<const Extension*> unpacked_extensions;
281 for (const scoped_refptr<const extensions::Extension>& extension :
282 registry->enabled_extensions()) {
283 if (Manifest::IsUnpackedLocation(extension->location()))
284 unpacked_extensions.push_back(extension.get());
287 for (std::vector<const Extension*>::iterator iter =
288 unpacked_extensions.begin(); iter != unpacked_extensions.end(); ++iter) {
289 extension_service_->ReloadExtensionWithQuietFailure((*iter)->id());
293 } // namespace extensions