Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(874)

Side by Side Diff: chrome/browser/extensions/api/declarative_content/content_condition.h

Issue 11547033: Implement declarativeContent API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Take out ParseJson and DeclarativeRule template Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_CONTENT_CONTENT_CONDITION_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_CONTENT_CONTENT_CONDITION_H_
7
8 #include <map>
9 #include <string>
10 #include <vector>
11
12 #include "base/hash_tables.h"
13 #include "base/memory/linked_ptr.h"
14 #include "base/memory/ref_counted.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "base/memory/scoped_vector.h"
17 #include "base/values.h"
18 #include "chrome/browser/extensions/api/declarative/declarative_rule.h"
19 #include "chrome/common/extensions/matcher/url_matcher.h"
20 #include "googleurl/src/gurl.h"
battre 2012/12/15 11:54:10 nit: some of the includes are not necessary.
Jeffrey Yasskin 2013/01/17 09:22:56 Done.
21
22 namespace extensions {
23
24 struct RendererContentMatchData {
25 RendererContentMatchData();
26 ~RendererContentMatchData();
27 GURL page_url;
28 base::hash_set<std::string> css_rules;
battre 2012/12/15 11:54:10 are these css selectors? in that case, I think we
Jeffrey Yasskin 2013/01/17 09:22:56 Good point. Done.
29 };
30
31 // Representation of a condition in the Declarative Content API. A condition
32 // consists of an optional URL and a list of CSS selectors. Each of these
33 // attributes needs to be fulfilled in order for the condition to be fulfilled.
34 //
35 // We distinguish between two types of attributes:
36 // - URL Matcher attributes are attributes that test the URL of a page.
battre 2012/12/15 11:54:10 does this apply to main_frames or also to other fr
Jeffrey Yasskin 2013/01/17 09:22:56 For now, it's just top-level pages. I think the at
37 // These are treated separately because we use a URLMatcher to efficiently
38 // test many of these attributes in parallel by using some advanced
39 // data structures. The URLMatcher tells us if all URL Matcher attributes
40 // are fulfilled for a ContentCondition.
41 // - All other conditions are represented individually as fields in
42 // ContentCondition. These conditions are probed linearly (only if the URL
43 // Matcher found a hit).
44 //
45 // TODO(battre) Consider making the URLMatcher an owner of the
46 // URLMatcherConditionSet and only pass a pointer to URLMatcherConditionSet
47 // in url_matcher_condition_set(). This saves some copying in
48 // ContentConditionSet::GetURLMatcherConditionSets.
49 class ContentCondition {
50 public:
51 typedef RendererContentMatchData MatchData;
52
53 ContentCondition(
54 scoped_refptr<URLMatcherConditionSet> url_matcher_conditions,
55 const std::vector<std::string>& css_rules);
56 ~ContentCondition();
57
58 // Factory method that instantiates a ContentCondition according to the
59 // description |condition| passed by the extension API. |condition| should be
60 // an instance of declarativeContent.PageStateMatcher.
61 static scoped_ptr<ContentCondition> Create(
62 URLMatcherConditionFactory* url_matcher_condition_factory,
63 const base::Value& condition,
64 std::string* error);
65
66 // Returns whether the request is a match, given that the URLMatcher found
67 // a match for |url_matcher_conditions_|.
68 bool IsFulfilled(const RendererContentMatchData& renderer_data) const;
69
70 // Returns a URLMatcherConditionSet::ID which is the canonical representation
71 // for all URL patterns that need to be matched by this ContentCondition.
72 // This ID is registered in a URLMatcher that can inform us in case of a
73 // match.
74 URLMatcherConditionSet::ID url_matcher_condition_set_id() const {
75 return url_matcher_conditions_->id();
76 }
77
78 // Returns the set of conditions that are checked on the URL. This is the
79 // primary trigger for ContentCondition and therefore never empty. (If it was
80 // empty, the URLMatcher would never notify us about page changes which might
81 // fulfill the entire ContentCondition).
82 scoped_refptr<URLMatcherConditionSet> url_matcher_condition_set() const {
83 return url_matcher_conditions_;
84 }
85
86 // Returns the CSS rules required to match by this condition.
87 const std::vector<std::string>& css_rules() const {
88 return css_rules_;
89 }
90
91 private:
92 scoped_refptr<URLMatcherConditionSet> url_matcher_conditions_;
93 std::vector<std::string> css_rules_;
94
95 DISALLOW_COPY_AND_ASSIGN(ContentCondition);
96 };
97
98 typedef DeclarativeConditionSet<ContentCondition> ContentConditionSet;
99
100 } // namespace extensions
101
102 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_CONTENT_CONTENT_CONDITION_H _
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698