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

Side by Side Diff: chrome/browser/extensions/api/declarative_content/chrome_content_rules_registry.h

Issue 590573002: Remove ContentRulesRegistry dependence from RulesRegistryService. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rename to CreateContentRulesRegistry. Created 6 years, 3 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_CONTENT_CONTENT_RULES_REGISTRY _H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_CONTENT_CHROME_CONTENT_RULES_R EGISTRY_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_CONTENT_CONTENT_RULES_REGISTRY _H_ 6 #define CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_CONTENT_CHROME_CONTENT_RULES_R EGISTRY_H_
7 7
8 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/memory/linked_ptr.h" 13 #include "base/memory/linked_ptr.h"
14 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
15 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
16 #include "base/time/time.h" 16 #include "base/time/time.h"
17 #include "chrome/browser/extensions/api/declarative_content/content_action.h" 17 #include "chrome/browser/extensions/api/declarative_content/content_action.h"
18 #include "chrome/browser/extensions/api/declarative_content/content_condition.h" 18 #include "chrome/browser/extensions/api/declarative_content/content_condition.h"
19 #include "components/url_matcher/url_matcher.h" 19 #include "components/url_matcher/url_matcher.h"
20 #include "content/public/browser/notification_observer.h" 20 #include "content/public/browser/notification_observer.h"
21 #include "content/public/browser/notification_registrar.h" 21 #include "content/public/browser/notification_registrar.h"
22 #include "extensions/browser/api/declarative/declarative_rule.h" 22 #include "extensions/browser/api/declarative/declarative_rule.h"
23 #include "extensions/browser/api/declarative/rules_registry.h" 23 #include "extensions/browser/api/declarative_content/content_rules_registry.h"
24 #include "extensions/browser/info_map.h" 24 #include "extensions/browser/info_map.h"
25 25
26 class ContentPermissions; 26 class ContentPermissions;
27 27
28 namespace content { 28 namespace content {
29 class BrowserContext; 29 class BrowserContext;
30 class RenderProcessHost; 30 class RenderProcessHost;
31 class WebContents; 31 class WebContents;
32 struct FrameNavigateParams; 32 struct FrameNavigateParams;
33 struct LoadCommittedDetails; 33 struct LoadCommittedDetails;
34 } 34 }
35 35
36 namespace extension_web_request_api_helpers { 36 namespace extension_web_request_api_helpers {
37 struct EventResponseDelta; 37 struct EventResponseDelta;
38 } 38 }
39 39
40 namespace net { 40 namespace net {
41 class URLRequest; 41 class URLRequest;
42 } 42 }
43 43
44 namespace extensions { 44 namespace extensions {
45 45
46 class RulesRegistryService; 46 class RulesRegistryService;
47 47
48 typedef DeclarativeRule<ContentCondition, ContentAction> ContentRule; 48 typedef DeclarativeRule<ContentCondition, ContentAction> ContentRule;
49 49
50 // The ContentRulesRegistry is responsible for managing 50 // The ChromeContentRulesRegistry is responsible for managing
51 // the internal representation of rules for the Declarative Content API. 51 // the internal representation of rules for the Declarative Content API.
52 // 52 //
53 // Here is the high level overview of this functionality: 53 // Here is the high level overview of this functionality:
54 // 54 //
55 // RulesRegistry::Rule consists of Conditions and Actions, these are 55 // RulesRegistry::Rule consists of Conditions and Actions, these are
56 // represented as a ContentRule with ContentConditions and 56 // represented as a ContentRule with ContentConditions and
57 // ContentRuleActions. 57 // ContentRuleActions.
58 // 58 //
59 // The evaluation of URL related condition attributes (host_suffix, path_prefix) 59 // The evaluation of URL related condition attributes (host_suffix, path_prefix)
60 // is delegated to a URLMatcher, because this is capable of evaluating many 60 // is delegated to a URLMatcher, because this is capable of evaluating many
61 // of such URL related condition attributes in parallel. 61 // of such URL related condition attributes in parallel.
62 class ContentRulesRegistry : public RulesRegistry, 62 class ChromeContentRulesRegistry : public ContentRulesRegistry,
63 public content::NotificationObserver { 63 public content::NotificationObserver {
64 public: 64 public:
65 // For testing, |ui_part| can be NULL. In that case it constructs the 65 // For testing, |ui_part| can be NULL. In that case it constructs the
66 // registry with storage functionality suspended. 66 // registry with storage functionality suspended.
67 ContentRulesRegistry(content::BrowserContext* browser_context, 67 ChromeContentRulesRegistry(content::BrowserContext* browser_context,
68 RulesCacheDelegate* cache_delegate); 68 RulesCacheDelegate* cache_delegate);
69 69
70 // ChromeContentRulesRegistryIntermediary implementation:
Ken Rockot(use gerrit already) 2014/09/23 16:13:40 nit: Update comment.
70 // Applies all content rules given an update (CSS match change or 71 // Applies all content rules given an update (CSS match change or
71 // page navigation, for now) from the renderer. 72 // page navigation, for now) from the renderer.
72 void Apply(content::WebContents* contents, 73 virtual void Apply(
73 const std::vector<std::string>& matching_css_selectors); 74 content::WebContents* contents,
75 const std::vector<std::string>& matching_css_selectors) OVERRIDE;
74 76
75 // Applies all content rules given that a tab was just navigated. 77 // Applies all content rules given that a tab was just navigated.
76 void DidNavigateMainFrame(content::WebContents* tab, 78 virtual void DidNavigateMainFrame(
77 const content::LoadCommittedDetails& details, 79 content::WebContents* tab,
78 const content::FrameNavigateParams& params); 80 const content::LoadCommittedDetails& details,
81 const content::FrameNavigateParams& params) OVERRIDE;
79 82
80 // Implementation of RulesRegistry: 83 // Implementation of RulesRegistry:
81 virtual std::string AddRulesImpl( 84 virtual std::string AddRulesImpl(
82 const std::string& extension_id, 85 const std::string& extension_id,
83 const std::vector<linked_ptr<RulesRegistry::Rule> >& rules) OVERRIDE; 86 const std::vector<linked_ptr<RulesRegistry::Rule> >& rules) OVERRIDE;
84 virtual std::string RemoveRulesImpl( 87 virtual std::string RemoveRulesImpl(
85 const std::string& extension_id, 88 const std::string& extension_id,
86 const std::vector<std::string>& rule_identifiers) OVERRIDE; 89 const std::vector<std::string>& rule_identifiers) OVERRIDE;
87 virtual std::string RemoveAllRulesImpl( 90 virtual std::string RemoveAllRulesImpl(
88 const std::string& extension_id) OVERRIDE; 91 const std::string& extension_id) OVERRIDE;
89 92
90 // content::NotificationObserver implementation. 93 // content::NotificationObserver implementation.
91 virtual void Observe(int type, 94 virtual void Observe(int type,
92 const content::NotificationSource& source, 95 const content::NotificationSource& source,
93 const content::NotificationDetails& details) OVERRIDE; 96 const content::NotificationDetails& details) OVERRIDE;
94 97
95 // Returns true if this object retains no allocated data. Only for debugging. 98 // Returns true if this object retains no allocated data. Only for debugging.
96 bool IsEmpty() const; 99 bool IsEmpty() const;
97 100
98 protected: 101 protected:
99 virtual ~ContentRulesRegistry(); 102 virtual ~ChromeContentRulesRegistry();
100 103
101 // Virtual for testing: 104 // Virtual for testing:
102 virtual base::Time GetExtensionInstallationTime( 105 virtual base::Time GetExtensionInstallationTime(
103 const std::string& extension_id) const; 106 const std::string& extension_id) const;
104 107
105 private: 108 private:
106 friend class DeclarativeContentRulesRegistryTest; 109 friend class DeclarativeChromeContentRulesRegistryTest;
107 110
108 std::set<ContentRule*> 111 std::set<ContentRule*> GetMatches(
109 GetMatches(const RendererContentMatchData& renderer_data) const; 112 const RendererContentMatchData& renderer_data) const;
110 113
111 // Scans the rules for the set of conditions they're watching. If the set has 114 // Scans the rules for the set of conditions they're watching. If the set has
112 // changed, calls InstructRenderProcess() for each RenderProcessHost in the 115 // changed, calls InstructRenderProcess() for each RenderProcessHost in the
113 // current browser_context. 116 // current browser_context.
114 void UpdateConditionCache(); 117 void UpdateConditionCache();
115 118
116 // Tells a renderer what page attributes to watch for using an 119 // Tells a renderer what page attributes to watch for using an
117 // ExtensionMsg_WatchPages. 120 // ExtensionMsg_WatchPages.
118 void InstructRenderProcess(content::RenderProcessHost* process); 121 void InstructRenderProcess(content::RenderProcessHost* process);
119 122
(...skipping 16 matching lines...) Expand all
136 url_matcher::URLMatcher url_matcher_; 139 url_matcher::URLMatcher url_matcher_;
137 140
138 // All CSS selectors any rule's conditions watch for. 141 // All CSS selectors any rule's conditions watch for.
139 std::vector<std::string> watched_css_selectors_; 142 std::vector<std::string> watched_css_selectors_;
140 143
141 // Manages our notification registrations. 144 // Manages our notification registrations.
142 content::NotificationRegistrar registrar_; 145 content::NotificationRegistrar registrar_;
143 146
144 scoped_refptr<InfoMap> extension_info_map_; 147 scoped_refptr<InfoMap> extension_info_map_;
145 148
146 DISALLOW_COPY_AND_ASSIGN(ContentRulesRegistry); 149 DISALLOW_COPY_AND_ASSIGN(ChromeContentRulesRegistry);
147 }; 150 };
148 151
149 } // namespace extensions 152 } // namespace extensions
150 153
151 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_CONTENT_CONTENT_RULES_REGIS TRY_H_ 154 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_CONTENT_CHROME_CONTENT_RULE S_REGISTRY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698