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

Side by Side 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: Back to one matcher Created 7 years, 11 months 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_ registry.h" 5 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_ registry.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 12 matching lines...) Expand all
23 23
24 namespace extensions { 24 namespace extensions {
25 25
26 WebRequestRulesRegistry::WebRequestRulesRegistry(Profile* profile, 26 WebRequestRulesRegistry::WebRequestRulesRegistry(Profile* profile,
27 Delegate* delegate) 27 Delegate* delegate)
28 : RulesRegistryWithCache(delegate) { 28 : RulesRegistryWithCache(delegate) {
29 if (profile) 29 if (profile)
30 extension_info_map_ = ExtensionSystem::Get(profile)->info_map(); 30 extension_info_map_ = ExtensionSystem::Get(profile)->info_map();
31 } 31 }
32 32
33 std::set<const WebRequestRule*> 33 std::set<const WebRequestRule*> WebRequestRulesRegistry::GetMatches(
34 WebRequestRulesRegistry::GetMatches( 34 DeclarativeWebRequestData* request_data) {
35 const DeclarativeWebRequestData& request_data) {
36 typedef std::set<const WebRequestRule*> RuleSet; 35 typedef std::set<const WebRequestRule*> RuleSet;
37 typedef std::set<URLMatcherConditionSet::ID> URLMatches; 36 typedef std::set<URLMatcherConditionSet::ID> URLMatches;
38 37
39 RuleSet result; 38 RuleSet result;
40 URLMatches url_matches = url_matcher_.MatchURL(request_data.request->url()); 39
40 request_data->url_match_ids =
41 url_matcher_.MatchURL(request_data->request->url());
42 request_data->first_party_url_match_ids =
43 url_matcher_.MatchURL(request_data->request->first_party_for_cookies());
44 URLMatches all_url_matches = request_data->url_match_ids;
vabr (Chromium) 2013/01/22 14:54:30 This would go away if we got rid of the now-unused
45 all_url_matches.insert(request_data->first_party_url_match_ids.begin(),
46 request_data->first_party_url_match_ids.end());
41 47
42 // 1st phase -- add all rules with some conditions without UrlFilter 48 // 1st phase -- add all rules with some conditions without UrlFilter
43 // attributes. 49 // attributes.
44 for (RuleSet::const_iterator it = rules_with_untriggered_conditions_.begin(); 50 for (RuleSet::const_iterator it = rules_with_untriggered_conditions_.begin();
45 it != rules_with_untriggered_conditions_.end(); ++it) { 51 it != rules_with_untriggered_conditions_.end(); ++it) {
46 if ((*it)->conditions().IsFulfilled(-1, url_matches, request_data)) 52 if ((*it)->conditions().IsFulfilled(-1, all_url_matches, *request_data))
47 result.insert(*it); 53 result.insert(*it);
48 } 54 }
49 55
50 // 2nd phase -- add all rules with some conditions triggered by URL matches. 56 // 2nd phase -- add all rules with some conditions triggered by URL matches.
51 for (URLMatches::const_iterator url_match = url_matches.begin(); 57 for (URLMatches::const_iterator url_match = all_url_matches.begin();
52 url_match != url_matches.end(); ++url_match) { 58 url_match != all_url_matches.end(); ++url_match) {
53 RuleTriggers::const_iterator rule_trigger = rule_triggers_.find(*url_match); 59 RuleTriggers::const_iterator rule_trigger = rule_triggers_.find(*url_match);
54 CHECK(rule_trigger != rule_triggers_.end()); 60 CHECK(rule_trigger != rule_triggers_.end());
55 if (!ContainsKey(result, rule_trigger->second) && 61 if (!ContainsKey(result, rule_trigger->second) &&
56 rule_trigger->second->conditions().IsFulfilled(*url_match, url_matches, 62 rule_trigger->second->conditions().IsFulfilled(
57 request_data)) 63 *url_match, all_url_matches, *request_data))
58 result.insert(rule_trigger->second); 64 result.insert(rule_trigger->second);
59 } 65 }
60 66
61 return result; 67 return result;
62 } 68 }
63 69
64 std::list<LinkedPtrEventResponseDelta> WebRequestRulesRegistry::CreateDeltas( 70 std::list<LinkedPtrEventResponseDelta> WebRequestRulesRegistry::CreateDeltas(
65 const ExtensionInfoMap* extension_info_map, 71 const ExtensionInfoMap* extension_info_map,
66 const DeclarativeWebRequestData& request_data, 72 DeclarativeWebRequestData* request_data,
67 bool crosses_incognito) { 73 bool crosses_incognito) {
68 if (webrequest_rules_.empty()) 74 if (webrequest_rules_.empty())
69 return std::list<LinkedPtrEventResponseDelta>(); 75 return std::list<LinkedPtrEventResponseDelta>();
70 76
71 std::set<const WebRequestRule*> matches = GetMatches(request_data); 77 std::set<const WebRequestRule*> matches = GetMatches(request_data);
72 78
73 // Sort all matching rules by their priority so that they can be processed 79 // Sort all matching rules by their priority so that they can be processed
74 // in decreasing order. 80 // in decreasing order.
75 typedef std::pair<WebRequestRule::Priority, WebRequestRule::GlobalRuleId> 81 typedef std::pair<WebRequestRule::Priority, WebRequestRule::GlobalRuleId>
76 PriorityRuleIdPair; 82 PriorityRuleIdPair;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 115
110 // Skip rule if a previous rule of this extension instructed to ignore 116 // Skip rule if a previous rule of this extension instructed to ignore
111 // all rules with a lower priority than min_priorities[extension_id]. 117 // all rules with a lower priority than min_priorities[extension_id].
112 int current_min_priority = min_priorities[extension_id]; 118 int current_min_priority = min_priorities[extension_id];
113 if (priority_of_rule < current_min_priority) 119 if (priority_of_rule < current_min_priority)
114 continue; 120 continue;
115 121
116 122
117 std::list<LinkedPtrEventResponseDelta> rule_result; 123 std::list<LinkedPtrEventResponseDelta> rule_result;
118 WebRequestAction::ApplyInfo apply_info = { 124 WebRequestAction::ApplyInfo apply_info = {
119 extension_info_map, request_data, crosses_incognito, &rule_result 125 extension_info_map, *request_data, crosses_incognito, &rule_result
120 }; 126 };
121 rule->Apply(&apply_info); 127 rule->Apply(&apply_info);
122 result.splice(result.begin(), rule_result); 128 result.splice(result.begin(), rule_result);
123 129
124 min_priorities[extension_id] = std::max(current_min_priority, 130 min_priorities[extension_id] = std::max(current_min_priority,
125 rule->GetMinimumPriority()); 131 rule->GetMinimumPriority());
126 } 132 }
127 return result; 133 return result;
128 } 134 }
129 135
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 } 300 }
295 if (!found_matching_condition) { 301 if (!found_matching_condition) {
296 *error = kActionCannotBeExecuted; 302 *error = kActionCannotBeExecuted;
297 return false; 303 return false;
298 } 304 }
299 } 305 }
300 return true; 306 return true;
301 } 307 }
302 308
303 } // namespace extensions 309 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698