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

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

Issue 11547033: Implement declarativeContent API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync Created 7 years, 11 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_CONTENT_CONTENT_RULES_REGISTRY _H_
6 #define CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_CONTENT_CONTENT_RULES_REGISTRY _H_
7
8 #include <map>
9 #include <set>
vabr (Chromium) 2013/01/23 12:32:56 Lint: add #include for string.
Jeffrey Yasskin 2013/01/23 22:13:17 Done.
10 #include <vector>
11
12 #include "base/memory/linked_ptr.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/time.h"
15 #include "chrome/browser/extensions/api/declarative/declarative_rule.h"
16 #include "chrome/browser/extensions/api/declarative/rules_registry_with_cache.h"
17 #include "chrome/browser/extensions/api/declarative_content/content_action.h"
18 #include "chrome/browser/extensions/api/declarative_content/content_condition.h"
19 #include "chrome/browser/extensions/extension_info_map.h"
20 #include "chrome/common/extensions/matcher/url_matcher.h"
21 #include "content/public/browser/notification_observer.h"
22 #include "content/public/browser/notification_registrar.h"
23
24 class Profile;
25 class ContentPermissions;
26
27 namespace content {
28 class RenderProcessHost;
29 class WebContents;
30 struct FrameNavigateParams;
31 struct LoadCommittedDetails;
32 }
33
34 namespace extension_web_request_api_helpers {
35 struct EventResponseDelta;
36 }
37
38 namespace net {
39 class URLRequest;
40 }
41
42 namespace extensions {
43
44 class RulesRegistryService;
45
46 typedef DeclarativeRule<ContentCondition, ContentAction> ContentRule;
47
48 // The ContentRulesRegistry is responsible for managing
49 // the internal representation of rules for the Declarative Content API.
50 //
51 // Here is the high level overview of this functionality:
52 //
53 // RulesRegistry::Rule consists of Conditions and Actions, these are
54 // represented as a ContentRule with ContentConditions and
55 // ContentRuleActions.
56 //
57 // The evaluation of URL related condition attributes (host_suffix, path_prefix)
58 // is delegated to a URLMatcher, because this is capable of evaluating many
59 // of such URL related condition attributes in parallel.
60 class ContentRulesRegistry : public RulesRegistryWithCache,
61 public content::NotificationObserver {
62 public:
63 ContentRulesRegistry(Profile* profile, Delegate* delegate);
64
65 // Applies all content rules given an update (CSS match change or
66 // page navigation, for now) from the renderer.
67 void Apply(content::WebContents* contents,
68 const std::vector<std::string>& matching_css_selectors);
69
70 // Applies all content rules given that a tab was just navigated.
71 void DidNavigateMainFrame(content::WebContents* tab,
72 const content::LoadCommittedDetails& details,
73 const content::FrameNavigateParams& params);
74
75 // Implementation of RulesRegistryWithCache:
76 virtual std::string AddRulesImpl(
77 const std::string& extension_id,
78 const std::vector<linked_ptr<RulesRegistry::Rule> >& rules) OVERRIDE;
79 virtual std::string RemoveRulesImpl(
80 const std::string& extension_id,
81 const std::vector<std::string>& rule_identifiers) OVERRIDE;
82 virtual std::string RemoveAllRulesImpl(
83 const std::string& extension_id) OVERRIDE;
84 virtual content::BrowserThread::ID GetOwnerThread() const OVERRIDE;
85
86 // content::NotificationObserver implementation.
87 virtual void Observe(int type,
88 const content::NotificationSource& source,
89 const content::NotificationDetails& details) OVERRIDE;
90
91 // Returns true if this object retains no allocated data. Only for debugging.
92 bool IsEmpty() const;
93
94 protected:
95 virtual ~ContentRulesRegistry();
96
97 // Virtual for testing:
98 virtual base::Time GetExtensionInstallationTime(
99 const std::string& extension_id) const;
100
101 private:
102 std::set<ContentRule*>
103 GetMatches(const RendererContentMatchData& renderer_data);
104
105 // Scans the rules for the set of conditions they're watching. If the set has
106 // changed, calls InstructRenderProcess() for each RenderProcessHost in the
107 // current profile.
108 void UpdateConditionCache();
109
110 // Tells a renderer what page attributes to watch for using an
111 // ExtensionMsg_WatchPages.
112 void InstructRenderProcess(content::RenderProcessHost* process);
113
114 typedef std::map<URLMatcherConditionSet::ID, ContentRule*> URLMatcherIdToRule;
115 typedef std::map<ContentRule::GlobalRuleId, linked_ptr<ContentRule> >
116 RulesMap;
117
118 Profile* const profile_;
119
120 // Map that tells us which ContentRules may match under the condition that
121 // the URLMatcherConditionSet::ID was returned by the |url_matcher_|.
122 URLMatcherIdToRule match_id_to_rule_;
123
124 RulesMap content_rules_;
125
126 // Maps tab_id to the set of rules that match on that tab. This
127 // lets us call Revert as appropriate.
128 std::map<int, std::set<ContentRule*> > active_rules_;
129
130 // Matches URLs for the page_url condition.
131 URLMatcher url_matcher_;
132
133 // All CSS selectors any rule's conditions watch for.
134 std::vector<std::string> watched_css_selectors_;
135
136 // Manages our notification registrations.
137 content::NotificationRegistrar registrar_;
138
139 scoped_refptr<ExtensionInfoMap> extension_info_map_;
140 };
141
142 } // namespace extensions
143
144 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_CONTENT_CONTENT_RULES_REGIS TRY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698