OLD | NEW |
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 "extensions/browser/api/declarative_webrequest/webrequest_rules_registr
y.h" | 5 #include "extensions/browser/api/declarative_webrequest/webrequest_rules_registr
y.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 result.splice(result.begin(), rule_result); | 144 result.splice(result.begin(), rule_result); |
145 | 145 |
146 min_priorities[extension_id] = std::max(current_min_priority, | 146 min_priorities[extension_id] = std::max(current_min_priority, |
147 rule->GetMinimumPriority()); | 147 rule->GetMinimumPriority()); |
148 } | 148 } |
149 return result; | 149 return result; |
150 } | 150 } |
151 | 151 |
152 std::string WebRequestRulesRegistry::AddRulesImpl( | 152 std::string WebRequestRulesRegistry::AddRulesImpl( |
153 const std::string& extension_id, | 153 const std::string& extension_id, |
154 const std::vector<linked_ptr<core_api::events::Rule>>& rules) { | 154 const std::vector<linked_ptr<api::events::Rule>>& rules) { |
155 typedef std::pair<WebRequestRule::RuleId, linked_ptr<const WebRequestRule>> | 155 typedef std::pair<WebRequestRule::RuleId, linked_ptr<const WebRequestRule>> |
156 IdRulePair; | 156 IdRulePair; |
157 typedef std::vector<IdRulePair> RulesVector; | 157 typedef std::vector<IdRulePair> RulesVector; |
158 | 158 |
159 base::Time extension_installation_time = | 159 base::Time extension_installation_time = |
160 GetExtensionInstallationTime(extension_id); | 160 GetExtensionInstallationTime(extension_id); |
161 | 161 |
162 std::string error; | 162 std::string error; |
163 RulesVector new_webrequest_rules; | 163 RulesVector new_webrequest_rules; |
164 new_webrequest_rules.reserve(rules.size()); | 164 new_webrequest_rules.reserve(rules.size()); |
165 const Extension* extension = | 165 const Extension* extension = |
166 extension_info_map_->extensions().GetByID(extension_id); | 166 extension_info_map_->extensions().GetByID(extension_id); |
167 RulesMap& registered_rules = webrequest_rules_[extension_id]; | 167 RulesMap& registered_rules = webrequest_rules_[extension_id]; |
168 | 168 |
169 for (const linked_ptr<core_api::events::Rule>& rule : rules) { | 169 for (const linked_ptr<api::events::Rule>& rule : rules) { |
170 const WebRequestRule::RuleId& rule_id(*rule->id); | 170 const WebRequestRule::RuleId& rule_id(*rule->id); |
171 DCHECK(registered_rules.find(rule_id) == registered_rules.end()); | 171 DCHECK(registered_rules.find(rule_id) == registered_rules.end()); |
172 | 172 |
173 scoped_ptr<WebRequestRule> webrequest_rule(WebRequestRule::Create( | 173 scoped_ptr<WebRequestRule> webrequest_rule(WebRequestRule::Create( |
174 url_matcher_.condition_factory(), browser_context(), extension, | 174 url_matcher_.condition_factory(), browser_context(), extension, |
175 extension_installation_time, rule, | 175 extension_installation_time, rule, |
176 base::Bind(&Checker, base::Unretained(extension)), &error)); | 176 base::Bind(&Checker, base::Unretained(extension)), &error)); |
177 if (!error.empty()) { | 177 if (!error.empty()) { |
178 // We don't return here, because we want to clear temporary | 178 // We don't return here, because we want to clear temporary |
179 // condition sets in the url_matcher_. | 179 // condition sets in the url_matcher_. |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 for (url_matcher::URLMatcherConditionSet::ID url_match : url_matches) { | 381 for (url_matcher::URLMatcherConditionSet::ID url_match : url_matches) { |
382 RuleTriggers::const_iterator rule_trigger = rule_triggers_.find(url_match); | 382 RuleTriggers::const_iterator rule_trigger = rule_triggers_.find(url_match); |
383 CHECK(rule_trigger != rule_triggers_.end()); | 383 CHECK(rule_trigger != rule_triggers_.end()); |
384 if (!ContainsKey(*result, rule_trigger->second) && | 384 if (!ContainsKey(*result, rule_trigger->second) && |
385 rule_trigger->second->conditions().IsFulfilled(url_match, request_data)) | 385 rule_trigger->second->conditions().IsFulfilled(url_match, request_data)) |
386 result->insert(rule_trigger->second); | 386 result->insert(rule_trigger->second); |
387 } | 387 } |
388 } | 388 } |
389 | 389 |
390 } // namespace extensions | 390 } // namespace extensions |
OLD | NEW |