Chromium Code Reviews| 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 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
| 13 #include "extensions/browser/api/declarative_webrequest/webrequest_condition.h" | 13 #include "extensions/browser/api/declarative_webrequest/webrequest_condition.h" |
| 14 #include "extensions/browser/api/declarative_webrequest/webrequest_constants.h" | 14 #include "extensions/browser/api/declarative_webrequest/webrequest_constants.h" |
| 15 #include "extensions/browser/api/web_request/web_request_api_helpers.h" | 15 #include "extensions/browser/api/web_request/web_request_api_helpers.h" |
| 16 #include "extensions/browser/api/web_request/web_request_permissions.h" | 16 #include "extensions/browser/api/web_request/web_request_permissions.h" |
| 17 #include "extensions/browser/extension_system.h" | 17 #include "extensions/browser/extension_system.h" |
| 18 #include "extensions/common/error_utils.h" | 18 #include "extensions/common/error_utils.h" |
| 19 #include "extensions/common/extension.h" | 19 #include "extensions/common/extension.h" |
| 20 #include "extensions/common/extension_id.h" | |
|
Devlin
2016/11/11 23:10:06
don't need this here; it's in the .h
lazyboy
2016/11/12 00:13:16
Done.
| |
| 20 #include "extensions/common/permissions/permissions_data.h" | 21 #include "extensions/common/permissions/permissions_data.h" |
| 21 #include "net/url_request/url_request.h" | 22 #include "net/url_request/url_request.h" |
| 22 | 23 |
| 23 using url_matcher::URLMatcherConditionSet; | 24 using url_matcher::URLMatcherConditionSet; |
| 24 | 25 |
| 25 namespace { | 26 namespace { |
| 26 | 27 |
| 27 const char kActionCannotBeExecuted[] = "The action '*' can never be executed " | 28 const char kActionCannotBeExecuted[] = "The action '*' can never be executed " |
| 28 "because there are is no time in the request life-cycle during which the " | 29 "because there are is no time in the request life-cycle during which the " |
| 29 "conditions can be checked and the action can possibly be executed."; | 30 "conditions can be checked and the action can possibly be executed."; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 92 ordered_matches.reserve(matches.size()); | 93 ordered_matches.reserve(matches.size()); |
| 93 for (const WebRequestRule* rule : matches) | 94 for (const WebRequestRule* rule : matches) |
| 94 ordered_matches.push_back(make_pair(rule->priority(), rule->id())); | 95 ordered_matches.push_back(make_pair(rule->priority(), rule->id())); |
| 95 // Sort from rbegin to rend in order to get descending priority order. | 96 // Sort from rbegin to rend in order to get descending priority order. |
| 96 std::sort(ordered_matches.rbegin(), ordered_matches.rend()); | 97 std::sort(ordered_matches.rbegin(), ordered_matches.rend()); |
| 97 | 98 |
| 98 // Build a map that maps each extension id to the minimum required priority | 99 // 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 | 100 // 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 | 101 // will be increased when the rules are processed and raise the bar via |
| 101 // WebRequestIgnoreRulesActions. | 102 // WebRequestIgnoreRulesActions. |
| 102 typedef std::string ExtensionId; | |
| 103 typedef std::map<ExtensionId, WebRequestRule::Priority> MinPriorities; | 103 typedef std::map<ExtensionId, WebRequestRule::Priority> MinPriorities; |
| 104 typedef std::map<ExtensionId, std::set<std::string> > IgnoreTags; | 104 typedef std::map<ExtensionId, std::set<std::string> > IgnoreTags; |
| 105 MinPriorities min_priorities; | 105 MinPriorities min_priorities; |
| 106 IgnoreTags ignore_tags; | 106 IgnoreTags ignore_tags; |
| 107 for (const PriorityRuleIdPair& priority_rule_id_pair : ordered_matches) { | 107 for (const PriorityRuleIdPair& priority_rule_id_pair : ordered_matches) { |
| 108 const WebRequestRule::GlobalRuleId& rule_id = priority_rule_id_pair.second; | 108 const WebRequestRule::GlobalRuleId& rule_id = priority_rule_id_pair.second; |
| 109 const ExtensionId& extension_id = rule_id.first; | 109 const ExtensionId& extension_id = rule_id.first; |
| 110 min_priorities[extension_id] = std::numeric_limits<int>::min(); | 110 min_priorities[extension_id] = std::numeric_limits<int>::min(); |
| 111 } | 111 } |
| 112 | 112 |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 282 } | 282 } |
| 283 rules_with_untriggered_conditions_.erase(rule); | 283 rules_with_untriggered_conditions_.erase(rule); |
| 284 } | 284 } |
| 285 | 285 |
| 286 bool WebRequestRulesRegistry::IsEmpty() const { | 286 bool WebRequestRulesRegistry::IsEmpty() const { |
| 287 // Easy first. | 287 // Easy first. |
| 288 if (!rule_triggers_.empty() && url_matcher_.IsEmpty()) | 288 if (!rule_triggers_.empty() && url_matcher_.IsEmpty()) |
| 289 return false; | 289 return false; |
| 290 | 290 |
| 291 // Now all the registered rules for each extensions. | 291 // Now all the registered rules for each extensions. |
| 292 for (const std::pair<WebRequestRule::ExtensionId, RulesMap>& | 292 for (const std::pair<ExtensionId, RulesMap>& extension_id_rules_map_pair : |
| 293 extension_id_rules_map_pair : webrequest_rules_) { | 293 webrequest_rules_) { |
| 294 if (!extension_id_rules_map_pair.second.empty()) | 294 if (!extension_id_rules_map_pair.second.empty()) |
| 295 return false; | 295 return false; |
| 296 } | 296 } |
| 297 return true; | 297 return true; |
| 298 } | 298 } |
| 299 | 299 |
| 300 WebRequestRulesRegistry::~WebRequestRulesRegistry() {} | 300 WebRequestRulesRegistry::~WebRequestRulesRegistry() {} |
| 301 | 301 |
| 302 base::Time WebRequestRulesRegistry::GetExtensionInstallationTime( | 302 base::Time WebRequestRulesRegistry::GetExtensionInstallationTime( |
| 303 const std::string& extension_id) const { | 303 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) { | 374 for (url_matcher::URLMatcherConditionSet::ID url_match : url_matches) { |
| 375 RuleTriggers::const_iterator rule_trigger = rule_triggers_.find(url_match); | 375 RuleTriggers::const_iterator rule_trigger = rule_triggers_.find(url_match); |
| 376 CHECK(rule_trigger != rule_triggers_.end()); | 376 CHECK(rule_trigger != rule_triggers_.end()); |
| 377 if (!base::ContainsKey(*result, rule_trigger->second) && | 377 if (!base::ContainsKey(*result, rule_trigger->second) && |
| 378 rule_trigger->second->conditions().IsFulfilled(url_match, request_data)) | 378 rule_trigger->second->conditions().IsFulfilled(url_match, request_data)) |
| 379 result->insert(rule_trigger->second); | 379 result->insert(rule_trigger->second); |
| 380 } | 380 } |
| 381 } | 381 } |
| 382 | 382 |
| 383 } // namespace extensions | 383 } // namespace extensions |
| OLD | NEW |