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

Unified Diff: chrome/browser/extensions/api/declarative/rules_registry_service.cc

Issue 344433003: Prepare declarativeContent API for new script injection feature. Added Javascript types and functio… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add note about what it means to revert RequestContentScript Created 6 years, 6 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: 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 7e99d994c3ac5a3f324c02dd79c41fa326efcb78..af049decf4271ae0477531faf6597424e3889fd2 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_));
@@ -88,15 +91,43 @@ void RulesRegistryService::EnsureDefaultRulesRegistriesRegistered(
profile_, webview_key, web_request_rules_registry));
#if defined(ENABLE_EXTENSIONS)
- // Only create a ContentRulesRegistry for regular pages and not webviews.
+ // Only create content rules registries 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> >
+ 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()));
+ }
}
#endif // defined(ENABLE_EXTENSIONS)
}
@@ -151,6 +182,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);

Powered by Google App Engine
This is Rietveld 408576698