Skip to content

Commit

Permalink
Move extensions/common/matcher into components/url_matcher.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
joaodasilva@chromium.org committed Dec 13, 2013
1 parent 32c90a9 commit 716c016
Show file tree
Hide file tree
Showing 50 changed files with 393 additions and 288 deletions.
1 change: 1 addition & 0 deletions chrome/browser/DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
24 changes: 12 additions & 12 deletions chrome/browser/extensions/api/declarative/declarative_rule.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand All @@ -80,20 +80,20 @@ 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 {
return !conditions_without_urls_.empty();
}

private:
typedef std::map<URLMatcherConditionSet::ID, const ConditionT*>
typedef std::map<url_matcher::URLMatcherConditionSet::ID, const ConditionT*>
URLMatcherIdToCondition;

DeclarativeConditionSet(
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand All @@ -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;
Expand All @@ -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) {
Expand All @@ -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();
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
Expand Down Expand Up @@ -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();

Expand All @@ -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);

Expand All @@ -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_);
}
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand All @@ -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_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -70,16 +70,17 @@ 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();

// Factory method that instantiates a WebRequestCondition according to
// 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);

Expand All @@ -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
Expand All @@ -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_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand Down
Loading

0 comments on commit 716c016

Please sign in to comment.