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 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 273 case kExtensionPrefsScopeIncognitoPersistent: | 273 case kExtensionPrefsScopeIncognitoPersistent: |
| 274 *result = kPrefIncognitoPreferences; | 274 *result = kPrefIncognitoPreferences; |
| 275 return true; | 275 return true; |
| 276 case kExtensionPrefsScopeIncognitoSessionOnly: | 276 case kExtensionPrefsScopeIncognitoSessionOnly: |
| 277 return false; | 277 return false; |
| 278 } | 278 } |
| 279 NOTREACHED(); | 279 NOTREACHED(); |
| 280 return false; | 280 return false; |
| 281 } | 281 } |
| 282 | 282 |
| 283 // Reads a boolean pref from |ext| with key |pref_key|. | |
| 284 // Return false if the value is false or |pref_key| does not exist. | |
| 285 bool ReadBooleanFromPref(const DictionaryValue* ext, | |
| 286 const std::string& pref_key) { | |
| 287 bool bool_value = false; | |
| 288 ext->GetBoolean(pref_key, &bool_value); | |
| 289 return bool_value; | |
| 290 } | |
| 291 | |
| 292 // Reads an integer pref from |ext| with key |pref_key|. | |
| 293 // Return false if the value does not exist. | |
| 294 bool ReadIntegerFromPref(const DictionaryValue* ext, | |
| 295 const std::string& pref_key, | |
| 296 int* out_value) { | |
| 297 if (!ext->GetInteger(pref_key, out_value)) | |
| 298 return false; | |
| 299 return out_value != NULL; | |
| 300 } | |
| 301 | |
| 302 // Checks if kPrefBlacklist is set to true in the DictionaryValue. | |
| 303 // Return false if the value is false or kPrefBlacklist does not exist. | |
| 304 // This is used to decide if an extension is blacklisted. | |
| 305 bool IsBlacklistBitSet(const DictionaryValue* ext) { | |
| 306 return ReadBooleanFromPref(ext, kPrefBlacklist); | |
| 307 } | |
| 308 | |
| 283 } // namespace | 309 } // namespace |
| 284 | 310 |
| 285 ExtensionPrefs::ExtensionPrefs( | 311 ExtensionPrefs::ExtensionPrefs( |
| 286 PrefService* prefs, | 312 PrefService* prefs, |
| 287 const FilePath& root_dir, | 313 const FilePath& root_dir, |
| 288 ExtensionPrefValueMap* extension_pref_value_map) | 314 ExtensionPrefValueMap* extension_pref_value_map) |
| 289 : prefs_(prefs), | 315 : prefs_(prefs), |
| 290 install_directory_(root_dir), | 316 install_directory_(root_dir), |
| 291 extension_pref_value_map_(extension_pref_value_map), | 317 extension_pref_value_map_(extension_pref_value_map), |
| 292 ALLOW_THIS_IN_INITIALIZER_LIST(extension_sorting_( | 318 ALLOW_THIS_IN_INITIALIZER_LIST(extension_sorting_( |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 360 continue; | 386 continue; |
| 361 } | 387 } |
| 362 FilePath::StringType path_string; | 388 FilePath::StringType path_string; |
| 363 extension_dict->GetString(kPrefPath, &path_string); | 389 extension_dict->GetString(kPrefPath, &path_string); |
| 364 FilePath path(path_string); | 390 FilePath path(path_string); |
| 365 extension_dict->SetString(kPrefPath, | 391 extension_dict->SetString(kPrefPath, |
| 366 MakePathRelative(install_directory_, path)); | 392 MakePathRelative(install_directory_, path)); |
| 367 } | 393 } |
| 368 } | 394 } |
| 369 | 395 |
| 370 void ExtensionPrefs::MakePathsAbsolute(DictionaryValue* dict) { | |
| 371 if (!dict || dict->empty()) | |
| 372 return; | |
| 373 | |
| 374 for (DictionaryValue::key_iterator i = dict->begin_keys(); | |
| 375 i != dict->end_keys(); ++i) { | |
| 376 DictionaryValue* extension_dict = NULL; | |
| 377 if (!dict->GetDictionaryWithoutPathExpansion(*i, &extension_dict)) { | |
| 378 NOTREACHED(); | |
| 379 continue; | |
| 380 } | |
| 381 | |
| 382 int location_value; | |
| 383 if (extension_dict->GetInteger(kPrefLocation, &location_value) && | |
| 384 location_value == Extension::LOAD) { | |
| 385 // Unpacked extensions will already have absolute paths. | |
| 386 continue; | |
| 387 } | |
| 388 | |
| 389 FilePath::StringType path_string; | |
| 390 if (!extension_dict->GetString(kPrefPath, &path_string)) | |
| 391 continue; | |
| 392 | |
| 393 DCHECK(location_value == Extension::COMPONENT || | |
| 394 !FilePath(path_string).IsAbsolute()); | |
| 395 extension_dict->SetString( | |
| 396 kPrefPath, install_directory_.Append(path_string).value()); | |
| 397 } | |
| 398 } | |
| 399 | |
| 400 DictionaryValue* ExtensionPrefs::CopyCurrentExtensions() { | |
| 401 const DictionaryValue* extensions = prefs_->GetDictionary(kExtensionsPref); | |
| 402 if (extensions) { | |
| 403 DictionaryValue* copy = extensions->DeepCopy(); | |
| 404 MakePathsAbsolute(copy); | |
| 405 return copy; | |
| 406 } | |
| 407 return new DictionaryValue; | |
| 408 } | |
| 409 | |
| 410 // static | |
| 411 bool ExtensionPrefs::ReadBooleanFromPref( | |
| 412 const DictionaryValue* ext, const std::string& pref_key) { | |
| 413 bool bool_value = false; | |
| 414 ext->GetBoolean(pref_key, &bool_value); | |
| 415 return bool_value; | |
| 416 } | |
| 417 | |
| 418 bool ExtensionPrefs::ReadExtensionPrefBoolean( | 396 bool ExtensionPrefs::ReadExtensionPrefBoolean( |
| 419 const std::string& extension_id, const std::string& pref_key) const { | 397 const std::string& extension_id, const std::string& pref_key) const { |
| 420 const DictionaryValue* ext = GetExtensionPref(extension_id); | 398 const DictionaryValue* ext = GetExtensionPref(extension_id); |
| 421 if (!ext) { | 399 if (!ext) { |
| 422 // No such extension yet. | 400 // No such extension yet. |
| 423 return false; | 401 return false; |
| 424 } | 402 } |
| 425 return ReadBooleanFromPref(ext, pref_key); | 403 return ReadBooleanFromPref(ext, pref_key); |
| 426 } | 404 } |
| 427 | 405 |
| 428 // static | |
| 429 bool ExtensionPrefs::ReadIntegerFromPref( | |
| 430 const DictionaryValue* ext, const std::string& pref_key, int* out_value) { | |
| 431 if (!ext->GetInteger(pref_key, out_value)) | |
| 432 return false; | |
| 433 | |
| 434 return out_value != NULL; | |
| 435 } | |
| 436 | |
| 437 bool ExtensionPrefs::ReadExtensionPrefInteger( | 406 bool ExtensionPrefs::ReadExtensionPrefInteger( |
| 438 const std::string& extension_id, const std::string& pref_key, | 407 const std::string& extension_id, const std::string& pref_key, |
| 439 int* out_value) const { | 408 int* out_value) const { |
| 440 const DictionaryValue* ext = GetExtensionPref(extension_id); | 409 const DictionaryValue* ext = GetExtensionPref(extension_id); |
| 441 if (!ext) { | 410 if (!ext) { |
| 442 // No such extension yet. | 411 // No such extension yet. |
| 443 return false; | 412 return false; |
| 444 } | 413 } |
| 445 return ReadIntegerFromPref(ext, pref_key, out_value); | 414 return ReadIntegerFromPref(ext, pref_key, out_value); |
| 446 } | 415 } |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 551 } | 520 } |
| 552 | 521 |
| 553 // Set the scriptable host permissions. | 522 // Set the scriptable host permissions. |
| 554 if (!new_value->scriptable_hosts().is_empty()) { | 523 if (!new_value->scriptable_hosts().is_empty()) { |
| 555 SetExtensionPrefURLPatternSet(extension_id, | 524 SetExtensionPrefURLPatternSet(extension_id, |
| 556 JoinPrefs(pref_key, kPrefScriptableHosts), | 525 JoinPrefs(pref_key, kPrefScriptableHosts), |
| 557 new_value->scriptable_hosts()); | 526 new_value->scriptable_hosts()); |
| 558 } | 527 } |
| 559 } | 528 } |
| 560 | 529 |
| 561 // static | |
| 562 bool ExtensionPrefs::IsBlacklistBitSet(const DictionaryValue* ext) { | |
| 563 return ReadBooleanFromPref(ext, kPrefBlacklist); | |
| 564 } | |
| 565 | |
| 566 bool ExtensionPrefs::IsExtensionBlacklisted(const std::string& extension_id) { | |
| 567 return ReadExtensionPrefBoolean(extension_id, kPrefBlacklist); | |
| 568 } | |
| 569 | |
| 570 bool ExtensionPrefs::IsExtensionOrphaned(const std::string& extension_id) { | 530 bool ExtensionPrefs::IsExtensionOrphaned(const std::string& extension_id) { |
| 571 // TODO(miket): we believe that this test will hinge on the number of | 531 // TODO(miket): we believe that this test will hinge on the number of |
| 572 // consecutive times that an update check has returned a certain response | 532 // consecutive times that an update check has returned a certain response |
| 573 // versus a success response. For now nobody is orphaned. | 533 // versus a success response. For now nobody is orphaned. |
| 574 return false; | 534 return false; |
| 575 } | 535 } |
| 576 | 536 |
| 577 bool ExtensionPrefs::IsExternalExtensionAcknowledged( | 537 bool ExtensionPrefs::IsExternalExtensionAcknowledged( |
| 578 const std::string& extension_id) { | 538 const std::string& extension_id) { |
| 579 return ReadExtensionPrefBoolean(extension_id, kPrefExternalAcknowledged); | 539 return ReadExtensionPrefBoolean(extension_id, kPrefExternalAcknowledged); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 653 #ifdef NDEBUG | 613 #ifdef NDEBUG |
| 654 NOTREACHED(); | 614 NOTREACHED(); |
| 655 return std::string(); | 615 return std::string(); |
| 656 #else | 616 #else |
| 657 return "admin policy black/white/forcelist, via the ExtensionPrefs"; | 617 return "admin policy black/white/forcelist, via the ExtensionPrefs"; |
| 658 #endif | 618 #endif |
| 659 } | 619 } |
| 660 | 620 |
| 661 bool ExtensionPrefs::UserMayLoad(const Extension* extension, | 621 bool ExtensionPrefs::UserMayLoad(const Extension* extension, |
| 662 string16* error) const { | 622 string16* error) const { |
| 623 const DictionaryValue* ext_prefs = GetExtensionPref(extension->id()); | |
| 624 bool is_google_blacklisted = ext_prefs && IsBlacklistBitSet(ext_prefs); | |
| 663 | 625 |
| 664 const base::ListValue* blacklist = | 626 const base::ListValue* blacklist = |
| 665 prefs_->GetList(prefs::kExtensionInstallDenyList); | 627 prefs_->GetList(prefs::kExtensionInstallDenyList); |
| 666 const base::ListValue* whitelist = | 628 const base::ListValue* whitelist = |
| 667 prefs_->GetList(prefs::kExtensionInstallAllowList); | 629 prefs_->GetList(prefs::kExtensionInstallAllowList); |
| 668 return admin_policy::UserMayLoad(blacklist, whitelist, extension, | 630 const base::ListValue* forcelist = |
| 669 error); | 631 prefs_->GetList(prefs::kExtensionInstallForceList); |
| 632 return admin_policy::UserMayLoad(is_google_blacklisted, blacklist, whitelist, | |
| 633 forcelist, extension, error); | |
| 670 } | 634 } |
| 671 | 635 |
| 672 bool ExtensionPrefs::UserMayModifySettings(const Extension* extension, | 636 bool ExtensionPrefs::UserMayModifySettings(const Extension* extension, |
| 673 string16* error) const { | 637 string16* error) const { |
| 674 return admin_policy::UserMayModifySettings(extension, error); | 638 return admin_policy::UserMayModifySettings(extension, error); |
| 675 } | 639 } |
| 676 | 640 |
| 677 bool ExtensionPrefs::MustRemainEnabled(const Extension* extension, | 641 bool ExtensionPrefs::MustRemainEnabled(const Extension* extension, |
| 678 string16* error) const { | 642 string16* error) const { |
| 679 return admin_policy::MustRemainEnabled(extension, error); | 643 return admin_policy::MustRemainEnabled(extension, error); |
| (...skipping 841 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1521 const DictionaryValue* ExtensionPrefs::GetExtensionPref( | 1485 const DictionaryValue* ExtensionPrefs::GetExtensionPref( |
| 1522 const std::string& extension_id) const { | 1486 const std::string& extension_id) const { |
| 1523 const DictionaryValue* dict = prefs_->GetDictionary(kExtensionsPref); | 1487 const DictionaryValue* dict = prefs_->GetDictionary(kExtensionsPref); |
| 1524 if (!dict) | 1488 if (!dict) |
| 1525 return NULL; | 1489 return NULL; |
| 1526 const DictionaryValue* extension = NULL; | 1490 const DictionaryValue* extension = NULL; |
| 1527 dict->GetDictionary(extension_id, &extension); | 1491 dict->GetDictionary(extension_id, &extension); |
| 1528 return extension; | 1492 return extension; |
| 1529 } | 1493 } |
| 1530 | 1494 |
| 1531 // Helper function for GetInstalledExtensionsInfo. | 1495 ExtensionInfo* ExtensionPrefs::GetInstalledExtensionInfo( |
| 1532 static ExtensionInfo* GetInstalledExtensionInfoImpl( | 1496 const std::string& extension_id) const { |
| 1533 DictionaryValue* extension_data, | 1497 const DictionaryValue* ext; |
| 1534 DictionaryValue::key_iterator extension_id) { | 1498 const DictionaryValue* extensions = prefs_->GetDictionary(kExtensionsPref); |
| 1535 DictionaryValue* ext; | 1499 if (!extensions || |
| 1536 if (!extension_data->GetDictionaryWithoutPathExpansion(*extension_id, &ext)) { | 1500 !extensions->GetDictionaryWithoutPathExpansion(extension_id, &ext)) |
| 1537 LOG(WARNING) << "Invalid pref for extension " << *extension_id; | |
| 1538 NOTREACHED(); | |
| 1539 return NULL; | 1501 return NULL; |
| 1540 } | 1502 if (IsBlacklistBitSet(ext)) |
| 1541 if (ext->HasKey(kPrefBlacklist)) { | |
| 1542 bool is_blacklisted = false; | |
| 1543 if (!ext->GetBoolean(kPrefBlacklist, &is_blacklisted)) { | |
| 1544 NOTREACHED() << "Invalid blacklist pref:" << *extension_id; | |
| 1545 return NULL; | 1503 return NULL; |
| 1546 } | |
| 1547 if (is_blacklisted) { | |
| 1548 return NULL; | |
| 1549 } | |
| 1550 } | |
| 1551 int state_value; | 1504 int state_value; |
| 1552 if (!ext->GetInteger(kPrefState, &state_value)) { | 1505 if (!ext->GetInteger(kPrefState, &state_value)) { |
| 1553 // This can legitimately happen if we store preferences for component | 1506 // This can legitimately happen if we store preferences for component |
| 1554 // extensions. | 1507 // extensions. |
| 1555 return NULL; | 1508 return NULL; |
| 1556 } | 1509 } |
| 1557 if (state_value == Extension::EXTERNAL_EXTENSION_UNINSTALLED) { | 1510 if (state_value == Extension::EXTERNAL_EXTENSION_UNINSTALLED) { |
| 1558 LOG(WARNING) << "External extension with id " << *extension_id | 1511 LOG(WARNING) << "External extension with id " << extension_id |
| 1559 << " has been uninstalled by the user"; | 1512 << " has been uninstalled by the user"; |
| 1560 return NULL; | 1513 return NULL; |
| 1561 } | 1514 } |
| 1562 FilePath::StringType path; | 1515 FilePath::StringType path; |
| 1563 if (!ext->GetString(kPrefPath, &path)) { | 1516 int location_value; |
| 1517 if (!ext->GetInteger(kPrefLocation, &location_value)) | |
| 1564 return NULL; | 1518 return NULL; |
| 1565 } | 1519 |
| 1566 int location_value; | 1520 if (!ext->GetString(kPrefPath, &path)) |
| 1567 if (!ext->GetInteger(kPrefLocation, &location_value)) { | |
| 1568 return NULL; | 1521 return NULL; |
| 1522 | |
| 1523 // Make path absolute. Unpacked extensions will already have absolute paths, | |
| 1524 // otherwise make it so. | |
| 1525 if (location_value != Extension::LOAD) { | |
| 1526 DCHECK(location_value == Extension::COMPONENT || | |
| 1527 !FilePath(path).IsAbsolute()); | |
| 1528 path = install_directory_.Append(path).value(); | |
| 1569 } | 1529 } |
| 1570 | 1530 |
| 1571 // Only the following extension types can be installed permanently in the | 1531 // Only the following extension types can be installed permanently in the |
| 1572 // preferences. | 1532 // preferences. |
| 1573 Extension::Location location = | 1533 Extension::Location location = |
| 1574 static_cast<Extension::Location>(location_value); | 1534 static_cast<Extension::Location>(location_value); |
| 1575 if (location != Extension::INTERNAL && | 1535 if (location != Extension::INTERNAL && |
| 1576 location != Extension::LOAD && | 1536 location != Extension::LOAD && |
| 1577 !Extension::IsExternalLocation(location)) { | 1537 !Extension::IsExternalLocation(location)) { |
| 1578 NOTREACHED(); | 1538 NOTREACHED(); |
| 1579 return NULL; | 1539 return NULL; |
| 1580 } | 1540 } |
| 1581 | 1541 |
| 1582 DictionaryValue* manifest = NULL; | 1542 const DictionaryValue* manifest = NULL; |
| 1583 if (location != Extension::LOAD && | 1543 if (location != Extension::LOAD && |
| 1584 !ext->GetDictionary(kPrefManifest, &manifest)) { | 1544 !ext->GetDictionary(kPrefManifest, &manifest)) { |
| 1585 LOG(WARNING) << "Missing manifest for extension " << *extension_id; | 1545 LOG(WARNING) << "Missing manifest for extension " << extension_id; |
| 1586 // Just a warning for now. | 1546 // Just a warning for now. |
| 1587 } | 1547 } |
| 1588 | 1548 |
| 1589 return new ExtensionInfo(manifest, *extension_id, FilePath(path), location); | 1549 return new ExtensionInfo(manifest, extension_id, FilePath(path), location); |
| 1590 } | 1550 } |
| 1591 | 1551 |
| 1592 ExtensionPrefs::ExtensionsInfo* ExtensionPrefs::GetInstalledExtensionsInfo() { | 1552 ExtensionPrefs::ExtensionsInfo* ExtensionPrefs::GetInstalledExtensionsInfo( |
| 1593 scoped_ptr<DictionaryValue> extension_data(CopyCurrentExtensions()); | 1553 ) const { |
| 1594 | |
| 1595 ExtensionsInfo* extensions_info = new ExtensionsInfo; | 1554 ExtensionsInfo* extensions_info = new ExtensionsInfo; |
| 1596 | 1555 |
| 1597 for (DictionaryValue::key_iterator extension_id( | 1556 const DictionaryValue* extensions = prefs_->GetDictionary(kExtensionsPref); |
| 1598 extension_data->begin_keys()); | 1557 for (DictionaryValue::key_iterator extension_id = extensions->begin_keys(); |
| 1599 extension_id != extension_data->end_keys(); ++extension_id) { | 1558 extension_id != extensions->end_keys(); ++extension_id) { |
| 1600 if (!Extension::IdIsValid(*extension_id)) | 1559 if (!Extension::IdIsValid(*extension_id)) |
| 1601 continue; | 1560 continue; |
| 1602 | 1561 |
| 1603 ExtensionInfo* info = GetInstalledExtensionInfoImpl(extension_data.get(), | 1562 ExtensionInfo* info = GetInstalledExtensionInfo(*extension_id); |
| 1604 extension_id); | |
| 1605 if (info) | 1563 if (info) |
| 1606 extensions_info->push_back(linked_ptr<ExtensionInfo>(info)); | 1564 extensions_info->push_back(linked_ptr<ExtensionInfo>(info)); |
| 1607 } | 1565 } |
| 1608 | 1566 |
| 1609 return extensions_info; | 1567 return extensions_info; |
| 1610 } | 1568 } |
| 1611 | 1569 |
| 1612 ExtensionInfo* ExtensionPrefs::GetInstalledExtensionInfo( | |
| 1613 const std::string& extension_id) { | |
| 1614 scoped_ptr<DictionaryValue> extension_data(CopyCurrentExtensions()); | |
| 1615 | |
| 1616 for (DictionaryValue::key_iterator extension_iter( | |
| 1617 extension_data->begin_keys()); | |
| 1618 extension_iter != extension_data->end_keys(); ++extension_iter) { | |
| 1619 if (*extension_iter == extension_id) { | |
| 1620 return GetInstalledExtensionInfoImpl(extension_data.get(), | |
| 1621 extension_iter); | |
| 1622 } | |
| 1623 } | |
| 1624 | |
| 1625 return NULL; | |
| 1626 } | |
| 1627 | |
| 1628 void ExtensionPrefs::SetIdleInstallInfo(const std::string& extension_id, | 1570 void ExtensionPrefs::SetIdleInstallInfo(const std::string& extension_id, |
| 1629 const FilePath& crx_path, | 1571 const FilePath& crx_path, |
| 1630 const std::string& version, | 1572 const std::string& version, |
| 1631 const base::Time& fetch_time) { | 1573 const base::Time& fetch_time) { |
| 1632 DictionaryValue* info = new DictionaryValue(); | 1574 DictionaryValue* info = new DictionaryValue(); |
| 1633 info->SetString(kIdleInstallInfoCrxPath, crx_path.value()); | 1575 info->SetString(kIdleInstallInfoCrxPath, crx_path.value()); |
| 1634 info->SetString(kIdleInstallInfoVersion, version); | 1576 info->SetString(kIdleInstallInfoVersion, version); |
| 1635 info->SetString(kIdleInstallInfoFetchTime, | 1577 info->SetString(kIdleInstallInfoFetchTime, |
| 1636 base::Int64ToString(fetch_time.ToInternalValue())); | 1578 base::Int64ToString(fetch_time.ToInternalValue())); |
| 1637 UpdateExtensionPref(extension_id, kIdleInstallInfo, info); | 1579 UpdateExtensionPref(extension_id, kIdleInstallInfo, info); |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1809 scoped_ptr<ExtensionsInfo> extensions_info(GetInstalledExtensionsInfo()); | 1751 scoped_ptr<ExtensionsInfo> extensions_info(GetInstalledExtensionsInfo()); |
| 1810 | 1752 |
| 1811 for (size_t i = 0; i < extensions_info->size(); ++i) { | 1753 for (size_t i = 0; i < extensions_info->size(); ++i) { |
| 1812 ExtensionInfo* info = extensions_info->at(i).get(); | 1754 ExtensionInfo* info = extensions_info->at(i).get(); |
| 1813 out->push_back(info->extension_id); | 1755 out->push_back(info->extension_id); |
| 1814 } | 1756 } |
| 1815 } | 1757 } |
| 1816 | 1758 |
| 1817 // static | 1759 // static |
| 1818 ExtensionPrefs::ExtensionIdSet ExtensionPrefs::GetExtensionsFrom( | 1760 ExtensionPrefs::ExtensionIdSet ExtensionPrefs::GetExtensionsFrom( |
| 1819 const base::DictionaryValue* extension_prefs) { | 1761 const PrefService* pref_service) { |
| 1820 ExtensionIdSet result; | 1762 ExtensionIdSet result; |
| 1763 | |
| 1764 const base::DictionaryValue* extension_prefs; | |
| 1765 const base::Value* extension_prefs_value = | |
| 1766 pref_service->GetUserPrefValue(kExtensionsPref); | |
| 1767 if (!extension_prefs_value || | |
| 1768 !extension_prefs_value->GetAsDictionary(&extension_prefs)) { | |
| 1769 return result; // Empty set | |
| 1770 } | |
| 1771 | |
| 1821 for (base::DictionaryValue::key_iterator it = extension_prefs->begin_keys(); | 1772 for (base::DictionaryValue::key_iterator it = extension_prefs->begin_keys(); |
| 1822 it != extension_prefs->end_keys(); ++it) { | 1773 it != extension_prefs->end_keys(); ++it) |
| 1823 const DictionaryValue* ext; | |
| 1824 if (!extension_prefs->GetDictionaryWithoutPathExpansion(*it, &ext)) { | |
| 1825 NOTREACHED() << "Invalid pref for extension " << *it; | |
| 1826 continue; | |
| 1827 } | |
| 1828 if (!IsBlacklistBitSet(ext)) | |
| 1829 result.push_back(*it); | 1774 result.push_back(*it); |
|
qfel
2012/08/14 13:03:14
Now it returns Google-blacklisted extensions too.
Mattias Nissler (ping if slow)
2012/08/14 14:12:31
Btw, indentation is wrong here. Please fix.
Mattias Nissler (ping if slow)
2012/08/14 14:12:31
I'm not so sure about this. Isn't the blacklist bi
Matt Perry
2012/08/15 21:17:07
I'm not an expert here, but judging by the use cas
| |
| 1830 } | |
| 1831 return result; | 1775 return result; |
| 1832 } | 1776 } |
| 1833 | 1777 |
| 1834 void ExtensionPrefs::FixMissingPrefs(const ExtensionIdSet& extension_ids) { | 1778 void ExtensionPrefs::FixMissingPrefs(const ExtensionIdSet& extension_ids) { |
| 1835 // Fix old entries that did not get an installation time entry when they | 1779 // Fix old entries that did not get an installation time entry when they |
| 1836 // were installed or don't have a preferences field. | 1780 // were installed or don't have a preferences field. |
| 1837 for (ExtensionIdSet::const_iterator ext_id = extension_ids.begin(); | 1781 for (ExtensionIdSet::const_iterator ext_id = extension_ids.begin(); |
| 1838 ext_id != extension_ids.end(); ++ext_id) { | 1782 ext_id != extension_ids.end(); ++ext_id) { |
| 1839 if (GetInstallTime(*ext_id) == base::Time()) { | 1783 if (GetInstallTime(*ext_id) == base::Time()) { |
| 1840 LOG(INFO) << "Could not parse installation time of extension " | 1784 LOG(INFO) << "Could not parse installation time of extension " |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2098 const ExtensionIdSet& strings) { | 2042 const ExtensionIdSet& strings) { |
| 2099 ListPrefUpdate update(prefs_, pref); | 2043 ListPrefUpdate update(prefs_, pref); |
| 2100 ListValue* list_of_values = update.Get(); | 2044 ListValue* list_of_values = update.Get(); |
| 2101 list_of_values->Clear(); | 2045 list_of_values->Clear(); |
| 2102 for (ExtensionIdSet::const_iterator iter = strings.begin(); | 2046 for (ExtensionIdSet::const_iterator iter = strings.begin(); |
| 2103 iter != strings.end(); ++iter) | 2047 iter != strings.end(); ++iter) |
| 2104 list_of_values->Append(new StringValue(*iter)); | 2048 list_of_values->Append(new StringValue(*iter)); |
| 2105 } | 2049 } |
| 2106 | 2050 |
| 2107 } // namespace extensions | 2051 } // namespace extensions |
| OLD | NEW |