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 pending_install_dict->Remove(kDelayedInstallReason, NULL); |
1446 | 1453 |
1447 const base::Time install_time = time_provider_->GetCurrentTime(); | 1454 const base::Time install_time = time_provider_->GetCurrentTime(); |
1448 pending_install_dict->Set( | 1455 pending_install_dict->Set( |
1449 kPrefInstallTime, | 1456 kPrefInstallTime, |
1450 Value::CreateStringValue( | 1457 Value::CreateStringValue( |
1451 base::Int64ToString(install_time.ToInternalValue()))); | 1458 base::Int64ToString(install_time.ToInternalValue()))); |
1452 | 1459 |
1453 // Commit the delayed install data. | 1460 // Commit the delayed install data. |
1454 extension_dict->MergeDictionary(pending_install_dict); | 1461 extension_dict->MergeDictionary(pending_install_dict); |
1455 FinishExtensionInfoPrefs(extension_id, install_time, needs_sort_ordinal, | 1462 FinishExtensionInfoPrefs(extension_id, install_time, needs_sort_ordinal, |
1456 suggested_page_ordinal, extension_dict); | 1463 suggested_page_ordinal, extension_dict); |
1457 return true; | 1464 return true; |
1458 } | 1465 } |
1459 | 1466 |
1460 scoped_ptr<ExtensionInfo> ExtensionPrefs::GetDelayedInstallInfo( | 1467 scoped_ptr<ExtensionInfo> ExtensionPrefs::GetDelayedInstallInfo( |
1461 const std::string& extension_id) const { | 1468 const std::string& extension_id) const { |
1462 const DictionaryValue* extension_prefs = | 1469 const DictionaryValue* extension_prefs = |
1463 GetExtensionPref(extension_id); | 1470 GetExtensionPref(extension_id); |
1464 if (!extension_prefs) | 1471 if (!extension_prefs) |
1465 return scoped_ptr<ExtensionInfo>(); | 1472 return scoped_ptr<ExtensionInfo>(); |
1466 | 1473 |
1467 const DictionaryValue* ext = NULL; | 1474 const DictionaryValue* ext = NULL; |
1468 if (!extension_prefs->GetDictionary(kDelayedInstallInfo, &ext)) | 1475 if (!extension_prefs->GetDictionary(kDelayedInstallInfo, &ext)) |
1469 return scoped_ptr<ExtensionInfo>(); | 1476 return scoped_ptr<ExtensionInfo>(); |
1470 | 1477 |
1471 return GetInstalledInfoHelper(extension_id, ext); | 1478 return GetInstalledInfoHelper(extension_id, ext); |
1472 } | 1479 } |
1473 | 1480 |
| 1481 ExtensionPrefs::DelayReason ExtensionPrefs::GetDelayedInstallReason( |
| 1482 const std::string& extension_id) const { |
| 1483 const DictionaryValue* extension_prefs = |
| 1484 GetExtensionPref(extension_id); |
| 1485 if (!extension_prefs) |
| 1486 return DELAY_REASON_NONE; |
| 1487 |
| 1488 const DictionaryValue* ext = NULL; |
| 1489 if (!extension_prefs->GetDictionary(kDelayedInstallInfo, &ext)) |
| 1490 return DELAY_REASON_NONE; |
| 1491 |
| 1492 int delay_reason; |
| 1493 if (!ext->GetInteger(kDelayedInstallReason, &delay_reason)) |
| 1494 return DELAY_REASON_NONE; |
| 1495 |
| 1496 return static_cast<DelayReason>(delay_reason); |
| 1497 } |
| 1498 |
1474 scoped_ptr<ExtensionPrefs::ExtensionsInfo> ExtensionPrefs:: | 1499 scoped_ptr<ExtensionPrefs::ExtensionsInfo> ExtensionPrefs:: |
1475 GetAllDelayedInstallInfo() const { | 1500 GetAllDelayedInstallInfo() const { |
1476 scoped_ptr<ExtensionsInfo> extensions_info(new ExtensionsInfo); | 1501 scoped_ptr<ExtensionsInfo> extensions_info(new ExtensionsInfo); |
1477 | 1502 |
1478 const DictionaryValue* extensions = prefs_->GetDictionary(kExtensionsPref); | 1503 const DictionaryValue* extensions = prefs_->GetDictionary(kExtensionsPref); |
1479 for (DictionaryValue::Iterator extension_id(*extensions); | 1504 for (DictionaryValue::Iterator extension_id(*extensions); |
1480 !extension_id.IsAtEnd(); extension_id.Advance()) { | 1505 !extension_id.IsAtEnd(); extension_id.Advance()) { |
1481 if (!Extension::IdIsValid(extension_id.key())) | 1506 if (!Extension::IdIsValid(extension_id.key())) |
1482 continue; | 1507 continue; |
1483 | 1508 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1540 if (IsFromBookmark(extension_id)) | 1565 if (IsFromBookmark(extension_id)) |
1541 creation_flags |= Extension::FROM_BOOKMARK; | 1566 creation_flags |= Extension::FROM_BOOKMARK; |
1542 if (IsFromWebStore(extension_id)) | 1567 if (IsFromWebStore(extension_id)) |
1543 creation_flags |= Extension::FROM_WEBSTORE; | 1568 creation_flags |= Extension::FROM_WEBSTORE; |
1544 if (WasInstalledByDefault(extension_id)) | 1569 if (WasInstalledByDefault(extension_id)) |
1545 creation_flags |= Extension::WAS_INSTALLED_BY_DEFAULT; | 1570 creation_flags |= Extension::WAS_INSTALLED_BY_DEFAULT; |
1546 } | 1571 } |
1547 return creation_flags; | 1572 return creation_flags; |
1548 } | 1573 } |
1549 | 1574 |
| 1575 int ExtensionPrefs::GetDelayedInstallCreationFlags( |
| 1576 const std::string& extension_id) const { |
| 1577 int creation_flags = Extension::NO_FLAGS; |
| 1578 const DictionaryValue* delayed_info = NULL; |
| 1579 if (ReadPrefAsDictionary(extension_id, kDelayedInstallInfo, &delayed_info)) { |
| 1580 delayed_info->GetInteger(kPrefCreationFlags, &creation_flags); |
| 1581 } |
| 1582 return creation_flags; |
| 1583 } |
| 1584 |
1550 bool ExtensionPrefs::WasInstalledByDefault( | 1585 bool ExtensionPrefs::WasInstalledByDefault( |
1551 const std::string& extension_id) const { | 1586 const std::string& extension_id) const { |
1552 const DictionaryValue* dictionary = GetExtensionPref(extension_id); | 1587 const DictionaryValue* dictionary = GetExtensionPref(extension_id); |
1553 bool result = false; | 1588 bool result = false; |
1554 if (dictionary && | 1589 if (dictionary && |
1555 dictionary->GetBoolean(kPrefWasInstalledByDefault, &result)) | 1590 dictionary->GetBoolean(kPrefWasInstalledByDefault, &result)) |
1556 return result; | 1591 return result; |
1557 return false; | 1592 return false; |
1558 } | 1593 } |
1559 | 1594 |
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2045 is_enabled = initial_state == Extension::ENABLED; | 2080 is_enabled = initial_state == Extension::ENABLED; |
2046 } | 2081 } |
2047 | 2082 |
2048 extension_pref_value_map_->RegisterExtension(extension_id, install_time, | 2083 extension_pref_value_map_->RegisterExtension(extension_id, install_time, |
2049 is_enabled); | 2084 is_enabled); |
2050 content_settings_store_->RegisterExtension(extension_id, install_time, | 2085 content_settings_store_->RegisterExtension(extension_id, install_time, |
2051 is_enabled); | 2086 is_enabled); |
2052 } | 2087 } |
2053 | 2088 |
2054 } // namespace extensions | 2089 } // namespace extensions |
OLD | NEW |