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/web_request/web_request_api_helpers.h" | 5 #include "extensions/browser/api/web_request/web_request_api_helpers.h" |
6 | 6 |
| 7 #include <stddef.h> |
| 8 #include <stdint.h> |
| 9 |
7 #include <algorithm> | 10 #include <algorithm> |
8 #include <cmath> | 11 #include <cmath> |
9 #include <utility> | 12 #include <utility> |
10 | 13 |
11 #include "base/bind.h" | 14 #include "base/bind.h" |
12 #include "base/macros.h" | 15 #include "base/macros.h" |
13 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
14 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
15 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
16 #include "base/time/time.h" | 19 #include "base/time/time.h" |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 | 82 |
80 const size_t kResourceTypeValuesLength = arraysize(kResourceTypeValues); | 83 const size_t kResourceTypeValuesLength = arraysize(kResourceTypeValues); |
81 | 84 |
82 typedef std::vector<linked_ptr<net::ParsedCookie> > ParsedResponseCookies; | 85 typedef std::vector<linked_ptr<net::ParsedCookie> > ParsedResponseCookies; |
83 | 86 |
84 void ClearCacheOnNavigationOnUI() { | 87 void ClearCacheOnNavigationOnUI() { |
85 web_cache::WebCacheManager::GetInstance()->ClearCacheOnNavigation(); | 88 web_cache::WebCacheManager::GetInstance()->ClearCacheOnNavigation(); |
86 } | 89 } |
87 | 90 |
88 bool ParseCookieLifetime(net::ParsedCookie* cookie, | 91 bool ParseCookieLifetime(net::ParsedCookie* cookie, |
89 int64* seconds_till_expiry) { | 92 int64_t* seconds_till_expiry) { |
90 // 'Max-Age' is processed first because according to: | 93 // 'Max-Age' is processed first because according to: |
91 // http://tools.ietf.org/html/rfc6265#section-5.3 'Max-Age' attribute | 94 // http://tools.ietf.org/html/rfc6265#section-5.3 'Max-Age' attribute |
92 // overrides 'Expires' attribute. | 95 // overrides 'Expires' attribute. |
93 if (cookie->HasMaxAge() && | 96 if (cookie->HasMaxAge() && |
94 base::StringToInt64(cookie->MaxAge(), seconds_till_expiry)) { | 97 base::StringToInt64(cookie->MaxAge(), seconds_till_expiry)) { |
95 return true; | 98 return true; |
96 } | 99 } |
97 | 100 |
98 Time parsed_expiry_time; | 101 Time parsed_expiry_time; |
99 if (cookie->HasExpires()) | 102 if (cookie->HasExpires()) |
(...skipping 777 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
877 cookie->HasPath() ? cookie->Path() : std::string(); | 880 cookie->HasPath() ? cookie->Path() : std::string(); |
878 if (actual_value != *filter->path) | 881 if (actual_value != *filter->path) |
879 return false; | 882 return false; |
880 } | 883 } |
881 if (filter->secure && cookie->IsSecure() != *filter->secure) | 884 if (filter->secure && cookie->IsSecure() != *filter->secure) |
882 return false; | 885 return false; |
883 if (filter->http_only && cookie->IsHttpOnly() != *filter->http_only) | 886 if (filter->http_only && cookie->IsHttpOnly() != *filter->http_only) |
884 return false; | 887 return false; |
885 if (filter->age_upper_bound || filter->age_lower_bound || | 888 if (filter->age_upper_bound || filter->age_lower_bound || |
886 (filter->session_cookie && *filter->session_cookie)) { | 889 (filter->session_cookie && *filter->session_cookie)) { |
887 int64 seconds_to_expiry; | 890 int64_t seconds_to_expiry; |
888 bool lifetime_parsed = ParseCookieLifetime(cookie, &seconds_to_expiry); | 891 bool lifetime_parsed = ParseCookieLifetime(cookie, &seconds_to_expiry); |
889 if (filter->age_upper_bound && seconds_to_expiry > *filter->age_upper_bound) | 892 if (filter->age_upper_bound && seconds_to_expiry > *filter->age_upper_bound) |
890 return false; | 893 return false; |
891 if (filter->age_lower_bound && seconds_to_expiry < *filter->age_lower_bound) | 894 if (filter->age_lower_bound && seconds_to_expiry < *filter->age_lower_bound) |
892 return false; | 895 return false; |
893 if (filter->session_cookie && *filter->session_cookie && lifetime_parsed) | 896 if (filter->session_cookie && *filter->session_cookie && lifetime_parsed) |
894 return false; | 897 return false; |
895 } | 898 } |
896 return true; | 899 return true; |
897 } | 900 } |
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1278 std::find(kResourceTypeStrings, | 1281 std::find(kResourceTypeStrings, |
1279 kResourceTypeStrings + kResourceTypeStringsLength, | 1282 kResourceTypeStrings + kResourceTypeStringsLength, |
1280 type_str); | 1283 type_str); |
1281 if (iter == (kResourceTypeStrings + kResourceTypeStringsLength)) | 1284 if (iter == (kResourceTypeStrings + kResourceTypeStringsLength)) |
1282 return false; | 1285 return false; |
1283 *type = kResourceTypeValues[iter - kResourceTypeStrings]; | 1286 *type = kResourceTypeValues[iter - kResourceTypeStrings]; |
1284 return true; | 1287 return true; |
1285 } | 1288 } |
1286 | 1289 |
1287 } // namespace extension_web_request_api_helpers | 1290 } // namespace extension_web_request_api_helpers |
OLD | NEW |