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" |
11 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
14 #include "base/value_conversions.h" | 14 #include "base/value_conversions.h" |
15 #include "chrome/browser/extensions/api/content_settings/content_settings_store.
h" | 15 #include "chrome/browser/extensions/api/content_settings/content_settings_store.
h" |
16 #include "chrome/browser/extensions/api/preference/preference_api.h" | |
17 #include "components/user_prefs/pref_registry_syncable.h" | 16 #include "components/user_prefs/pref_registry_syncable.h" |
18 #include "extensions/browser/admin_policy.h" | 17 #include "extensions/browser/admin_policy.h" |
19 #include "extensions/browser/app_sorting.h" | 18 #include "extensions/browser/app_sorting.h" |
20 #include "extensions/browser/event_router.h" | 19 #include "extensions/browser/event_router.h" |
21 #include "extensions/browser/extension_pref_store.h" | 20 #include "extensions/browser/extension_pref_store.h" |
22 #include "extensions/browser/extension_prefs_factory.h" | 21 #include "extensions/browser/extension_prefs_factory.h" |
23 #include "extensions/browser/pref_names.h" | 22 #include "extensions/browser/pref_names.h" |
24 #include "extensions/common/feature_switch.h" | 23 #include "extensions/common/feature_switch.h" |
25 #include "extensions/common/manifest.h" | 24 #include "extensions/common/manifest.h" |
26 #include "extensions/common/permissions/permission_set.h" | 25 #include "extensions/common/permissions/permission_set.h" |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 bool IsBlacklistBitSet(const base::DictionaryValue* ext) { | 229 bool IsBlacklistBitSet(const base::DictionaryValue* ext) { |
231 bool bool_value; | 230 bool bool_value; |
232 return ext->GetBoolean(kPrefBlacklist, &bool_value) && bool_value; | 231 return ext->GetBoolean(kPrefBlacklist, &bool_value) && bool_value; |
233 } | 232 } |
234 | 233 |
235 bool IsEvictedEphemeralApp(const base::DictionaryValue* ext) { | 234 bool IsEvictedEphemeralApp(const base::DictionaryValue* ext) { |
236 bool bool_value; | 235 bool bool_value; |
237 return ext->GetBoolean(kPrefEvictedEphemeralApp, &bool_value) && bool_value; | 236 return ext->GetBoolean(kPrefEvictedEphemeralApp, &bool_value) && bool_value; |
238 } | 237 } |
239 | 238 |
| 239 void LoadExtensionControlledPrefs(ExtensionPrefs* prefs, |
| 240 ExtensionPrefValueMap* value_map, |
| 241 const std::string& extension_id, |
| 242 ExtensionPrefsScope scope) { |
| 243 std::string scope_string; |
| 244 if (!pref_names::ScopeToPrefName(scope, &scope_string)) |
| 245 return; |
| 246 std::string key = extension_id + "." + scope_string; |
| 247 |
| 248 const base::DictionaryValue* source_dict = |
| 249 prefs->pref_service()->GetDictionary(pref_names::kExtensions); |
| 250 const base::DictionaryValue* preferences = NULL; |
| 251 if (!source_dict->GetDictionary(key, &preferences)) |
| 252 return; |
| 253 |
| 254 for (base::DictionaryValue::Iterator iter(*preferences); !iter.IsAtEnd(); |
| 255 iter.Advance()) { |
| 256 value_map->SetExtensionPref( |
| 257 extension_id, iter.key(), scope, iter.value().DeepCopy()); |
| 258 } |
| 259 } |
| 260 |
| 261 void InitExtensionControlledPrefs(ExtensionPrefs* prefs, |
| 262 ExtensionPrefValueMap* value_map) { |
| 263 ExtensionIdList extension_ids; |
| 264 prefs->GetExtensions(&extension_ids); |
| 265 |
| 266 for (ExtensionIdList::iterator extension_id = extension_ids.begin(); |
| 267 extension_id != extension_ids.end(); |
| 268 ++extension_id) { |
| 269 base::Time install_time = prefs->GetInstallTime(*extension_id); |
| 270 bool is_enabled = !prefs->IsExtensionDisabled(*extension_id); |
| 271 bool is_incognito_enabled = prefs->IsIncognitoEnabled(*extension_id); |
| 272 value_map->RegisterExtension( |
| 273 *extension_id, install_time, is_enabled, is_incognito_enabled); |
| 274 prefs->content_settings_store()->RegisterExtension( |
| 275 *extension_id, install_time, is_enabled); |
| 276 |
| 277 // Set regular extension controlled prefs. |
| 278 LoadExtensionControlledPrefs( |
| 279 prefs, value_map, *extension_id, kExtensionPrefsScopeRegular); |
| 280 // Set incognito extension controlled prefs. |
| 281 LoadExtensionControlledPrefs(prefs, |
| 282 value_map, |
| 283 *extension_id, |
| 284 kExtensionPrefsScopeIncognitoPersistent); |
| 285 // Set regular-only extension controlled prefs. |
| 286 LoadExtensionControlledPrefs( |
| 287 prefs, value_map, *extension_id, kExtensionPrefsScopeRegularOnly); |
| 288 |
| 289 // Set content settings. |
| 290 const base::ListValue* content_settings = NULL; |
| 291 if (prefs->ReadPrefAsList(*extension_id, |
| 292 pref_names::kPrefContentSettings, |
| 293 &content_settings)) { |
| 294 prefs->content_settings_store()->SetExtensionContentSettingFromList( |
| 295 *extension_id, content_settings, kExtensionPrefsScopeRegular); |
| 296 } |
| 297 if (prefs->ReadPrefAsList(*extension_id, |
| 298 pref_names::kPrefIncognitoContentSettings, |
| 299 &content_settings)) { |
| 300 prefs->content_settings_store()->SetExtensionContentSettingFromList( |
| 301 *extension_id, |
| 302 content_settings, |
| 303 kExtensionPrefsScopeIncognitoPersistent); |
| 304 } |
| 305 } |
| 306 } |
| 307 |
240 } // namespace | 308 } // namespace |
241 | 309 |
242 // | 310 // |
243 // TimeProvider | 311 // TimeProvider |
244 // | 312 // |
245 | 313 |
246 ExtensionPrefs::TimeProvider::TimeProvider() { | 314 ExtensionPrefs::TimeProvider::TimeProvider() { |
247 } | 315 } |
248 | 316 |
249 ExtensionPrefs::TimeProvider::~TimeProvider() { | 317 ExtensionPrefs::TimeProvider::~TimeProvider() { |
(...skipping 1501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1751 ScopedExtensionPrefUpdate update(prefs_, *ext_id); | 1819 ScopedExtensionPrefUpdate update(prefs_, *ext_id); |
1752 // This creates an empty dictionary if none is stored. | 1820 // This creates an empty dictionary if none is stored. |
1753 update.Get(); | 1821 update.Get(); |
1754 } | 1822 } |
1755 | 1823 |
1756 FixMissingPrefs(extension_ids); | 1824 FixMissingPrefs(extension_ids); |
1757 MigratePermissions(extension_ids); | 1825 MigratePermissions(extension_ids); |
1758 MigrateDisableReasons(extension_ids); | 1826 MigrateDisableReasons(extension_ids); |
1759 app_sorting_->Initialize(extension_ids); | 1827 app_sorting_->Initialize(extension_ids); |
1760 | 1828 |
1761 PreferenceAPI::InitExtensionControlledPrefs(this, extension_pref_value_map_); | 1829 InitExtensionControlledPrefs(this, extension_pref_value_map_); |
1762 | 1830 |
1763 extension_pref_value_map_->NotifyInitializationCompleted(); | 1831 extension_pref_value_map_->NotifyInitializationCompleted(); |
1764 } | 1832 } |
1765 | 1833 |
1766 bool ExtensionPrefs::HasIncognitoPrefValue(const std::string& pref_key) { | 1834 bool ExtensionPrefs::HasIncognitoPrefValue(const std::string& pref_key) { |
1767 bool has_incognito_pref_value = false; | 1835 bool has_incognito_pref_value = false; |
1768 extension_pref_value_map_->GetEffectivePrefValue(pref_key, | 1836 extension_pref_value_map_->GetEffectivePrefValue(pref_key, |
1769 true, | 1837 true, |
1770 &has_incognito_pref_value); | 1838 &has_incognito_pref_value); |
1771 return has_incognito_pref_value; | 1839 return has_incognito_pref_value; |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2077 } | 2145 } |
2078 bool is_incognito_enabled = IsIncognitoEnabled(extension_id); | 2146 bool is_incognito_enabled = IsIncognitoEnabled(extension_id); |
2079 | 2147 |
2080 extension_pref_value_map_->RegisterExtension( | 2148 extension_pref_value_map_->RegisterExtension( |
2081 extension_id, install_time, is_enabled, is_incognito_enabled); | 2149 extension_id, install_time, is_enabled, is_incognito_enabled); |
2082 content_settings_store_->RegisterExtension(extension_id, install_time, | 2150 content_settings_store_->RegisterExtension(extension_id, install_time, |
2083 is_enabled); | 2151 is_enabled); |
2084 } | 2152 } |
2085 | 2153 |
2086 } // namespace extensions | 2154 } // namespace extensions |
OLD | NEW |