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 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 // A preference that contains extension-set content settings. | 172 // A preference that contains extension-set content settings. |
173 const char kPrefContentSettings[] = "content_settings"; | 173 const char kPrefContentSettings[] = "content_settings"; |
174 | 174 |
175 // A preference that contains extension-set content settings. | 175 // A preference that contains extension-set content settings. |
176 const char kPrefIncognitoContentSettings[] = "incognito_content_settings"; | 176 const char kPrefIncognitoContentSettings[] = "incognito_content_settings"; |
177 | 177 |
178 // A list of event names that this extension has registered from its lazy | 178 // A list of event names that this extension has registered from its lazy |
179 // background page. | 179 // background page. |
180 const char kRegisteredEvents[] = "events"; | 180 const char kRegisteredEvents[] = "events"; |
181 | 181 |
| 182 // A dictionary of event names to lists of filters that this extension has |
| 183 // registered from its lazy background page. |
| 184 const char kFilteredEvents[] = "filtered_events"; |
| 185 |
182 // Persisted value for omnibox.setDefaultSuggestion. | 186 // Persisted value for omnibox.setDefaultSuggestion. |
183 const char kOmniboxDefaultSuggestion[] = "omnibox_default_suggestion"; | 187 const char kOmniboxDefaultSuggestion[] = "omnibox_default_suggestion"; |
184 | 188 |
185 // Provider of write access to a dictionary storing extension prefs. | 189 // Provider of write access to a dictionary storing extension prefs. |
186 class ScopedExtensionPrefUpdate : public DictionaryPrefUpdate { | 190 class ScopedExtensionPrefUpdate : public DictionaryPrefUpdate { |
187 public: | 191 public: |
188 ScopedExtensionPrefUpdate(PrefService* service, | 192 ScopedExtensionPrefUpdate(PrefService* service, |
189 const std::string& extension_id) : | 193 const std::string& extension_id) : |
190 DictionaryPrefUpdate(service, ExtensionPrefs::kExtensionsPref), | 194 DictionaryPrefUpdate(service, ExtensionPrefs::kExtensionsPref), |
191 extension_id_(extension_id) {} | 195 extension_id_(extension_id) {} |
(...skipping 787 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
979 return events; | 983 return events; |
980 | 984 |
981 for (size_t i = 0; i < value->GetSize(); ++i) { | 985 for (size_t i = 0; i < value->GetSize(); ++i) { |
982 std::string event; | 986 std::string event; |
983 if (value->GetString(i, &event)) | 987 if (value->GetString(i, &event)) |
984 events.insert(event); | 988 events.insert(event); |
985 } | 989 } |
986 return events; | 990 return events; |
987 } | 991 } |
988 | 992 |
| 993 void ExtensionPrefs::AddFilterToEvent(const std::string& event_name, |
| 994 const std::string& extension_id, |
| 995 const DictionaryValue* filter) { |
| 996 ScopedExtensionPrefUpdate update(prefs_, extension_id); |
| 997 DictionaryValue* extension_dict = update.Get(); |
| 998 DictionaryValue* filtered_events = NULL; |
| 999 if (!extension_dict->GetDictionary(kFilteredEvents, &filtered_events)) { |
| 1000 filtered_events = new DictionaryValue; |
| 1001 extension_dict->Set(kFilteredEvents, filtered_events); |
| 1002 } |
| 1003 ListValue* filter_list = NULL; |
| 1004 if (!filtered_events->GetList(event_name, &filter_list)) { |
| 1005 filter_list = new ListValue; |
| 1006 filtered_events->Set(event_name, filter_list); |
| 1007 } |
| 1008 |
| 1009 filter_list->Append(filter->DeepCopy()); |
| 1010 } |
| 1011 |
| 1012 void ExtensionPrefs::RemoveFilterFromEvent(const std::string& event_name, |
| 1013 const std::string& extension_id, |
| 1014 const DictionaryValue* filter) { |
| 1015 ScopedExtensionPrefUpdate update(prefs_, extension_id); |
| 1016 DictionaryValue* extension_dict = update.Get(); |
| 1017 DictionaryValue* filtered_events = NULL; |
| 1018 |
| 1019 if (!extension_dict->GetDictionary(kFilteredEvents, &filtered_events)) |
| 1020 return; |
| 1021 ListValue* filter_list = NULL; |
| 1022 if (!filtered_events->GetList(event_name, &filter_list)) |
| 1023 return; |
| 1024 |
| 1025 for (size_t i = 0; i < filter_list->GetSize(); i++) { |
| 1026 DictionaryValue* filter; |
| 1027 CHECK(filter_list->GetDictionary(i, &filter)); |
| 1028 if (filter->Equals(filter)) { |
| 1029 filter_list->Remove(i, NULL); |
| 1030 break; |
| 1031 } |
| 1032 } |
| 1033 } |
| 1034 |
| 1035 const DictionaryValue* ExtensionPrefs::GetFilteredEvents( |
| 1036 const std::string& extension_id) const { |
| 1037 const DictionaryValue* extension = GetExtensionPref(extension_id); |
| 1038 if (!extension) |
| 1039 return NULL; |
| 1040 DictionaryValue* result = NULL; |
| 1041 if (!extension->GetDictionary(kFilteredEvents, &result)) |
| 1042 return NULL; |
| 1043 return result; |
| 1044 } |
| 1045 |
989 void ExtensionPrefs::SetRegisteredEvents( | 1046 void ExtensionPrefs::SetRegisteredEvents( |
990 const std::string& extension_id, const std::set<std::string>& events) { | 1047 const std::string& extension_id, const std::set<std::string>& events) { |
991 ListValue* value = new ListValue(); | 1048 ListValue* value = new ListValue(); |
992 for (std::set<std::string>::const_iterator it = events.begin(); | 1049 for (std::set<std::string>::const_iterator it = events.begin(); |
993 it != events.end(); ++it) { | 1050 it != events.end(); ++it) { |
994 value->Append(new StringValue(*it)); | 1051 value->Append(new StringValue(*it)); |
995 } | 1052 } |
996 UpdateExtensionPref(extension_id, kRegisteredEvents, value); | 1053 UpdateExtensionPref(extension_id, kRegisteredEvents, value); |
997 } | 1054 } |
998 | 1055 |
(...skipping 909 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1908 PrefService::UNSYNCABLE_PREF); | 1965 PrefService::UNSYNCABLE_PREF); |
1909 prefs->RegisterInt64Pref(prefs::kLastExtensionsUpdateCheck, | 1966 prefs->RegisterInt64Pref(prefs::kLastExtensionsUpdateCheck, |
1910 0, // default value | 1967 0, // default value |
1911 PrefService::UNSYNCABLE_PREF); | 1968 PrefService::UNSYNCABLE_PREF); |
1912 prefs->RegisterInt64Pref(prefs::kNextExtensionsUpdateCheck, | 1969 prefs->RegisterInt64Pref(prefs::kNextExtensionsUpdateCheck, |
1913 0, // default value | 1970 0, // default value |
1914 PrefService::UNSYNCABLE_PREF); | 1971 PrefService::UNSYNCABLE_PREF); |
1915 prefs->RegisterListPref(prefs::kExtensionAllowedInstallSites, | 1972 prefs->RegisterListPref(prefs::kExtensionAllowedInstallSites, |
1916 PrefService::UNSYNCABLE_PREF); | 1973 PrefService::UNSYNCABLE_PREF); |
1917 } | 1974 } |
OLD | NEW |