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 "extensions/browser/api/declarative_webrequest/webrequest_condition.h" | 5 #include "extensions/browser/api/declarative_webrequest/webrequest_condition.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/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 | 39 |
40 namespace extensions { | 40 namespace extensions { |
41 | 41 |
42 namespace keys = declarative_webrequest_constants; | 42 namespace keys = declarative_webrequest_constants; |
43 | 43 |
44 // | 44 // |
45 // WebRequestData | 45 // WebRequestData |
46 // | 46 // |
47 | 47 |
48 WebRequestData::WebRequestData(net::URLRequest* request, RequestStage stage) | 48 WebRequestData::WebRequestData(net::URLRequest* request, RequestStage stage) |
49 : request(request), | 49 : request(request), stage(stage), original_response_headers(nullptr) { |
50 stage(stage), | 50 } |
51 original_response_headers(NULL) {} | |
52 | 51 |
53 WebRequestData::WebRequestData( | 52 WebRequestData::WebRequestData( |
54 net::URLRequest* request, | 53 net::URLRequest* request, |
55 RequestStage stage, | 54 RequestStage stage, |
56 const net::HttpResponseHeaders* original_response_headers) | 55 const net::HttpResponseHeaders* original_response_headers) |
57 : request(request), | 56 : request(request), |
58 stage(stage), | 57 stage(stage), |
59 original_response_headers(original_response_headers) {} | 58 original_response_headers(original_response_headers) {} |
60 | 59 |
61 WebRequestData::~WebRequestData() {} | 60 WebRequestData::~WebRequestData() {} |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 if (first_party_url_matcher_conditions_.get()) | 122 if (first_party_url_matcher_conditions_.get()) |
124 condition_sets->push_back(first_party_url_matcher_conditions_); | 123 condition_sets->push_back(first_party_url_matcher_conditions_); |
125 } | 124 } |
126 | 125 |
127 // static | 126 // static |
128 scoped_ptr<WebRequestCondition> WebRequestCondition::Create( | 127 scoped_ptr<WebRequestCondition> WebRequestCondition::Create( |
129 const Extension* extension, | 128 const Extension* extension, |
130 URLMatcherConditionFactory* url_matcher_condition_factory, | 129 URLMatcherConditionFactory* url_matcher_condition_factory, |
131 const base::Value& condition, | 130 const base::Value& condition, |
132 std::string* error) { | 131 std::string* error) { |
133 const base::DictionaryValue* condition_dict = NULL; | 132 const base::DictionaryValue* condition_dict = nullptr; |
134 if (!condition.GetAsDictionary(&condition_dict)) { | 133 if (!condition.GetAsDictionary(&condition_dict)) { |
135 *error = kExpectedDictionary; | 134 *error = kExpectedDictionary; |
136 return scoped_ptr<WebRequestCondition>(); | 135 return scoped_ptr<WebRequestCondition>(); |
137 } | 136 } |
138 | 137 |
139 // Verify that we are dealing with a Condition whose type we understand. | 138 // Verify that we are dealing with a Condition whose type we understand. |
140 std::string instance_type; | 139 std::string instance_type; |
141 if (!condition_dict->GetString(keys::kInstanceTypeKey, &instance_type)) { | 140 if (!condition_dict->GetString(keys::kInstanceTypeKey, &instance_type)) { |
142 *error = kConditionWithoutInstanceType; | 141 *error = kConditionWithoutInstanceType; |
143 return scoped_ptr<WebRequestCondition>(); | 142 return scoped_ptr<WebRequestCondition>(); |
144 } | 143 } |
145 if (instance_type != keys::kRequestMatcherType) { | 144 if (instance_type != keys::kRequestMatcherType) { |
146 *error = kExpectedOtherConditionType; | 145 *error = kExpectedOtherConditionType; |
147 return scoped_ptr<WebRequestCondition>(); | 146 return scoped_ptr<WebRequestCondition>(); |
148 } | 147 } |
149 | 148 |
150 WebRequestConditionAttributes attributes; | 149 WebRequestConditionAttributes attributes; |
151 scoped_refptr<URLMatcherConditionSet> url_matcher_condition_set; | 150 scoped_refptr<URLMatcherConditionSet> url_matcher_condition_set; |
152 scoped_refptr<URLMatcherConditionSet> first_party_url_matcher_condition_set; | 151 scoped_refptr<URLMatcherConditionSet> first_party_url_matcher_condition_set; |
153 | 152 |
154 for (base::DictionaryValue::Iterator iter(*condition_dict); | 153 for (base::DictionaryValue::Iterator iter(*condition_dict); |
155 !iter.IsAtEnd(); iter.Advance()) { | 154 !iter.IsAtEnd(); iter.Advance()) { |
156 const std::string& condition_attribute_name = iter.key(); | 155 const std::string& condition_attribute_name = iter.key(); |
157 const base::Value& condition_attribute_value = iter.value(); | 156 const base::Value& condition_attribute_value = iter.value(); |
158 const bool name_is_url = condition_attribute_name == keys::kUrlKey; | 157 const bool name_is_url = condition_attribute_name == keys::kUrlKey; |
159 if (condition_attribute_name == keys::kInstanceTypeKey) { | 158 if (condition_attribute_name == keys::kInstanceTypeKey) { |
160 // Skip this. | 159 // Skip this. |
161 } else if (name_is_url || | 160 } else if (name_is_url || |
162 condition_attribute_name == keys::kFirstPartyForCookiesUrlKey) { | 161 condition_attribute_name == keys::kFirstPartyForCookiesUrlKey) { |
163 const base::DictionaryValue* dict = NULL; | 162 const base::DictionaryValue* dict = nullptr; |
164 if (!condition_attribute_value.GetAsDictionary(&dict)) { | 163 if (!condition_attribute_value.GetAsDictionary(&dict)) { |
165 *error = base::StringPrintf(kInvalidTypeOfParamter, | 164 *error = base::StringPrintf(kInvalidTypeOfParamter, |
166 condition_attribute_name.c_str()); | 165 condition_attribute_name.c_str()); |
167 } else { | 166 } else { |
168 if (name_is_url) { | 167 if (name_is_url) { |
169 url_matcher_condition_set = | 168 url_matcher_condition_set = |
170 URLMatcherFactory::CreateFromURLFilterDictionary( | 169 URLMatcherFactory::CreateFromURLFilterDictionary( |
171 url_matcher_condition_factory, dict, ++g_next_id, error); | 170 url_matcher_condition_factory, dict, ++g_next_id, error); |
172 } else { | 171 } else { |
173 first_party_url_matcher_condition_set = | 172 first_party_url_matcher_condition_set = |
(...skipping 21 matching lines...) Expand all Loading... |
195 | 194 |
196 if (!result->stages()) { | 195 if (!result->stages()) { |
197 *error = kConditionCannotBeFulfilled; | 196 *error = kConditionCannotBeFulfilled; |
198 return scoped_ptr<WebRequestCondition>(); | 197 return scoped_ptr<WebRequestCondition>(); |
199 } | 198 } |
200 | 199 |
201 return result.Pass(); | 200 return result.Pass(); |
202 } | 201 } |
203 | 202 |
204 } // namespace extensions | 203 } // namespace extensions |
OLD | NEW |