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 == Extension::DISABLE_NONE) { |
| 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 switch (value) { |
| 931 case Extension::DEPRECATED_DISABLE_USER_ACTION: |
| 932 new_value = Extension::DISABLE_USER_ACTION; |
| 933 break; |
| 934 case Extension::DEPRECATED_DISABLE_PERMISSIONS_INCREASE: |
| 935 new_value = Extension::DISABLE_PERMISSIONS_INCREASE; |
| 936 break; |
| 937 case Extension::DEPRECATED_DISABLE_RELOAD: |
| 938 new_value = Extension::DISABLE_RELOAD; |
| 939 break; |
| 940 } |
| 941 |
| 942 UpdateExtensionPref(*ext_id, kPrefDisableReasons, |
| 943 Value::CreateIntegerValue(new_value)); |
| 944 // Remove the old disable reason. |
| 945 UpdateExtensionPref(*ext_id, kDeprecatedPrefDisableReason, NULL); |
| 946 } |
| 947 } |
| 948 } |
| 949 |
905 PermissionSet* ExtensionPrefs::GetGrantedPermissions( | 950 PermissionSet* ExtensionPrefs::GetGrantedPermissions( |
906 const std::string& extension_id) { | 951 const std::string& extension_id) { |
907 CHECK(Extension::IdIsValid(extension_id)); | 952 CHECK(Extension::IdIsValid(extension_id)); |
908 return ReadExtensionPrefPermissionSet(extension_id, kPrefGrantedPermissions); | 953 return ReadExtensionPrefPermissionSet(extension_id, kPrefGrantedPermissions); |
909 } | 954 } |
910 | 955 |
911 void ExtensionPrefs::AddGrantedPermissions( | 956 void ExtensionPrefs::AddGrantedPermissions( |
912 const std::string& extension_id, | 957 const std::string& extension_id, |
913 const PermissionSet* permissions) { | 958 const PermissionSet* permissions) { |
914 CHECK(Extension::IdIsValid(extension_id)); | 959 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). | 1926 // are pruned when persisting the preferences to disk). |
1882 for (ExtensionIdSet::iterator ext_id = extension_ids.begin(); | 1927 for (ExtensionIdSet::iterator ext_id = extension_ids.begin(); |
1883 ext_id != extension_ids.end(); ++ext_id) { | 1928 ext_id != extension_ids.end(); ++ext_id) { |
1884 ScopedExtensionPrefUpdate update(prefs_, *ext_id); | 1929 ScopedExtensionPrefUpdate update(prefs_, *ext_id); |
1885 // This creates an empty dictionary if none is stored. | 1930 // This creates an empty dictionary if none is stored. |
1886 update.Get(); | 1931 update.Get(); |
1887 } | 1932 } |
1888 | 1933 |
1889 FixMissingPrefs(extension_ids); | 1934 FixMissingPrefs(extension_ids); |
1890 MigratePermissions(extension_ids); | 1935 MigratePermissions(extension_ids); |
| 1936 MigrateDisableReasons(extension_ids); |
1891 extension_sorting_->Initialize(extension_ids); | 1937 extension_sorting_->Initialize(extension_ids); |
1892 | 1938 |
1893 // Store extension controlled preference values in the | 1939 // Store extension controlled preference values in the |
1894 // |extension_pref_value_map_|, which then informs the subscribers | 1940 // |extension_pref_value_map_|, which then informs the subscribers |
1895 // (ExtensionPrefStores) about the winning values. | 1941 // (ExtensionPrefStores) about the winning values. |
1896 for (ExtensionIdSet::iterator ext_id = extension_ids.begin(); | 1942 for (ExtensionIdSet::iterator ext_id = extension_ids.begin(); |
1897 ext_id != extension_ids.end(); ++ext_id) { | 1943 ext_id != extension_ids.end(); ++ext_id) { |
1898 extension_pref_value_map_->RegisterExtension( | 1944 extension_pref_value_map_->RegisterExtension( |
1899 *ext_id, | 1945 *ext_id, |
1900 GetInstallTime(*ext_id), | 1946 GetInstallTime(*ext_id), |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2098 const ExtensionIdSet& strings) { | 2144 const ExtensionIdSet& strings) { |
2099 ListPrefUpdate update(prefs_, pref); | 2145 ListPrefUpdate update(prefs_, pref); |
2100 ListValue* list_of_values = update.Get(); | 2146 ListValue* list_of_values = update.Get(); |
2101 list_of_values->Clear(); | 2147 list_of_values->Clear(); |
2102 for (ExtensionIdSet::const_iterator iter = strings.begin(); | 2148 for (ExtensionIdSet::const_iterator iter = strings.begin(); |
2103 iter != strings.end(); ++iter) | 2149 iter != strings.end(); ++iter) |
2104 list_of_values->Append(new StringValue(*iter)); | 2150 list_of_values->Append(new StringValue(*iter)); |
2105 } | 2151 } |
2106 | 2152 |
2107 } // namespace extensions | 2153 } // namespace extensions |
OLD | NEW |