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

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

Issue 590573002: Remove ContentRulesRegistry dependence from RulesRegistryService. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix comment. Created 6 years, 2 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 #include "chrome/browser/extensions/api/declarative_content/content_rules_regist ry.h" 5 #include "chrome/browser/extensions/api/declarative_content/chrome_content_rules _registry.h"
6 6
7 #include "chrome/browser/chrome_notification_types.h" 7 #include "chrome/browser/chrome_notification_types.h"
8 #include "chrome/browser/extensions/api/declarative_content/content_action.h" 8 #include "chrome/browser/extensions/api/declarative_content/content_action.h"
9 #include "chrome/browser/extensions/api/declarative_content/content_condition.h" 9 #include "chrome/browser/extensions/api/declarative_content/content_condition.h"
10 #include "chrome/browser/extensions/api/declarative_content/content_constants.h" 10 #include "chrome/browser/extensions/api/declarative_content/content_constants.h"
11 #include "chrome/browser/extensions/extension_tab_util.h" 11 #include "chrome/browser/extensions/extension_tab_util.h"
12 #include "content/public/browser/navigation_details.h" 12 #include "content/public/browser/navigation_details.h"
13 #include "content/public/browser/notification_service.h" 13 #include "content/public/browser/notification_service.h"
14 #include "content/public/browser/notification_source.h" 14 #include "content/public/browser/notification_source.h"
15 #include "content/public/browser/render_process_host.h" 15 #include "content/public/browser/render_process_host.h"
16 #include "content/public/browser/web_contents.h" 16 #include "content/public/browser/web_contents.h"
17 #include "extensions/browser/extension_registry.h" 17 #include "extensions/browser/extension_registry.h"
18 #include "extensions/browser/extension_system.h" 18 #include "extensions/browser/extension_system.h"
19 #include "extensions/common/extension_messages.h" 19 #include "extensions/common/extension_messages.h"
20 20
21 using url_matcher::URLMatcherConditionSet; 21 using url_matcher::URLMatcherConditionSet;
22 22
23 namespace extensions { 23 namespace extensions {
24 24
25 ContentRulesRegistry::ContentRulesRegistry( 25 ChromeContentRulesRegistry::ChromeContentRulesRegistry(
26 content::BrowserContext* browser_context, 26 content::BrowserContext* browser_context,
27 RulesCacheDelegate* cache_delegate) 27 RulesCacheDelegate* cache_delegate)
28 : RulesRegistry(browser_context, 28 : ContentRulesRegistry(browser_context,
29 declarative_content_constants::kOnPageChanged, 29 declarative_content_constants::kOnPageChanged,
30 content::BrowserThread::UI, 30 content::BrowserThread::UI,
31 cache_delegate, 31 cache_delegate,
32 WebViewKey(0, 0)) { 32 WebViewKey(0, 0)) {
33 extension_info_map_ = ExtensionSystem::Get(browser_context)->info_map(); 33 extension_info_map_ = ExtensionSystem::Get(browser_context)->info_map();
34 34
35 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CREATED, 35 registrar_.Add(this,
36 content::NOTIFICATION_RENDERER_PROCESS_CREATED,
36 content::NotificationService::AllBrowserContextsAndSources()); 37 content::NotificationService::AllBrowserContextsAndSources());
37 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, 38 registrar_.Add(this,
39 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
38 content::NotificationService::AllBrowserContextsAndSources()); 40 content::NotificationService::AllBrowserContextsAndSources());
39 } 41 }
40 42
41 void ContentRulesRegistry::Observe( 43 void ChromeContentRulesRegistry::Observe(
42 int type, 44 int type,
43 const content::NotificationSource& source, 45 const content::NotificationSource& source,
44 const content::NotificationDetails& details) { 46 const content::NotificationDetails& details) {
45 switch (type) { 47 switch (type) {
46 case content::NOTIFICATION_RENDERER_PROCESS_CREATED: { 48 case content::NOTIFICATION_RENDERER_PROCESS_CREATED: {
47 content::RenderProcessHost* process = 49 content::RenderProcessHost* process =
48 content::Source<content::RenderProcessHost>(source).ptr(); 50 content::Source<content::RenderProcessHost>(source).ptr();
49 if (process->GetBrowserContext() == browser_context()) 51 if (process->GetBrowserContext() == browser_context())
50 InstructRenderProcess(process); 52 InstructRenderProcess(process);
51 break; 53 break;
52 } 54 }
53 case content::NOTIFICATION_WEB_CONTENTS_DESTROYED: { 55 case content::NOTIFICATION_WEB_CONTENTS_DESTROYED: {
54 content::WebContents* tab = 56 content::WebContents* tab =
55 content::Source<content::WebContents>(source).ptr(); 57 content::Source<content::WebContents>(source).ptr();
56 // GetTabId() returns -1 for non-tab WebContents, which won't be 58 // GetTabId() returns -1 for non-tab WebContents, which won't be
57 // in the map. Similarly, tabs from other browser_contexts won't be in 59 // in the map. Similarly, tabs from other browser_contexts won't be in
58 // the map. 60 // the map.
59 active_rules_.erase(ExtensionTabUtil::GetTabId(tab)); 61 active_rules_.erase(ExtensionTabUtil::GetTabId(tab));
60 break; 62 break;
61 } 63 }
62 } 64 }
63 } 65 }
64 66
65 void ContentRulesRegistry::Apply( 67 void ChromeContentRulesRegistry::Apply(
66 content::WebContents* contents, 68 content::WebContents* contents,
67 const std::vector<std::string>& matching_css_selectors) { 69 const std::vector<std::string>& matching_css_selectors) {
68 const int tab_id = ExtensionTabUtil::GetTabId(contents); 70 const int tab_id = ExtensionTabUtil::GetTabId(contents);
69 RendererContentMatchData renderer_data; 71 RendererContentMatchData renderer_data;
70 renderer_data.page_url_matches = url_matcher_.MatchURL(contents->GetURL()); 72 renderer_data.page_url_matches = url_matcher_.MatchURL(contents->GetURL());
71 renderer_data.css_selectors.insert(matching_css_selectors.begin(), 73 renderer_data.css_selectors.insert(matching_css_selectors.begin(),
72 matching_css_selectors.end()); 74 matching_css_selectors.end());
73 std::set<ContentRule*> matching_rules = GetMatches(renderer_data); 75 std::set<ContentRule*> matching_rules = GetMatches(renderer_data);
74 if (matching_rules.empty() && !ContainsKey(active_rules_, tab_id)) 76 if (matching_rules.empty() && !ContainsKey(active_rules_, tab_id))
75 return; 77 return;
76 78
77 std::set<ContentRule*>& prev_matching_rules = active_rules_[tab_id]; 79 std::set<ContentRule*>& prev_matching_rules = active_rules_[tab_id];
78 ContentAction::ApplyInfo apply_info = { 80 ContentAction::ApplyInfo apply_info = {browser_context(), contents};
79 browser_context(), contents
80 };
81 for (std::set<ContentRule*>::const_iterator it = matching_rules.begin(); 81 for (std::set<ContentRule*>::const_iterator it = matching_rules.begin();
82 it != matching_rules.end(); ++it) { 82 it != matching_rules.end();
83 ++it) {
83 apply_info.priority = (*it)->priority(); 84 apply_info.priority = (*it)->priority();
84 if (!ContainsKey(prev_matching_rules, *it)) { 85 if (!ContainsKey(prev_matching_rules, *it)) {
85 (*it)->actions().Apply((*it)->extension_id(), base::Time(), &apply_info); 86 (*it)->actions().Apply((*it)->extension_id(), base::Time(), &apply_info);
86 } else { 87 } else {
87 (*it)->actions().Reapply( 88 (*it)->actions().Reapply(
88 (*it)->extension_id(), base::Time(), &apply_info); 89 (*it)->extension_id(), base::Time(), &apply_info);
89 } 90 }
90 } 91 }
91 for (std::set<ContentRule*>::const_iterator it = prev_matching_rules.begin(); 92 for (std::set<ContentRule*>::const_iterator it = prev_matching_rules.begin();
92 it != prev_matching_rules.end(); ++it) { 93 it != prev_matching_rules.end();
94 ++it) {
93 if (!ContainsKey(matching_rules, *it)) { 95 if (!ContainsKey(matching_rules, *it)) {
94 apply_info.priority = (*it)->priority(); 96 apply_info.priority = (*it)->priority();
95 (*it)->actions().Revert((*it)->extension_id(), base::Time(), &apply_info); 97 (*it)->actions().Revert((*it)->extension_id(), base::Time(), &apply_info);
96 } 98 }
97 } 99 }
98 100
99 if (matching_rules.empty()) 101 if (matching_rules.empty())
100 active_rules_.erase(tab_id); 102 active_rules_.erase(tab_id);
101 else 103 else
102 swap(matching_rules, prev_matching_rules); 104 swap(matching_rules, prev_matching_rules);
103 } 105 }
104 106
105 void ContentRulesRegistry::DidNavigateMainFrame( 107 void ChromeContentRulesRegistry::DidNavigateMainFrame(
106 content::WebContents* contents, 108 content::WebContents* contents,
107 const content::LoadCommittedDetails& details, 109 const content::LoadCommittedDetails& details,
108 const content::FrameNavigateParams& params) { 110 const content::FrameNavigateParams& params) {
109 if (details.is_in_page) { 111 if (details.is_in_page) {
110 // Within-page navigations don't change the set of elements that 112 // Within-page navigations don't change the set of elements that
111 // exist, and we only support filtering on the top-level URL, so 113 // exist, and we only support filtering on the top-level URL, so
112 // this can't change which rules match. 114 // this can't change which rules match.
113 return; 115 return;
114 } 116 }
115 117
116 // Top-level navigation produces a new document. Initially, the 118 // Top-level navigation produces a new document. Initially, the
117 // document's empty, so no CSS rules match. The renderer will send 119 // document's empty, so no CSS rules match. The renderer will send
118 // an ExtensionHostMsg_OnWatchedPageChange later if any CSS rules 120 // an ExtensionHostMsg_OnWatchedPageChange later if any CSS rules
119 // match. 121 // match.
120 std::vector<std::string> no_css_selectors; 122 std::vector<std::string> no_css_selectors;
121 Apply(contents, no_css_selectors); 123 Apply(contents, no_css_selectors);
122 } 124 }
123 125
124 std::set<ContentRule*> 126 std::set<ContentRule*> ChromeContentRulesRegistry::GetMatches(
125 ContentRulesRegistry::GetMatches(
126 const RendererContentMatchData& renderer_data) const { 127 const RendererContentMatchData& renderer_data) const {
127 std::set<ContentRule*> result; 128 std::set<ContentRule*> result;
128 129
129 // Then we need to check for each of these, whether the other 130 // Then we need to check for each of these, whether the other
130 // attributes are also fulfilled. 131 // attributes are also fulfilled.
131 for (std::set<URLMatcherConditionSet::ID>::iterator 132 for (std::set<URLMatcherConditionSet::ID>::iterator url_match =
132 url_match = renderer_data.page_url_matches.begin(); 133 renderer_data.page_url_matches.begin();
133 url_match != renderer_data.page_url_matches.end(); ++url_match) { 134 url_match != renderer_data.page_url_matches.end();
135 ++url_match) {
134 URLMatcherIdToRule::const_iterator rule_iter = 136 URLMatcherIdToRule::const_iterator rule_iter =
135 match_id_to_rule_.find(*url_match); 137 match_id_to_rule_.find(*url_match);
136 CHECK(rule_iter != match_id_to_rule_.end()); 138 CHECK(rule_iter != match_id_to_rule_.end());
137 139
138 ContentRule* rule = rule_iter->second; 140 ContentRule* rule = rule_iter->second;
139 if (rule->conditions().IsFulfilled(*url_match, renderer_data)) 141 if (rule->conditions().IsFulfilled(*url_match, renderer_data))
140 result.insert(rule); 142 result.insert(rule);
141 } 143 }
142 return result; 144 return result;
143 } 145 }
144 146
145 std::string ContentRulesRegistry::AddRulesImpl( 147 std::string ChromeContentRulesRegistry::AddRulesImpl(
146 const std::string& extension_id, 148 const std::string& extension_id,
147 const std::vector<linked_ptr<RulesRegistry::Rule> >& rules) { 149 const std::vector<linked_ptr<RulesRegistry::Rule> >& rules) {
148 const Extension* extension = 150 const Extension* extension =
149 ExtensionRegistry::Get(browser_context()) 151 ExtensionRegistry::Get(browser_context())
150 ->GetExtensionById(extension_id, ExtensionRegistry::EVERYTHING); 152 ->GetExtensionById(extension_id, ExtensionRegistry::EVERYTHING);
151 DCHECK(extension) << "Must have extension with id " << extension_id; 153 DCHECK(extension) << "Must have extension with id " << extension_id;
152 154
153 base::Time extension_installation_time = 155 base::Time extension_installation_time =
154 GetExtensionInstallationTime(extension_id); 156 GetExtensionInstallationTime(extension_id);
155 157
156 std::string error; 158 std::string error;
157 RulesMap new_content_rules; 159 RulesMap new_content_rules;
158 160
159 for (std::vector<linked_ptr<RulesRegistry::Rule> >::const_iterator rule = 161 for (std::vector<linked_ptr<RulesRegistry::Rule> >::const_iterator rule =
160 rules.begin(); rule != rules.end(); ++rule) { 162 rules.begin();
163 rule != rules.end();
164 ++rule) {
161 ContentRule::GlobalRuleId rule_id(extension_id, *(*rule)->id); 165 ContentRule::GlobalRuleId rule_id(extension_id, *(*rule)->id);
162 DCHECK(content_rules_.find(rule_id) == content_rules_.end()); 166 DCHECK(content_rules_.find(rule_id) == content_rules_.end());
163 167
164 scoped_ptr<ContentRule> content_rule( 168 scoped_ptr<ContentRule> content_rule(
165 ContentRule::Create(url_matcher_.condition_factory(), 169 ContentRule::Create(url_matcher_.condition_factory(),
166 browser_context(), 170 browser_context(),
167 extension, 171 extension,
168 extension_installation_time, 172 extension_installation_time,
169 *rule, 173 *rule,
170 ContentRule::ConsistencyChecker(), 174 ContentRule::ConsistencyChecker(),
171 &error)); 175 &error));
172 if (!error.empty()) { 176 if (!error.empty()) {
173 // Clean up temporary condition sets created during rule creation. 177 // Clean up temporary condition sets created during rule creation.
174 url_matcher_.ClearUnusedConditionSets(); 178 url_matcher_.ClearUnusedConditionSets();
175 return error; 179 return error;
176 } 180 }
177 DCHECK(content_rule); 181 DCHECK(content_rule);
178 182
179 new_content_rules[rule_id] = make_linked_ptr(content_rule.release()); 183 new_content_rules[rule_id] = make_linked_ptr(content_rule.release());
180 } 184 }
181 185
182 // Wohoo, everything worked fine. 186 // Wohoo, everything worked fine.
183 content_rules_.insert(new_content_rules.begin(), new_content_rules.end()); 187 content_rules_.insert(new_content_rules.begin(), new_content_rules.end());
184 188
185 // Create the triggers. 189 // Create the triggers.
186 for (RulesMap::iterator i = new_content_rules.begin(); 190 for (RulesMap::iterator i = new_content_rules.begin();
187 i != new_content_rules.end(); ++i) { 191 i != new_content_rules.end();
192 ++i) {
188 URLMatcherConditionSet::Vector url_condition_sets; 193 URLMatcherConditionSet::Vector url_condition_sets;
189 const ContentConditionSet& conditions = i->second->conditions(); 194 const ContentConditionSet& conditions = i->second->conditions();
190 conditions.GetURLMatcherConditionSets(&url_condition_sets); 195 conditions.GetURLMatcherConditionSets(&url_condition_sets);
191 for (URLMatcherConditionSet::Vector::iterator j = 196 for (URLMatcherConditionSet::Vector::iterator j =
192 url_condition_sets.begin(); j != url_condition_sets.end(); ++j) { 197 url_condition_sets.begin();
198 j != url_condition_sets.end();
199 ++j) {
193 match_id_to_rule_[(*j)->id()] = i->second.get(); 200 match_id_to_rule_[(*j)->id()] = i->second.get();
194 } 201 }
195 } 202 }
196 203
197 // Register url patterns in url_matcher_. 204 // Register url patterns in url_matcher_.
198 URLMatcherConditionSet::Vector all_new_condition_sets; 205 URLMatcherConditionSet::Vector all_new_condition_sets;
199 for (RulesMap::iterator i = new_content_rules.begin(); 206 for (RulesMap::iterator i = new_content_rules.begin();
200 i != new_content_rules.end(); ++i) { 207 i != new_content_rules.end();
208 ++i) {
201 i->second->conditions().GetURLMatcherConditionSets(&all_new_condition_sets); 209 i->second->conditions().GetURLMatcherConditionSets(&all_new_condition_sets);
202 } 210 }
203 url_matcher_.AddConditionSets(all_new_condition_sets); 211 url_matcher_.AddConditionSets(all_new_condition_sets);
204 212
205 UpdateConditionCache(); 213 UpdateConditionCache();
206 214
207 return std::string(); 215 return std::string();
208 } 216 }
209 217
210 std::string ContentRulesRegistry::RemoveRulesImpl( 218 std::string ChromeContentRulesRegistry::RemoveRulesImpl(
211 const std::string& extension_id, 219 const std::string& extension_id,
212 const std::vector<std::string>& rule_identifiers) { 220 const std::vector<std::string>& rule_identifiers) {
213 // URLMatcherConditionSet IDs that can be removed from URLMatcher. 221 // URLMatcherConditionSet IDs that can be removed from URLMatcher.
214 std::vector<URLMatcherConditionSet::ID> remove_from_url_matcher; 222 std::vector<URLMatcherConditionSet::ID> remove_from_url_matcher;
215 223
216 for (std::vector<std::string>::const_iterator i = rule_identifiers.begin(); 224 for (std::vector<std::string>::const_iterator i = rule_identifiers.begin();
217 i != rule_identifiers.end(); ++i) { 225 i != rule_identifiers.end();
226 ++i) {
218 ContentRule::GlobalRuleId rule_id(extension_id, *i); 227 ContentRule::GlobalRuleId rule_id(extension_id, *i);
219 228
220 // Skip unknown rules. 229 // Skip unknown rules.
221 RulesMap::iterator content_rules_entry = content_rules_.find(rule_id); 230 RulesMap::iterator content_rules_entry = content_rules_.find(rule_id);
222 if (content_rules_entry == content_rules_.end()) 231 if (content_rules_entry == content_rules_.end())
223 continue; 232 continue;
224 233
225 // Remove all triggers but collect their IDs. 234 // Remove all triggers but collect their IDs.
226 URLMatcherConditionSet::Vector condition_sets; 235 URLMatcherConditionSet::Vector condition_sets;
227 ContentRule* rule = content_rules_entry->second.get(); 236 ContentRule* rule = content_rules_entry->second.get();
228 rule->conditions().GetURLMatcherConditionSets(&condition_sets); 237 rule->conditions().GetURLMatcherConditionSets(&condition_sets);
229 for (URLMatcherConditionSet::Vector::iterator j = condition_sets.begin(); 238 for (URLMatcherConditionSet::Vector::iterator j = condition_sets.begin();
230 j != condition_sets.end(); ++j) { 239 j != condition_sets.end();
240 ++j) {
231 remove_from_url_matcher.push_back((*j)->id()); 241 remove_from_url_matcher.push_back((*j)->id());
232 match_id_to_rule_.erase((*j)->id()); 242 match_id_to_rule_.erase((*j)->id());
233 } 243 }
234 244
235 // Remove the ContentRule from active_rules_. 245 // Remove the ContentRule from active_rules_.
236 for (std::map<int, std::set<ContentRule*> >::iterator 246 for (std::map<int, std::set<ContentRule*> >::iterator it =
237 it = active_rules_.begin(); 247 active_rules_.begin();
238 it != active_rules_.end(); ++it) { 248 it != active_rules_.end();
249 ++it) {
239 if (ContainsKey(it->second, rule)) { 250 if (ContainsKey(it->second, rule)) {
240 content::WebContents* tab; 251 content::WebContents* tab;
241 if (!ExtensionTabUtil::GetTabById( 252 if (!ExtensionTabUtil::GetTabById(
242 it->first, browser_context(), true, NULL, NULL, &tab, NULL)) { 253 it->first, browser_context(), true, NULL, NULL, &tab, NULL)) {
243 LOG(DFATAL) << "Tab id " << it->first 254 LOG(DFATAL) << "Tab id " << it->first
244 << " still in active_rules_, but tab has been destroyed"; 255 << " still in active_rules_, but tab has been destroyed";
245 continue; 256 continue;
246 } 257 }
247 ContentAction::ApplyInfo apply_info = {browser_context(), tab}; 258 ContentAction::ApplyInfo apply_info = {browser_context(), tab};
248 rule->actions().Revert(rule->extension_id(), base::Time(), &apply_info); 259 rule->actions().Revert(rule->extension_id(), base::Time(), &apply_info);
249 it->second.erase(rule); 260 it->second.erase(rule);
250 } 261 }
251 } 262 }
252 263
253 // Remove reference to actual rule. 264 // Remove reference to actual rule.
254 content_rules_.erase(content_rules_entry); 265 content_rules_.erase(content_rules_entry);
255 } 266 }
256 267
257 // Clear URLMatcher based on condition_set_ids that are not needed any more. 268 // Clear URLMatcher based on condition_set_ids that are not needed any more.
258 url_matcher_.RemoveConditionSets(remove_from_url_matcher); 269 url_matcher_.RemoveConditionSets(remove_from_url_matcher);
259 270
260 UpdateConditionCache(); 271 UpdateConditionCache();
261 272
262 return std::string(); 273 return std::string();
263 } 274 }
264 275
265 std::string ContentRulesRegistry::RemoveAllRulesImpl( 276 std::string ChromeContentRulesRegistry::RemoveAllRulesImpl(
266 const std::string& extension_id) { 277 const std::string& extension_id) {
267 // Search all identifiers of rules that belong to extension |extension_id|. 278 // Search all identifiers of rules that belong to extension |extension_id|.
268 std::vector<std::string> rule_identifiers; 279 std::vector<std::string> rule_identifiers;
269 for (RulesMap::iterator i = content_rules_.begin(); 280 for (RulesMap::iterator i = content_rules_.begin(); i != content_rules_.end();
270 i != content_rules_.end(); ++i) { 281 ++i) {
271 const ContentRule::GlobalRuleId& global_rule_id = i->first; 282 const ContentRule::GlobalRuleId& global_rule_id = i->first;
272 if (global_rule_id.first == extension_id) 283 if (global_rule_id.first == extension_id)
273 rule_identifiers.push_back(global_rule_id.second); 284 rule_identifiers.push_back(global_rule_id.second);
274 } 285 }
275 286
276 return RemoveRulesImpl(extension_id, rule_identifiers); 287 return RemoveRulesImpl(extension_id, rule_identifiers);
277 } 288 }
278 289
279 void ContentRulesRegistry::UpdateConditionCache() { 290 void ChromeContentRulesRegistry::UpdateConditionCache() {
280 std::set<std::string> css_selectors; // We rely on this being sorted. 291 std::set<std::string> css_selectors; // We rely on this being sorted.
281 for (RulesMap::const_iterator i = content_rules_.begin(); 292 for (RulesMap::const_iterator i = content_rules_.begin();
282 i != content_rules_.end(); ++i) { 293 i != content_rules_.end();
294 ++i) {
283 ContentRule& rule = *i->second; 295 ContentRule& rule = *i->second;
284 for (ContentConditionSet::const_iterator 296 for (ContentConditionSet::const_iterator condition =
285 condition = rule.conditions().begin(); 297 rule.conditions().begin();
286 condition != rule.conditions().end(); ++condition) { 298 condition != rule.conditions().end();
299 ++condition) {
287 const std::vector<std::string>& condition_css_selectors = 300 const std::vector<std::string>& condition_css_selectors =
288 (*condition)->css_selectors(); 301 (*condition)->css_selectors();
289 css_selectors.insert(condition_css_selectors.begin(), 302 css_selectors.insert(condition_css_selectors.begin(),
290 condition_css_selectors.end()); 303 condition_css_selectors.end());
291 } 304 }
292 } 305 }
293 306
294 if (css_selectors.size() != watched_css_selectors_.size() || 307 if (css_selectors.size() != watched_css_selectors_.size() ||
295 !std::equal(css_selectors.begin(), css_selectors.end(), 308 !std::equal(css_selectors.begin(),
309 css_selectors.end(),
296 watched_css_selectors_.begin())) { 310 watched_css_selectors_.begin())) {
297 watched_css_selectors_.assign(css_selectors.begin(), css_selectors.end()); 311 watched_css_selectors_.assign(css_selectors.begin(), css_selectors.end());
298 312
299 for (content::RenderProcessHost::iterator it( 313 for (content::RenderProcessHost::iterator it(
300 content::RenderProcessHost::AllHostsIterator()); 314 content::RenderProcessHost::AllHostsIterator());
301 !it.IsAtEnd(); it.Advance()) { 315 !it.IsAtEnd();
316 it.Advance()) {
302 content::RenderProcessHost* process = it.GetCurrentValue(); 317 content::RenderProcessHost* process = it.GetCurrentValue();
303 if (process->GetBrowserContext() == browser_context()) 318 if (process->GetBrowserContext() == browser_context())
304 InstructRenderProcess(process); 319 InstructRenderProcess(process);
305 } 320 }
306 } 321 }
307 } 322 }
308 323
309 void ContentRulesRegistry::InstructRenderProcess( 324 void ChromeContentRulesRegistry::InstructRenderProcess(
310 content::RenderProcessHost* process) { 325 content::RenderProcessHost* process) {
311 process->Send(new ExtensionMsg_WatchPages(watched_css_selectors_)); 326 process->Send(new ExtensionMsg_WatchPages(watched_css_selectors_));
312 } 327 }
313 328
314 bool ContentRulesRegistry::IsEmpty() const { 329 bool ChromeContentRulesRegistry::IsEmpty() const {
315 return match_id_to_rule_.empty() && content_rules_.empty() && 330 return match_id_to_rule_.empty() && content_rules_.empty() &&
316 url_matcher_.IsEmpty(); 331 url_matcher_.IsEmpty();
317 } 332 }
318 333
319 ContentRulesRegistry::~ContentRulesRegistry() {} 334 ChromeContentRulesRegistry::~ChromeContentRulesRegistry() {
335 }
320 336
321 base::Time ContentRulesRegistry::GetExtensionInstallationTime( 337 base::Time ChromeContentRulesRegistry::GetExtensionInstallationTime(
322 const std::string& extension_id) const { 338 const std::string& extension_id) const {
323 if (!extension_info_map_.get()) // May be NULL during testing. 339 if (!extension_info_map_.get()) // May be NULL during testing.
324 return base::Time(); 340 return base::Time();
325 341
326 return extension_info_map_->GetInstallTime(extension_id); 342 return extension_info_map_->GetInstallTime(extension_id);
327 } 343 }
328 344
329 } // namespace extensions 345 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698