Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4081)

Unified Diff: chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_registry.cc

Issue 11414230: Declarative Web Request: firstPartyForCookiesUrl (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added event order Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..1aaadb53c6b643f8c9b2101a82955f496b36ad12 100644
--- a/chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_registry.cc
+++ b/chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_registry.cc
@@ -4,6 +4,7 @@
#include "chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_registry.h"
+#include <algorithm>
#include <limits>
#include "chrome/browser/extensions/api/declarative_webrequest/webrequest_condition.h"
@@ -29,16 +30,27 @@ WebRequestRulesRegistry::GetMatches(
// Figure out for which rules the URL match conditions were fulfilled.
typedef std::set<URLMatcherConditionSet::ID> URLMatches;
URLMatches url_matches = url_matcher_.MatchURL(request_data.request->url());
+ std::set<const WebRequestRule*> url_matched_rules;
+ std::transform(url_matches.begin(), url_matches.end(),
+ std::inserter(url_matched_rules, url_matched_rules.begin()),
+ RuleTriggersOperator(rule_triggers_));
+
+ URLMatches first_party_url_matches = first_party_url_matcher_.MatchURL(
+ request_data.request->first_party_for_cookies());
// Then we need to check for each of these, whether the other
// WebRequestConditionAttributes are also fulfilled.
- for (URLMatches::iterator url_match = url_matches.begin();
- url_match != url_matches.end(); ++url_match) {
+ for (URLMatches::iterator url_match = first_party_url_matches.begin();
+ url_match != first_party_url_matches.end(); ++url_match) {
RuleTriggers::iterator rule_trigger = rule_triggers_.find(*url_match);
CHECK(rule_trigger != rule_triggers_.end());
WebRequestRule* rule = rule_trigger->second;
- if (rule->conditions().IsFulfilled(*url_match, request_data))
+ // We already iterate over rules which have the first-party URL condition
+ // satisfied. Now check that the request URL is also satisfied, and finally
+ // check the rest of the attributes.
+ if (url_matched_rules.find(rule) != url_matched_rules.end() &&
+ rule->conditions().IsFulfilled(*url_match, request_data))
result.insert(rule->id());
}
return result;
@@ -124,11 +136,13 @@ std::string WebRequestRulesRegistry::AddRulesImpl(
DCHECK(webrequest_rules_.find(rule_id) == webrequest_rules_.end());
scoped_ptr<WebRequestRule> webrequest_rule(
- WebRequestRule::Create(url_matcher_.condition_factory(), extension_id,
+ WebRequestRule::Create(url_matcher_.condition_factory(),
+ first_party_url_matcher_.condition_factory(),
+ extension_id,
extension_installation_time, *rule, &error));
if (!error.empty()) {
// We don't return here, because we want to clear temporary
- // condition sets in the url_matcher_.
+ // condition sets in |url_matcher_| and |first_party_url_matcher_|.
break;
}
@@ -138,6 +152,7 @@ std::string WebRequestRulesRegistry::AddRulesImpl(
if (!error.empty()) {
// Clean up temporary condition sets created during rule creation.
url_matcher_.ClearUnusedConditionSets();
+ first_party_url_matcher_.ClearUnusedConditionSets();
return error;
}
@@ -151,19 +166,24 @@ std::string WebRequestRulesRegistry::AddRulesImpl(
URLMatcherConditionSet::Vector url_condition_sets;
const WebRequestConditionSet& conditions = i->second->conditions();
conditions.GetURLMatcherConditionSets(&url_condition_sets);
+ conditions.GetFirstPartyURLMatcherConditionSets(&url_condition_sets);
for (URLMatcherConditionSet::Vector::iterator j =
url_condition_sets.begin(); j != url_condition_sets.end(); ++j) {
rule_triggers_[(*j)->id()] = i->second.get();
}
}
- // Register url patterns in url_matcher_.
+ // Register url patterns in |url_matcher_| and |first_party_url_matcher_|.
URLMatcherConditionSet::Vector all_new_condition_sets;
+ URLMatcherConditionSet::Vector all_new_condition_sets_first_party;
for (RulesMap::iterator i = new_webrequest_rules.begin();
i != new_webrequest_rules.end(); ++i) {
i->second->conditions().GetURLMatcherConditionSets(&all_new_condition_sets);
+ i->second->conditions().GetFirstPartyURLMatcherConditionSets(
+ &all_new_condition_sets_first_party);
}
url_matcher_.AddConditionSets(all_new_condition_sets);
+ first_party_url_matcher_.AddConditionSets(all_new_condition_sets_first_party);
ClearCacheOnNavigation();
@@ -173,8 +193,9 @@ std::string WebRequestRulesRegistry::AddRulesImpl(
std::string WebRequestRulesRegistry::RemoveRulesImpl(
const std::string& extension_id,
const std::vector<std::string>& rule_identifiers) {
- // URLMatcherConditionSet IDs that can be removed from URLMatcher.
+ // URLMatcherConditionSet IDs that can be removed from URL matchers.
std::vector<URLMatcherConditionSet::ID> remove_from_url_matcher;
+ std::vector<URLMatcherConditionSet::ID> remove_from_first_party_url_matcher;
for (std::vector<std::string>::const_iterator i = rule_identifiers.begin();
i != rule_identifiers.end(); ++i) {
@@ -187,20 +208,31 @@ std::string WebRequestRulesRegistry::RemoveRulesImpl(
// Remove all triggers but collect their IDs.
URLMatcherConditionSet::Vector condition_sets;
+ URLMatcherConditionSet::Vector condition_sets_first_party;
WebRequestRule* rule = webrequest_rules_entry->second.get();
rule->conditions().GetURLMatcherConditionSets(&condition_sets);
+ rule->conditions().GetFirstPartyURLMatcherConditionSets(
+ &condition_sets_first_party);
for (URLMatcherConditionSet::Vector::iterator j = condition_sets.begin();
j != condition_sets.end(); ++j) {
remove_from_url_matcher.push_back((*j)->id());
rule_triggers_.erase((*j)->id());
}
+ for (URLMatcherConditionSet::Vector::iterator j =
+ condition_sets_first_party.begin();
+ j != condition_sets_first_party.end(); ++j) {
+ remove_from_first_party_url_matcher.push_back((*j)->id());
+ rule_triggers_.erase((*j)->id());
+ }
// Remove reference to actual rule.
webrequest_rules_.erase(webrequest_rules_entry);
}
- // Clear URLMatcher based on condition_set_ids that are not needed any more.
+ // Clear URL matchers based on condition_set_ids that are not needed any more.
url_matcher_.RemoveConditionSets(remove_from_url_matcher);
+ first_party_url_matcher_.RemoveConditionSets(
+ remove_from_first_party_url_matcher);
ClearCacheOnNavigation();
@@ -229,7 +261,7 @@ content::BrowserThread::ID WebRequestRulesRegistry::GetOwnerThread() const {
bool WebRequestRulesRegistry::IsEmpty() const {
return rule_triggers_.empty() && webrequest_rules_.empty() &&
- url_matcher_.IsEmpty();
+ url_matcher_.IsEmpty() && first_party_url_matcher_.IsEmpty();
}
WebRequestRulesRegistry::~WebRequestRulesRegistry() {}
@@ -246,4 +278,12 @@ void WebRequestRulesRegistry::ClearCacheOnNavigation() {
extension_web_request_api_helpers::ClearCacheOnNavigation();
}
+WebRequestRulesRegistry::RuleTriggersOperator::RuleTriggersOperator(
+ const RuleTriggers& triggers)
+ : triggers_(triggers) {
+}
+
+WebRequestRulesRegistry::RuleTriggersOperator::~RuleTriggersOperator() {
+}
+
} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698