| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 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-2013 Eyeo GmbH | 3 * Copyright (C) 2006-2013 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 <vector> | 21 #include <functional> |
| 22 #include <map> | 22 #include <map> |
| 23 #include <string> | 23 #include <string> |
| 24 #include <vector> | |
| 24 #include <AdblockPlus/JsEngine.h> | 25 #include <AdblockPlus/JsEngine.h> |
| 25 #include <AdblockPlus/JsValue.h> | 26 #include <AdblockPlus/JsValue.h> |
| 26 | 27 |
| 27 #include "tr1_memory.h" | 28 #include "tr1_memory.h" |
| 28 | 29 |
| 29 namespace AdblockPlus | 30 namespace AdblockPlus |
| 30 { | 31 { |
| 31 class FilterEngine; | 32 class FilterEngine; |
| 32 | 33 |
| 33 class Filter : public JsValue, | 34 class Filter : public JsValue, |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 60 | 61 |
| 61 Subscription(JsValuePtr value); | 62 Subscription(JsValuePtr value); |
| 62 }; | 63 }; |
| 63 | 64 |
| 64 typedef std::tr1::shared_ptr<Filter> FilterPtr; | 65 typedef std::tr1::shared_ptr<Filter> FilterPtr; |
| 65 typedef std::tr1::shared_ptr<Subscription> SubscriptionPtr; | 66 typedef std::tr1::shared_ptr<Subscription> SubscriptionPtr; |
| 66 | 67 |
| 67 class FilterEngine | 68 class FilterEngine |
| 68 { | 69 { |
| 69 public: | 70 public: |
| 70 typedef void(*UpdaterCallback)(const std::string& error); | 71 typedef std::function<void(const std::string&)> UpdaterCallback; |
| 71 | 72 |
| 72 explicit FilterEngine(JsEnginePtr jsEngine); | 73 explicit FilterEngine(JsEnginePtr jsEngine); |
| 73 JsEnginePtr GetJsEngine() const { return jsEngine; } | 74 JsEnginePtr GetJsEngine() const { return jsEngine; } |
| 74 bool IsFirstRun() const; | 75 bool IsFirstRun() const; |
| 75 FilterPtr GetFilter(const std::string& text); | 76 FilterPtr GetFilter(const std::string& text); |
| 76 SubscriptionPtr GetSubscription(const std::string& url); | 77 SubscriptionPtr GetSubscription(const std::string& url); |
| 77 std::vector<FilterPtr> GetListedFilters() const; | 78 std::vector<FilterPtr> GetListedFilters() const; |
| 78 std::vector<SubscriptionPtr> GetListedSubscriptions() const; | 79 std::vector<SubscriptionPtr> GetListedSubscriptions() const; |
| 79 std::vector<SubscriptionPtr> FetchAvailableSubscriptions() const; | 80 std::vector<SubscriptionPtr> FetchAvailableSubscriptions() const; |
| 80 FilterPtr Matches(const std::string& url, | 81 FilterPtr Matches(const std::string& url, |
| 81 const std::string& contentType, | 82 const std::string& contentType, |
| 82 const std::string& documentUrl) const; | 83 const std::string& documentUrl) const; |
| 83 std::vector<std::string> GetElementHidingSelectors(const std::string& domain ) const; | 84 std::vector<std::string> GetElementHidingSelectors(const std::string& domain ) const; |
| 84 JsValuePtr GetPref(const std::string& pref) const; | 85 JsValuePtr GetPref(const std::string& pref) const; |
| 85 void SetPref(const std::string& pref, JsValuePtr value); | 86 void SetPref(const std::string& pref, JsValuePtr value); |
| 86 void ForceUpdateCheck(UpdaterCallback callback = 0); | 87 void ForceUpdateCheck(UpdaterCallback callback = 0); |
|
Felix Dahlke
2013/06/05 15:47:36
I suppose you considered using an std::function he
Wladimir Palant
2013/06/05 18:58:21
No, I somehow forgot about that option. Works fine
| |
| 87 | 88 |
| 88 private: | 89 private: |
| 89 JsEnginePtr jsEngine; | 90 JsEnginePtr jsEngine; |
| 90 bool initialized; | 91 bool initialized; |
| 91 bool firstRun; | 92 bool firstRun; |
| 92 int updateCheckId; | 93 int updateCheckId; |
| 93 | 94 |
| 94 void InitDone(JsValueList& params); | 95 void InitDone(JsValueList& params); |
| 95 void UpdateCheckDone(std::string eventName, UpdaterCallback callback, JsValu eList& params); | 96 void UpdateCheckDone(const std::string& eventName, UpdaterCallback callback, JsValueList& params); |
|
Felix Dahlke
2013/06/05 15:47:36
Any reason why eventName is not a const string ref
Wladimir Palant
2013/06/05 18:58:21
I had concerns where that reference would point to
| |
| 96 }; | 97 }; |
| 97 } | 98 } |
| 98 | 99 |
| 99 #endif | 100 #endif |
| LEFT | RIGHT |