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

Side by Side Diff: extensions/browser/extension_prefs.cc

Issue 1589403002: ExtensionPrefs: remove MigratePermissions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@depr_disable_reason
Patch Set: update test data Created 4 years, 11 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
« no previous file with comments | « extensions/browser/extension_prefs.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "extensions/browser/extension_prefs.h" 5 #include "extensions/browser/extension_prefs.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <iterator> 10 #include <iterator>
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 // permissions because they may differ from those defined in the manifest. 131 // permissions because they may differ from those defined in the manifest.
132 const char kPrefActivePermissions[] = "active_permissions"; 132 const char kPrefActivePermissions[] = "active_permissions";
133 const char kPrefGrantedPermissions[] = "granted_permissions"; 133 const char kPrefGrantedPermissions[] = "granted_permissions";
134 134
135 // The preference names for PermissionSet values. 135 // The preference names for PermissionSet values.
136 const char kPrefAPIs[] = "api"; 136 const char kPrefAPIs[] = "api";
137 const char kPrefManifestPermissions[] = "manifest_permissions"; 137 const char kPrefManifestPermissions[] = "manifest_permissions";
138 const char kPrefExplicitHosts[] = "explicit_host"; 138 const char kPrefExplicitHosts[] = "explicit_host";
139 const char kPrefScriptableHosts[] = "scriptable_host"; 139 const char kPrefScriptableHosts[] = "scriptable_host";
140 140
141 // The preference names for the old granted permissions scheme.
142 const char kPrefOldGrantedFullAccess[] = "granted_permissions.full";
143 const char kPrefOldGrantedHosts[] = "granted_permissions.host";
144 const char kPrefOldGrantedAPIs[] = "granted_permissions.api";
145
146 // A preference that indicates when an extension was installed. 141 // A preference that indicates when an extension was installed.
147 const char kPrefInstallTime[] = "install_time"; 142 const char kPrefInstallTime[] = "install_time";
148 143
149 // A preference which saves the creation flags for extensions. 144 // A preference which saves the creation flags for extensions.
150 const char kPrefCreationFlags[] = "creation_flags"; 145 const char kPrefCreationFlags[] = "creation_flags";
151 146
152 // A preference that indicates whether the extension was installed from the 147 // A preference that indicates whether the extension was installed from the
153 // Chrome Web Store. 148 // Chrome Web Store.
154 const char kPrefFromWebStore[] = "from_webstore"; 149 const char kPrefFromWebStore[] = "from_webstore";
155 150
(...skipping 780 matching lines...) Expand 10 before | Expand all | Expand 10 after
936 return result; 931 return result;
937 return false; 932 return false;
938 } 933 }
939 934
940 void ExtensionPrefs::SetActiveBit(const std::string& extension_id, 935 void ExtensionPrefs::SetActiveBit(const std::string& extension_id,
941 bool active) { 936 bool active) {
942 UpdateExtensionPref(extension_id, kActiveBit, 937 UpdateExtensionPref(extension_id, kActiveBit,
943 new base::FundamentalValue(active)); 938 new base::FundamentalValue(active));
944 } 939 }
945 940
946 void ExtensionPrefs::MigratePermissions(const ExtensionIdList& extension_ids) {
947 PermissionsInfo* info = PermissionsInfo::GetInstance();
948 for (ExtensionIdList::const_iterator ext_id =
949 extension_ids.begin(); ext_id != extension_ids.end(); ++ext_id) {
950 // An extension's granted permissions need to be migrated if the
951 // full_access bit is present. This bit was always present in the previous
952 // scheme and is never present now.
953 bool full_access = false;
954 const base::DictionaryValue* ext = GetExtensionPref(*ext_id);
955 if (!ext || !ext->GetBoolean(kPrefOldGrantedFullAccess, &full_access))
956 continue;
957
958 // Remove the full access bit (empty list will get trimmed).
959 UpdateExtensionPref(
960 *ext_id, kPrefOldGrantedFullAccess, new base::ListValue());
961
962 // Add the plugin permission if the full access bit was set.
963 if (full_access) {
964 const base::ListValue* apis = NULL;
965 base::ListValue* new_apis = NULL;
966
967 std::string granted_apis = JoinPrefs(kPrefGrantedPermissions, kPrefAPIs);
968 if (ext->GetList(kPrefOldGrantedAPIs, &apis))
969 new_apis = apis->DeepCopy();
970 else
971 new_apis = new base::ListValue();
972
973 std::string plugin_name = info->GetByID(APIPermission::kPlugin)->name();
974 new_apis->Append(new base::StringValue(plugin_name));
975 UpdateExtensionPref(*ext_id, granted_apis, new_apis);
976 }
977
978 // The granted permissions originally only held the effective hosts,
979 // which are a combination of host and user script host permissions.
980 // We now maintain these lists separately. For migration purposes, it
981 // does not matter how we treat the old effective hosts as long as the
982 // new effective hosts will be the same, so we move them to explicit
983 // host permissions.
984 const base::ListValue* hosts = NULL;
985 std::string explicit_hosts =
986 JoinPrefs(kPrefGrantedPermissions, kPrefExplicitHosts);
987 if (ext->GetList(kPrefOldGrantedHosts, &hosts)) {
988 UpdateExtensionPref(
989 *ext_id, explicit_hosts, hosts->DeepCopy());
990
991 // We can get rid of the old one by setting it to an empty list.
992 UpdateExtensionPref(*ext_id, kPrefOldGrantedHosts, new base::ListValue());
993 }
994 }
995 }
996
997 scoped_ptr<const PermissionSet> ExtensionPrefs::GetGrantedPermissions( 941 scoped_ptr<const PermissionSet> ExtensionPrefs::GetGrantedPermissions(
998 const std::string& extension_id) const { 942 const std::string& extension_id) const {
999 CHECK(crx_file::id_util::IdIsValid(extension_id)); 943 CHECK(crx_file::id_util::IdIsValid(extension_id));
1000 return ReadPrefAsPermissionSet(extension_id, kPrefGrantedPermissions); 944 return ReadPrefAsPermissionSet(extension_id, kPrefGrantedPermissions);
1001 } 945 }
1002 946
1003 void ExtensionPrefs::AddGrantedPermissions(const std::string& extension_id, 947 void ExtensionPrefs::AddGrantedPermissions(const std::string& extension_id,
1004 const PermissionSet& permissions) { 948 const PermissionSet& permissions) {
1005 CHECK(crx_file::id_util::IdIsValid(extension_id)); 949 CHECK(crx_file::id_util::IdIsValid(extension_id));
1006 scoped_ptr<const PermissionSet> granted = GetGrantedPermissions(extension_id); 950 scoped_ptr<const PermissionSet> granted = GetGrantedPermissions(extension_id);
(...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after
1700 // Create empty preferences dictionary for each extension (these dictionaries 1644 // Create empty preferences dictionary for each extension (these dictionaries
1701 // are pruned when persisting the preferences to disk). 1645 // are pruned when persisting the preferences to disk).
1702 for (ExtensionIdList::iterator ext_id = extension_ids.begin(); 1646 for (ExtensionIdList::iterator ext_id = extension_ids.begin();
1703 ext_id != extension_ids.end(); ++ext_id) { 1647 ext_id != extension_ids.end(); ++ext_id) {
1704 ScopedExtensionPrefUpdate update(prefs_, *ext_id); 1648 ScopedExtensionPrefUpdate update(prefs_, *ext_id);
1705 // This creates an empty dictionary if none is stored. 1649 // This creates an empty dictionary if none is stored.
1706 update.Get(); 1650 update.Get();
1707 } 1651 }
1708 1652
1709 FixMissingPrefs(extension_ids); 1653 FixMissingPrefs(extension_ids);
1710 MigratePermissions(extension_ids);
1711 1654
1712 InitExtensionControlledPrefs(extension_pref_value_map_); 1655 InitExtensionControlledPrefs(extension_pref_value_map_);
1713 1656
1714 extension_pref_value_map_->NotifyInitializationCompleted(); 1657 extension_pref_value_map_->NotifyInitializationCompleted();
1715 } 1658 }
1716 1659
1717 bool ExtensionPrefs::HasIncognitoPrefValue(const std::string& pref_key) const { 1660 bool ExtensionPrefs::HasIncognitoPrefValue(const std::string& pref_key) const {
1718 bool has_incognito_pref_value = false; 1661 bool has_incognito_pref_value = false;
1719 extension_pref_value_map_->GetEffectivePrefValue(pref_key, 1662 extension_pref_value_map_->GetEffectivePrefValue(pref_key,
1720 true, 1663 true,
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
2044 extension_pref_value_map_->RegisterExtension( 1987 extension_pref_value_map_->RegisterExtension(
2045 extension_id, install_time, is_enabled, is_incognito_enabled); 1988 extension_id, install_time, is_enabled, is_incognito_enabled);
2046 1989
2047 FOR_EACH_OBSERVER( 1990 FOR_EACH_OBSERVER(
2048 ExtensionPrefsObserver, 1991 ExtensionPrefsObserver,
2049 observer_list_, 1992 observer_list_,
2050 OnExtensionRegistered(extension_id, install_time, is_enabled)); 1993 OnExtensionRegistered(extension_id, install_time, is_enabled));
2051 } 1994 }
2052 1995
2053 } // namespace extensions 1996 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/extension_prefs.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698