LEFT | RIGHT |
1 #include <AdblockPlus.h> | 1 #include <AdblockPlus.h> |
2 | 2 |
3 using namespace AdblockPlus; | 3 using namespace AdblockPlus; |
4 | 4 |
5 Subscription::Subscription(const std::string& title, const std::string& url) | 5 Subscription::Subscription(const std::string& url, const std::string& title) |
6 : title(title), url(url) | 6 : url(url), title(title) |
7 { | 7 { |
8 } | 8 } |
9 | 9 |
10 FilterEngine::FilterEngine(JsEngine& jsEngine) : jsEngine(jsEngine) | 10 FilterEngine::FilterEngine(JsEngine& jsEngine) : jsEngine(jsEngine) |
11 { | 11 { |
| 12 // TODO: Load ABP: |
| 13 // jsEngine.Load("adblockplus_compat.js"); |
| 14 // jsEngine.Load("adblockplus.js"); |
12 } | 15 } |
13 | 16 |
14 void FilterEngine::AddSubscription(Subscription subscription) | 17 void FilterEngine::AddSubscription(Subscription subscription) |
15 { | 18 { |
16 subscriptions.push_back(subscription); | 19 subscriptions.push_back(subscription); |
17 } | 20 } |
18 | 21 |
19 void FilterEngine::RemoveSubscription(const Subscription& subscription) | 22 void FilterEngine::RemoveSubscription(const Subscription& subscription) |
20 { | 23 { |
21 for (std::vector<Subscription>::iterator it = subscriptions.begin(); | 24 for (std::vector<Subscription>::iterator it = subscriptions.begin(); |
22 it != subscriptions.end();) | 25 it != subscriptions.end();) |
23 if (it->url == subscription.url) | 26 if (it->url == subscription.url) |
24 it = subscriptions.erase(it); | 27 it = subscriptions.erase(it); |
25 else | 28 else |
26 it++; | 29 it++; |
27 } | 30 } |
28 | 31 |
| 32 const Subscription* FilterEngine::FindSubscription(const std::string& url) const |
| 33 { |
| 34 for (std::vector<Subscription>::const_iterator it = subscriptions.begin(); |
| 35 it != subscriptions.end(); it++) |
| 36 if (it->url == url) |
| 37 return &(*it); |
| 38 return 0; |
| 39 } |
| 40 |
29 const std::vector<Subscription>& FilterEngine::GetSubscriptions() const | 41 const std::vector<Subscription>& FilterEngine::GetSubscriptions() const |
30 { | 42 { |
31 return subscriptions; | 43 return subscriptions; |
32 } | 44 } |
33 | 45 |
34 void FilterEngine::UpdateSubscriptionFilters(const Subscription& subscription) | 46 void FilterEngine::UpdateSubscriptionFilters(const Subscription& subscription) |
35 { | 47 { |
36 } | 48 } |
37 | 49 |
38 std::vector<Subscription> FilterEngine::FetchAvailableSubscriptions() | 50 std::vector<Subscription> FilterEngine::FetchAvailableSubscriptions() |
39 { | 51 { |
40 std::vector<Subscription> availableSubscriptions; | 52 std::vector<Subscription> availableSubscriptions; |
41 availableSubscriptions.push_back(Subscription("EasyList", "https://easylist-do
wnloads.adblockplus.org/easylist.txt")); | 53 availableSubscriptions.push_back(Subscription("https://easylist-downloads.adbl
ockplus.org/easylist.txt", "EasyList")); |
42 availableSubscriptions.push_back(Subscription("EasyList Germany+EasyList", "ht
tps://easylist-downloads.adblockplus.org/easylistgermany+easylist.txt")); | 54 availableSubscriptions.push_back(Subscription("https://easylist-downloads.adbl
ockplus.org/easylistgermany+easylist.txt", "EasyList Germany+EasyList")); |
43 return availableSubscriptions; | 55 return availableSubscriptions; |
44 } | 56 } |
45 | 57 |
46 bool FilterEngine::MatchesFilters(const std::string& url, | 58 bool FilterEngine::Matches(const std::string& url, |
47 const std::string& contentType) const | 59 const std::string& contentType) const |
48 { | 60 { |
49 return subscriptions.size() && url.length() % 2; | 61 return subscriptions.size() && url.length() % 2; |
50 } | 62 } |
51 | 63 |
52 std::vector<std::string> FilterEngine::GetElementHidingRules() const | 64 std::vector<std::string> FilterEngine::GetElementHidingRules() const |
53 { | 65 { |
54 std::vector<std::string> hidingRules; | 66 std::vector<std::string> hidingRules; |
55 hidingRules.push_back("###ad"); | 67 hidingRules.push_back("###ad"); |
56 hidingRules.push_back("##.ad"); | 68 hidingRules.push_back("##.ad"); |
57 return hidingRules; | 69 return hidingRules; |
58 } | 70 } |
LEFT | RIGHT |