Chromium Code Reviews| 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" |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 25 #include "chrome/browser/extensions/extension_host.h" | 25 #include "chrome/browser/extensions/extension_host.h" |
| 26 #include "chrome/browser/extensions/extension_service.h" | 26 #include "chrome/browser/extensions/extension_service.h" |
| 27 #include "chrome/browser/extensions/extension_system.h" | 27 #include "chrome/browser/extensions/extension_system.h" |
| 28 #include "chrome/browser/extensions/extension_warning_set.h" | 28 #include "chrome/browser/extensions/extension_warning_set.h" |
| 29 #include "chrome/browser/extensions/lazy_background_task_queue.h" | 29 #include "chrome/browser/extensions/lazy_background_task_queue.h" |
| 30 #include "chrome/browser/extensions/management_policy.h" | 30 #include "chrome/browser/extensions/management_policy.h" |
| 31 #include "chrome/browser/extensions/shell_window_registry.h" | 31 #include "chrome/browser/extensions/shell_window_registry.h" |
| 32 #include "chrome/browser/extensions/unpacked_installer.h" | 32 #include "chrome/browser/extensions/unpacked_installer.h" |
| 33 #include "chrome/browser/extensions/updater/extension_updater.h" | 33 #include "chrome/browser/extensions/updater/extension_updater.h" |
| 34 #include "chrome/browser/google/google_util.h" | 34 #include "chrome/browser/google/google_util.h" |
| 35 #include "chrome/browser/managed_mode/managed_mode_navigation_observer.h" | |
| 35 #include "chrome/browser/managed_mode/managed_user_service.h" | 36 #include "chrome/browser/managed_mode/managed_user_service.h" |
| 36 #include "chrome/browser/managed_mode/managed_user_service_factory.h" | 37 #include "chrome/browser/managed_mode/managed_user_service_factory.h" |
| 38 #include "chrome/browser/managed_mode/scoped_extension_elevation.h" | |
| 37 #include "chrome/browser/profiles/profile.h" | 39 #include "chrome/browser/profiles/profile.h" |
| 38 #include "chrome/browser/tab_contents/background_contents.h" | 40 #include "chrome/browser/tab_contents/background_contents.h" |
| 39 #include "chrome/browser/ui/browser_finder.h" | 41 #include "chrome/browser/ui/browser_finder.h" |
| 40 #include "chrome/browser/ui/chrome_select_file_policy.h" | 42 #include "chrome/browser/ui/chrome_select_file_policy.h" |
| 41 #include "chrome/browser/ui/extensions/application_launch.h" | 43 #include "chrome/browser/ui/extensions/application_launch.h" |
| 42 #include "chrome/browser/ui/extensions/shell_window.h" | 44 #include "chrome/browser/ui/extensions/shell_window.h" |
| 43 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" | 45 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" |
| 44 #include "chrome/browser/view_type_utils.h" | 46 #include "chrome/browser/view_type_utils.h" |
| 45 #include "chrome/common/chrome_notification_types.h" | 47 #include "chrome/common/chrome_notification_types.h" |
| 46 #include "chrome/common/chrome_switches.h" | 48 #include "chrome/common/chrome_switches.h" |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 124 | 126 |
| 125 DictionaryValue* ExtensionSettingsHandler::CreateExtensionDetailValue( | 127 DictionaryValue* ExtensionSettingsHandler::CreateExtensionDetailValue( |
| 126 const Extension* extension, | 128 const Extension* extension, |
| 127 const std::vector<ExtensionPage>& pages, | 129 const std::vector<ExtensionPage>& pages, |
| 128 const extensions::ExtensionWarningService* warning_service) { | 130 const extensions::ExtensionWarningService* warning_service) { |
| 129 DictionaryValue* extension_data = new DictionaryValue(); | 131 DictionaryValue* extension_data = new DictionaryValue(); |
| 130 bool enabled = extension_service_->IsExtensionEnabled(extension->id()); | 132 bool enabled = extension_service_->IsExtensionEnabled(extension->id()); |
| 131 extension->GetBasicInfo(enabled, extension_data); | 133 extension->GetBasicInfo(enabled, extension_data); |
| 132 | 134 |
| 133 extension_data->SetBoolean("userModifiable", | 135 extension_data->SetBoolean("userModifiable", |
| 134 management_policy_->UserMayModifySettings(extension, NULL)); | 136 CheckUserMayModifySettings(extension)); |
| 135 | 137 |
| 136 GURL icon = | 138 GURL icon = |
| 137 ExtensionIconSource::GetIconURL(extension, | 139 ExtensionIconSource::GetIconURL(extension, |
| 138 extension_misc::EXTENSION_ICON_MEDIUM, | 140 extension_misc::EXTENSION_ICON_MEDIUM, |
| 139 ExtensionIconSet::MATCH_BIGGER, | 141 ExtensionIconSet::MATCH_BIGGER, |
| 140 !enabled, NULL); | 142 !enabled, NULL); |
| 141 if (Manifest::IsUnpackedLocation(extension->location())) | 143 if (Manifest::IsUnpackedLocation(extension->location())) |
| 142 extension_data->SetString("path", extension->path().value()); | 144 extension_data->SetString("path", extension->path().value()); |
| 143 extension_data->SetString("icon", icon.spec()); | 145 extension_data->SetString("icon", icon.spec()); |
| 144 extension_data->SetBoolean("isUnpacked", | 146 extension_data->SetBoolean("isUnpacked", |
| (...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 547 | 549 |
| 548 for (std::vector<const Extension*>::iterator iter = | 550 for (std::vector<const Extension*>::iterator iter = |
| 549 unpacked_extensions.begin(); iter != unpacked_extensions.end(); ++iter) { | 551 unpacked_extensions.begin(); iter != unpacked_extensions.end(); ++iter) { |
| 550 extension_service_->ReloadExtension((*iter)->id()); | 552 extension_service_->ReloadExtension((*iter)->id()); |
| 551 } | 553 } |
| 552 } | 554 } |
| 553 | 555 |
| 554 void ExtensionSettingsHandler::PassphraseDialogCallback(bool success) { | 556 void ExtensionSettingsHandler::PassphraseDialogCallback(bool success) { |
| 555 if (!success) | 557 if (!success) |
| 556 return; | 558 return; |
| 557 Profile* profile = Profile::FromWebUI(web_ui()); | 559 ManagedModeNavigationObserver* observer = |
| 558 ManagedUserServiceFactory::GetForProfile(profile)->SetElevated(true); | 560 ManagedModeNavigationObserver::FromWebContents( |
| 561 web_ui()->GetWebContents()); | |
| 562 observer->set_elevated(true); | |
| 559 HandleRequestExtensionsData(NULL); | 563 HandleRequestExtensionsData(NULL); |
| 560 } | 564 } |
| 561 | 565 |
| 562 void ExtensionSettingsHandler::ManagedUserSetElevated(const ListValue* args) { | 566 void ExtensionSettingsHandler::ManagedUserSetElevated(const ListValue* args) { |
| 563 ManagedUserService* service = ManagedUserServiceFactory::GetForProfile( | 567 ManagedUserService* service = ManagedUserServiceFactory::GetForProfile( |
| 564 Profile::FromWebUI(web_ui())); | 568 Profile::FromWebUI(web_ui())); |
| 565 bool elevated; | 569 bool elevated; |
| 566 CHECK(args->GetBoolean(0, &elevated)); | 570 CHECK(args->GetBoolean(0, &elevated)); |
| 567 if (elevated) { | 571 if (elevated) { |
| 568 service->RequestAuthorization( | 572 service->RequestAuthorization( |
| 569 web_ui()->GetWebContents(), | 573 web_ui()->GetWebContents(), |
| 570 base::Bind(&ExtensionSettingsHandler::PassphraseDialogCallback, | 574 base::Bind(&ExtensionSettingsHandler::PassphraseDialogCallback, |
| 571 base::Unretained(this))); | 575 base::Unretained(this))); |
| 572 } else { | 576 } else { |
| 573 service->SetElevated(false); | 577 ManagedModeNavigationObserver* observer = |
| 578 ManagedModeNavigationObserver::FromWebContents( | |
| 579 web_ui()->GetWebContents()); | |
| 580 observer->set_elevated(false); | |
| 574 HandleRequestExtensionsData(NULL); | 581 HandleRequestExtensionsData(NULL); |
| 575 } | 582 } |
| 576 } | 583 } |
| 577 | 584 |
| 585 bool ExtensionSettingsHandler::CheckUserMayModifySettings( | |
| 586 const Extension* extension) { | |
| 587 ManagedUserService* service = ManagedUserServiceFactory::GetForProfile( | |
| 588 Profile::FromWebUI(web_ui())); | |
| 589 scoped_ptr<ScopedExtensionElevation> elevation; | |
| 590 if (service->ProfileIsManaged() && | |
| 591 service->IsElevatedForWebContents(web_ui()->GetWebContents())) { | |
| 592 elevation.reset(new ScopedExtensionElevation(service)); | |
| 593 elevation->AddExtension(extension->id()); | |
| 594 } | |
| 595 return management_policy_->UserMayModifySettings(extension, NULL); | |
| 596 } | |
| 597 | |
| 578 void ExtensionSettingsHandler::HandleRequestExtensionsData( | 598 void ExtensionSettingsHandler::HandleRequestExtensionsData( |
| 579 const ListValue* args) { | 599 const ListValue* args) { |
| 580 DictionaryValue results; | 600 DictionaryValue results; |
| 581 | 601 |
| 582 Profile* profile = Profile::FromWebUI(web_ui()); | 602 Profile* profile = Profile::FromWebUI(web_ui()); |
| 583 | 603 |
| 584 // Add the extensions to the results structure. | 604 // Add the extensions to the results structure. |
| 585 ListValue *extensions_list = new ListValue(); | 605 ListValue *extensions_list = new ListValue(); |
| 586 | 606 |
| 587 extensions::ExtensionWarningService* warnings = | 607 extensions::ExtensionWarningService* warnings = |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 617 empty_pages, // Terminated process has no active pages. | 637 empty_pages, // Terminated process has no active pages. |
| 618 warnings)); | 638 warnings)); |
| 619 } | 639 } |
| 620 } | 640 } |
| 621 results.Set("extensions", extensions_list); | 641 results.Set("extensions", extensions_list); |
| 622 | 642 |
| 623 ManagedUserService* service = | 643 ManagedUserService* service = |
| 624 ManagedUserServiceFactory::GetForProfile(profile); | 644 ManagedUserServiceFactory::GetForProfile(profile); |
| 625 | 645 |
| 626 bool is_managed = service->ProfileIsManaged(); | 646 bool is_managed = service->ProfileIsManaged(); |
| 627 bool is_elevated = service->IsElevated(); | 647 bool is_elevated = |
| 648 service->IsElevatedForWebContents(web_ui()->GetWebContents()); | |
| 628 bool developer_mode = | 649 bool developer_mode = |
| 629 (!is_managed || is_elevated) && | 650 (!is_managed || is_elevated) && |
| 630 profile->GetPrefs()->GetBoolean(prefs::kExtensionsUIDeveloperMode); | 651 profile->GetPrefs()->GetBoolean(prefs::kExtensionsUIDeveloperMode); |
| 631 results.SetBoolean("profileIsManaged", is_managed); | 652 results.SetBoolean("profileIsManaged", is_managed); |
| 632 results.SetBoolean("profileIsElevated", is_elevated); | 653 results.SetBoolean("profileIsElevated", is_elevated); |
| 633 results.SetBoolean("developerMode", developer_mode); | 654 results.SetBoolean("developerMode", developer_mode); |
| 634 | 655 |
| 635 // Check to see if we have any wiped out extensions. | 656 // Check to see if we have any wiped out extensions. |
| 636 ExtensionService* extension_service = | 657 ExtensionService* extension_service = |
| 637 extensions::ExtensionSystem::Get(profile)->extension_service(); | 658 extensions::ExtensionSystem::Get(profile)->extension_service(); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 728 } | 749 } |
| 729 | 750 |
| 730 void ExtensionSettingsHandler::HandleEnableMessage(const ListValue* args) { | 751 void ExtensionSettingsHandler::HandleEnableMessage(const ListValue* args) { |
| 731 CHECK_EQ(2U, args->GetSize()); | 752 CHECK_EQ(2U, args->GetSize()); |
| 732 std::string extension_id, enable_str; | 753 std::string extension_id, enable_str; |
| 733 CHECK(args->GetString(0, &extension_id)); | 754 CHECK(args->GetString(0, &extension_id)); |
| 734 CHECK(args->GetString(1, &enable_str)); | 755 CHECK(args->GetString(1, &enable_str)); |
| 735 | 756 |
| 736 const Extension* extension = | 757 const Extension* extension = |
| 737 extension_service_->GetInstalledExtension(extension_id); | 758 extension_service_->GetInstalledExtension(extension_id); |
| 738 if (!extension || | 759 if (!extension || !CheckUserMayModifySettings(extension)) { |
| 739 !management_policy_->UserMayModifySettings(extension, NULL)) { | |
| 740 LOG(ERROR) << "Attempt to enable an extension that is non-usermanagable was" | 760 LOG(ERROR) << "Attempt to enable an extension that is non-usermanagable was" |
| 741 << "made. Extension id: " << extension->id(); | 761 << "made. Extension id: " << extension->id(); |
| 742 return; | 762 return; |
| 743 } | 763 } |
| 744 | 764 |
| 745 if (enable_str == "true") { | 765 if (enable_str == "true") { |
| 746 extensions::ExtensionPrefs* prefs = extension_service_->extension_prefs(); | 766 extensions::ExtensionPrefs* prefs = extension_service_->extension_prefs(); |
| 747 if (prefs->DidExtensionEscalatePermissions(extension_id)) { | 767 if (prefs->DidExtensionEscalatePermissions(extension_id)) { |
| 748 extensions::ShowExtensionDisabledDialog( | 768 extensions::ShowExtensionDisabledDialog( |
| 749 extension_service_, web_ui()->GetWebContents(), extension); | 769 extension_service_, web_ui()->GetWebContents(), extension); |
| 750 } else if ((prefs->GetDisableReasons(extension_id) & | 770 } else if ((prefs->GetDisableReasons(extension_id) & |
| 751 Extension::DISABLE_UNSUPPORTED_REQUIREMENT) && | 771 Extension::DISABLE_UNSUPPORTED_REQUIREMENT) && |
| 752 !requirements_checker_.get()) { | 772 !requirements_checker_.get()) { |
| 753 // Recheck the requirements. | 773 // Recheck the requirements. |
| 754 scoped_refptr<const Extension> extension = | 774 scoped_refptr<const Extension> extension = |
| 755 extension_service_->GetExtensionById(extension_id, | 775 extension_service_->GetExtensionById(extension_id, |
| 756 true /* include disabled */); | 776 true /* include disabled */); |
| 757 requirements_checker_.reset(new extensions::RequirementsChecker()); | 777 requirements_checker_.reset(new extensions::RequirementsChecker()); |
| 758 requirements_checker_->Check( | 778 requirements_checker_->Check( |
| 759 extension, | 779 extension, |
| 760 base::Bind(&ExtensionSettingsHandler::OnRequirementsChecked, | 780 base::Bind(&ExtensionSettingsHandler::OnRequirementsChecked, |
| 761 AsWeakPtr(), extension_id)); | 781 AsWeakPtr(), extension_id)); |
| 762 } else { | 782 } else { |
| 763 extension_service_->EnableExtension(extension_id); | 783 extension_service_->EnableExtension(extension_id); |
| 764 | 784 |
| 765 // Make sure any browser action contained within it is not hidden. | 785 // Make sure any browser action contained within it is not hidden. |
| 766 prefs->SetBrowserActionVisibility(extension, true); | 786 prefs->SetBrowserActionVisibility(extension, true); |
| 767 } | 787 } |
| 768 } else { | 788 } else { |
| 789 ManagedUserService* service = ManagedUserServiceFactory::GetForProfile( | |
| 790 Profile::FromWebUI(web_ui())); | |
| 791 scoped_ptr<ScopedExtensionElevation> elevation; | |
|
Bernhard Bauer
2013/03/28 15:52:01
The nice thing is that now you can construct the o
Adrian Kuegel
2013/03/28 16:05:53
Done.
| |
| 792 if (service->ProfileIsManaged() && | |
| 793 service->IsElevatedForWebContents(web_ui()->GetWebContents())) { | |
| 794 elevation.reset(new ScopedExtensionElevation(service)); | |
| 795 elevation->AddExtension(extension_id); | |
| 796 } | |
| 769 extension_service_->DisableExtension( | 797 extension_service_->DisableExtension( |
| 770 extension_id, Extension::DISABLE_USER_ACTION); | 798 extension_id, Extension::DISABLE_USER_ACTION); |
| 771 } | 799 } |
| 772 } | 800 } |
| 773 | 801 |
| 774 void ExtensionSettingsHandler::HandleEnableIncognitoMessage( | 802 void ExtensionSettingsHandler::HandleEnableIncognitoMessage( |
| 775 const ListValue* args) { | 803 const ListValue* args) { |
| 776 CHECK_EQ(2U, args->GetSize()); | 804 CHECK_EQ(2U, args->GetSize()); |
| 777 std::string extension_id, enable_str; | 805 std::string extension_id, enable_str; |
| 778 CHECK(args->GetString(0, &extension_id)); | 806 CHECK(args->GetString(0, &extension_id)); |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 803 const ListValue* args) { | 831 const ListValue* args) { |
| 804 CHECK_EQ(2U, args->GetSize()); | 832 CHECK_EQ(2U, args->GetSize()); |
| 805 std::string extension_id, allow_str; | 833 std::string extension_id, allow_str; |
| 806 CHECK(args->GetString(0, &extension_id)); | 834 CHECK(args->GetString(0, &extension_id)); |
| 807 CHECK(args->GetString(1, &allow_str)); | 835 CHECK(args->GetString(1, &allow_str)); |
| 808 const Extension* extension = | 836 const Extension* extension = |
| 809 extension_service_->GetInstalledExtension(extension_id); | 837 extension_service_->GetInstalledExtension(extension_id); |
| 810 if (!extension) | 838 if (!extension) |
| 811 return; | 839 return; |
| 812 | 840 |
| 813 if (!management_policy_->UserMayModifySettings(extension, NULL)) { | 841 if (!CheckUserMayModifySettings(extension)) { |
| 814 LOG(ERROR) << "Attempt to change allow file access of an extension that is " | 842 LOG(ERROR) << "Attempt to change allow file access of an extension that is " |
| 815 << "non-usermanagable was made. Extension id : " | 843 << "non-usermanagable was made. Extension id : " |
| 816 << extension->id(); | 844 << extension->id(); |
| 817 return; | 845 return; |
| 818 } | 846 } |
| 819 | 847 |
| 820 extension_service_->SetAllowFileAccess(extension, allow_str == "true"); | 848 extension_service_->SetAllowFileAccess(extension, allow_str == "true"); |
| 821 } | 849 } |
| 822 | 850 |
| 823 void ExtensionSettingsHandler::HandleUninstallMessage(const ListValue* args) { | 851 void ExtensionSettingsHandler::HandleUninstallMessage(const ListValue* args) { |
| 824 CHECK_EQ(1U, args->GetSize()); | 852 CHECK_EQ(1U, args->GetSize()); |
| 825 std::string extension_id; | 853 std::string extension_id; |
| 826 CHECK(args->GetString(0, &extension_id)); | 854 CHECK(args->GetString(0, &extension_id)); |
| 827 const Extension* extension = | 855 const Extension* extension = |
| 828 extension_service_->GetInstalledExtension(extension_id); | 856 extension_service_->GetInstalledExtension(extension_id); |
| 829 if (!extension) | 857 if (!extension) |
| 830 return; | 858 return; |
| 831 | 859 |
| 832 if (!management_policy_->UserMayModifySettings(extension, NULL)) { | 860 if (!CheckUserMayModifySettings(extension)) { |
| 833 LOG(ERROR) << "Attempt to uninstall an extension that is non-usermanagable " | 861 LOG(ERROR) << "Attempt to uninstall an extension that is non-usermanagable " |
| 834 << "was made. Extension id : " << extension->id(); | 862 << "was made. Extension id : " << extension->id(); |
| 835 return; | 863 return; |
| 836 } | 864 } |
| 837 | 865 |
| 838 if (!extension_id_prompting_.empty()) | 866 if (!extension_id_prompting_.empty()) |
| 839 return; // Only one prompt at a time. | 867 return; // Only one prompt at a time. |
| 840 | 868 |
| 841 extension_id_prompting_ = extension_id; | 869 extension_id_prompting_ = extension_id; |
| 842 | 870 |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1077 std::vector<std::string> requirement_errors) { | 1105 std::vector<std::string> requirement_errors) { |
| 1078 if (requirement_errors.empty()) { | 1106 if (requirement_errors.empty()) { |
| 1079 extension_service_->EnableExtension(extension_id); | 1107 extension_service_->EnableExtension(extension_id); |
| 1080 } else { | 1108 } else { |
| 1081 ExtensionErrorReporter::GetInstance()->ReportError( | 1109 ExtensionErrorReporter::GetInstance()->ReportError( |
| 1082 UTF8ToUTF16(JoinString(requirement_errors, ' ')), | 1110 UTF8ToUTF16(JoinString(requirement_errors, ' ')), |
| 1083 true /* be noisy */); | 1111 true /* be noisy */); |
| 1084 } | 1112 } |
| 1085 requirements_checker_.reset(); | 1113 requirements_checker_.reset(); |
| 1086 } | 1114 } |
| OLD | NEW |