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 14 matching lines...) Expand all Loading... |
25 #include "net/cookies/cookie_util.h" | 25 #include "net/cookies/cookie_util.h" |
26 #include "net/cookies/parsed_cookie.h" | 26 #include "net/cookies/parsed_cookie.h" |
27 #include "net/http/http_util.h" | 27 #include "net/http/http_util.h" |
28 #include "net/url_request/url_request.h" | 28 #include "net/url_request/url_request.h" |
29 #include "url/url_constants.h" | 29 #include "url/url_constants.h" |
30 | 30 |
31 // TODO(battre): move all static functions into an anonymous namespace at the | 31 // TODO(battre): move all static functions into an anonymous namespace at the |
32 // top of this file. | 32 // top of this file. |
33 | 33 |
34 using base::Time; | 34 using base::Time; |
35 using content::ResourceType; | |
36 using net::cookie_util::ParsedRequestCookie; | 35 using net::cookie_util::ParsedRequestCookie; |
37 using net::cookie_util::ParsedRequestCookies; | 36 using net::cookie_util::ParsedRequestCookies; |
38 | 37 |
39 namespace extension_web_request_api_helpers { | 38 namespace extension_web_request_api_helpers { |
40 | 39 |
41 namespace { | 40 namespace { |
42 | 41 |
43 typedef std::vector<linked_ptr<net::ParsedCookie> > ParsedResponseCookies; | 42 typedef std::vector<linked_ptr<net::ParsedCookie> > ParsedResponseCookies; |
44 | 43 |
45 static const char* kResourceTypeStrings[] = { | |
46 "main_frame", | |
47 "sub_frame", | |
48 "stylesheet", | |
49 "script", | |
50 "image", | |
51 "object", | |
52 "xmlhttprequest", | |
53 "other", | |
54 "other", | |
55 }; | |
56 | |
57 static ResourceType kResourceTypeValues[] = { | |
58 content::RESOURCE_TYPE_MAIN_FRAME, | |
59 content::RESOURCE_TYPE_SUB_FRAME, | |
60 content::RESOURCE_TYPE_STYLESHEET, | |
61 content::RESOURCE_TYPE_SCRIPT, | |
62 content::RESOURCE_TYPE_IMAGE, | |
63 content::RESOURCE_TYPE_OBJECT, | |
64 content::RESOURCE_TYPE_XHR, | |
65 content::RESOURCE_TYPE_LAST_TYPE, // represents "other" | |
66 // TODO(jochen): We duplicate the last entry, so the array's size is not a | |
67 // power of two. If it is, this triggers a bug in gcc 4.4 in Release builds | |
68 // (http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43949). Once we use a version | |
69 // of gcc with this bug fixed, or the array is changed so this duplicate | |
70 // entry is no longer required, this should be removed. | |
71 content::RESOURCE_TYPE_LAST_TYPE, | |
72 }; | |
73 | |
74 COMPILE_ASSERT( | |
75 arraysize(kResourceTypeStrings) == arraysize(kResourceTypeValues), | |
76 keep_resource_types_in_sync); | |
77 | |
78 void ClearCacheOnNavigationOnUI() { | 44 void ClearCacheOnNavigationOnUI() { |
79 WebCacheManager::GetInstance()->ClearCacheOnNavigation(); | 45 WebCacheManager::GetInstance()->ClearCacheOnNavigation(); |
80 } | 46 } |
81 | 47 |
82 bool ParseCookieLifetime(net::ParsedCookie* cookie, | 48 bool ParseCookieLifetime(net::ParsedCookie* cookie, |
83 int64* seconds_till_expiry) { | 49 int64* seconds_till_expiry) { |
84 // 'Max-Age' is processed first because according to: | 50 // 'Max-Age' is processed first because according to: |
85 // http://tools.ietf.org/html/rfc6265#section-5.3 'Max-Age' attribute | 51 // http://tools.ietf.org/html/rfc6265#section-5.3 'Max-Age' attribute |
86 // overrides 'Expires' attribute. | 52 // overrides 'Expires' attribute. |
87 if (cookie->HasMaxAge() && | 53 if (cookie->HasMaxAge() && |
(...skipping 1085 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1173 net::NetLog::TYPE_CHROME_EXTENSION_PROVIDE_AUTH_CREDENTIALS, | 1139 net::NetLog::TYPE_CHROME_EXTENSION_PROVIDE_AUTH_CREDENTIALS, |
1174 CreateNetLogExtensionIdCallback(delta->get())); | 1140 CreateNetLogExtensionIdCallback(delta->get())); |
1175 *auth_credentials = *(*delta)->auth_credentials; | 1141 *auth_credentials = *(*delta)->auth_credentials; |
1176 credentials_set = true; | 1142 credentials_set = true; |
1177 winning_extension_id = (*delta)->extension_id; | 1143 winning_extension_id = (*delta)->extension_id; |
1178 } | 1144 } |
1179 } | 1145 } |
1180 return credentials_set; | 1146 return credentials_set; |
1181 } | 1147 } |
1182 | 1148 |
1183 | |
1184 #define ARRAYEND(array) (array + arraysize(array)) | |
1185 | |
1186 bool IsRelevantResourceType(ResourceType type) { | |
1187 ResourceType* iter = | |
1188 std::find(kResourceTypeValues, ARRAYEND(kResourceTypeValues), type); | |
1189 return iter != ARRAYEND(kResourceTypeValues); | |
1190 } | |
1191 | |
1192 const char* ResourceTypeToString(ResourceType type) { | |
1193 ResourceType* iter = | |
1194 std::find(kResourceTypeValues, ARRAYEND(kResourceTypeValues), type); | |
1195 if (iter == ARRAYEND(kResourceTypeValues)) | |
1196 return "other"; | |
1197 | |
1198 return kResourceTypeStrings[iter - kResourceTypeValues]; | |
1199 } | |
1200 | |
1201 bool ParseResourceType(const std::string& type_str, | |
1202 ResourceType* type) { | |
1203 const char** iter = | |
1204 std::find(kResourceTypeStrings, ARRAYEND(kResourceTypeStrings), type_str); | |
1205 if (iter == ARRAYEND(kResourceTypeStrings)) | |
1206 return false; | |
1207 *type = kResourceTypeValues[iter - kResourceTypeStrings]; | |
1208 return true; | |
1209 } | |
1210 | |
1211 void ClearCacheOnNavigation() { | 1149 void ClearCacheOnNavigation() { |
1212 if (content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) { | 1150 if (content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) { |
1213 ClearCacheOnNavigationOnUI(); | 1151 ClearCacheOnNavigationOnUI(); |
1214 } else { | 1152 } else { |
1215 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, | 1153 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, |
1216 base::Bind(&ClearCacheOnNavigationOnUI)); | 1154 base::Bind(&ClearCacheOnNavigationOnUI)); |
1217 } | 1155 } |
1218 } | 1156 } |
1219 | 1157 |
1220 void NotifyWebRequestAPIUsed( | 1158 void NotifyWebRequestAPIUsed( |
(...skipping 14 matching lines...) Expand all Loading... |
1235 for (content::RenderProcessHost::iterator it = | 1173 for (content::RenderProcessHost::iterator it = |
1236 content::RenderProcessHost::AllHostsIterator(); | 1174 content::RenderProcessHost::AllHostsIterator(); |
1237 !it.IsAtEnd(); it.Advance()) { | 1175 !it.IsAtEnd(); it.Advance()) { |
1238 content::RenderProcessHost* host = it.GetCurrentValue(); | 1176 content::RenderProcessHost* host = it.GetCurrentValue(); |
1239 if (host->GetBrowserContext() == browser_context) | 1177 if (host->GetBrowserContext() == browser_context) |
1240 SendExtensionWebRequestStatusToHost(host); | 1178 SendExtensionWebRequestStatusToHost(host); |
1241 } | 1179 } |
1242 } | 1180 } |
1243 | 1181 |
1244 } // namespace extension_web_request_api_helpers | 1182 } // namespace extension_web_request_api_helpers |
OLD | NEW |