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

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

Issue 601843002: Merge web_request_api_utils back into web_request_api_helpers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
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 119fbaf27ab6570cbcea11c463425cf261f9be15..680a9532eef0864765dc3e0efae169d5a5aa9446 100644
--- a/extensions/browser/api/web_request/web_request_api_helpers.cc
+++ b/extensions/browser/api/web_request/web_request_api_helpers.cc
@@ -4,9 +4,11 @@
#include "extensions/browser/api/web_request/web_request_api_helpers.h"
+#include <algorithm>
#include <cmath>
#include "base/bind.h"
+#include "base/macros.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
@@ -33,6 +35,7 @@
// top of this file.
using base::Time;
+using content::ResourceType;
using net::cookie_util::ParsedRequestCookie;
using net::cookie_util::ParsedRequestCookies;
@@ -42,6 +45,39 @@ namespace extension_web_request_api_helpers {
namespace {
+static const char* kResourceTypeStrings[] = {
+ "main_frame",
+ "sub_frame",
+ "stylesheet",
+ "script",
+ "image",
+ "object",
+ "xmlhttprequest",
+ "other",
+ "other",
+};
+
+const size_t kResourceTypeStringsLength = arraysize(kResourceTypeStrings);
+
+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,
+};
+
+const size_t kResourceTypeValuesLength = arraysize(kResourceTypeValues);
+
typedef std::vector<linked_ptr<net::ParsedCookie> > ParsedResponseCookies;
void ClearCacheOnNavigationOnUI() {
@@ -1217,4 +1253,37 @@ base::DictionaryValue* CreateHeaderDictionary(
return header;
}
+#define ARRAYEND(array) (array + arraysize(array))
+
+bool IsRelevantResourceType(ResourceType type) {
+ ResourceType* iter =
+ std::find(kResourceTypeValues,
+ kResourceTypeValues + kResourceTypeValuesLength,
+ type);
+ return iter != (kResourceTypeValues + kResourceTypeValuesLength);
+}
+
+const char* ResourceTypeToString(ResourceType type) {
+ ResourceType* iter =
+ std::find(kResourceTypeValues,
+ kResourceTypeValues + kResourceTypeValuesLength,
+ type);
+ if (iter == (kResourceTypeValues + kResourceTypeValuesLength))
+ return "other";
+
+ return kResourceTypeStrings[iter - kResourceTypeValues];
+}
+
+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;
+}
+
} // namespace extension_web_request_api_helpers

Powered by Google App Engine
This is Rietveld 408576698