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 42ab193385a5dcdae6efc4bed5e903d98a473105..2471f6f73c30aa4838f30ea226c82f942eebbac5 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<const WebRequestRule*> |
WebRequestRulesRegistry::GetMatches( |
- const WebRequestRule::RequestData& request_data) { |
+ DeclarativeWebRequestData request_data) { |
// 1st phase -- add all rules with some conditions without UrlFilter |
// attributes. |
std::set<const WebRequestRule*> result(rules_with_untriggered_conditions_); |
@@ -38,11 +44,13 @@ WebRequestRulesRegistry::GetMatches( |
result.insert(rule_trigger->second); |
} |
+ request_data.url_matches = &url_matches; |
+ |
// 3rd phase -- eliminate all rules with no satisfied condition (that may |
// happen due to non-UrlFilter attributes). |
std::set<const WebRequestRule*>::iterator it = result.begin(); |
while (it != result.end()) { |
- if ((*it)->conditions().IsFulfilled(url_matches, request_data)) |
+ if ((*it)->conditions().IsFulfilled(request_data)) |
++it; |
else |
result.erase(it++); |
@@ -53,7 +61,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>(); |
@@ -103,8 +111,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, |
@@ -129,7 +141,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_. |
@@ -255,4 +268,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; |
+ } |
+ if (!found_matching_condition) { |
+ *error = kActionCannotBeExecuted; |
+ return false; |
+ } |
+ } |
+ return true; |
+} |
+ |
} // namespace extensions |