diff options
author | joaodasilva@chromium.org <joaodasilva@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-13 20:36:53 +0000 |
---|---|---|
committer | joaodasilva@chromium.org <joaodasilva@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-13 20:36:53 +0000 |
commit | 716c016d95025a8f4d42baab6639b9dc90498f2d (patch) | |
tree | 9efb703e070ecbfb1b73bfac9b350a3b81af14f6 | |
parent | 32c90a98f03fa68da4ba3d97a8e56ca70e92a07d (diff) | |
download | chromium_src-716c016d95025a8f4d42baab6639b9dc90498f2d.zip chromium_src-716c016d95025a8f4d42baab6639b9dc90498f2d.tar.gz chromium_src-716c016d95025a8f4d42baab6639b9dc90498f2d.tar.bz2 |
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
50 files changed, 393 insertions, 288 deletions
diff --git a/chrome/browser/DEPS b/chrome/browser/DEPS index 5425da7..74cae02 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 d51d7e2..b06ae700 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<DeclarativeConditionSet> 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<URLMatcherConditionSet::ID, const ConditionT*> + typedef std::map<url_matcher::URLMatcherConditionSet::ID, const ConditionT*> 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<DeclarativeRule> Create( - URLMatcherConditionFactory* url_matcher_condition_factory, + url_matcher::URLMatcherConditionFactory* url_matcher_condition_factory, const Extension* extension, base::Time extension_installation_time, linked_ptr<JsonRule> rule, @@ -260,7 +260,7 @@ class DeclarativeRule { template<typename ConditionT> bool DeclarativeConditionSet<ConditionT>::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<ConditionT>::IsFulfilled( template<typename ConditionT> void DeclarativeConditionSet<ConditionT>::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<typename ConditionT> scoped_ptr<DeclarativeConditionSet<ConditionT> > DeclarativeConditionSet<ConditionT>::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<ConditionT>::Create( URLMatcherIdToCondition match_id_to_condition; std::vector<const ConditionT*> 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<ConditionT>::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<ConditionT, ActionT>::DeclarativeRule( template<typename ConditionT, typename ActionT> scoped_ptr<DeclarativeRule<ConditionT, ActionT> > DeclarativeRule<ConditionT, ActionT>::Create( - URLMatcherConditionFactory* url_matcher_condition_factory, + url_matcher::URLMatcherConditionFactory* url_matcher_condition_factory, const Extension* extension, base::Time extension_installation_time, linked_ptr<JsonRule> rule, diff --git a/chrome/browser/extensions/api/declarative/declarative_rule_unittest.cc b/chrome/browser/extensions/api/declarative/declarative_rule_unittest.cc index df30af1..98b2552 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 74319f8..5a88d1c 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 389f301..c7a1db6 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<URLMatcherConditionSet::ID> page_url_matches; + std::set<url_matcher::URLMatcherConditionSet::ID> page_url_matches; // All watched CSS selectors that match on frames with the same // origin as the page's main frame. base::hash_set<std::string> css_selectors; @@ -54,7 +54,7 @@ class ContentCondition { typedef RendererContentMatchData MatchData; ContentCondition( - scoped_refptr<URLMatcherConditionSet> url_matcher_conditions, + scoped_refptr<url_matcher::URLMatcherConditionSet> url_matcher_conditions, const std::vector<std::string>& css_selectors); ~ContentCondition(); @@ -63,7 +63,7 @@ class ContentCondition { // an instance of declarativeContent.PageStateMatcher. static scoped_ptr<ContentCondition> 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<URLMatcherConditionSet> url_matcher_conditions_; + scoped_refptr<url_matcher::URLMatcherConditionSet> url_matcher_conditions_; std::vector<std::string> 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 f4cdb8e..fe0cdcb 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 4e9a511..5c76c37 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 c752ebb..9224374 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<URLMatcherConditionSet::ID, ContentRule*> URLMatcherIdToRule; + typedef std::map<url_matcher::URLMatcherConditionSet::ID, ContentRule*> + URLMatcherIdToRule; typedef std::map<ContentRule::GlobalRuleId, linked_ptr<ContentRule> > RulesMap; @@ -131,7 +132,7 @@ class ContentRulesRegistry : public RulesRegistry, std::map<int, std::set<ContentRule*> > 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<std::string> 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 1e1ddec..b557633 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 a9c9355..5dc1508 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<URLMatcherConditionSet::ID> url_match_ids; - std::set<URLMatcherConditionSet::ID> first_party_url_match_ids; + std::set<url_matcher::URLMatcherConditionSet::ID> url_match_ids; + std::set<url_matcher::URLMatcherConditionSet::ID> 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<URLMatcherConditionSet> url_matcher_conditions, - scoped_refptr<URLMatcherConditionSet> first_party_url_matcher_conditions, + scoped_refptr<url_matcher::URLMatcherConditionSet> url_matcher_conditions, + scoped_refptr<url_matcher::URLMatcherConditionSet> + 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<WebRequestCondition> 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<URLMatcherConditionSet> url_matcher_conditions_; - scoped_refptr<URLMatcherConditionSet> first_party_url_matcher_conditions_; + scoped_refptr<url_matcher::URLMatcherConditionSet> url_matcher_conditions_; + scoped_refptr<url_matcher::URLMatcherConditionSet> + 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 38552ad..8531a15 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 949796e..8cd1595 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 805b0b2..188beaf 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<URLMatcherConditionSet::ID, WebRequestRule*> RuleTriggers; + typedef std::map<url_matcher::URLMatcherConditionSet::ID, WebRequestRule*> + RuleTriggers; typedef std::map<WebRequestRule::RuleId, linked_ptr<WebRequestRule> > RulesMap; - typedef std::set<URLMatcherConditionSet::ID> URLMatches; + typedef std::set<url_matcher::URLMatcherConditionSet::ID> URLMatches; typedef std::set<const WebRequestRule*> 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<URLMatcherConditionSet::ID>* remove_from_url_matcher); + void CleanUpAfterRule(const WebRequestRule* rule, + std::vector<url_matcher::URLMatcherConditionSet::ID>* + 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<WebRequestRule::ExtensionId, RulesMap> webrequest_rules_; - URLMatcher url_matcher_; + url_matcher::URLMatcher url_matcher_; void* profile_id_; scoped_refptr<InfoMap> 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 93de526..dc0a6fb 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 174257d..d60255f 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<extensions::URLMatcherConditionSet> condition_set = + scoped_refptr<URLMatcherConditionSet> 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 e4f6db4..322afa5 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<extensions::URLMatcherConditionSet> -URLBlacklist::CreateConditionSet( - extensions::URLMatcher* url_matcher, +scoped_refptr<URLMatcherConditionSet> 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 f502369..d7f9423 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<extensions::URLMatcherConditionSet> CreateConditionSet( - extensions::URLMatcher* url_matcher, - extensions::URLMatcherConditionSet::ID id, + static scoped_refptr<url_matcher::URLMatcherConditionSet> 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<extensions::URLMatcherConditionSet::ID, FilterComponents> filters_; - scoped_ptr<extensions::URLMatcher> url_matcher_; + url_matcher::URLMatcherConditionSet::ID id_; + std::map<url_matcher::URLMatcherConditionSet::ID, FilterComponents> filters_; + scoped_ptr<url_matcher::URLMatcher> url_matcher_; DISALLOW_COPY_AND_ASSIGN(URLBlacklist); }; diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 89984af..5b1ea14 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 1452424..82951ee 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 0742aaf..42a031e 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 3bd1a2b..47ece66 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 294970f..72b8e52 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 0000000..3476552 --- /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 0000000..0de07bb --- /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 index d5f125f..d5f125f 100644 --- a/extensions/common/matcher/OWNERS +++ b/components/url_matcher/OWNERS diff --git a/extensions/common/matcher/regex_set_matcher.cc b/components/url_matcher/regex_set_matcher.cc index 24d99ef..c0b977c 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 index 906ab9c..e4eb1dc 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 <map> #include <set> @@ -11,20 +11,21 @@ #include <vector> #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<const StringPattern*> 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 index 49d312a..dd54e51 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 <set> #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 index 4e5c350..d103bce 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 index 1781b03..ca5f223 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 <string> #include <vector> #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 index 6e7e4bf..460f431 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 <string> #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 index 91ac718..9669788 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 <algorithm> #include <queue> @@ -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 index 610efc0..8a05ef3 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 <limits> #include <map> @@ -12,13 +12,14 @@ #include <vector> #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 index fde65bf..f5f2be0 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 <set> #include <string> @@ -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 index 5a1d876..de8632d 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 <algorithm> #include <iterator> #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 index d93a606..53c393a 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 <set> #include <vector> @@ -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<std::string>& 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<int, int> 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<URLMatcherConditionSet> { +class URL_MATCHER_EXPORT URLMatcherConditionSet + : public base::RefCounted<URLMatcherConditionSet> { public: typedef int ID; typedef std::set<URLMatcherCondition> Conditions; @@ -285,7 +287,7 @@ class URLMatcherConditionSet : public base::RefCounted<URLMatcherConditionSet> { // 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 index 5b23dea..6c2c43d 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 0000000..2f8e18a --- /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 0000000..82a0181 --- /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 index 6eec2e6..ab1c365 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 <algorithm> #include <cctype> @@ -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<std::string, FactoryMethod> FactoryMethods; @@ -98,8 +100,6 @@ static base::LazyInstance<URLMatcherConditionFactoryMethods> } // namespace -namespace extensions { - // static scoped_refptr<URLMatcherConditionSet> URLMatcherFactory::CreateFromURLFilterDictionary( @@ -140,9 +140,8 @@ URLMatcherFactory::CreateFromURLFilterDictionary( return scoped_refptr<URLMatcherConditionSet>(NULL); } else { // Handle unknown attributes. - *error = ErrorUtils::FormatErrorMessage( - kUnknownURLFilterAttribute, - condition_attribute_name); + *error = base::StringPrintf(kUnknownURLFilterAttribute, + condition_attribute_name.c_str()); return scoped_refptr<URLMatcherConditionSet>(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<URLMatcherSchemeFilter> URLMatcherFactory::CreateURLMatcherScheme( std::string* error) { std::vector<std::string> schemas; if (!helpers::GetAsStringVector(value, &schemas)) { - *error = ErrorUtils::FormatErrorMessage(kVectorOfStringsExpected, - keys::kSchemesKey); + *error = base::StringPrintf(kVectorOfStringsExpected, keys::kSchemesKey); return scoped_ptr<URLMatcherSchemeFilter>(); } for (std::vector<std::string>::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<URLMatcherSchemeFilter>(); } } @@ -274,4 +270,4 @@ scoped_ptr<URLMatcherPortFilter> URLMatcherFactory::CreateURLMatcherPorts( return scoped_ptr<URLMatcherPortFilter>(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 index 7c5be68..93ff202 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 <string> #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 index 733e1b8..9d6632e 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 index e4832cc..61358e7 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 index 57bd299..15aa0c5 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 <string> #include <vector> @@ -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<std::string>* 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 index 29b7c89..748d310 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 f286a2e..898a76b 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 70915b9..ad954c9 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 6ef136c..ddd0681 100644 --- a/extensions/common/event_filter.h +++ b/extensions/common/event_filter.h @@ -9,9 +9,9 @@ #include <set> #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<EventMatcher> event_matcher, - URLMatcher* url_matcher, - const URLMatcherConditionSet::Vector& condition_sets); + EventMatcherEntry( + scoped_ptr<EventMatcher> 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<EventMatcher> event_matcher_; // The id sets in url_matcher_ that this EventMatcher owns. - std::vector<URLMatcherConditionSet::ID> condition_set_ids_; - URLMatcher* url_matcher_; + std::vector<url_matcher::URLMatcherConditionSet::ID> 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<URLMatcherConditionSet::ID, MatcherID> + std::map<url_matcher::URLMatcherConditionSet::ID, MatcherID> 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 0618a52..0000000 --- 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 96a0075..ce04afa 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', |