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

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

Powered by Google App Engine
This is Rietveld 408576698