Chromium Code Reviews| Index: chrome/browser/extensions/api/declarative/rules_registry_service.cc |
| diff --git a/chrome/browser/extensions/api/declarative/rules_registry_service.cc b/chrome/browser/extensions/api/declarative/rules_registry_service.cc |
| index 7f3d12fee0f2efde60eb87a83bd28c19c1504a05..41afebbe12b80f7b3c56645911ee16a11831008b 100644 |
| --- a/chrome/browser/extensions/api/declarative/rules_registry_service.cc |
| +++ b/chrome/browser/extensions/api/declarative/rules_registry_service.cc |
| @@ -4,12 +4,15 @@ |
| #include "chrome/browser/extensions/api/declarative/rules_registry_service.h" |
| +#include <utility> |
| + |
| #include "base/bind.h" |
| #include "base/lazy_instance.h" |
| #include "base/logging.h" |
| #include "base/memory/scoped_ptr.h" |
| #include "chrome/browser/chrome_notification_types.h" |
| #include "chrome/browser/extensions/api/declarative/rules_cache_delegate.h" |
| +#include "chrome/browser/extensions/api/declarative_content/content_constants.h" |
| #include "chrome/browser/extensions/api/declarative_content/content_rules_registry.h" |
| #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_constants.h" |
| #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_registry.h" |
| @@ -22,6 +25,7 @@ |
| #include "content/public/browser/render_process_host.h" |
| #include "extensions/browser/extension_registry.h" |
| #include "extensions/common/extension.h" |
| +#include "extensions/common/watched_pages_recipient.h" |
| namespace extensions { |
| @@ -43,8 +47,7 @@ bool IsWebView(const RulesRegistryService::WebViewKey& webview_key) { |
| } // namespace |
| RulesRegistryService::RulesRegistryService(content::BrowserContext* context) |
| - : content_rules_registry_(NULL), |
| - extension_registry_observer_(this), |
| + : extension_registry_observer_(this), |
| profile_(Profile::FromBrowserContext(context)) { |
| if (profile_) { |
| extension_registry_observer_.Add(ExtensionRegistry::Get(profile_)); |
| @@ -89,13 +92,41 @@ void RulesRegistryService::EnsureDefaultRulesRegistriesRegistered( |
| // Only create a ContentRulesRegistry for regular pages and not webviews. |
| if (!IsWebView(webview_key)) { |
| - RulesCacheDelegate* content_rules_cache_delegate = |
| - new RulesCacheDelegate(false /*log_storage_init_delay*/); |
| - cache_delegates_.push_back(content_rules_cache_delegate); |
| - scoped_refptr<ContentRulesRegistry> content_rules_registry( |
| - new ContentRulesRegistry(profile_, content_rules_cache_delegate)); |
| - RegisterRulesRegistry(content_rules_registry); |
| - content_rules_registry_ = content_rules_registry.get(); |
| + namespace dcc = declarative_content_constants; |
| + typedef std::vector< std::pair<std::string, WatchedPagesRecipient> > |
|
Jeffrey Yasskin
2014/06/27 22:03:41
For something with a constant set of elements, I'd
Mark Dittmer
2014/06/30 12:34:02
Done.
|
| + ContentRegistryIDList; |
| + ContentRegistryIDList content_registry_ids; |
| + |
| + // onPageChanged supports browser-side ShowPageAction. Browser-side rules |
| + // registry must be notified. |
| + content_registry_ids.push_back( |
| + std::make_pair(dcc::kOnPageChanged, CONTENT_RULES_REGISTRY)); |
| + |
| + // onDocument- Start/End/Idle supports renderer-side RequestContentScript. |
| + // Renderer-side user script manager must be notified. |
| + content_registry_ids.push_back( |
| + std::make_pair(dcc::kOnDocumentStart, USER_SCRIPT_MANAGER)); |
| + content_registry_ids.push_back( |
| + std::make_pair(dcc::kOnDocumentEnd, USER_SCRIPT_MANAGER)); |
| + content_registry_ids.push_back( |
| + std::make_pair(dcc::kOnDocumentIdle, USER_SCRIPT_MANAGER)); |
| + |
| + for (ContentRegistryIDList::const_iterator it = |
| + content_registry_ids.begin(); |
| + it != content_registry_ids.end(); ++it) { |
| + RulesCacheDelegate* content_rules_cache_delegate = |
| + new RulesCacheDelegate(false /*log_storage_init_delay*/); |
| + cache_delegates_.push_back(content_rules_cache_delegate); |
| + scoped_refptr<ContentRulesRegistry> content_rules_registry( |
| + new ContentRulesRegistry(profile_, |
| + it->first, // event_name. |
| + it->second, // watched_pages_recipient. |
| + content_rules_cache_delegate)); |
| + RegisterRulesRegistry(content_rules_registry); |
| + content_rules_registry_map_.insert( |
| + std::make_pair(it->first, // event_name. |
| + content_rules_registry.get())); |
|
Jeffrey Yasskin
2014/06/27 22:03:41
This is going to use the registry after it's been
Mark Dittmer
2014/06/30 11:50:35
How is this different from how the code was before
Jeffrey Yasskin
2014/07/15 17:12:58
Whoops, you're right. Never mind.
|
| + } |
| } |
| } |
| @@ -149,6 +180,17 @@ scoped_refptr<RulesRegistry> RulesRegistryService::GetRulesRegistry( |
| return i->second; |
| } |
| +ContentRulesRegistry* RulesRegistryService::GetContentRulesRegistry( |
| + const std::string& event_name) { |
| + ContentRulesRegistryMap::iterator it = |
| + content_rules_registry_map_.find(event_name); |
| + if (it == content_rules_registry_map_.end()) |
| + return NULL; |
| + |
| + return content_rules_registry_map_[event_name]; |
| +} |
| + |
| + |
| void RulesRegistryService::RemoveWebViewRulesRegistries(int process_id) { |
| DCHECK_NE(0, process_id); |