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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 "sub_frame", | 48 "sub_frame", |
49 "stylesheet", | 49 "stylesheet", |
50 "script", | 50 "script", |
51 "image", | 51 "image", |
52 "object", | 52 "object", |
53 "xmlhttprequest", | 53 "xmlhttprequest", |
54 "other", | 54 "other", |
55 "other", | 55 "other", |
56 }; | 56 }; |
57 | 57 |
58 static ResourceType::Type kResourceTypeValues[] = { | 58 static ResourceType kResourceTypeValues[] = { |
59 ResourceType::MAIN_FRAME, | 59 content::RESOURCE_TYPE_MAIN_FRAME, |
60 ResourceType::SUB_FRAME, | 60 content::RESOURCE_TYPE_SUB_FRAME, |
61 ResourceType::STYLESHEET, | 61 content::RESOURCE_TYPE_STYLESHEET, |
62 ResourceType::SCRIPT, | 62 content::RESOURCE_TYPE_SCRIPT, |
63 ResourceType::IMAGE, | 63 content::RESOURCE_TYPE_IMAGE, |
64 ResourceType::OBJECT, | 64 content::RESOURCE_TYPE_OBJECT, |
65 ResourceType::XHR, | 65 content::RESOURCE_TYPE_XHR, |
66 ResourceType::LAST_TYPE, // represents "other" | 66 content::RESOURCE_TYPE_LAST_TYPE, // represents "other" |
67 // TODO(jochen): We duplicate the last entry, so the array's size is not a | 67 // TODO(jochen): We duplicate the last entry, so the array's size is not a |
68 // power of two. If it is, this triggers a bug in gcc 4.4 in Release builds | 68 // power of two. If it is, this triggers a bug in gcc 4.4 in Release builds |
69 // (http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43949). Once we use a version | 69 // (http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43949). Once we use a version |
70 // of gcc with this bug fixed, or the array is changed so this duplicate | 70 // of gcc with this bug fixed, or the array is changed so this duplicate |
71 // entry is no longer required, this should be removed. | 71 // entry is no longer required, this should be removed. |
72 ResourceType::LAST_TYPE, | 72 content::RESOURCE_TYPE_LAST_TYPE, |
73 }; | 73 }; |
74 | 74 |
75 COMPILE_ASSERT( | 75 COMPILE_ASSERT( |
76 arraysize(kResourceTypeStrings) == arraysize(kResourceTypeValues), | 76 arraysize(kResourceTypeStrings) == arraysize(kResourceTypeValues), |
77 keep_resource_types_in_sync); | 77 keep_resource_types_in_sync); |
78 | 78 |
79 void ClearCacheOnNavigationOnUI() { | 79 void ClearCacheOnNavigationOnUI() { |
80 WebCacheManager::GetInstance()->ClearCacheOnNavigation(); | 80 WebCacheManager::GetInstance()->ClearCacheOnNavigation(); |
81 } | 81 } |
82 | 82 |
(...skipping 1094 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1177 credentials_set = true; | 1177 credentials_set = true; |
1178 winning_extension_id = (*delta)->extension_id; | 1178 winning_extension_id = (*delta)->extension_id; |
1179 } | 1179 } |
1180 } | 1180 } |
1181 return credentials_set; | 1181 return credentials_set; |
1182 } | 1182 } |
1183 | 1183 |
1184 | 1184 |
1185 #define ARRAYEND(array) (array + arraysize(array)) | 1185 #define ARRAYEND(array) (array + arraysize(array)) |
1186 | 1186 |
1187 bool IsRelevantResourceType(ResourceType::Type type) { | 1187 bool IsRelevantResourceType(ResourceType type) { |
1188 ResourceType::Type* iter = | 1188 ResourceType* iter = |
1189 std::find(kResourceTypeValues, ARRAYEND(kResourceTypeValues), type); | 1189 std::find(kResourceTypeValues, ARRAYEND(kResourceTypeValues), type); |
1190 return iter != ARRAYEND(kResourceTypeValues); | 1190 return iter != ARRAYEND(kResourceTypeValues); |
1191 } | 1191 } |
1192 | 1192 |
1193 const char* ResourceTypeToString(ResourceType::Type type) { | 1193 const char* ResourceTypeToString(ResourceType type) { |
1194 ResourceType::Type* iter = | 1194 ResourceType* iter = |
1195 std::find(kResourceTypeValues, ARRAYEND(kResourceTypeValues), type); | 1195 std::find(kResourceTypeValues, ARRAYEND(kResourceTypeValues), type); |
1196 if (iter == ARRAYEND(kResourceTypeValues)) | 1196 if (iter == ARRAYEND(kResourceTypeValues)) |
1197 return "other"; | 1197 return "other"; |
1198 | 1198 |
1199 return kResourceTypeStrings[iter - kResourceTypeValues]; | 1199 return kResourceTypeStrings[iter - kResourceTypeValues]; |
1200 } | 1200 } |
1201 | 1201 |
1202 bool ParseResourceType(const std::string& type_str, | 1202 bool ParseResourceType(const std::string& type_str, |
1203 ResourceType::Type* type) { | 1203 ResourceType* type) { |
1204 const char** iter = | 1204 const char** iter = |
1205 std::find(kResourceTypeStrings, ARRAYEND(kResourceTypeStrings), type_str); | 1205 std::find(kResourceTypeStrings, ARRAYEND(kResourceTypeStrings), type_str); |
1206 if (iter == ARRAYEND(kResourceTypeStrings)) | 1206 if (iter == ARRAYEND(kResourceTypeStrings)) |
1207 return false; | 1207 return false; |
1208 *type = kResourceTypeValues[iter - kResourceTypeStrings]; | 1208 *type = kResourceTypeValues[iter - kResourceTypeStrings]; |
1209 return true; | 1209 return true; |
1210 } | 1210 } |
1211 | 1211 |
1212 void ClearCacheOnNavigation() { | 1212 void ClearCacheOnNavigation() { |
1213 if (content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) { | 1213 if (content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1247 return net::HttpUtil::IsToken(name); | 1247 return net::HttpUtil::IsToken(name); |
1248 } | 1248 } |
1249 | 1249 |
1250 bool IsValidHeaderValue(const std::string& value) { | 1250 bool IsValidHeaderValue(const std::string& value) { |
1251 // Just a sanity check: disallow NUL and CRLF. | 1251 // Just a sanity check: disallow NUL and CRLF. |
1252 return value.find('\0') == std::string::npos && | 1252 return value.find('\0') == std::string::npos && |
1253 value.find("\r\n") == std::string::npos; | 1253 value.find("\r\n") == std::string::npos; |
1254 } | 1254 } |
1255 | 1255 |
1256 } // namespace extension_web_request_api_helpers | 1256 } // namespace extension_web_request_api_helpers |
OLD | NEW |