Chromium Code Reviews| Index: chrome/browser/extensions/extension_prefs.cc |
| diff --git a/chrome/browser/extensions/extension_prefs.cc b/chrome/browser/extensions/extension_prefs.cc |
| index 41c10171a5dee562a3c3b21bb4a7450a7e186720..034f442c965562cff449afb055f45ccf7218fcf6 100644 |
| --- a/chrome/browser/extensions/extension_prefs.cc |
| +++ b/chrome/browser/extensions/extension_prefs.cc |
| @@ -171,6 +171,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"; |
| + |
| // A list of alarms that this extension has set. |
| const char kRegisteredAlarms[] = "alarms"; |
| const char kAlarmScheduledRunTime[] = "scheduled_run_time"; |
| @@ -947,6 +951,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; |
|
battre
2012/06/13 09:21:54
initialize to NULL
koz (OOO until 15th September)
2012/06/14 02:15:55
Done.
|
| + 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()); |
| +} |
| + |
| +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; |
|
battre
2012/06/13 09:21:54
initialize to NULL.
koz (OOO until 15th September)
2012/06/14 02:15:55
Done.
|
| + 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(); |