summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions/extension_prefs.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/extensions/extension_prefs.cc')
-rw-r--r--chrome/browser/extensions/extension_prefs.cc57
1 files changed, 57 insertions, 0 deletions
diff --git a/chrome/browser/extensions/extension_prefs.cc b/chrome/browser/extensions/extension_prefs.cc
index 9337830..fc523325 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,59 @@ std::set<std::string> ExtensionPrefs::GetRegisteredEvents(
return events;
}
+void ExtensionPrefs::AddFilterToEvent(const std::string& event_name,
+ const std::string& extension_id,
+ const DictionaryValue* filter) {
+ ScopedExtensionPrefUpdate update(prefs_, extension_id);
+ DictionaryValue* extension_dict = update.Get();
+ DictionaryValue* filtered_events = NULL;
+ if (!extension_dict->GetDictionary(kFilteredEvents, &filtered_events)) {
+ filtered_events = new DictionaryValue;
+ extension_dict->Set(kFilteredEvents, filtered_events);
+ }
+ ListValue* filter_list = NULL;
+ if (!filtered_events->GetList(event_name, &filter_list)) {
+ filter_list = new ListValue;
+ filtered_events->Set(event_name, filter_list);
+ }
+
+ filter_list->Append(filter->DeepCopy());
+}
+
+void ExtensionPrefs::RemoveFilterFromEvent(const std::string& event_name,
+ const std::string& extension_id,
+ const DictionaryValue* filter) {
+ ScopedExtensionPrefUpdate update(prefs_, extension_id);
+ DictionaryValue* extension_dict = update.Get();
+ DictionaryValue* filtered_events = NULL;
+
+ if (!extension_dict->GetDictionary(kFilteredEvents, &filtered_events))
+ return;
+ ListValue* filter_list = NULL;
+ if (!filtered_events->GetList(event_name, &filter_list))
+ return;
+
+ 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);
+ break;
+ }
+ }
+}
+
+const DictionaryValue* ExtensionPrefs::GetFilteredEvents(
+ const std::string& extension_id) const {
+ 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();