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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
56 const char kPrefAppNotificationDisbaled[] = "app_notif_disabled"; | 56 const char kPrefAppNotificationDisbaled[] = "app_notif_disabled"; |
57 | 57 |
58 // Indicates whether the user has acknowledged various types of extensions. | 58 // Indicates whether the user has acknowledged various types of extensions. |
59 const char kPrefExternalAcknowledged[] = "ack_external"; | 59 const char kPrefExternalAcknowledged[] = "ack_external"; |
60 const char kPrefBlacklistAcknowledged[] = "ack_blacklist"; | 60 const char kPrefBlacklistAcknowledged[] = "ack_blacklist"; |
61 const char kPrefOrphanAcknowledged[] = "ack_orphan"; | 61 const char kPrefOrphanAcknowledged[] = "ack_orphan"; |
62 | 62 |
63 // Indicates whether to show an install warning when the user enables. | 63 // Indicates whether to show an install warning when the user enables. |
64 const char kExtensionDidEscalatePermissions[] = "install_warning_on_enable"; | 64 const char kExtensionDidEscalatePermissions[] = "install_warning_on_enable"; |
65 | 65 |
66 // Any errors that arose from unmet requirements. | |
67 const char kUnsupportedRequirements[] = "unsupported_requirements"; | |
68 | |
66 // Indicates whether the extension was updated while it was disabled. | 69 // Indicates whether the extension was updated while it was disabled. |
67 const char kPrefDisableReason[] = "disable_reason"; | 70 const char kPrefDisableReason[] = "disable_reason"; |
68 | 71 |
69 // A preference that tracks browser action toolbar configuration. This is a list | 72 // A preference that tracks browser action toolbar configuration. This is a list |
70 // object stored in the Preferences file. The extensions are stored by ID. | 73 // object stored in the Preferences file. The extensions are stored by ID. |
71 const char kExtensionToolbar[] = "extensions.toolbar"; | 74 const char kExtensionToolbar[] = "extensions.toolbar"; |
72 | 75 |
73 // The key for a serialized Time value indicating the start of the day (from the | 76 // The key for a serialized Time value indicating the start of the day (from the |
74 // server's perspective) an extension last included a "ping" parameter during | 77 // server's perspective) an extension last included a "ping" parameter during |
75 // its update check. | 78 // its update check. |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
432 const DictionaryValue* ext = GetExtensionPref(extension_id); | 435 const DictionaryValue* ext = GetExtensionPref(extension_id); |
433 const ListValue* out = NULL; | 436 const ListValue* out = NULL; |
434 if (!ext || !ext->GetList(pref_key, &out)) | 437 if (!ext || !ext->GetList(pref_key, &out)) |
435 return false; | 438 return false; |
436 if (out_value) | 439 if (out_value) |
437 *out_value = out; | 440 *out_value = out; |
438 | 441 |
439 return true; | 442 return true; |
440 } | 443 } |
441 | 444 |
445 bool ExtensionPrefs::ReadExtensionPrefStringList( | |
446 const std::string& extension_id, const std::string& pref_key, | |
447 std::vector<std::string>* out_value) const { | |
448 const ListValue* value_list = NULL; | |
449 if (!ReadExtensionPrefList(extension_id, kUnsupportedRequirements, | |
450 &value_list)) | |
Aaron Boodman
2012/08/06 20:36:07
Needs curlies.
eaugusti
2012/08/17 23:25:01
Done.
| |
451 return false; | |
452 | |
453 for (size_t i = 0; i < value_list->GetSize(); ++i) { | |
454 std::string value; | |
455 if (value_list->GetString(i, &value)) | |
456 out_value->push_back(value); | |
457 } | |
458 | |
459 return true; | |
460 } | |
461 | |
442 bool ExtensionPrefs::ReadExtensionPrefString( | 462 bool ExtensionPrefs::ReadExtensionPrefString( |
443 const std::string& extension_id, const std::string& pref_key, | 463 const std::string& extension_id, const std::string& pref_key, |
444 std::string* out_value) const { | 464 std::string* out_value) const { |
445 const DictionaryValue* ext = GetExtensionPref(extension_id); | 465 const DictionaryValue* ext = GetExtensionPref(extension_id); |
446 | 466 |
447 if (!ext || !ext->GetString(pref_key, out_value)) | 467 if (!ext || !ext->GetString(pref_key, out_value)) |
448 return false; | 468 return false; |
449 | 469 |
450 return true; | 470 return true; |
451 } | 471 } |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
617 UpdateExtensionPref(extension_id, kPrefAppNotificationClientId, | 637 UpdateExtensionPref(extension_id, kPrefAppNotificationClientId, |
618 Value::CreateStringValue(oauth_client_id)); | 638 Value::CreateStringValue(oauth_client_id)); |
619 } | 639 } |
620 | 640 |
621 bool ExtensionPrefs::IsAppNotificationDisabled( | 641 bool ExtensionPrefs::IsAppNotificationDisabled( |
622 const std::string& extension_id) const { | 642 const std::string& extension_id) const { |
623 return ReadExtensionPrefBoolean(extension_id, kPrefAppNotificationDisbaled); | 643 return ReadExtensionPrefBoolean(extension_id, kPrefAppNotificationDisbaled); |
624 } | 644 } |
625 | 645 |
626 void ExtensionPrefs::SetAppNotificationDisabled( | 646 void ExtensionPrefs::SetAppNotificationDisabled( |
627 const std::string& extension_id, bool value) { | 647 const std::string& extension_id, bool value) { |
628 DCHECK(Extension::IdIsValid(extension_id)); | 648 DCHECK(Extension::IdIsValid(extension_id)); |
629 UpdateExtensionPref(extension_id, kPrefAppNotificationDisbaled, | 649 UpdateExtensionPref(extension_id, kPrefAppNotificationDisbaled, |
630 Value::CreateBooleanValue(value)); | 650 Value::CreateBooleanValue(value)); |
631 } | 651 } |
632 | 652 |
633 std::string ExtensionPrefs::GetDebugPolicyProviderName() const { | 653 std::string ExtensionPrefs::GetDebugPolicyProviderName() const { |
634 #ifdef NDEBUG | 654 #ifdef NDEBUG |
635 NOTREACHED(); | 655 NOTREACHED(); |
636 return std::string(); | 656 return std::string(); |
637 #else | 657 #else |
638 return "admin policy black/white/forcelist, via the ExtensionPrefs"; | 658 return "admin policy black/white/forcelist, via the ExtensionPrefs"; |
639 #endif | 659 #endif |
640 } | 660 } |
641 | 661 |
642 bool ExtensionPrefs::UserMayLoad(const Extension* extension, | 662 bool ExtensionPrefs::UserMayLoad(const Extension* extension, |
643 string16* error) const { | 663 string16* error) const { |
644 | 664 |
Aaron Boodman
2012/08/06 20:36:07
stray edit
eaugusti
2012/08/17 23:25:01
Done.
| |
645 const base::ListValue* blacklist = | 665 const base::ListValue* blacklist = |
646 prefs_->GetList(prefs::kExtensionInstallDenyList); | 666 prefs_->GetList(prefs::kExtensionInstallDenyList); |
647 const base::ListValue* whitelist = | 667 const base::ListValue* whitelist = |
648 prefs_->GetList(prefs::kExtensionInstallAllowList); | 668 prefs_->GetList(prefs::kExtensionInstallAllowList); |
649 return admin_policy::UserMayLoad(blacklist, whitelist, extension, | 669 return admin_policy::UserMayLoad(blacklist, whitelist, extension, |
650 error); | 670 error); |
651 } | 671 } |
652 | 672 |
653 bool ExtensionPrefs::UserMayModifySettings(const Extension* extension, | 673 bool ExtensionPrefs::UserMayModifySettings(const Extension* extension, |
654 string16* error) const { | 674 string16* error) const { |
(...skipping 15 matching lines...) Expand all Loading... | |
670 return ReadExtensionPrefBoolean(extension_id, | 690 return ReadExtensionPrefBoolean(extension_id, |
671 kExtensionDidEscalatePermissions); | 691 kExtensionDidEscalatePermissions); |
672 } | 692 } |
673 | 693 |
674 void ExtensionPrefs::SetDidExtensionEscalatePermissions( | 694 void ExtensionPrefs::SetDidExtensionEscalatePermissions( |
675 const Extension* extension, bool did_escalate) { | 695 const Extension* extension, bool did_escalate) { |
676 UpdateExtensionPref(extension->id(), kExtensionDidEscalatePermissions, | 696 UpdateExtensionPref(extension->id(), kExtensionDidEscalatePermissions, |
677 Value::CreateBooleanValue(did_escalate)); | 697 Value::CreateBooleanValue(did_escalate)); |
678 } | 698 } |
679 | 699 |
700 bool ExtensionPrefs::HasUnsupportedRequirements( | |
701 const std::string& extension_id) { | |
702 const ListValue* requirement_errors = NULL; | |
703 return ReadExtensionPrefList(extension_id, | |
704 kUnsupportedRequirements, | |
705 &requirement_errors); | |
706 } | |
707 | |
708 void ExtensionPrefs::ClearUnsupportedRequirements( | |
709 const std::string& extension_id) { | |
710 UpdateExtensionPref(extension_id, kUnsupportedRequirements, NULL); | |
711 } | |
712 | |
713 void ExtensionPrefs::SetUnsupportedRequirements( | |
714 const std::string& extension_id, | |
715 std::vector<std::string> requirement_errors) { | |
716 UpdateExtensionPrefList(extension_id, | |
717 kUnsupportedRequirements, | |
718 requirement_errors); | |
719 } | |
720 | |
721 std::vector<std::string> ExtensionPrefs::GetUnsupportedRequirements( | |
722 const std::string& extension_id) { | |
723 std::vector<std::string> errors; | |
724 ReadExtensionPrefStringList(extension_id, kUnsupportedRequirements, &errors); | |
725 return errors; | |
726 } | |
727 | |
680 Extension::DisableReason ExtensionPrefs::GetDisableReason( | 728 Extension::DisableReason ExtensionPrefs::GetDisableReason( |
681 const std::string& extension_id) { | 729 const std::string& extension_id) { |
682 int value = -1; | 730 int value = -1; |
683 if (ReadExtensionPrefInteger(extension_id, kPrefDisableReason, &value) && | 731 if (ReadExtensionPrefInteger(extension_id, kPrefDisableReason, &value) && |
684 value >= 0 && value < Extension::DISABLE_LAST) { | 732 value >= 0 && value < Extension::DISABLE_LAST) { |
685 return static_cast<Extension::DisableReason>(value); | 733 return static_cast<Extension::DisableReason>(value); |
686 } | 734 } |
687 return Extension::DISABLE_UNKNOWN; | 735 return Extension::DISABLE_UNKNOWN; |
688 } | 736 } |
689 | 737 |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
826 void ExtensionPrefs::SetActiveBit(const std::string& extension_id, | 874 void ExtensionPrefs::SetActiveBit(const std::string& extension_id, |
827 bool active) { | 875 bool active) { |
828 UpdateExtensionPref(extension_id, kActiveBit, | 876 UpdateExtensionPref(extension_id, kActiveBit, |
829 Value::CreateBooleanValue(active)); | 877 Value::CreateBooleanValue(active)); |
830 } | 878 } |
831 | 879 |
832 void ExtensionPrefs::MigratePermissions(const ExtensionIdSet& extension_ids) { | 880 void ExtensionPrefs::MigratePermissions(const ExtensionIdSet& extension_ids) { |
833 PermissionsInfo* info = PermissionsInfo::GetInstance(); | 881 PermissionsInfo* info = PermissionsInfo::GetInstance(); |
834 for (ExtensionIdSet::const_iterator ext_id = | 882 for (ExtensionIdSet::const_iterator ext_id = |
835 extension_ids.begin(); ext_id != extension_ids.end(); ++ext_id) { | 883 extension_ids.begin(); ext_id != extension_ids.end(); ++ext_id) { |
836 | 884 |
Aaron Boodman
2012/08/06 20:36:07
stray edit
eaugusti
2012/08/17 23:25:01
Done.
| |
837 // An extension's granted permissions need to be migrated if the | 885 // An extension's granted permissions need to be migrated if the |
838 // full_access bit is present. This bit was always present in the previous | 886 // full_access bit is present. This bit was always present in the previous |
839 // scheme and is never present now. | 887 // scheme and is never present now. |
840 bool full_access; | 888 bool full_access; |
841 const DictionaryValue* ext = GetExtensionPref(*ext_id); | 889 const DictionaryValue* ext = GetExtensionPref(*ext_id); |
842 if (!ext || !ext->GetBoolean(kPrefOldGrantedFullAccess, &full_access)) | 890 if (!ext || !ext->GetBoolean(kPrefOldGrantedFullAccess, &full_access)) |
843 continue; | 891 continue; |
844 | 892 |
845 // Remove the full access bit (empty list will get trimmed). | 893 // Remove the full access bit (empty list will get trimmed). |
846 UpdateExtensionPref( | 894 UpdateExtensionPref( |
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1366 NOTREACHED() << "Invalid extension_id " << extension_id; | 1414 NOTREACHED() << "Invalid extension_id " << extension_id; |
1367 return; | 1415 return; |
1368 } | 1416 } |
1369 ScopedExtensionPrefUpdate update(prefs_, extension_id); | 1417 ScopedExtensionPrefUpdate update(prefs_, extension_id); |
1370 if (data_value) | 1418 if (data_value) |
1371 update->Set(key, data_value); | 1419 update->Set(key, data_value); |
1372 else | 1420 else |
1373 update->Remove(key, NULL); | 1421 update->Remove(key, NULL); |
1374 } | 1422 } |
1375 | 1423 |
1424 void ExtensionPrefs::UpdateExtensionPrefList( | |
1425 const std::string& extension_id, const std::string& key, | |
1426 const std::vector<std::string>& data_value) { | |
1427 ListValue* data_list = new ListValue(); | |
1428 std::vector<std::string>::const_iterator it; | |
1429 for (it = data_value.begin(); it != data_value.end(); ++it) | |
1430 data_list->Append(Value::CreateStringValue(*it)); | |
1431 UpdateExtensionPref(extension_id, key, data_list); | |
1432 } | |
1433 | |
1376 void ExtensionPrefs::DeleteExtensionPrefs(const std::string& extension_id) { | 1434 void ExtensionPrefs::DeleteExtensionPrefs(const std::string& extension_id) { |
1377 extension_pref_value_map_->UnregisterExtension(extension_id); | 1435 extension_pref_value_map_->UnregisterExtension(extension_id); |
1378 content_settings_store_->UnregisterExtension(extension_id); | 1436 content_settings_store_->UnregisterExtension(extension_id); |
1379 DictionaryPrefUpdate update(prefs_, kExtensionsPref); | 1437 DictionaryPrefUpdate update(prefs_, kExtensionsPref); |
1380 DictionaryValue* dict = update.Get(); | 1438 DictionaryValue* dict = update.Get(); |
1381 dict->Remove(extension_id, NULL); | 1439 dict->Remove(extension_id, NULL); |
1382 } | 1440 } |
1383 | 1441 |
1384 const DictionaryValue* ExtensionPrefs::GetExtensionPref( | 1442 const DictionaryValue* ExtensionPrefs::GetExtensionPref( |
1385 const std::string& extension_id) const { | 1443 const std::string& extension_id) const { |
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1934 0, // default value | 1992 0, // default value |
1935 PrefService::UNSYNCABLE_PREF); | 1993 PrefService::UNSYNCABLE_PREF); |
1936 prefs->RegisterInt64Pref(prefs::kNextExtensionsUpdateCheck, | 1994 prefs->RegisterInt64Pref(prefs::kNextExtensionsUpdateCheck, |
1937 0, // default value | 1995 0, // default value |
1938 PrefService::UNSYNCABLE_PREF); | 1996 PrefService::UNSYNCABLE_PREF); |
1939 prefs->RegisterListPref(prefs::kExtensionAllowedInstallSites, | 1997 prefs->RegisterListPref(prefs::kExtensionAllowedInstallSites, |
1940 PrefService::UNSYNCABLE_PREF); | 1998 PrefService::UNSYNCABLE_PREF); |
1941 } | 1999 } |
1942 | 2000 |
1943 } // namespace extensions | 2001 } // namespace extensions |
OLD | NEW |