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/web_request/web_request_api_helpers.h" | 5 #include "chrome/browser/extensions/api/web_request/web_request_api_helpers.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 if (!new_response_headers) | 335 if (!new_response_headers) |
336 return result; | 336 return result; |
337 | 337 |
338 // Find deleted headers (header keys are treated case insensitively). | 338 // Find deleted headers (header keys are treated case insensitively). |
339 { | 339 { |
340 void* iter = NULL; | 340 void* iter = NULL; |
341 std::string name; | 341 std::string name; |
342 std::string value; | 342 std::string value; |
343 while (old_response_headers->EnumerateHeaderLines(&iter, &name, &value)) { | 343 while (old_response_headers->EnumerateHeaderLines(&iter, &name, &value)) { |
344 std::string name_lowercase(name); | 344 std::string name_lowercase(name); |
345 StringToLowerASCII(&name_lowercase); | 345 base::StringToLowerASCII(&name_lowercase); |
346 | 346 |
347 bool header_found = false; | 347 bool header_found = false; |
348 for (ResponseHeaders::const_iterator i = new_response_headers->begin(); | 348 for (ResponseHeaders::const_iterator i = new_response_headers->begin(); |
349 i != new_response_headers->end(); ++i) { | 349 i != new_response_headers->end(); ++i) { |
350 if (LowerCaseEqualsASCII(i->first, name_lowercase.c_str()) && | 350 if (LowerCaseEqualsASCII(i->first, name_lowercase.c_str()) && |
351 value == i->second) { | 351 value == i->second) { |
352 header_found = true; | 352 header_found = true; |
353 break; | 353 break; |
354 } | 354 } |
355 } | 355 } |
(...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1010 modified |= MergeRemoveResponseCookieModifications(deltas, &cookies); | 1010 modified |= MergeRemoveResponseCookieModifications(deltas, &cookies); |
1011 | 1011 |
1012 // Store new value. | 1012 // Store new value. |
1013 if (modified) | 1013 if (modified) |
1014 StoreResponseCookies(cookies, *override_response_headers); | 1014 StoreResponseCookies(cookies, *override_response_headers); |
1015 } | 1015 } |
1016 | 1016 |
1017 // Converts the key of the (key, value) pair to lower case. | 1017 // Converts the key of the (key, value) pair to lower case. |
1018 static ResponseHeader ToLowerCase(const ResponseHeader& header) { | 1018 static ResponseHeader ToLowerCase(const ResponseHeader& header) { |
1019 std::string lower_key(header.first); | 1019 std::string lower_key(header.first); |
1020 StringToLowerASCII(&lower_key); | 1020 base::StringToLowerASCII(&lower_key); |
1021 return ResponseHeader(lower_key, header.second); | 1021 return ResponseHeader(lower_key, header.second); |
1022 } | 1022 } |
1023 | 1023 |
1024 // Returns the extension ID of the first extension in |deltas| that removes the | 1024 // Returns the extension ID of the first extension in |deltas| that removes the |
1025 // request header identified by |key|. | 1025 // request header identified by |key|. |
1026 static std::string FindRemoveResponseHeader( | 1026 static std::string FindRemoveResponseHeader( |
1027 const EventResponseDeltas& deltas, | 1027 const EventResponseDeltas& deltas, |
1028 const std::string& key) { | 1028 const std::string& key) { |
1029 std::string lower_key = StringToLowerASCII(key); | 1029 std::string lower_key = base::StringToLowerASCII(key); |
1030 EventResponseDeltas::const_iterator delta; | 1030 EventResponseDeltas::const_iterator delta; |
1031 for (delta = deltas.begin(); delta != deltas.end(); ++delta) { | 1031 for (delta = deltas.begin(); delta != deltas.end(); ++delta) { |
1032 ResponseHeaders::const_iterator i; | 1032 ResponseHeaders::const_iterator i; |
1033 for (i = (*delta)->deleted_response_headers.begin(); | 1033 for (i = (*delta)->deleted_response_headers.begin(); |
1034 i != (*delta)->deleted_response_headers.end(); ++i) { | 1034 i != (*delta)->deleted_response_headers.end(); ++i) { |
1035 if (StringToLowerASCII(i->first) == lower_key) | 1035 if (base::StringToLowerASCII(i->first) == lower_key) |
1036 return (*delta)->extension_id; | 1036 return (*delta)->extension_id; |
1037 } | 1037 } |
1038 } | 1038 } |
1039 return std::string(); | 1039 return std::string(); |
1040 } | 1040 } |
1041 | 1041 |
1042 void MergeOnHeadersReceivedResponses( | 1042 void MergeOnHeadersReceivedResponses( |
1043 const EventResponseDeltas& deltas, | 1043 const EventResponseDeltas& deltas, |
1044 const net::HttpResponseHeaders* original_response_headers, | 1044 const net::HttpResponseHeaders* original_response_headers, |
1045 scoped_refptr<net::HttpResponseHeaders>* override_response_headers, | 1045 scoped_refptr<net::HttpResponseHeaders>* override_response_headers, |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1247 return net::HttpUtil::IsToken(name); | 1247 return net::HttpUtil::IsToken(name); |
1248 } | 1248 } |
1249 | 1249 |
1250 bool IsValidHeaderValue(const std::string& value) { | 1250 bool IsValidHeaderValue(const std::string& value) { |
1251 // Just a sanity check: disallow NUL and CRLF. | 1251 // Just a sanity check: disallow NUL and CRLF. |
1252 return value.find('\0') == std::string::npos && | 1252 return value.find('\0') == std::string::npos && |
1253 value.find("\r\n") == std::string::npos; | 1253 value.find("\r\n") == std::string::npos; |
1254 } | 1254 } |
1255 | 1255 |
1256 } // namespace extension_web_request_api_helpers | 1256 } // namespace extension_web_request_api_helpers |
OLD | NEW |