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 "chrome/browser/extensions/api/declarative_webrequest/webrequest_condit
ion.h" | 5 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_condit
ion.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
11 #include "chrome/browser/extensions/api/declarative_webrequest/request_stages.h" | 11 #include "chrome/browser/extensions/api/declarative_webrequest/request_stage.h" |
12 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_condit
ion_attribute.h" | 12 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_condit
ion_attribute.h" |
13 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_consta
nts.h" | 13 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_consta
nts.h" |
14 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_consta
nts.h" | 14 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_consta
nts.h" |
15 #include "chrome/common/extensions/matcher/url_matcher.h" | 15 #include "chrome/common/extensions/matcher/url_matcher.h" |
16 #include "chrome/common/extensions/matcher/url_matcher_factory.h" | 16 #include "chrome/common/extensions/matcher/url_matcher_factory.h" |
17 #include "net/url_request/url_request.h" | 17 #include "net/url_request/url_request.h" |
18 | 18 |
19 namespace keys = extensions::declarative_webrequest_constants; | 19 namespace keys = extensions::declarative_webrequest_constants; |
20 | 20 |
21 namespace { | 21 namespace { |
(...skipping 26 matching lines...) Expand all Loading... |
48 applicable_request_stages_(~0) { | 48 applicable_request_stages_(~0) { |
49 CHECK(url_matcher_conditions.get()); | 49 CHECK(url_matcher_conditions.get()); |
50 for (WebRequestConditionAttributes::const_iterator i = | 50 for (WebRequestConditionAttributes::const_iterator i = |
51 condition_attributes_.begin(); i != condition_attributes_.end(); ++i) { | 51 condition_attributes_.begin(); i != condition_attributes_.end(); ++i) { |
52 applicable_request_stages_ &= (*i)->GetStages(); | 52 applicable_request_stages_ &= (*i)->GetStages(); |
53 } | 53 } |
54 } | 54 } |
55 | 55 |
56 WebRequestCondition::~WebRequestCondition() {} | 56 WebRequestCondition::~WebRequestCondition() {} |
57 | 57 |
58 bool WebRequestCondition::IsFulfilled(net::URLRequest* request, | 58 bool WebRequestCondition::IsFulfilled( |
59 RequestStages request_stage) const { | 59 const WebRequestRule::RequestData& request_data) const { |
60 // All condition attributes must be fulfilled for a fulfilled condition. | 60 // All condition attributes must be fulfilled for a fulfilled condition. |
61 if (!(request_stage & applicable_request_stages_)) { | 61 if (!(request_data.stage & applicable_request_stages_)) { |
62 // A condition that cannot be evaluated is considered as violated. | 62 // A condition that cannot be evaluated is considered as violated. |
63 return false; | 63 return false; |
64 } | 64 } |
65 | 65 |
66 for (WebRequestConditionAttributes::const_iterator i = | 66 for (WebRequestConditionAttributes::const_iterator i = |
67 condition_attributes_.begin(); i != condition_attributes_.end(); ++i) { | 67 condition_attributes_.begin(); i != condition_attributes_.end(); ++i) { |
68 if (!(*i)->IsFulfilled(request, request_stage)) | 68 if (!(*i)->IsFulfilled(request_data)) |
69 return false; | 69 return false; |
70 } | 70 } |
71 return true; | 71 return true; |
72 } | 72 } |
73 | 73 |
74 // static | 74 // static |
75 scoped_ptr<WebRequestCondition> WebRequestCondition::Create( | 75 scoped_ptr<WebRequestCondition> WebRequestCondition::Create( |
76 URLMatcherConditionFactory* url_matcher_condition_factory, | 76 URLMatcherConditionFactory* url_matcher_condition_factory, |
77 const base::Value& condition, | 77 const base::Value& condition, |
78 std::string* error) { | 78 std::string* error) { |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 URLMatcherConditionSet::ID trigger_id = | 153 URLMatcherConditionSet::ID trigger_id = |
154 (*i)->url_matcher_condition_set_id(); | 154 (*i)->url_matcher_condition_set_id(); |
155 match_triggers_[trigger_id] = i->get(); | 155 match_triggers_[trigger_id] = i->get(); |
156 } | 156 } |
157 } | 157 } |
158 | 158 |
159 WebRequestConditionSet::~WebRequestConditionSet() {} | 159 WebRequestConditionSet::~WebRequestConditionSet() {} |
160 | 160 |
161 bool WebRequestConditionSet::IsFulfilled( | 161 bool WebRequestConditionSet::IsFulfilled( |
162 URLMatcherConditionSet::ID url_match, | 162 URLMatcherConditionSet::ID url_match, |
163 net::URLRequest* request, | 163 const WebRequestRule::RequestData& request_data) const { |
164 RequestStages request_stage) const { | |
165 MatchTriggers::const_iterator trigger = match_triggers_.find(url_match); | 164 MatchTriggers::const_iterator trigger = match_triggers_.find(url_match); |
166 DCHECK(trigger != match_triggers_.end()); | 165 DCHECK(trigger != match_triggers_.end()); |
167 DCHECK_EQ(url_match, trigger->second->url_matcher_condition_set_id()); | 166 DCHECK_EQ(url_match, trigger->second->url_matcher_condition_set_id()); |
168 return trigger->second->IsFulfilled(request, request_stage); | 167 return trigger->second->IsFulfilled(request_data); |
169 } | 168 } |
170 | 169 |
171 void WebRequestConditionSet::GetURLMatcherConditionSets( | 170 void WebRequestConditionSet::GetURLMatcherConditionSets( |
172 URLMatcherConditionSet::Vector* condition_sets) const { | 171 URLMatcherConditionSet::Vector* condition_sets) const { |
173 for (Conditions::const_iterator i = conditions_.begin(); | 172 for (Conditions::const_iterator i = conditions_.begin(); |
174 i != conditions_.end(); ++i) { | 173 i != conditions_.end(); ++i) { |
175 condition_sets->push_back((*i)->url_matcher_condition_set()); | 174 condition_sets->push_back((*i)->url_matcher_condition_set()); |
176 } | 175 } |
177 } | 176 } |
178 | 177 |
(...skipping 12 matching lines...) Expand all Loading... |
191 (*i)->value(), error); | 190 (*i)->value(), error); |
192 if (!error->empty()) | 191 if (!error->empty()) |
193 return scoped_ptr<WebRequestConditionSet>(NULL); | 192 return scoped_ptr<WebRequestConditionSet>(NULL); |
194 result.push_back(make_linked_ptr(condition.release())); | 193 result.push_back(make_linked_ptr(condition.release())); |
195 } | 194 } |
196 | 195 |
197 return scoped_ptr<WebRequestConditionSet>(new WebRequestConditionSet(result)); | 196 return scoped_ptr<WebRequestConditionSet>(new WebRequestConditionSet(result)); |
198 } | 197 } |
199 | 198 |
200 } // namespace extensions | 199 } // namespace extensions |
OLD | NEW |