| 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> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 #include "net/log/net_log_event_type.h" | 36 #include "net/log/net_log_event_type.h" |
| 37 #include "net/log/net_log_parameters_callback.h" | 37 #include "net/log/net_log_parameters_callback.h" |
| 38 #include "net/log/net_log_with_source.h" | 38 #include "net/log/net_log_with_source.h" |
| 39 #include "net/url_request/url_request.h" | 39 #include "net/url_request/url_request.h" |
| 40 #include "url/url_constants.h" | 40 #include "url/url_constants.h" |
| 41 | 41 |
| 42 // TODO(battre): move all static functions into an anonymous namespace at the | 42 // TODO(battre): move all static functions into an anonymous namespace at the |
| 43 // top of this file. | 43 // top of this file. |
| 44 | 44 |
| 45 using base::Time; | 45 using base::Time; |
| 46 using content::ResourceType; | |
| 47 using net::cookie_util::ParsedRequestCookie; | 46 using net::cookie_util::ParsedRequestCookie; |
| 48 using net::cookie_util::ParsedRequestCookies; | 47 using net::cookie_util::ParsedRequestCookies; |
| 49 | 48 |
| 50 namespace keys = extension_web_request_api_constants; | 49 namespace keys = extension_web_request_api_constants; |
| 51 | 50 |
| 52 namespace extension_web_request_api_helpers { | 51 namespace extension_web_request_api_helpers { |
| 53 | 52 |
| 54 namespace { | 53 namespace { |
| 55 | 54 |
| 56 // Multiple ResourceTypes may map to the same string, but the converse is not | 55 using ParsedResponseCookies = std::vector<linked_ptr<net::ParsedCookie>>; |
| 57 // possible. | |
| 58 static const char* kResourceTypeStrings[] = { | |
| 59 "main_frame", | |
| 60 "sub_frame", | |
| 61 "stylesheet", | |
| 62 "script", | |
| 63 "image", | |
| 64 "font", | |
| 65 "object", | |
| 66 "script", | |
| 67 "script", | |
| 68 "image", | |
| 69 "xmlhttprequest", | |
| 70 "ping", | |
| 71 "script", | |
| 72 "object", | |
| 73 "other", | |
| 74 }; | |
| 75 | |
| 76 const size_t kResourceTypeStringsLength = arraysize(kResourceTypeStrings); | |
| 77 | |
| 78 static ResourceType kResourceTypeValues[] = { | |
| 79 content::RESOURCE_TYPE_MAIN_FRAME, | |
| 80 content::RESOURCE_TYPE_SUB_FRAME, | |
| 81 content::RESOURCE_TYPE_STYLESHEET, | |
| 82 content::RESOURCE_TYPE_SCRIPT, | |
| 83 content::RESOURCE_TYPE_IMAGE, | |
| 84 content::RESOURCE_TYPE_FONT_RESOURCE, | |
| 85 content::RESOURCE_TYPE_OBJECT, | |
| 86 content::RESOURCE_TYPE_WORKER, | |
| 87 content::RESOURCE_TYPE_SHARED_WORKER, | |
| 88 content::RESOURCE_TYPE_FAVICON, | |
| 89 content::RESOURCE_TYPE_XHR, | |
| 90 content::RESOURCE_TYPE_PING, | |
| 91 content::RESOURCE_TYPE_SERVICE_WORKER, | |
| 92 content::RESOURCE_TYPE_PLUGIN_RESOURCE, | |
| 93 content::RESOURCE_TYPE_LAST_TYPE, // represents "other" | |
| 94 }; | |
| 95 | |
| 96 const size_t kResourceTypeValuesLength = arraysize(kResourceTypeValues); | |
| 97 | |
| 98 static_assert(kResourceTypeStringsLength == kResourceTypeValuesLength, | |
| 99 "Sizes of string lists and ResourceType lists should be equal"); | |
| 100 | |
| 101 typedef std::vector<linked_ptr<net::ParsedCookie> > ParsedResponseCookies; | |
| 102 | 56 |
| 103 void ClearCacheOnNavigationOnUI() { | 57 void ClearCacheOnNavigationOnUI() { |
| 104 web_cache::WebCacheManager::GetInstance()->ClearCacheOnNavigation(); | 58 web_cache::WebCacheManager::GetInstance()->ClearCacheOnNavigation(); |
| 105 } | 59 } |
| 106 | 60 |
| 107 bool ParseCookieLifetime(net::ParsedCookie* cookie, | 61 bool ParseCookieLifetime(net::ParsedCookie* cookie, |
| 108 int64_t* seconds_till_expiry) { | 62 int64_t* seconds_till_expiry) { |
| 109 // 'Max-Age' is processed first because according to: | 63 // 'Max-Age' is processed first because according to: |
| 110 // http://tools.ietf.org/html/rfc6265#section-5.3 'Max-Age' attribute | 64 // http://tools.ietf.org/html/rfc6265#section-5.3 'Max-Age' attribute |
| 111 // overrides 'Expires' attribute. | 65 // overrides 'Expires' attribute. |
| (...skipping 1129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1241 header->SetString(keys::kHeaderNameKey, name); | 1195 header->SetString(keys::kHeaderNameKey, name); |
| 1242 if (base::IsStringUTF8(value)) { | 1196 if (base::IsStringUTF8(value)) { |
| 1243 header->SetString(keys::kHeaderValueKey, value); | 1197 header->SetString(keys::kHeaderValueKey, value); |
| 1244 } else { | 1198 } else { |
| 1245 header->Set(keys::kHeaderBinaryValueKey, | 1199 header->Set(keys::kHeaderBinaryValueKey, |
| 1246 StringToCharList(value)); | 1200 StringToCharList(value)); |
| 1247 } | 1201 } |
| 1248 return header; | 1202 return header; |
| 1249 } | 1203 } |
| 1250 | 1204 |
| 1251 bool IsRelevantResourceType(ResourceType type) { | |
| 1252 ResourceType* iter = | |
| 1253 std::find(kResourceTypeValues, | |
| 1254 kResourceTypeValues + kResourceTypeValuesLength, | |
| 1255 type); | |
| 1256 return iter != (kResourceTypeValues + kResourceTypeValuesLength); | |
| 1257 } | |
| 1258 | |
| 1259 const char* ResourceTypeToString(ResourceType type) { | |
| 1260 ResourceType* iter = | |
| 1261 std::find(kResourceTypeValues, | |
| 1262 kResourceTypeValues + kResourceTypeValuesLength, | |
| 1263 type); | |
| 1264 if (iter == (kResourceTypeValues + kResourceTypeValuesLength)) | |
| 1265 return "other"; | |
| 1266 | |
| 1267 return kResourceTypeStrings[iter - kResourceTypeValues]; | |
| 1268 } | |
| 1269 | |
| 1270 bool ParseResourceType(const std::string& type_str, | |
| 1271 std::vector<ResourceType>* types) { | |
| 1272 bool found = false; | |
| 1273 for (size_t i = 0; i < kResourceTypeStringsLength; ++i) { | |
| 1274 if (type_str == kResourceTypeStrings[i]) { | |
| 1275 found = true; | |
| 1276 types->push_back(kResourceTypeValues[i]); | |
| 1277 } | |
| 1278 } | |
| 1279 return found; | |
| 1280 } | |
| 1281 | |
| 1282 } // namespace extension_web_request_api_helpers | 1205 } // namespace extension_web_request_api_helpers |
| OLD | NEW |