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

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

Issue 10012004: Implemented proper support for checking schemes and requested resource types. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Renamed 'scheme' to 'schemes' Created 8 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
Index: chrome/browser/extensions/api/web_request/web_request_api_helpers.cc
diff --git a/chrome/browser/extensions/api/web_request/web_request_api_helpers.cc b/chrome/browser/extensions/api/web_request/web_request_api_helpers.cc
index 63fc0e3bc7a431df66974be0ac3eed097385a91d..60b3807f492588609d74592d4795f931f21ccf0c 100644
--- a/chrome/browser/extensions/api/web_request/web_request_api_helpers.cc
+++ b/chrome/browser/extensions/api/web_request/web_request_api_helpers.cc
@@ -13,6 +13,43 @@
namespace extension_web_request_api_helpers {
+namespace {
+
+static const char* kResourceTypeStrings[] = {
+ "main_frame",
+ "sub_frame",
+ "stylesheet",
+ "script",
+ "image",
+ "object",
+ "xmlhttprequest",
+ "other",
+ "other",
+};
+
+static ResourceType::Type kResourceTypeValues[] = {
+ ResourceType::MAIN_FRAME,
+ ResourceType::SUB_FRAME,
+ ResourceType::STYLESHEET,
+ ResourceType::SCRIPT,
+ ResourceType::IMAGE,
+ ResourceType::OBJECT,
+ ResourceType::XHR,
+ ResourceType::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.
+ ResourceType::LAST_TYPE,
+};
+
+COMPILE_ASSERT(
+ arraysize(kResourceTypeStrings) == arraysize(kResourceTypeValues),
+ keep_resource_types_in_sync);
+
+} // namespace
+
EventResponseDelta::EventResponseDelta(
const std::string& extension_id, const base::Time& extension_install_time)
@@ -595,4 +632,31 @@ bool HideRequestForURL(const GURL& url) {
return IsSensitiveURL(url) || !HasWebRequestScheme(url);
}
+#define ARRAYEND(array) (array + arraysize(array))
+
+bool IsRelevantResourceType(ResourceType::Type type) {
+ ResourceType::Type* iter =
+ std::find(kResourceTypeValues, ARRAYEND(kResourceTypeValues), type);
+ return iter != ARRAYEND(kResourceTypeValues);
+}
+
+const char* ResourceTypeToString(ResourceType::Type type) {
+ ResourceType::Type* 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* 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_helpers
« no previous file with comments | « chrome/browser/extensions/api/web_request/web_request_api_helpers.h ('k') | chrome/chrome_browser_extensions.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698