From 1b970299e390f8a5d7091ec888e1e7013731cffc Mon Sep 17 00:00:00 2001 From: wjmaclean Date: Thu, 11 Sep 2014 11:57:17 -0700 Subject: [PATCH] Move web_request_condition* files to extensions/browser/api/declarative_webrequest/ This is a simple move, except that we move three functions out of chrome/browser/extensions/api/web_request/web_request_api_helpers to extensions/browser/api/web_request/web_request_api_utils in order to remove the chrome/ dependency. A new namespace is introduced to avoid confusion. BUG=352293. Review URL: https://codereview.chromium.org/562913002 Cr-Commit-Position: refs/heads/master@{#294437} --- .../declarative_webrequest/webrequest_action.cc | 2 +- .../webrequest_action_unittest.cc | 2 +- .../webrequest_rules_registry.cc | 2 +- .../webrequest_rules_registry.h | 2 +- .../extensions/api/web_request/web_request_api.cc | 8 ++- .../api/web_request/web_request_api_helpers.cc | 62 ------------------ .../api/web_request/web_request_api_helpers.h | 15 ----- chrome/chrome_browser_extensions.gypi | 4 -- chrome/chrome_tests_unit.gypi | 2 - extensions/BUILD.gn | 2 + extensions/browser/BUILD.gn | 6 ++ .../declarative_webrequest/webrequest_condition.cc | 4 +- .../declarative_webrequest/webrequest_condition.h | 8 +-- .../webrequest_condition_attribute.cc | 10 +-- .../webrequest_condition_attribute.h | 6 +- .../webrequest_condition_attribute_unittest.cc | 4 +- .../webrequest_condition_unittest.cc | 2 +- .../api/web_request/web_request_api_utils.cc | 73 ++++++++++++++++++++++ .../api/web_request/web_request_api_utils.h | 34 ++++++++++ extensions/extensions.gyp | 8 +++ 20 files changed, 149 insertions(+), 107 deletions(-) rename {chrome/browser/extensions => extensions/browser}/api/declarative_webrequest/webrequest_condition.cc (97%) rename {chrome/browser/extensions => extensions/browser}/api/declarative_webrequest/webrequest_condition.h (92%) rename {chrome/browser/extensions => extensions/browser}/api/declarative_webrequest/webrequest_condition_attribute.cc (98%) rename {chrome/browser/extensions => extensions/browser}/api/declarative_webrequest/webrequest_condition_attribute.h (97%) rename {chrome/browser/extensions => extensions/browser}/api/declarative_webrequest/webrequest_condition_attribute_unittest.cc (99%) rename {chrome/browser/extensions => extensions/browser}/api/declarative_webrequest/webrequest_condition_unittest.cc (99%) create mode 100644 extensions/browser/api/web_request/web_request_api_utils.cc create mode 100644 extensions/browser/api/web_request/web_request_api_utils.h diff --git a/chrome/browser/extensions/api/declarative_webrequest/webrequest_action.cc b/chrome/browser/extensions/api/declarative_webrequest/webrequest_action.cc index 5648540ae49a..95daec897852 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 85600c8f6495..94466e9c2466 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 c93c0d1a2176..66b3fca46f40 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 7404446f9f7e..889510ad2ecb 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 f3c69c612f7c..a1cecb7dc997 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 2cfbde51a479..26f1ef605280 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 > 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 77d540abc8f9..86c48f919733 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 2d900908e943..c271efb3d6fb 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 c1944290e309..6b98b42fd39a 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 21477fde9387..2769bdbb3c38 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 beb44f3866b8..73e62eb95d9a 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 similarity index 97% rename from chrome/browser/extensions/api/declarative_webrequest/webrequest_condition.cc rename to extensions/browser/api/declarative_webrequest/webrequest_condition.cc index bdc37a284edf..28c28ce7d543 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 similarity index 92% rename from chrome/browser/extensions/api/declarative_webrequest/webrequest_condition.h rename to extensions/browser/api/declarative_webrequest/webrequest_condition.h index 5a5d1e8cc640..12d47f8aa561 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 #include @@ -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 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 similarity index 98% rename from chrome/browser/extensions/api/declarative_webrequest/webrequest_condition_attribute.cc rename to extensions/browser/api/declarative_webrequest/webrequest_condition_attribute.cc index efdddc7b96ff..10295d26ee45 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 @@ -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(NULL); diff --git a/chrome/browser/extensions/api/declarative_webrequest/webrequest_condition_attribute.h b/extensions/browser/api/declarative_webrequest/webrequest_condition_attribute.h similarity index 97% rename from chrome/browser/extensions/api/declarative_webrequest/webrequest_condition_attribute.h rename to extensions/browser/api/declarative_webrequest/webrequest_condition_attribute.h index 9fc7ee3c88ad..aeebc23d8015 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 #include @@ -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 similarity index 99% rename from chrome/browser/extensions/api/declarative_webrequest/webrequest_condition_attribute_unittest.cc rename to extensions/browser/api/declarative_webrequest/webrequest_condition_attribute_unittest.cc index 775637ed7250..e24c3a997856 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 similarity index 99% rename from chrome/browser/extensions/api/declarative_webrequest/webrequest_condition_unittest.cc rename to extensions/browser/api/declarative_webrequest/webrequest_condition_unittest.cc index 0587f0e807fa..64a9bc8a8fab 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 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 000000000000..a19bcd0e770c --- /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 + +#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 000000000000..61b8fddf7064 --- /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 + +#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 fc657637e3c0..98f4c9f7d018 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', -- 2.11.4.GIT