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

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

Issue 1515703005: WebRequest API: add more resource types (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Replace == with && 2x Created 4 years, 12 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 <algorithm>
8 #include <cmath> 8 #include <cmath>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 namespace extension_web_request_api_helpers { 44 namespace extension_web_request_api_helpers {
45 45
46 namespace { 46 namespace {
47 47
48 static const char* kResourceTypeStrings[] = { 48 static const char* kResourceTypeStrings[] = {
49 "main_frame", 49 "main_frame",
50 "sub_frame", 50 "sub_frame",
51 "stylesheet", 51 "stylesheet",
52 "script", 52 "script",
53 "image", 53 "image",
54 "font",
54 "object", 55 "object",
56 "script",
57 "script",
58 "image",
55 "xmlhttprequest", 59 "xmlhttprequest",
56 "other", 60 "ping",
61 "script",
62 "object",
57 "other", 63 "other",
58 }; 64 };
59 65
60 const size_t kResourceTypeStringsLength = arraysize(kResourceTypeStrings); 66 const size_t kResourceTypeStringsLength = arraysize(kResourceTypeStrings);
61 67
62 static ResourceType kResourceTypeValues[] = { 68 static ResourceType kResourceTypeValues[] = {
63 content::RESOURCE_TYPE_MAIN_FRAME, 69 content::RESOURCE_TYPE_MAIN_FRAME,
64 content::RESOURCE_TYPE_SUB_FRAME, 70 content::RESOURCE_TYPE_SUB_FRAME,
65 content::RESOURCE_TYPE_STYLESHEET, 71 content::RESOURCE_TYPE_STYLESHEET,
66 content::RESOURCE_TYPE_SCRIPT, 72 content::RESOURCE_TYPE_SCRIPT,
67 content::RESOURCE_TYPE_IMAGE, 73 content::RESOURCE_TYPE_IMAGE,
74 content::RESOURCE_TYPE_FONT_RESOURCE,
68 content::RESOURCE_TYPE_OBJECT, 75 content::RESOURCE_TYPE_OBJECT,
76 content::RESOURCE_TYPE_WORKER,
77 content::RESOURCE_TYPE_SHARED_WORKER,
78 content::RESOURCE_TYPE_FAVICON,
69 content::RESOURCE_TYPE_XHR, 79 content::RESOURCE_TYPE_XHR,
80 content::RESOURCE_TYPE_PING,
81 content::RESOURCE_TYPE_SERVICE_WORKER,
82 content::RESOURCE_TYPE_PLUGIN_RESOURCE,
70 content::RESOURCE_TYPE_LAST_TYPE, // represents "other" 83 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 }; 84 };
78 85
79 const size_t kResourceTypeValuesLength = arraysize(kResourceTypeValues); 86 const size_t kResourceTypeValuesLength = arraysize(kResourceTypeValues);
80 87
81 typedef std::vector<linked_ptr<net::ParsedCookie> > ParsedResponseCookies; 88 typedef std::vector<linked_ptr<net::ParsedCookie> > ParsedResponseCookies;
82 89
83 void ClearCacheOnNavigationOnUI() { 90 void ClearCacheOnNavigationOnUI() {
84 web_cache::WebCacheManager::GetInstance()->ClearCacheOnNavigation(); 91 web_cache::WebCacheManager::GetInstance()->ClearCacheOnNavigation();
85 } 92 }
86 93
(...skipping 1155 matching lines...) Expand 10 before | Expand all | Expand 10 after
1242 header->SetString(keys::kHeaderNameKey, name); 1249 header->SetString(keys::kHeaderNameKey, name);
1243 if (base::IsStringUTF8(value)) { 1250 if (base::IsStringUTF8(value)) {
1244 header->SetString(keys::kHeaderValueKey, value); 1251 header->SetString(keys::kHeaderValueKey, value);
1245 } else { 1252 } else {
1246 header->Set(keys::kHeaderBinaryValueKey, 1253 header->Set(keys::kHeaderBinaryValueKey,
1247 StringToCharList(value)); 1254 StringToCharList(value));
1248 } 1255 }
1249 return header; 1256 return header;
1250 } 1257 }
1251 1258
1252 #define ARRAYEND(array) (array + arraysize(array))
1253
1254 bool IsRelevantResourceType(ResourceType type) { 1259 bool IsRelevantResourceType(ResourceType type) {
1255 ResourceType* iter = 1260 ResourceType* iter =
1256 std::find(kResourceTypeValues, 1261 std::find(kResourceTypeValues,
1257 kResourceTypeValues + kResourceTypeValuesLength, 1262 kResourceTypeValues + kResourceTypeValuesLength,
1258 type); 1263 type);
1259 return iter != (kResourceTypeValues + kResourceTypeValuesLength); 1264 return iter != (kResourceTypeValues + kResourceTypeValuesLength);
1260 } 1265 }
1261 1266
1262 const char* ResourceTypeToString(ResourceType type) { 1267 const char* ResourceTypeToString(ResourceType type) {
1263 ResourceType* iter = 1268 ResourceType* iter =
(...skipping 12 matching lines...) Expand all
1276 std::find(kResourceTypeStrings, 1281 std::find(kResourceTypeStrings,
1277 kResourceTypeStrings + kResourceTypeStringsLength, 1282 kResourceTypeStrings + kResourceTypeStringsLength,
1278 type_str); 1283 type_str);
1279 if (iter == (kResourceTypeStrings + kResourceTypeStringsLength)) 1284 if (iter == (kResourceTypeStrings + kResourceTypeStringsLength))
1280 return false; 1285 return false;
1281 *type = kResourceTypeValues[iter - kResourceTypeStrings]; 1286 *type = kResourceTypeValues[iter - kResourceTypeStrings];
1282 return true; 1287 return true;
1283 } 1288 }
1284 1289
1285 } // namespace extension_web_request_api_helpers 1290 } // namespace extension_web_request_api_helpers
OLDNEW
« no previous file with comments | « content/public/common/resource_type.h ('k') | extensions/common/api/declarative_web_request.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698