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

Unified Diff: extensions/browser/api/web_request/web_request_api_helpers.cc

Issue 1853283002: Map webRequest filter type to multiple internal ResourceTypes if needed (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: extensions/browser/api/web_request/web_request_api_helpers.cc
diff --git a/extensions/browser/api/web_request/web_request_api_helpers.cc b/extensions/browser/api/web_request/web_request_api_helpers.cc
index 158a8d9d440f72d4aa082d518ca378af69121271..6bdb87c7befa6114fc23e98f7955235822997afd 100644
--- a/extensions/browser/api/web_request/web_request_api_helpers.cc
+++ b/extensions/browser/api/web_request/web_request_api_helpers.cc
@@ -49,6 +49,8 @@ namespace extension_web_request_api_helpers {
namespace {
+// Multiple ResourceTypes may map to the same string, but the converse is not
+// possible.
static const char* kResourceTypeStrings[] = {
"main_frame",
"sub_frame",
@@ -89,6 +91,9 @@ static ResourceType kResourceTypeValues[] = {
const size_t kResourceTypeValuesLength = arraysize(kResourceTypeValues);
+static_assert(kResourceTypeStringsLength == kResourceTypeValuesLength,
+ "Sizes of string lists and ResourceType lists should be equal");
+
typedef std::vector<linked_ptr<net::ParsedCookie> > ParsedResponseCookies;
void ClearCacheOnNavigationOnUI() {
@@ -1308,15 +1313,15 @@ const char* ResourceTypeToString(ResourceType type) {
}
bool ParseResourceType(const std::string& type_str,
- ResourceType* type) {
- const char** iter =
- std::find(kResourceTypeStrings,
- kResourceTypeStrings + kResourceTypeStringsLength,
- type_str);
- if (iter == (kResourceTypeStrings + kResourceTypeStringsLength))
- return false;
- *type = kResourceTypeValues[iter - kResourceTypeStrings];
- return true;
+ std::vector<ResourceType>* types) {
+ bool found = false;
+ for (size_t i = 0; i < kResourceTypeStringsLength; ++i) {
+ if (type_str == kResourceTypeStrings[i]) {
+ found = true;
+ types->push_back(kResourceTypeValues[i]);
+ }
+ }
+ return found;
}
} // namespace extension_web_request_api_helpers
« 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