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