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 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 // A preference that contains extension-set content settings. | 166 // A preference that contains extension-set content settings. |
167 const char kPrefContentSettings[] = "content_settings"; | 167 const char kPrefContentSettings[] = "content_settings"; |
168 | 168 |
169 // A preference that contains extension-set content settings. | 169 // A preference that contains extension-set content settings. |
170 const char kPrefIncognitoContentSettings[] = "incognito_content_settings"; | 170 const char kPrefIncognitoContentSettings[] = "incognito_content_settings"; |
171 | 171 |
172 // A list of event names that this extension has registered from its lazy | 172 // A list of event names that this extension has registered from its lazy |
173 // background page. | 173 // background page. |
174 const char kRegisteredEvents[] = "events"; | 174 const char kRegisteredEvents[] = "events"; |
175 | 175 |
| 176 // A dictionary of event names to lists of filters that this extension has |
| 177 // registered from its lazy background page. |
| 178 const char kFilteredEvents[] = "filtered_events"; |
| 179 |
176 // Persisted value for omnibox.setDefaultSuggestion. | 180 // Persisted value for omnibox.setDefaultSuggestion. |
177 const char kOmniboxDefaultSuggestion[] = "omnibox_default_suggestion"; | 181 const char kOmniboxDefaultSuggestion[] = "omnibox_default_suggestion"; |
178 | 182 |
179 // Provider of write access to a dictionary storing extension prefs. | 183 // Provider of write access to a dictionary storing extension prefs. |
180 class ScopedExtensionPrefUpdate : public DictionaryPrefUpdate { | 184 class ScopedExtensionPrefUpdate : public DictionaryPrefUpdate { |
181 public: | 185 public: |
182 ScopedExtensionPrefUpdate(PrefService* service, | 186 ScopedExtensionPrefUpdate(PrefService* service, |
183 const std::string& extension_id) : | 187 const std::string& extension_id) : |
184 DictionaryPrefUpdate(service, ExtensionPrefs::kExtensionsPref), | 188 DictionaryPrefUpdate(service, ExtensionPrefs::kExtensionsPref), |
185 extension_id_(extension_id) {} | 189 extension_id_(extension_id) {} |
(...skipping 764 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
950 return events; | 954 return events; |
951 | 955 |
952 for (size_t i = 0; i < value->GetSize(); ++i) { | 956 for (size_t i = 0; i < value->GetSize(); ++i) { |
953 std::string event; | 957 std::string event; |
954 if (value->GetString(i, &event)) | 958 if (value->GetString(i, &event)) |
955 events.insert(event); | 959 events.insert(event); |
956 } | 960 } |
957 return events; | 961 return events; |
958 } | 962 } |
959 | 963 |
| 964 void ExtensionPrefs::AddFilterToEvent(const std::string& event_name, |
| 965 const std::string& extension_id, |
| 966 const DictionaryValue* filter) { |
| 967 ScopedExtensionPrefUpdate update(prefs_, extension_id); |
| 968 DictionaryValue* extension_dict = update.Get(); |
| 969 DictionaryValue* filtered_events = NULL; |
| 970 if (!extension_dict->GetDictionary(kFilteredEvents, &filtered_events)) { |
| 971 filtered_events = new DictionaryValue; |
| 972 extension_dict->Set(kFilteredEvents, filtered_events); |
| 973 } |
| 974 ListValue* filter_list = NULL; |
| 975 if (!filtered_events->GetList(event_name, &filter_list)) { |
| 976 filter_list = new ListValue; |
| 977 filtered_events->Set(event_name, filter_list); |
| 978 } |
| 979 |
| 980 filter_list->Append(filter->DeepCopy()); |
| 981 } |
| 982 |
| 983 void ExtensionPrefs::RemoveFilterFromEvent(const std::string& event_name, |
| 984 const std::string& extension_id, |
| 985 const DictionaryValue* filter) { |
| 986 ScopedExtensionPrefUpdate update(prefs_, extension_id); |
| 987 DictionaryValue* extension_dict = update.Get(); |
| 988 DictionaryValue* filtered_events = NULL; |
| 989 |
| 990 if (!extension_dict->GetDictionary(kFilteredEvents, &filtered_events)) |
| 991 return; |
| 992 ListValue* filter_list = NULL; |
| 993 if (!filtered_events->GetList(event_name, &filter_list)) |
| 994 return; |
| 995 |
| 996 for (size_t i = 0; i < filter_list->GetSize(); i++) { |
| 997 DictionaryValue* filter; |
| 998 CHECK(filter_list->GetDictionary(i, &filter)); |
| 999 if (filter->Equals(filter)) { |
| 1000 filter_list->Remove(i, NULL); |
| 1001 break; |
| 1002 } |
| 1003 } |
| 1004 } |
| 1005 |
| 1006 const DictionaryValue* ExtensionPrefs::GetFilteredEvents( |
| 1007 const std::string& extension_id) const { |
| 1008 const DictionaryValue* extension = GetExtensionPref(extension_id); |
| 1009 if (!extension) |
| 1010 return NULL; |
| 1011 DictionaryValue* result = NULL; |
| 1012 if (!extension->GetDictionary(kFilteredEvents, &result)) |
| 1013 return NULL; |
| 1014 return result; |
| 1015 } |
| 1016 |
960 void ExtensionPrefs::SetRegisteredEvents( | 1017 void ExtensionPrefs::SetRegisteredEvents( |
961 const std::string& extension_id, const std::set<std::string>& events) { | 1018 const std::string& extension_id, const std::set<std::string>& events) { |
962 ListValue* value = new ListValue(); | 1019 ListValue* value = new ListValue(); |
963 for (std::set<std::string>::const_iterator it = events.begin(); | 1020 for (std::set<std::string>::const_iterator it = events.begin(); |
964 it != events.end(); ++it) { | 1021 it != events.end(); ++it) { |
965 value->Append(new StringValue(*it)); | 1022 value->Append(new StringValue(*it)); |
966 } | 1023 } |
967 UpdateExtensionPref(extension_id, kRegisteredEvents, value); | 1024 UpdateExtensionPref(extension_id, kRegisteredEvents, value); |
968 } | 1025 } |
969 | 1026 |
(...skipping 909 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1879 PrefService::UNSYNCABLE_PREF); | 1936 PrefService::UNSYNCABLE_PREF); |
1880 prefs->RegisterInt64Pref(prefs::kLastExtensionsUpdateCheck, | 1937 prefs->RegisterInt64Pref(prefs::kLastExtensionsUpdateCheck, |
1881 0, // default value | 1938 0, // default value |
1882 PrefService::UNSYNCABLE_PREF); | 1939 PrefService::UNSYNCABLE_PREF); |
1883 prefs->RegisterInt64Pref(prefs::kNextExtensionsUpdateCheck, | 1940 prefs->RegisterInt64Pref(prefs::kNextExtensionsUpdateCheck, |
1884 0, // default value | 1941 0, // default value |
1885 PrefService::UNSYNCABLE_PREF); | 1942 PrefService::UNSYNCABLE_PREF); |
1886 prefs->RegisterListPref(prefs::kExtensionAllowedInstallSites, | 1943 prefs->RegisterListPref(prefs::kExtensionAllowedInstallSites, |
1887 PrefService::UNSYNCABLE_PREF); | 1944 PrefService::UNSYNCABLE_PREF); |
1888 } | 1945 } |
OLD | NEW |