| 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/webui/extensions/extension_icon_source.h" | 33 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" |
| 32 #include "chrome/browser/view_type_utils.h" | 34 #include "chrome/browser/view_type_utils.h" |
| 33 #include "chrome/common/chrome_notification_types.h" | 35 #include "chrome/common/chrome_notification_types.h" |
| 34 #include "chrome/common/chrome_switches.h" | 36 #include "chrome/common/chrome_switches.h" |
| 35 #include "chrome/common/extensions/extension.h" | 37 #include "chrome/common/extensions/extension.h" |
| 36 #include "chrome/common/extensions/extension_icon_set.h" | 38 #include "chrome/common/extensions/extension_icon_set.h" |
| 37 #include "chrome/common/extensions/extension_set.h" | 39 #include "chrome/common/extensions/extension_set.h" |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 localized_strings->SetString("extensionSettingsOptions", | 256 localized_strings->SetString("extensionSettingsOptions", |
| 255 l10n_util::GetStringUTF16(IDS_EXTENSIONS_OPTIONS_LINK)); | 257 l10n_util::GetStringUTF16(IDS_EXTENSIONS_OPTIONS_LINK)); |
| 256 localized_strings->SetString("extensionSettingsActivity", | 258 localized_strings->SetString("extensionSettingsActivity", |
| 257 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ACTIVITY_LINK)); | 259 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ACTIVITY_LINK)); |
| 258 localized_strings->SetString("extensionSettingsVisitWebsite", | 260 localized_strings->SetString("extensionSettingsVisitWebsite", |
| 259 l10n_util::GetStringUTF16(IDS_EXTENSIONS_VISIT_WEBSITE)); | 261 l10n_util::GetStringUTF16(IDS_EXTENSIONS_VISIT_WEBSITE)); |
| 260 localized_strings->SetString("extensionSettingsVisitWebStore", | 262 localized_strings->SetString("extensionSettingsVisitWebStore", |
| 261 l10n_util::GetStringUTF16(IDS_EXTENSIONS_VISIT_WEBSTORE)); | 263 l10n_util::GetStringUTF16(IDS_EXTENSIONS_VISIT_WEBSTORE)); |
| 262 localized_strings->SetString("extensionSettingsPolicyControlled", | 264 localized_strings->SetString("extensionSettingsPolicyControlled", |
| 263 l10n_util::GetStringUTF16(IDS_EXTENSIONS_POLICY_CONTROLLED)); | 265 l10n_util::GetStringUTF16(IDS_EXTENSIONS_POLICY_CONTROLLED)); |
| 266 localized_strings->SetString("extensionSettingsManagedMode", |
| 267 l10n_util::GetStringUTF16(IDS_EXTENSIONS_LOCKED_MANAGED_MODE)); |
| 264 localized_strings->SetString("extensionSettingsShowButton", | 268 localized_strings->SetString("extensionSettingsShowButton", |
| 265 l10n_util::GetStringUTF16(IDS_EXTENSIONS_SHOW_BUTTON)); | 269 l10n_util::GetStringUTF16(IDS_EXTENSIONS_SHOW_BUTTON)); |
| 266 localized_strings->SetString("extensionSettingsLoadUnpackedButton", | 270 localized_strings->SetString("extensionSettingsLoadUnpackedButton", |
| 267 l10n_util::GetStringUTF16(IDS_EXTENSIONS_LOAD_UNPACKED_BUTTON)); | 271 l10n_util::GetStringUTF16(IDS_EXTENSIONS_LOAD_UNPACKED_BUTTON)); |
| 268 localized_strings->SetString("extensionSettingsPackButton", | 272 localized_strings->SetString("extensionSettingsPackButton", |
| 269 l10n_util::GetStringUTF16(IDS_EXTENSIONS_PACK_BUTTON)); | 273 l10n_util::GetStringUTF16(IDS_EXTENSIONS_PACK_BUTTON)); |
| 270 localized_strings->SetString("extensionSettingsCommandsLink", | 274 localized_strings->SetString("extensionSettingsCommandsLink", |
| 271 l10n_util::GetStringUTF16(IDS_EXTENSIONS_COMMANDS_CONFIGURE)); | 275 l10n_util::GetStringUTF16(IDS_EXTENSIONS_COMMANDS_CONFIGURE)); |
| 272 localized_strings->SetString("extensionSettingsUpdateButton", | 276 localized_strings->SetString("extensionSettingsUpdateButton", |
| 273 l10n_util::GetStringUTF16(IDS_EXTENSIONS_UPDATE_BUTTON)); | 277 l10n_util::GetStringUTF16(IDS_EXTENSIONS_UPDATE_BUTTON)); |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 extension != extensions->end(); ++extension) { | 492 extension != extensions->end(); ++extension) { |
| 489 if ((*extension)->ShouldDisplayInExtensionSettings()) { | 493 if ((*extension)->ShouldDisplayInExtensionSettings()) { |
| 490 extensions_list->Append(CreateExtensionDetailValue( | 494 extensions_list->Append(CreateExtensionDetailValue( |
| 491 *extension, | 495 *extension, |
| 492 empty_pages, // Terminated process has no active pages. | 496 empty_pages, // Terminated process has no active pages. |
| 493 warnings)); | 497 warnings)); |
| 494 } | 498 } |
| 495 } | 499 } |
| 496 results.Set("extensions", extensions_list); | 500 results.Set("extensions", extensions_list); |
| 497 | 501 |
| 498 Profile* profile = Profile::FromWebUI(web_ui()); | 502 if (ManagedMode::IsInManagedMode()) { |
| 499 bool developer_mode = | 503 results.SetBoolean("managedMode", true); |
| 500 profile->GetPrefs()->GetBoolean(prefs::kExtensionsUIDeveloperMode); | 504 results.SetBoolean("developerMode", false); |
| 501 results.SetBoolean("developerMode", developer_mode); | 505 } else { |
| 506 results.SetBoolean("managedMode", false); |
| 507 Profile* profile = Profile::FromWebUI(web_ui()); |
| 508 bool developer_mode = |
| 509 profile->GetPrefs()->GetBoolean(prefs::kExtensionsUIDeveloperMode); |
| 510 results.SetBoolean("developerMode", developer_mode); |
| 511 } |
| 502 | 512 |
| 503 bool load_unpacked_disabled = | 513 bool load_unpacked_disabled = |
| 504 extension_service_->extension_prefs()->ExtensionsBlacklistedByDefault(); | 514 extension_service_->extension_prefs()->ExtensionsBlacklistedByDefault(); |
| 505 results.SetBoolean("loadUnpackedDisabled", load_unpacked_disabled); | 515 results.SetBoolean("loadUnpackedDisabled", load_unpacked_disabled); |
| 506 | 516 |
| 507 web_ui()->CallJavascriptFunction("ExtensionSettings.returnExtensionsData", | 517 web_ui()->CallJavascriptFunction("ExtensionSettings.returnExtensionsData", |
| 508 results); | 518 results); |
| 509 content::WebContentsObserver::Observe(web_ui()->GetWebContents()); | 519 content::WebContentsObserver::Observe(web_ui()->GetWebContents()); |
| 510 | 520 |
| 511 MaybeRegisterForNotifications(); | 521 MaybeRegisterForNotifications(); |
| 512 } | 522 } |
| 513 | 523 |
| 514 void ExtensionSettingsHandler::HandleToggleDeveloperMode( | 524 void ExtensionSettingsHandler::HandleToggleDeveloperMode( |
| 515 const ListValue* args) { | 525 const ListValue* args) { |
| 526 if (ManagedMode::IsInManagedMode()) |
| 527 return; |
| 528 |
| 516 Profile* profile = Profile::FromWebUI(web_ui()); | 529 Profile* profile = Profile::FromWebUI(web_ui()); |
| 517 bool developer_mode = | 530 bool developer_mode = |
| 518 profile->GetPrefs()->GetBoolean(prefs::kExtensionsUIDeveloperMode); | 531 profile->GetPrefs()->GetBoolean(prefs::kExtensionsUIDeveloperMode); |
| 519 profile->GetPrefs()->SetBoolean( | 532 profile->GetPrefs()->SetBoolean( |
| 520 prefs::kExtensionsUIDeveloperMode, !developer_mode); | 533 prefs::kExtensionsUIDeveloperMode, !developer_mode); |
| 521 } | 534 } |
| 522 | 535 |
| 523 void ExtensionSettingsHandler::HandleInspectMessage(const ListValue* args) { | 536 void ExtensionSettingsHandler::HandleInspectMessage(const ListValue* args) { |
| 524 std::string extension_id; | 537 std::string extension_id; |
| 525 std::string render_process_id_str; | 538 std::string render_process_id_str; |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 767 chrome::NOTIFICATION_BACKGROUND_CONTENTS_DELETED, | 780 chrome::NOTIFICATION_BACKGROUND_CONTENTS_DELETED, |
| 768 content::NotificationService::AllBrowserContextsAndSources()); | 781 content::NotificationService::AllBrowserContextsAndSources()); |
| 769 registrar_.Add( | 782 registrar_.Add( |
| 770 this, | 783 this, |
| 771 chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED, | 784 chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED, |
| 772 content::Source<ExtensionPrefs>(profile->GetExtensionService()-> | 785 content::Source<ExtensionPrefs>(profile->GetExtensionService()-> |
| 773 extension_prefs())); | 786 extension_prefs())); |
| 774 | 787 |
| 775 pref_registrar_.Init(profile->GetPrefs()); | 788 pref_registrar_.Init(profile->GetPrefs()); |
| 776 pref_registrar_.Add(prefs::kExtensionInstallDenyList, this); | 789 pref_registrar_.Add(prefs::kExtensionInstallDenyList, this); |
| 790 local_state_pref_registrar_.Init(g_browser_process->local_state()); |
| 791 local_state_pref_registrar_.Add(prefs::kInManagedMode, this); |
| 777 } | 792 } |
| 778 | 793 |
| 779 std::vector<ExtensionPage> | 794 std::vector<ExtensionPage> |
| 780 ExtensionSettingsHandler::GetInspectablePagesForExtension( | 795 ExtensionSettingsHandler::GetInspectablePagesForExtension( |
| 781 const Extension* extension, bool extension_is_enabled) { | 796 const Extension* extension, bool extension_is_enabled) { |
| 782 std::vector<ExtensionPage> result; | 797 std::vector<ExtensionPage> result; |
| 783 | 798 |
| 784 // Get the extension process's active views. | 799 // Get the extension process's active views. |
| 785 ExtensionProcessManager* process_manager = | 800 ExtensionProcessManager* process_manager = |
| 786 extension_service_->profile()->GetExtensionProcessManager(); | 801 extension_service_->profile()->GetExtensionProcessManager(); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 846 return extension_uninstall_dialog_.get(); | 861 return extension_uninstall_dialog_.get(); |
| 847 #else | 862 #else |
| 848 return NULL; | 863 return NULL; |
| 849 #endif // !defined(OS_ANDROID) | 864 #endif // !defined(OS_ANDROID) |
| 850 } | 865 } |
| 851 | 866 |
| 852 void ExtensionSettingsHandler::InspectExtensionHost(ExtensionHost* host) { | 867 void ExtensionSettingsHandler::InspectExtensionHost(ExtensionHost* host) { |
| 853 if (host) | 868 if (host) |
| 854 DevToolsWindow::OpenDevToolsWindow(host->render_view_host()); | 869 DevToolsWindow::OpenDevToolsWindow(host->render_view_host()); |
| 855 } | 870 } |
| OLD | NEW |