Index: chrome/browser/extensions/extension_prefs.cc |
diff --git a/chrome/browser/extensions/extension_prefs.cc b/chrome/browser/extensions/extension_prefs.cc |
index 93378302def373cecd331cdd8b81de8a2f99dba4..6b265badda925d69509b65b0764e4a6d4b0118db 100644 |
--- a/chrome/browser/extensions/extension_prefs.cc |
+++ b/chrome/browser/extensions/extension_prefs.cc |
@@ -173,6 +173,10 @@ const char kPrefIncognitoContentSettings[] = "incognito_content_settings"; |
// background page. |
const char kRegisteredEvents[] = "events"; |
+// A dictionary of event names to lists of filters that this extension has |
+// registered from its lazy background page. |
+const char kFilteredEvents[] = "filtered_events"; |
+ |
// Persisted value for omnibox.setDefaultSuggestion. |
const char kOmniboxDefaultSuggestion[] = "omnibox_default_suggestion"; |
@@ -957,6 +961,66 @@ std::set<std::string> ExtensionPrefs::GetRegisteredEvents( |
return events; |
} |
+void ExtensionPrefs::AddFilterToEvent(const std::string& event_name, |
+ const std::string& extension_id, |
+ const DictionaryValue* filter) { |
+ const DictionaryValue* filtered_events = GetFilteredEvents(extension_id); |
+ scoped_ptr<DictionaryValue> new_filtered_events; |
+ if (!filtered_events) |
+ new_filtered_events.reset(new DictionaryValue); |
+ else |
+ new_filtered_events.reset(filtered_events->DeepCopy()); |
+ |
+ ListValue* filter_list = NULL; |
+ if (!new_filtered_events->GetList(event_name, &filter_list)) { |
+ filter_list = new ListValue(); |
+ new_filtered_events->Set(event_name, filter_list); |
+ } |
+ filter_list->Append(filter->DeepCopy()); |
+ |
+ UpdateExtensionPref(extension_id, kFilteredEvents, |
+ new_filtered_events.release()); |
battre
2012/06/19 14:26:23
What do you think of modifying the list instead of
koz (OOO until 15th September)
2012/06/20 08:05:56
Sounds good! Done.
|
+} |
+ |
+void ExtensionPrefs::RemoveFilterFromEvent(const std::string& event_name, |
+ const std::string& extension_id, |
+ const DictionaryValue* filter) { |
+ const DictionaryValue* filtered_events = GetFilteredEvents(extension_id); |
+ if (!filtered_events) |
+ return; |
+ |
+ scoped_ptr<DictionaryValue> new_filtered_events(filtered_events->DeepCopy()); |
+ ListValue* filter_list; |
+ if (!new_filtered_events->GetList(event_name, &filter_list)) |
+ return; |
+ |
+ bool removed = false; |
+ for (size_t i = 0; i < filter_list->GetSize(); i++) { |
+ DictionaryValue* filter; |
+ CHECK(filter_list->GetDictionary(i, &filter)); |
+ if (filter->Equals(filter)) { |
+ filter_list->Remove(i, NULL); |
+ removed = true; |
+ break; |
+ } |
+ } |
+ |
+ if (removed) |
+ UpdateExtensionPref(extension_id, kFilteredEvents, |
+ new_filtered_events.release()); |
+} |
+ |
+const DictionaryValue* ExtensionPrefs::GetFilteredEvents( |
+ const std::string& extension_id) { |
+ const DictionaryValue* extension = GetExtensionPref(extension_id); |
+ if (!extension) |
+ return NULL; |
+ DictionaryValue* result = NULL; |
+ if (!extension->GetDictionary(kFilteredEvents, &result)) |
+ return NULL; |
+ return result; |
+} |
+ |
void ExtensionPrefs::SetRegisteredEvents( |
const std::string& extension_id, const std::set<std::string>& events) { |
ListValue* value = new ListValue(); |