summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/extensions/api/declarative_webrequest/webrequest_action.cc2
-rw-r--r--chrome/browser/extensions/api/declarative_webrequest/webrequest_action_unittest.cc2
-rw-r--r--chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_registry.cc2
-rw-r--r--chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_registry.h2
-rw-r--r--chrome/browser/extensions/api/web_request/web_request_api.cc8
-rw-r--r--chrome/browser/extensions/api/web_request/web_request_api_helpers.cc62
-rw-r--r--chrome/browser/extensions/api/web_request/web_request_api_helpers.h15
-rw-r--r--chrome/chrome_browser_extensions.gypi4
-rw-r--r--chrome/chrome_tests_unit.gypi2
-rw-r--r--extensions/BUILD.gn2
-rw-r--r--extensions/browser/BUILD.gn6
-rw-r--r--extensions/browser/api/declarative_webrequest/webrequest_condition.cc (renamed from chrome/browser/extensions/api/declarative_webrequest/webrequest_condition.cc)4
-rw-r--r--extensions/browser/api/declarative_webrequest/webrequest_condition.h (renamed from chrome/browser/extensions/api/declarative_webrequest/webrequest_condition.h)8
-rw-r--r--extensions/browser/api/declarative_webrequest/webrequest_condition_attribute.cc (renamed from chrome/browser/extensions/api/declarative_webrequest/webrequest_condition_attribute.cc)10
-rw-r--r--extensions/browser/api/declarative_webrequest/webrequest_condition_attribute.h (renamed from chrome/browser/extensions/api/declarative_webrequest/webrequest_condition_attribute.h)6
-rw-r--r--extensions/browser/api/declarative_webrequest/webrequest_condition_attribute_unittest.cc (renamed from chrome/browser/extensions/api/declarative_webrequest/webrequest_condition_attribute_unittest.cc)4
-rw-r--r--extensions/browser/api/declarative_webrequest/webrequest_condition_unittest.cc (renamed from chrome/browser/extensions/api/declarative_webrequest/webrequest_condition_unittest.cc)2
-rw-r--r--extensions/browser/api/web_request/web_request_api_utils.cc73
-rw-r--r--extensions/browser/api/web_request/web_request_api_utils.h34
-rw-r--r--extensions/extensions.gyp8
20 files changed, 149 insertions, 107 deletions
diff --git a/chrome/browser/extensions/api/declarative_webrequest/webrequest_action.cc b/chrome/browser/extensions/api/declarative_webrequest/webrequest_action.cc
index 5648540a..95daec8 100644
--- a/chrome/browser/extensions/api/declarative_webrequest/webrequest_action.cc
+++ b/chrome/browser/extensions/api/declarative_webrequest/webrequest_action.cc
@@ -11,7 +11,6 @@
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/values.h"
-#include "chrome/browser/extensions/api/declarative_webrequest/webrequest_condition.h"
#include "chrome/browser/extensions/api/web_request/web_request_api_constants.h"
#include "chrome/browser/extensions/api/web_request/web_request_api_helpers.h"
#include "chrome/browser/extensions/api/web_request/web_request_permissions.h"
@@ -19,6 +18,7 @@
#include "content/public/common/url_constants.h"
#include "extensions/browser/api/declarative/deduping_factory.h"
#include "extensions/browser/api/declarative_webrequest/request_stage.h"
+#include "extensions/browser/api/declarative_webrequest/webrequest_condition.h"
#include "extensions/browser/api/declarative_webrequest/webrequest_constants.h"
#include "extensions/browser/guest_view/web_view/web_view_renderer_state.h"
#include "extensions/browser/info_map.h"
diff --git a/chrome/browser/extensions/api/declarative_webrequest/webrequest_action_unittest.cc b/chrome/browser/extensions/api/declarative_webrequest/webrequest_action_unittest.cc
index 85600c8..94466e9 100644
--- a/chrome/browser/extensions/api/declarative_webrequest/webrequest_action_unittest.cc
+++ b/chrome/browser/extensions/api/declarative_webrequest/webrequest_action_unittest.cc
@@ -13,13 +13,13 @@
#include "base/test/values_test_util.h"
#include "base/time/time.h"
#include "base/values.h"
-#include "chrome/browser/extensions/api/declarative_webrequest/webrequest_condition.h"
#include "chrome/browser/extensions/api/web_request/web_request_api_helpers.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/extensions/extension_constants.h"
#include "chrome/common/extensions/extension_test_util.h"
#include "content/public/test/test_browser_thread_bundle.h"
#include "extensions/browser/api/declarative_webrequest/request_stage.h"
+#include "extensions/browser/api/declarative_webrequest/webrequest_condition.h"
#include "extensions/browser/api/declarative_webrequest/webrequest_constants.h"
#include "extensions/browser/info_map.h"
#include "extensions/common/extension.h"
diff --git a/chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_registry.cc b/chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_registry.cc
index c93c0d1..66b3fca 100644
--- a/chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_registry.cc
+++ b/chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_registry.cc
@@ -10,9 +10,9 @@
#include "base/bind.h"
#include "base/stl_util.h"
-#include "chrome/browser/extensions/api/declarative_webrequest/webrequest_condition.h"
#include "chrome/browser/extensions/api/web_request/web_request_api_helpers.h"
#include "chrome/browser/extensions/api/web_request/web_request_permissions.h"
+#include "extensions/browser/api/declarative_webrequest/webrequest_condition.h"
#include "extensions/browser/api/declarative_webrequest/webrequest_constants.h"
#include "extensions/browser/extension_system.h"
#include "extensions/common/error_utils.h"
diff --git a/chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_registry.h b/chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_registry.h
index 7404446..889510a 100644
--- a/chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_registry.h
+++ b/chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_registry.h
@@ -17,11 +17,11 @@
#include "base/memory/scoped_ptr.h"
#include "base/time/time.h"
#include "chrome/browser/extensions/api/declarative_webrequest/webrequest_action.h"
-#include "chrome/browser/extensions/api/declarative_webrequest/webrequest_condition.h"
#include "components/url_matcher/url_matcher.h"
#include "extensions/browser/api/declarative/declarative_rule.h"
#include "extensions/browser/api/declarative/rules_registry.h"
#include "extensions/browser/api/declarative_webrequest/request_stage.h"
+#include "extensions/browser/api/declarative_webrequest/webrequest_condition.h"
#include "extensions/browser/info_map.h"
class WebRequestPermissions;
diff --git a/chrome/browser/extensions/api/web_request/web_request_api.cc b/chrome/browser/extensions/api/web_request/web_request_api.cc
index f3c69c6..a1cecb7 100644
--- a/chrome/browser/extensions/api/web_request/web_request_api.cc
+++ b/chrome/browser/extensions/api/web_request/web_request_api.cc
@@ -42,6 +42,7 @@
#include "content/public/browser/user_metrics.h"
#include "extensions/browser/api/declarative_webrequest/request_stage.h"
#include "extensions/browser/api/declarative_webrequest/webrequest_constants.h"
+#include "extensions/browser/api/web_request/web_request_api_utils.h"
#include "extensions/browser/event_router.h"
#include "extensions/browser/extension_message_filter.h"
#include "extensions/browser/extension_prefs.h"
@@ -87,6 +88,7 @@ using extensions::WarningService;
using extensions::WarningSet;
namespace helpers = extension_web_request_api_helpers;
+namespace utils = extension_web_request_api_utils;
namespace keys = extension_web_request_api_constants;
namespace web_request = extensions::api::web_request;
namespace declarative_keys = extensions::declarative_webrequest_constants;
@@ -220,7 +222,7 @@ void ExtractRequestInfoDetails(net::URLRequest* request,
*routing_id = info->GetRouteID();
// Restrict the resource type to the values we care about.
- if (helpers::IsRelevantResourceType(info->GetResourceType()))
+ if (utils::IsRelevantResourceType(info->GetResourceType()))
*resource_type = info->GetResourceType();
else
*resource_type = content::RESOURCE_TYPE_LAST_TYPE;
@@ -256,7 +258,7 @@ void ExtractRequestInfo(net::URLRequest* request, base::DictionaryValue* out) {
out->SetInteger(keys::kFrameIdKey, frame_id_for_extension);
out->SetInteger(keys::kParentFrameIdKey, parent_frame_id_for_extension);
out->SetInteger(keys::kTabIdKey, tab_id);
- out->SetString(keys::kTypeKey, helpers::ResourceTypeToString(resource_type));
+ out->SetString(keys::kTypeKey, utils::ResourceTypeToString(resource_type));
out->SetDouble(keys::kTimeStampKey, base::Time::Now().ToDoubleT() * 1000);
}
@@ -627,7 +629,7 @@ bool ExtensionWebRequestEventRouter::RequestFilter::InitFromValue(
std::string type_str;
ResourceType type;
if (!types_value->GetString(i, &type_str) ||
- !helpers::ParseResourceType(type_str, &type))
+ !utils::ParseResourceType(type_str, &type))
return false;
types.push_back(type);
}
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 2cfbde5..26f1ef6 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
@@ -32,7 +32,6 @@
// top of this file.
using base::Time;
-using content::ResourceType;
using net::cookie_util::ParsedRequestCookie;
using net::cookie_util::ParsedRequestCookies;
@@ -42,39 +41,6 @@ namespace {
typedef std::vector<linked_ptr<net::ParsedCookie> > ParsedResponseCookies;
-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,
-};
-
-COMPILE_ASSERT(
- arraysize(kResourceTypeStrings) == arraysize(kResourceTypeValues),
- keep_resource_types_in_sync);
-
void ClearCacheOnNavigationOnUI() {
WebCacheManager::GetInstance()->ClearCacheOnNavigation();
}
@@ -1180,34 +1146,6 @@ bool MergeOnAuthRequiredResponses(
return credentials_set;
}
-
-#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;
-}
-
void ClearCacheOnNavigation() {
if (content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) {
ClearCacheOnNavigationOnUI();
diff --git a/chrome/browser/extensions/api/web_request/web_request_api_helpers.h b/chrome/browser/extensions/api/web_request/web_request_api_helpers.h
index 77d540a..86c48f9 100644
--- a/chrome/browser/extensions/api/web_request/web_request_api_helpers.h
+++ b/chrome/browser/extensions/api/web_request/web_request_api_helpers.h
@@ -15,7 +15,6 @@
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/time/time.h"
-#include "content/public/common/resource_type.h"
#include "extensions/browser/warning_set.h"
#include "net/base/auth.h"
#include "net/http/http_request_headers.h"
@@ -302,20 +301,6 @@ bool MergeOnAuthRequiredResponses(
extensions::WarningSet* conflicting_extensions,
const net::BoundNetLog* net_log);
-// Returns whether |type| is a ResourceType that is handled by the web request
-// API.
-bool IsRelevantResourceType(content::ResourceType type);
-
-// Returns a string representation of |type| or |other| if |type| is not handled
-// by the web request API.
-const char* ResourceTypeToString(content::ResourceType type);
-
-// Stores a |content::ResourceType| representation in |type| if |type_str| is
-// a resource type handled by the web request API. Returns true in case of
-// success.
-bool ParseResourceType(const std::string& type_str,
- content::ResourceType* type);
-
// Triggers clearing each renderer's in-memory cache the next time it navigates.
void ClearCacheOnNavigation();
diff --git a/chrome/chrome_browser_extensions.gypi b/chrome/chrome_browser_extensions.gypi
index 2d90090..c271efb 100644
--- a/chrome/chrome_browser_extensions.gypi
+++ b/chrome/chrome_browser_extensions.gypi
@@ -184,10 +184,6 @@
'browser/extensions/api/declarative_content/content_rules_registry.h',
'browser/extensions/api/declarative_webrequest/webrequest_action.cc',
'browser/extensions/api/declarative_webrequest/webrequest_action.h',
- 'browser/extensions/api/declarative_webrequest/webrequest_condition.cc',
- 'browser/extensions/api/declarative_webrequest/webrequest_condition.h',
- 'browser/extensions/api/declarative_webrequest/webrequest_condition_attribute.cc',
- 'browser/extensions/api/declarative_webrequest/webrequest_condition_attribute.h',
'browser/extensions/api/declarative_webrequest/webrequest_rules_registry.cc',
'browser/extensions/api/declarative_webrequest/webrequest_rules_registry.h',
'browser/extensions/api/desktop_capture/desktop_capture_api.cc',
diff --git a/chrome/chrome_tests_unit.gypi b/chrome/chrome_tests_unit.gypi
index c194429..6b98b42 100644
--- a/chrome/chrome_tests_unit.gypi
+++ b/chrome/chrome_tests_unit.gypi
@@ -843,8 +843,6 @@
'browser/extensions/api/declarative_content/content_condition_unittest.cc',
'browser/extensions/api/declarative_content/content_rules_registry_unittest.cc',
'browser/extensions/api/declarative_webrequest/webrequest_action_unittest.cc',
- 'browser/extensions/api/declarative_webrequest/webrequest_condition_attribute_unittest.cc',
- 'browser/extensions/api/declarative_webrequest/webrequest_condition_unittest.cc',
'browser/extensions/api/declarative_webrequest/webrequest_rules_registry_unittest.cc',
'browser/extensions/api/dial/dial_device_data_unittest.cc',
'browser/extensions/api/dial/dial_registry_unittest.cc',
diff --git a/extensions/BUILD.gn b/extensions/BUILD.gn
index 21477fd..2769bdb 100644
--- a/extensions/BUILD.gn
+++ b/extensions/BUILD.gn
@@ -167,6 +167,8 @@ test("unittests") {
"browser/api/api_resource_manager_unittest.cc",
"browser/api/declarative/declarative_rule_unittest.cc",
"browser/api/declarative/deduping_factory_unittest.cc",
+ "browser/api/declarative_webrequest/webrequest_condition_attribute_unittest.cc",
+ "browser/api/declarative_webrequest/webrequest_condition_unittest.cc",
"browser/api/sockets_tcp/sockets_tcp_api_unittest.cc",
"browser/api/storage/settings_quota_unittest.cc",
"browser/api/storage/storage_api_unittest.cc",
diff --git a/extensions/browser/BUILD.gn b/extensions/browser/BUILD.gn
index beb44f3..73e62eb 100644
--- a/extensions/browser/BUILD.gn
+++ b/extensions/browser/BUILD.gn
@@ -103,6 +103,10 @@ source_set("browser") {
"api/declarative/test_rules_registry.h",
"api/declarative_webrequest/request_stage.cc",
"api/declarative_webrequest/request_stage.h",
+ "api/declarative_webrequest/webrequest_condition_attribute.cc",
+ "api/declarative_webrequest/webrequest_condition_attribute.h",
+ "api/declarative_webrequest/webrequest_condition.cc",
+ "api/declarative_webrequest/webrequest_condition.h",
"api/declarative_webrequest/webrequest_constants.cc",
"api/declarative_webrequest/webrequest_constants.h",
"api/dns/dns_api.cc",
@@ -206,6 +210,8 @@ source_set("browser") {
"api/usb/usb_device_resource.h",
"api/usb_private/usb_private_api.cc",
"api/usb_private/usb_private_api.h",
+ "api/web_request/web_request_api_utils.cc",
+ "api/web_request/web_request_api_utils.h",
"api/web_view/web_view_internal_api.cc",
"api/web_view/web_view_internal_api.h",
"api_activity_monitor.h",
diff --git a/chrome/browser/extensions/api/declarative_webrequest/webrequest_condition.cc b/extensions/browser/api/declarative_webrequest/webrequest_condition.cc
index bdc37a2..28c28ce 100644
--- a/chrome/browser/extensions/api/declarative_webrequest/webrequest_condition.cc
+++ b/extensions/browser/api/declarative_webrequest/webrequest_condition.cc
@@ -2,16 +2,16 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/extensions/api/declarative_webrequest/webrequest_condition.h"
+#include "extensions/browser/api/declarative_webrequest/webrequest_condition.h"
#include "base/bind.h"
#include "base/logging.h"
#include "base/stl_util.h"
#include "base/strings/stringprintf.h"
#include "base/values.h"
-#include "chrome/browser/extensions/api/declarative_webrequest/webrequest_condition_attribute.h"
#include "components/url_matcher/url_matcher_factory.h"
#include "extensions/browser/api/declarative_webrequest/request_stage.h"
+#include "extensions/browser/api/declarative_webrequest/webrequest_condition_attribute.h"
#include "extensions/browser/api/declarative_webrequest/webrequest_constants.h"
#include "net/url_request/url_request.h"
diff --git a/chrome/browser/extensions/api/declarative_webrequest/webrequest_condition.h b/extensions/browser/api/declarative_webrequest/webrequest_condition.h
index 5a5d1e8..12d47f8 100644
--- a/chrome/browser/extensions/api/declarative_webrequest/webrequest_condition.h
+++ b/extensions/browser/api/declarative_webrequest/webrequest_condition.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_CONDITION_H_
-#define CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_CONDITION_H_
+#ifndef EXTENSIONS_BROWSER_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_CONDITION_H_
+#define EXTENSIONS_BROWSER_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_CONDITION_H_
#include <map>
#include <set>
@@ -12,9 +12,9 @@
#include "base/basictypes.h"
#include "base/memory/linked_ptr.h"
-#include "chrome/browser/extensions/api/declarative_webrequest/webrequest_condition_attribute.h"
#include "components/url_matcher/url_matcher.h"
#include "extensions/browser/api/declarative/declarative_rule.h"
+#include "extensions/browser/api/declarative_webrequest/webrequest_condition_attribute.h"
#include "net/http/http_response_headers.h"
namespace extensions {
@@ -116,4 +116,4 @@ typedef DeclarativeConditionSet<WebRequestCondition> WebRequestConditionSet;
} // namespace extensions
-#endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_CONDITION_H_
+#endif // EXTENSIONS_BROWSER_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_CONDITION_H_
diff --git a/chrome/browser/extensions/api/declarative_webrequest/webrequest_condition_attribute.cc b/extensions/browser/api/declarative_webrequest/webrequest_condition_attribute.cc
index efdddc7..10295d2 100644
--- a/chrome/browser/extensions/api/declarative_webrequest/webrequest_condition_attribute.cc
+++ b/extensions/browser/api/declarative_webrequest/webrequest_condition_attribute.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/extensions/api/declarative_webrequest/webrequest_condition_attribute.h"
+#include "extensions/browser/api/declarative_webrequest/webrequest_condition_attribute.h"
#include <algorithm>
@@ -11,12 +11,12 @@
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/values.h"
-#include "chrome/browser/extensions/api/declarative_webrequest/webrequest_condition.h"
-#include "chrome/browser/extensions/api/web_request/web_request_api_helpers.h"
#include "content/public/browser/resource_request_info.h"
#include "extensions/browser/api/declarative/deduping_factory.h"
#include "extensions/browser/api/declarative_webrequest/request_stage.h"
+#include "extensions/browser/api/declarative_webrequest/webrequest_condition.h"
#include "extensions/browser/api/declarative_webrequest/webrequest_constants.h"
+#include "extensions/browser/api/web_request/web_request_api_utils.h"
#include "extensions/common/error_utils.h"
#include "net/base/net_errors.h"
#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
@@ -32,7 +32,7 @@ using base::StringValue;
using base::Value;
using content::ResourceType;
-namespace helpers = extension_web_request_api_helpers;
+namespace utils = extension_web_request_api_utils;
namespace keys = extensions::declarative_webrequest_constants;
namespace extensions {
@@ -154,7 +154,7 @@ WebRequestConditionAttributeResourceType::Create(
std::string resource_type_string;
ResourceType type = content::RESOURCE_TYPE_LAST_TYPE;
if (!value_as_list->GetString(i, &resource_type_string) ||
- !helpers::ParseResourceType(resource_type_string, &type)) {
+ !utils::ParseResourceType(resource_type_string, &type)) {
*error = ErrorUtils::FormatErrorMessage(kInvalidValue,
keys::kResourceTypeKey);
return scoped_refptr<const WebRequestConditionAttribute>(NULL);
diff --git a/chrome/browser/extensions/api/declarative_webrequest/webrequest_condition_attribute.h b/extensions/browser/api/declarative_webrequest/webrequest_condition_attribute.h
index 9fc7ee3..aeebc23 100644
--- a/chrome/browser/extensions/api/declarative_webrequest/webrequest_condition_attribute.h
+++ b/extensions/browser/api/declarative_webrequest/webrequest_condition_attribute.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_CONDITION_ATTRIBUTE_H_
-#define CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_CONDITION_ATTRIBUTE_H_
+#ifndef EXTENSIONS_BROWSER_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_CONDITION_ATTRIBUTE_H_
+#define EXTENSIONS_BROWSER_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_CONDITION_ATTRIBUTE_H_
#include <string>
#include <vector>
@@ -272,4 +272,4 @@ class WebRequestConditionAttributeStages
} // namespace extensions
-#endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_CONDITION_ATTRIBUTE_H_
+#endif // EXTENSIONS_BROWSER_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_CONDITION_ATTRIBUTE_H_
diff --git a/chrome/browser/extensions/api/declarative_webrequest/webrequest_condition_attribute_unittest.cc b/extensions/browser/api/declarative_webrequest/webrequest_condition_attribute_unittest.cc
index 775637e..e24c3a9 100644
--- a/chrome/browser/extensions/api/declarative_webrequest/webrequest_condition_attribute_unittest.cc
+++ b/extensions/browser/api/declarative_webrequest/webrequest_condition_attribute_unittest.cc
@@ -2,15 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/extensions/api/declarative_webrequest/webrequest_condition_attribute.h"
+#include "extensions/browser/api/declarative_webrequest/webrequest_condition_attribute.h"
#include "base/basictypes.h"
#include "base/files/file_path.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_loop.h"
#include "base/values.h"
-#include "chrome/browser/extensions/api/declarative_webrequest/webrequest_condition.h"
#include "content/public/browser/resource_request_info.h"
+#include "extensions/browser/api/declarative_webrequest/webrequest_condition.h"
#include "extensions/browser/api/declarative_webrequest/webrequest_constants.h"
#include "net/base/request_priority.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
diff --git a/chrome/browser/extensions/api/declarative_webrequest/webrequest_condition_unittest.cc b/extensions/browser/api/declarative_webrequest/webrequest_condition_unittest.cc
index 0587f0e..64a9bc8 100644
--- a/chrome/browser/extensions/api/declarative_webrequest/webrequest_condition_unittest.cc
+++ b/extensions/browser/api/declarative_webrequest/webrequest_condition_unittest.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/extensions/api/declarative_webrequest/webrequest_condition.h"
+#include "extensions/browser/api/declarative_webrequest/webrequest_condition.h"
#include <set>
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 0000000..a19bcd0
--- /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
diff --git a/extensions/browser/api/web_request/web_request_api_utils.h b/extensions/browser/api/web_request/web_request_api_utils.h
new file mode 100644
index 0000000..61b8fdd
--- /dev/null
+++ b/extensions/browser/api/web_request/web_request_api_utils.h
@@ -0,0 +1,34 @@
+// 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.
+
+// Helper functions used for the WebRequest API.
+
+#ifndef EXTENSIONS_BROWSER_API_WEB_REQUEST_WEB_REQUEST_API_UTILS_H_
+#define EXTENSIONS_BROWSER_API_WEB_REQUEST_WEB_REQUEST_API_UTILS_H_
+
+#include <string>
+
+#include "content/public/common/resource_type.h"
+
+using content::ResourceType;
+
+namespace extension_web_request_api_utils {
+
+// Returns whether |type| is a ResourceType that is handled by the web request
+// API.
+bool IsRelevantResourceType(content::ResourceType type);
+
+// Returns a string representation of |type| or |other| if |type| is not handled
+// by the web request API.
+const char* ResourceTypeToString(content::ResourceType type);
+
+// Stores a |content::ResourceType| representation in |type| if |type_str| is
+// a resource type handled by the web request API. Returns true in case of
+// success.
+bool ParseResourceType(const std::string& type_str,
+ content::ResourceType* type);
+
+} // namespace extension_web_request_api_utils
+
+#endif // EXTENSIONS_BROWSER_API_WEB_REQUEST_WEB_REQUEST_API_UTILS_H_
diff --git a/extensions/extensions.gyp b/extensions/extensions.gyp
index fc65763..98f4c9f 100644
--- a/extensions/extensions.gyp
+++ b/extensions/extensions.gyp
@@ -371,6 +371,10 @@
'browser/api/declarative/test_rules_registry.h',
'browser/api/declarative_webrequest/request_stage.cc',
'browser/api/declarative_webrequest/request_stage.h',
+ 'browser/api/declarative_webrequest/webrequest_condition.cc',
+ 'browser/api/declarative_webrequest/webrequest_condition.h',
+ 'browser/api/declarative_webrequest/webrequest_condition_attribute.cc',
+ 'browser/api/declarative_webrequest/webrequest_condition_attribute.h',
'browser/api/declarative_webrequest/webrequest_constants.cc',
'browser/api/declarative_webrequest/webrequest_constants.h',
'browser/api/dns/dns_api.cc',
@@ -466,6 +470,8 @@
'browser/api/system_storage/storage_info_provider.h',
'browser/api/system_storage/system_storage_api.cc',
'browser/api/system_storage/system_storage_api.h',
+ 'browser/api/web_request/web_request_api_utils.cc',
+ 'browser/api/web_request/web_request_api_utils.h',
'browser/api/test/test_api.cc',
'browser/api/test/test_api.h',
'browser/api/usb/usb_api.cc',
@@ -1047,6 +1053,8 @@
'browser/api/cast_channel/logger_unittest.cc',
'browser/api/declarative/declarative_rule_unittest.cc',
'browser/api/declarative/deduping_factory_unittest.cc',
+ 'browser/api/declarative_webrequest/webrequest_condition_unittest.cc',
+ 'browser/api/declarative_webrequest/webrequest_condition_attribute_unittest.cc',
'browser/api/power/power_api_unittest.cc',
'browser/api/sockets_tcp/sockets_tcp_api_unittest.cc',
'browser/api/storage/settings_quota_unittest.cc',