Chromium Code Reviews| Index: chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_registry.cc |
| diff --git a/chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_registry.cc b/chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_registry.cc |
| index 77bc9b8f44ef22fa8bbbf5a3aa67ed9398a29687..ba6bac062e732c55e4aac4f7bda8577dcd31f89a 100644 |
| --- a/chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_registry.cc |
| +++ b/chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_registry.cc |
| @@ -12,6 +12,12 @@ |
| #include "chrome/browser/extensions/extension_system.h" |
| #include "net/url_request/url_request.h" |
| +namespace { |
| +const char kActionCannotBeExecuted[] = "An action can never be executed " |
| + "because there are is no time in the request life-cycle during which the " |
| + "conditions can be checked and the action can possibly be executed."; |
| +} // namespace |
| + |
| namespace extensions { |
| WebRequestRulesRegistry::WebRequestRulesRegistry(Profile* profile, |
| @@ -23,7 +29,7 @@ WebRequestRulesRegistry::WebRequestRulesRegistry(Profile* profile, |
| std::set<WebRequestRule::GlobalRuleId> |
| WebRequestRulesRegistry::GetMatches( |
| - const WebRequestRule::RequestData& request_data) { |
| + const DeclarativeWebRequestData& request_data) { |
| std::set<WebRequestRule::GlobalRuleId> result; |
| // Figure out for which rules the URL match conditions were fulfilled. |
| @@ -46,7 +52,7 @@ WebRequestRulesRegistry::GetMatches( |
| std::list<LinkedPtrEventResponseDelta> WebRequestRulesRegistry::CreateDeltas( |
| const ExtensionInfoMap* extension_info_map, |
| - const WebRequestRule::RequestData& request_data, |
| + const DeclarativeWebRequestData& request_data, |
| bool crosses_incognito) { |
| if (webrequest_rules_.empty()) |
| return std::list<LinkedPtrEventResponseDelta>(); |
| @@ -99,8 +105,12 @@ std::list<LinkedPtrEventResponseDelta> WebRequestRulesRegistry::CreateDeltas( |
| if (priority_of_rule < current_min_priority) |
| continue; |
| - std::list<LinkedPtrEventResponseDelta> rule_result = |
| - rule->CreateDeltas(extension_info_map, request_data, crosses_incognito); |
| + |
| + std::list<LinkedPtrEventResponseDelta> rule_result; |
| + WebRequestAction::ApplyInfo apply_info = { |
| + extension_info_map, request_data, crosses_incognito, &rule_result |
| + }; |
| + rule->Apply(apply_info); |
| result.splice(result.begin(), rule_result); |
| min_priorities[extension_id] = std::max(current_min_priority, |
| @@ -125,7 +135,8 @@ std::string WebRequestRulesRegistry::AddRulesImpl( |
| scoped_ptr<WebRequestRule> webrequest_rule( |
| WebRequestRule::Create(url_matcher_.condition_factory(), extension_id, |
| - extension_installation_time, *rule, &error)); |
| + extension_installation_time, *rule, |
| + &CheckConsistency, &error)); |
| if (!error.empty()) { |
| // We don't return here, because we want to clear temporary |
| // condition sets in the url_matcher_. |
| @@ -246,4 +257,34 @@ void WebRequestRulesRegistry::ClearCacheOnNavigation() { |
| extension_web_request_api_helpers::ClearCacheOnNavigation(); |
| } |
| +// static |
| +bool WebRequestRulesRegistry::CheckConsistency( |
| + WebRequestConditionSet* conditions, |
| + WebRequestActionSet* actions, |
| + std::string* error) { |
| + // Actions and conditions can be checked and executed in specific phases |
| + // of each web request. We consider a rule inconsistent if there is an action |
| + // that cannot be triggered by any condition. |
| + for (WebRequestActionSet::Actions::const_iterator action_iter = |
| + actions->actions().begin(); |
| + action_iter != actions->actions().end(); |
| + ++action_iter) { |
| + bool found_matching_condition = false; |
| + for (WebRequestConditionSet::Conditions::const_iterator condition_iter = |
| + conditions->conditions().begin(); |
| + condition_iter != conditions->conditions().end() && |
| + !found_matching_condition; |
| + ++condition_iter) { |
| + // Test the intersection of bit masks, this is intentionally & and not &&. |
| + if ((*action_iter)->GetStages() & (*condition_iter)->stages()) |
| + found_matching_condition = true; |
|
Matt Perry
2012/12/13 20:27:48
break;
Jeffrey Yasskin
2012/12/14 00:38:20
This is just moved from WebRequestRule::CheckConsi
|
| + } |
| + if (!found_matching_condition) { |
| + *error = kActionCannotBeExecuted; |
| + return false; |
| + } |
| + } |
| + return true; |
| +} |
| + |
| } // namespace extensions |