Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(467)

Side by Side Diff: extensions/browser/api/web_request/web_request_api_helpers.cc

Issue 601843002: Merge web_request_api_utils back into web_request_api_helpers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <algorithm>
7 #include <cmath> 8 #include <cmath>
8 9
9 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/macros.h"
10 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
11 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
12 #include "base/strings/stringprintf.h" 14 #include "base/strings/stringprintf.h"
13 #include "base/time/time.h" 15 #include "base/time/time.h"
14 #include "base/values.h" 16 #include "base/values.h"
15 #include "components/web_cache/browser/web_cache_manager.h" 17 #include "components/web_cache/browser/web_cache_manager.h"
16 #include "content/public/browser/browser_thread.h" 18 #include "content/public/browser/browser_thread.h"
17 #include "content/public/browser/render_process_host.h" 19 #include "content/public/browser/render_process_host.h"
18 #include "extensions/browser/api/web_request/web_request_api_constants.h" 20 #include "extensions/browser/api/web_request/web_request_api_constants.h"
19 #include "extensions/browser/extension_registry.h" 21 #include "extensions/browser/extension_registry.h"
20 #include "extensions/browser/extension_system.h" 22 #include "extensions/browser/extension_system.h"
21 #include "extensions/browser/extensions_browser_client.h" 23 #include "extensions/browser/extensions_browser_client.h"
22 #include "extensions/browser/runtime_data.h" 24 #include "extensions/browser/runtime_data.h"
23 #include "extensions/browser/warning_set.h" 25 #include "extensions/browser/warning_set.h"
24 #include "extensions/common/extension_messages.h" 26 #include "extensions/common/extension_messages.h"
25 #include "net/base/net_log.h" 27 #include "net/base/net_log.h"
26 #include "net/cookies/cookie_util.h" 28 #include "net/cookies/cookie_util.h"
27 #include "net/cookies/parsed_cookie.h" 29 #include "net/cookies/parsed_cookie.h"
28 #include "net/http/http_util.h" 30 #include "net/http/http_util.h"
29 #include "net/url_request/url_request.h" 31 #include "net/url_request/url_request.h"
30 #include "url/url_constants.h" 32 #include "url/url_constants.h"
31 33
32 // TODO(battre): move all static functions into an anonymous namespace at the 34 // TODO(battre): move all static functions into an anonymous namespace at the
33 // top of this file. 35 // top of this file.
34 36
35 using base::Time; 37 using base::Time;
38 using content::ResourceType;
36 using net::cookie_util::ParsedRequestCookie; 39 using net::cookie_util::ParsedRequestCookie;
37 using net::cookie_util::ParsedRequestCookies; 40 using net::cookie_util::ParsedRequestCookies;
38 41
39 namespace keys = extension_web_request_api_constants; 42 namespace keys = extension_web_request_api_constants;
40 43
41 namespace extension_web_request_api_helpers { 44 namespace extension_web_request_api_helpers {
42 45
43 namespace { 46 namespace {
44 47
48 static const char* kResourceTypeStrings[] = {
49 "main_frame",
50 "sub_frame",
51 "stylesheet",
52 "script",
53 "image",
54 "object",
55 "xmlhttprequest",
56 "other",
57 "other",
58 };
59
60 const size_t kResourceTypeStringsLength = arraysize(kResourceTypeStrings);
61
62 static ResourceType kResourceTypeValues[] = {
63 content::RESOURCE_TYPE_MAIN_FRAME,
64 content::RESOURCE_TYPE_SUB_FRAME,
65 content::RESOURCE_TYPE_STYLESHEET,
66 content::RESOURCE_TYPE_SCRIPT,
67 content::RESOURCE_TYPE_IMAGE,
68 content::RESOURCE_TYPE_OBJECT,
69 content::RESOURCE_TYPE_XHR,
70 content::RESOURCE_TYPE_LAST_TYPE, // represents "other"
71 // TODO(jochen): We duplicate the last entry, so the array's size is not a
72 // power of two. If it is, this triggers a bug in gcc 4.4 in Release builds
73 // (http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43949). Once we use a version
74 // of gcc with this bug fixed, or the array is changed so this duplicate
75 // entry is no longer required, this should be removed.
76 content::RESOURCE_TYPE_LAST_TYPE,
77 };
78
79 const size_t kResourceTypeValuesLength = arraysize(kResourceTypeValues);
80
45 typedef std::vector<linked_ptr<net::ParsedCookie> > ParsedResponseCookies; 81 typedef std::vector<linked_ptr<net::ParsedCookie> > ParsedResponseCookies;
46 82
47 void ClearCacheOnNavigationOnUI() { 83 void ClearCacheOnNavigationOnUI() {
48 web_cache::WebCacheManager::GetInstance()->ClearCacheOnNavigation(); 84 web_cache::WebCacheManager::GetInstance()->ClearCacheOnNavigation();
49 } 85 }
50 86
51 bool ParseCookieLifetime(net::ParsedCookie* cookie, 87 bool ParseCookieLifetime(net::ParsedCookie* cookie,
52 int64* seconds_till_expiry) { 88 int64* seconds_till_expiry) {
53 // 'Max-Age' is processed first because according to: 89 // 'Max-Age' is processed first because according to:
54 // http://tools.ietf.org/html/rfc6265#section-5.3 'Max-Age' attribute 90 // http://tools.ietf.org/html/rfc6265#section-5.3 'Max-Age' attribute
(...skipping 1155 matching lines...) Expand 10 before | Expand all | Expand 10 after
1210 header->SetString(keys::kHeaderNameKey, name); 1246 header->SetString(keys::kHeaderNameKey, name);
1211 if (base::IsStringUTF8(value)) { 1247 if (base::IsStringUTF8(value)) {
1212 header->SetString(keys::kHeaderValueKey, value); 1248 header->SetString(keys::kHeaderValueKey, value);
1213 } else { 1249 } else {
1214 header->Set(keys::kHeaderBinaryValueKey, 1250 header->Set(keys::kHeaderBinaryValueKey,
1215 StringToCharList(value)); 1251 StringToCharList(value));
1216 } 1252 }
1217 return header; 1253 return header;
1218 } 1254 }
1219 1255
1256 #define ARRAYEND(array) (array + arraysize(array))
1257
1258 bool IsRelevantResourceType(ResourceType type) {
1259 ResourceType* iter =
1260 std::find(kResourceTypeValues,
1261 kResourceTypeValues + kResourceTypeValuesLength,
1262 type);
1263 return iter != (kResourceTypeValues + kResourceTypeValuesLength);
1264 }
1265
1266 const char* ResourceTypeToString(ResourceType type) {
1267 ResourceType* iter =
1268 std::find(kResourceTypeValues,
1269 kResourceTypeValues + kResourceTypeValuesLength,
1270 type);
1271 if (iter == (kResourceTypeValues + kResourceTypeValuesLength))
1272 return "other";
1273
1274 return kResourceTypeStrings[iter - kResourceTypeValues];
1275 }
1276
1277 bool ParseResourceType(const std::string& type_str,
1278 ResourceType* type) {
1279 const char** iter =
1280 std::find(kResourceTypeStrings,
1281 kResourceTypeStrings + kResourceTypeStringsLength,
1282 type_str);
1283 if (iter == (kResourceTypeStrings + kResourceTypeStringsLength))
1284 return false;
1285 *type = kResourceTypeValues[iter - kResourceTypeStrings];
1286 return true;
1287 }
1288
1220 } // namespace extension_web_request_api_helpers 1289 } // namespace extension_web_request_api_helpers
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698