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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
57 const char kPrefAppNotificationDisbaled[] = "app_notif_disabled"; | 57 const char kPrefAppNotificationDisbaled[] = "app_notif_disabled"; |
58 | 58 |
59 // Indicates whether the user has acknowledged various types of extensions. | 59 // Indicates whether the user has acknowledged various types of extensions. |
60 const char kPrefExternalAcknowledged[] = "ack_external"; | 60 const char kPrefExternalAcknowledged[] = "ack_external"; |
61 const char kPrefBlacklistAcknowledged[] = "ack_blacklist"; | 61 const char kPrefBlacklistAcknowledged[] = "ack_blacklist"; |
62 const char kPrefOrphanAcknowledged[] = "ack_orphan"; | 62 const char kPrefOrphanAcknowledged[] = "ack_orphan"; |
63 | 63 |
64 // Indicates whether to show an install warning when the user enables. | 64 // Indicates whether to show an install warning when the user enables. |
65 const char kExtensionDidEscalatePermissions[] = "install_warning_on_enable"; | 65 const char kExtensionDidEscalatePermissions[] = "install_warning_on_enable"; |
66 | 66 |
67 // DO NOT USE, use kPrefDisableReasons instead. | |
67 // Indicates whether the extension was updated while it was disabled. | 68 // Indicates whether the extension was updated while it was disabled. |
68 const char kPrefDisableReason[] = "disable_reason"; | 69 const char kDeprecatedPrefDisableReason[] = "disable_reason"; |
70 | |
71 // A bitmask of all the reasons an extension is disabled. | |
72 const char kPrefDisableReasons[] = "disable_reasons"; | |
69 | 73 |
70 // A preference that tracks browser action toolbar configuration. This is a list | 74 // A preference that tracks browser action toolbar configuration. This is a list |
71 // object stored in the Preferences file. The extensions are stored by ID. | 75 // object stored in the Preferences file. The extensions are stored by ID. |
72 const char kExtensionToolbar[] = "extensions.toolbar"; | 76 const char kExtensionToolbar[] = "extensions.toolbar"; |
73 | 77 |
74 // A preference that tracks the order of extensions in an action box | 78 // A preference that tracks the order of extensions in an action box |
75 // (list of extension ids). | 79 // (list of extension ids). |
76 const char kExtensionActionBox[] = "extensions.action_box_order"; | 80 const char kExtensionActionBox[] = "extensions.action_box_order"; |
77 | 81 |
78 // A preference that tracks the order of extensions in a toolbar when | 82 // A preference that tracks the order of extensions in a toolbar when |
(...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
689 return ReadExtensionPrefBoolean(extension_id, | 693 return ReadExtensionPrefBoolean(extension_id, |
690 kExtensionDidEscalatePermissions); | 694 kExtensionDidEscalatePermissions); |
691 } | 695 } |
692 | 696 |
693 void ExtensionPrefs::SetDidExtensionEscalatePermissions( | 697 void ExtensionPrefs::SetDidExtensionEscalatePermissions( |
694 const Extension* extension, bool did_escalate) { | 698 const Extension* extension, bool did_escalate) { |
695 UpdateExtensionPref(extension->id(), kExtensionDidEscalatePermissions, | 699 UpdateExtensionPref(extension->id(), kExtensionDidEscalatePermissions, |
696 Value::CreateBooleanValue(did_escalate)); | 700 Value::CreateBooleanValue(did_escalate)); |
697 } | 701 } |
698 | 702 |
699 Extension::DisableReason ExtensionPrefs::GetDisableReason( | 703 int ExtensionPrefs::GetDisableReasons(const std::string& extension_id) { |
700 const std::string& extension_id) { | |
701 int value = -1; | 704 int value = -1; |
702 if (ReadExtensionPrefInteger(extension_id, kPrefDisableReason, &value) && | 705 if (ReadExtensionPrefInteger(extension_id, kPrefDisableReasons, &value) && |
703 value >= 0 && value < Extension::DISABLE_LAST) { | 706 value >= 0) { |
704 return static_cast<Extension::DisableReason>(value); | 707 return value; |
705 } | 708 } |
706 return Extension::DISABLE_UNKNOWN; | 709 return Extension::DISABLE_NONE; |
707 } | 710 } |
708 | 711 |
709 void ExtensionPrefs::SetDisableReason(const std::string& extension_id, | 712 void ExtensionPrefs::AddDisableReason(const std::string& extension_id, |
710 Extension::DisableReason disable_reason) { | 713 Extension::DisableReason disable_reason) { |
711 UpdateExtensionPref( | 714 int new_value = GetDisableReasons(extension_id) | |
712 extension_id, kPrefDisableReason, | 715 static_cast<int>(disable_reason); |
713 Value::CreateIntegerValue(static_cast<int>(disable_reason))); | 716 UpdateExtensionPref(extension_id, kPrefDisableReasons, |
717 Value::CreateIntegerValue(new_value)); | |
714 } | 718 } |
715 | 719 |
716 void ExtensionPrefs::RemoveDisableReason(const std::string& extension_id) { | 720 void ExtensionPrefs::RemoveDisableReason( |
717 UpdateExtensionPref(extension_id, kPrefDisableReason, NULL); | 721 const std::string& extension_id, |
722 Extension::DisableReason disable_reason) { | |
723 int new_value = GetDisableReasons(extension_id) & | |
724 ~static_cast<int>(disable_reason); | |
725 if (new_value == 0) { | |
Yoyo Zhou
2012/08/15 00:58:09
Change 0 to DISABLE_REASON_NONE?
eaugusti
2012/08/15 17:36:11
Done.
| |
726 UpdateExtensionPref(extension_id, kPrefDisableReasons, NULL); | |
727 } else { | |
728 UpdateExtensionPref(extension_id, kPrefDisableReasons, | |
729 Value::CreateIntegerValue(new_value)); | |
730 } | |
731 } | |
732 | |
733 void ExtensionPrefs::ClearDisableReasons(const std::string& extension_id) { | |
734 UpdateExtensionPref(extension_id, kPrefDisableReasons, NULL); | |
718 } | 735 } |
719 | 736 |
720 void ExtensionPrefs::UpdateBlacklist( | 737 void ExtensionPrefs::UpdateBlacklist( |
721 const std::set<std::string>& blacklist_set) { | 738 const std::set<std::string>& blacklist_set) { |
722 ExtensionIdSet remove_pref_ids; | 739 ExtensionIdSet remove_pref_ids; |
723 std::set<std::string> used_id_set; | 740 std::set<std::string> used_id_set; |
724 const DictionaryValue* extensions = prefs_->GetDictionary(kExtensionsPref); | 741 const DictionaryValue* extensions = prefs_->GetDictionary(kExtensionsPref); |
725 | 742 |
726 if (extensions) { | 743 if (extensions) { |
727 for (DictionaryValue::key_iterator extension_id = extensions->begin_keys(); | 744 for (DictionaryValue::key_iterator extension_id = extensions->begin_keys(); |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
895 if (ext->GetList(kPrefOldGrantedHosts, &hosts)) { | 912 if (ext->GetList(kPrefOldGrantedHosts, &hosts)) { |
896 UpdateExtensionPref( | 913 UpdateExtensionPref( |
897 *ext_id, explicit_hosts, hosts->DeepCopy()); | 914 *ext_id, explicit_hosts, hosts->DeepCopy()); |
898 | 915 |
899 // We can get rid of the old one by setting it to an empty list. | 916 // We can get rid of the old one by setting it to an empty list. |
900 UpdateExtensionPref(*ext_id, kPrefOldGrantedHosts, new ListValue()); | 917 UpdateExtensionPref(*ext_id, kPrefOldGrantedHosts, new ListValue()); |
901 } | 918 } |
902 } | 919 } |
903 } | 920 } |
904 | 921 |
922 void ExtensionPrefs::MigrateDisableReasons( | |
923 const ExtensionIdSet& extension_ids) { | |
924 for (ExtensionIdSet::const_iterator ext_id = | |
925 extension_ids.begin(); ext_id != extension_ids.end(); ++ext_id) { | |
926 int value = -1; | |
927 if (ReadExtensionPrefInteger(*ext_id, kDeprecatedPrefDisableReason, | |
928 &value)) { | |
929 int new_value = Extension::DISABLE_NONE; | |
930 if (value > Extension::DEPRECATED_DISABLE_UNKNOWN && | |
Yoyo Zhou
2012/08/15 00:58:09
nit: I would remove this if statement as well as t
eaugusti
2012/08/15 17:36:11
Done.
| |
931 value < Extension::DEPRECATED_DISABLE_LAST) { | |
932 switch (value) { | |
933 case Extension::DEPRECATED_DISABLE_USER_ACTION: | |
934 new_value = Extension::DISABLE_USER_ACTION; | |
935 break; | |
936 case Extension::DEPRECATED_DISABLE_PERMISSIONS_INCREASE: | |
937 new_value = Extension::DISABLE_PERMISSIONS_INCREASE; | |
938 break; | |
939 case Extension::DEPRECATED_DISABLE_RELOAD: | |
940 new_value = Extension::DISABLE_RELOAD; | |
941 break; | |
942 default: | |
943 NOTREACHED(); | |
944 return; | |
945 } | |
946 } | |
947 | |
948 UpdateExtensionPref(*ext_id, kPrefDisableReasons, | |
949 Value::CreateIntegerValue(new_value)); | |
950 // Remove the old disable reason. | |
951 UpdateExtensionPref(*ext_id, kDeprecatedPrefDisableReason, NULL); | |
952 } | |
953 } | |
954 } | |
955 | |
905 PermissionSet* ExtensionPrefs::GetGrantedPermissions( | 956 PermissionSet* ExtensionPrefs::GetGrantedPermissions( |
906 const std::string& extension_id) { | 957 const std::string& extension_id) { |
907 CHECK(Extension::IdIsValid(extension_id)); | 958 CHECK(Extension::IdIsValid(extension_id)); |
908 return ReadExtensionPrefPermissionSet(extension_id, kPrefGrantedPermissions); | 959 return ReadExtensionPrefPermissionSet(extension_id, kPrefGrantedPermissions); |
909 } | 960 } |
910 | 961 |
911 void ExtensionPrefs::AddGrantedPermissions( | 962 void ExtensionPrefs::AddGrantedPermissions( |
912 const std::string& extension_id, | 963 const std::string& extension_id, |
913 const PermissionSet* permissions) { | 964 const PermissionSet* permissions) { |
914 CHECK(Extension::IdIsValid(extension_id)); | 965 CHECK(Extension::IdIsValid(extension_id)); |
(...skipping 966 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1881 // are pruned when persisting the preferences to disk). | 1932 // are pruned when persisting the preferences to disk). |
1882 for (ExtensionIdSet::iterator ext_id = extension_ids.begin(); | 1933 for (ExtensionIdSet::iterator ext_id = extension_ids.begin(); |
1883 ext_id != extension_ids.end(); ++ext_id) { | 1934 ext_id != extension_ids.end(); ++ext_id) { |
1884 ScopedExtensionPrefUpdate update(prefs_, *ext_id); | 1935 ScopedExtensionPrefUpdate update(prefs_, *ext_id); |
1885 // This creates an empty dictionary if none is stored. | 1936 // This creates an empty dictionary if none is stored. |
1886 update.Get(); | 1937 update.Get(); |
1887 } | 1938 } |
1888 | 1939 |
1889 FixMissingPrefs(extension_ids); | 1940 FixMissingPrefs(extension_ids); |
1890 MigratePermissions(extension_ids); | 1941 MigratePermissions(extension_ids); |
1942 MigrateDisableReasons(extension_ids); | |
1891 extension_sorting_->Initialize(extension_ids); | 1943 extension_sorting_->Initialize(extension_ids); |
1892 | 1944 |
1893 // Store extension controlled preference values in the | 1945 // Store extension controlled preference values in the |
1894 // |extension_pref_value_map_|, which then informs the subscribers | 1946 // |extension_pref_value_map_|, which then informs the subscribers |
1895 // (ExtensionPrefStores) about the winning values. | 1947 // (ExtensionPrefStores) about the winning values. |
1896 for (ExtensionIdSet::iterator ext_id = extension_ids.begin(); | 1948 for (ExtensionIdSet::iterator ext_id = extension_ids.begin(); |
1897 ext_id != extension_ids.end(); ++ext_id) { | 1949 ext_id != extension_ids.end(); ++ext_id) { |
1898 extension_pref_value_map_->RegisterExtension( | 1950 extension_pref_value_map_->RegisterExtension( |
1899 *ext_id, | 1951 *ext_id, |
1900 GetInstallTime(*ext_id), | 1952 GetInstallTime(*ext_id), |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2098 const ExtensionIdSet& strings) { | 2150 const ExtensionIdSet& strings) { |
2099 ListPrefUpdate update(prefs_, pref); | 2151 ListPrefUpdate update(prefs_, pref); |
2100 ListValue* list_of_values = update.Get(); | 2152 ListValue* list_of_values = update.Get(); |
2101 list_of_values->Clear(); | 2153 list_of_values->Clear(); |
2102 for (ExtensionIdSet::const_iterator iter = strings.begin(); | 2154 for (ExtensionIdSet::const_iterator iter = strings.begin(); |
2103 iter != strings.end(); ++iter) | 2155 iter != strings.end(); ++iter) |
2104 list_of_values->Append(new StringValue(*iter)); | 2156 list_of_values->Append(new StringValue(*iter)); |
2105 } | 2157 } |
2106 | 2158 |
2107 } // namespace extensions | 2159 } // namespace extensions |
OLD | NEW |