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; | 46 using extensions::WebRequestResourceType; |
47 using net::cookie_util::ParsedRequestCookie; | 47 using net::cookie_util::ParsedRequestCookie; |
48 using net::cookie_util::ParsedRequestCookies; | 48 using net::cookie_util::ParsedRequestCookies; |
49 | 49 |
50 namespace keys = extension_web_request_api_constants; | 50 namespace keys = extension_web_request_api_constants; |
51 | 51 |
52 namespace extension_web_request_api_helpers { | 52 namespace extension_web_request_api_helpers { |
53 | 53 |
54 namespace { | 54 namespace { |
55 | 55 |
56 // Multiple ResourceTypes may map to the same string, but the converse is not | 56 // Multiple ResourceTypes may map to the same string, but the converse is not |
57 // possible. | 57 // possible. |
58 static const char* kResourceTypeStrings[] = { | 58 static const char* kResourceTypeStrings[] = { |
59 "main_frame", | 59 "main_frame", |
60 "sub_frame", | 60 "sub_frame", |
61 "stylesheet", | 61 "stylesheet", |
62 "script", | 62 "script", |
63 "image", | 63 "image", |
64 "font", | 64 "font", |
65 "object", | 65 "object", |
66 "script", | 66 "script", |
67 "script", | 67 "script", |
68 "image", | 68 "image", |
69 "xmlhttprequest", | 69 "xmlhttprequest", |
70 "ping", | 70 "ping", |
71 "script", | 71 "script", |
72 "object", | 72 "object", |
73 "other", | 73 "websocket", |
74 "other", | |
74 }; | 75 }; |
75 | 76 |
76 const size_t kResourceTypeStringsLength = arraysize(kResourceTypeStrings); | 77 const size_t kResourceTypeStringsLength = arraysize(kResourceTypeStrings); |
77 | 78 |
78 static ResourceType kResourceTypeValues[] = { | 79 static WebRequestResourceType kResourceTypeValues[] = { |
79 content::RESOURCE_TYPE_MAIN_FRAME, | 80 WebRequestResourceType::MAIN_FRAME, |
80 content::RESOURCE_TYPE_SUB_FRAME, | 81 WebRequestResourceType::SUB_FRAME, |
81 content::RESOURCE_TYPE_STYLESHEET, | 82 WebRequestResourceType::STYLESHEET, |
82 content::RESOURCE_TYPE_SCRIPT, | 83 WebRequestResourceType::SCRIPT, |
83 content::RESOURCE_TYPE_IMAGE, | 84 WebRequestResourceType::IMAGE, |
84 content::RESOURCE_TYPE_FONT_RESOURCE, | 85 WebRequestResourceType::FONT_RESOURCE, |
85 content::RESOURCE_TYPE_OBJECT, | 86 WebRequestResourceType::OBJECT, |
86 content::RESOURCE_TYPE_WORKER, | 87 WebRequestResourceType::WORKER, |
87 content::RESOURCE_TYPE_SHARED_WORKER, | 88 WebRequestResourceType::SHARED_WORKER, |
88 content::RESOURCE_TYPE_FAVICON, | 89 WebRequestResourceType::FAVICON, |
89 content::RESOURCE_TYPE_XHR, | 90 WebRequestResourceType::XHR, |
90 content::RESOURCE_TYPE_PING, | 91 WebRequestResourceType::PING, |
91 content::RESOURCE_TYPE_SERVICE_WORKER, | 92 WebRequestResourceType::SERVICE_WORKER, |
92 content::RESOURCE_TYPE_PLUGIN_RESOURCE, | 93 WebRequestResourceType::PLUGIN_RESOURCE, |
93 content::RESOURCE_TYPE_LAST_TYPE, // represents "other" | 94 WebRequestResourceType::WEBSOCKET, |
95 WebRequestResourceType::LAST_TYPE, // Represents "other". | |
Devlin
2017/02/16 15:13:05
if these aren't included in UMA anywhere, it could
pkalinnikov
2017/02/16 15:52:45
Done.
tyoshino (SeeGerritForStatus)
2017/02/16 16:26:34
sounds good
| |
94 }; | 96 }; |
95 | 97 |
96 const size_t kResourceTypeValuesLength = arraysize(kResourceTypeValues); | 98 const size_t kResourceTypeValuesLength = arraysize(kResourceTypeValues); |
97 | 99 |
98 static_assert(kResourceTypeStringsLength == kResourceTypeValuesLength, | 100 static_assert(kResourceTypeStringsLength == kResourceTypeValuesLength, |
99 "Sizes of string lists and ResourceType lists should be equal"); | 101 "Sizes of string lists and ResourceType lists should be equal."); |
100 | 102 |
101 typedef std::vector<linked_ptr<net::ParsedCookie> > ParsedResponseCookies; | 103 using ParsedResponseCookies = std::vector<linked_ptr<net::ParsedCookie>>; |
102 | 104 |
103 void ClearCacheOnNavigationOnUI() { | 105 void ClearCacheOnNavigationOnUI() { |
104 web_cache::WebCacheManager::GetInstance()->ClearCacheOnNavigation(); | 106 web_cache::WebCacheManager::GetInstance()->ClearCacheOnNavigation(); |
105 } | 107 } |
106 | 108 |
107 bool ParseCookieLifetime(net::ParsedCookie* cookie, | 109 bool ParseCookieLifetime(net::ParsedCookie* cookie, |
108 int64_t* seconds_till_expiry) { | 110 int64_t* seconds_till_expiry) { |
109 // 'Max-Age' is processed first because according to: | 111 // 'Max-Age' is processed first because according to: |
110 // http://tools.ietf.org/html/rfc6265#section-5.3 'Max-Age' attribute | 112 // http://tools.ietf.org/html/rfc6265#section-5.3 'Max-Age' attribute |
111 // overrides 'Expires' attribute. | 113 // overrides 'Expires' attribute. |
(...skipping 1129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1241 header->SetString(keys::kHeaderNameKey, name); | 1243 header->SetString(keys::kHeaderNameKey, name); |
1242 if (base::IsStringUTF8(value)) { | 1244 if (base::IsStringUTF8(value)) { |
1243 header->SetString(keys::kHeaderValueKey, value); | 1245 header->SetString(keys::kHeaderValueKey, value); |
1244 } else { | 1246 } else { |
1245 header->Set(keys::kHeaderBinaryValueKey, | 1247 header->Set(keys::kHeaderBinaryValueKey, |
1246 StringToCharList(value)); | 1248 StringToCharList(value)); |
1247 } | 1249 } |
1248 return header; | 1250 return header; |
1249 } | 1251 } |
1250 | 1252 |
1251 bool IsRelevantResourceType(ResourceType type) { | 1253 bool IsRelevantResourceType(content::ResourceType type) { |
1252 ResourceType* iter = | 1254 auto* end = kResourceTypeValues + kResourceTypeValuesLength; |
1253 std::find(kResourceTypeValues, | 1255 return std::find(kResourceTypeValues, end, |
1254 kResourceTypeValues + kResourceTypeValuesLength, | 1256 extensions::ToWebRequestResourceType(type)) != end; |
1255 type); | |
1256 return iter != (kResourceTypeValues + kResourceTypeValuesLength); | |
1257 } | 1257 } |
1258 | 1258 |
1259 const char* ResourceTypeToString(ResourceType type) { | 1259 const char* ResourceTypeToString(WebRequestResourceType type) { |
1260 ResourceType* iter = | 1260 DCHECK_NE(WebRequestResourceType::WEBSOCKET, type); |
1261 std::find(kResourceTypeValues, | 1261 auto* end = kResourceTypeValues + kResourceTypeValuesLength; |
1262 kResourceTypeValues + kResourceTypeValuesLength, | 1262 auto* iter = std::find(kResourceTypeValues, end, type); |
1263 type); | 1263 return iter != end ? kResourceTypeStrings[iter - kResourceTypeValues] |
1264 if (iter == (kResourceTypeValues + kResourceTypeValuesLength)) | 1264 : "other"; |
tyoshino (SeeGerritForStatus)
2017/02/16 16:13:58
Not a change proposal. Let me explain my understan
pkalinnikov
2017/02/16 19:27:30
Please see the new change. Looks like it addressed
| |
1265 return "other"; | |
1266 | |
1267 return kResourceTypeStrings[iter - kResourceTypeValues]; | |
1268 } | 1265 } |
1269 | 1266 |
1270 bool ParseResourceType(const std::string& type_str, | 1267 bool ParseResourceType(const std::string& type_str, |
1271 std::vector<ResourceType>* types) { | 1268 std::vector<WebRequestResourceType>* types) { |
1272 bool found = false; | 1269 bool found = false; |
1273 for (size_t i = 0; i < kResourceTypeStringsLength; ++i) { | 1270 for (size_t i = 0; i < kResourceTypeStringsLength; ++i) { |
1274 if (type_str == kResourceTypeStrings[i]) { | 1271 if (type_str == kResourceTypeStrings[i]) { |
1272 DCHECK_NE(WebRequestResourceType::WEBSOCKET, kResourceTypeValues[i]); | |
1273 types->push_back(kResourceTypeValues[i]); | |
1275 found = true; | 1274 found = true; |
1276 types->push_back(kResourceTypeValues[i]); | |
1277 } | 1275 } |
1278 } | 1276 } |
1279 return found; | 1277 return found; |
1280 } | 1278 } |
1281 | 1279 |
1282 } // namespace extension_web_request_api_helpers | 1280 } // namespace extension_web_request_api_helpers |
OLD | NEW |