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

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

Issue 1865303006: Map webRequest filter type to multiple internal ResourceTypes if needed (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2661
Patch Set: Created 4 years, 8 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
« no previous file with comments | « extensions/browser/api/web_request/web_request_api_helpers.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 using content::ResourceType; 42 using content::ResourceType;
43 using net::cookie_util::ParsedRequestCookie; 43 using net::cookie_util::ParsedRequestCookie;
44 using net::cookie_util::ParsedRequestCookies; 44 using net::cookie_util::ParsedRequestCookies;
45 45
46 namespace keys = extension_web_request_api_constants; 46 namespace keys = extension_web_request_api_constants;
47 47
48 namespace extension_web_request_api_helpers { 48 namespace extension_web_request_api_helpers {
49 49
50 namespace { 50 namespace {
51 51
52 // Multiple ResourceTypes may map to the same string, but the converse is not
53 // possible.
52 static const char* kResourceTypeStrings[] = { 54 static const char* kResourceTypeStrings[] = {
53 "main_frame", 55 "main_frame",
54 "sub_frame", 56 "sub_frame",
55 "stylesheet", 57 "stylesheet",
56 "script", 58 "script",
57 "image", 59 "image",
58 "font", 60 "font",
59 "object", 61 "object",
60 "script", 62 "script",
61 "script", 63 "script",
(...skipping 20 matching lines...) Expand all
82 content::RESOURCE_TYPE_FAVICON, 84 content::RESOURCE_TYPE_FAVICON,
83 content::RESOURCE_TYPE_XHR, 85 content::RESOURCE_TYPE_XHR,
84 content::RESOURCE_TYPE_PING, 86 content::RESOURCE_TYPE_PING,
85 content::RESOURCE_TYPE_SERVICE_WORKER, 87 content::RESOURCE_TYPE_SERVICE_WORKER,
86 content::RESOURCE_TYPE_PLUGIN_RESOURCE, 88 content::RESOURCE_TYPE_PLUGIN_RESOURCE,
87 content::RESOURCE_TYPE_LAST_TYPE, // represents "other" 89 content::RESOURCE_TYPE_LAST_TYPE, // represents "other"
88 }; 90 };
89 91
90 const size_t kResourceTypeValuesLength = arraysize(kResourceTypeValues); 92 const size_t kResourceTypeValuesLength = arraysize(kResourceTypeValues);
91 93
94 static_assert(kResourceTypeStringsLength == kResourceTypeValuesLength,
95 "Sizes of string lists and ResourceType lists should be equal");
96
92 typedef std::vector<linked_ptr<net::ParsedCookie> > ParsedResponseCookies; 97 typedef std::vector<linked_ptr<net::ParsedCookie> > ParsedResponseCookies;
93 98
94 void ClearCacheOnNavigationOnUI() { 99 void ClearCacheOnNavigationOnUI() {
95 web_cache::WebCacheManager::GetInstance()->ClearCacheOnNavigation(); 100 web_cache::WebCacheManager::GetInstance()->ClearCacheOnNavigation();
96 } 101 }
97 102
98 bool ParseCookieLifetime(net::ParsedCookie* cookie, 103 bool ParseCookieLifetime(net::ParsedCookie* cookie,
99 int64_t* seconds_till_expiry) { 104 int64_t* seconds_till_expiry) {
100 // 'Max-Age' is processed first because according to: 105 // 'Max-Age' is processed first because according to:
101 // http://tools.ietf.org/html/rfc6265#section-5.3 'Max-Age' attribute 106 // http://tools.ietf.org/html/rfc6265#section-5.3 'Max-Age' attribute
(...skipping 1199 matching lines...) Expand 10 before | Expand all | Expand 10 after
1301 std::find(kResourceTypeValues, 1306 std::find(kResourceTypeValues,
1302 kResourceTypeValues + kResourceTypeValuesLength, 1307 kResourceTypeValues + kResourceTypeValuesLength,
1303 type); 1308 type);
1304 if (iter == (kResourceTypeValues + kResourceTypeValuesLength)) 1309 if (iter == (kResourceTypeValues + kResourceTypeValuesLength))
1305 return "other"; 1310 return "other";
1306 1311
1307 return kResourceTypeStrings[iter - kResourceTypeValues]; 1312 return kResourceTypeStrings[iter - kResourceTypeValues];
1308 } 1313 }
1309 1314
1310 bool ParseResourceType(const std::string& type_str, 1315 bool ParseResourceType(const std::string& type_str,
1311 ResourceType* type) { 1316 std::vector<ResourceType>* types) {
1312 const char** iter = 1317 bool found = false;
1313 std::find(kResourceTypeStrings, 1318 for (size_t i = 0; i < kResourceTypeStringsLength; ++i) {
1314 kResourceTypeStrings + kResourceTypeStringsLength, 1319 if (type_str == kResourceTypeStrings[i]) {
1315 type_str); 1320 found = true;
1316 if (iter == (kResourceTypeStrings + kResourceTypeStringsLength)) 1321 types->push_back(kResourceTypeValues[i]);
1317 return false; 1322 }
1318 *type = kResourceTypeValues[iter - kResourceTypeStrings]; 1323 }
1319 return true; 1324 return found;
1320 } 1325 }
1321 1326
1322 } // namespace extension_web_request_api_helpers 1327 } // namespace extension_web_request_api_helpers
OLDNEW
« no previous file with comments | « extensions/browser/api/web_request/web_request_api_helpers.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698