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 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
985 | 988 |
986 for (const scoped_refptr<const Extension>& extension : *to_unblock) { | 989 for (const scoped_refptr<const Extension>& extension : *to_unblock) { |
987 registry_->RemoveBlocked(extension->id()); | 990 registry_->RemoveBlocked(extension->id()); |
988 AddExtension(extension.get()); | 991 AddExtension(extension.get()); |
989 } | 992 } |
990 } | 993 } |
991 | 994 |
992 void ExtensionService::GrantPermissionsAndEnableExtension( | 995 void ExtensionService::GrantPermissionsAndEnableExtension( |
993 const Extension* extension) { | 996 const Extension* extension) { |
994 GrantPermissions(extension); | 997 GrantPermissions(extension); |
995 RecordPermissionMessagesHistogram(extension, | 998 RecordPermissionMessagesHistogram(extension, "ReEnable"); |
996 "Extensions.Permissions_ReEnable2"); | |
997 extension_prefs_->SetDidExtensionEscalatePermissions(extension, false); | 999 extension_prefs_->SetDidExtensionEscalatePermissions(extension, false); |
998 EnableExtension(extension->id()); | 1000 EnableExtension(extension->id()); |
999 } | 1001 } |
1000 | 1002 |
1001 void ExtensionService::GrantPermissions(const Extension* extension) { | 1003 void ExtensionService::GrantPermissions(const Extension* extension) { |
1002 CHECK(extension); | 1004 CHECK(extension); |
1003 extensions::PermissionsUpdater(profile()).GrantActivePermissions(extension); | 1005 extensions::PermissionsUpdater(profile()).GrantActivePermissions(extension); |
1004 } | 1006 } |
1005 | 1007 |
1006 // static | 1008 // static |
1007 void ExtensionService::RecordPermissionMessagesHistogram( | 1009 void ExtensionService::RecordPermissionMessagesHistogram( |
1008 const Extension* extension, const char* histogram) { | 1010 const Extension* extension, const char* histogram) { |
1009 // Since this is called from multiple sources, and since the histogram macros | 1011 // Since this is called from multiple sources, and since the histogram macros |
1010 // use statics, we need to manually lookup the histogram ourselves. | 1012 // use statics, we need to manually lookup the histogram ourselves. |
1011 base::HistogramBase* counter = base::LinearHistogram::FactoryGet( | 1013 base::HistogramBase* legacy_counter = base::LinearHistogram::FactoryGet( |
1012 histogram, | 1014 base::StringPrintf("Extensions.Permissions_%s2", histogram), |
1013 1, | 1015 1, |
1014 PermissionMessage::kEnumBoundary, | 1016 PermissionMessage::kEnumBoundary, |
1015 PermissionMessage::kEnumBoundary + 1, | 1017 PermissionMessage::kEnumBoundary + 1, |
1016 base::HistogramBase::kUmaTargetedHistogramFlag); | 1018 base::HistogramBase::kUmaTargetedHistogramFlag); |
1017 | 1019 |
1018 PermissionMessageIDs permissions = | 1020 // TODO(treib): Remove the legacy "2" histograms. See crbug.com/484102. |
| 1021 PermissionMessageIDs legacy_permissions = |
1019 extension->permissions_data()->GetLegacyPermissionMessageIDs(); | 1022 extension->permissions_data()->GetLegacyPermissionMessageIDs(); |
1020 if (permissions.empty()) { | 1023 if (legacy_permissions.empty()) { |
1021 counter->Add(PermissionMessage::kNone); | 1024 legacy_counter->Add(PermissionMessage::kNone); |
1022 } else { | 1025 } else { |
1023 for (PermissionMessage::ID id : permissions) | 1026 for (PermissionMessage::ID id : legacy_permissions) |
1024 counter->Add(id); | 1027 legacy_counter->Add(id); |
1025 } | 1028 } |
| 1029 |
| 1030 base::HistogramBase* counter = base::LinearHistogram::FactoryGet( |
| 1031 base::StringPrintf("Extensions.Permissions_%s3", histogram), |
| 1032 1, |
| 1033 APIPermission::kEnumBoundary, |
| 1034 APIPermission::kEnumBoundary + 1, |
| 1035 base::HistogramBase::kUmaTargetedHistogramFlag); |
| 1036 |
| 1037 base::HistogramBase* counter_has_any = base::BooleanHistogram::FactoryGet( |
| 1038 base::StringPrintf("Extensions.HasPermissions_%s3", histogram), |
| 1039 base::HistogramBase::kUmaTargetedHistogramFlag); |
| 1040 |
| 1041 PermissionIDSet permissions = |
| 1042 extensions::PermissionMessageProvider::Get()->GetAllPermissionIDs( |
| 1043 extension->permissions_data()->active_permissions().get(), |
| 1044 extension->GetType()); |
| 1045 counter_has_any->AddBoolean(!permissions.empty()); |
| 1046 for (const PermissionID& id : permissions) |
| 1047 counter->Add(id.id()); |
1026 } | 1048 } |
1027 | 1049 |
1028 void ExtensionService::NotifyExtensionLoaded(const Extension* extension) { | 1050 void ExtensionService::NotifyExtensionLoaded(const Extension* extension) { |
1029 // The URLRequestContexts need to be first to know that the extension | 1051 // The URLRequestContexts need to be first to know that the extension |
1030 // was loaded, otherwise a race can arise where a renderer that is created | 1052 // was loaded, otherwise a race can arise where a renderer that is created |
1031 // for the extension may try to load an extension URL with an extension id | 1053 // for the extension may try to load an extension URL with an extension id |
1032 // that the request context doesn't yet know about. The profile is responsible | 1054 // that the request context doesn't yet know about. The profile is responsible |
1033 // for ensuring its URLRequestContexts appropriately discover the loaded | 1055 // for ensuring its URLRequestContexts appropriately discover the loaded |
1034 // extension. | 1056 // extension. |
1035 system_->RegisterExtensionWithRequestContexts(extension); | 1057 system_->RegisterExtensionWithRequestContexts(extension); |
(...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1654 // Extension has changed permissions significantly. Disable it. A | 1676 // Extension has changed permissions significantly. Disable it. A |
1655 // notification should be sent by the caller. If the extension is already | 1677 // notification should be sent by the caller. If the extension is already |
1656 // disabled because it was installed remotely, don't add another disable | 1678 // disabled because it was installed remotely, don't add another disable |
1657 // reason, but instead always set the "did escalate permissions" flag, to | 1679 // reason, but instead always set the "did escalate permissions" flag, to |
1658 // ensure enabling it will always show a warning. | 1680 // ensure enabling it will always show a warning. |
1659 if (disable_reasons == Extension::DISABLE_REMOTE_INSTALL) { | 1681 if (disable_reasons == Extension::DISABLE_REMOTE_INSTALL) { |
1660 extension_prefs_->SetDidExtensionEscalatePermissions(extension, true); | 1682 extension_prefs_->SetDidExtensionEscalatePermissions(extension, true); |
1661 } else if (is_privilege_increase) { | 1683 } else if (is_privilege_increase) { |
1662 disable_reasons |= Extension::DISABLE_PERMISSIONS_INCREASE; | 1684 disable_reasons |= Extension::DISABLE_PERMISSIONS_INCREASE; |
1663 if (!extension_prefs_->DidExtensionEscalatePermissions(extension->id())) { | 1685 if (!extension_prefs_->DidExtensionEscalatePermissions(extension->id())) { |
1664 RecordPermissionMessagesHistogram(extension, | 1686 RecordPermissionMessagesHistogram(extension, "AutoDisable"); |
1665 "Extensions.Permissions_AutoDisable2"); | |
1666 } | 1687 } |
1667 extension_prefs_->SetExtensionState(extension->id(), Extension::DISABLED); | 1688 extension_prefs_->SetExtensionState(extension->id(), Extension::DISABLED); |
1668 extension_prefs_->SetDidExtensionEscalatePermissions(extension, true); | 1689 extension_prefs_->SetDidExtensionEscalatePermissions(extension, true); |
1669 | 1690 |
1670 #if defined(ENABLE_SUPERVISED_USERS) | 1691 #if defined(ENABLE_SUPERVISED_USERS) |
1671 // If a custodian-installed extension is disabled for a supervised user due | 1692 // If a custodian-installed extension is disabled for a supervised user due |
1672 // to a permissions increase, send a request to the custodian, since the | 1693 // to a permissions increase, send a request to the custodian, since the |
1673 // supervised user themselves can't re-enable the extension. | 1694 // supervised user themselves can't re-enable the extension. |
1674 if (extensions::util::IsExtensionSupervised(extension, profile_)) { | 1695 if (extensions::util::IsExtensionSupervised(extension, profile_)) { |
1675 SupervisedUserService* supervised_user_service = | 1696 SupervisedUserService* supervised_user_service = |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1778 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.SilentInstall", | 1799 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.SilentInstall", |
1779 extension->location(), | 1800 extension->location(), |
1780 Manifest::NUM_LOCATIONS); | 1801 Manifest::NUM_LOCATIONS); |
1781 } | 1802 } |
1782 | 1803 |
1783 if (!GetInstalledExtension(extension->id())) { | 1804 if (!GetInstalledExtension(extension->id())) { |
1784 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallType", | 1805 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallType", |
1785 extension->GetType(), 100); | 1806 extension->GetType(), 100); |
1786 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallSource", | 1807 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallSource", |
1787 extension->location(), Manifest::NUM_LOCATIONS); | 1808 extension->location(), Manifest::NUM_LOCATIONS); |
1788 RecordPermissionMessagesHistogram(extension, | 1809 RecordPermissionMessagesHistogram(extension, "Install"); |
1789 "Extensions.Permissions_Install2"); | |
1790 } else { | 1810 } else { |
1791 UMA_HISTOGRAM_ENUMERATION("Extensions.UpdateType", | 1811 UMA_HISTOGRAM_ENUMERATION("Extensions.UpdateType", |
1792 extension->GetType(), 100); | 1812 extension->GetType(), 100); |
1793 UMA_HISTOGRAM_ENUMERATION("Extensions.UpdateSource", | 1813 UMA_HISTOGRAM_ENUMERATION("Extensions.UpdateSource", |
1794 extension->location(), Manifest::NUM_LOCATIONS); | 1814 extension->location(), Manifest::NUM_LOCATIONS); |
1795 | 1815 |
1796 // A fully installed app cannot be demoted to an ephemeral app. | 1816 // A fully installed app cannot be demoted to an ephemeral app. |
1797 if ((install_flags & extensions::kInstallFlagIsEphemeral) && | 1817 if ((install_flags & extensions::kInstallFlagIsEphemeral) && |
1798 !extension_prefs_->IsEphemeralApp(id)) { | 1818 !extension_prefs_->IsEphemeralApp(id)) { |
1799 install_flags &= ~static_cast<int>(extensions::kInstallFlagIsEphemeral); | 1819 install_flags &= ~static_cast<int>(extensions::kInstallFlagIsEphemeral); |
(...skipping 778 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2578 } | 2598 } |
2579 | 2599 |
2580 void ExtensionService::OnProfileDestructionStarted() { | 2600 void ExtensionService::OnProfileDestructionStarted() { |
2581 ExtensionIdSet ids_to_unload = registry_->enabled_extensions().GetIDs(); | 2601 ExtensionIdSet ids_to_unload = registry_->enabled_extensions().GetIDs(); |
2582 for (ExtensionIdSet::iterator it = ids_to_unload.begin(); | 2602 for (ExtensionIdSet::iterator it = ids_to_unload.begin(); |
2583 it != ids_to_unload.end(); | 2603 it != ids_to_unload.end(); |
2584 ++it) { | 2604 ++it) { |
2585 UnloadExtension(*it, UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN); | 2605 UnloadExtension(*it, UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN); |
2586 } | 2606 } |
2587 } | 2607 } |
OLD | NEW |