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