| 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 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 541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 617 UpdateExtensionPref(extension_id, kPrefAppNotificationClientId, | 620 UpdateExtensionPref(extension_id, kPrefAppNotificationClientId, |
| 618 Value::CreateStringValue(oauth_client_id)); | 621 Value::CreateStringValue(oauth_client_id)); |
| 619 } | 622 } |
| 620 | 623 |
| 621 bool ExtensionPrefs::IsAppNotificationDisabled( | 624 bool ExtensionPrefs::IsAppNotificationDisabled( |
| 622 const std::string& extension_id) const { | 625 const std::string& extension_id) const { |
| 623 return ReadExtensionPrefBoolean(extension_id, kPrefAppNotificationDisbaled); | 626 return ReadExtensionPrefBoolean(extension_id, kPrefAppNotificationDisbaled); |
| 624 } | 627 } |
| 625 | 628 |
| 626 void ExtensionPrefs::SetAppNotificationDisabled( | 629 void ExtensionPrefs::SetAppNotificationDisabled( |
| 627 const std::string& extension_id, bool value) { | 630 const std::string& extension_id, bool value) { |
| 628 DCHECK(Extension::IdIsValid(extension_id)); | 631 DCHECK(Extension::IdIsValid(extension_id)); |
| 629 UpdateExtensionPref(extension_id, kPrefAppNotificationDisbaled, | 632 UpdateExtensionPref(extension_id, kPrefAppNotificationDisbaled, |
| 630 Value::CreateBooleanValue(value)); | 633 Value::CreateBooleanValue(value)); |
| 631 } | 634 } |
| 632 | 635 |
| 633 std::string ExtensionPrefs::GetDebugPolicyProviderName() const { | 636 std::string ExtensionPrefs::GetDebugPolicyProviderName() const { |
| 634 #ifdef NDEBUG | 637 #ifdef NDEBUG |
| 635 NOTREACHED(); | 638 NOTREACHED(); |
| 636 return std::string(); | 639 return std::string(); |
| 637 #else | 640 #else |
| 638 return "admin policy black/white/forcelist, via the ExtensionPrefs"; | 641 return "admin policy black/white/forcelist, via the ExtensionPrefs"; |
| 639 #endif | 642 #endif |
| 640 } | 643 } |
| 641 | 644 |
| 642 bool ExtensionPrefs::UserMayLoad(const Extension* extension, | 645 bool ExtensionPrefs::UserMayLoad(const Extension* extension, |
| 643 string16* error) const { | 646 string16* error) const { |
| 644 | |
| 645 const base::ListValue* blacklist = | 647 const base::ListValue* blacklist = |
| 646 prefs_->GetList(prefs::kExtensionInstallDenyList); | 648 prefs_->GetList(prefs::kExtensionInstallDenyList); |
| 647 const base::ListValue* whitelist = | 649 const base::ListValue* whitelist = |
| 648 prefs_->GetList(prefs::kExtensionInstallAllowList); | 650 prefs_->GetList(prefs::kExtensionInstallAllowList); |
| 649 return admin_policy::UserMayLoad(blacklist, whitelist, extension, | 651 return admin_policy::UserMayLoad(blacklist, whitelist, extension, |
| 650 error); | 652 error); |
| 651 } | 653 } |
| 652 | 654 |
| 653 bool ExtensionPrefs::UserMayModifySettings(const Extension* extension, | 655 bool ExtensionPrefs::UserMayModifySettings(const Extension* extension, |
| 654 string16* error) const { | 656 string16* error) const { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 670 return ReadExtensionPrefBoolean(extension_id, | 672 return ReadExtensionPrefBoolean(extension_id, |
| 671 kExtensionDidEscalatePermissions); | 673 kExtensionDidEscalatePermissions); |
| 672 } | 674 } |
| 673 | 675 |
| 674 void ExtensionPrefs::SetDidExtensionEscalatePermissions( | 676 void ExtensionPrefs::SetDidExtensionEscalatePermissions( |
| 675 const Extension* extension, bool did_escalate) { | 677 const Extension* extension, bool did_escalate) { |
| 676 UpdateExtensionPref(extension->id(), kExtensionDidEscalatePermissions, | 678 UpdateExtensionPref(extension->id(), kExtensionDidEscalatePermissions, |
| 677 Value::CreateBooleanValue(did_escalate)); | 679 Value::CreateBooleanValue(did_escalate)); |
| 678 } | 680 } |
| 679 | 681 |
| 682 bool ExtensionPrefs::HasUnsupportedRequirements( |
| 683 const std::string& extension_id) { |
| 684 const ListValue* requirement_errors = NULL; |
| 685 return ReadExtensionPrefList(extension_id, |
| 686 kUnsupportedRequirements, |
| 687 &requirement_errors); |
| 688 } |
| 689 |
| 690 void ExtensionPrefs::ClearUnsupportedRequirements( |
| 691 const std::string& extension_id) { |
| 692 UpdateExtensionPref(extension_id, kUnsupportedRequirements, NULL); |
| 693 } |
| 694 |
| 695 void ExtensionPrefs::SetUnsupportedRequirements( |
| 696 const std::string& extension_id, |
| 697 std::vector<std::string> requirement_errors) { |
| 698 ListValue* errors_list = new ListValue(); |
| 699 std::vector<std::string>::iterator it; |
| 700 for (it = requirement_errors.begin(); it != requirement_errors.end(); ++it) |
| 701 errors_list->Append(Value::CreateStringValue(*it)); |
| 702 UpdateExtensionPref(extension_id, kUnsupportedRequirements, errors_list); |
| 703 } |
| 704 |
| 705 std::vector<std::string> ExtensionPrefs::GetUnsupportedRequirements( |
| 706 const std::string& extension_id) { |
| 707 std::vector<std::string> requirement_errors; |
| 708 const DictionaryValue* extension = GetExtensionPref(extension_id); |
| 709 if (!extension) |
| 710 return requirement_errors; |
| 711 |
| 712 ListValue* value = NULL; |
| 713 if (!extension->GetList(kUnsupportedRequirements, &value)) |
| 714 return requirement_errors; |
| 715 |
| 716 for (size_t i = 0; i < value->GetSize(); ++i) { |
| 717 std::string error; |
| 718 if (value->GetString(i, &error)) |
| 719 requirement_errors.push_back(error); |
| 720 } |
| 721 return requirement_errors; |
| 722 } |
| 723 |
| 680 Extension::DisableReason ExtensionPrefs::GetDisableReason( | 724 Extension::DisableReason ExtensionPrefs::GetDisableReason( |
| 681 const std::string& extension_id) { | 725 const std::string& extension_id) { |
| 682 int value = -1; | 726 int value = -1; |
| 683 if (ReadExtensionPrefInteger(extension_id, kPrefDisableReason, &value) && | 727 if (ReadExtensionPrefInteger(extension_id, kPrefDisableReason, &value) && |
| 684 value >= 0 && value < Extension::DISABLE_LAST) { | 728 value >= 0 && value < Extension::DISABLE_LAST) { |
| 685 return static_cast<Extension::DisableReason>(value); | 729 return static_cast<Extension::DisableReason>(value); |
| 686 } | 730 } |
| 687 return Extension::DISABLE_UNKNOWN; | 731 return Extension::DISABLE_UNKNOWN; |
| 688 } | 732 } |
| 689 | 733 |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 826 void ExtensionPrefs::SetActiveBit(const std::string& extension_id, | 870 void ExtensionPrefs::SetActiveBit(const std::string& extension_id, |
| 827 bool active) { | 871 bool active) { |
| 828 UpdateExtensionPref(extension_id, kActiveBit, | 872 UpdateExtensionPref(extension_id, kActiveBit, |
| 829 Value::CreateBooleanValue(active)); | 873 Value::CreateBooleanValue(active)); |
| 830 } | 874 } |
| 831 | 875 |
| 832 void ExtensionPrefs::MigratePermissions(const ExtensionIdSet& extension_ids) { | 876 void ExtensionPrefs::MigratePermissions(const ExtensionIdSet& extension_ids) { |
| 833 PermissionsInfo* info = PermissionsInfo::GetInstance(); | 877 PermissionsInfo* info = PermissionsInfo::GetInstance(); |
| 834 for (ExtensionIdSet::const_iterator ext_id = | 878 for (ExtensionIdSet::const_iterator ext_id = |
| 835 extension_ids.begin(); ext_id != extension_ids.end(); ++ext_id) { | 879 extension_ids.begin(); ext_id != extension_ids.end(); ++ext_id) { |
| 836 | |
| 837 // An extension's granted permissions need to be migrated if the | 880 // 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 | 881 // full_access bit is present. This bit was always present in the previous |
| 839 // scheme and is never present now. | 882 // scheme and is never present now. |
| 840 bool full_access; | 883 bool full_access; |
| 841 const DictionaryValue* ext = GetExtensionPref(*ext_id); | 884 const DictionaryValue* ext = GetExtensionPref(*ext_id); |
| 842 if (!ext || !ext->GetBoolean(kPrefOldGrantedFullAccess, &full_access)) | 885 if (!ext || !ext->GetBoolean(kPrefOldGrantedFullAccess, &full_access)) |
| 843 continue; | 886 continue; |
| 844 | 887 |
| 845 // Remove the full access bit (empty list will get trimmed). | 888 // Remove the full access bit (empty list will get trimmed). |
| 846 UpdateExtensionPref( | 889 UpdateExtensionPref( |
| (...skipping 1087 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1934 0, // default value | 1977 0, // default value |
| 1935 PrefService::UNSYNCABLE_PREF); | 1978 PrefService::UNSYNCABLE_PREF); |
| 1936 prefs->RegisterInt64Pref(prefs::kNextExtensionsUpdateCheck, | 1979 prefs->RegisterInt64Pref(prefs::kNextExtensionsUpdateCheck, |
| 1937 0, // default value | 1980 0, // default value |
| 1938 PrefService::UNSYNCABLE_PREF); | 1981 PrefService::UNSYNCABLE_PREF); |
| 1939 prefs->RegisterListPref(prefs::kExtensionAllowedInstallSites, | 1982 prefs->RegisterListPref(prefs::kExtensionAllowedInstallSites, |
| 1940 PrefService::UNSYNCABLE_PREF); | 1983 PrefService::UNSYNCABLE_PREF); |
| 1941 } | 1984 } |
| 1942 | 1985 |
| 1943 } // namespace extensions | 1986 } // namespace extensions |
| OLD | NEW |