| 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..1d0e6fdc469e2f07228dcd59a4ab341f1cc2f9f1 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 = 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());
|
| +}
|
| +
|
| +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();
|
|
|