Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_prefs.h" | 5 #include "chrome/browser/extensions/extension_prefs.h" |
| 6 | 6 |
| 7 #include "base/string_number_conversions.h" | 7 #include "base/string_number_conversions.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/extensions/admin_policy.h" | 10 #include "chrome/browser/extensions/admin_policy.h" |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 264 case kExtensionPrefsScopeIncognitoPersistent: | 264 case kExtensionPrefsScopeIncognitoPersistent: |
| 265 *result = kPrefIncognitoPreferences; | 265 *result = kPrefIncognitoPreferences; |
| 266 return true; | 266 return true; |
| 267 case kExtensionPrefsScopeIncognitoSessionOnly: | 267 case kExtensionPrefsScopeIncognitoSessionOnly: |
| 268 return false; | 268 return false; |
| 269 } | 269 } |
| 270 NOTREACHED(); | 270 NOTREACHED(); |
| 271 return false; | 271 return false; |
| 272 } | 272 } |
| 273 | 273 |
| 274 // Reads a boolean pref from |ext| with key |pref_key|. | |
| 275 // Return false if the value is false or |pref_key| does not exist. | |
| 276 bool ReadBooleanFromPref(const DictionaryValue* ext, | |
| 277 const std::string& pref_key) { | |
| 278 bool bool_value = false; | |
| 279 ext->GetBoolean(pref_key, &bool_value); | |
| 280 return bool_value; | |
| 281 } | |
| 282 | |
| 283 // Reads an integer pref from |ext| with key |pref_key|. | |
| 284 // Return false if the value does not exist. | |
| 285 bool ReadIntegerFromPref(const DictionaryValue* ext, | |
| 286 const std::string& pref_key, int* out_value) { | |
|
Mattias Nissler (ping if slow)
2012/08/08 08:08:37
all parameters on separate lines
qfel
2012/08/13 16:03:01
Done.
| |
| 287 if (!ext->GetInteger(pref_key, out_value)) | |
| 288 return false; | |
| 289 return out_value != NULL; | |
| 290 } | |
| 291 | |
| 292 // Checks if kPrefBlacklist is set to true in the DictionaryValue. | |
| 293 // Return false if the value is false or kPrefBlacklist does not exist. | |
| 294 // This is used to decide if an extension is blacklisted. | |
| 295 bool IsBlacklistBitSet(const DictionaryValue* ext) { | |
| 296 return ReadBooleanFromPref(ext, kPrefBlacklist); | |
| 297 } | |
| 298 | |
| 274 } // namespace | 299 } // namespace |
| 275 | 300 |
| 276 ExtensionPrefs::ExtensionPrefs( | 301 ExtensionPrefs::ExtensionPrefs( |
| 277 PrefService* prefs, | 302 PrefService* prefs, |
| 278 const FilePath& root_dir, | 303 const FilePath& root_dir, |
| 279 ExtensionPrefValueMap* extension_pref_value_map) | 304 ExtensionPrefValueMap* extension_pref_value_map) |
| 280 : prefs_(prefs), | 305 : prefs_(prefs), |
| 281 install_directory_(root_dir), | 306 install_directory_(root_dir), |
| 282 extension_pref_value_map_(extension_pref_value_map), | 307 extension_pref_value_map_(extension_pref_value_map), |
| 283 ALLOW_THIS_IN_INITIALIZER_LIST(extension_sorting_( | 308 ALLOW_THIS_IN_INITIALIZER_LIST(extension_sorting_( |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 391 DictionaryValue* ExtensionPrefs::CopyCurrentExtensions() { | 416 DictionaryValue* ExtensionPrefs::CopyCurrentExtensions() { |
| 392 const DictionaryValue* extensions = prefs_->GetDictionary(kExtensionsPref); | 417 const DictionaryValue* extensions = prefs_->GetDictionary(kExtensionsPref); |
| 393 if (extensions) { | 418 if (extensions) { |
| 394 DictionaryValue* copy = extensions->DeepCopy(); | 419 DictionaryValue* copy = extensions->DeepCopy(); |
| 395 MakePathsAbsolute(copy); | 420 MakePathsAbsolute(copy); |
| 396 return copy; | 421 return copy; |
| 397 } | 422 } |
| 398 return new DictionaryValue; | 423 return new DictionaryValue; |
| 399 } | 424 } |
| 400 | 425 |
| 401 // static | |
| 402 bool ExtensionPrefs::ReadBooleanFromPref( | |
| 403 const DictionaryValue* ext, const std::string& pref_key) { | |
| 404 bool bool_value = false; | |
| 405 ext->GetBoolean(pref_key, &bool_value); | |
| 406 return bool_value; | |
| 407 } | |
| 408 | |
| 409 bool ExtensionPrefs::ReadExtensionPrefBoolean( | 426 bool ExtensionPrefs::ReadExtensionPrefBoolean( |
| 410 const std::string& extension_id, const std::string& pref_key) const { | 427 const std::string& extension_id, const std::string& pref_key) const { |
| 411 const DictionaryValue* ext = GetExtensionPref(extension_id); | 428 const DictionaryValue* ext = GetExtensionPref(extension_id); |
| 412 if (!ext) { | 429 if (!ext) { |
| 413 // No such extension yet. | 430 // No such extension yet. |
| 414 return false; | 431 return false; |
| 415 } | 432 } |
| 416 return ReadBooleanFromPref(ext, pref_key); | 433 return ReadBooleanFromPref(ext, pref_key); |
| 417 } | 434 } |
| 418 | 435 |
| 419 // static | |
| 420 bool ExtensionPrefs::ReadIntegerFromPref( | |
| 421 const DictionaryValue* ext, const std::string& pref_key, int* out_value) { | |
| 422 if (!ext->GetInteger(pref_key, out_value)) | |
| 423 return false; | |
| 424 | |
| 425 return out_value != NULL; | |
| 426 } | |
| 427 | |
| 428 bool ExtensionPrefs::ReadExtensionPrefInteger( | 436 bool ExtensionPrefs::ReadExtensionPrefInteger( |
| 429 const std::string& extension_id, const std::string& pref_key, | 437 const std::string& extension_id, const std::string& pref_key, |
| 430 int* out_value) const { | 438 int* out_value) const { |
| 431 const DictionaryValue* ext = GetExtensionPref(extension_id); | 439 const DictionaryValue* ext = GetExtensionPref(extension_id); |
| 432 if (!ext) { | 440 if (!ext) { |
| 433 // No such extension yet. | 441 // No such extension yet. |
| 434 return false; | 442 return false; |
| 435 } | 443 } |
| 436 return ReadIntegerFromPref(ext, pref_key, out_value); | 444 return ReadIntegerFromPref(ext, pref_key, out_value); |
| 437 } | 445 } |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 542 } | 550 } |
| 543 | 551 |
| 544 // Set the scriptable host permissions. | 552 // Set the scriptable host permissions. |
| 545 if (!new_value->scriptable_hosts().is_empty()) { | 553 if (!new_value->scriptable_hosts().is_empty()) { |
| 546 SetExtensionPrefURLPatternSet(extension_id, | 554 SetExtensionPrefURLPatternSet(extension_id, |
| 547 JoinPrefs(pref_key, kPrefScriptableHosts), | 555 JoinPrefs(pref_key, kPrefScriptableHosts), |
| 548 new_value->scriptable_hosts()); | 556 new_value->scriptable_hosts()); |
| 549 } | 557 } |
| 550 } | 558 } |
| 551 | 559 |
| 552 // static | 560 bool ExtensionPrefs::IsExtensionBlacklisted( |
| 553 bool ExtensionPrefs::IsBlacklistBitSet(const DictionaryValue* ext) { | 561 const std::string& extension_id) const { |
| 554 return ReadBooleanFromPref(ext, kPrefBlacklist); | 562 return IsExtensionBlacklisted(extension_id, prefs_); |
| 555 } | 563 } |
| 556 | 564 |
| 557 bool ExtensionPrefs::IsExtensionBlacklisted(const std::string& extension_id) { | 565 // static |
| 558 return ReadExtensionPrefBoolean(extension_id, kPrefBlacklist); | 566 bool ExtensionPrefs::IsExtensionBlacklisted(const std::string& extension_id, |
| 567 const PrefService* pref_service) { | |
| 568 const DictionaryValue* dict = pref_service->GetDictionary(kExtensionsPref); | |
| 569 if (!dict) | |
| 570 return false; | |
| 571 const DictionaryValue* ext = NULL; | |
| 572 if (!dict->GetDictionary(extension_id, &ext)) { | |
| 573 // No such extension yet. | |
| 574 return false; | |
| 575 } | |
| 576 if (!IsBlacklistBitSet(ext)) | |
| 577 return false; | |
| 578 | |
| 579 // Check if policy settings override the blacklist. | |
| 580 const base::ListValue* whitelist = | |
| 581 pref_service->GetList(prefs::kExtensionInstallAllowList); | |
| 582 const base::ListValue* forcelist = | |
| 583 pref_service->GetList(prefs::kExtensionInstallForceList); | |
| 584 base::StringValue id(extension_id); | |
| 585 return (!whitelist || whitelist->Find(id) == whitelist->end()) && | |
| 586 (!forcelist || forcelist->Find(id) == forcelist->end()); | |
|
Mattias Nissler (ping if slow)
2012/08/08 08:08:37
Blacklisting has recently been abstracted into chr
| |
| 559 } | 587 } |
| 560 | 588 |
| 561 bool ExtensionPrefs::IsExtensionOrphaned(const std::string& extension_id) { | 589 bool ExtensionPrefs::IsExtensionOrphaned(const std::string& extension_id) { |
| 562 // TODO(miket): we believe that this test will hinge on the number of | 590 // TODO(miket): we believe that this test will hinge on the number of |
| 563 // consecutive times that an update check has returned a certain response | 591 // consecutive times that an update check has returned a certain response |
| 564 // versus a success response. For now nobody is orphaned. | 592 // versus a success response. For now nobody is orphaned. |
| 565 return false; | 593 return false; |
| 566 } | 594 } |
| 567 | 595 |
| 568 bool ExtensionPrefs::IsExternalExtensionAcknowledged( | 596 bool ExtensionPrefs::IsExternalExtensionAcknowledged( |
| (...skipping 940 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1509 const DictionaryValue* ExtensionPrefs::GetExtensionPref( | 1537 const DictionaryValue* ExtensionPrefs::GetExtensionPref( |
| 1510 const std::string& extension_id) const { | 1538 const std::string& extension_id) const { |
| 1511 const DictionaryValue* dict = prefs_->GetDictionary(kExtensionsPref); | 1539 const DictionaryValue* dict = prefs_->GetDictionary(kExtensionsPref); |
| 1512 if (!dict) | 1540 if (!dict) |
| 1513 return NULL; | 1541 return NULL; |
| 1514 const DictionaryValue* extension = NULL; | 1542 const DictionaryValue* extension = NULL; |
| 1515 dict->GetDictionary(extension_id, &extension); | 1543 dict->GetDictionary(extension_id, &extension); |
| 1516 return extension; | 1544 return extension; |
| 1517 } | 1545 } |
| 1518 | 1546 |
| 1519 // Helper function for GetInstalledExtensionsInfo. | 1547 ExtensionInfo* ExtensionPrefs::GetInstalledExtensionInfoImpl( |
| 1520 static ExtensionInfo* GetInstalledExtensionInfoImpl( | |
| 1521 DictionaryValue* extension_data, | 1548 DictionaryValue* extension_data, |
| 1522 DictionaryValue::key_iterator extension_id) { | 1549 DictionaryValue::key_iterator extension_id) const { |
|
Mattias Nissler (ping if slow)
2012/08/08 08:08:37
any reason to pass an iterator here instead of the
qfel
2012/08/13 16:03:01
I guess the original author did it mechanically wh
| |
| 1523 DictionaryValue* ext; | 1550 DictionaryValue* ext; |
| 1524 if (!extension_data->GetDictionaryWithoutPathExpansion(*extension_id, &ext)) { | 1551 if (!extension_data->GetDictionaryWithoutPathExpansion(*extension_id, &ext)) { |
| 1525 LOG(WARNING) << "Invalid pref for extension " << *extension_id; | 1552 LOG(WARNING) << "Invalid pref for extension " << *extension_id; |
| 1526 NOTREACHED(); | 1553 NOTREACHED(); |
| 1527 return NULL; | 1554 return NULL; |
| 1528 } | 1555 } |
| 1529 if (ext->HasKey(kPrefBlacklist)) { | 1556 if (IsExtensionBlacklisted(*extension_id)) |
|
Mattias Nissler (ping if slow)
2012/08/08 08:08:37
so you get the extension dictionary passed, and yo
| |
| 1530 bool is_blacklisted = false; | |
| 1531 if (!ext->GetBoolean(kPrefBlacklist, &is_blacklisted)) { | |
| 1532 NOTREACHED() << "Invalid blacklist pref:" << *extension_id; | |
| 1533 return NULL; | 1557 return NULL; |
| 1534 } | |
| 1535 if (is_blacklisted) { | |
| 1536 return NULL; | |
| 1537 } | |
| 1538 } | |
| 1539 int state_value; | 1558 int state_value; |
| 1540 if (!ext->GetInteger(kPrefState, &state_value)) { | 1559 if (!ext->GetInteger(kPrefState, &state_value)) { |
| 1541 // This can legitimately happen if we store preferences for component | 1560 // This can legitimately happen if we store preferences for component |
| 1542 // extensions. | 1561 // extensions. |
| 1543 return NULL; | 1562 return NULL; |
| 1544 } | 1563 } |
| 1545 if (state_value == Extension::EXTERNAL_EXTENSION_UNINSTALLED) { | 1564 if (state_value == Extension::EXTERNAL_EXTENSION_UNINSTALLED) { |
| 1546 LOG(WARNING) << "External extension with id " << *extension_id | 1565 LOG(WARNING) << "External extension with id " << *extension_id |
| 1547 << " has been uninstalled by the user"; | 1566 << " has been uninstalled by the user"; |
| 1548 return NULL; | 1567 return NULL; |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1797 scoped_ptr<ExtensionsInfo> extensions_info(GetInstalledExtensionsInfo()); | 1816 scoped_ptr<ExtensionsInfo> extensions_info(GetInstalledExtensionsInfo()); |
| 1798 | 1817 |
| 1799 for (size_t i = 0; i < extensions_info->size(); ++i) { | 1818 for (size_t i = 0; i < extensions_info->size(); ++i) { |
| 1800 ExtensionInfo* info = extensions_info->at(i).get(); | 1819 ExtensionInfo* info = extensions_info->at(i).get(); |
| 1801 out->push_back(info->extension_id); | 1820 out->push_back(info->extension_id); |
| 1802 } | 1821 } |
| 1803 } | 1822 } |
| 1804 | 1823 |
| 1805 // static | 1824 // static |
| 1806 ExtensionPrefs::ExtensionIdSet ExtensionPrefs::GetExtensionsFrom( | 1825 ExtensionPrefs::ExtensionIdSet ExtensionPrefs::GetExtensionsFrom( |
| 1807 const base::DictionaryValue* extension_prefs) { | 1826 const PrefService* pref_service) { |
| 1808 ExtensionIdSet result; | 1827 ExtensionIdSet result; |
| 1828 | |
| 1829 const base::DictionaryValue* extension_prefs; | |
| 1830 const base::Value* extension_prefs_value = | |
| 1831 pref_service->GetUserPrefValue(kExtensionsPref); | |
| 1832 if (!extension_prefs_value || | |
| 1833 !extension_prefs_value->GetAsDictionary(&extension_prefs)) { | |
| 1834 return result; // Empty set | |
| 1835 } | |
| 1836 | |
| 1809 for (base::DictionaryValue::key_iterator it = extension_prefs->begin_keys(); | 1837 for (base::DictionaryValue::key_iterator it = extension_prefs->begin_keys(); |
| 1810 it != extension_prefs->end_keys(); ++it) { | 1838 it != extension_prefs->end_keys(); ++it) { |
| 1811 const DictionaryValue* ext; | 1839 if (!IsExtensionBlacklisted(*it, pref_service)) |
| 1812 if (!extension_prefs->GetDictionaryWithoutPathExpansion(*it, &ext)) { | |
| 1813 NOTREACHED() << "Invalid pref for extension " << *it; | |
| 1814 continue; | |
| 1815 } | |
| 1816 if (!IsBlacklistBitSet(ext)) | |
| 1817 result.push_back(*it); | 1840 result.push_back(*it); |
| 1818 } | 1841 } |
| 1819 return result; | 1842 return result; |
| 1820 } | 1843 } |
| 1821 | 1844 |
| 1822 void ExtensionPrefs::FixMissingPrefs(const ExtensionIdSet& extension_ids) { | 1845 void ExtensionPrefs::FixMissingPrefs(const ExtensionIdSet& extension_ids) { |
| 1823 // Fix old entries that did not get an installation time entry when they | 1846 // Fix old entries that did not get an installation time entry when they |
| 1824 // were installed or don't have a preferences field. | 1847 // were installed or don't have a preferences field. |
| 1825 for (ExtensionIdSet::const_iterator ext_id = extension_ids.begin(); | 1848 for (ExtensionIdSet::const_iterator ext_id = extension_ids.begin(); |
| 1826 ext_id != extension_ids.end(); ++ext_id) { | 1849 ext_id != extension_ids.end(); ++ext_id) { |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2059 0, // default value | 2082 0, // default value |
| 2060 PrefService::UNSYNCABLE_PREF); | 2083 PrefService::UNSYNCABLE_PREF); |
| 2061 prefs->RegisterInt64Pref(prefs::kNextExtensionsUpdateCheck, | 2084 prefs->RegisterInt64Pref(prefs::kNextExtensionsUpdateCheck, |
| 2062 0, // default value | 2085 0, // default value |
| 2063 PrefService::UNSYNCABLE_PREF); | 2086 PrefService::UNSYNCABLE_PREF); |
| 2064 prefs->RegisterListPref(prefs::kExtensionAllowedInstallSites, | 2087 prefs->RegisterListPref(prefs::kExtensionAllowedInstallSites, |
| 2065 PrefService::UNSYNCABLE_PREF); | 2088 PrefService::UNSYNCABLE_PREF); |
| 2066 } | 2089 } |
| 2067 | 2090 |
| 2068 } // namespace extensions | 2091 } // namespace extensions |
| OLD | NEW |