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_att
ribute.h" | 5 #include "extensions/browser/api/declarative_webrequest/webrequest_condition_att
ribute.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | |
10 #include <utility> | 9 #include <utility> |
11 #include <vector> | 10 #include <vector> |
12 | 11 |
13 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
14 #include "base/logging.h" | 13 #include "base/logging.h" |
15 #include "base/macros.h" | 14 #include "base/macros.h" |
16 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
| 16 #include "base/stl_util.h" |
17 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
18 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
19 #include "base/values.h" | 19 #include "base/values.h" |
20 #include "content/public/browser/resource_request_info.h" | 20 #include "content/public/browser/resource_request_info.h" |
21 #include "extensions/browser/api/declarative/deduping_factory.h" | 21 #include "extensions/browser/api/declarative/deduping_factory.h" |
22 #include "extensions/browser/api/declarative_webrequest/request_stage.h" | 22 #include "extensions/browser/api/declarative_webrequest/request_stage.h" |
23 #include "extensions/browser/api/declarative_webrequest/webrequest_condition.h" | 23 #include "extensions/browser/api/declarative_webrequest/webrequest_condition.h" |
24 #include "extensions/browser/api/declarative_webrequest/webrequest_constants.h" | 24 #include "extensions/browser/api/declarative_webrequest/webrequest_constants.h" |
25 #include "extensions/browser/api/web_request/web_request_api_helpers.h" | 25 #include "extensions/browser/api/web_request/web_request_api_helpers.h" |
26 #include "extensions/browser/api/web_request/web_request_resource_type.h" | 26 #include "extensions/browser/api/web_request/web_request_resource_type.h" |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 return ON_BEFORE_REQUEST | ON_BEFORE_SEND_HEADERS | ON_SEND_HEADERS | | 175 return ON_BEFORE_REQUEST | ON_BEFORE_SEND_HEADERS | ON_SEND_HEADERS | |
176 ON_HEADERS_RECEIVED | ON_AUTH_REQUIRED | ON_BEFORE_REDIRECT | | 176 ON_HEADERS_RECEIVED | ON_AUTH_REQUIRED | ON_BEFORE_REDIRECT | |
177 ON_RESPONSE_STARTED | ON_COMPLETED | ON_ERROR; | 177 ON_RESPONSE_STARTED | ON_COMPLETED | ON_ERROR; |
178 } | 178 } |
179 | 179 |
180 bool WebRequestConditionAttributeResourceType::IsFulfilled( | 180 bool WebRequestConditionAttributeResourceType::IsFulfilled( |
181 const WebRequestData& request_data) const { | 181 const WebRequestData& request_data) const { |
182 if (!(request_data.stage & GetStages())) | 182 if (!(request_data.stage & GetStages())) |
183 return false; | 183 return false; |
184 const auto resource_type = GetWebRequestResourceType(request_data.request); | 184 const auto resource_type = GetWebRequestResourceType(request_data.request); |
185 return std::find(types_.begin(), types_.end(), resource_type) != types_.end(); | 185 return base::ContainsValue(types_, resource_type); |
186 } | 186 } |
187 | 187 |
188 WebRequestConditionAttribute::Type | 188 WebRequestConditionAttribute::Type |
189 WebRequestConditionAttributeResourceType::GetType() const { | 189 WebRequestConditionAttributeResourceType::GetType() const { |
190 return CONDITION_RESOURCE_TYPE; | 190 return CONDITION_RESOURCE_TYPE; |
191 } | 191 } |
192 | 192 |
193 std::string WebRequestConditionAttributeResourceType::GetName() const { | 193 std::string WebRequestConditionAttributeResourceType::GetName() const { |
194 return keys::kResourceTypeKey; | 194 return keys::kResourceTypeKey; |
195 } | 195 } |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 std::string content_type; | 259 std::string content_type; |
260 request_data.original_response_headers->GetNormalizedHeader( | 260 request_data.original_response_headers->GetNormalizedHeader( |
261 net::HttpRequestHeaders::kContentType, &content_type); | 261 net::HttpRequestHeaders::kContentType, &content_type); |
262 std::string mime_type; | 262 std::string mime_type; |
263 std::string charset; | 263 std::string charset; |
264 bool had_charset = false; | 264 bool had_charset = false; |
265 net::HttpUtil::ParseContentType( | 265 net::HttpUtil::ParseContentType( |
266 content_type, &mime_type, &charset, &had_charset, NULL); | 266 content_type, &mime_type, &charset, &had_charset, NULL); |
267 | 267 |
268 if (inclusive_) { | 268 if (inclusive_) { |
269 return std::find(content_types_.begin(), content_types_.end(), | 269 return base::ContainsValue(content_types_, mime_type); |
270 mime_type) != content_types_.end(); | |
271 } else { | 270 } else { |
272 return std::find(content_types_.begin(), content_types_.end(), | 271 return !base::ContainsValue(content_types_, mime_type); |
273 mime_type) == content_types_.end(); | |
274 } | 272 } |
275 } | 273 } |
276 | 274 |
277 WebRequestConditionAttribute::Type | 275 WebRequestConditionAttribute::Type |
278 WebRequestConditionAttributeContentType::GetType() const { | 276 WebRequestConditionAttributeContentType::GetType() const { |
279 return CONDITION_CONTENT_TYPE; | 277 return CONDITION_CONTENT_TYPE; |
280 } | 278 } |
281 | 279 |
282 std::string WebRequestConditionAttributeContentType::GetName() const { | 280 std::string WebRequestConditionAttributeContentType::GetName() const { |
283 return (inclusive_ ? keys::kContentTypeKey : keys::kExcludeContentTypeKey); | 281 return (inclusive_ ? keys::kContentTypeKey : keys::kExcludeContentTypeKey); |
(...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
873 bool WebRequestConditionAttributeStages::Equals( | 871 bool WebRequestConditionAttributeStages::Equals( |
874 const WebRequestConditionAttribute* other) const { | 872 const WebRequestConditionAttribute* other) const { |
875 if (!WebRequestConditionAttribute::Equals(other)) | 873 if (!WebRequestConditionAttribute::Equals(other)) |
876 return false; | 874 return false; |
877 const WebRequestConditionAttributeStages* casted_other = | 875 const WebRequestConditionAttributeStages* casted_other = |
878 static_cast<const WebRequestConditionAttributeStages*>(other); | 876 static_cast<const WebRequestConditionAttributeStages*>(other); |
879 return allowed_stages_ == casted_other->allowed_stages_; | 877 return allowed_stages_ == casted_other->allowed_stages_; |
880 } | 878 } |
881 | 879 |
882 } // namespace extensions | 880 } // namespace extensions |
OLD | NEW |