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/prefs/pref_notifier.h" | 7 #include "base/prefs/pref_notifier.h" |
8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
111 const char kActiveBit[] = "active_bit"; | 111 const char kActiveBit[] = "active_bit"; |
112 | 112 |
113 // Path for settings specific to blacklist update. | 113 // Path for settings specific to blacklist update. |
114 const char kExtensionsBlacklistUpdate[] = "extensions.blacklistupdate"; | 114 const char kExtensionsBlacklistUpdate[] = "extensions.blacklistupdate"; |
115 | 115 |
116 // Path for the delayed install info dictionary preference. The actual string | 116 // Path for the delayed install info dictionary preference. The actual string |
117 // value is a legacy artifact for when delayed installs only pertained to | 117 // value is a legacy artifact for when delayed installs only pertained to |
118 // updates that were waiting for idle. | 118 // updates that were waiting for idle. |
119 const char kDelayedInstallInfo[] = "idle_install_info"; | 119 const char kDelayedInstallInfo[] = "idle_install_info"; |
120 | 120 |
121 // Reason why the extension's install was delayed. | |
122 const char kDelayedInstallReason[] = "delay_install_reason"; | |
123 | |
121 // Path for the suggested page ordinal of a delayed extension install. | 124 // Path for the suggested page ordinal of a delayed extension install. |
122 const char kPrefSuggestedPageOrdinal[] = "suggested_page_ordinal"; | 125 const char kPrefSuggestedPageOrdinal[] = "suggested_page_ordinal"; |
123 | 126 |
124 // A preference that, if true, will allow this extension to run in incognito | 127 // A preference that, if true, will allow this extension to run in incognito |
125 // mode. | 128 // mode. |
126 const char kPrefIncognitoEnabled[] = "incognito"; | 129 const char kPrefIncognitoEnabled[] = "incognito"; |
127 | 130 |
128 // A preference to control whether an extension is allowed to inject script in | 131 // A preference to control whether an extension is allowed to inject script in |
129 // pages with file URLs. | 132 // pages with file URLs. |
130 const char kPrefAllowFileAccess[] = "newAllowFileAccess"; | 133 const char kPrefAllowFileAccess[] = "newAllowFileAccess"; |
(...skipping 1256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1387 if (info) | 1390 if (info) |
1388 extensions_info->push_back(linked_ptr<ExtensionInfo>(info.release())); | 1391 extensions_info->push_back(linked_ptr<ExtensionInfo>(info.release())); |
1389 } | 1392 } |
1390 | 1393 |
1391 return extensions_info.Pass(); | 1394 return extensions_info.Pass(); |
1392 } | 1395 } |
1393 | 1396 |
1394 void ExtensionPrefs::SetDelayedInstallInfo( | 1397 void ExtensionPrefs::SetDelayedInstallInfo( |
1395 const Extension* extension, | 1398 const Extension* extension, |
1396 Extension::State initial_state, | 1399 Extension::State initial_state, |
1400 DelayReason delay_reason, | |
1397 const syncer::StringOrdinal& page_ordinal) { | 1401 const syncer::StringOrdinal& page_ordinal) { |
1398 DictionaryValue* extension_dict = new DictionaryValue(); | 1402 DictionaryValue* extension_dict = new DictionaryValue(); |
1399 PopulateExtensionInfoPrefs(extension, time_provider_->GetCurrentTime(), | 1403 PopulateExtensionInfoPrefs(extension, time_provider_->GetCurrentTime(), |
1400 initial_state, extension_dict); | 1404 initial_state, extension_dict); |
1401 | 1405 |
1402 // Add transient data that is needed by FinishDelayedInstallInfo(), but | 1406 // Add transient data that is needed by FinishDelayedInstallInfo(), but |
1403 // should not be in the final extension prefs. All entries here should have | 1407 // should not be in the final extension prefs. All entries here should have |
1404 // a corresponding Remove() call in FinishDelayedInstallInfo(). | 1408 // a corresponding Remove() call in FinishDelayedInstallInfo(). |
1405 if (extension->RequiresSortOrdinal()) { | 1409 if (extension->RequiresSortOrdinal()) { |
1406 extension_dict->SetString( | 1410 extension_dict->SetString( |
1407 kPrefSuggestedPageOrdinal, | 1411 kPrefSuggestedPageOrdinal, |
1408 page_ordinal.IsValid() ? page_ordinal.ToInternalValue() | 1412 page_ordinal.IsValid() ? page_ordinal.ToInternalValue() |
1409 : std::string()); | 1413 : std::string()); |
1410 } | 1414 } |
1415 extension_dict->SetInteger(kDelayedInstallReason, | |
1416 static_cast<int>(delay_reason)); | |
1411 | 1417 |
1412 UpdateExtensionPref(extension->id(), kDelayedInstallInfo, extension_dict); | 1418 UpdateExtensionPref(extension->id(), kDelayedInstallInfo, extension_dict); |
1413 } | 1419 } |
1414 | 1420 |
1415 bool ExtensionPrefs::RemoveDelayedInstallInfo( | 1421 bool ExtensionPrefs::RemoveDelayedInstallInfo( |
1416 const std::string& extension_id) { | 1422 const std::string& extension_id) { |
1417 if (!GetExtensionPref(extension_id)) | 1423 if (!GetExtensionPref(extension_id)) |
1418 return false; | 1424 return false; |
1419 ScopedExtensionPrefUpdate update(prefs_, extension_id); | 1425 ScopedExtensionPrefUpdate update(prefs_, extension_id); |
1420 bool result = update->Remove(kDelayedInstallInfo, NULL); | 1426 bool result = update->Remove(kDelayedInstallInfo, NULL); |
(...skipping 15 matching lines...) Expand all Loading... | |
1436 // Also do any other data cleanup that makes sense. | 1442 // Also do any other data cleanup that makes sense. |
1437 std::string serialized_ordinal; | 1443 std::string serialized_ordinal; |
1438 syncer::StringOrdinal suggested_page_ordinal; | 1444 syncer::StringOrdinal suggested_page_ordinal; |
1439 bool needs_sort_ordinal = false; | 1445 bool needs_sort_ordinal = false; |
1440 if (pending_install_dict->GetString(kPrefSuggestedPageOrdinal, | 1446 if (pending_install_dict->GetString(kPrefSuggestedPageOrdinal, |
1441 &serialized_ordinal)) { | 1447 &serialized_ordinal)) { |
1442 suggested_page_ordinal = syncer::StringOrdinal(serialized_ordinal); | 1448 suggested_page_ordinal = syncer::StringOrdinal(serialized_ordinal); |
1443 needs_sort_ordinal = true; | 1449 needs_sort_ordinal = true; |
1444 pending_install_dict->Remove(kPrefSuggestedPageOrdinal, NULL); | 1450 pending_install_dict->Remove(kPrefSuggestedPageOrdinal, NULL); |
1445 } | 1451 } |
1452 int delay_reason; | |
1453 if (pending_install_dict->GetInteger(kDelayedInstallReason, &delay_reason)) | |
1454 pending_install_dict->Remove(kDelayedInstallReason, NULL); | |
Matt Perry
2013/06/12 00:58:29
you can call Remove without calling GetInteger fir
elijahtaylor1
2013/06/12 23:53:23
Done.
| |
1446 | 1455 |
1447 const base::Time install_time = time_provider_->GetCurrentTime(); | 1456 const base::Time install_time = time_provider_->GetCurrentTime(); |
1448 pending_install_dict->Set( | 1457 pending_install_dict->Set( |
1449 kPrefInstallTime, | 1458 kPrefInstallTime, |
1450 Value::CreateStringValue( | 1459 Value::CreateStringValue( |
1451 base::Int64ToString(install_time.ToInternalValue()))); | 1460 base::Int64ToString(install_time.ToInternalValue()))); |
1452 | 1461 |
1453 // Commit the delayed install data. | 1462 // Commit the delayed install data. |
1454 extension_dict->MergeDictionary(pending_install_dict); | 1463 extension_dict->MergeDictionary(pending_install_dict); |
1455 FinishExtensionInfoPrefs(extension_id, install_time, needs_sort_ordinal, | 1464 FinishExtensionInfoPrefs(extension_id, install_time, needs_sort_ordinal, |
1456 suggested_page_ordinal, extension_dict); | 1465 suggested_page_ordinal, extension_dict); |
1457 return true; | 1466 return true; |
1458 } | 1467 } |
1459 | 1468 |
1460 scoped_ptr<ExtensionInfo> ExtensionPrefs::GetDelayedInstallInfo( | 1469 scoped_ptr<ExtensionInfo> ExtensionPrefs::GetDelayedInstallInfo( |
1461 const std::string& extension_id) const { | 1470 const std::string& extension_id) const { |
1462 const DictionaryValue* extension_prefs = | 1471 const DictionaryValue* extension_prefs = |
1463 GetExtensionPref(extension_id); | 1472 GetExtensionPref(extension_id); |
1464 if (!extension_prefs) | 1473 if (!extension_prefs) |
1465 return scoped_ptr<ExtensionInfo>(); | 1474 return scoped_ptr<ExtensionInfo>(); |
1466 | 1475 |
1467 const DictionaryValue* ext = NULL; | 1476 const DictionaryValue* ext = NULL; |
1468 if (!extension_prefs->GetDictionary(kDelayedInstallInfo, &ext)) | 1477 if (!extension_prefs->GetDictionary(kDelayedInstallInfo, &ext)) |
1469 return scoped_ptr<ExtensionInfo>(); | 1478 return scoped_ptr<ExtensionInfo>(); |
1470 | 1479 |
1471 return GetInstalledInfoHelper(extension_id, ext); | 1480 return GetInstalledInfoHelper(extension_id, ext); |
1472 } | 1481 } |
1473 | 1482 |
1483 ExtensionPrefs::DelayReason ExtensionPrefs::GetDelayedInstallReason( | |
1484 const std::string& extension_id) const { | |
1485 const DictionaryValue* extension_prefs = | |
1486 GetExtensionPref(extension_id); | |
1487 if (!extension_prefs) | |
1488 return DELAY_REASON_NONE; | |
1489 | |
1490 const DictionaryValue* ext = NULL; | |
1491 if (!extension_prefs->GetDictionary(kDelayedInstallInfo, &ext)) | |
1492 return DELAY_REASON_NONE; | |
1493 | |
1494 int delay_reason; | |
1495 if (!ext->GetInteger(kDelayedInstallReason, &delay_reason)) | |
1496 return DELAY_REASON_NONE; | |
1497 | |
1498 return static_cast<DelayReason>(delay_reason); | |
1499 } | |
1500 | |
1474 scoped_ptr<ExtensionPrefs::ExtensionsInfo> ExtensionPrefs:: | 1501 scoped_ptr<ExtensionPrefs::ExtensionsInfo> ExtensionPrefs:: |
1475 GetAllDelayedInstallInfo() const { | 1502 GetAllDelayedInstallInfo() const { |
1476 scoped_ptr<ExtensionsInfo> extensions_info(new ExtensionsInfo); | 1503 scoped_ptr<ExtensionsInfo> extensions_info(new ExtensionsInfo); |
1477 | 1504 |
1478 const DictionaryValue* extensions = prefs_->GetDictionary(kExtensionsPref); | 1505 const DictionaryValue* extensions = prefs_->GetDictionary(kExtensionsPref); |
1479 for (DictionaryValue::Iterator extension_id(*extensions); | 1506 for (DictionaryValue::Iterator extension_id(*extensions); |
1480 !extension_id.IsAtEnd(); extension_id.Advance()) { | 1507 !extension_id.IsAtEnd(); extension_id.Advance()) { |
1481 if (!Extension::IdIsValid(extension_id.key())) | 1508 if (!Extension::IdIsValid(extension_id.key())) |
1482 continue; | 1509 continue; |
1483 | 1510 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1540 if (IsFromBookmark(extension_id)) | 1567 if (IsFromBookmark(extension_id)) |
1541 creation_flags |= Extension::FROM_BOOKMARK; | 1568 creation_flags |= Extension::FROM_BOOKMARK; |
1542 if (IsFromWebStore(extension_id)) | 1569 if (IsFromWebStore(extension_id)) |
1543 creation_flags |= Extension::FROM_WEBSTORE; | 1570 creation_flags |= Extension::FROM_WEBSTORE; |
1544 if (WasInstalledByDefault(extension_id)) | 1571 if (WasInstalledByDefault(extension_id)) |
1545 creation_flags |= Extension::WAS_INSTALLED_BY_DEFAULT; | 1572 creation_flags |= Extension::WAS_INSTALLED_BY_DEFAULT; |
1546 } | 1573 } |
1547 return creation_flags; | 1574 return creation_flags; |
1548 } | 1575 } |
1549 | 1576 |
1577 int ExtensionPrefs::GetDelayedInstallCreationFlags( | |
1578 const std::string& extension_id) const { | |
1579 int creation_flags = Extension::NO_FLAGS; | |
1580 const DictionaryValue* delayed_info = NULL; | |
1581 if (ReadPrefAsDictionary(extension_id, kDelayedInstallInfo, &delayed_info)) { | |
1582 delayed_info->GetInteger(kPrefCreationFlags, &creation_flags); | |
1583 } | |
1584 return creation_flags; | |
1585 } | |
1586 | |
1550 bool ExtensionPrefs::WasInstalledByDefault( | 1587 bool ExtensionPrefs::WasInstalledByDefault( |
1551 const std::string& extension_id) const { | 1588 const std::string& extension_id) const { |
1552 const DictionaryValue* dictionary = GetExtensionPref(extension_id); | 1589 const DictionaryValue* dictionary = GetExtensionPref(extension_id); |
1553 bool result = false; | 1590 bool result = false; |
1554 if (dictionary && | 1591 if (dictionary && |
1555 dictionary->GetBoolean(kPrefWasInstalledByDefault, &result)) | 1592 dictionary->GetBoolean(kPrefWasInstalledByDefault, &result)) |
1556 return result; | 1593 return result; |
1557 return false; | 1594 return false; |
1558 } | 1595 } |
1559 | 1596 |
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2045 is_enabled = initial_state == Extension::ENABLED; | 2082 is_enabled = initial_state == Extension::ENABLED; |
2046 } | 2083 } |
2047 | 2084 |
2048 extension_pref_value_map_->RegisterExtension(extension_id, install_time, | 2085 extension_pref_value_map_->RegisterExtension(extension_id, install_time, |
2049 is_enabled); | 2086 is_enabled); |
2050 content_settings_store_->RegisterExtension(extension_id, install_time, | 2087 content_settings_store_->RegisterExtension(extension_id, install_time, |
2051 is_enabled); | 2088 is_enabled); |
2052 } | 2089 } |
2053 | 2090 |
2054 } // namespace extensions | 2091 } // namespace extensions |
OLD | NEW |