Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2816)

Unified Diff: extensions/browser/api/declarative/rules_registry.cc

Issue 1158693006: Create a mechanism define declarative rules via the extension manifest. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add test Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: extensions/browser/api/declarative/rules_registry.cc
diff --git a/extensions/browser/api/declarative/rules_registry.cc b/extensions/browser/api/declarative/rules_registry.cc
index dfd9c35260ace0ea706aa383d78d355c8177e57b..bcc069b9fcb87d7ad4ce311877805d68c1a959b3 100644
--- a/extensions/browser/api/declarative/rules_registry.cc
+++ b/extensions/browser/api/declarative/rules_registry.cc
@@ -19,6 +19,7 @@
#include "content/public/browser/notification_source.h"
#include "extensions/browser/api/declarative/rules_cache_delegate.h"
#include "extensions/browser/extension_prefs.h"
+#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/state_store.h"
#include "extensions/common/extension.h"
@@ -226,9 +227,21 @@ void RulesRegistry::OnExtensionLoaded(const std::string& extension_id) {
DCHECK_CURRENTLY_ON(owner_thread());
std::vector<linked_ptr<Rule> > rules;
GetAllRules(extension_id, &rules);
- std::string error = AddRulesImpl(extension_id, rules);
- if (!error.empty())
- LOG(ERROR) << error;
+ if (rules.empty()) {
+ // If no rules have been registered yet, check if there are any rules
not at google - send to devlin 2015/06/02 22:44:50 Why only if there are no rules registered yet? It
danduong 2015/06/04 23:06:37 Done.
+ // defined in the extension manifest to add.
+ const Extension* extension =
+ ExtensionRegistry::Get(browser_context())
+ ->GetExtensionById(extension_id, ExtensionRegistry::EVERYTHING);
+ const base::ListValue* value = NULL;
+ if (extension->manifest()->GetList(event_name_, &value)) {
+ AddRules(extension_id, RulesFromValue(value));
+ }
+ } else {
+ std::string error = AddRulesImpl(extension_id, rules);
+ if (!error.empty())
+ LOG(ERROR) << error;
+ }
}
size_t RulesRegistry::GetNumberOfUsedRuleIdentifiersForTesting() const {

Powered by Google App Engine
This is Rietveld 408576698