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

Unified Diff: chrome/browser/extensions/api/declarative_content/chrome_content_rules_registry.h

Issue 1159733004: Encapsulate CSS selector declarative content condition tracking (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@stars-declarative-content-range-for
Patch Set: iwyu 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: chrome/browser/extensions/api/declarative_content/chrome_content_rules_registry.h
diff --git a/chrome/browser/extensions/api/declarative_content/chrome_content_rules_registry.h b/chrome/browser/extensions/api/declarative_content/chrome_content_rules_registry.h
index 316fc9e4c8ea227eb716fdaf80aefd02d6f62ec2..f8964c9f0c81f794c5def0409835a1b116e9caa7 100644
--- a/chrome/browser/extensions/api/declarative_content/chrome_content_rules_registry.h
+++ b/chrome/browser/extensions/api/declarative_content/chrome_content_rules_registry.h
@@ -16,10 +16,11 @@
#include "base/time/time.h"
#include "chrome/browser/extensions/api/declarative_content/content_action.h"
#include "chrome/browser/extensions/api/declarative_content/content_condition.h"
+#include "chrome/browser/extensions/api/declarative_content/declarative_content_css_condition_tracker.h"
+#include "chrome/browser/extensions/api/declarative_content/declarative_content_rule.h"
#include "components/url_matcher/url_matcher.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
-#include "extensions/browser/api/declarative/declarative_rule.h"
#include "extensions/browser/api/declarative_content/content_rules_registry.h"
#include "extensions/browser/info_map.h"
@@ -45,7 +46,7 @@ namespace extensions {
class RulesRegistryService;
-typedef DeclarativeRule<ContentCondition, ContentAction> ContentRule;
+typedef DeclarativeContentRule ContentRule;
not at google - send to devlin 2015/06/01 22:51:11 Yeah, again we should try to delete this typedef i
// The ChromeContentRulesRegistry is responsible for managing
// the internal representation of rules for the Declarative Content API.
@@ -66,20 +67,26 @@ typedef DeclarativeRule<ContentCondition, ContentAction> ContentRule;
// side of split-mode extensions to incognito tabs. The non-incognito instance
// handles incognito tabs for spanning-mode extensions, plus all non-incognito
// tabs.
-class ChromeContentRulesRegistry : public ContentRulesRegistry,
- public content::NotificationObserver {
+class ChromeContentRulesRegistry
+ : public ContentRulesRegistry,
+ public content::NotificationObserver,
+ public DeclarativeContentCssConditionTrackerDelegate {
public:
// For testing, |ui_part| can be NULL. In that case it constructs the
// registry with storage functionality suspended.
ChromeContentRulesRegistry(content::BrowserContext* browser_context,
RulesCacheDelegate* cache_delegate);
- // ChromeContentRulesRegistry implementation:
- // Applies all content rules given an update (CSS match change or
- // page navigation, for now) from the renderer.
- void Apply(content::WebContents* contents,
- const std::vector<std::string>& matching_css_selectors) override;
+ // TODO(wittman): Remove once DeclarativeChromeContentRulesRegistry no longer
+ // depends on concrete condition implementations. At that point
+ // DeclarativeChromeContentRulesRegistryTest.ActiveRulesDoesntGrow will be
+ // able to use a test condition object and not need to depend on force setting
+ // matching CSS seleectors.
+ void UpdateMatchingCssSelectorsForTesting(
+ content::WebContents* contents,
+ const std::vector<std::string>& matching_css_selectors);
+ // ContentRulesRegistry:
// Applies all content rules given that a tab was just navigated.
void DidNavigateMainFrame(
content::WebContents* tab,
@@ -94,7 +101,7 @@ class ChromeContentRulesRegistry : public ContentRulesRegistry,
const content::LoadCommittedDetails& details,
const content::FrameNavigateParams& params) override;
- // Implementation of RulesRegistry:
+ // RulesRegistry:
std::string AddRulesImpl(
const std::string& extension_id,
const std::vector<linked_ptr<RulesRegistry::Rule>>& rules) override;
@@ -103,11 +110,16 @@ class ChromeContentRulesRegistry : public ContentRulesRegistry,
const std::vector<std::string>& rule_identifiers) override;
std::string RemoveAllRulesImpl(const std::string& extension_id) override;
- // content::NotificationObserver implementation.
+ // content::NotificationObserver:
void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) override;
+ // DeclarativeContentCssConditionTrackerDelegate:
+ void RequestEvaluation(content::WebContents* contents) override;
+ bool ShouldManageConditionsForBrowserContext(
+ content::BrowserContext* context) override;
+
// Returns true if this object retains no allocated data. Only for debugging.
bool IsEmpty() const;
@@ -124,22 +136,12 @@ class ChromeContentRulesRegistry : public ContentRulesRegistry,
// True if this object is managing the rules for |context|.
bool ManagingRulesForBrowserContext(content::BrowserContext* context);
- // Applies all content rules given that a tab was just navigated.
- void OnTabNavigation(content::WebContents* tab, bool is_in_page_navigation);
-
std::set<const ContentRule*> GetMatches(
const RendererContentMatchData& renderer_data,
bool is_incognito_renderer) const;
- // Scans the rules for the set of conditions they're watching. If the set has
- // changed, calls InstructRenderProcess() for each RenderProcessHost in the
- // current browser_context.
- void UpdateConditionCache();
-
- // If the renderer process is associated with our browser context, tells it
- // what page attributes to watch for using an ExtensionMsg_WatchPages.
- void InstructRenderProcessIfSameBrowserContext(
- content::RenderProcessHost* process);
+ // Updates the condition evaluator with the current watched CSS selectors.
+ void UpdateCssSelectorsFromRules();
// Evaluates the conditions for |tab| based on the tab state and matching CSS
// selectors.
@@ -152,8 +154,6 @@ class ChromeContentRulesRegistry : public ContentRulesRegistry,
URLMatcherIdToRule;
typedef std::map<ContentRule::GlobalRuleId, linked_ptr<const ContentRule>>
RulesMap;
- typedef std::map<content::WebContents*, std::vector<std::string>>
- CssSelectors;
// Map that tells us which ContentRules may match under the condition that
// the URLMatcherConditionSet::ID was returned by the |url_matcher_|.
@@ -168,17 +168,14 @@ class ChromeContentRulesRegistry : public ContentRulesRegistry,
// Matches URLs for the page_url condition.
url_matcher::URLMatcher url_matcher_;
- // All CSS selectors any rule's conditions watch for.
- std::vector<std::string> watched_css_selectors_;
+ // Responsible for evaluating the declarative content conditions.
+ DeclarativeContentCssConditionTracker css_condition_tracker_;
// Manages our notification registrations.
content::NotificationRegistrar registrar_;
scoped_refptr<InfoMap> extension_info_map_;
- // Maps tab_id to the matching CSS selectors for the tab.
- CssSelectors matching_css_selectors_;
-
DISALLOW_COPY_AND_ASSIGN(ChromeContentRulesRegistry);
};

Powered by Google App Engine
This is Rietveld 408576698