Left: | ||
Right: |
LEFT | RIGHT |
---|---|
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 <map> |
6 #include <string> | 6 #include <string> |
7 #include <tr1/memory> | |
7 | 8 |
8 namespace AdblockPlus | 9 namespace AdblockPlus |
9 { | 10 { |
10 class JsEngine; | 11 class JsEngine; |
11 class FilterEngine; | 12 class FilterEngine; |
12 | 13 |
13 class Subscription | 14 class JsObject |
15 { | |
16 public: | |
17 std::string GetProperty(const std::string& name, const std::string& defaultV alue) const; | |
18 int GetProperty(const std::string& name, int defaultValue) const; | |
19 bool GetProperty(const std::string& name, bool defaultValue) const; | |
20 inline std::string GetProperty(const std::string& name, const char* defaultV alue) const | |
21 { | |
22 return GetProperty(name, std::string(defaultValue)); | |
23 } | |
24 | |
25 void SetProperty(const std::string& name, const std::string& value); | |
26 void SetProperty(const std::string& name, int value); | |
27 void SetProperty(const std::string& name, bool value); | |
28 inline void SetProperty(const std::string& name, const char* value) | |
29 { | |
30 SetProperty(name, std::string(value)); | |
31 } | |
32 | |
33 protected: | |
34 #if FILTER_ENGINE_STUBS | |
35 JsObject(FilterEngine& filterEngine); | |
36 | |
37 FilterEngine& filterEngine; | |
38 std::map<std::string, std::string> stringProperties; | |
39 std::map<std::string, int> intProperties; | |
40 std::map<std::string, bool> boolProperties; | |
41 #else | |
42 JsObject(); | |
43 #endif | |
44 }; | |
45 | |
46 class Filter : public JsObject, | |
47 public std::tr1::enable_shared_from_this<Filter> | |
14 { | 48 { |
15 friend class FilterEngine; | 49 friend class FilterEngine; |
50 | |
16 public: | 51 public: |
17 const std::string GetProperty(const std::string& name) const; | 52 enum Type {TYPE_BLOCKING, TYPE_EXCEPTION, |
Felix Dahlke
2013/04/05 08:50:20
Why return a const value here? It's copied on retu
Wladimir Palant
2013/04/05 12:15:16
True of course, originally I tried to return a ref
| |
18 int GetIntProperty(const std::string& name) const; | 53 TYPE_ELEMHIDE, TYPE_ELEMHIDE_EXCEPTION, |
19 void SetProperty(const std::string& name, const std::string& value); | 54 TYPE_COMMENT, TYPE_INVALID}; |
20 void SetIntProperty(const std::string& name, int value); | |
21 | 55 |
56 bool IsListed() const; | |
57 void AddToList(); | |
58 void RemoveFromList(); | |
59 | |
60 private: | |
61 #if FILTER_ENGINE_STUBS | |
62 Filter(FilterEngine& filterEngine, const std::string& text); | |
63 #else | |
64 Filter(); | |
65 #endif | |
66 }; | |
67 | |
68 class Subscription : public JsObject, | |
69 public std::tr1::enable_shared_from_this<Subscription> | |
70 { | |
71 friend class FilterEngine; | |
72 | |
73 public: | |
22 bool IsListed() const; | 74 bool IsListed() const; |
23 void AddToList(); | 75 void AddToList(); |
24 void RemoveFromList(); | 76 void RemoveFromList(); |
25 void UpdateFilters(); | 77 void UpdateFilters(); |
26 | 78 |
27 private: | 79 private: |
28 #if FILTER_ENGINE_STUBS | 80 #if FILTER_ENGINE_STUBS |
29 Subscription(FilterEngine& filterEngine, const std::string& url); | 81 Subscription(FilterEngine& filterEngine, const std::string& url); |
30 | |
31 FilterEngine& filterEngine; | |
32 std::map<std::string,std::string> properties; | |
Felix Dahlke
2013/04/05 08:50:20
We generally put a space after a comma in template
| |
33 std::map<std::string,int> intProperties; | |
Felix Dahlke
2013/04/05 08:50:20
Will we need more types than string and int? We'll
Wladimir Palant
2013/04/05 12:15:16
Yes, we need booleans as well. Other than that sub
| |
34 #else | 82 #else |
35 Subscription(); | 83 Subscription(); |
36 #endif | 84 #endif |
37 }; | 85 }; |
38 | 86 |
39 typedef void (*SubscriptionsCallback)(const std::vector<Subscription*>&); | 87 typedef std::tr1::shared_ptr<Filter> FilterPtr; |
88 typedef std::tr1::shared_ptr<Subscription> SubscriptionPtr; | |
89 typedef void (*SubscriptionsCallback)(const std::vector<SubscriptionPtr>&); | |
40 | 90 |
41 class FilterEngine | 91 class FilterEngine |
42 { | 92 { |
93 friend class Filter; | |
43 friend class Subscription; | 94 friend class Subscription; |
44 public: | 95 public: |
45 explicit FilterEngine(JsEngine& jsEngine); | 96 explicit FilterEngine(JsEngine& jsEngine); |
97 Filter& GetFilter(const std::string& text); | |
46 Subscription& GetSubscription(const std::string& url); | 98 Subscription& GetSubscription(const std::string& url); |
47 const std::vector<Subscription*>& GetListedSubscriptions() const; | 99 const std::vector<FilterPtr>& GetListedFilters() const; |
100 const std::vector<SubscriptionPtr>& GetListedSubscriptions() const; | |
48 void FetchAvailableSubscriptions(SubscriptionsCallback callback); | 101 void FetchAvailableSubscriptions(SubscriptionsCallback callback); |
49 bool Matches(const std::string& url, | 102 FilterPtr Matches(const std::string& url, |
50 const std::string& contentType, | 103 const std::string& contentType, |
51 const std::string& documentUrl) const; | 104 const std::string& documentUrl); |
52 std::vector<std::string> GetElementHidingRules() const; | 105 std::vector<std::string> GetElementHidingSelectors(const std::string& domain ) const; |
53 | 106 |
54 private: | 107 private: |
55 JsEngine& jsEngine; | 108 JsEngine& jsEngine; |
56 #if FILTER_ENGINE_STUBS | 109 #if FILTER_ENGINE_STUBS |
57 std::map<std::string,Subscription*> knownSubscriptions; | 110 std::map<std::string, FilterPtr> knownFilters; |
58 std::vector<Subscription*> listedSubscriptions; | 111 std::vector<FilterPtr> listedFilters; |
112 std::map<std::string, SubscriptionPtr> knownSubscriptions; | |
113 std::vector<SubscriptionPtr> listedSubscriptions; | |
59 #endif | 114 #endif |
60 }; | 115 }; |
61 } | 116 } |
62 | 117 |
63 #endif | 118 #endif |
LEFT | RIGHT |