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..a34d0e9df55affdbb9877e6e7bd5c0ddf17675c3 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,6 +16,7 @@ |
#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 "components/url_matcher/url_matcher.h" |
#include "content/public/browser/notification_observer.h" |
#include "content/public/browser/notification_registrar.h" |
@@ -66,35 +67,25 @@ 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; |
- |
- // Applies all content rules given that a tab was just navigated. |
+ // ContentRulesRegistry: |
+ void MonitorWebContentsForRuleEvaluation( |
+ content::WebContents* contents) override; |
void DidNavigateMainFrame( |
content::WebContents* tab, |
const content::LoadCommittedDetails& details, |
const content::FrameNavigateParams& params) override; |
- // Applies all content rules given that a tab was just navigated on the |
- // original context. Only invoked on the OffTheRecord registry instance. |tab| |
- // is owned by the original context, not this one. |
- void DidNavigateMainFrameOfOriginalContext( |
- content::WebContents* tab, |
- 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,14 +94,31 @@ 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; |
+ // 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); |
+ |
+ // Returns the number of active rules. |
+ size_t GetActiveRulesCountForTesting(); |
+ |
protected: |
~ChromeContentRulesRegistry() override; |
@@ -119,27 +127,15 @@ class ChromeContentRulesRegistry : public ContentRulesRegistry, |
const std::string& extension_id) const; |
private: |
- friend class DeclarativeChromeContentRulesRegistryTest; |
- |
// 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 +148,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_|. |
@@ -162,23 +156,22 @@ class ChromeContentRulesRegistry : public ContentRulesRegistry, |
RulesMap content_rules_; |
// Maps a WebContents to the set of rules that match on that WebContents. |
- // This lets us call Revert as appropriate. |
+ // This lets us call Revert as appropriate. Note that this is expected to have |
+ // a key-value pair for every WebContents the registry is tracking, even if |
+ // the value is the empty set. |
std::map<content::WebContents*, std::set<const ContentRule*>> active_rules_; |
// 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); |
}; |