| 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" |
| 37 #include "chrome/browser/profiles/profile.h" | 38 #include "chrome/browser/profiles/profile.h" |
| 38 #include "chrome/browser/tab_contents/background_contents.h" | 39 #include "chrome/browser/tab_contents/background_contents.h" |
| 39 #include "chrome/browser/ui/browser_finder.h" | 40 #include "chrome/browser/ui/browser_finder.h" |
| 40 #include "chrome/browser/ui/chrome_select_file_policy.h" | 41 #include "chrome/browser/ui/chrome_select_file_policy.h" |
| 41 #include "chrome/browser/ui/extensions/application_launch.h" | 42 #include "chrome/browser/ui/extensions/application_launch.h" |
| 42 #include "chrome/browser/ui/extensions/shell_window.h" | 43 #include "chrome/browser/ui/extensions/shell_window.h" |
| 43 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" | 44 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" |
| 44 #include "chrome/common/chrome_notification_types.h" | 45 #include "chrome/common/chrome_notification_types.h" |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 | 125 |
| 125 DictionaryValue* ExtensionSettingsHandler::CreateExtensionDetailValue( | 126 DictionaryValue* ExtensionSettingsHandler::CreateExtensionDetailValue( |
| 126 const Extension* extension, | 127 const Extension* extension, |
| 127 const std::vector<ExtensionPage>& pages, | 128 const std::vector<ExtensionPage>& pages, |
| 128 const extensions::ExtensionWarningService* warning_service) { | 129 const extensions::ExtensionWarningService* warning_service) { |
| 129 DictionaryValue* extension_data = new DictionaryValue(); | 130 DictionaryValue* extension_data = new DictionaryValue(); |
| 130 bool enabled = extension_service_->IsExtensionEnabled(extension->id()); | 131 bool enabled = extension_service_->IsExtensionEnabled(extension->id()); |
| 131 extension->GetBasicInfo(enabled, extension_data); | 132 extension->GetBasicInfo(enabled, extension_data); |
| 132 | 133 |
| 133 extension_data->SetBoolean("userModifiable", | 134 extension_data->SetBoolean("userModifiable", |
| 134 management_policy_->UserMayModifySettings(extension, NULL)); | 135 CheckUserMayModifySettings(extension)); |
| 135 | 136 |
| 136 GURL icon = | 137 GURL icon = |
| 137 ExtensionIconSource::GetIconURL(extension, | 138 ExtensionIconSource::GetIconURL(extension, |
| 138 extension_misc::EXTENSION_ICON_MEDIUM, | 139 extension_misc::EXTENSION_ICON_MEDIUM, |
| 139 ExtensionIconSet::MATCH_BIGGER, | 140 ExtensionIconSet::MATCH_BIGGER, |
| 140 !enabled, NULL); | 141 !enabled, NULL); |
| 141 if (Manifest::IsUnpackedLocation(extension->location())) | 142 if (Manifest::IsUnpackedLocation(extension->location())) |
| 142 extension_data->SetString("path", extension->path().value()); | 143 extension_data->SetString("path", extension->path().value()); |
| 143 extension_data->SetString("icon", icon.spec()); | 144 extension_data->SetString("icon", icon.spec()); |
| 144 extension_data->SetBoolean("isUnpacked", | 145 extension_data->SetBoolean("isUnpacked", |
| (...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 | 548 |
| 548 for (std::vector<const Extension*>::iterator iter = | 549 for (std::vector<const Extension*>::iterator iter = |
| 549 unpacked_extensions.begin(); iter != unpacked_extensions.end(); ++iter) { | 550 unpacked_extensions.begin(); iter != unpacked_extensions.end(); ++iter) { |
| 550 extension_service_->ReloadExtension((*iter)->id()); | 551 extension_service_->ReloadExtension((*iter)->id()); |
| 551 } | 552 } |
| 552 } | 553 } |
| 553 | 554 |
| 554 void ExtensionSettingsHandler::PassphraseDialogCallback(bool success) { | 555 void ExtensionSettingsHandler::PassphraseDialogCallback(bool success) { |
| 555 if (!success) | 556 if (!success) |
| 556 return; | 557 return; |
| 557 Profile* profile = Profile::FromWebUI(web_ui()); | 558 ManagedModeNavigationObserver* observer = |
| 558 ManagedUserServiceFactory::GetForProfile(profile)->SetElevated(true); | 559 ManagedModeNavigationObserver::FromWebContents( |
| 560 web_ui()->GetWebContents()); |
| 561 observer->set_elevated(true); |
| 559 HandleRequestExtensionsData(NULL); | 562 HandleRequestExtensionsData(NULL); |
| 560 } | 563 } |
| 561 | 564 |
| 562 void ExtensionSettingsHandler::ManagedUserSetElevated(const ListValue* args) { | 565 void ExtensionSettingsHandler::ManagedUserSetElevated(const ListValue* args) { |
| 563 ManagedUserService* service = ManagedUserServiceFactory::GetForProfile( | 566 ManagedUserService* service = ManagedUserServiceFactory::GetForProfile( |
| 564 Profile::FromWebUI(web_ui())); | 567 Profile::FromWebUI(web_ui())); |
| 565 bool elevated; | 568 bool elevated; |
| 566 CHECK(args->GetBoolean(0, &elevated)); | 569 CHECK(args->GetBoolean(0, &elevated)); |
| 567 if (elevated) { | 570 if (elevated) { |
| 568 service->RequestAuthorization( | 571 service->RequestAuthorization( |
| 569 web_ui()->GetWebContents(), | 572 web_ui()->GetWebContents(), |
| 570 base::Bind(&ExtensionSettingsHandler::PassphraseDialogCallback, | 573 base::Bind(&ExtensionSettingsHandler::PassphraseDialogCallback, |
| 571 base::Unretained(this))); | 574 base::Unretained(this))); |
| 572 } else { | 575 } else { |
| 573 service->SetElevated(false); | 576 ManagedModeNavigationObserver* observer = |
| 577 ManagedModeNavigationObserver::FromWebContents( |
| 578 web_ui()->GetWebContents()); |
| 579 observer->set_elevated(false); |
| 574 HandleRequestExtensionsData(NULL); | 580 HandleRequestExtensionsData(NULL); |
| 575 } | 581 } |
| 576 } | 582 } |
| 577 | 583 |
| 584 scoped_ptr<ScopedExtensionElevation> |
| 585 ExtensionSettingsHandler::GetScopedElevation( |
| 586 const std::string& extension_id) { |
| 587 // web_ui() can be NULL in a unit_test. |
| 588 if (web_ui() == NULL) |
| 589 return scoped_ptr<ScopedExtensionElevation>(NULL); |
| 590 ManagedUserService* service = ManagedUserServiceFactory::GetForProfile( |
| 591 Profile::FromWebUI(web_ui())); |
| 592 scoped_ptr<ScopedExtensionElevation> elevation( |
| 593 new ScopedExtensionElevation(service)); |
| 594 if (service->ProfileIsManaged() && |
| 595 service->IsElevatedForWebContents(web_ui()->GetWebContents())) { |
| 596 elevation->AddExtension(extension_id); |
| 597 } |
| 598 return elevation.Pass(); |
| 599 } |
| 600 |
| 601 bool ExtensionSettingsHandler::CheckUserMayModifySettings( |
| 602 const Extension* extension) { |
| 603 // Get managed user elevation for a specific extension id. The elevation will |
| 604 // be removed automatically when |elevation| goes out of scope. |
| 605 scoped_ptr<ScopedExtensionElevation> elevation = |
| 606 GetScopedElevation(extension->id()); |
| 607 return management_policy_->UserMayModifySettings(extension, NULL); |
| 608 } |
| 609 |
| 578 void ExtensionSettingsHandler::HandleRequestExtensionsData( | 610 void ExtensionSettingsHandler::HandleRequestExtensionsData( |
| 579 const ListValue* args) { | 611 const ListValue* args) { |
| 580 DictionaryValue results; | 612 DictionaryValue results; |
| 581 | 613 |
| 582 Profile* profile = Profile::FromWebUI(web_ui()); | 614 Profile* profile = Profile::FromWebUI(web_ui()); |
| 583 | 615 |
| 584 // Add the extensions to the results structure. | 616 // Add the extensions to the results structure. |
| 585 ListValue *extensions_list = new ListValue(); | 617 ListValue *extensions_list = new ListValue(); |
| 586 | 618 |
| 587 extensions::ExtensionWarningService* warnings = | 619 extensions::ExtensionWarningService* warnings = |
| (...skipping 29 matching lines...) Expand all Loading... |
| 617 empty_pages, // Terminated process has no active pages. | 649 empty_pages, // Terminated process has no active pages. |
| 618 warnings)); | 650 warnings)); |
| 619 } | 651 } |
| 620 } | 652 } |
| 621 results.Set("extensions", extensions_list); | 653 results.Set("extensions", extensions_list); |
| 622 | 654 |
| 623 ManagedUserService* service = | 655 ManagedUserService* service = |
| 624 ManagedUserServiceFactory::GetForProfile(profile); | 656 ManagedUserServiceFactory::GetForProfile(profile); |
| 625 | 657 |
| 626 bool is_managed = service->ProfileIsManaged(); | 658 bool is_managed = service->ProfileIsManaged(); |
| 627 bool is_elevated = service->IsElevated(); | 659 bool is_elevated = |
| 660 service->IsElevatedForWebContents(web_ui()->GetWebContents()); |
| 628 bool developer_mode = | 661 bool developer_mode = |
| 629 (!is_managed || is_elevated) && | 662 (!is_managed || is_elevated) && |
| 630 profile->GetPrefs()->GetBoolean(prefs::kExtensionsUIDeveloperMode); | 663 profile->GetPrefs()->GetBoolean(prefs::kExtensionsUIDeveloperMode); |
| 631 results.SetBoolean("profileIsManaged", is_managed); | 664 results.SetBoolean("profileIsManaged", is_managed); |
| 632 results.SetBoolean("profileIsElevated", is_elevated); | 665 results.SetBoolean("profileIsElevated", is_elevated); |
| 633 results.SetBoolean("developerMode", developer_mode); | 666 results.SetBoolean("developerMode", developer_mode); |
| 634 | 667 |
| 635 // Check to see if we have any wiped out extensions. | 668 // Check to see if we have any wiped out extensions. |
| 636 ExtensionService* extension_service = | 669 ExtensionService* extension_service = |
| 637 extensions::ExtensionSystem::Get(profile)->extension_service(); | 670 extensions::ExtensionSystem::Get(profile)->extension_service(); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 727 } | 760 } |
| 728 | 761 |
| 729 void ExtensionSettingsHandler::HandleEnableMessage(const ListValue* args) { | 762 void ExtensionSettingsHandler::HandleEnableMessage(const ListValue* args) { |
| 730 CHECK_EQ(2U, args->GetSize()); | 763 CHECK_EQ(2U, args->GetSize()); |
| 731 std::string extension_id, enable_str; | 764 std::string extension_id, enable_str; |
| 732 CHECK(args->GetString(0, &extension_id)); | 765 CHECK(args->GetString(0, &extension_id)); |
| 733 CHECK(args->GetString(1, &enable_str)); | 766 CHECK(args->GetString(1, &enable_str)); |
| 734 | 767 |
| 735 const Extension* extension = | 768 const Extension* extension = |
| 736 extension_service_->GetInstalledExtension(extension_id); | 769 extension_service_->GetInstalledExtension(extension_id); |
| 737 if (!extension || | 770 if (!extension || !CheckUserMayModifySettings(extension)) { |
| 738 !management_policy_->UserMayModifySettings(extension, NULL)) { | |
| 739 LOG(ERROR) << "Attempt to enable an extension that is non-usermanagable was" | 771 LOG(ERROR) << "Attempt to enable an extension that is non-usermanagable was" |
| 740 << "made. Extension id: " << extension->id(); | 772 << "made. Extension id: " << extension->id(); |
| 741 return; | 773 return; |
| 742 } | 774 } |
| 743 | 775 |
| 744 if (enable_str == "true") { | 776 if (enable_str == "true") { |
| 745 extensions::ExtensionPrefs* prefs = extension_service_->extension_prefs(); | 777 extensions::ExtensionPrefs* prefs = extension_service_->extension_prefs(); |
| 746 if (prefs->DidExtensionEscalatePermissions(extension_id)) { | 778 if (prefs->DidExtensionEscalatePermissions(extension_id)) { |
| 747 extensions::ShowExtensionDisabledDialog( | 779 extensions::ShowExtensionDisabledDialog( |
| 748 extension_service_, web_ui()->GetWebContents(), extension); | 780 extension_service_, web_ui()->GetWebContents(), extension); |
| 749 } else if ((prefs->GetDisableReasons(extension_id) & | 781 } else if ((prefs->GetDisableReasons(extension_id) & |
| 750 Extension::DISABLE_UNSUPPORTED_REQUIREMENT) && | 782 Extension::DISABLE_UNSUPPORTED_REQUIREMENT) && |
| 751 !requirements_checker_.get()) { | 783 !requirements_checker_.get()) { |
| 752 // Recheck the requirements. | 784 // Recheck the requirements. |
| 753 scoped_refptr<const Extension> extension = | 785 scoped_refptr<const Extension> extension = |
| 754 extension_service_->GetExtensionById(extension_id, | 786 extension_service_->GetExtensionById(extension_id, |
| 755 true /* include disabled */); | 787 true /* include disabled */); |
| 756 requirements_checker_.reset(new extensions::RequirementsChecker()); | 788 requirements_checker_.reset(new extensions::RequirementsChecker()); |
| 757 requirements_checker_->Check( | 789 requirements_checker_->Check( |
| 758 extension, | 790 extension, |
| 759 base::Bind(&ExtensionSettingsHandler::OnRequirementsChecked, | 791 base::Bind(&ExtensionSettingsHandler::OnRequirementsChecked, |
| 760 AsWeakPtr(), extension_id)); | 792 AsWeakPtr(), extension_id)); |
| 761 } else { | 793 } else { |
| 762 extension_service_->EnableExtension(extension_id); | 794 extension_service_->EnableExtension(extension_id); |
| 763 | 795 |
| 764 // Make sure any browser action contained within it is not hidden. | 796 // Make sure any browser action contained within it is not hidden. |
| 765 prefs->SetBrowserActionVisibility(extension, true); | 797 prefs->SetBrowserActionVisibility(extension, true); |
| 766 } | 798 } |
| 767 } else { | 799 } else { |
| 800 // Get managed user elevation for a specific extension id. The elevation |
| 801 // will be removed automatically when |elevation| goes out of scope. |
| 802 scoped_ptr<ScopedExtensionElevation> elevation = |
| 803 GetScopedElevation(extension_id); |
| 768 extension_service_->DisableExtension( | 804 extension_service_->DisableExtension( |
| 769 extension_id, Extension::DISABLE_USER_ACTION); | 805 extension_id, Extension::DISABLE_USER_ACTION); |
| 770 } | 806 } |
| 771 } | 807 } |
| 772 | 808 |
| 773 void ExtensionSettingsHandler::HandleEnableIncognitoMessage( | 809 void ExtensionSettingsHandler::HandleEnableIncognitoMessage( |
| 774 const ListValue* args) { | 810 const ListValue* args) { |
| 775 CHECK_EQ(2U, args->GetSize()); | 811 CHECK_EQ(2U, args->GetSize()); |
| 776 std::string extension_id, enable_str; | 812 std::string extension_id, enable_str; |
| 777 CHECK(args->GetString(0, &extension_id)); | 813 CHECK(args->GetString(0, &extension_id)); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 802 const ListValue* args) { | 838 const ListValue* args) { |
| 803 CHECK_EQ(2U, args->GetSize()); | 839 CHECK_EQ(2U, args->GetSize()); |
| 804 std::string extension_id, allow_str; | 840 std::string extension_id, allow_str; |
| 805 CHECK(args->GetString(0, &extension_id)); | 841 CHECK(args->GetString(0, &extension_id)); |
| 806 CHECK(args->GetString(1, &allow_str)); | 842 CHECK(args->GetString(1, &allow_str)); |
| 807 const Extension* extension = | 843 const Extension* extension = |
| 808 extension_service_->GetInstalledExtension(extension_id); | 844 extension_service_->GetInstalledExtension(extension_id); |
| 809 if (!extension) | 845 if (!extension) |
| 810 return; | 846 return; |
| 811 | 847 |
| 812 if (!management_policy_->UserMayModifySettings(extension, NULL)) { | 848 if (!CheckUserMayModifySettings(extension)) { |
| 813 LOG(ERROR) << "Attempt to change allow file access of an extension that is " | 849 LOG(ERROR) << "Attempt to change allow file access of an extension that is " |
| 814 << "non-usermanagable was made. Extension id : " | 850 << "non-usermanagable was made. Extension id : " |
| 815 << extension->id(); | 851 << extension->id(); |
| 816 return; | 852 return; |
| 817 } | 853 } |
| 818 | 854 |
| 819 extension_service_->SetAllowFileAccess(extension, allow_str == "true"); | 855 extension_service_->SetAllowFileAccess(extension, allow_str == "true"); |
| 820 } | 856 } |
| 821 | 857 |
| 822 void ExtensionSettingsHandler::HandleUninstallMessage(const ListValue* args) { | 858 void ExtensionSettingsHandler::HandleUninstallMessage(const ListValue* args) { |
| 823 CHECK_EQ(1U, args->GetSize()); | 859 CHECK_EQ(1U, args->GetSize()); |
| 824 std::string extension_id; | 860 std::string extension_id; |
| 825 CHECK(args->GetString(0, &extension_id)); | 861 CHECK(args->GetString(0, &extension_id)); |
| 826 const Extension* extension = | 862 const Extension* extension = |
| 827 extension_service_->GetInstalledExtension(extension_id); | 863 extension_service_->GetInstalledExtension(extension_id); |
| 828 if (!extension) | 864 if (!extension) |
| 829 return; | 865 return; |
| 830 | 866 |
| 831 if (!management_policy_->UserMayModifySettings(extension, NULL)) { | 867 if (!CheckUserMayModifySettings(extension)) { |
| 832 LOG(ERROR) << "Attempt to uninstall an extension that is non-usermanagable " | 868 LOG(ERROR) << "Attempt to uninstall an extension that is non-usermanagable " |
| 833 << "was made. Extension id : " << extension->id(); | 869 << "was made. Extension id : " << extension->id(); |
| 834 return; | 870 return; |
| 835 } | 871 } |
| 836 | 872 |
| 837 if (!extension_id_prompting_.empty()) | 873 if (!extension_id_prompting_.empty()) |
| 838 return; // Only one prompt at a time. | 874 return; // Only one prompt at a time. |
| 839 | 875 |
| 840 extension_id_prompting_ = extension_id; | 876 extension_id_prompting_ = extension_id; |
| 841 | 877 |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1078 std::vector<std::string> requirement_errors) { | 1114 std::vector<std::string> requirement_errors) { |
| 1079 if (requirement_errors.empty()) { | 1115 if (requirement_errors.empty()) { |
| 1080 extension_service_->EnableExtension(extension_id); | 1116 extension_service_->EnableExtension(extension_id); |
| 1081 } else { | 1117 } else { |
| 1082 ExtensionErrorReporter::GetInstance()->ReportError( | 1118 ExtensionErrorReporter::GetInstance()->ReportError( |
| 1083 UTF8ToUTF16(JoinString(requirement_errors, ' ')), | 1119 UTF8ToUTF16(JoinString(requirement_errors, ' ')), |
| 1084 true /* be noisy */); | 1120 true /* be noisy */); |
| 1085 } | 1121 } |
| 1086 requirements_checker_.reset(); | 1122 requirements_checker_.reset(); |
| 1087 } | 1123 } |
| OLD | NEW |