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" |
| 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/browser/view_type_utils.h" | 45 #include "chrome/browser/view_type_utils.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 bool ExtensionSettingsHandler::CheckUserMayModifySettings( | |
| 585 const Extension* extension) { | |
| 586 ManagedUserService* service = ManagedUserServiceFactory::GetForProfile( | |
| 587 Profile::FromWebUI(web_ui())); | |
| 588 bool need_elevation = | |
| 589 service->ProfileIsManaged() && | |
| 590 service->IsElevatedForWebContents(web_ui()->GetWebContents()); | |
| 591 if (need_elevation) | |
| 592 service->AddElevationForExtension(extension->id()); | |
|
Bernhard Bauer
2013/03/27 15:48:14
Often when we have the need to balance calls like
Adrian Kuegel
2013/03/27 16:17:43
Done.
| |
| 593 bool result = management_policy_->UserMayModifySettings(extension, NULL); | |
| 594 if (need_elevation) | |
| 595 service->RemoveElevationForExtension(extension->id()); | |
| 596 return result; | |
| 597 } | |
| 598 | |
| 578 void ExtensionSettingsHandler::HandleRequestExtensionsData( | 599 void ExtensionSettingsHandler::HandleRequestExtensionsData( |
| 579 const ListValue* args) { | 600 const ListValue* args) { |
| 580 DictionaryValue results; | 601 DictionaryValue results; |
| 581 | 602 |
| 582 Profile* profile = Profile::FromWebUI(web_ui()); | 603 Profile* profile = Profile::FromWebUI(web_ui()); |
| 583 | 604 |
| 584 // Add the extensions to the results structure. | 605 // Add the extensions to the results structure. |
| 585 ListValue *extensions_list = new ListValue(); | 606 ListValue *extensions_list = new ListValue(); |
| 586 | 607 |
| 587 extensions::ExtensionWarningService* warnings = | 608 extensions::ExtensionWarningService* warnings = |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 617 empty_pages, // Terminated process has no active pages. | 638 empty_pages, // Terminated process has no active pages. |
| 618 warnings)); | 639 warnings)); |
| 619 } | 640 } |
| 620 } | 641 } |
| 621 results.Set("extensions", extensions_list); | 642 results.Set("extensions", extensions_list); |
| 622 | 643 |
| 623 ManagedUserService* service = | 644 ManagedUserService* service = |
| 624 ManagedUserServiceFactory::GetForProfile(profile); | 645 ManagedUserServiceFactory::GetForProfile(profile); |
| 625 | 646 |
| 626 bool is_managed = service->ProfileIsManaged(); | 647 bool is_managed = service->ProfileIsManaged(); |
| 627 bool is_elevated = service->IsElevated(); | 648 bool is_elevated = |
| 649 service->IsElevatedForWebContents(web_ui()->GetWebContents()); | |
| 628 bool developer_mode = | 650 bool developer_mode = |
| 629 (!is_managed || is_elevated) && | 651 (!is_managed || is_elevated) && |
| 630 profile->GetPrefs()->GetBoolean(prefs::kExtensionsUIDeveloperMode); | 652 profile->GetPrefs()->GetBoolean(prefs::kExtensionsUIDeveloperMode); |
| 631 results.SetBoolean("profileIsManaged", is_managed); | 653 results.SetBoolean("profileIsManaged", is_managed); |
| 632 results.SetBoolean("profileIsElevated", is_elevated); | 654 results.SetBoolean("profileIsElevated", is_elevated); |
| 633 results.SetBoolean("developerMode", developer_mode); | 655 results.SetBoolean("developerMode", developer_mode); |
| 634 | 656 |
| 635 // Check to see if we have any wiped out extensions. | 657 // Check to see if we have any wiped out extensions. |
| 636 ExtensionService* extension_service = | 658 ExtensionService* extension_service = |
| 637 extensions::ExtensionSystem::Get(profile)->extension_service(); | 659 extensions::ExtensionSystem::Get(profile)->extension_service(); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 728 } | 750 } |
| 729 | 751 |
| 730 void ExtensionSettingsHandler::HandleEnableMessage(const ListValue* args) { | 752 void ExtensionSettingsHandler::HandleEnableMessage(const ListValue* args) { |
| 731 CHECK_EQ(2U, args->GetSize()); | 753 CHECK_EQ(2U, args->GetSize()); |
| 732 std::string extension_id, enable_str; | 754 std::string extension_id, enable_str; |
| 733 CHECK(args->GetString(0, &extension_id)); | 755 CHECK(args->GetString(0, &extension_id)); |
| 734 CHECK(args->GetString(1, &enable_str)); | 756 CHECK(args->GetString(1, &enable_str)); |
| 735 | 757 |
| 736 const Extension* extension = | 758 const Extension* extension = |
| 737 extension_service_->GetInstalledExtension(extension_id); | 759 extension_service_->GetInstalledExtension(extension_id); |
| 738 if (!extension || | 760 if (!extension || !CheckUserMayModifySettings(extension)) { |
| 739 !management_policy_->UserMayModifySettings(extension, NULL)) { | |
| 740 LOG(ERROR) << "Attempt to enable an extension that is non-usermanagable was" | 761 LOG(ERROR) << "Attempt to enable an extension that is non-usermanagable was" |
| 741 << "made. Extension id: " << extension->id(); | 762 << "made. Extension id: " << extension->id(); |
| 742 return; | 763 return; |
| 743 } | 764 } |
| 744 | 765 |
| 745 if (enable_str == "true") { | 766 if (enable_str == "true") { |
| 746 extensions::ExtensionPrefs* prefs = extension_service_->extension_prefs(); | 767 extensions::ExtensionPrefs* prefs = extension_service_->extension_prefs(); |
| 747 if (prefs->DidExtensionEscalatePermissions(extension_id)) { | 768 if (prefs->DidExtensionEscalatePermissions(extension_id)) { |
| 748 extensions::ShowExtensionDisabledDialog( | 769 extensions::ShowExtensionDisabledDialog( |
| 749 extension_service_, web_ui()->GetWebContents(), extension); | 770 extension_service_, web_ui()->GetWebContents(), extension); |
| 750 } else if ((prefs->GetDisableReasons(extension_id) & | 771 } else if ((prefs->GetDisableReasons(extension_id) & |
| 751 Extension::DISABLE_UNSUPPORTED_REQUIREMENT) && | 772 Extension::DISABLE_UNSUPPORTED_REQUIREMENT) && |
| 752 !requirements_checker_.get()) { | 773 !requirements_checker_.get()) { |
| 753 // Recheck the requirements. | 774 // Recheck the requirements. |
| 754 scoped_refptr<const Extension> extension = | 775 scoped_refptr<const Extension> extension = |
| 755 extension_service_->GetExtensionById(extension_id, | 776 extension_service_->GetExtensionById(extension_id, |
| 756 true /* include disabled */); | 777 true /* include disabled */); |
| 757 requirements_checker_.reset(new extensions::RequirementsChecker()); | 778 requirements_checker_.reset(new extensions::RequirementsChecker()); |
| 758 requirements_checker_->Check( | 779 requirements_checker_->Check( |
| 759 extension, | 780 extension, |
| 760 base::Bind(&ExtensionSettingsHandler::OnRequirementsChecked, | 781 base::Bind(&ExtensionSettingsHandler::OnRequirementsChecked, |
| 761 AsWeakPtr(), extension_id)); | 782 AsWeakPtr(), extension_id)); |
| 762 } else { | 783 } else { |
| 763 extension_service_->EnableExtension(extension_id); | 784 extension_service_->EnableExtension(extension_id); |
| 764 | 785 |
| 765 // Make sure any browser action contained within it is not hidden. | 786 // Make sure any browser action contained within it is not hidden. |
| 766 prefs->SetBrowserActionVisibility(extension, true); | 787 prefs->SetBrowserActionVisibility(extension, true); |
| 767 } | 788 } |
| 768 } else { | 789 } else { |
| 790 ManagedUserService* service = ManagedUserServiceFactory::GetForProfile( | |
| 791 Profile::FromWebUI(web_ui())); | |
| 792 bool need_elevation = | |
| 793 service->ProfileIsManaged() && | |
| 794 service->IsElevatedForWebContents(web_ui()->GetWebContents()); | |
| 795 if (need_elevation) | |
| 796 service->AddElevationForExtension(extension_id); | |
| 769 extension_service_->DisableExtension( | 797 extension_service_->DisableExtension( |
| 770 extension_id, Extension::DISABLE_USER_ACTION); | 798 extension_id, Extension::DISABLE_USER_ACTION); |
| 799 if (need_elevation) | |
| 800 service->RemoveElevationForExtension(extension_id); | |
| 771 } | 801 } |
| 772 } | 802 } |
| 773 | 803 |
| 774 void ExtensionSettingsHandler::HandleEnableIncognitoMessage( | 804 void ExtensionSettingsHandler::HandleEnableIncognitoMessage( |
| 775 const ListValue* args) { | 805 const ListValue* args) { |
| 776 CHECK_EQ(2U, args->GetSize()); | 806 CHECK_EQ(2U, args->GetSize()); |
| 777 std::string extension_id, enable_str; | 807 std::string extension_id, enable_str; |
| 778 CHECK(args->GetString(0, &extension_id)); | 808 CHECK(args->GetString(0, &extension_id)); |
| 779 CHECK(args->GetString(1, &enable_str)); | 809 CHECK(args->GetString(1, &enable_str)); |
| 780 const Extension* extension = | 810 const Extension* extension = |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 803 const ListValue* args) { | 833 const ListValue* args) { |
| 804 CHECK_EQ(2U, args->GetSize()); | 834 CHECK_EQ(2U, args->GetSize()); |
| 805 std::string extension_id, allow_str; | 835 std::string extension_id, allow_str; |
| 806 CHECK(args->GetString(0, &extension_id)); | 836 CHECK(args->GetString(0, &extension_id)); |
| 807 CHECK(args->GetString(1, &allow_str)); | 837 CHECK(args->GetString(1, &allow_str)); |
| 808 const Extension* extension = | 838 const Extension* extension = |
| 809 extension_service_->GetInstalledExtension(extension_id); | 839 extension_service_->GetInstalledExtension(extension_id); |
| 810 if (!extension) | 840 if (!extension) |
| 811 return; | 841 return; |
| 812 | 842 |
| 813 if (!management_policy_->UserMayModifySettings(extension, NULL)) { | 843 if (!CheckUserMayModifySettings(extension)) { |
| 814 LOG(ERROR) << "Attempt to change allow file access of an extension that is " | 844 LOG(ERROR) << "Attempt to change allow file access of an extension that is " |
| 815 << "non-usermanagable was made. Extension id : " | 845 << "non-usermanagable was made. Extension id : " |
| 816 << extension->id(); | 846 << extension->id(); |
| 817 return; | 847 return; |
| 818 } | 848 } |
| 819 | 849 |
| 820 extension_service_->SetAllowFileAccess(extension, allow_str == "true"); | 850 extension_service_->SetAllowFileAccess(extension, allow_str == "true"); |
| 821 } | 851 } |
| 822 | 852 |
| 823 void ExtensionSettingsHandler::HandleUninstallMessage(const ListValue* args) { | 853 void ExtensionSettingsHandler::HandleUninstallMessage(const ListValue* args) { |
| 824 CHECK_EQ(1U, args->GetSize()); | 854 CHECK_EQ(1U, args->GetSize()); |
| 825 std::string extension_id; | 855 std::string extension_id; |
| 826 CHECK(args->GetString(0, &extension_id)); | 856 CHECK(args->GetString(0, &extension_id)); |
| 827 const Extension* extension = | 857 const Extension* extension = |
| 828 extension_service_->GetInstalledExtension(extension_id); | 858 extension_service_->GetInstalledExtension(extension_id); |
| 829 if (!extension) | 859 if (!extension) |
| 830 return; | 860 return; |
| 831 | 861 |
| 832 if (!management_policy_->UserMayModifySettings(extension, NULL)) { | 862 if (!CheckUserMayModifySettings(extension)) { |
| 833 LOG(ERROR) << "Attempt to uninstall an extension that is non-usermanagable " | 863 LOG(ERROR) << "Attempt to uninstall an extension that is non-usermanagable " |
| 834 << "was made. Extension id : " << extension->id(); | 864 << "was made. Extension id : " << extension->id(); |
| 835 return; | 865 return; |
| 836 } | 866 } |
| 837 | 867 |
| 838 if (!extension_id_prompting_.empty()) | 868 if (!extension_id_prompting_.empty()) |
| 839 return; // Only one prompt at a time. | 869 return; // Only one prompt at a time. |
| 840 | 870 |
| 841 extension_id_prompting_ = extension_id; | 871 extension_id_prompting_ = extension_id; |
| 842 | 872 |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1077 std::vector<std::string> requirement_errors) { | 1107 std::vector<std::string> requirement_errors) { |
| 1078 if (requirement_errors.empty()) { | 1108 if (requirement_errors.empty()) { |
| 1079 extension_service_->EnableExtension(extension_id); | 1109 extension_service_->EnableExtension(extension_id); |
| 1080 } else { | 1110 } else { |
| 1081 ExtensionErrorReporter::GetInstance()->ReportError( | 1111 ExtensionErrorReporter::GetInstance()->ReportError( |
| 1082 UTF8ToUTF16(JoinString(requirement_errors, ' ')), | 1112 UTF8ToUTF16(JoinString(requirement_errors, ' ')), |
| 1083 true /* be noisy */); | 1113 true /* be noisy */); |
| 1084 } | 1114 } |
| 1085 requirements_checker_.reset(); | 1115 requirements_checker_.reset(); |
| 1086 } | 1116 } |
| OLD | NEW |