| 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/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/prefs/pref_notifier.h" | 8 #include "base/prefs/pref_notifier.h" |
| 9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 | 36 |
| 37 namespace extensions { | 37 namespace extensions { |
| 38 | 38 |
| 39 namespace { | 39 namespace { |
| 40 | 40 |
| 41 // Additional preferences keys | 41 // Additional preferences keys |
| 42 | 42 |
| 43 // Whether this extension was running when chrome last shutdown. | 43 // Whether this extension was running when chrome last shutdown. |
| 44 const char kPrefRunning[] = "running"; | 44 const char kPrefRunning[] = "running"; |
| 45 | 45 |
| 46 // Where an extension was installed from. (see Extension::Location) | 46 // Where an extension was installed from. (see Manifest::Location) |
| 47 const char kPrefLocation[] = "location"; | 47 const char kPrefLocation[] = "location"; |
| 48 | 48 |
| 49 // Enabled, disabled, killed, etc. (see Extension::State) | 49 // Enabled, disabled, killed, etc. (see Extension::State) |
| 50 const char kPrefState[] = "state"; | 50 const char kPrefState[] = "state"; |
| 51 | 51 |
| 52 // The path to the current version's manifest file. | 52 // The path to the current version's manifest file. |
| 53 const char kPrefPath[] = "path"; | 53 const char kPrefPath[] = "path"; |
| 54 | 54 |
| 55 // The dictionary containing the extension's manifest. | 55 // The dictionary containing the extension's manifest. |
| 56 const char kPrefManifest[] = "manifest"; | 56 const char kPrefManifest[] = "manifest"; |
| (...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 | 423 |
| 424 // Collect all extensions ids with absolute paths in |absolute_keys|. | 424 // Collect all extensions ids with absolute paths in |absolute_keys|. |
| 425 std::set<std::string> absolute_keys; | 425 std::set<std::string> absolute_keys; |
| 426 for (DictionaryValue::key_iterator i = dict->begin_keys(); | 426 for (DictionaryValue::key_iterator i = dict->begin_keys(); |
| 427 i != dict->end_keys(); ++i) { | 427 i != dict->end_keys(); ++i) { |
| 428 const DictionaryValue* extension_dict = NULL; | 428 const DictionaryValue* extension_dict = NULL; |
| 429 if (!dict->GetDictionaryWithoutPathExpansion(*i, &extension_dict)) | 429 if (!dict->GetDictionaryWithoutPathExpansion(*i, &extension_dict)) |
| 430 continue; | 430 continue; |
| 431 int location_value; | 431 int location_value; |
| 432 if (extension_dict->GetInteger(kPrefLocation, &location_value) && | 432 if (extension_dict->GetInteger(kPrefLocation, &location_value) && |
| 433 location_value == Extension::LOAD) { | 433 location_value == Manifest::LOAD) { |
| 434 // Unpacked extensions can have absolute paths. | 434 // Unpacked extensions can have absolute paths. |
| 435 continue; | 435 continue; |
| 436 } | 436 } |
| 437 FilePath::StringType path_string; | 437 FilePath::StringType path_string; |
| 438 if (!extension_dict->GetString(kPrefPath, &path_string)) | 438 if (!extension_dict->GetString(kPrefPath, &path_string)) |
| 439 continue; | 439 continue; |
| 440 FilePath path(path_string); | 440 FilePath path(path_string); |
| 441 if (path.IsAbsolute()) | 441 if (path.IsAbsolute()) |
| 442 absolute_keys.insert(*i); | 442 absolute_keys.insert(*i); |
| 443 } | 443 } |
| (...skipping 994 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1438 DictionaryValue* extension_dict = update.Get(); | 1438 DictionaryValue* extension_dict = update.Get(); |
| 1439 const base::Time install_time = time_provider_->GetCurrentTime(); | 1439 const base::Time install_time = time_provider_->GetCurrentTime(); |
| 1440 PopulateExtensionInfoPrefs(extension, install_time, initial_state, | 1440 PopulateExtensionInfoPrefs(extension, install_time, initial_state, |
| 1441 extension_dict); | 1441 extension_dict); |
| 1442 FinishExtensionInfoPrefs(extension->id(), install_time, | 1442 FinishExtensionInfoPrefs(extension->id(), install_time, |
| 1443 extension->RequiresSortOrdinal(), | 1443 extension->RequiresSortOrdinal(), |
| 1444 page_ordinal, extension_dict); | 1444 page_ordinal, extension_dict); |
| 1445 } | 1445 } |
| 1446 | 1446 |
| 1447 void ExtensionPrefs::OnExtensionUninstalled(const std::string& extension_id, | 1447 void ExtensionPrefs::OnExtensionUninstalled(const std::string& extension_id, |
| 1448 const Extension::Location& location, | 1448 const Manifest::Location& location, |
| 1449 bool external_uninstall) { | 1449 bool external_uninstall) { |
| 1450 extension_sorting_->ClearOrdinals(extension_id); | 1450 extension_sorting_->ClearOrdinals(extension_id); |
| 1451 | 1451 |
| 1452 // For external extensions, we save a preference reminding ourself not to try | 1452 // For external extensions, we save a preference reminding ourself not to try |
| 1453 // and install the extension anymore (except when |external_uninstall| is | 1453 // and install the extension anymore (except when |external_uninstall| is |
| 1454 // true, which signifies that the registry key was deleted or the pref file | 1454 // true, which signifies that the registry key was deleted or the pref file |
| 1455 // no longer lists the extension). | 1455 // no longer lists the extension). |
| 1456 if (!external_uninstall && Extension::IsExternalLocation(location)) { | 1456 if (!external_uninstall && Manifest::IsExternalLocation(location)) { |
| 1457 UpdateExtensionPref(extension_id, kPrefState, | 1457 UpdateExtensionPref(extension_id, kPrefState, |
| 1458 Value::CreateIntegerValue( | 1458 Value::CreateIntegerValue( |
| 1459 Extension::EXTERNAL_EXTENSION_UNINSTALLED)); | 1459 Extension::EXTERNAL_EXTENSION_UNINSTALLED)); |
| 1460 extension_pref_value_map_->SetExtensionState(extension_id, false); | 1460 extension_pref_value_map_->SetExtensionState(extension_id, false); |
| 1461 content_settings_store_->SetExtensionState(extension_id, false); | 1461 content_settings_store_->SetExtensionState(extension_id, false); |
| 1462 } else { | 1462 } else { |
| 1463 DeleteExtensionPrefs(extension_id); | 1463 DeleteExtensionPrefs(extension_id); |
| 1464 } | 1464 } |
| 1465 } | 1465 } |
| 1466 | 1466 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1517 std::string version; | 1517 std::string version; |
| 1518 if (!extension->GetString(kPrefVersion, &version)) { | 1518 if (!extension->GetString(kPrefVersion, &version)) { |
| 1519 LOG(ERROR) << "Bad or missing pref 'version' for extension '" | 1519 LOG(ERROR) << "Bad or missing pref 'version' for extension '" |
| 1520 << extension_id << "'"; | 1520 << extension_id << "'"; |
| 1521 } | 1521 } |
| 1522 | 1522 |
| 1523 return version; | 1523 return version; |
| 1524 } | 1524 } |
| 1525 | 1525 |
| 1526 void ExtensionPrefs::UpdateManifest(const Extension* extension) { | 1526 void ExtensionPrefs::UpdateManifest(const Extension* extension) { |
| 1527 if (extension->location() != Extension::LOAD) { | 1527 if (extension->location() != Manifest::LOAD) { |
| 1528 const DictionaryValue* extension_dict = GetExtensionPref(extension->id()); | 1528 const DictionaryValue* extension_dict = GetExtensionPref(extension->id()); |
| 1529 if (!extension_dict) | 1529 if (!extension_dict) |
| 1530 return; | 1530 return; |
| 1531 const DictionaryValue* old_manifest = NULL; | 1531 const DictionaryValue* old_manifest = NULL; |
| 1532 bool update_required = | 1532 bool update_required = |
| 1533 !extension_dict->GetDictionary(kPrefManifest, &old_manifest) || | 1533 !extension_dict->GetDictionary(kPrefManifest, &old_manifest) || |
| 1534 !extension->manifest()->value()->Equals(old_manifest); | 1534 !extension->manifest()->value()->Equals(old_manifest); |
| 1535 if (update_required) { | 1535 if (update_required) { |
| 1536 UpdateExtensionPref(extension->id(), kPrefManifest, | 1536 UpdateExtensionPref(extension->id(), kPrefManifest, |
| 1537 extension->manifest()->value()->DeepCopy()); | 1537 extension->manifest()->value()->DeepCopy()); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1605 FilePath::StringType path; | 1605 FilePath::StringType path; |
| 1606 int location_value; | 1606 int location_value; |
| 1607 if (!ext->GetInteger(kPrefLocation, &location_value)) | 1607 if (!ext->GetInteger(kPrefLocation, &location_value)) |
| 1608 return scoped_ptr<ExtensionInfo>(); | 1608 return scoped_ptr<ExtensionInfo>(); |
| 1609 | 1609 |
| 1610 if (!ext->GetString(kPrefPath, &path)) | 1610 if (!ext->GetString(kPrefPath, &path)) |
| 1611 return scoped_ptr<ExtensionInfo>(); | 1611 return scoped_ptr<ExtensionInfo>(); |
| 1612 | 1612 |
| 1613 // Make path absolute. Unpacked extensions will already have absolute paths, | 1613 // Make path absolute. Unpacked extensions will already have absolute paths, |
| 1614 // otherwise make it so. | 1614 // otherwise make it so. |
| 1615 if (location_value != Extension::LOAD) { | 1615 if (location_value != Manifest::LOAD) { |
| 1616 DCHECK(location_value == Extension::COMPONENT || | 1616 DCHECK(location_value == Manifest::COMPONENT || |
| 1617 !FilePath(path).IsAbsolute()); | 1617 !FilePath(path).IsAbsolute()); |
| 1618 path = install_directory_.Append(path).value(); | 1618 path = install_directory_.Append(path).value(); |
| 1619 } | 1619 } |
| 1620 | 1620 |
| 1621 // Only the following extension types can be installed permanently in the | 1621 // Only the following extension types can be installed permanently in the |
| 1622 // preferences. | 1622 // preferences. |
| 1623 Extension::Location location = | 1623 Manifest::Location location = |
| 1624 static_cast<Extension::Location>(location_value); | 1624 static_cast<Manifest::Location>(location_value); |
| 1625 if (location != Extension::INTERNAL && | 1625 if (location != Manifest::INTERNAL && |
| 1626 location != Extension::LOAD && | 1626 location != Manifest::LOAD && |
| 1627 !Extension::IsExternalLocation(location)) { | 1627 !Manifest::IsExternalLocation(location)) { |
| 1628 NOTREACHED(); | 1628 NOTREACHED(); |
| 1629 return scoped_ptr<ExtensionInfo>(); | 1629 return scoped_ptr<ExtensionInfo>(); |
| 1630 } | 1630 } |
| 1631 | 1631 |
| 1632 const DictionaryValue* manifest = NULL; | 1632 const DictionaryValue* manifest = NULL; |
| 1633 if (location != Extension::LOAD && | 1633 if (location != Manifest::LOAD && |
| 1634 !ext->GetDictionary(kPrefManifest, &manifest)) { | 1634 !ext->GetDictionary(kPrefManifest, &manifest)) { |
| 1635 LOG(WARNING) << "Missing manifest for extension " << extension_id; | 1635 LOG(WARNING) << "Missing manifest for extension " << extension_id; |
| 1636 // Just a warning for now. | 1636 // Just a warning for now. |
| 1637 } | 1637 } |
| 1638 | 1638 |
| 1639 return scoped_ptr<ExtensionInfo>( | 1639 return scoped_ptr<ExtensionInfo>( |
| 1640 new ExtensionInfo(manifest, extension_id, FilePath(path), location)); | 1640 new ExtensionInfo(manifest, extension_id, FilePath(path), location)); |
| 1641 } | 1641 } |
| 1642 | 1642 |
| 1643 scoped_ptr<ExtensionPrefs::ExtensionsInfo> | 1643 scoped_ptr<ExtensionPrefs::ExtensionsInfo> |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1737 FilePath::StringType path; | 1737 FilePath::StringType path; |
| 1738 int location_value; | 1738 int location_value; |
| 1739 if (!ext->GetInteger(kPrefLocation, &location_value)) | 1739 if (!ext->GetInteger(kPrefLocation, &location_value)) |
| 1740 return scoped_ptr<ExtensionInfo>(); | 1740 return scoped_ptr<ExtensionInfo>(); |
| 1741 | 1741 |
| 1742 if (!ext->GetString(kPrefPath, &path)) | 1742 if (!ext->GetString(kPrefPath, &path)) |
| 1743 return scoped_ptr<ExtensionInfo>(); | 1743 return scoped_ptr<ExtensionInfo>(); |
| 1744 | 1744 |
| 1745 // Make path absolute. Unpacked extensions will already have absolute paths, | 1745 // Make path absolute. Unpacked extensions will already have absolute paths, |
| 1746 // otherwise make it so. | 1746 // otherwise make it so. |
| 1747 if (location_value != Extension::LOAD) { | 1747 if (location_value != Manifest::LOAD) { |
| 1748 DCHECK(location_value == Extension::COMPONENT || | 1748 DCHECK(location_value == Manifest::COMPONENT || |
| 1749 !FilePath(path).IsAbsolute()); | 1749 !FilePath(path).IsAbsolute()); |
| 1750 path = install_directory_.Append(path).value(); | 1750 path = install_directory_.Append(path).value(); |
| 1751 } | 1751 } |
| 1752 | 1752 |
| 1753 // Only the following extension types can be installed permanently in the | 1753 // Only the following extension types can be installed permanently in the |
| 1754 // preferences. | 1754 // preferences. |
| 1755 Extension::Location location = | 1755 Manifest::Location location = |
| 1756 static_cast<Extension::Location>(location_value); | 1756 static_cast<Manifest::Location>(location_value); |
| 1757 if (location != Extension::INTERNAL && | 1757 if (location != Manifest::INTERNAL && |
| 1758 location != Extension::LOAD && | 1758 location != Manifest::LOAD && |
| 1759 !Extension::IsExternalLocation(location)) { | 1759 !Manifest::IsExternalLocation(location)) { |
| 1760 NOTREACHED(); | 1760 NOTREACHED(); |
| 1761 return scoped_ptr<ExtensionInfo>(); | 1761 return scoped_ptr<ExtensionInfo>(); |
| 1762 } | 1762 } |
| 1763 | 1763 |
| 1764 const DictionaryValue* manifest = NULL; | 1764 const DictionaryValue* manifest = NULL; |
| 1765 if (location != Extension::LOAD && | 1765 if (location != Manifest::LOAD && |
| 1766 !ext->GetDictionary(kPrefManifest, &manifest)) { | 1766 !ext->GetDictionary(kPrefManifest, &manifest)) { |
| 1767 LOG(WARNING) << "Missing manifest for extension " << extension_id; | 1767 LOG(WARNING) << "Missing manifest for extension " << extension_id; |
| 1768 // Just a warning for now. | 1768 // Just a warning for now. |
| 1769 } | 1769 } |
| 1770 | 1770 |
| 1771 return scoped_ptr<ExtensionInfo>( | 1771 return scoped_ptr<ExtensionInfo>( |
| 1772 new ExtensionInfo(manifest, extension_id, FilePath(path), location)); | 1772 new ExtensionInfo(manifest, extension_id, FilePath(path), location)); |
| 1773 } | 1773 } |
| 1774 | 1774 |
| 1775 scoped_ptr<ExtensionPrefs::ExtensionsInfo> ExtensionPrefs:: | 1775 scoped_ptr<ExtensionPrefs::ExtensionsInfo> ExtensionPrefs:: |
| (...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2310 Value::CreateBooleanValue(extension->was_installed_by_default())); | 2310 Value::CreateBooleanValue(extension->was_installed_by_default())); |
| 2311 extension_dict->Set(kPrefInstallTime, | 2311 extension_dict->Set(kPrefInstallTime, |
| 2312 Value::CreateStringValue( | 2312 Value::CreateStringValue( |
| 2313 base::Int64ToString(install_time.ToInternalValue()))); | 2313 base::Int64ToString(install_time.ToInternalValue()))); |
| 2314 | 2314 |
| 2315 FilePath::StringType path = MakePathRelative(install_directory_, | 2315 FilePath::StringType path = MakePathRelative(install_directory_, |
| 2316 extension->path()); | 2316 extension->path()); |
| 2317 extension_dict->Set(kPrefPath, Value::CreateStringValue(path)); | 2317 extension_dict->Set(kPrefPath, Value::CreateStringValue(path)); |
| 2318 // We store prefs about LOAD extensions, but don't cache their manifest | 2318 // We store prefs about LOAD extensions, but don't cache their manifest |
| 2319 // since it may change on disk. | 2319 // since it may change on disk. |
| 2320 if (extension->location() != Extension::LOAD) { | 2320 if (extension->location() != Manifest::LOAD) { |
| 2321 extension_dict->Set(kPrefManifest, | 2321 extension_dict->Set(kPrefManifest, |
| 2322 extension->manifest()->value()->DeepCopy()); | 2322 extension->manifest()->value()->DeepCopy()); |
| 2323 } | 2323 } |
| 2324 } | 2324 } |
| 2325 | 2325 |
| 2326 void ExtensionPrefs::FinishExtensionInfoPrefs( | 2326 void ExtensionPrefs::FinishExtensionInfoPrefs( |
| 2327 const std::string& extension_id, | 2327 const std::string& extension_id, |
| 2328 const base::Time install_time, | 2328 const base::Time install_time, |
| 2329 bool needs_sort_ordinal, | 2329 bool needs_sort_ordinal, |
| 2330 const syncer::StringOrdinal& suggested_page_ordinal, | 2330 const syncer::StringOrdinal& suggested_page_ordinal, |
| (...skipping 28 matching lines...) Expand all Loading... |
| 2359 is_enabled = initial_state == Extension::ENABLED; | 2359 is_enabled = initial_state == Extension::ENABLED; |
| 2360 } | 2360 } |
| 2361 | 2361 |
| 2362 extension_pref_value_map_->RegisterExtension(extension_id, install_time, | 2362 extension_pref_value_map_->RegisterExtension(extension_id, install_time, |
| 2363 is_enabled); | 2363 is_enabled); |
| 2364 content_settings_store_->RegisterExtension(extension_id, install_time, | 2364 content_settings_store_->RegisterExtension(extension_id, install_time, |
| 2365 is_enabled); | 2365 is_enabled); |
| 2366 } | 2366 } |
| 2367 | 2367 |
| 2368 } // namespace extensions | 2368 } // namespace extensions |
| OLD | NEW |