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"
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"
38 namespace extensions
{
40 ExtensionSettingsHandler::ExtensionSettingsHandler()
41 : extension_service_(nullptr) {
44 ExtensionSettingsHandler::~ExtensionSettingsHandler() {
48 void ExtensionSettingsHandler::RegisterProfilePrefs(
49 user_prefs::PrefRegistrySyncable
* registry
) {
50 registry
->RegisterBooleanPref(
51 prefs::kExtensionsUIDeveloperMode
,
53 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
54 registry
->RegisterBooleanPref(
55 prefs::kExtensionsUIDismissedADTPromo
,
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
));
70 "extensionSettingsSuggestGallery",
71 l10n_util::GetStringFUTF16(
72 IDS_EXTENSIONS_NONE_INSTALLED_SUGGEST_GALLERY
,
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
));
80 "extensionSettingsGetMoreExtensionsUrl",
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
));
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("loading",
146 l10n_util::GetStringUTF16(IDS_EXTENSIONS_LOADING
));
147 source
->AddString("extensionSettingsCorruptInstall",
148 l10n_util::GetStringUTF16(
149 IDS_EXTENSIONS_CORRUPTED_EXTENSION
));
150 source
->AddString("extensionSettingsSuspiciousInstall",
151 l10n_util::GetStringFUTF16(
152 IDS_EXTENSIONS_ADDED_WITHOUT_KNOWLEDGE
,
153 l10n_util::GetStringUTF16(IDS_EXTENSION_WEB_STORE_TITLE
)));
154 source
->AddString("extensionSettingsLearnMore",
155 l10n_util::GetStringUTF16(IDS_LEARN_MORE
));
156 source
->AddString("extensionSettingsSuspiciousInstallHelpUrl",
158 google_util::AppendGoogleLocaleParam(
159 GURL(chrome::kRemoveNonCWSExtensionURL
),
160 g_browser_process
->GetApplicationLocale()).spec()));
161 source
->AddString("extensionSettingsShowButton",
162 l10n_util::GetStringUTF16(IDS_EXTENSIONS_SHOW_BUTTON
));
163 source
->AddString("extensionSettingsLoadUnpackedButton",
164 l10n_util::GetStringUTF16(IDS_EXTENSIONS_LOAD_UNPACKED_BUTTON
));
165 source
->AddString("extensionSettingsPackButton",
166 l10n_util::GetStringUTF16(IDS_EXTENSIONS_PACK_BUTTON
));
167 source
->AddString("extensionSettingsCommandsLink",
168 l10n_util::GetStringUTF16(IDS_EXTENSIONS_COMMANDS_CONFIGURE
));
169 source
->AddString("extensionSettingsUpdateButton",
170 l10n_util::GetStringUTF16(IDS_EXTENSIONS_UPDATE_BUTTON
));
171 source
->AddString("extensionSettingsCrashMessage",
172 l10n_util::GetStringUTF16(IDS_EXTENSIONS_CRASHED_EXTENSION
));
173 source
->AddString("extensionSettingsInDevelopment",
174 l10n_util::GetStringUTF16(IDS_EXTENSIONS_IN_DEVELOPMENT
));
175 source
->AddString("extensionSettingsWarningsTitle",
176 l10n_util::GetStringUTF16(IDS_EXTENSION_WARNINGS_TITLE
));
177 source
->AddString("extensionSettingsShowDetails",
178 l10n_util::GetStringUTF16(IDS_EXTENSIONS_SHOW_DETAILS
));
179 source
->AddString("extensionSettingsHideDetails",
180 l10n_util::GetStringUTF16(IDS_EXTENSIONS_HIDE_DETAILS
));
181 source
->AddString("extensionSettingsUpdateRequiredBePolicy",
182 l10n_util::GetStringUTF16(
183 IDS_EXTENSIONS_DISABLED_UPDATE_REQUIRED_BY_POLICY
));
185 // TODO(estade): comb through the above strings to find ones no longer used in
187 source
->AddString("extensionUninstall",
188 l10n_util::GetStringUTF16(IDS_EXTENSIONS_UNINSTALL
));
190 // Pack Extension Overlay:
191 source
->AddString("packExtensionOverlay",
192 l10n_util::GetStringUTF16(IDS_EXTENSION_PACK_DIALOG_TITLE
));
193 source
->AddString("packExtensionHeading",
194 l10n_util::GetStringUTF16(IDS_EXTENSION_PACK_DIALOG_HEADING
));
195 source
->AddString("packExtensionCommit",
196 l10n_util::GetStringUTF16(IDS_EXTENSION_PACK_BUTTON
));
197 source
->AddString("ok", l10n_util::GetStringUTF16(IDS_OK
));
198 source
->AddString("cancel", l10n_util::GetStringUTF16(IDS_CANCEL
));
199 source
->AddString("packExtensionRootDir",
200 l10n_util::GetStringUTF16(
201 IDS_EXTENSION_PACK_DIALOG_ROOT_DIRECTORY_LABEL
));
202 source
->AddString("packExtensionPrivateKey",
203 l10n_util::GetStringUTF16(IDS_EXTENSION_PACK_DIALOG_PRIVATE_KEY_LABEL
));
204 source
->AddString("packExtensionBrowseButton",
205 l10n_util::GetStringUTF16(IDS_EXTENSION_PACK_DIALOG_BROWSE
));
206 source
->AddString("packExtensionProceedAnyway",
207 l10n_util::GetStringUTF16(IDS_EXTENSION_PROCEED_ANYWAY
));
208 source
->AddString("packExtensionWarningTitle",
209 l10n_util::GetStringUTF16(IDS_EXTENSION_PACK_WARNING_TITLE
));
210 source
->AddString("packExtensionErrorTitle",
211 l10n_util::GetStringUTF16(IDS_EXTENSION_PACK_ERROR_TITLE
));
213 // Extension Error and Extension Error Overlay:
214 source
->AddString("extensionErrorHeading",
215 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ERROR_HEADING
));
216 source
->AddString("extensionErrorClearAll",
217 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ERROR_CLEAR_ALL
));
218 source
->AddString("extensionErrorNoErrors",
219 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ERROR_NO_ERRORS
));
221 "extensionErrorNoErrorsCodeMessage",
222 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ERROR_NO_ERRORS_CODE_MESSAGE
));
223 source
->AddString("extensionErrorOverlayDone",
224 l10n_util::GetStringUTF16(IDS_DONE
));
226 "extensionErrorOverlayContextUrl",
227 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ERROR_CONTEXT
));
229 "extensionErrorOverlayStackTrace",
230 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ERROR_STACK_TRACE
));
232 "extensionErrorOverlayAnonymousFunction",
233 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ERROR_ANONYMOUS_FUNCTION
));
235 "extensionErrorOverlayLaunchDevtools",
236 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ERROR_LAUNCH_DEVTOOLS
));
238 "extensionErrorOverlayContextUnknown",
239 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ERROR_CONTEXT_UNKNOWN
));
241 "extensionErrorOverlayNoCodeToDisplay",
242 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ERROR_NO_CODE_TO_DISPLAY
));
244 // Extension Commands Overlay:
245 source
->AddString("extensionCommandsOverlay",
246 l10n_util::GetStringUTF16(IDS_EXTENSION_COMMANDS_DIALOG_TITLE
));
247 source
->AddString("extensionCommandsEmpty",
248 l10n_util::GetStringUTF16(IDS_EXTENSION_COMMANDS_EMPTY
));
249 source
->AddString("extensionCommandsInactive",
250 l10n_util::GetStringUTF16(IDS_EXTENSION_COMMANDS_INACTIVE
));
251 source
->AddString("extensionCommandsStartTyping",
252 l10n_util::GetStringUTF16(IDS_EXTENSION_TYPE_SHORTCUT
));
253 source
->AddString("extensionCommandsDelete",
254 l10n_util::GetStringUTF16(IDS_EXTENSION_DELETE_SHORTCUT
));
255 source
->AddString("extensionCommandsGlobal",
256 l10n_util::GetStringUTF16(IDS_EXTENSION_COMMANDS_GLOBAL
));
257 source
->AddString("extensionCommandsRegular",
258 l10n_util::GetStringUTF16(IDS_EXTENSION_COMMANDS_NOT_GLOBAL
));
259 source
->AddString("ok", l10n_util::GetStringUTF16(IDS_OK
));
262 void ExtensionSettingsHandler::DidStartNavigationToPendingEntry(
264 content::NavigationController::ReloadType reload_type
) {
265 if (reload_type
!= content::NavigationController::NO_RELOAD
)
266 ReloadUnpackedExtensions();
269 void ExtensionSettingsHandler::RegisterMessages() {
270 Profile
* profile
= Profile::FromWebUI(web_ui())->GetOriginalProfile();
272 extensions::ExtensionSystem::Get(profile
)->extension_service();
273 // Clear the preference for the ADT Promo before fully removing it.
274 // TODO(devlin): Take this out when everyone's been updated.
275 Profile::FromWebUI(web_ui())->GetPrefs()->ClearPref(
276 prefs::kExtensionsUIDismissedADTPromo
);
279 void ExtensionSettingsHandler::ReloadUnpackedExtensions() {
280 ExtensionRegistry
* registry
=
281 ExtensionRegistry::Get(extension_service_
->profile());
282 std::vector
<const Extension
*> unpacked_extensions
;
283 for (const scoped_refptr
<const extensions::Extension
>& extension
:
284 registry
->enabled_extensions()) {
285 if (Manifest::IsUnpackedLocation(extension
->location()))
286 unpacked_extensions
.push_back(extension
.get());
289 for (std::vector
<const Extension
*>::iterator iter
=
290 unpacked_extensions
.begin(); iter
!= unpacked_extensions
.end(); ++iter
) {
291 extension_service_
->ReloadExtensionWithQuietFailure((*iter
)->id());
295 } // namespace extensions