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

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

Issue 10213003: Make JsEngine::Evaluate() return a wrapper for v8::Value to accessdifferent variable types easily (Closed)
Patch Set: Extended JsValue API to support all FilterEngine functions Created April 13, 2013, 8:42 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 | « include/AdblockPlus.h ('k') | include/AdblockPlus/JsEngine.h » ('j') | no next file with comments »
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 <map>
6 #include <string> 6 #include <string>
7 #ifdef _MSC_VER 7 #ifdef _MSC_VER
8 #include <memory> 8 #include <memory>
9 #else 9 #else
10 #include <tr1/memory> 10 #include <tr1/memory>
11 #endif 11 #endif
12 #include <AdblockPlus/JsValue.h>
13
12 namespace AdblockPlus 14 namespace AdblockPlus
13 { 15 {
14 class JsEngine; 16 class JsEngine;
15 class FilterEngine; 17 class FilterEngine;
16 18
19 #if FILTER_ENGINE_STUBS
17 class JsObject 20 class JsObject
21 #else
22 class JsObject : public JsValue
23 #endif
18 { 24 {
19 public: 25 public:
20 std::string GetProperty(const std::string& name, const std::string& defaultV alue) const; 26 std::string GetProperty(const std::string& name, const std::string& defaultV alue) const;
21 int GetProperty(const std::string& name, int defaultValue) const; 27 int64_t GetProperty(const std::string& name, int64_t defaultValue) const;
22 bool GetProperty(const std::string& name, bool defaultValue) const; 28 bool GetProperty(const std::string& name, bool defaultValue) const;
23 inline std::string GetProperty(const std::string& name, const char* defaultV alue) const 29 inline std::string GetProperty(const std::string& name, const char* defaultV alue) const
24 { 30 {
25 return GetProperty(name, std::string(defaultValue)); 31 return GetProperty(name, std::string(defaultValue));
26 } 32 }
27 33
34 #if FILTER_ENGINE_STUBS
28 void SetProperty(const std::string& name, const std::string& value); 35 void SetProperty(const std::string& name, const std::string& value);
29 void SetProperty(const std::string& name, int value); 36 void SetProperty(const std::string& name, int64_t value);
30 void SetProperty(const std::string& name, bool value); 37 void SetProperty(const std::string& name, bool value);
31 inline void SetProperty(const std::string& name, const char* value) 38 inline void SetProperty(const std::string& name, const char* value)
32 { 39 {
33 SetProperty(name, std::string(value)); 40 SetProperty(name, std::string(value));
34 } 41 }
42 #endif
35 43
36 protected: 44 protected:
37 #if FILTER_ENGINE_STUBS 45 #if FILTER_ENGINE_STUBS
38 JsObject(FilterEngine& filterEngine); 46 JsObject(FilterEngine& filterEngine);
39 47
40 FilterEngine& filterEngine; 48 FilterEngine& filterEngine;
41 std::map<std::string, std::string> stringProperties; 49 std::map<std::string, std::string> stringProperties;
42 std::map<std::string, int> intProperties; 50 std::map<std::string, int64_t> intProperties;
43 std::map<std::string, bool> boolProperties; 51 std::map<std::string, bool> boolProperties;
44 #else 52 #else
45 JsObject(); 53 JsObject(JsValuePtr value);
46 #endif 54 #endif
47 }; 55 };
48 56
49 class Filter : public JsObject, 57 class Filter : public JsObject,
50 public std::tr1::enable_shared_from_this<Filter> 58 public std::tr1::enable_shared_from_this<Filter>
51 { 59 {
52 friend class FilterEngine;
53
54 public: 60 public:
55 enum Type {TYPE_BLOCKING, TYPE_EXCEPTION, 61 enum Type {TYPE_BLOCKING, TYPE_EXCEPTION,
56 TYPE_ELEMHIDE, TYPE_ELEMHIDE_EXCEPTION, 62 TYPE_ELEMHIDE, TYPE_ELEMHIDE_EXCEPTION,
57 TYPE_COMMENT, TYPE_INVALID}; 63 TYPE_COMMENT, TYPE_INVALID};
58 64
59 bool IsListed() const; 65 bool IsListed();
60 void AddToList(); 66 void AddToList();
61 void RemoveFromList(); 67 void RemoveFromList();
68 bool operator==(const Filter& filter) const;
62 69
70 #if FILTER_ENGINE_STUBS
63 private: 71 private:
64 #if FILTER_ENGINE_STUBS 72 friend class FilterEngine;
65 Filter(FilterEngine& filterEngine, const std::string& text); 73 Filter(FilterEngine& filterEngine, const std::string& text);
66 #else 74 #else
67 Filter(); 75 Filter(JsValuePtr value);
68 #endif 76 #endif
69 }; 77 };
70 78
71 class Subscription : public JsObject, 79 class Subscription : public JsObject,
72 public std::tr1::enable_shared_from_this<Subscription> 80 public std::tr1::enable_shared_from_this<Subscription>
73 { 81 {
74 friend class FilterEngine;
75
76 public: 82 public:
77 bool IsListed() const; 83 bool IsListed();
78 void AddToList(); 84 void AddToList();
79 void RemoveFromList(); 85 void RemoveFromList();
80 void UpdateFilters(); 86 void UpdateFilters();
87 bool operator==(const Subscription& subscription) const;
81 88
89 #if FILTER_ENGINE_STUBS
82 private: 90 private:
83 #if FILTER_ENGINE_STUBS 91 friend class FilterEngine;
84 Subscription(FilterEngine& filterEngine, const std::string& url); 92 Subscription(FilterEngine& filterEngine, const std::string& url);
85 #else 93 #else
86 Subscription(); 94 Subscription(JsValuePtr value);
87 #endif 95 #endif
88 }; 96 };
89 97
90 typedef std::tr1::shared_ptr<Filter> FilterPtr; 98 typedef std::tr1::shared_ptr<Filter> FilterPtr;
91 typedef std::tr1::shared_ptr<Subscription> SubscriptionPtr; 99 typedef std::tr1::shared_ptr<Subscription> SubscriptionPtr;
92 typedef void (*SubscriptionsCallback)(const std::vector<SubscriptionPtr>&); 100 typedef void (*SubscriptionsCallback)(const std::vector<SubscriptionPtr>&);
93 101
94 class FilterEngine 102 class FilterEngine
95 { 103 {
104 #if FILTER_ENGINE_STUBS
96 friend class Filter; 105 friend class Filter;
97 friend class Subscription; 106 friend class Subscription;
107 #endif
108
98 public: 109 public:
99 explicit FilterEngine(JsEngine& jsEngine); 110 explicit FilterEngine(JsEngine& jsEngine);
100 FilterPtr GetFilter(const std::string& text); 111 FilterPtr GetFilter(const std::string& text);
101 SubscriptionPtr GetSubscription(const std::string& url); 112 SubscriptionPtr GetSubscription(const std::string& url);
102 const std::vector<FilterPtr>& GetListedFilters() const; 113 const std::vector<FilterPtr> GetListedFilters() const;
103 const std::vector<SubscriptionPtr>& GetListedSubscriptions() const; 114 const std::vector<SubscriptionPtr> GetListedSubscriptions() const;
104 void FetchAvailableSubscriptions(SubscriptionsCallback callback); 115 void FetchAvailableSubscriptions(SubscriptionsCallback callback);
105 FilterPtr Matches(const std::string& url, 116 FilterPtr Matches(const std::string& url,
106 const std::string& contentType, 117 const std::string& contentType,
107 const std::string& documentUrl); 118 const std::string& documentUrl);
108 std::vector<std::string> GetElementHidingSelectors(const std::string& domain ) const; 119 std::vector<std::string> GetElementHidingSelectors(const std::string& domain ) const;
109 120
110 private: 121 private:
111 JsEngine& jsEngine; 122 JsEngine& jsEngine;
112 #if FILTER_ENGINE_STUBS 123 #if FILTER_ENGINE_STUBS
113 std::map<std::string, FilterPtr> knownFilters; 124 std::map<std::string, FilterPtr> knownFilters;
114 std::vector<FilterPtr> listedFilters; 125 std::vector<FilterPtr> listedFilters;
115 std::map<std::string, SubscriptionPtr> knownSubscriptions; 126 std::map<std::string, SubscriptionPtr> knownSubscriptions;
116 std::vector<SubscriptionPtr> listedSubscriptions; 127 std::vector<SubscriptionPtr> listedSubscriptions;
117 #endif 128 #endif
118 }; 129 };
119 } 130 }
120 131
121 #endif 132 #endif
OLDNEW
« no previous file with comments | « include/AdblockPlus.h ('k') | include/AdblockPlus/JsEngine.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld