Left: | ||
Right: |
OLD | NEW |
---|---|
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 |
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); |
Oleksandr
2013/04/05 14:09:07
Might be just me, but based on this signature I mi
Felix Dahlke
2013/04/05 14:20:59
How would that be any less ambigous?
IMO, we shou
Wladimir Palant
2013/04/05 14:31:45
Actually, the idea was that filters and subscripti
Felix Dahlke
2013/04/05 14:43:55
Then a pointer should be fine.
You have a point i
Wladimir Palant
2013/04/08 13:51:47
I am using shared_ptr instead of raw pointers now.
| |
31 std::vector<std::string> GetElementHidingRules() const; | 96 std::vector<std::string> GetElementHidingRules() 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 |
OLD | NEW |