OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/webui/extensions/extension_settings_handler.h" | 5 #include "chrome/browser/ui/webui/extensions/extension_settings_handler.h" |
6 | 6 |
7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "base/base64.h" | 8 #include "base/base64.h" |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
13 #include "base/string_number_conversions.h" | 13 #include "base/string_number_conversions.h" |
14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
15 #include "base/values.h" | 15 #include "base/values.h" |
16 #include "base/version.h" | 16 #include "base/version.h" |
| 17 #include "chrome/browser/browser_process.h" |
17 #include "chrome/browser/debugger/devtools_window.h" | 18 #include "chrome/browser/debugger/devtools_window.h" |
18 #include "chrome/browser/extensions/crx_installer.h" | 19 #include "chrome/browser/extensions/crx_installer.h" |
19 #include "chrome/browser/extensions/extension_disabled_ui.h" | 20 #include "chrome/browser/extensions/extension_disabled_ui.h" |
20 #include "chrome/browser/extensions/extension_host.h" | 21 #include "chrome/browser/extensions/extension_host.h" |
21 #include "chrome/browser/extensions/extension_service.h" | 22 #include "chrome/browser/extensions/extension_service.h" |
22 #include "chrome/browser/extensions/extension_system.h" | 23 #include "chrome/browser/extensions/extension_system.h" |
23 #include "chrome/browser/extensions/extension_warning_set.h" | 24 #include "chrome/browser/extensions/extension_warning_set.h" |
24 #include "chrome/browser/extensions/lazy_background_task_queue.h" | 25 #include "chrome/browser/extensions/lazy_background_task_queue.h" |
25 #include "chrome/browser/extensions/unpacked_installer.h" | 26 #include "chrome/browser/extensions/unpacked_installer.h" |
26 #include "chrome/browser/extensions/updater/extension_updater.h" | 27 #include "chrome/browser/extensions/updater/extension_updater.h" |
27 #include "chrome/browser/google/google_util.h" | 28 #include "chrome/browser/google/google_util.h" |
| 29 #include "chrome/browser/managed_mode.h" |
28 #include "chrome/browser/prefs/pref_service.h" | 30 #include "chrome/browser/prefs/pref_service.h" |
29 #include "chrome/browser/profiles/profile.h" | 31 #include "chrome/browser/profiles/profile.h" |
30 #include "chrome/browser/tab_contents/background_contents.h" | 32 #include "chrome/browser/tab_contents/background_contents.h" |
31 #include "chrome/browser/ui/browser_finder.h" | 33 #include "chrome/browser/ui/browser_finder.h" |
32 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" | 34 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" |
33 #include "chrome/browser/view_type_utils.h" | 35 #include "chrome/browser/view_type_utils.h" |
34 #include "chrome/common/chrome_notification_types.h" | 36 #include "chrome/common/chrome_notification_types.h" |
35 #include "chrome/common/chrome_switches.h" | 37 #include "chrome/common/chrome_switches.h" |
36 #include "chrome/common/extensions/extension.h" | 38 #include "chrome/common/extensions/extension.h" |
37 #include "chrome/common/extensions/extension_icon_set.h" | 39 #include "chrome/common/extensions/extension_icon_set.h" |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 localized_strings->SetString("extensionSettingsOptions", | 262 localized_strings->SetString("extensionSettingsOptions", |
261 l10n_util::GetStringUTF16(IDS_EXTENSIONS_OPTIONS_LINK)); | 263 l10n_util::GetStringUTF16(IDS_EXTENSIONS_OPTIONS_LINK)); |
262 localized_strings->SetString("extensionSettingsActivity", | 264 localized_strings->SetString("extensionSettingsActivity", |
263 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ACTIVITY_LINK)); | 265 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ACTIVITY_LINK)); |
264 localized_strings->SetString("extensionSettingsVisitWebsite", | 266 localized_strings->SetString("extensionSettingsVisitWebsite", |
265 l10n_util::GetStringUTF16(IDS_EXTENSIONS_VISIT_WEBSITE)); | 267 l10n_util::GetStringUTF16(IDS_EXTENSIONS_VISIT_WEBSITE)); |
266 localized_strings->SetString("extensionSettingsVisitWebStore", | 268 localized_strings->SetString("extensionSettingsVisitWebStore", |
267 l10n_util::GetStringUTF16(IDS_EXTENSIONS_VISIT_WEBSTORE)); | 269 l10n_util::GetStringUTF16(IDS_EXTENSIONS_VISIT_WEBSTORE)); |
268 localized_strings->SetString("extensionSettingsPolicyControlled", | 270 localized_strings->SetString("extensionSettingsPolicyControlled", |
269 l10n_util::GetStringUTF16(IDS_EXTENSIONS_POLICY_CONTROLLED)); | 271 l10n_util::GetStringUTF16(IDS_EXTENSIONS_POLICY_CONTROLLED)); |
| 272 localized_strings->SetString("extensionSettingsManagedMode", |
| 273 l10n_util::GetStringUTF16(IDS_EXTENSIONS_LOCKED_MANAGED_MODE)); |
270 localized_strings->SetString("extensionSettingsShowButton", | 274 localized_strings->SetString("extensionSettingsShowButton", |
271 l10n_util::GetStringUTF16(IDS_EXTENSIONS_SHOW_BUTTON)); | 275 l10n_util::GetStringUTF16(IDS_EXTENSIONS_SHOW_BUTTON)); |
272 localized_strings->SetString("extensionSettingsLoadUnpackedButton", | 276 localized_strings->SetString("extensionSettingsLoadUnpackedButton", |
273 l10n_util::GetStringUTF16(IDS_EXTENSIONS_LOAD_UNPACKED_BUTTON)); | 277 l10n_util::GetStringUTF16(IDS_EXTENSIONS_LOAD_UNPACKED_BUTTON)); |
274 localized_strings->SetString("extensionSettingsPackButton", | 278 localized_strings->SetString("extensionSettingsPackButton", |
275 l10n_util::GetStringUTF16(IDS_EXTENSIONS_PACK_BUTTON)); | 279 l10n_util::GetStringUTF16(IDS_EXTENSIONS_PACK_BUTTON)); |
276 localized_strings->SetString("extensionSettingsCommandsLink", | 280 localized_strings->SetString("extensionSettingsCommandsLink", |
277 l10n_util::GetStringUTF16(IDS_EXTENSIONS_COMMANDS_CONFIGURE)); | 281 l10n_util::GetStringUTF16(IDS_EXTENSIONS_COMMANDS_CONFIGURE)); |
278 localized_strings->SetString("extensionSettingsUpdateButton", | 282 localized_strings->SetString("extensionSettingsUpdateButton", |
279 l10n_util::GetStringUTF16(IDS_EXTENSIONS_UPDATE_BUTTON)); | 283 l10n_util::GetStringUTF16(IDS_EXTENSIONS_UPDATE_BUTTON)); |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
494 extension != extensions->end(); ++extension) { | 498 extension != extensions->end(); ++extension) { |
495 if ((*extension)->ShouldDisplayInExtensionSettings()) { | 499 if ((*extension)->ShouldDisplayInExtensionSettings()) { |
496 extensions_list->Append(CreateExtensionDetailValue( | 500 extensions_list->Append(CreateExtensionDetailValue( |
497 *extension, | 501 *extension, |
498 empty_pages, // Terminated process has no active pages. | 502 empty_pages, // Terminated process has no active pages. |
499 warnings)); | 503 warnings)); |
500 } | 504 } |
501 } | 505 } |
502 results.Set("extensions", extensions_list); | 506 results.Set("extensions", extensions_list); |
503 | 507 |
504 Profile* profile = Profile::FromWebUI(web_ui()); | 508 if (ManagedMode::IsInManagedMode()) { |
505 bool developer_mode = | 509 results.SetBoolean("managedMode", true); |
506 profile->GetPrefs()->GetBoolean(prefs::kExtensionsUIDeveloperMode); | 510 results.SetBoolean("developerMode", false); |
507 results.SetBoolean("developerMode", developer_mode); | 511 } else { |
| 512 results.SetBoolean("managedMode", false); |
| 513 Profile* profile = Profile::FromWebUI(web_ui()); |
| 514 bool developer_mode = |
| 515 profile->GetPrefs()->GetBoolean(prefs::kExtensionsUIDeveloperMode); |
| 516 results.SetBoolean("developerMode", developer_mode); |
| 517 } |
508 | 518 |
509 bool load_unpacked_disabled = | 519 bool load_unpacked_disabled = |
510 extension_service_->extension_prefs()->ExtensionsBlacklistedByDefault(); | 520 extension_service_->extension_prefs()->ExtensionsBlacklistedByDefault(); |
511 results.SetBoolean("loadUnpackedDisabled", load_unpacked_disabled); | 521 results.SetBoolean("loadUnpackedDisabled", load_unpacked_disabled); |
512 | 522 |
513 web_ui()->CallJavascriptFunction("ExtensionSettings.returnExtensionsData", | 523 web_ui()->CallJavascriptFunction("ExtensionSettings.returnExtensionsData", |
514 results); | 524 results); |
515 content::WebContentsObserver::Observe(web_ui()->GetWebContents()); | 525 content::WebContentsObserver::Observe(web_ui()->GetWebContents()); |
516 | 526 |
517 MaybeRegisterForNotifications(); | 527 MaybeRegisterForNotifications(); |
518 } | 528 } |
519 | 529 |
520 void ExtensionSettingsHandler::HandleToggleDeveloperMode( | 530 void ExtensionSettingsHandler::HandleToggleDeveloperMode( |
521 const ListValue* args) { | 531 const ListValue* args) { |
| 532 if (ManagedMode::IsInManagedMode()) |
| 533 return; |
| 534 |
522 Profile* profile = Profile::FromWebUI(web_ui()); | 535 Profile* profile = Profile::FromWebUI(web_ui()); |
523 bool developer_mode = | 536 bool developer_mode = |
524 profile->GetPrefs()->GetBoolean(prefs::kExtensionsUIDeveloperMode); | 537 profile->GetPrefs()->GetBoolean(prefs::kExtensionsUIDeveloperMode); |
525 profile->GetPrefs()->SetBoolean( | 538 profile->GetPrefs()->SetBoolean( |
526 prefs::kExtensionsUIDeveloperMode, !developer_mode); | 539 prefs::kExtensionsUIDeveloperMode, !developer_mode); |
527 } | 540 } |
528 | 541 |
529 void ExtensionSettingsHandler::HandleInspectMessage(const ListValue* args) { | 542 void ExtensionSettingsHandler::HandleInspectMessage(const ListValue* args) { |
530 std::string extension_id; | 543 std::string extension_id; |
531 std::string render_process_id_str; | 544 std::string render_process_id_str; |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
775 chrome::NOTIFICATION_BACKGROUND_CONTENTS_DELETED, | 788 chrome::NOTIFICATION_BACKGROUND_CONTENTS_DELETED, |
776 content::NotificationService::AllBrowserContextsAndSources()); | 789 content::NotificationService::AllBrowserContextsAndSources()); |
777 registrar_.Add( | 790 registrar_.Add( |
778 this, | 791 this, |
779 chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED, | 792 chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED, |
780 content::Source<ExtensionPrefs>(profile->GetExtensionService()-> | 793 content::Source<ExtensionPrefs>(profile->GetExtensionService()-> |
781 extension_prefs())); | 794 extension_prefs())); |
782 | 795 |
783 pref_registrar_.Init(profile->GetPrefs()); | 796 pref_registrar_.Init(profile->GetPrefs()); |
784 pref_registrar_.Add(prefs::kExtensionInstallDenyList, this); | 797 pref_registrar_.Add(prefs::kExtensionInstallDenyList, this); |
| 798 local_state_pref_registrar_.Init(g_browser_process->local_state()); |
| 799 local_state_pref_registrar_.Add(prefs::kInManagedMode, this); |
785 } | 800 } |
786 | 801 |
787 std::vector<ExtensionPage> | 802 std::vector<ExtensionPage> |
788 ExtensionSettingsHandler::GetInspectablePagesForExtension( | 803 ExtensionSettingsHandler::GetInspectablePagesForExtension( |
789 const Extension* extension, bool extension_is_enabled) { | 804 const Extension* extension, bool extension_is_enabled) { |
790 std::vector<ExtensionPage> result; | 805 std::vector<ExtensionPage> result; |
791 | 806 |
792 // Get the extension process's active views. | 807 // Get the extension process's active views. |
793 ExtensionProcessManager* process_manager = | 808 ExtensionProcessManager* process_manager = |
794 extension_service_->profile()->GetExtensionProcessManager(); | 809 extension_service_->profile()->GetExtensionProcessManager(); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
854 return extension_uninstall_dialog_.get(); | 869 return extension_uninstall_dialog_.get(); |
855 #else | 870 #else |
856 return NULL; | 871 return NULL; |
857 #endif // !defined(OS_ANDROID) | 872 #endif // !defined(OS_ANDROID) |
858 } | 873 } |
859 | 874 |
860 void ExtensionSettingsHandler::InspectExtensionHost(ExtensionHost* host) { | 875 void ExtensionSettingsHandler::InspectExtensionHost(ExtensionHost* host) { |
861 if (host) | 876 if (host) |
862 DevToolsWindow::OpenDevToolsWindow(host->render_view_host()); | 877 DevToolsWindow::OpenDevToolsWindow(host->render_view_host()); |
863 } | 878 } |
OLD | NEW |