Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(42)

Side by Side Diff: chrome/browser/extensions/extension_service.cc

Issue 1094873002: Extensions: Switch to new permission message system, part V (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: presubmit Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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
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),
not at google - send to devlin 2015/04/30 16:31:32 I can see this change get a little bit frustrating
Marc Treib 2015/05/04 09:15:58 Done.
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 PermissionMessageIDs legacy_permissions =
1023 extension->permissions_data()->GetLegacyPermissionMessageIDs(); 1025 extension->permissions_data()->GetLegacyPermissionMessageIDs();
1024 if (permissions.empty()) { 1026 if (legacy_permissions.empty()) {
1025 counter->Add(PermissionMessage::kNone); 1027 legacy_counter->Add(PermissionMessage::kNone);
1026 } else { 1028 } else {
1027 for (PermissionMessage::ID id : permissions) 1029 for (PermissionMessage::ID id : legacy_permissions)
1028 counter->Add(id); 1030 legacy_counter->Add(id);
1029 } 1031 }
1032
not at google - send to devlin 2015/04/30 16:31:32 could you add some comments in this method explain
Marc Treib 2015/05/04 09:15:58 Done.
1033 base::HistogramBase* counter = base::LinearHistogram::FactoryGet(
1034 base::StringPrintf("Extensions.Permissions_%s3", histogram),
1035 1,
1036 APIPermission::kEnumBoundary,
1037 APIPermission::kEnumBoundary + 1,
1038 base::HistogramBase::kUmaTargetedHistogramFlag);
1039
1040 base::HistogramBase* counter_has_any = base::BooleanHistogram::FactoryGet(
1041 base::StringPrintf("Extensions.HasPermissions_%s3", histogram),
1042 base::HistogramBase::kUmaTargetedHistogramFlag);
1043
1044 PermissionIDSet permissions =
1045 extensions::PermissionMessageProvider::Get()->GetAllPermissionIDs(
1046 extension->permissions_data()->active_permissions().get(),
1047 extension->GetType());
1048 counter_has_any->AddBoolean(!permissions.empty());
1049 for (const PermissionID& id : permissions)
1050 counter->Add(id.id());
1030 } 1051 }
1031 1052
1032 void ExtensionService::NotifyExtensionLoaded(const Extension* extension) { 1053 void ExtensionService::NotifyExtensionLoaded(const Extension* extension) {
1033 // The URLRequestContexts need to be first to know that the extension 1054 // 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 1055 // 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 1056 // 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 1057 // that the request context doesn't yet know about. The profile is responsible
1037 // for ensuring its URLRequestContexts appropriately discover the loaded 1058 // for ensuring its URLRequestContexts appropriately discover the loaded
1038 // extension. 1059 // extension.
1039 system_->RegisterExtensionWithRequestContexts(extension); 1060 system_->RegisterExtensionWithRequestContexts(extension);
(...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after
1662 // Extension has changed permissions significantly. Disable it. A 1683 // Extension has changed permissions significantly. Disable it. A
1663 // notification should be sent by the caller. If the extension is already 1684 // notification should be sent by the caller. If the extension is already
1664 // disabled because it was installed remotely, don't add another disable 1685 // disabled because it was installed remotely, don't add another disable
1665 // reason, but instead always set the "did escalate permissions" flag, to 1686 // reason, but instead always set the "did escalate permissions" flag, to
1666 // ensure enabling it will always show a warning. 1687 // ensure enabling it will always show a warning.
1667 if (disable_reasons == Extension::DISABLE_REMOTE_INSTALL) { 1688 if (disable_reasons == Extension::DISABLE_REMOTE_INSTALL) {
1668 extension_prefs_->SetDidExtensionEscalatePermissions(extension, true); 1689 extension_prefs_->SetDidExtensionEscalatePermissions(extension, true);
1669 } else if (is_privilege_increase) { 1690 } else if (is_privilege_increase) {
1670 disable_reasons |= Extension::DISABLE_PERMISSIONS_INCREASE; 1691 disable_reasons |= Extension::DISABLE_PERMISSIONS_INCREASE;
1671 if (!extension_prefs_->DidExtensionEscalatePermissions(extension->id())) { 1692 if (!extension_prefs_->DidExtensionEscalatePermissions(extension->id())) {
1672 RecordPermissionMessagesHistogram(extension, 1693 RecordPermissionMessagesHistogram(extension, "AutoDisable");
1673 "Extensions.Permissions_AutoDisable2");
1674 } 1694 }
1675 extension_prefs_->SetExtensionState(extension->id(), Extension::DISABLED); 1695 extension_prefs_->SetExtensionState(extension->id(), Extension::DISABLED);
1676 extension_prefs_->SetDidExtensionEscalatePermissions(extension, true); 1696 extension_prefs_->SetDidExtensionEscalatePermissions(extension, true);
1677 1697
1678 #if defined(ENABLE_SUPERVISED_USERS) 1698 #if defined(ENABLE_SUPERVISED_USERS)
1679 // If a custodian-installed extension is disabled for a supervised user due 1699 // 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 1700 // to a permissions increase, send a request to the custodian, since the
1681 // supervised user themselves can't re-enable the extension. 1701 // supervised user themselves can't re-enable the extension.
1682 if (extensions::util::IsExtensionSupervised(extension, profile_)) { 1702 if (extensions::util::IsExtensionSupervised(extension, profile_)) {
1683 SupervisedUserService* supervised_user_service = 1703 SupervisedUserService* supervised_user_service =
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
1786 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.SilentInstall", 1806 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.SilentInstall",
1787 extension->location(), 1807 extension->location(),
1788 Manifest::NUM_LOCATIONS); 1808 Manifest::NUM_LOCATIONS);
1789 } 1809 }
1790 1810
1791 if (!GetInstalledExtension(extension->id())) { 1811 if (!GetInstalledExtension(extension->id())) {
1792 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallType", 1812 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallType",
1793 extension->GetType(), 100); 1813 extension->GetType(), 100);
1794 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallSource", 1814 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallSource",
1795 extension->location(), Manifest::NUM_LOCATIONS); 1815 extension->location(), Manifest::NUM_LOCATIONS);
1796 RecordPermissionMessagesHistogram(extension, 1816 RecordPermissionMessagesHistogram(extension, "Install");
1797 "Extensions.Permissions_Install2");
1798 } else { 1817 } else {
1799 UMA_HISTOGRAM_ENUMERATION("Extensions.UpdateType", 1818 UMA_HISTOGRAM_ENUMERATION("Extensions.UpdateType",
1800 extension->GetType(), 100); 1819 extension->GetType(), 100);
1801 UMA_HISTOGRAM_ENUMERATION("Extensions.UpdateSource", 1820 UMA_HISTOGRAM_ENUMERATION("Extensions.UpdateSource",
1802 extension->location(), Manifest::NUM_LOCATIONS); 1821 extension->location(), Manifest::NUM_LOCATIONS);
1803 1822
1804 // A fully installed app cannot be demoted to an ephemeral app. 1823 // A fully installed app cannot be demoted to an ephemeral app.
1805 if ((install_flags & extensions::kInstallFlagIsEphemeral) && 1824 if ((install_flags & extensions::kInstallFlagIsEphemeral) &&
1806 !extension_prefs_->IsEphemeralApp(id)) { 1825 !extension_prefs_->IsEphemeralApp(id)) {
1807 install_flags &= ~static_cast<int>(extensions::kInstallFlagIsEphemeral); 1826 install_flags &= ~static_cast<int>(extensions::kInstallFlagIsEphemeral);
(...skipping 778 matching lines...) Expand 10 before | Expand all | Expand 10 after
2586 } 2605 }
2587 2606
2588 void ExtensionService::OnProfileDestructionStarted() { 2607 void ExtensionService::OnProfileDestructionStarted() {
2589 ExtensionIdSet ids_to_unload = registry_->enabled_extensions().GetIDs(); 2608 ExtensionIdSet ids_to_unload = registry_->enabled_extensions().GetIDs();
2590 for (ExtensionIdSet::iterator it = ids_to_unload.begin(); 2609 for (ExtensionIdSet::iterator it = ids_to_unload.begin();
2591 it != ids_to_unload.end(); 2610 it != ids_to_unload.end();
2592 ++it) { 2611 ++it) {
2593 UnloadExtension(*it, UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN); 2612 UnloadExtension(*it, UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN);
2594 } 2613 }
2595 } 2614 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698