| 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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 ordered_matches.reserve(matches.size()); | 92 ordered_matches.reserve(matches.size()); |
| 93 for (const WebRequestRule* rule : matches) | 93 for (const WebRequestRule* rule : matches) |
| 94 ordered_matches.push_back(make_pair(rule->priority(), rule->id())); | 94 ordered_matches.push_back(make_pair(rule->priority(), rule->id())); |
| 95 // Sort from rbegin to rend in order to get descending priority order. | 95 // Sort from rbegin to rend in order to get descending priority order. |
| 96 std::sort(ordered_matches.rbegin(), ordered_matches.rend()); | 96 std::sort(ordered_matches.rbegin(), ordered_matches.rend()); |
| 97 | 97 |
| 98 // Build a map that maps each extension id to the minimum required priority | 98 // Build a map that maps each extension id to the minimum required priority |
| 99 // for rules of that extension. Initially, this priority is -infinite and | 99 // for rules of that extension. Initially, this priority is -infinite and |
| 100 // will be increased when the rules are processed and raise the bar via | 100 // will be increased when the rules are processed and raise the bar via |
| 101 // WebRequestIgnoreRulesActions. | 101 // WebRequestIgnoreRulesActions. |
| 102 typedef std::string ExtensionId; | |
| 103 typedef std::map<ExtensionId, WebRequestRule::Priority> MinPriorities; | 102 typedef std::map<ExtensionId, WebRequestRule::Priority> MinPriorities; |
| 104 typedef std::map<ExtensionId, std::set<std::string> > IgnoreTags; | 103 typedef std::map<ExtensionId, std::set<std::string> > IgnoreTags; |
| 105 MinPriorities min_priorities; | 104 MinPriorities min_priorities; |
| 106 IgnoreTags ignore_tags; | 105 IgnoreTags ignore_tags; |
| 107 for (const PriorityRuleIdPair& priority_rule_id_pair : ordered_matches) { | 106 for (const PriorityRuleIdPair& priority_rule_id_pair : ordered_matches) { |
| 108 const WebRequestRule::GlobalRuleId& rule_id = priority_rule_id_pair.second; | 107 const WebRequestRule::GlobalRuleId& rule_id = priority_rule_id_pair.second; |
| 109 const ExtensionId& extension_id = rule_id.first; | 108 const ExtensionId& extension_id = rule_id.first; |
| 110 min_priorities[extension_id] = std::numeric_limits<int>::min(); | 109 min_priorities[extension_id] = std::numeric_limits<int>::min(); |
| 111 } | 110 } |
| 112 | 111 |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 } | 281 } |
| 283 rules_with_untriggered_conditions_.erase(rule); | 282 rules_with_untriggered_conditions_.erase(rule); |
| 284 } | 283 } |
| 285 | 284 |
| 286 bool WebRequestRulesRegistry::IsEmpty() const { | 285 bool WebRequestRulesRegistry::IsEmpty() const { |
| 287 // Easy first. | 286 // Easy first. |
| 288 if (!rule_triggers_.empty() && url_matcher_.IsEmpty()) | 287 if (!rule_triggers_.empty() && url_matcher_.IsEmpty()) |
| 289 return false; | 288 return false; |
| 290 | 289 |
| 291 // Now all the registered rules for each extensions. | 290 // Now all the registered rules for each extensions. |
| 292 for (const std::pair<WebRequestRule::ExtensionId, RulesMap>& | 291 for (const std::pair<ExtensionId, RulesMap>& extension_id_rules_map_pair : |
| 293 extension_id_rules_map_pair : webrequest_rules_) { | 292 webrequest_rules_) { |
| 294 if (!extension_id_rules_map_pair.second.empty()) | 293 if (!extension_id_rules_map_pair.second.empty()) |
| 295 return false; | 294 return false; |
| 296 } | 295 } |
| 297 return true; | 296 return true; |
| 298 } | 297 } |
| 299 | 298 |
| 300 WebRequestRulesRegistry::~WebRequestRulesRegistry() {} | 299 WebRequestRulesRegistry::~WebRequestRulesRegistry() {} |
| 301 | 300 |
| 302 base::Time WebRequestRulesRegistry::GetExtensionInstallationTime( | 301 base::Time WebRequestRulesRegistry::GetExtensionInstallationTime( |
| 303 const std::string& extension_id) const { | 302 const std::string& extension_id) const { |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 for (url_matcher::URLMatcherConditionSet::ID url_match : url_matches) { | 373 for (url_matcher::URLMatcherConditionSet::ID url_match : url_matches) { |
| 375 RuleTriggers::const_iterator rule_trigger = rule_triggers_.find(url_match); | 374 RuleTriggers::const_iterator rule_trigger = rule_triggers_.find(url_match); |
| 376 CHECK(rule_trigger != rule_triggers_.end()); | 375 CHECK(rule_trigger != rule_triggers_.end()); |
| 377 if (!base::ContainsKey(*result, rule_trigger->second) && | 376 if (!base::ContainsKey(*result, rule_trigger->second) && |
| 378 rule_trigger->second->conditions().IsFulfilled(url_match, request_data)) | 377 rule_trigger->second->conditions().IsFulfilled(url_match, request_data)) |
| 379 result->insert(rule_trigger->second); | 378 result->insert(rule_trigger->second); |
| 380 } | 379 } |
| 381 } | 380 } |
| 382 | 381 |
| 383 } // namespace extensions | 382 } // namespace extensions |
| OLD | NEW |