| 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 886 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 897 modified |= cookie->SetIsSecure(*modification->secure); | 897 modified |= cookie->SetIsSecure(*modification->secure); |
| 898 if (modification->http_only.get()) | 898 if (modification->http_only.get()) |
| 899 modified |= cookie->SetIsHttpOnly(*modification->http_only); | 899 modified |= cookie->SetIsHttpOnly(*modification->http_only); |
| 900 return modified; | 900 return modified; |
| 901 } | 901 } |
| 902 | 902 |
| 903 static bool DoesResponseCookieMatchFilter(net::ParsedCookie* cookie, | 903 static bool DoesResponseCookieMatchFilter(net::ParsedCookie* cookie, |
| 904 FilterResponseCookie* filter) { | 904 FilterResponseCookie* filter) { |
| 905 if (!cookie->IsValid()) return false; | 905 if (!cookie->IsValid()) return false; |
| 906 if (!filter) return true; | 906 if (!filter) return true; |
| 907 if (filter->name.get() && cookie->Name() != *filter->name) return false; | 907 if (filter->name && cookie->Name() != *filter->name) |
| 908 if (filter->value.get() && cookie->Value() != *filter->value) return false; | 908 return false; |
| 909 if (filter->expires.get()) { | 909 if (filter->value && cookie->Value() != *filter->value) |
| 910 return false; |
| 911 if (filter->expires) { |
| 910 std::string actual_value = | 912 std::string actual_value = |
| 911 cookie->HasExpires() ? cookie->Expires() : std::string(); | 913 cookie->HasExpires() ? cookie->Expires() : std::string(); |
| 912 if (actual_value != *filter->expires) | 914 if (actual_value != *filter->expires) |
| 913 return false; | 915 return false; |
| 914 } | 916 } |
| 915 if (filter->max_age.get()) { | 917 if (filter->max_age) { |
| 916 std::string actual_value = | 918 std::string actual_value = |
| 917 cookie->HasMaxAge() ? cookie->MaxAge() : std::string(); | 919 cookie->HasMaxAge() ? cookie->MaxAge() : std::string(); |
| 918 if (actual_value != base::IntToString(*filter->max_age)) | 920 if (actual_value != base::IntToString(*filter->max_age)) |
| 919 return false; | 921 return false; |
| 920 } | 922 } |
| 921 if (filter->domain.get()) { | 923 if (filter->domain) { |
| 922 std::string actual_value = | 924 std::string actual_value = |
| 923 cookie->HasDomain() ? cookie->Domain() : std::string(); | 925 cookie->HasDomain() ? cookie->Domain() : std::string(); |
| 924 if (actual_value != *filter->domain) | 926 if (actual_value != *filter->domain) |
| 925 return false; | 927 return false; |
| 926 } | 928 } |
| 927 if (filter->path.get()) { | 929 if (filter->path) { |
| 928 std::string actual_value = | 930 std::string actual_value = |
| 929 cookie->HasPath() ? cookie->Path() : std::string(); | 931 cookie->HasPath() ? cookie->Path() : std::string(); |
| 930 if (actual_value != *filter->path) | 932 if (actual_value != *filter->path) |
| 931 return false; | 933 return false; |
| 932 } | 934 } |
| 933 if (filter->secure.get() && cookie->IsSecure() != *filter->secure) | 935 if (filter->secure && cookie->IsSecure() != *filter->secure) |
| 934 return false; | 936 return false; |
| 935 if (filter->http_only.get() && cookie->IsHttpOnly() != *filter->http_only) | 937 if (filter->http_only && cookie->IsHttpOnly() != *filter->http_only) |
| 936 return false; | 938 return false; |
| 937 int64 seconds_till_expiry; | 939 if (filter->age_upper_bound || filter->age_lower_bound || |
| 938 bool lifetime_parsed = false; | 940 (filter->session_cookie && *filter->session_cookie)) { |
| 939 if (filter->age_upper_bound.get() || | 941 int64 seconds_to_expiry; |
| 940 filter->age_lower_bound.get() || | 942 bool lifetime_parsed = ParseCookieLifetime(cookie, &seconds_to_expiry); |
| 941 (filter->session_cookie.get() && *filter->session_cookie)) { | 943 if (filter->age_upper_bound && seconds_to_expiry > *filter->age_upper_bound) |
| 942 lifetime_parsed = ParseCookieLifetime(cookie, &seconds_till_expiry); | |
| 943 } | |
| 944 if (filter->age_upper_bound.get()) { | |
| 945 if (seconds_till_expiry > *filter->age_upper_bound) | |
| 946 return false; | 944 return false; |
| 947 } | 945 if (filter->age_lower_bound && seconds_to_expiry < *filter->age_lower_bound) |
| 948 if (filter->age_lower_bound.get()) { | |
| 949 if (seconds_till_expiry < *filter->age_lower_bound) | |
| 950 return false; | 946 return false; |
| 951 } | 947 if (filter->session_cookie && *filter->session_cookie && lifetime_parsed) |
| 952 if (filter->session_cookie.get() && | 948 return false; |
| 953 *filter->session_cookie && | |
| 954 lifetime_parsed) { | |
| 955 return false; | |
| 956 } | 949 } |
| 957 return true; | 950 return true; |
| 958 } | 951 } |
| 959 | 952 |
| 960 // Applies all CookieModificationType::ADD operations for response cookies of | 953 // Applies all CookieModificationType::ADD operations for response cookies of |
| 961 // |deltas| to |cookies|. Returns whether any cookie was added. | 954 // |deltas| to |cookies|. Returns whether any cookie was added. |
| 962 static bool MergeAddResponseCookieModifications( | 955 static bool MergeAddResponseCookieModifications( |
| 963 const EventResponseDeltas& deltas, | 956 const EventResponseDeltas& deltas, |
| 964 ParsedResponseCookies* cookies) { | 957 ParsedResponseCookies* cookies) { |
| 965 bool modified = false; | 958 bool modified = false; |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1315 return net::HttpUtil::IsToken(name); | 1308 return net::HttpUtil::IsToken(name); |
| 1316 } | 1309 } |
| 1317 | 1310 |
| 1318 bool IsValidHeaderValue(const std::string& value) { | 1311 bool IsValidHeaderValue(const std::string& value) { |
| 1319 // Just a sanity check: disallow NUL and CRLF. | 1312 // Just a sanity check: disallow NUL and CRLF. |
| 1320 return value.find('\0') == std::string::npos && | 1313 return value.find('\0') == std::string::npos && |
| 1321 value.find("\r\n") == std::string::npos; | 1314 value.find("\r\n") == std::string::npos; |
| 1322 } | 1315 } |
| 1323 | 1316 |
| 1324 } // namespace extension_web_request_api_helpers | 1317 } // namespace extension_web_request_api_helpers |
| OLD | NEW |