OLD | NEW |
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 <iterator> | 7 #include <iterator> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/prefs/pref_notifier.h" | 10 #include "base/prefs/pref_notifier.h" |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 // the user to accept them once recognized. We store the active permission | 141 // the user to accept them once recognized. We store the active permission |
142 // permissions because they may differ from those defined in the manifest. | 142 // permissions because they may differ from those defined in the manifest. |
143 const char kPrefActivePermissions[] = "active_permissions"; | 143 const char kPrefActivePermissions[] = "active_permissions"; |
144 const char kPrefGrantedPermissions[] = "granted_permissions"; | 144 const char kPrefGrantedPermissions[] = "granted_permissions"; |
145 | 145 |
146 // The preference names for PermissionSet values. | 146 // The preference names for PermissionSet values. |
147 const char kPrefAPIs[] = "api"; | 147 const char kPrefAPIs[] = "api"; |
148 const char kPrefManifestPermissions[] = "manifest_permissions"; | 148 const char kPrefManifestPermissions[] = "manifest_permissions"; |
149 const char kPrefExplicitHosts[] = "explicit_host"; | 149 const char kPrefExplicitHosts[] = "explicit_host"; |
150 const char kPrefScriptableHosts[] = "scriptable_host"; | 150 const char kPrefScriptableHosts[] = "scriptable_host"; |
| 151 const char kPrefPersistedPermissions[] = "persisted_permissions"; |
151 | 152 |
152 // The preference names for the old granted permissions scheme. | 153 // The preference names for the old granted permissions scheme. |
153 const char kPrefOldGrantedFullAccess[] = "granted_permissions.full"; | 154 const char kPrefOldGrantedFullAccess[] = "granted_permissions.full"; |
154 const char kPrefOldGrantedHosts[] = "granted_permissions.host"; | 155 const char kPrefOldGrantedHosts[] = "granted_permissions.host"; |
155 const char kPrefOldGrantedAPIs[] = "granted_permissions.api"; | 156 const char kPrefOldGrantedAPIs[] = "granted_permissions.api"; |
156 | 157 |
157 // A preference that indicates when an extension was installed. | 158 // A preference that indicates when an extension was installed. |
158 const char kPrefInstallTime[] = "install_time"; | 159 const char kPrefInstallTime[] = "install_time"; |
159 | 160 |
160 // A preference which saves the creation flags for extensions. | 161 // A preference which saves the creation flags for extensions. |
(...skipping 963 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1124 return ReadPrefAsPermissionSet(extension_id, kPrefActivePermissions); | 1125 return ReadPrefAsPermissionSet(extension_id, kPrefActivePermissions); |
1125 } | 1126 } |
1126 | 1127 |
1127 void ExtensionPrefs::SetActivePermissions( | 1128 void ExtensionPrefs::SetActivePermissions( |
1128 const std::string& extension_id, | 1129 const std::string& extension_id, |
1129 const PermissionSet* permissions) { | 1130 const PermissionSet* permissions) { |
1130 SetExtensionPrefPermissionSet( | 1131 SetExtensionPrefPermissionSet( |
1131 extension_id, kPrefActivePermissions, permissions); | 1132 extension_id, kPrefActivePermissions, permissions); |
1132 } | 1133 } |
1133 | 1134 |
| 1135 bool ExtensionPrefs::GetPersistedPermissions( |
| 1136 const std::string& extension_id, |
| 1137 URLPatternSet* persisted_permissions) { |
| 1138 CHECK(Extension::IdIsValid(extension_id)); |
| 1139 return ReadPrefAsURLPatternSet(extension_id, |
| 1140 kPrefPersistedPermissions, |
| 1141 persisted_permissions, |
| 1142 UserScript::ValidUserScriptSchemes()); |
| 1143 } |
| 1144 |
| 1145 void ExtensionPrefs::AddPersistedPermission(const Extension* extension, |
| 1146 const URLPattern* pattern) { |
| 1147 DictionaryPrefUpdate update(prefs_, "extensions.settings"); |
| 1148 base::DictionaryValue* dict = update.Get(); |
| 1149 base::DictionaryValue* prefer = NULL; |
| 1150 dict->GetDictionary(extension->id(), &prefer); |
| 1151 |
| 1152 base::ListValue* pattern_list = NULL; |
| 1153 |
| 1154 if (!prefer->GetList(kPrefPersistedPermissions, &pattern_list)) { |
| 1155 prefer->Set(kPrefPersistedPermissions, new base::ListValue()); |
| 1156 prefer->GetList(kPrefPersistedPermissions, &pattern_list); |
| 1157 } |
| 1158 |
| 1159 pattern_list->Append(new base::StringValue(pattern->GetAsString())); |
| 1160 } |
| 1161 |
| 1162 void ExtensionPrefs::ClearPersistedPermissions(const Extension* extension) { |
| 1163 DictionaryPrefUpdate update(prefs_, "extensions.settings"); |
| 1164 base::DictionaryValue* dict = update.Get(); |
| 1165 base::DictionaryValue* prefer = NULL; |
| 1166 dict->GetDictionary(extension->id(), &prefer); |
| 1167 |
| 1168 prefer->Set(kPrefPersistedPermissions, new base::ListValue()); |
| 1169 } |
| 1170 |
1134 void ExtensionPrefs::SetExtensionRunning(const std::string& extension_id, | 1171 void ExtensionPrefs::SetExtensionRunning(const std::string& extension_id, |
1135 bool is_running) { | 1172 bool is_running) { |
1136 base::Value* value = new base::FundamentalValue(is_running); | 1173 base::Value* value = new base::FundamentalValue(is_running); |
1137 UpdateExtensionPref(extension_id, kPrefRunning, value); | 1174 UpdateExtensionPref(extension_id, kPrefRunning, value); |
1138 } | 1175 } |
1139 | 1176 |
1140 bool ExtensionPrefs::IsExtensionRunning(const std::string& extension_id) { | 1177 bool ExtensionPrefs::IsExtensionRunning(const std::string& extension_id) { |
1141 const base::DictionaryValue* extension = GetExtensionPref(extension_id); | 1178 const base::DictionaryValue* extension = GetExtensionPref(extension_id); |
1142 if (!extension) | 1179 if (!extension) |
1143 return false; | 1180 return false; |
(...skipping 1042 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2186 extension_pref_value_map_->RegisterExtension( | 2223 extension_pref_value_map_->RegisterExtension( |
2187 extension_id, install_time, is_enabled, is_incognito_enabled); | 2224 extension_id, install_time, is_enabled, is_incognito_enabled); |
2188 | 2225 |
2189 FOR_EACH_OBSERVER( | 2226 FOR_EACH_OBSERVER( |
2190 ExtensionPrefsObserver, | 2227 ExtensionPrefsObserver, |
2191 observer_list_, | 2228 observer_list_, |
2192 OnExtensionRegistered(extension_id, install_time, is_enabled)); | 2229 OnExtensionRegistered(extension_id, install_time, is_enabled)); |
2193 } | 2230 } |
2194 | 2231 |
2195 } // namespace extensions | 2232 } // namespace extensions |
OLD | NEW |