Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: include/AdblockPlus/FilterEngine.h

Issue 10100009: FilterEngine API improvements (Closed)
Patch Set: Replace GetElementHidingRules by a domain-specific GetElementHidingSelectors Created April 5, 2013, 12:22 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | libadblockplus.gyp » ('j') | shell/src/FiltersCommand.cpp » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #ifndef ADBLOCKPLUS_FILTER_ENGINE_H 1 #ifndef ADBLOCKPLUS_FILTER_ENGINE_H
2 #define ADBLOCKPLUS_FILTER_ENGINE_H 2 #define ADBLOCKPLUS_FILTER_ENGINE_H
3 3
4 #include <vector> 4 #include <vector>
5 #include <map>
5 #include <string> 6 #include <string>
6 7
7 namespace AdblockPlus 8 namespace AdblockPlus
8 { 9 {
9 class JsEngine; 10 class JsEngine;
11 class FilterEngine;
10 12
11 struct Subscription 13 class JSObject
Felix Dahlke 2013/04/06 05:17:05 Should be JsObject for consistency. I've thought
12 { 14 {
13 std::string url; 15 public:
14 std::string title; 16 std::string GetProperty(const std::string& name, const std::string& defaultV alue) const;
17 int GetProperty(const std::string& name, int defaultValue) const;
18 bool GetProperty(const std::string& name, bool defaultValue) const;
19 inline std::string GetProperty(const std::string& name, const char* defaultV alue) const
20 {
21 return GetProperty(name, std::string(defaultValue));
22 }
15 23
16 Subscription(const std::string& url, const std::string& title); 24 void SetProperty(const std::string& name, const std::string& value);
25 void SetProperty(const std::string& name, int value);
26 void SetProperty(const std::string& name, bool value);
27 inline void SetProperty(const std::string& name, const char* value)
28 {
29 SetProperty(name, std::string(value));
30 }
31
32 protected:
33 #if FILTER_ENGINE_STUBS
34 JSObject(FilterEngine& filterEngine);
35
36 FilterEngine& filterEngine;
37 std::map<std::string, std::string> stringProperties;
38 std::map<std::string, int> intProperties;
39 std::map<std::string, bool> boolProperties;
40 #else
41 JSObject();
42 #endif
17 }; 43 };
18 44
45 class Filter : public JSObject
46 {
47 friend class FilterEngine;
48
49 public:
50 bool IsListed() const;
51 void AddToList();
52 void RemoveFromList();
53
54 private:
55 #if FILTER_ENGINE_STUBS
56 Filter(FilterEngine& filterEngine, const std::string& text);
57 #else
58 Filter();
59 #endif
60 };
61
62 class Subscription : public JSObject
63 {
64 friend class FilterEngine;
65
66 public:
67 bool IsListed() const;
68 void AddToList();
69 void RemoveFromList();
70 void UpdateFilters();
71
72 private:
73 #if FILTER_ENGINE_STUBS
74 Subscription(FilterEngine& filterEngine, const std::string& url);
75 #else
76 Subscription();
77 #endif
78 };
79
80 typedef void (*SubscriptionsCallback)(const std::vector<Subscription*>&);
81
19 class FilterEngine 82 class FilterEngine
20 { 83 {
84 friend class Filter;
85 friend class Subscription;
21 public: 86 public:
22 explicit FilterEngine(JsEngine& jsEngine); 87 explicit FilterEngine(JsEngine& jsEngine);
23 void AddSubscription(Subscription subscription); 88 Filter& GetFilter(const std::string& text);
24 void RemoveSubscription(const Subscription& subscription); 89 Subscription& GetSubscription(const std::string& url);
25 const Subscription* FindSubscription(const std::string& url) const; 90 const std::vector<Filter*>& GetListedFilters() const;
26 const std::vector<Subscription>& GetSubscriptions() const; 91 const std::vector<Subscription*>& GetListedSubscriptions() const;
27 void UpdateSubscriptionFilters(const Subscription& subscription); 92 void FetchAvailableSubscriptions(SubscriptionsCallback callback);
28 std::vector<Subscription> FetchAvailableSubscriptions(); 93 Filter* Matches(const std::string& url,
29 bool Matches(const std::string& url, 94 const std::string& contentType,
30 const std::string& contentType) const; 95 const std::string& documentUrl);
31 std::vector<std::string> GetElementHidingRules() const; 96 std::vector<std::string> GetElementHidingSelectors(const std::string& domain ) const;
32 97
33 private: 98 private:
34 JsEngine& jsEngine; 99 JsEngine& jsEngine;
35 std::vector<Subscription> subscriptions; 100 #if FILTER_ENGINE_STUBS
101 std::map<std::string, Filter*> knownFilters;
102 std::vector<Filter*> listedFilters;
103 std::map<std::string, Subscription*> knownSubscriptions;
104 std::vector<Subscription*> listedSubscriptions;
105 #endif
36 }; 106 };
37 } 107 }
38 108
39 #endif 109 #endif
OLDNEW
« no previous file with comments | « no previous file | libadblockplus.gyp » ('j') | shell/src/FiltersCommand.cpp » ('J')

Powered by Google App Engine
This is Rietveld