Left: | ||
Right: |
OLD | NEW |
---|---|
1 /* | 1 /* |
2 * This file is part of Adblock Plus <http://adblockplus.org/>, | 2 * This file is part of Adblock Plus <http://adblockplus.org/>, |
3 * Copyright (C) 2006-2014 Eyeo GmbH | 3 * Copyright (C) 2006-2014 Eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
16 */ | 16 */ |
17 | 17 |
18 #ifndef ADBLOCK_PLUS_FILTER_ENGINE_H | 18 #ifndef ADBLOCK_PLUS_FILTER_ENGINE_H |
19 #define ADBLOCK_PLUS_FILTER_ENGINE_H | 19 #define ADBLOCK_PLUS_FILTER_ENGINE_H |
20 | 20 |
21 #include <functional> | 21 #include <functional> |
22 #include <map> | 22 #include <map> |
23 #include <memory> | |
23 #include <string> | 24 #include <string> |
24 #include <vector> | 25 #include <vector> |
25 #include <AdblockPlus/JsEngine.h> | 26 #include <AdblockPlus/JsEngine.h> |
26 #include <AdblockPlus/JsValue.h> | 27 #include <AdblockPlus/JsValue.h> |
27 | 28 |
28 #include "tr1_memory.h" | |
29 | |
30 namespace AdblockPlus | 29 namespace AdblockPlus |
31 { | 30 { |
32 class FilterEngine; | 31 class FilterEngine; |
33 | 32 |
34 class Filter : public JsValue, | 33 class Filter : public JsValue, |
35 public std::tr1::enable_shared_from_this<Filter> | 34 public std::enable_shared_from_this<Filter> |
36 { | 35 { |
37 public: | 36 public: |
38 enum Type {TYPE_BLOCKING, TYPE_EXCEPTION, | 37 enum Type {TYPE_BLOCKING, TYPE_EXCEPTION, |
39 TYPE_ELEMHIDE, TYPE_ELEMHIDE_EXCEPTION, | 38 TYPE_ELEMHIDE, TYPE_ELEMHIDE_EXCEPTION, |
40 TYPE_COMMENT, TYPE_INVALID}; | 39 TYPE_COMMENT, TYPE_INVALID}; |
41 | 40 |
42 Type GetType(); | 41 Type GetType(); |
43 bool IsListed(); | 42 bool IsListed(); |
44 void AddToList(); | 43 void AddToList(); |
45 void RemoveFromList(); | 44 void RemoveFromList(); |
46 bool operator==(const Filter& filter) const; | 45 bool operator==(const Filter& filter) const; |
47 | 46 |
48 Filter(JsValuePtr value); | 47 Filter(JsValuePtr value); |
49 }; | 48 }; |
50 | 49 |
51 class Subscription : public JsValue, | 50 class Subscription : public JsValue, |
52 public std::tr1::enable_shared_from_this<Subscription> | 51 public std::enable_shared_from_this<Subscription> |
53 { | 52 { |
54 public: | 53 public: |
55 bool IsListed(); | 54 bool IsListed(); |
56 void AddToList(); | 55 void AddToList(); |
57 void RemoveFromList(); | 56 void RemoveFromList(); |
58 void UpdateFilters(); | 57 void UpdateFilters(); |
59 bool IsUpdating(); | 58 bool IsUpdating(); |
60 bool operator==(const Subscription& subscription) const; | 59 bool operator==(const Subscription& subscription) const; |
61 | 60 |
62 Subscription(JsValuePtr value); | 61 Subscription(JsValuePtr value); |
63 }; | 62 }; |
64 | 63 |
65 typedef std::tr1::shared_ptr<Filter> FilterPtr; | 64 typedef std::shared_ptr<Filter> FilterPtr; |
66 typedef std::tr1::shared_ptr<Subscription> SubscriptionPtr; | 65 typedef std::shared_ptr<Subscription> SubscriptionPtr; |
67 | 66 |
68 class FilterEngine | 67 class FilterEngine |
69 { | 68 { |
70 public: | 69 public: |
71 typedef std::tr1::function<void(const std::string&)> UpdaterCallback; | 70 typedef std::function<void(const std::string&)> UpdaterCallback; |
72 typedef std::tr1::function<void(const std::string&, const JsValuePtr)> Filte rChangeCallback; | 71 typedef std::function<void(const std::string&, const JsValuePtr)> FilterChan geCallback; |
73 | 72 |
74 explicit FilterEngine(JsEnginePtr jsEngine); | 73 explicit FilterEngine(JsEnginePtr jsEngine); |
75 JsEnginePtr GetJsEngine() const { return jsEngine; } | 74 JsEnginePtr GetJsEngine() const { return jsEngine; } |
76 bool IsFirstRun() const; | 75 bool IsFirstRun() const; |
77 FilterPtr GetFilter(const std::string& text); | 76 FilterPtr GetFilter(const std::string& text); |
78 SubscriptionPtr GetSubscription(const std::string& url); | 77 SubscriptionPtr GetSubscription(const std::string& url); |
79 std::vector<FilterPtr> GetListedFilters() const; | 78 std::vector<FilterPtr> GetListedFilters() const; |
80 std::vector<SubscriptionPtr> GetListedSubscriptions() const; | 79 std::vector<SubscriptionPtr> GetListedSubscriptions() const; |
81 std::vector<SubscriptionPtr> FetchAvailableSubscriptions() const; | 80 std::vector<SubscriptionPtr> FetchAvailableSubscriptions() const; |
82 FilterPtr Matches(const std::string& url, | 81 FilterPtr Matches(const std::string& url, |
83 const std::string& contentType, | 82 const std::string& contentType, |
84 const std::string& documentUrl) const; | 83 const std::string& documentUrl) const; |
85 FilterPtr Matches(const std::string& url, | 84 FilterPtr Matches(const std::string& url, |
86 const std::string& contentType, | 85 const std::string& contentType, |
87 const std::vector<std::string>& documentUrls) const; | 86 const std::vector<std::string>& documentUrls) const; |
88 std::vector<std::string> GetElementHidingSelectors(const std::string& domain ) const; | 87 std::vector<std::string> GetElementHidingSelectors(const std::string& domain ) const; |
89 JsValuePtr GetPref(const std::string& pref) const; | 88 JsValuePtr GetPref(const std::string& pref) const; |
90 void SetPref(const std::string& pref, JsValuePtr value); | 89 void SetPref(const std::string& pref, JsValuePtr value); |
91 std::string GetHostFromURL(const std::string& url); | 90 std::string GetHostFromURL(const std::string& url); |
92 void ForceUpdateCheck(UpdaterCallback callback = 0); | 91 void ForceUpdateCheck(UpdaterCallback callback); |
Wladimir Palant
2014/07/11 14:29:11
Actually, there is one more actual code change her
sergei
2015/01/06 13:51:39
Actually, when do we need a default value here?
R
Felix Dahlke
2015/08/04 11:21:49
Probably some subtle differences between std::func
| |
93 void SetFilterChangeCallback(FilterChangeCallback callback); | 92 void SetFilterChangeCallback(FilterChangeCallback callback); |
94 void RemoveFilterChangeCallback(); | 93 void RemoveFilterChangeCallback(); |
95 | 94 |
96 private: | 95 private: |
97 JsEnginePtr jsEngine; | 96 JsEnginePtr jsEngine; |
98 bool initialized; | 97 bool initialized; |
99 bool firstRun; | 98 bool firstRun; |
100 int updateCheckId; | 99 int updateCheckId; |
101 | 100 |
102 void InitDone(JsValueList& params); | 101 void InitDone(JsValueList& params); |
103 FilterPtr CheckFilterMatch(const std::string& url, | 102 FilterPtr CheckFilterMatch(const std::string& url, |
104 const std::string& contentType, | 103 const std::string& contentType, |
105 const std::string& documentUrl) const; | 104 const std::string& documentUrl) const; |
106 void UpdateCheckDone(const std::string& eventName, UpdaterCallback callback, JsValueList& params); | 105 void UpdateCheckDone(const std::string& eventName, UpdaterCallback callback, JsValueList& params); |
107 void FilterChanged(FilterChangeCallback callback, JsValueList& params); | 106 void FilterChanged(FilterChangeCallback callback, JsValueList& params); |
108 }; | 107 }; |
109 } | 108 } |
110 | 109 |
111 #endif | 110 #endif |
OLD | NEW |