From 716c016d95025a8f4d42baab6639b9dc90498f2d Mon Sep 17 00:00:00 2001 From: "joaodasilva@chromium.org" Date: Fri, 13 Dec 2013 20:36:53 +0000 Subject: [PATCH] Move extensions/common/matcher into components/url_matcher. This allows using that code in builds that don't include extensions without having to introduce layering exceptions. This is meant for inclusion on the iOS build. BUG=271392 TBR=brettw@chromium.org Review URL: https://codereview.chromium.org/113903002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@240736 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/DEPS | 1 + .../api/declarative/declarative_rule.h | 24 +++---- .../declarative/declarative_rule_unittest.cc | 9 ++- .../declarative_content/content_condition.cc | 8 ++- .../declarative_content/content_condition.h | 14 ++-- .../content_condition_unittest.cc | 10 +-- .../content_rules_registry.cc | 2 + .../content_rules_registry.h | 7 +- .../webrequest_condition.cc | 8 ++- .../webrequest_condition.h | 20 +++--- .../webrequest_condition_unittest.cc | 8 +-- .../webrequest_rules_registry.cc | 2 + .../webrequest_rules_registry.h | 15 +++-- .../webrequest_rules_registry_unittest.cc | 16 ++--- .../managed_mode/managed_mode_url_filter.cc | 8 +-- .../browser/policy/url_blacklist_manager.cc | 17 +++-- chrome/browser/policy/url_blacklist_manager.h | 14 ++-- chrome/chrome_browser.gypi | 1 + chrome/chrome_browser_extensions.gypi | 1 + chrome/chrome_tests_unit.gypi | 5 -- components/components.gyp | 1 + components/components_tests.gyp | 8 +++ components/url_matcher.gypi | 43 +++++++++++++ components/url_matcher/DEPS | 3 + .../matcher => components/url_matcher}/OWNERS | 0 .../url_matcher}/regex_set_matcher.cc | 10 +-- .../url_matcher}/regex_set_matcher.h | 19 +++--- .../regex_set_matcher_unittest.cc | 11 ++-- .../url_matcher}/string_pattern.cc | 8 +-- .../url_matcher}/string_pattern.h | 15 +++-- .../url_matcher}/string_pattern_unittest.cc | 8 ++- .../url_matcher}/substring_set_matcher.cc | 8 +-- .../url_matcher}/substring_set_matcher.h | 17 ++--- .../substring_set_matcher_unittest.cc | 13 ++-- .../url_matcher}/url_matcher.cc | 9 ++- .../url_matcher}/url_matcher.h | 30 +++++---- .../url_matcher}/url_matcher_constants.cc | 8 +-- .../url_matcher/url_matcher_constants.h | 41 ++++++++++++ components/url_matcher/url_matcher_export.h | 29 +++++++++ .../url_matcher}/url_matcher_factory.cc | 64 +++++++++---------- .../url_matcher}/url_matcher_factory.h | 17 ++--- .../url_matcher_factory_unittest.cc | 10 +-- .../url_matcher}/url_matcher_helpers.cc | 8 +-- .../url_matcher}/url_matcher_helpers.h | 14 ++-- .../url_matcher}/url_matcher_unittest.cc | 8 +-- extensions/DEPS | 1 + extensions/common/event_filter.cc | 6 +- extensions/common/event_filter.h | 28 ++++---- .../common/matcher/url_matcher_constants.h | 39 ----------- extensions/extensions.gyp | 15 +---- 50 files changed, 393 insertions(+), 288 deletions(-) create mode 100644 components/url_matcher.gypi create mode 100644 components/url_matcher/DEPS rename {extensions/common/matcher => components/url_matcher}/OWNERS (100%) rename {extensions/common/matcher => components/url_matcher}/regex_set_matcher.cc (93%) rename {extensions/common/matcher => components/url_matcher}/regex_set_matcher.h (82%) rename {extensions/common/matcher => components/url_matcher}/regex_set_matcher_unittest.cc (90%) rename {extensions/common/matcher => components/url_matcher}/string_pattern.cc (71%) rename {extensions/common/matcher => components/url_matcher}/string_pattern.h (71%) rename {extensions/common/matcher => components/url_matcher}/string_pattern_unittest.cc (73%) rename {extensions/common/matcher => components/url_matcher}/substring_set_matcher.cc (97%) rename {extensions/common/matcher => components/url_matcher}/substring_set_matcher.h (92%) rename {extensions/common/matcher => components/url_matcher}/substring_set_matcher_unittest.cc (96%) rename {extensions/common/matcher => components/url_matcher}/url_matcher.cc (99%) rename {extensions/common/matcher => components/url_matcher}/url_matcher.h (94%) rename {extensions/common/matcher => components/url_matcher}/url_matcher_constants.cc (87%) create mode 100644 components/url_matcher/url_matcher_constants.h create mode 100644 components/url_matcher/url_matcher_export.h rename {extensions/common/matcher => components/url_matcher}/url_matcher_factory.cc (83%) rename {extensions/common/matcher => components/url_matcher}/url_matcher_factory.h (81%) rename {extensions/common/matcher => components/url_matcher}/url_matcher_factory_unittest.cc (98%) rename {extensions/common/matcher => components/url_matcher}/url_matcher_helpers.cc (80%) rename {extensions/common/matcher => components/url_matcher}/url_matcher_helpers.h (57%) rename {extensions/common/matcher => components/url_matcher}/url_matcher_unittest.cc (99%) delete mode 100644 extensions/common/matcher/url_matcher_constants.h diff --git a/chrome/browser/DEPS b/chrome/browser/DEPS index 5425da78765ccd..74cae02f549a62 100644 --- a/chrome/browser/DEPS +++ b/chrome/browser/DEPS @@ -19,6 +19,7 @@ include_rules = [ "+components/sessions", "+components/startup_metric_utils", "+components/translate/common", + "+components/url_matcher", "+components/user_prefs", "+components/webdata", "+components/web_modal", diff --git a/chrome/browser/extensions/api/declarative/declarative_rule.h b/chrome/browser/extensions/api/declarative/declarative_rule.h index d51d7e24bcba97..b06ae7004eca48 100644 --- a/chrome/browser/extensions/api/declarative/declarative_rule.h +++ b/chrome/browser/extensions/api/declarative/declarative_rule.h @@ -21,8 +21,8 @@ #include "base/stl_util.h" #include "base/time/time.h" #include "chrome/common/extensions/api/events.h" +#include "components/url_matcher/url_matcher.h" #include "extensions/common/extension.h" -#include "extensions/common/matcher/url_matcher.h" namespace base { class Time; @@ -64,7 +64,7 @@ class DeclarativeConditionSet { // |error| and returns NULL in case of an error. static scoped_ptr Create( const Extension* extension, - URLMatcherConditionFactory* url_matcher_condition_factory, + url_matcher::URLMatcherConditionFactory* url_matcher_condition_factory, const AnyVector& conditions, std::string* error); @@ -80,12 +80,12 @@ class DeclarativeConditionSet { // IsFulfilled(|match_data|). If there is no such condition, then false is // returned. If |url_match_trigger| is -1, this function returns whether any // of the conditions without URL attributes is satisfied. - bool IsFulfilled(URLMatcherConditionSet::ID url_match_trigger, + bool IsFulfilled(url_matcher::URLMatcherConditionSet::ID url_match_trigger, const typename ConditionT::MatchData& match_data) const; // Appends the URLMatcherConditionSet from all conditions to |condition_sets|. void GetURLMatcherConditionSets( - URLMatcherConditionSet::Vector* condition_sets) const; + url_matcher::URLMatcherConditionSet::Vector* condition_sets) const; // Returns whether there are some conditions without UrlFilter attributes. bool HasConditionsWithoutUrls() const { @@ -93,7 +93,7 @@ class DeclarativeConditionSet { } private: - typedef std::map + typedef std::map URLMatcherIdToCondition; DeclarativeConditionSet( @@ -216,7 +216,7 @@ class DeclarativeRule { // check is needed. If |error| is empty, the translation was successful and // the returned rule is internally consistent. static scoped_ptr Create( - URLMatcherConditionFactory* url_matcher_condition_factory, + url_matcher::URLMatcherConditionFactory* url_matcher_condition_factory, const Extension* extension, base::Time extension_installation_time, linked_ptr rule, @@ -260,7 +260,7 @@ class DeclarativeRule { template bool DeclarativeConditionSet::IsFulfilled( - URLMatcherConditionSet::ID url_match_trigger, + url_matcher::URLMatcherConditionSet::ID url_match_trigger, const typename ConditionT::MatchData& match_data) const { if (url_match_trigger == -1) { // Invalid trigger -- indication that we should only check conditions @@ -282,7 +282,7 @@ bool DeclarativeConditionSet::IsFulfilled( template void DeclarativeConditionSet::GetURLMatcherConditionSets( - URLMatcherConditionSet::Vector* condition_sets) const { + url_matcher::URLMatcherConditionSet::Vector* condition_sets) const { for (typename Conditions::const_iterator i = conditions_.begin(); i != conditions_.end(); ++i) { (*i)->GetURLMatcherConditionSets(condition_sets); @@ -294,7 +294,7 @@ template scoped_ptr > DeclarativeConditionSet::Create( const Extension* extension, - URLMatcherConditionFactory* url_matcher_condition_factory, + url_matcher::URLMatcherConditionFactory* url_matcher_condition_factory, const AnyVector& conditions, std::string* error) { Conditions result; @@ -311,7 +311,7 @@ DeclarativeConditionSet::Create( URLMatcherIdToCondition match_id_to_condition; std::vector conditions_without_urls; - URLMatcherConditionSet::Vector condition_sets; + url_matcher::URLMatcherConditionSet::Vector condition_sets; for (typename Conditions::const_iterator i = result.begin(); i != result.end(); ++i) { @@ -320,7 +320,7 @@ DeclarativeConditionSet::Create( if (condition_sets.empty()) { conditions_without_urls.push_back(i->get()); } else { - for (URLMatcherConditionSet::Vector::const_iterator + for (url_matcher::URLMatcherConditionSet::Vector::const_iterator match_set = condition_sets.begin(); match_set != condition_sets.end(); ++match_set) match_id_to_condition[(*match_set)->id()] = i->get(); @@ -429,7 +429,7 @@ DeclarativeRule::DeclarativeRule( template scoped_ptr > DeclarativeRule::Create( - URLMatcherConditionFactory* url_matcher_condition_factory, + url_matcher::URLMatcherConditionFactory* url_matcher_condition_factory, const Extension* extension, base::Time extension_installation_time, linked_ptr rule, diff --git a/chrome/browser/extensions/api/declarative/declarative_rule_unittest.cc b/chrome/browser/extensions/api/declarative/declarative_rule_unittest.cc index df30af1522a6db..98b2552d7e7aa8 100644 --- a/chrome/browser/extensions/api/declarative/declarative_rule_unittest.cc +++ b/chrome/browser/extensions/api/declarative/declarative_rule_unittest.cc @@ -8,14 +8,17 @@ #include "base/message_loop/message_loop.h" #include "base/test/values_test_util.h" #include "base/values.h" +#include "components/url_matcher/url_matcher_constants.h" #include "extensions/common/extension_builder.h" -#include "extensions/common/matcher/url_matcher_constants.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" -namespace extensions { - using base::test::ParseJson; +using url_matcher::URLMatcher; +using url_matcher::URLMatcherConditionFactory; +using url_matcher::URLMatcherConditionSet; + +namespace extensions { namespace { diff --git a/chrome/browser/extensions/api/declarative_content/content_condition.cc b/chrome/browser/extensions/api/declarative_content/content_condition.cc index 74319f8337a628..5a88d1c446e461 100644 --- a/chrome/browser/extensions/api/declarative_content/content_condition.cc +++ b/chrome/browser/extensions/api/declarative_content/content_condition.cc @@ -7,12 +7,16 @@ #include "base/strings/stringprintf.h" #include "base/values.h" #include "chrome/browser/extensions/api/declarative_content/content_constants.h" -#include "extensions/common/matcher/url_matcher_factory.h" +#include "components/url_matcher/url_matcher_factory.h" + +using url_matcher::URLMatcherConditionFactory; +using url_matcher::URLMatcherConditionSet; +using url_matcher::URLMatcherFactory; namespace keys = extensions::declarative_content_constants; namespace { -static extensions::URLMatcherConditionSet::ID g_next_id = 0; +static URLMatcherConditionSet::ID g_next_id = 0; // TODO(jyasskin): improve error messaging to give more meaningful messages // to the extension developer. diff --git a/chrome/browser/extensions/api/declarative_content/content_condition.h b/chrome/browser/extensions/api/declarative_content/content_condition.h index 389f301e78ae9f..c7a1db6d7316bd 100644 --- a/chrome/browser/extensions/api/declarative_content/content_condition.h +++ b/chrome/browser/extensions/api/declarative_content/content_condition.h @@ -15,7 +15,7 @@ #include "base/memory/scoped_ptr.h" #include "base/values.h" #include "chrome/browser/extensions/api/declarative/declarative_rule.h" -#include "extensions/common/matcher/url_matcher.h" +#include "components/url_matcher/url_matcher.h" #include "url/gurl.h" namespace extensions { @@ -25,7 +25,7 @@ struct RendererContentMatchData { ~RendererContentMatchData(); // Match IDs for the URL of the top-level page the renderer is // returning data for. - std::set page_url_matches; + std::set page_url_matches; // All watched CSS selectors that match on frames with the same // origin as the page's main frame. base::hash_set css_selectors; @@ -54,7 +54,7 @@ class ContentCondition { typedef RendererContentMatchData MatchData; ContentCondition( - scoped_refptr url_matcher_conditions, + scoped_refptr url_matcher_conditions, const std::vector& css_selectors); ~ContentCondition(); @@ -63,7 +63,7 @@ class ContentCondition { // an instance of declarativeContent.PageStateMatcher. static scoped_ptr Create( const Extension* extension, - URLMatcherConditionFactory* url_matcher_condition_factory, + url_matcher::URLMatcherConditionFactory* url_matcher_condition_factory, const base::Value& condition, std::string* error); @@ -75,13 +75,13 @@ class ContentCondition { // for all URL patterns that need to be matched by this ContentCondition. // This ID is registered in a URLMatcher that can inform us in case of a // match. - URLMatcherConditionSet::ID url_matcher_condition_set_id() const { + url_matcher::URLMatcherConditionSet::ID url_matcher_condition_set_id() const { return url_matcher_conditions_->id(); } // If this Condition has a url filter, appends it to |condition_sets|. void GetURLMatcherConditionSets( - URLMatcherConditionSet::Vector* condition_sets) const { + url_matcher::URLMatcherConditionSet::Vector* condition_sets) const { if (url_matcher_conditions_.get()) condition_sets->push_back(url_matcher_conditions_); } @@ -98,7 +98,7 @@ class ContentCondition { } private: - scoped_refptr url_matcher_conditions_; + scoped_refptr url_matcher_conditions_; std::vector css_selectors_; DISALLOW_COPY_AND_ASSIGN(ContentCondition); diff --git a/chrome/browser/extensions/api/declarative_content/content_condition_unittest.cc b/chrome/browser/extensions/api/declarative_content/content_condition_unittest.cc index f4cdb8ef6ed593..fe0cdcbbc03785 100644 --- a/chrome/browser/extensions/api/declarative_content/content_condition_unittest.cc +++ b/chrome/browser/extensions/api/declarative_content/content_condition_unittest.cc @@ -10,15 +10,17 @@ #include "base/test/values_test_util.h" #include "base/values.h" #include "chrome/browser/extensions/api/declarative_content/content_constants.h" -#include "extensions/common/matcher/url_matcher.h" +#include "components/url_matcher/url_matcher.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" -namespace extensions { -namespace { - using testing::ElementsAre; using testing::HasSubstr; +using url_matcher::URLMatcher; +using url_matcher::URLMatcherConditionSet; + +namespace extensions { +namespace { TEST(DeclarativeContentConditionTest, UnknownConditionName) { URLMatcher matcher; diff --git a/chrome/browser/extensions/api/declarative_content/content_rules_registry.cc b/chrome/browser/extensions/api/declarative_content/content_rules_registry.cc index 4e9a51128fa40d..5c76c37c7a5fbc 100644 --- a/chrome/browser/extensions/api/declarative_content/content_rules_registry.cc +++ b/chrome/browser/extensions/api/declarative_content/content_rules_registry.cc @@ -19,6 +19,8 @@ #include "content/public/browser/render_process_host.h" #include "content/public/browser/web_contents.h" +using url_matcher::URLMatcherConditionSet; + namespace extensions { ContentRulesRegistry::ContentRulesRegistry(Profile* profile, diff --git a/chrome/browser/extensions/api/declarative_content/content_rules_registry.h b/chrome/browser/extensions/api/declarative_content/content_rules_registry.h index c752ebba3f6ff9..9224374a7ee358 100644 --- a/chrome/browser/extensions/api/declarative_content/content_rules_registry.h +++ b/chrome/browser/extensions/api/declarative_content/content_rules_registry.h @@ -18,10 +18,10 @@ #include "chrome/browser/extensions/api/declarative/rules_registry.h" #include "chrome/browser/extensions/api/declarative_content/content_action.h" #include "chrome/browser/extensions/api/declarative_content/content_condition.h" +#include "components/url_matcher/url_matcher.h" #include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_registrar.h" #include "extensions/browser/info_map.h" -#include "extensions/common/matcher/url_matcher.h" class Profile; class ContentPermissions; @@ -116,7 +116,8 @@ class ContentRulesRegistry : public RulesRegistry, // ExtensionMsg_WatchPages. void InstructRenderProcess(content::RenderProcessHost* process); - typedef std::map URLMatcherIdToRule; + typedef std::map + URLMatcherIdToRule; typedef std::map > RulesMap; @@ -131,7 +132,7 @@ class ContentRulesRegistry : public RulesRegistry, std::map > active_rules_; // Matches URLs for the page_url condition. - URLMatcher url_matcher_; + url_matcher::URLMatcher url_matcher_; // All CSS selectors any rule's conditions watch for. std::vector watched_css_selectors_; diff --git a/chrome/browser/extensions/api/declarative_webrequest/webrequest_condition.cc b/chrome/browser/extensions/api/declarative_webrequest/webrequest_condition.cc index 1e1ddec101d5f3..b557633e5503cc 100644 --- a/chrome/browser/extensions/api/declarative_webrequest/webrequest_condition.cc +++ b/chrome/browser/extensions/api/declarative_webrequest/webrequest_condition.cc @@ -12,13 +12,17 @@ #include "chrome/browser/extensions/api/declarative_webrequest/request_stage.h" #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_condition_attribute.h" #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_constants.h" -#include "extensions/common/matcher/url_matcher_factory.h" +#include "components/url_matcher/url_matcher_factory.h" #include "net/url_request/url_request.h" +using url_matcher::URLMatcherConditionFactory; +using url_matcher::URLMatcherConditionSet; +using url_matcher::URLMatcherFactory; + namespace keys = extensions::declarative_webrequest_constants; namespace { -static extensions::URLMatcherConditionSet::ID g_next_id = 0; +static URLMatcherConditionSet::ID g_next_id = 0; // TODO(battre): improve error messaging to give more meaningful messages // to the extension developer. diff --git a/chrome/browser/extensions/api/declarative_webrequest/webrequest_condition.h b/chrome/browser/extensions/api/declarative_webrequest/webrequest_condition.h index a9c935548266ee..5dc15085888f35 100644 --- a/chrome/browser/extensions/api/declarative_webrequest/webrequest_condition.h +++ b/chrome/browser/extensions/api/declarative_webrequest/webrequest_condition.h @@ -14,7 +14,7 @@ #include "base/memory/linked_ptr.h" #include "chrome/browser/extensions/api/declarative/declarative_rule.h" #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_condition_attribute.h" -#include "extensions/common/matcher/url_matcher.h" +#include "components/url_matcher/url_matcher.h" #include "net/http/http_response_headers.h" namespace extensions { @@ -44,8 +44,8 @@ struct WebRequestDataWithMatchIds { ~WebRequestDataWithMatchIds(); const WebRequestData* data; - std::set url_match_ids; - std::set first_party_url_match_ids; + std::set url_match_ids; + std::set first_party_url_match_ids; }; // Representation of a condition in the Declarative WebRequest API. A condition @@ -70,8 +70,9 @@ class WebRequestCondition { typedef WebRequestDataWithMatchIds MatchData; WebRequestCondition( - scoped_refptr url_matcher_conditions, - scoped_refptr first_party_url_matcher_conditions, + scoped_refptr url_matcher_conditions, + scoped_refptr + first_party_url_matcher_conditions, const WebRequestConditionAttributes& condition_attributes); ~WebRequestCondition(); @@ -79,7 +80,7 @@ class WebRequestCondition { // the description |condition| passed by the extension API. static scoped_ptr Create( const Extension* extension, - URLMatcherConditionFactory* url_matcher_condition_factory, + url_matcher::URLMatcherConditionFactory* url_matcher_condition_factory, const base::Value& condition, std::string* error); @@ -88,7 +89,7 @@ class WebRequestCondition { // If this condition has url attributes, appends them to |condition_sets|. void GetURLMatcherConditionSets( - URLMatcherConditionSet::Vector* condition_sets) const; + url_matcher::URLMatcherConditionSet::Vector* condition_sets) const; // Returns a bit vector representing extensions::RequestStage. The bit vector // contains a 1 for each request stage during which the condition can be @@ -97,8 +98,9 @@ class WebRequestCondition { private: // URL attributes of this condition. - scoped_refptr url_matcher_conditions_; - scoped_refptr first_party_url_matcher_conditions_; + scoped_refptr url_matcher_conditions_; + scoped_refptr + first_party_url_matcher_conditions_; // All non-UrlFilter attributes of this condition. WebRequestConditionAttributes condition_attributes_; diff --git a/chrome/browser/extensions/api/declarative_webrequest/webrequest_condition_unittest.cc b/chrome/browser/extensions/api/declarative_webrequest/webrequest_condition_unittest.cc index 38552ad89dac5f..8531a1535734db 100644 --- a/chrome/browser/extensions/api/declarative_webrequest/webrequest_condition_unittest.cc +++ b/chrome/browser/extensions/api/declarative_webrequest/webrequest_condition_unittest.cc @@ -10,16 +10,16 @@ #include "base/test/values_test_util.h" #include "base/values.h" #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_constants.h" +#include "components/url_matcher/url_matcher_constants.h" #include "content/public/browser/resource_request_info.h" -#include "extensions/common/matcher/url_matcher_constants.h" #include "net/base/request_priority.h" #include "net/url_request/url_request_test_util.h" #include "testing/gtest/include/gtest/gtest.h" -namespace extensions { +using url_matcher::URLMatcher; +using url_matcher::URLMatcherConditionSet; -namespace keys = declarative_webrequest_constants; -namespace keys2 = url_matcher_constants; +namespace extensions { TEST(WebRequestConditionTest, CreateCondition) { // Necessary for TestURLRequest. 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 949796ef76e917..8cd1595d114103 100644 --- a/chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_registry.cc +++ b/chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_registry.cc @@ -20,6 +20,8 @@ #include "extensions/common/permissions/permissions_data.h" #include "net/url_request/url_request.h" +using url_matcher::URLMatcherConditionSet; + namespace { const char kActionCannotBeExecuted[] = "The action '*' can never be executed " 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 805b0b24489d37..188beaf85e8942 100644 --- a/chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_registry.h +++ b/chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_registry.h @@ -21,8 +21,8 @@ #include "chrome/browser/extensions/api/declarative_webrequest/request_stage.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/info_map.h" -#include "extensions/common/matcher/url_matcher.h" class Profile; class WebRequestPermissions; @@ -127,10 +127,11 @@ class WebRequestRulesRegistry : public RulesRegistry { FRIEND_TEST_ALL_PREFIXES(WebRequestRulesRegistrySimpleTest, HostPermissionsChecker); - typedef std::map RuleTriggers; + typedef std::map + RuleTriggers; typedef std::map > RulesMap; - typedef std::set URLMatches; + typedef std::set URLMatches; typedef std::set RuleSet; // This bundles all consistency checkers. Returns true in case of consistency @@ -158,9 +159,9 @@ class WebRequestRulesRegistry : public RulesRegistry { // and add every of the rule's URLMatcherConditionSet to // |remove_from_url_matcher|, so that the caller can remove them from the // matcher later. - void CleanUpAfterRule( - const WebRequestRule* rule, - std::vector* remove_from_url_matcher); + void CleanUpAfterRule(const WebRequestRule* rule, + std::vector* + remove_from_url_matcher); // This is a helper function to GetMatches. Rules triggered by |url_matches| // get added to |result| if one of their conditions is fulfilled. @@ -180,7 +181,7 @@ class WebRequestRulesRegistry : public RulesRegistry { std::map webrequest_rules_; - URLMatcher url_matcher_; + url_matcher::URLMatcher url_matcher_; void* profile_id_; scoped_refptr extension_info_map_; diff --git a/chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_registry_unittest.cc b/chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_registry_unittest.cc index 93de526a9dd520..dc0a6fb8ad065f 100644 --- a/chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_registry_unittest.cc +++ b/chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_registry_unittest.cc @@ -17,14 +17,20 @@ #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_constants.h" #include "chrome/browser/extensions/api/web_request/web_request_api_helpers.h" #include "chrome/common/extensions/extension_test_util.h" +#include "components/url_matcher/url_matcher_constants.h" #include "content/public/test/test_browser_thread.h" -#include "extensions/common/matcher/url_matcher_constants.h" #include "net/base/request_priority.h" #include "net/url_request/url_request_test_util.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest-message.h" #include "testing/gtest/include/gtest/gtest.h" +using base::Value; +using extension_test_util::LoadManifest; +using extension_test_util::LoadManifestUnchecked; +using testing::HasSubstr; +using url_matcher::URLMatcher; + namespace { const char kExtensionId[] = "ext1"; const char kExtensionId2[] = "ext2"; @@ -34,17 +40,11 @@ const char kRuleId3[] = "rule3"; const char kRuleId4[] = "rule4"; } // namespace -using extension_test_util::LoadManifest; -using extension_test_util::LoadManifestUnchecked; - namespace extensions { -using base::Value; -using testing::HasSubstr; - namespace helpers = extension_web_request_api_helpers; namespace keys = declarative_webrequest_constants; -namespace keys2 = url_matcher_constants; +namespace keys2 = url_matcher::url_matcher_constants; class TestWebRequestRulesRegistry : public WebRequestRulesRegistry { public: diff --git a/chrome/browser/managed_mode/managed_mode_url_filter.cc b/chrome/browser/managed_mode/managed_mode_url_filter.cc index 174257d6850d50..d60255f5ecb4ee 100644 --- a/chrome/browser/managed_mode/managed_mode_url_filter.cc +++ b/chrome/browser/managed_mode/managed_mode_url_filter.cc @@ -14,17 +14,17 @@ #include "base/task_runner_util.h" #include "base/threading/sequenced_worker_pool.h" #include "chrome/browser/policy/url_blacklist_manager.h" +#include "components/url_matcher/url_matcher.h" #include "content/public/browser/browser_thread.h" -#include "extensions/common/matcher/url_matcher.h" #include "net/base/registry_controlled_domains/registry_controlled_domain.h" #include "url/gurl.h" using content::BrowserThread; -using extensions::URLMatcher; -using extensions::URLMatcherConditionSet; using net::registry_controlled_domains::EXCLUDE_UNKNOWN_REGISTRIES; using net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES; using net::registry_controlled_domains::GetRegistryLength; +using url_matcher::URLMatcher; +using url_matcher::URLMatcherConditionSet; struct ManagedModeURLFilter::Contents { URLMatcher url_matcher; @@ -93,7 +93,7 @@ bool FilterBuilder::AddPattern(const std::string& pattern, int site_id) { return false; } - scoped_refptr condition_set = + scoped_refptr condition_set = policy::URLBlacklist::CreateConditionSet( &contents_->url_matcher, ++matcher_id_, scheme, host, match_subdomains, port, path); diff --git a/chrome/browser/policy/url_blacklist_manager.cc b/chrome/browser/policy/url_blacklist_manager.cc index e4f6db4568cfce..322afa571bba7b 100644 --- a/chrome/browser/policy/url_blacklist_manager.cc +++ b/chrome/browser/policy/url_blacklist_manager.cc @@ -30,12 +30,12 @@ #endif using content::BrowserThread; -using extensions::URLMatcher; -using extensions::URLMatcherCondition; -using extensions::URLMatcherConditionFactory; -using extensions::URLMatcherConditionSet; -using extensions::URLMatcherPortFilter; -using extensions::URLMatcherSchemeFilter; +using url_matcher::URLMatcher; +using url_matcher::URLMatcherCondition; +using url_matcher::URLMatcherConditionFactory; +using url_matcher::URLMatcherConditionSet; +using url_matcher::URLMatcherPortFilter; +using url_matcher::URLMatcherSchemeFilter; namespace policy { @@ -236,9 +236,8 @@ bool URLBlacklist::FilterToComponents(const std::string& filter, } // static -scoped_refptr -URLBlacklist::CreateConditionSet( - extensions::URLMatcher* url_matcher, +scoped_refptr URLBlacklist::CreateConditionSet( + URLMatcher* url_matcher, int id, const std::string& scheme, const std::string& host, diff --git a/chrome/browser/policy/url_blacklist_manager.h b/chrome/browser/policy/url_blacklist_manager.h index f502369e95f961..d7f9423714a771 100644 --- a/chrome/browser/policy/url_blacklist_manager.h +++ b/chrome/browser/policy/url_blacklist_manager.h @@ -15,7 +15,7 @@ #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" #include "base/prefs/pref_change_registrar.h" -#include "extensions/common/matcher/url_matcher.h" +#include "components/url_matcher/url_matcher.h" class GURL; class PrefService; @@ -79,9 +79,9 @@ class URLBlacklist { // Creates a condition set that can be used with the |url_matcher|. |id| needs // to be a unique number that will be returned by the |url_matcher| if the URL // matches that condition set. - static scoped_refptr CreateConditionSet( - extensions::URLMatcher* url_matcher, - extensions::URLMatcherConditionSet::ID id, + static scoped_refptr CreateConditionSet( + url_matcher::URLMatcher* url_matcher, + url_matcher::URLMatcherConditionSet::ID id, const std::string& scheme, const std::string& host, bool match_subdomains, @@ -95,9 +95,9 @@ class URLBlacklist { static bool FilterTakesPrecedence(const FilterComponents& lhs, const FilterComponents& rhs); - extensions::URLMatcherConditionSet::ID id_; - std::map filters_; - scoped_ptr url_matcher_; + url_matcher::URLMatcherConditionSet::ID id_; + std::map filters_; + scoped_ptr url_matcher_; DISALLOW_COPY_AND_ASSIGN(URLBlacklist); }; diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 89984af60713ba..5b1ea1451d8cce 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -2616,6 +2616,7 @@ '../components/components.gyp:dom_distiller_content', '../components/components.gyp:navigation_interception', '../components/components.gyp:sessions', + '../components/components.gyp:url_matcher', '../components/components.gyp:visitedlink_browser', '../components/components.gyp:visitedlink_common', '../components/components.gyp:web_modal', diff --git a/chrome/chrome_browser_extensions.gypi b/chrome/chrome_browser_extensions.gypi index 14524249fcf4af..82951eec37c078 100644 --- a/chrome/chrome_browser_extensions.gypi +++ b/chrome/chrome_browser_extensions.gypi @@ -29,6 +29,7 @@ 'sync_file_system_proto', '../components/component_strings.gyp:component_strings', '../components/components.gyp:onc_component', + '../components/components.gyp:url_matcher', '../components/components.gyp:wifi_component', '../content/content.gyp:content_browser', '../crypto/crypto.gyp:crypto', diff --git a/chrome/chrome_tests_unit.gypi b/chrome/chrome_tests_unit.gypi index 0742aafff1dba3..42a031ed954db7 100644 --- a/chrome/chrome_tests_unit.gypi +++ b/chrome/chrome_tests_unit.gypi @@ -532,11 +532,6 @@ '../extensions/common/id_util_unittest.cc', '../extensions/common/manifest_handler_unittest.cc', '../extensions/common/manifest_handlers/shared_module_manifest_unittest.cc', - '../extensions/common/matcher/regex_set_matcher_unittest.cc', - '../extensions/common/matcher/string_pattern_unittest.cc', - '../extensions/common/matcher/substring_set_matcher_unittest.cc', - '../extensions/common/matcher/url_matcher_factory_unittest.cc', - '../extensions/common/matcher/url_matcher_unittest.cc', '../extensions/common/one_shot_event_unittest.cc', '../extensions/common/permissions/api_permission_set_unittest.cc', '../extensions/common/permissions/manifest_permission_set_unittest.cc', diff --git a/components/components.gyp b/components/components.gyp index 3bd1a2bbf05d7d..47ece66a0d516f 100644 --- a/components/components.gyp +++ b/components/components.gyp @@ -32,6 +32,7 @@ 'navigation_interception.gypi', 'plugins.gypi', 'sessions.gypi', + 'url_matcher.gypi', 'visitedlink.gypi', 'web_contents_delegate_android.gypi', 'web_modal.gypi', diff --git a/components/components_tests.gyp b/components/components_tests.gyp index 294970f20123f0..72b8e52cb37ab1 100644 --- a/components/components_tests.gyp +++ b/components/components_tests.gyp @@ -46,6 +46,11 @@ 'translate/common/translate_metrics_unittest.cc', 'translate/common/translate_util_unittest.cc', 'translate/language_detection/language_detection_util_unittest.cc', + 'url_matcher/regex_set_matcher_unittest.cc', + 'url_matcher/string_pattern_unittest.cc', + 'url_matcher/substring_set_matcher_unittest.cc', + 'url_matcher/url_matcher_factory_unittest.cc', + 'url_matcher/url_matcher_unittest.cc', # TODO(asvitkine): These should be tested on iOS too. 'variations/entropy_provider_unittest.cc', 'variations/metrics_util_unittest.cc', @@ -117,6 +122,9 @@ 'components.gyp:sessions', 'components.gyp:sessions_test_support', + # Dependencies of url_matcher. + 'components.gyp:url_matcher', + # Dependencies of visitedlink 'components.gyp:visitedlink_browser', 'components.gyp:visitedlink_renderer', diff --git a/components/url_matcher.gypi b/components/url_matcher.gypi new file mode 100644 index 00000000000000..34765526db7aad --- /dev/null +++ b/components/url_matcher.gypi @@ -0,0 +1,43 @@ +# Copyright 2013 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. + +{ + 'targets': [ + { + 'target_name': 'url_matcher', + 'type': '<(component)', + 'dependencies': [ + '../base/base.gyp:base', + '../base/third_party/dynamic_annotations/dynamic_annotations.gyp:dynamic_annotations', + '../third_party/re2/re2.gyp:re2', + '../url/url.gyp:url_lib', + ], + 'include_dirs': [ + '..', + ], + 'defines': [ + 'URL_MATCHER_IMPLEMENTATION', + ], + 'sources': [ + 'url_matcher/regex_set_matcher.cc', + 'url_matcher/regex_set_matcher.h', + 'url_matcher/string_pattern.cc', + 'url_matcher/string_pattern.h', + 'url_matcher/substring_set_matcher.cc', + 'url_matcher/substring_set_matcher.h', + 'url_matcher/url_matcher.cc', + 'url_matcher/url_matcher.h', + 'url_matcher/url_matcher_constants.cc', + 'url_matcher/url_matcher_constants.h', + 'url_matcher/url_matcher_export.h', + 'url_matcher/url_matcher_factory.cc', + 'url_matcher/url_matcher_factory.h', + 'url_matcher/url_matcher_helpers.cc', + 'url_matcher/url_matcher_helpers.h', + ], + # Disable c4267 warnings until we fix size_t to int truncations. + 'msvs_disabled_warnings': [ 4267, ], + }, + ], +} diff --git a/components/url_matcher/DEPS b/components/url_matcher/DEPS new file mode 100644 index 00000000000000..0de07bbaf08865 --- /dev/null +++ b/components/url_matcher/DEPS @@ -0,0 +1,3 @@ +include_rules = [ + "+third_party/re2", +] diff --git a/extensions/common/matcher/OWNERS b/components/url_matcher/OWNERS similarity index 100% rename from extensions/common/matcher/OWNERS rename to components/url_matcher/OWNERS diff --git a/extensions/common/matcher/regex_set_matcher.cc b/components/url_matcher/regex_set_matcher.cc similarity index 93% rename from extensions/common/matcher/regex_set_matcher.cc rename to components/url_matcher/regex_set_matcher.cc index 24d99efa3ff488..c0b977cc4ee7cd 100644 --- a/extensions/common/matcher/regex_set_matcher.cc +++ b/components/url_matcher/regex_set_matcher.cc @@ -1,17 +1,17 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2013 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/common/matcher/regex_set_matcher.h" +#include "components/url_matcher/regex_set_matcher.h" #include "base/logging.h" #include "base/stl_util.h" #include "base/strings/string_util.h" -#include "extensions/common/matcher/substring_set_matcher.h" +#include "components/url_matcher/substring_set_matcher.h" #include "third_party/re2/re2/filtered_re2.h" #include "third_party/re2/re2/re2.h" -namespace extensions { +namespace url_matcher { RegexSetMatcher::RegexSetMatcher() {} @@ -110,4 +110,4 @@ void RegexSetMatcher::DeleteSubstringPatterns() { STLDeleteElements(&substring_patterns_); } -} // namespace extensions +} // namespace url_matcher diff --git a/extensions/common/matcher/regex_set_matcher.h b/components/url_matcher/regex_set_matcher.h similarity index 82% rename from extensions/common/matcher/regex_set_matcher.h rename to components/url_matcher/regex_set_matcher.h index 906ab9ca3eeb30..e4eb1dc052f1e0 100644 --- a/extensions/common/matcher/regex_set_matcher.h +++ b/components/url_matcher/regex_set_matcher.h @@ -1,9 +1,9 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2013 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. -#ifndef EXTENSIONS_COMMON_MATCHER_REGEX_SET_MATCHER_H_ -#define EXTENSIONS_COMMON_MATCHER_REGEX_SET_MATCHER_H_ +#ifndef COMPONENTS_URL_MATCHER_REGEX_SET_MATCHER_H_ +#define COMPONENTS_URL_MATCHER_REGEX_SET_MATCHER_H_ #include #include @@ -11,20 +11,21 @@ #include #include "base/memory/scoped_ptr.h" -#include "extensions/common/matcher/string_pattern.h" -#include "extensions/common/matcher/substring_set_matcher.h" +#include "components/url_matcher/string_pattern.h" +#include "components/url_matcher/substring_set_matcher.h" +#include "components/url_matcher/url_matcher_export.h" namespace re2 { class FilteredRE2; } -namespace extensions { +namespace url_matcher { // Efficiently matches URLs against a collection of regular expressions, // using FilteredRE2 to reduce the number of regexes that must be matched // by pre-filtering with substring matching. See: // http://swtch.com/~rsc/regexp/regexp3.html#analysis -class RegexSetMatcher { +class URL_MATCHER_EXPORT RegexSetMatcher { public: RegexSetMatcher(); virtual ~RegexSetMatcher(); @@ -77,6 +78,6 @@ class RegexSetMatcher { std::vector substring_patterns_; }; -} // namespace extensions +} // namespace url_matcher -#endif // EXTENSIONS_COMMON_MATCHER_REGEX_SET_MATCHER_H_ +#endif // COMPONENTS_URL_MATCHER_REGEX_SET_MATCHER_H_ diff --git a/extensions/common/matcher/regex_set_matcher_unittest.cc b/components/url_matcher/regex_set_matcher_unittest.cc similarity index 90% rename from extensions/common/matcher/regex_set_matcher_unittest.cc rename to components/url_matcher/regex_set_matcher_unittest.cc index 49d312a14017db..dd54e51d2fbb19 100644 --- a/extensions/common/matcher/regex_set_matcher_unittest.cc +++ b/components/url_matcher/regex_set_matcher_unittest.cc @@ -1,17 +1,16 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2013 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/common/matcher/regex_set_matcher.h" +#include "components/url_matcher/regex_set_matcher.h" #include #include "base/stl_util.h" -#include "url/gurl.h" #include "testing/gtest/include/gtest/gtest.h" +#include "url/gurl.h" -using extensions::StringPattern; -using extensions::RegexSetMatcher; +namespace url_matcher { TEST(RegexSetMatcherTest, MatchRegexes) { StringPattern pattern_1("ab.*c", 42); @@ -59,3 +58,5 @@ TEST(RegexSetMatcherTest, CaseSensitivity) { EXPECT_EQ(1U, result2.size()); EXPECT_TRUE(ContainsKey(result2, 57)); } + +} // namespace url_matcher diff --git a/extensions/common/matcher/string_pattern.cc b/components/url_matcher/string_pattern.cc similarity index 71% rename from extensions/common/matcher/string_pattern.cc rename to components/url_matcher/string_pattern.cc index 4e5c350c45a321..d103bced3e255d 100644 --- a/extensions/common/matcher/string_pattern.cc +++ b/components/url_matcher/string_pattern.cc @@ -1,10 +1,10 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2013 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/common/matcher/string_pattern.h" +#include "components/url_matcher/string_pattern.h" -namespace extensions { +namespace url_matcher { StringPattern::StringPattern(const std::string& pattern, StringPattern::ID id) @@ -17,4 +17,4 @@ bool StringPattern::operator<(const StringPattern& rhs) const { return pattern_ < rhs.pattern_; } -} // namespace extensions +} // namespace url_matcher diff --git a/extensions/common/matcher/string_pattern.h b/components/url_matcher/string_pattern.h similarity index 71% rename from extensions/common/matcher/string_pattern.h rename to components/url_matcher/string_pattern.h index 1781b032833097..ca5f223ec6f5a3 100644 --- a/extensions/common/matcher/string_pattern.h +++ b/components/url_matcher/string_pattern.h @@ -1,16 +1,17 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2013 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. -#ifndef EXTENSIONS_COMMON_MATCHER_STRING_PATTERN_H_ -#define EXTENSIONS_COMMON_MATCHER_STRING_PATTERN_H_ +#ifndef COMPONENTS_URL_MATCHER_STRING_PATTERN_H_ +#define COMPONENTS_URL_MATCHER_STRING_PATTERN_H_ #include #include #include "base/basictypes.h" +#include "components/url_matcher/url_matcher_export.h" -namespace extensions { +namespace url_matcher { // An individual pattern of a substring or regex matcher. A pattern consists of // a string (interpreted as individual bytes, no character encoding) and an @@ -19,7 +20,7 @@ namespace extensions { // RegexMatcher::MatchURL() to help the caller to figure out what // patterns matched a string. All patterns registered to a matcher // need to contain unique IDs. -class StringPattern { +class URL_MATCHER_EXPORT StringPattern { public: typedef int ID; @@ -37,6 +38,6 @@ class StringPattern { DISALLOW_COPY_AND_ASSIGN(StringPattern); }; -} // namespace extensions +} // namespace url_matcher -#endif // EXTENSIONS_COMMON_MATCHER_STRING_PATTERN_H_ +#endif // COMPONENTS_URL_MATCHER_STRING_PATTERN_H_ diff --git a/extensions/common/matcher/string_pattern_unittest.cc b/components/url_matcher/string_pattern_unittest.cc similarity index 73% rename from extensions/common/matcher/string_pattern_unittest.cc rename to components/url_matcher/string_pattern_unittest.cc index 6e7e4bfbcfeadf..460f431fc6f0eb 100644 --- a/extensions/common/matcher/string_pattern_unittest.cc +++ b/components/url_matcher/string_pattern_unittest.cc @@ -1,14 +1,14 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2013 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/common/matcher/string_pattern.h" +#include "components/url_matcher/string_pattern.h" #include #include "testing/gtest/include/gtest/gtest.h" -using extensions::StringPattern; +namespace url_matcher { TEST(StringPatternTest, StringPattern) { StringPattern r1("Test", 2); @@ -21,3 +21,5 @@ TEST(StringPatternTest, StringPattern) { StringPattern r3("ZZZZ", 2); EXPECT_TRUE(r1 < r3); } + +} // namespace url_matcher diff --git a/extensions/common/matcher/substring_set_matcher.cc b/components/url_matcher/substring_set_matcher.cc similarity index 97% rename from extensions/common/matcher/substring_set_matcher.cc rename to components/url_matcher/substring_set_matcher.cc index 91ac718b04c132..9669788152cc72 100644 --- a/extensions/common/matcher/substring_set_matcher.cc +++ b/components/url_matcher/substring_set_matcher.cc @@ -1,8 +1,8 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2013 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/common/matcher/substring_set_matcher.h" +#include "components/url_matcher/substring_set_matcher.h" #include #include @@ -10,7 +10,7 @@ #include "base/logging.h" #include "base/stl_util.h" -namespace extensions { +namespace url_matcher { namespace { @@ -269,4 +269,4 @@ void SubstringSetMatcher::AhoCorasickNode::AddMatches( matches_.insert(matches.begin(), matches.end()); } -} // namespace extensions +} // namespace url_matcher diff --git a/extensions/common/matcher/substring_set_matcher.h b/components/url_matcher/substring_set_matcher.h similarity index 92% rename from extensions/common/matcher/substring_set_matcher.h rename to components/url_matcher/substring_set_matcher.h index 610efc0fc22a27..8a05ef30f26e4c 100644 --- a/extensions/common/matcher/substring_set_matcher.h +++ b/components/url_matcher/substring_set_matcher.h @@ -1,9 +1,9 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2013 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. -#ifndef EXTENSIONS_COMMON_MATCHER_SUBSTRING_SET_MATCHER_H_ -#define EXTENSIONS_COMMON_MATCHER_SUBSTRING_SET_MATCHER_H_ +#ifndef COMPONENTS_URL_MATCHER_SUBSTRING_SET_MATCHER_H_ +#define COMPONENTS_URL_MATCHER_SUBSTRING_SET_MATCHER_H_ #include #include @@ -12,13 +12,14 @@ #include #include "base/basictypes.h" -#include "extensions/common/matcher/string_pattern.h" +#include "components/url_matcher/string_pattern.h" +#include "components/url_matcher/url_matcher_export.h" -namespace extensions { +namespace url_matcher { // Class that store a set of string patterns and can find for a string S, // which string patterns occur in S. -class SubstringSetMatcher { +class URL_MATCHER_EXPORT SubstringSetMatcher { public: SubstringSetMatcher(); ~SubstringSetMatcher(); @@ -135,6 +136,6 @@ class SubstringSetMatcher { DISALLOW_COPY_AND_ASSIGN(SubstringSetMatcher); }; -} // namespace extensions +} // namespace url_matcher -#endif // EXTENSIONS_COMMON_MATCHER_SUBSTRING_SET_MATCHER_H_ +#endif // COMPONENTS_URL_MATCHER_SUBSTRING_SET_MATCHER_H_ diff --git a/extensions/common/matcher/substring_set_matcher_unittest.cc b/components/url_matcher/substring_set_matcher_unittest.cc similarity index 96% rename from extensions/common/matcher/substring_set_matcher_unittest.cc rename to components/url_matcher/substring_set_matcher_unittest.cc index fde65bf2dca1e6..f5f2be00c407ee 100644 --- a/extensions/common/matcher/substring_set_matcher_unittest.cc +++ b/components/url_matcher/substring_set_matcher_unittest.cc @@ -1,8 +1,8 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2013 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/common/matcher/substring_set_matcher.h" +#include "components/url_matcher/substring_set_matcher.h" #include #include @@ -10,10 +10,10 @@ #include "testing/gtest/include/gtest/gtest.h" -using extensions::StringPattern; -using extensions::SubstringSetMatcher; +namespace url_matcher { namespace { + void TestOnePattern(const std::string& test_string, const std::string& pattern, bool is_match) { @@ -65,7 +65,8 @@ void TestTwoPatterns(const std::string& test_string, EXPECT_EQ(is_match_2, matches.find(2) != matches.end()) << test; } } -} + +} // namespace TEST(SubstringSetMatcherTest, TestMatcher) { // Test overlapping patterns @@ -165,3 +166,5 @@ TEST(SubstringSetMatcherTest, TestEmptyMatcher) { matcher.Match("abd", &matches); EXPECT_TRUE(matches.empty()); } + +} // namespace url_matcher diff --git a/extensions/common/matcher/url_matcher.cc b/components/url_matcher/url_matcher.cc similarity index 99% rename from extensions/common/matcher/url_matcher.cc rename to components/url_matcher/url_matcher.cc index 5a1d876cc6b8fa..de8632d730e4aa 100644 --- a/extensions/common/matcher/url_matcher.cc +++ b/components/url_matcher/url_matcher.cc @@ -1,18 +1,17 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2013 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/common/matcher/url_matcher.h" +#include "components/url_matcher/url_matcher.h" #include #include #include "base/logging.h" -#include "content/public/common/url_constants.h" #include "url/gurl.h" #include "url/url_canon.h" -namespace extensions { +namespace url_matcher { // This set of classes implement a mapping of URL Component Patterns, such as // host_prefix, host_suffix, host_equals, ..., etc., to StringPatterns @@ -878,4 +877,4 @@ void URLMatcher::UpdateInternalDatastructures() { UpdateConditionFactory(); } -} // namespace extensions +} // namespace url_matcher diff --git a/extensions/common/matcher/url_matcher.h b/components/url_matcher/url_matcher.h similarity index 94% rename from extensions/common/matcher/url_matcher.h rename to components/url_matcher/url_matcher.h index d93a60670130f9..53c393a9d736ec 100644 --- a/extensions/common/matcher/url_matcher.h +++ b/components/url_matcher/url_matcher.h @@ -1,9 +1,9 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2013 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. -#ifndef EXTENSIONS_COMMON_MATCHER_URL_MATCHER_H_ -#define EXTENSIONS_COMMON_MATCHER_URL_MATCHER_H_ +#ifndef COMPONENTS_URL_MATCHER_URL_MATCHER_H_ +#define COMPONENTS_URL_MATCHER_URL_MATCHER_H_ #include #include @@ -11,8 +11,9 @@ #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" #include "base/memory/scoped_vector.h" -#include "extensions/common/matcher/regex_set_matcher.h" -#include "extensions/common/matcher/substring_set_matcher.h" +#include "components/url_matcher/regex_set_matcher.h" +#include "components/url_matcher/substring_set_matcher.h" +#include "components/url_matcher/url_matcher_export.h" class GURL; @@ -20,7 +21,7 @@ namespace base { class DictionaryValue; } -namespace extensions { +namespace url_matcher { // This class represents a single URL matching condition, e.g. a match on the // host suffix or the containment of a string in the query component of a GURL. @@ -31,7 +32,7 @@ namespace extensions { // URLMatcherConditionFactory is not capable of expressing that alone. // // Also supported is matching regular expressions against the URL (URL_MATCHES). -class URLMatcherCondition { +class URL_MATCHER_EXPORT URLMatcherCondition { public: enum Criterion { HOST_PREFIX, @@ -116,7 +117,7 @@ class URLMatcherCondition { // IMPORTANT: The URLMatcherConditionFactory owns the StringPattern // referenced by created URLMatcherConditions. Therefore, it must outlive // all created URLMatcherCondition and the SubstringSetMatcher. -class URLMatcherConditionFactory { +class URL_MATCHER_EXPORT URLMatcherConditionFactory { public: URLMatcherConditionFactory(); ~URLMatcherConditionFactory(); @@ -214,7 +215,7 @@ class URLMatcherConditionFactory { // This class represents a filter for the URL scheme to be hooked up into a // URLMatcherConditionSet. -class URLMatcherSchemeFilter { +class URL_MATCHER_EXPORT URLMatcherSchemeFilter { public: explicit URLMatcherSchemeFilter(const std::string& filter); explicit URLMatcherSchemeFilter(const std::vector& filters); @@ -229,7 +230,7 @@ class URLMatcherSchemeFilter { // This class represents a filter for port numbers to be hooked up into a // URLMatcherConditionSet. -class URLMatcherPortFilter { +class URL_MATCHER_EXPORT URLMatcherPortFilter { public: // Boundaries of a port range (both ends are included). typedef std::pair Range; @@ -250,7 +251,8 @@ class URLMatcherPortFilter { // This class represents a set of conditions that all need to match on a // given URL in order to be considered a match. -class URLMatcherConditionSet : public base::RefCounted { +class URL_MATCHER_EXPORT URLMatcherConditionSet + : public base::RefCounted { public: typedef int ID; typedef std::set Conditions; @@ -285,7 +287,7 @@ class URLMatcherConditionSet : public base::RefCounted { // This class allows matching one URL against a large set of // URLMatcherConditionSets at the same time. -class URLMatcher { +class URL_MATCHER_EXPORT URLMatcher { public: URLMatcher(); ~URLMatcher(); @@ -350,6 +352,6 @@ class URLMatcher { DISALLOW_COPY_AND_ASSIGN(URLMatcher); }; -} // namespace extensions +} // namespace url_matcher -#endif // EXTENSIONS_COMMON_MATCHER_URL_MATCHER_H_ +#endif // COMPONENTS_URL_MATCHER_URL_MATCHER_H_ diff --git a/extensions/common/matcher/url_matcher_constants.cc b/components/url_matcher/url_matcher_constants.cc similarity index 87% rename from extensions/common/matcher/url_matcher_constants.cc rename to components/url_matcher/url_matcher_constants.cc index 5b23dea09ae433..6c2c43dfaa2f3b 100644 --- a/extensions/common/matcher/url_matcher_constants.cc +++ b/components/url_matcher/url_matcher_constants.cc @@ -1,10 +1,10 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2013 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/common/matcher/url_matcher_constants.h" +#include "components/url_matcher/url_matcher_constants.h" -namespace extensions { +namespace url_matcher { namespace url_matcher_constants { // Keys of dictionaries for URL constraints @@ -31,4 +31,4 @@ const char kURLPrefixKey[] = "urlPrefix"; const char kURLSuffixKey[] = "urlSuffix"; } // namespace url_matcher_constants -} // namespace extensions +} // namespace url_matcher diff --git a/components/url_matcher/url_matcher_constants.h b/components/url_matcher/url_matcher_constants.h new file mode 100644 index 00000000000000..2f8e18a3230bd9 --- /dev/null +++ b/components/url_matcher/url_matcher_constants.h @@ -0,0 +1,41 @@ +// Copyright 2013 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. + +// Constants used for the URLMatcher component of the Declarative API. + +#ifndef COMPONENTS_URL_MATCHER_URL_MATCHER_CONSTANTS_H_ +#define COMPONENTS_URL_MATCHER_URL_MATCHER_CONSTANTS_H_ + +#include "components/url_matcher/url_matcher_export.h" + +namespace url_matcher { +namespace url_matcher_constants { + +// Keys of dictionaries for URL constraints +URL_MATCHER_EXPORT extern const char kPortsKey[]; +URL_MATCHER_EXPORT extern const char kSchemesKey[]; +URL_MATCHER_EXPORT extern const char kHostContainsKey[]; +URL_MATCHER_EXPORT extern const char kHostEqualsKey[]; +URL_MATCHER_EXPORT extern const char kHostPrefixKey[]; +URL_MATCHER_EXPORT extern const char kHostSuffixKey[]; +URL_MATCHER_EXPORT extern const char kHostSuffixPathPrefixKey[]; +URL_MATCHER_EXPORT extern const char kOriginAndPathMatchesKey[]; +URL_MATCHER_EXPORT extern const char kPathContainsKey[]; +URL_MATCHER_EXPORT extern const char kPathEqualsKey[]; +URL_MATCHER_EXPORT extern const char kPathPrefixKey[]; +URL_MATCHER_EXPORT extern const char kPathSuffixKey[]; +URL_MATCHER_EXPORT extern const char kQueryContainsKey[]; +URL_MATCHER_EXPORT extern const char kQueryEqualsKey[]; +URL_MATCHER_EXPORT extern const char kQueryPrefixKey[]; +URL_MATCHER_EXPORT extern const char kQuerySuffixKey[]; +URL_MATCHER_EXPORT extern const char kURLContainsKey[]; +URL_MATCHER_EXPORT extern const char kURLEqualsKey[]; +URL_MATCHER_EXPORT extern const char kURLMatchesKey[]; +URL_MATCHER_EXPORT extern const char kURLPrefixKey[]; +URL_MATCHER_EXPORT extern const char kURLSuffixKey[]; + +} // namespace url_matcher_constants +} // namespace url_matcher + +#endif // COMPONENTS_URL_MATCHER_URL_MATCHER_CONSTANTS_H_ diff --git a/components/url_matcher/url_matcher_export.h b/components/url_matcher/url_matcher_export.h new file mode 100644 index 00000000000000..82a0181250d136 --- /dev/null +++ b/components/url_matcher/url_matcher_export.h @@ -0,0 +1,29 @@ +// Copyright 2013 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. + +#ifndef COMPONENTS_URL_MATCHER_URL_MATCHER_EXPORT_H_ +#define COMPONENTS_URL_MATCHER_URL_MATCHER_EXPORT_H_ + +#if defined(COMPONENT_BUILD) +#if defined(WIN32) + +#if defined(URL_MATCHER_IMPLEMENTATION) +#define URL_MATCHER_EXPORT __declspec(dllexport) +#else +#define URL_MATCHER_EXPORT __declspec(dllimport) +#endif // defined(BASE_PREFS_IMPLEMENTATION) + +#else // defined(WIN32) +#if defined(URL_MATCHER_IMPLEMENTATION) +#define URL_MATCHER_EXPORT __attribute__((visibility("default"))) +#else +#define URL_MATCHER_EXPORT +#endif +#endif + +#else // defined(COMPONENT_BUILD) +#define URL_MATCHER_EXPORT +#endif + +#endif // COMPONENTS_URL_MATCHER_URL_MATCHER_EXPORT_H_ diff --git a/extensions/common/matcher/url_matcher_factory.cc b/components/url_matcher/url_matcher_factory.cc similarity index 83% rename from extensions/common/matcher/url_matcher_factory.cc rename to components/url_matcher/url_matcher_factory.cc index 6eec2e6ab12e54..ab1c365439970e 100644 --- a/extensions/common/matcher/url_matcher_factory.cc +++ b/components/url_matcher/url_matcher_factory.cc @@ -1,8 +1,8 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2013 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/common/matcher/url_matcher_factory.h" +#include "components/url_matcher/url_matcher_factory.h" #include #include @@ -11,34 +11,36 @@ #include "base/logging.h" #include "base/strings/stringprintf.h" #include "base/values.h" -#include "extensions/common/error_utils.h" -#include "extensions/common/matcher/url_matcher_constants.h" -#include "extensions/common/matcher/url_matcher_helpers.h" +#include "components/url_matcher/url_matcher_constants.h" +#include "components/url_matcher/url_matcher_helpers.h" #include "third_party/re2/re2/re2.h" -namespace helpers = extensions::url_matcher_helpers; -namespace keys = extensions::url_matcher_constants; +namespace url_matcher { + +namespace helpers = url_matcher_helpers; +namespace keys = url_matcher_constants; namespace { + // Error messages: const char kInvalidPortRanges[] = "Invalid port ranges in UrlFilter."; const char kVectorOfStringsExpected[] = - "UrlFilter attribute '*' expected a vector of strings as parameter."; + "UrlFilter attribute '%s' expected a vector of strings as parameter."; const char kUnknownURLFilterAttribute[] = - "Unknown attribute '*' in UrlFilter."; + "Unknown attribute '%s' in UrlFilter."; const char kAttributeExpectedString[] = - "UrlFilter attribute '*' expected a string value."; + "UrlFilter attribute '%s' expected a string value."; const char kUnparseableRegexString[] = - "Could not parse regular expression '*': *"; -const char kLowerCaseExpected[] = "* values need to be in lower case."; + "Could not parse regular expression '%s': %s"; +const char kLowerCaseExpected[] = "%s values need to be in lower case."; -// Registry for all factory methods of extensions::URLMatcherConditionFactory +// Registry for all factory methods of URLMatcherConditionFactory // that allows translating string literals from the extension API into // the corresponding factory method to be called. class URLMatcherConditionFactoryMethods { public: URLMatcherConditionFactoryMethods() { - typedef extensions::URLMatcherConditionFactory F; + typedef URLMatcherConditionFactory F; factory_methods_[keys::kHostContainsKey] = &F::CreateHostContainsCondition; factory_methods_[keys::kHostEqualsKey] = &F::CreateHostEqualsCondition; factory_methods_[keys::kHostPrefixKey] = &F::CreateHostPrefixCondition; @@ -72,8 +74,8 @@ class URLMatcherConditionFactoryMethods { // |pattern_value| (e.g. "example.com"). // The |pattern_type| needs to be known to this class (see Contains()) or // a CHECK is triggered. - extensions::URLMatcherCondition Call( - extensions::URLMatcherConditionFactory* url_matcher_condition_factory, + URLMatcherCondition Call( + URLMatcherConditionFactory* url_matcher_condition_factory, const std::string& pattern_type, const std::string& pattern_value) const { FactoryMethods::const_iterator i = factory_methods_.find(pattern_type); @@ -83,8 +85,8 @@ class URLMatcherConditionFactoryMethods { } private: - typedef extensions::URLMatcherCondition - (extensions::URLMatcherConditionFactory::* FactoryMethod) + typedef URLMatcherCondition + (URLMatcherConditionFactory::* FactoryMethod) (const std::string& prefix); typedef std::map FactoryMethods; @@ -98,8 +100,6 @@ static base::LazyInstance } // namespace -namespace extensions { - // static scoped_refptr URLMatcherFactory::CreateFromURLFilterDictionary( @@ -140,9 +140,8 @@ URLMatcherFactory::CreateFromURLFilterDictionary( return scoped_refptr(NULL); } else { // Handle unknown attributes. - *error = ErrorUtils::FormatErrorMessage( - kUnknownURLFilterAttribute, - condition_attribute_name); + *error = base::StringPrintf(kUnknownURLFilterAttribute, + condition_attribute_name.c_str()); return scoped_refptr(NULL); } } @@ -187,8 +186,8 @@ URLMatcherCondition URLMatcherFactory::CreateURLMatcherCondition( std::string* error) { std::string str_value; if (!value->GetAsString(&str_value)) { - *error = ErrorUtils::FormatErrorMessage(kAttributeExpectedString, - condition_attribute_name); + *error = base::StringPrintf(kAttributeExpectedString, + condition_attribute_name.c_str()); return URLMatcherCondition(); } if (condition_attribute_name == keys::kHostContainsKey || @@ -196,8 +195,7 @@ URLMatcherCondition URLMatcherFactory::CreateURLMatcherCondition( condition_attribute_name == keys::kHostSuffixKey || condition_attribute_name == keys::kHostEqualsKey) { if (ContainsUpperCase(str_value)) { - *error = ErrorUtils::FormatErrorMessage(kLowerCaseExpected, - "Host"); + *error = base::StringPrintf(kLowerCaseExpected, "Host"); return URLMatcherCondition(); } } @@ -207,8 +205,8 @@ URLMatcherCondition URLMatcherFactory::CreateURLMatcherCondition( condition_attribute_name == keys::kOriginAndPathMatchesKey) { re2::RE2 regex(str_value); if (!regex.ok()) { - *error = ErrorUtils::FormatErrorMessage(kUnparseableRegexString, - str_value, regex.error()); + *error = base::StringPrintf( + kUnparseableRegexString, str_value.c_str(), regex.error().c_str()); return URLMatcherCondition(); } } @@ -222,15 +220,13 @@ scoped_ptr URLMatcherFactory::CreateURLMatcherScheme( std::string* error) { std::vector schemas; if (!helpers::GetAsStringVector(value, &schemas)) { - *error = ErrorUtils::FormatErrorMessage(kVectorOfStringsExpected, - keys::kSchemesKey); + *error = base::StringPrintf(kVectorOfStringsExpected, keys::kSchemesKey); return scoped_ptr(); } for (std::vector::const_iterator it = schemas.begin(); it != schemas.end(); ++it) { if (ContainsUpperCase(*it)) { - *error = ErrorUtils::FormatErrorMessage(kLowerCaseExpected, - "Scheme"); + *error = base::StringPrintf(kLowerCaseExpected, "Scheme"); return scoped_ptr(); } } @@ -274,4 +270,4 @@ scoped_ptr URLMatcherFactory::CreateURLMatcherPorts( return scoped_ptr(new URLMatcherPortFilter(ranges)); } -} // namespace extensions +} // namespace url_matcher diff --git a/extensions/common/matcher/url_matcher_factory.h b/components/url_matcher/url_matcher_factory.h similarity index 81% rename from extensions/common/matcher/url_matcher_factory.h rename to components/url_matcher/url_matcher_factory.h index 7c5be6832d87ae..93ff2025b75655 100644 --- a/extensions/common/matcher/url_matcher_factory.h +++ b/components/url_matcher/url_matcher_factory.h @@ -1,23 +1,24 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2013 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. -#ifndef EXTENSIONS_COMMON_MATCHER_URL_MATCHER_FACTORY_H_ -#define EXTENSIONS_COMMON_MATCHER_URL_MATCHER_FACTORY_H_ +#ifndef COMPONENTS_URL_MATCHER_URL_MATCHER_FACTORY_H_ +#define COMPONENTS_URL_MATCHER_URL_MATCHER_FACTORY_H_ #include #include "base/basictypes.h" -#include "extensions/common/matcher/url_matcher.h" +#include "components/url_matcher/url_matcher.h" +#include "components/url_matcher/url_matcher_export.h" namespace base { class DictionaryValue; class Value; } -namespace extensions { +namespace url_matcher { -class URLMatcherFactory { +class URL_MATCHER_EXPORT URLMatcherFactory { public: // Creates a URLMatcherConditionSet from a UrlFilter dictionary as defined in // the declarative API. |url_fetcher_dict| contains the dictionary passed @@ -57,6 +58,6 @@ class URLMatcherFactory { DISALLOW_IMPLICIT_CONSTRUCTORS(URLMatcherFactory); }; -} // namespace extensions +} // namespace url_matcher -#endif // EXTENSIONS_COMMON_MATCHER_URL_MATCHER_FACTORY_H_ +#endif // COMPONENTS_URL_MATCHER_URL_MATCHER_FACTORY_H_ diff --git a/extensions/common/matcher/url_matcher_factory_unittest.cc b/components/url_matcher/url_matcher_factory_unittest.cc similarity index 98% rename from extensions/common/matcher/url_matcher_factory_unittest.cc rename to components/url_matcher/url_matcher_factory_unittest.cc index 733e1b8a941712..9d6632e06ee18c 100644 --- a/extensions/common/matcher/url_matcher_factory_unittest.cc +++ b/components/url_matcher/url_matcher_factory_unittest.cc @@ -1,18 +1,18 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2013 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/common/matcher/url_matcher_factory.h" +#include "components/url_matcher/url_matcher_factory.h" #include "base/basictypes.h" #include "base/format_macros.h" #include "base/strings/stringprintf.h" #include "base/values.h" -#include "extensions/common/matcher/url_matcher_constants.h" +#include "components/url_matcher/url_matcher_constants.h" #include "testing/gtest/include/gtest/gtest.h" #include "url/gurl.h" -namespace extensions { +namespace url_matcher { namespace keys = url_matcher_constants; @@ -336,4 +336,4 @@ TEST(URLMatcherFactoryTest, CaseSensitivity) { } } -} // namespace extensions +} // namespace url_matcher diff --git a/extensions/common/matcher/url_matcher_helpers.cc b/components/url_matcher/url_matcher_helpers.cc similarity index 80% rename from extensions/common/matcher/url_matcher_helpers.cc rename to components/url_matcher/url_matcher_helpers.cc index e4832cc18ac7fb..61358e7e3dfad6 100644 --- a/extensions/common/matcher/url_matcher_helpers.cc +++ b/components/url_matcher/url_matcher_helpers.cc @@ -1,12 +1,12 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2013 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/common/matcher/url_matcher_helpers.h" +#include "components/url_matcher/url_matcher_helpers.h" #include "base/values.h" -namespace extensions { +namespace url_matcher { namespace url_matcher_helpers { // Converts a ValueList |value| of strings into a vector. Returns true if @@ -28,4 +28,4 @@ bool GetAsStringVector(const base::Value* value, } } // namespace url_matcher_helpers -} // namespace extensions +} // namespace url_matcher diff --git a/extensions/common/matcher/url_matcher_helpers.h b/components/url_matcher/url_matcher_helpers.h similarity index 57% rename from extensions/common/matcher/url_matcher_helpers.h rename to components/url_matcher/url_matcher_helpers.h index 57bd2997cee608..15aa0c5be1a301 100644 --- a/extensions/common/matcher/url_matcher_helpers.h +++ b/components/url_matcher/url_matcher_helpers.h @@ -1,11 +1,11 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2013 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 URLMatcher and Declarative APIs. -#ifndef EXTENSIONS_COMMON_MATCHER_URL_MATCHER_HELPERS_H_ -#define EXTENSIONS_COMMON_MATCHER_URL_MATCHER_HELPERS_H_ +#ifndef COMPONENTS_URL_MATCHER_URL_MATCHER_HELPERS_H_ +#define COMPONENTS_URL_MATCHER_URL_MATCHER_HELPERS_H_ #include #include @@ -14,14 +14,14 @@ namespace base { class Value; } -namespace extensions { +namespace url_matcher { namespace url_matcher_helpers { // Converts a ValueList |value| of strings into a vector. Returns true if // successful. bool GetAsStringVector(const base::Value* value, std::vector* out); -} // namespace declarative_helpers -} // namespace extensions +} // namespace url_matcher_helpers +} // namespace url_matcher -#endif // EXTENSIONS_COMMON_MATCHER_URL_MATCHER_HELPERS_H_ +#endif // COMPONENTS_URL_MATCHER_URL_MATCHER_HELPERS_H_ diff --git a/extensions/common/matcher/url_matcher_unittest.cc b/components/url_matcher/url_matcher_unittest.cc similarity index 99% rename from extensions/common/matcher/url_matcher_unittest.cc rename to components/url_matcher/url_matcher_unittest.cc index 29b7c890dfdc45..748d3101352d9e 100644 --- a/extensions/common/matcher/url_matcher_unittest.cc +++ b/components/url_matcher/url_matcher_unittest.cc @@ -1,14 +1,14 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2013 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/common/matcher/url_matcher.h" +#include "components/url_matcher/url_matcher.h" #include "base/strings/string_util.h" #include "testing/gtest/include/gtest/gtest.h" #include "url/gurl.h" -namespace extensions { +namespace url_matcher { // // URLMatcherCondition @@ -679,4 +679,4 @@ TEST(URLMatcherTest, TestOriginAndPathRegExNegative) { EXPECT_EQ(0u, matcher.MatchURL(url).size()); } -} // namespace extensions +} // namespace url_matcher diff --git a/extensions/DEPS b/extensions/DEPS index f286a2e6096979..898a76b883488a 100644 --- a/extensions/DEPS +++ b/extensions/DEPS @@ -1,4 +1,5 @@ include_rules = [ + "+components/url_matcher", "+content/public/common", "+crypto", "+testing", diff --git a/extensions/common/event_filter.cc b/extensions/common/event_filter.cc index 70915b976d0546..ad954c95103123 100644 --- a/extensions/common/event_filter.cc +++ b/extensions/common/event_filter.cc @@ -4,9 +4,13 @@ #include "extensions/common/event_filter.h" -#include "extensions/common/matcher/url_matcher_factory.h" +#include "components/url_matcher/url_matcher_factory.h" #include "ipc/ipc_message.h" +using url_matcher::URLMatcher; +using url_matcher::URLMatcherConditionSet; +using url_matcher::URLMatcherFactory; + namespace extensions { EventFilter::EventMatcherEntry::EventMatcherEntry( diff --git a/extensions/common/event_filter.h b/extensions/common/event_filter.h index 6ef136cb9dcba4..ddd0681fc81121 100644 --- a/extensions/common/event_filter.h +++ b/extensions/common/event_filter.h @@ -9,9 +9,9 @@ #include #include "base/memory/linked_ptr.h" +#include "components/url_matcher/url_matcher.h" #include "extensions/common/event_filtering_info.h" #include "extensions/common/event_matcher.h" -#include "extensions/common/matcher/url_matcher.h" namespace extensions { @@ -61,9 +61,10 @@ class EventFilter { // again on destruction. |condition_sets| should be the // URLMatcherConditionSets that match the URL constraints specified by // |event_matcher|. - EventMatcherEntry(scoped_ptr event_matcher, - URLMatcher* url_matcher, - const URLMatcherConditionSet::Vector& condition_sets); + EventMatcherEntry( + scoped_ptr event_matcher, + url_matcher::URLMatcher* url_matcher, + const url_matcher::URLMatcherConditionSet::Vector& condition_sets); ~EventMatcherEntry(); // Prevents the removal of condition sets when this class is destroyed. We @@ -79,8 +80,8 @@ class EventFilter { private: scoped_ptr event_matcher_; // The id sets in url_matcher_ that this EventMatcher owns. - std::vector condition_set_ids_; - URLMatcher* url_matcher_; + std::vector condition_set_ids_; + url_matcher::URLMatcher* url_matcher_; DISALLOW_COPY_AND_ASSIGN(EventMatcherEntry); }; @@ -93,27 +94,28 @@ class EventFilter { // Adds the list of URL filters in |matcher| to the URL matcher, having // matches for those URLs map to |id|. - bool CreateConditionSets(MatcherID id, - EventMatcher* matcher, - URLMatcherConditionSet::Vector* condition_sets); + bool CreateConditionSets( + MatcherID id, + EventMatcher* matcher, + url_matcher::URLMatcherConditionSet::Vector* condition_sets); bool AddDictionaryAsConditionSet( base::DictionaryValue* url_filter, - URLMatcherConditionSet::Vector* condition_sets); + url_matcher::URLMatcherConditionSet::Vector* condition_sets); - URLMatcher url_matcher_; + url_matcher::URLMatcher url_matcher_; EventMatcherMultiMap event_matchers_; // The next id to assign to an EventMatcher. MatcherID next_id_; // The next id to assign to a condition set passed to URLMatcher. - URLMatcherConditionSet::ID next_condition_set_id_; + url_matcher::URLMatcherConditionSet::ID next_condition_set_id_; // Maps condition set ids, which URLMatcher operates in, to event matcher // ids, which the interface to this class operates in. As each EventFilter // can specify many condition sets this is a many to one relationship. - std::map + std::map condition_set_id_to_event_matcher_id_; // Maps from event matcher ids to the name of the event they match on. diff --git a/extensions/common/matcher/url_matcher_constants.h b/extensions/common/matcher/url_matcher_constants.h deleted file mode 100644 index 0618a521577fd1..00000000000000 --- a/extensions/common/matcher/url_matcher_constants.h +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright (c) 2012 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. - -// Constants used for the URLMatcher component of the Declarative API. - -#ifndef EXTENSIONS_COMMON_MATCHER_URL_MATCHER_CONSTANTS_H_ -#define EXTENSIONS_COMMON_MATCHER_URL_MATCHER_CONSTANTS_H_ - -namespace extensions { -namespace url_matcher_constants { - -// Keys of dictionaries for URL constraints -extern const char kPortsKey[]; -extern const char kSchemesKey[]; -extern const char kHostContainsKey[]; -extern const char kHostEqualsKey[]; -extern const char kHostPrefixKey[]; -extern const char kHostSuffixKey[]; -extern const char kHostSuffixPathPrefixKey[]; -extern const char kOriginAndPathMatchesKey[]; -extern const char kPathContainsKey[]; -extern const char kPathEqualsKey[]; -extern const char kPathPrefixKey[]; -extern const char kPathSuffixKey[]; -extern const char kQueryContainsKey[]; -extern const char kQueryEqualsKey[]; -extern const char kQueryPrefixKey[]; -extern const char kQuerySuffixKey[]; -extern const char kURLContainsKey[]; -extern const char kURLEqualsKey[]; -extern const char kURLMatchesKey[]; -extern const char kURLPrefixKey[]; -extern const char kURLSuffixKey[]; - -} // namespace url_matcher_constants -} // namespace extensions - -#endif // EXTENSIONS_COMMON_MATCHER_URL_MATCHER_CONSTANTS_H_ diff --git a/extensions/extensions.gyp b/extensions/extensions.gyp index 96a007535738fd..ce04afaa3b3895 100644 --- a/extensions/extensions.gyp +++ b/extensions/extensions.gyp @@ -16,6 +16,7 @@ # http://crbug.com/162530 '../chrome/chrome_resources.gyp:chrome_resources', '../chrome/common/extensions/api/api.gyp:api', + '../components/components.gyp:url_matcher', '../content/content.gyp:content_common', '../third_party/re2/re2.gyp:re2', ], @@ -85,20 +86,6 @@ 'common/manifest_handlers/sandboxed_page_info.h', 'common/manifest_handlers/shared_module_info.cc', 'common/manifest_handlers/shared_module_info.h', - 'common/matcher/regex_set_matcher.cc', - 'common/matcher/regex_set_matcher.h', - 'common/matcher/string_pattern.cc', - 'common/matcher/string_pattern.h', - 'common/matcher/substring_set_matcher.cc', - 'common/matcher/substring_set_matcher.h', - 'common/matcher/url_matcher.cc', - 'common/matcher/url_matcher.h', - 'common/matcher/url_matcher_constants.cc', - 'common/matcher/url_matcher_constants.h', - 'common/matcher/url_matcher_factory.cc', - 'common/matcher/url_matcher_factory.h', - 'common/matcher/url_matcher_helpers.cc', - 'common/matcher/url_matcher_helpers.h', 'common/one_shot_event.cc', 'common/one_shot_event.h', 'common/permissions/api_permission.cc',