| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/extensions/extension_service.h" | 5 #include "chrome/browser/extensions/extension_service.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <iterator> | 8 #include <iterator> |
| 9 #include <set> | 9 #include <set> |
| 10 | 10 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 #include "extensions/browser/updater/extension_cache.h" | 75 #include "extensions/browser/updater/extension_cache.h" |
| 76 #include "extensions/browser/updater/extension_downloader.h" | 76 #include "extensions/browser/updater/extension_downloader.h" |
| 77 #include "extensions/common/extension_messages.h" | 77 #include "extensions/common/extension_messages.h" |
| 78 #include "extensions/common/extension_urls.h" | 78 #include "extensions/common/extension_urls.h" |
| 79 #include "extensions/common/feature_switch.h" | 79 #include "extensions/common/feature_switch.h" |
| 80 #include "extensions/common/file_util.h" | 80 #include "extensions/common/file_util.h" |
| 81 #include "extensions/common/manifest_constants.h" | 81 #include "extensions/common/manifest_constants.h" |
| 82 #include "extensions/common/manifest_handlers/background_info.h" | 82 #include "extensions/common/manifest_handlers/background_info.h" |
| 83 #include "extensions/common/manifest_url_handlers.h" | 83 #include "extensions/common/manifest_url_handlers.h" |
| 84 #include "extensions/common/one_shot_event.h" | 84 #include "extensions/common/one_shot_event.h" |
| 85 #include "extensions/common/permissions/api_permission.h" |
| 85 #include "extensions/common/permissions/permission_message_provider.h" | 86 #include "extensions/common/permissions/permission_message_provider.h" |
| 86 #include "extensions/common/permissions/permissions_data.h" | 87 #include "extensions/common/permissions/permissions_data.h" |
| 87 | 88 |
| 88 #if defined(ENABLE_SUPERVISED_USERS) | 89 #if defined(ENABLE_SUPERVISED_USERS) |
| 89 #include "chrome/browser/supervised_user/supervised_user_service.h" | 90 #include "chrome/browser/supervised_user/supervised_user_service.h" |
| 90 #include "chrome/browser/supervised_user/supervised_user_service_factory.h" | 91 #include "chrome/browser/supervised_user/supervised_user_service_factory.h" |
| 91 #endif | 92 #endif |
| 92 | 93 |
| 93 #if defined(OS_CHROMEOS) | 94 #if defined(OS_CHROMEOS) |
| 94 #include "chrome/browser/chromeos/extensions/install_limiter.h" | 95 #include "chrome/browser/chromeos/extensions/install_limiter.h" |
| 95 #include "storage/browser/fileapi/file_system_backend.h" | 96 #include "storage/browser/fileapi/file_system_backend.h" |
| 96 #include "storage/browser/fileapi/file_system_context.h" | 97 #include "storage/browser/fileapi/file_system_context.h" |
| 97 #endif | 98 #endif |
| 98 | 99 |
| 99 using content::BrowserContext; | 100 using content::BrowserContext; |
| 100 using content::BrowserThread; | 101 using content::BrowserThread; |
| 101 using content::DevToolsAgentHost; | 102 using content::DevToolsAgentHost; |
| 103 using extensions::APIPermission; |
| 102 using extensions::CrxInstaller; | 104 using extensions::CrxInstaller; |
| 103 using extensions::Extension; | 105 using extensions::Extension; |
| 104 using extensions::ExtensionIdSet; | 106 using extensions::ExtensionIdSet; |
| 105 using extensions::ExtensionInfo; | 107 using extensions::ExtensionInfo; |
| 106 using extensions::ExtensionRegistry; | 108 using extensions::ExtensionRegistry; |
| 107 using extensions::ExtensionSet; | 109 using extensions::ExtensionSet; |
| 108 using extensions::FeatureSwitch; | 110 using extensions::FeatureSwitch; |
| 109 using extensions::InstallVerifier; | 111 using extensions::InstallVerifier; |
| 110 using extensions::ManagementPolicy; | 112 using extensions::ManagementPolicy; |
| 111 using extensions::Manifest; | 113 using extensions::Manifest; |
| 114 using extensions::PermissionID; |
| 115 using extensions::PermissionIDSet; |
| 112 using extensions::PermissionMessage; | 116 using extensions::PermissionMessage; |
| 113 using extensions::PermissionMessageIDs; | 117 using extensions::PermissionMessageIDs; |
| 114 using extensions::PermissionSet; | 118 using extensions::PermissionSet; |
| 115 using extensions::SharedModuleInfo; | 119 using extensions::SharedModuleInfo; |
| 116 using extensions::SharedModuleService; | 120 using extensions::SharedModuleService; |
| 117 using extensions::UnloadedExtensionInfo; | 121 using extensions::UnloadedExtensionInfo; |
| 118 | 122 |
| 119 namespace { | 123 namespace { |
| 120 | 124 |
| 121 // Wait this many seconds after an extensions becomes idle before updating it. | 125 // Wait this many seconds after an extensions becomes idle before updating it. |
| (...skipping 613 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 735 if (extension_sync_service_ && | 739 if (extension_sync_service_ && |
| 736 reason != extensions::UNINSTALL_REASON_REINSTALL) { | 740 reason != extensions::UNINSTALL_REASON_REINSTALL) { |
| 737 sync_change = extension_sync_service_->PrepareToSyncUninstallExtension( | 741 sync_change = extension_sync_service_->PrepareToSyncUninstallExtension( |
| 738 extension.get(), is_ready()); | 742 extension.get(), is_ready()); |
| 739 } | 743 } |
| 740 | 744 |
| 741 system_->install_verifier()->Remove(extension->id()); | 745 system_->install_verifier()->Remove(extension->id()); |
| 742 | 746 |
| 743 UMA_HISTOGRAM_ENUMERATION("Extensions.UninstallType", | 747 UMA_HISTOGRAM_ENUMERATION("Extensions.UninstallType", |
| 744 extension->GetType(), 100); | 748 extension->GetType(), 100); |
| 745 RecordPermissionMessagesHistogram(extension.get(), | 749 RecordPermissionMessagesHistogram(extension.get(), "Uninstall"); |
| 746 "Extensions.Permissions_Uninstall2"); | |
| 747 | 750 |
| 748 // Unload before doing more cleanup to ensure that nothing is hanging on to | 751 // Unload before doing more cleanup to ensure that nothing is hanging on to |
| 749 // any of these resources. | 752 // any of these resources. |
| 750 UnloadExtension(extension->id(), UnloadedExtensionInfo::REASON_UNINSTALL); | 753 UnloadExtension(extension->id(), UnloadedExtensionInfo::REASON_UNINSTALL); |
| 751 | 754 |
| 752 // Tell the backend to start deleting installed extensions on the file thread. | 755 // Tell the backend to start deleting installed extensions on the file thread. |
| 753 if (!Manifest::IsUnpackedLocation(extension->location())) { | 756 if (!Manifest::IsUnpackedLocation(extension->location())) { |
| 754 if (!GetFileTaskRunner()->PostTask( | 757 if (!GetFileTaskRunner()->PostTask( |
| 755 FROM_HERE, | 758 FROM_HERE, |
| 756 base::Bind(&ExtensionService::UninstallExtensionOnFileThread, | 759 base::Bind(&ExtensionService::UninstallExtensionOnFileThread, |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 989 | 992 |
| 990 for (const scoped_refptr<const Extension>& extension : *to_unblock) { | 993 for (const scoped_refptr<const Extension>& extension : *to_unblock) { |
| 991 registry_->RemoveBlocked(extension->id()); | 994 registry_->RemoveBlocked(extension->id()); |
| 992 AddExtension(extension.get()); | 995 AddExtension(extension.get()); |
| 993 } | 996 } |
| 994 } | 997 } |
| 995 | 998 |
| 996 void ExtensionService::GrantPermissionsAndEnableExtension( | 999 void ExtensionService::GrantPermissionsAndEnableExtension( |
| 997 const Extension* extension) { | 1000 const Extension* extension) { |
| 998 GrantPermissions(extension); | 1001 GrantPermissions(extension); |
| 999 RecordPermissionMessagesHistogram(extension, | 1002 RecordPermissionMessagesHistogram(extension, "ReEnable"); |
| 1000 "Extensions.Permissions_ReEnable2"); | |
| 1001 extension_prefs_->SetDidExtensionEscalatePermissions(extension, false); | 1003 extension_prefs_->SetDidExtensionEscalatePermissions(extension, false); |
| 1002 EnableExtension(extension->id()); | 1004 EnableExtension(extension->id()); |
| 1003 } | 1005 } |
| 1004 | 1006 |
| 1005 void ExtensionService::GrantPermissions(const Extension* extension) { | 1007 void ExtensionService::GrantPermissions(const Extension* extension) { |
| 1006 CHECK(extension); | 1008 CHECK(extension); |
| 1007 extensions::PermissionsUpdater(profile()).GrantActivePermissions(extension); | 1009 extensions::PermissionsUpdater(profile()).GrantActivePermissions(extension); |
| 1008 } | 1010 } |
| 1009 | 1011 |
| 1010 // static | 1012 // static |
| 1011 void ExtensionService::RecordPermissionMessagesHistogram( | 1013 void ExtensionService::RecordPermissionMessagesHistogram( |
| 1012 const Extension* extension, const char* histogram) { | 1014 const Extension* extension, const char* histogram) { |
| 1013 // Since this is called from multiple sources, and since the histogram macros | 1015 // Since this is called from multiple sources, and since the histogram macros |
| 1014 // use statics, we need to manually lookup the histogram ourselves. | 1016 // use statics, we need to manually lookup the histogram ourselves. |
| 1015 base::HistogramBase* counter = base::LinearHistogram::FactoryGet( | 1017 base::HistogramBase* legacy_counter = base::LinearHistogram::FactoryGet( |
| 1016 histogram, | 1018 base::StringPrintf("Extensions.Permissions_%s2", histogram), |
| 1017 1, | 1019 1, |
| 1018 PermissionMessage::kEnumBoundary, | 1020 PermissionMessage::kEnumBoundary, |
| 1019 PermissionMessage::kEnumBoundary + 1, | 1021 PermissionMessage::kEnumBoundary + 1, |
| 1020 base::HistogramBase::kUmaTargetedHistogramFlag); | 1022 base::HistogramBase::kUmaTargetedHistogramFlag); |
| 1021 | 1023 |
| 1022 PermissionMessageIDs permissions = | 1024 // TODO(treib): Remove the legacy "2" histograms. See crbug.com/484102. |
| 1025 PermissionMessageIDs legacy_permissions = |
| 1023 extension->permissions_data()->GetLegacyPermissionMessageIDs(); | 1026 extension->permissions_data()->GetLegacyPermissionMessageIDs(); |
| 1024 if (permissions.empty()) { | 1027 if (legacy_permissions.empty()) { |
| 1025 counter->Add(PermissionMessage::kNone); | 1028 legacy_counter->Add(PermissionMessage::kNone); |
| 1026 } else { | 1029 } else { |
| 1027 for (PermissionMessage::ID id : permissions) | 1030 for (PermissionMessage::ID id : legacy_permissions) |
| 1028 counter->Add(id); | 1031 legacy_counter->Add(id); |
| 1029 } | 1032 } |
| 1033 |
| 1034 base::HistogramBase* counter = base::LinearHistogram::FactoryGet( |
| 1035 base::StringPrintf("Extensions.Permissions_%s3", histogram), |
| 1036 1, |
| 1037 APIPermission::kEnumBoundary, |
| 1038 APIPermission::kEnumBoundary + 1, |
| 1039 base::HistogramBase::kUmaTargetedHistogramFlag); |
| 1040 |
| 1041 base::HistogramBase* counter_has_any = base::BooleanHistogram::FactoryGet( |
| 1042 base::StringPrintf("Extensions.HasPermissions_%s3", histogram), |
| 1043 base::HistogramBase::kUmaTargetedHistogramFlag); |
| 1044 |
| 1045 PermissionIDSet permissions = |
| 1046 extensions::PermissionMessageProvider::Get()->GetAllPermissionIDs( |
| 1047 extension->permissions_data()->active_permissions().get(), |
| 1048 extension->GetType()); |
| 1049 counter_has_any->AddBoolean(!permissions.empty()); |
| 1050 for (const PermissionID& id : permissions) |
| 1051 counter->Add(id.id()); |
| 1030 } | 1052 } |
| 1031 | 1053 |
| 1032 void ExtensionService::NotifyExtensionLoaded(const Extension* extension) { | 1054 void ExtensionService::NotifyExtensionLoaded(const Extension* extension) { |
| 1033 // The URLRequestContexts need to be first to know that the extension | 1055 // The URLRequestContexts need to be first to know that the extension |
| 1034 // was loaded, otherwise a race can arise where a renderer that is created | 1056 // was loaded, otherwise a race can arise where a renderer that is created |
| 1035 // for the extension may try to load an extension URL with an extension id | 1057 // for the extension may try to load an extension URL with an extension id |
| 1036 // that the request context doesn't yet know about. The profile is responsible | 1058 // that the request context doesn't yet know about. The profile is responsible |
| 1037 // for ensuring its URLRequestContexts appropriately discover the loaded | 1059 // for ensuring its URLRequestContexts appropriately discover the loaded |
| 1038 // extension. | 1060 // extension. |
| 1039 system_->RegisterExtensionWithRequestContexts(extension); | 1061 system_->RegisterExtensionWithRequestContexts(extension); |
| (...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1662 // Extension has changed permissions significantly. Disable it. A | 1684 // Extension has changed permissions significantly. Disable it. A |
| 1663 // notification should be sent by the caller. If the extension is already | 1685 // notification should be sent by the caller. If the extension is already |
| 1664 // disabled because it was installed remotely, don't add another disable | 1686 // disabled because it was installed remotely, don't add another disable |
| 1665 // reason, but instead always set the "did escalate permissions" flag, to | 1687 // reason, but instead always set the "did escalate permissions" flag, to |
| 1666 // ensure enabling it will always show a warning. | 1688 // ensure enabling it will always show a warning. |
| 1667 if (disable_reasons == Extension::DISABLE_REMOTE_INSTALL) { | 1689 if (disable_reasons == Extension::DISABLE_REMOTE_INSTALL) { |
| 1668 extension_prefs_->SetDidExtensionEscalatePermissions(extension, true); | 1690 extension_prefs_->SetDidExtensionEscalatePermissions(extension, true); |
| 1669 } else if (is_privilege_increase) { | 1691 } else if (is_privilege_increase) { |
| 1670 disable_reasons |= Extension::DISABLE_PERMISSIONS_INCREASE; | 1692 disable_reasons |= Extension::DISABLE_PERMISSIONS_INCREASE; |
| 1671 if (!extension_prefs_->DidExtensionEscalatePermissions(extension->id())) { | 1693 if (!extension_prefs_->DidExtensionEscalatePermissions(extension->id())) { |
| 1672 RecordPermissionMessagesHistogram(extension, | 1694 RecordPermissionMessagesHistogram(extension, "AutoDisable"); |
| 1673 "Extensions.Permissions_AutoDisable2"); | |
| 1674 } | 1695 } |
| 1675 extension_prefs_->SetExtensionState(extension->id(), Extension::DISABLED); | 1696 extension_prefs_->SetExtensionState(extension->id(), Extension::DISABLED); |
| 1676 extension_prefs_->SetDidExtensionEscalatePermissions(extension, true); | 1697 extension_prefs_->SetDidExtensionEscalatePermissions(extension, true); |
| 1677 | 1698 |
| 1678 #if defined(ENABLE_SUPERVISED_USERS) | 1699 #if defined(ENABLE_SUPERVISED_USERS) |
| 1679 // If a custodian-installed extension is disabled for a supervised user due | 1700 // If a custodian-installed extension is disabled for a supervised user due |
| 1680 // to a permissions increase, send a request to the custodian, since the | 1701 // to a permissions increase, send a request to the custodian, since the |
| 1681 // supervised user themselves can't re-enable the extension. | 1702 // supervised user themselves can't re-enable the extension. |
| 1682 if (extensions::util::IsExtensionSupervised(extension, profile_)) { | 1703 if (extensions::util::IsExtensionSupervised(extension, profile_)) { |
| 1683 SupervisedUserService* supervised_user_service = | 1704 SupervisedUserService* supervised_user_service = |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1786 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.SilentInstall", | 1807 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.SilentInstall", |
| 1787 extension->location(), | 1808 extension->location(), |
| 1788 Manifest::NUM_LOCATIONS); | 1809 Manifest::NUM_LOCATIONS); |
| 1789 } | 1810 } |
| 1790 | 1811 |
| 1791 if (!GetInstalledExtension(extension->id())) { | 1812 if (!GetInstalledExtension(extension->id())) { |
| 1792 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallType", | 1813 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallType", |
| 1793 extension->GetType(), 100); | 1814 extension->GetType(), 100); |
| 1794 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallSource", | 1815 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallSource", |
| 1795 extension->location(), Manifest::NUM_LOCATIONS); | 1816 extension->location(), Manifest::NUM_LOCATIONS); |
| 1796 RecordPermissionMessagesHistogram(extension, | 1817 RecordPermissionMessagesHistogram(extension, "Install"); |
| 1797 "Extensions.Permissions_Install2"); | |
| 1798 } else { | 1818 } else { |
| 1799 UMA_HISTOGRAM_ENUMERATION("Extensions.UpdateType", | 1819 UMA_HISTOGRAM_ENUMERATION("Extensions.UpdateType", |
| 1800 extension->GetType(), 100); | 1820 extension->GetType(), 100); |
| 1801 UMA_HISTOGRAM_ENUMERATION("Extensions.UpdateSource", | 1821 UMA_HISTOGRAM_ENUMERATION("Extensions.UpdateSource", |
| 1802 extension->location(), Manifest::NUM_LOCATIONS); | 1822 extension->location(), Manifest::NUM_LOCATIONS); |
| 1803 | 1823 |
| 1804 // A fully installed app cannot be demoted to an ephemeral app. | 1824 // A fully installed app cannot be demoted to an ephemeral app. |
| 1805 if ((install_flags & extensions::kInstallFlagIsEphemeral) && | 1825 if ((install_flags & extensions::kInstallFlagIsEphemeral) && |
| 1806 !extension_prefs_->IsEphemeralApp(id)) { | 1826 !extension_prefs_->IsEphemeralApp(id)) { |
| 1807 install_flags &= ~static_cast<int>(extensions::kInstallFlagIsEphemeral); | 1827 install_flags &= ~static_cast<int>(extensions::kInstallFlagIsEphemeral); |
| (...skipping 778 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2586 } | 2606 } |
| 2587 | 2607 |
| 2588 void ExtensionService::OnProfileDestructionStarted() { | 2608 void ExtensionService::OnProfileDestructionStarted() { |
| 2589 ExtensionIdSet ids_to_unload = registry_->enabled_extensions().GetIDs(); | 2609 ExtensionIdSet ids_to_unload = registry_->enabled_extensions().GetIDs(); |
| 2590 for (ExtensionIdSet::iterator it = ids_to_unload.begin(); | 2610 for (ExtensionIdSet::iterator it = ids_to_unload.begin(); |
| 2591 it != ids_to_unload.end(); | 2611 it != ids_to_unload.end(); |
| 2592 ++it) { | 2612 ++it) { |
| 2593 UnloadExtension(*it, UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN); | 2613 UnloadExtension(*it, UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN); |
| 2594 } | 2614 } |
| 2595 } | 2615 } |
| OLD | NEW |