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

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

Issue 562913002: Move web_request_condition* files to extensions/browser/api/declarative_webrequest/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase to master@294403 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « extensions/browser/api/web_request/web_request_api_utils.h ('k') | extensions/extensions.gyp » ('j') | 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_utils.cc
diff --git a/extensions/browser/api/web_request/web_request_api_utils.cc b/extensions/browser/api/web_request/web_request_api_utils.cc
new file mode 100644
index 0000000000000000000000000000000000000000..a19bcd0e770c82ba844d2ddcfae6067df8bdccb4
--- /dev/null
+++ b/extensions/browser/api/web_request/web_request_api_utils.cc
@@ -0,0 +1,73 @@
+// Copyright (c) 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "extensions/browser/api/web_request/web_request_api_utils.h"
+
+#include <algorithm>
+
+#include "base/macros.h"
+
+namespace extension_web_request_api_utils {
+
+namespace {
+
+static const char* kResourceTypeStrings[] = {
+ "main_frame",
+ "sub_frame",
+ "stylesheet",
+ "script",
+ "image",
+ "object",
+ "xmlhttprequest",
+ "other",
+ "other",
+};
+
+static ResourceType kResourceTypeValues[] = {
+ content::RESOURCE_TYPE_MAIN_FRAME,
+ content::RESOURCE_TYPE_SUB_FRAME,
+ content::RESOURCE_TYPE_STYLESHEET,
+ content::RESOURCE_TYPE_SCRIPT,
+ content::RESOURCE_TYPE_IMAGE,
+ content::RESOURCE_TYPE_OBJECT,
+ content::RESOURCE_TYPE_XHR,
+ content::RESOURCE_TYPE_LAST_TYPE, // represents "other"
+ // TODO(jochen): We duplicate the last entry, so the array's size is not a
+ // power of two. If it is, this triggers a bug in gcc 4.4 in Release builds
+ // (http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43949). Once we use a version
+ // of gcc with this bug fixed, or the array is changed so this duplicate
+ // entry is no longer required, this should be removed.
+ content::RESOURCE_TYPE_LAST_TYPE,
+};
+
+}
+
+#define ARRAYEND(array) (array + arraysize(array))
+
+bool IsRelevantResourceType(ResourceType type) {
+ ResourceType* iter =
+ std::find(kResourceTypeValues, ARRAYEND(kResourceTypeValues), type);
+ return iter != ARRAYEND(kResourceTypeValues);
+}
+
+const char* ResourceTypeToString(ResourceType type) {
+ ResourceType* iter =
+ std::find(kResourceTypeValues, ARRAYEND(kResourceTypeValues), type);
+ if (iter == ARRAYEND(kResourceTypeValues))
+ return "other";
+
+ return kResourceTypeStrings[iter - kResourceTypeValues];
+}
+
+bool ParseResourceType(const std::string& type_str,
+ ResourceType* type) {
+ const char** iter =
+ std::find(kResourceTypeStrings, ARRAYEND(kResourceTypeStrings), type_str);
+ if (iter == ARRAYEND(kResourceTypeStrings))
+ return false;
+ *type = kResourceTypeValues[iter - kResourceTypeStrings];
+ return true;
+}
+
+} // namespace extension_web_request_api_utils
« no previous file with comments | « extensions/browser/api/web_request/web_request_api_utils.h ('k') | extensions/extensions.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698