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/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(std::string extension_id) { | |
|
Bernhard Bauer
2013/04/03 09:00:17
Pass string parameters via const ref.
Adrian Kuegel
2013/04/03 09:42:40
Done.
| |
| 586 ManagedUserService* service = ManagedUserServiceFactory::GetForProfile( | |
| 587 Profile::FromWebUI(web_ui())); | |
| 588 scoped_ptr<ScopedExtensionElevation> elevation( | |
| 589 new ScopedExtensionElevation(service)); | |
| 590 if (service->ProfileIsManaged() && | |
| 591 service->IsElevatedForWebContents(web_ui()->GetWebContents())) { | |
| 592 elevation->AddExtension(extension_id); | |
| 593 } | |
| 594 return elevation.Pass(); | |
| 595 } | |
| 596 | |
| 597 bool ExtensionSettingsHandler::CheckUserMayModifySettings( | |
| 598 const Extension* extension) { | |
| 599 scoped_ptr<ScopedExtensionElevation> elevation = | |
|
James Hawkins
2013/04/02 16:47:46
|elevation| is unused.
Adrian Kuegel
2013/04/03 08:30:26
It is used indirectly. ScopedExtensionElevation gi
| |
| 600 GetScopedElevation(extension->id()); | |
| 601 return management_policy_->UserMayModifySettings(extension, NULL); | |
| 602 } | |
| 603 | |
| 578 void ExtensionSettingsHandler::HandleRequestExtensionsData( | 604 void ExtensionSettingsHandler::HandleRequestExtensionsData( |
| 579 const ListValue* args) { | 605 const ListValue* args) { |
| 580 DictionaryValue results; | 606 DictionaryValue results; |
| 581 | 607 |
| 582 Profile* profile = Profile::FromWebUI(web_ui()); | 608 Profile* profile = Profile::FromWebUI(web_ui()); |
| 583 | 609 |
| 584 // Add the extensions to the results structure. | 610 // Add the extensions to the results structure. |
| 585 ListValue *extensions_list = new ListValue(); | 611 ListValue *extensions_list = new ListValue(); |
| 586 | 612 |
| 587 extensions::ExtensionWarningService* warnings = | 613 extensions::ExtensionWarningService* warnings = |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 617 empty_pages, // Terminated process has no active pages. | 643 empty_pages, // Terminated process has no active pages. |
| 618 warnings)); | 644 warnings)); |
| 619 } | 645 } |
| 620 } | 646 } |
| 621 results.Set("extensions", extensions_list); | 647 results.Set("extensions", extensions_list); |
| 622 | 648 |
| 623 ManagedUserService* service = | 649 ManagedUserService* service = |
| 624 ManagedUserServiceFactory::GetForProfile(profile); | 650 ManagedUserServiceFactory::GetForProfile(profile); |
| 625 | 651 |
| 626 bool is_managed = service->ProfileIsManaged(); | 652 bool is_managed = service->ProfileIsManaged(); |
| 627 bool is_elevated = service->IsElevated(); | 653 bool is_elevated = |
| 654 service->IsElevatedForWebContents(web_ui()->GetWebContents()); | |
| 628 bool developer_mode = | 655 bool developer_mode = |
| 629 (!is_managed || is_elevated) && | 656 (!is_managed || is_elevated) && |
| 630 profile->GetPrefs()->GetBoolean(prefs::kExtensionsUIDeveloperMode); | 657 profile->GetPrefs()->GetBoolean(prefs::kExtensionsUIDeveloperMode); |
| 631 results.SetBoolean("profileIsManaged", is_managed); | 658 results.SetBoolean("profileIsManaged", is_managed); |
| 632 results.SetBoolean("profileIsElevated", is_elevated); | 659 results.SetBoolean("profileIsElevated", is_elevated); |
| 633 results.SetBoolean("developerMode", developer_mode); | 660 results.SetBoolean("developerMode", developer_mode); |
| 634 | 661 |
| 635 // Check to see if we have any wiped out extensions. | 662 // Check to see if we have any wiped out extensions. |
| 636 ExtensionService* extension_service = | 663 ExtensionService* extension_service = |
| 637 extensions::ExtensionSystem::Get(profile)->extension_service(); | 664 extensions::ExtensionSystem::Get(profile)->extension_service(); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 728 } | 755 } |
| 729 | 756 |
| 730 void ExtensionSettingsHandler::HandleEnableMessage(const ListValue* args) { | 757 void ExtensionSettingsHandler::HandleEnableMessage(const ListValue* args) { |
| 731 CHECK_EQ(2U, args->GetSize()); | 758 CHECK_EQ(2U, args->GetSize()); |
| 732 std::string extension_id, enable_str; | 759 std::string extension_id, enable_str; |
| 733 CHECK(args->GetString(0, &extension_id)); | 760 CHECK(args->GetString(0, &extension_id)); |
| 734 CHECK(args->GetString(1, &enable_str)); | 761 CHECK(args->GetString(1, &enable_str)); |
| 735 | 762 |
| 736 const Extension* extension = | 763 const Extension* extension = |
| 737 extension_service_->GetInstalledExtension(extension_id); | 764 extension_service_->GetInstalledExtension(extension_id); |
| 738 if (!extension || | 765 if (!extension || !CheckUserMayModifySettings(extension)) { |
| 739 !management_policy_->UserMayModifySettings(extension, NULL)) { | |
| 740 LOG(ERROR) << "Attempt to enable an extension that is non-usermanagable was" | 766 LOG(ERROR) << "Attempt to enable an extension that is non-usermanagable was" |
| 741 << "made. Extension id: " << extension->id(); | 767 << "made. Extension id: " << extension->id(); |
| 742 return; | 768 return; |
| 743 } | 769 } |
| 744 | 770 |
| 745 if (enable_str == "true") { | 771 if (enable_str == "true") { |
| 746 extensions::ExtensionPrefs* prefs = extension_service_->extension_prefs(); | 772 extensions::ExtensionPrefs* prefs = extension_service_->extension_prefs(); |
| 747 if (prefs->DidExtensionEscalatePermissions(extension_id)) { | 773 if (prefs->DidExtensionEscalatePermissions(extension_id)) { |
| 748 extensions::ShowExtensionDisabledDialog( | 774 extensions::ShowExtensionDisabledDialog( |
| 749 extension_service_, web_ui()->GetWebContents(), extension); | 775 extension_service_, web_ui()->GetWebContents(), extension); |
| 750 } else if ((prefs->GetDisableReasons(extension_id) & | 776 } else if ((prefs->GetDisableReasons(extension_id) & |
| 751 Extension::DISABLE_UNSUPPORTED_REQUIREMENT) && | 777 Extension::DISABLE_UNSUPPORTED_REQUIREMENT) && |
| 752 !requirements_checker_.get()) { | 778 !requirements_checker_.get()) { |
| 753 // Recheck the requirements. | 779 // Recheck the requirements. |
| 754 scoped_refptr<const Extension> extension = | 780 scoped_refptr<const Extension> extension = |
| 755 extension_service_->GetExtensionById(extension_id, | 781 extension_service_->GetExtensionById(extension_id, |
| 756 true /* include disabled */); | 782 true /* include disabled */); |
| 757 requirements_checker_.reset(new extensions::RequirementsChecker()); | 783 requirements_checker_.reset(new extensions::RequirementsChecker()); |
| 758 requirements_checker_->Check( | 784 requirements_checker_->Check( |
| 759 extension, | 785 extension, |
| 760 base::Bind(&ExtensionSettingsHandler::OnRequirementsChecked, | 786 base::Bind(&ExtensionSettingsHandler::OnRequirementsChecked, |
| 761 AsWeakPtr(), extension_id)); | 787 AsWeakPtr(), extension_id)); |
| 762 } else { | 788 } else { |
| 763 extension_service_->EnableExtension(extension_id); | 789 extension_service_->EnableExtension(extension_id); |
| 764 | 790 |
| 765 // Make sure any browser action contained within it is not hidden. | 791 // Make sure any browser action contained within it is not hidden. |
| 766 prefs->SetBrowserActionVisibility(extension, true); | 792 prefs->SetBrowserActionVisibility(extension, true); |
| 767 } | 793 } |
| 768 } else { | 794 } else { |
| 795 scoped_ptr<ScopedExtensionElevation> elevation = | |
|
James Hawkins
2013/04/02 16:47:46
elevation is unused.
| |
| 796 GetScopedElevation(extension_id); | |
| 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 |