| OLD | NEW |
| 1 /* | 1 /* |
| 2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
| 3 * Copyright (C) 2006-2015 Eyeo GmbH | 3 * Copyright (C) 2006-2015 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 <string> | 23 #include <string> |
| 24 #include <vector> | 24 #include <vector> |
| 25 #include <AdblockPlus/JsEngine.h> | 25 #include <AdblockPlus/JsEngine.h> |
| 26 #include <AdblockPlus/JsValue.h> | 26 #include <AdblockPlus/JsValue.h> |
| 27 #include <AdblockPlus/Notification.h> | 27 #include <AdblockPlus/Notification.h> |
| 28 | 28 |
| 29 #include "tr1_memory.h" | |
| 30 | |
| 31 namespace AdblockPlus | 29 namespace AdblockPlus |
| 32 { | 30 { |
| 33 class FilterEngine; | 31 class FilterEngine; |
| 34 | 32 |
| 35 /** | 33 /** |
| 36 * Wrapper for an Adblock Plus filter object. | 34 * Wrapper for an Adblock Plus filter object. |
| 37 * There are no accessors for most | 35 * There are no accessors for most |
| 38 * [filter properties](https://adblockplus.org/jsdoc/adblockplus/symbols/Filte
r.html), | 36 * [filter properties](https://adblockplus.org/jsdoc/adblockplus/symbols/Filte
r.html), |
| 39 * use `GetProperty()` to retrieve them by name. | 37 * use `GetProperty()` to retrieve them by name. |
| 40 */ | 38 */ |
| 41 class Filter : public JsValue, | 39 class Filter : public JsValue, |
| 42 public std::tr1::enable_shared_from_this<Filter> | 40 public std::enable_shared_from_this<Filter> |
| 43 { | 41 { |
| 44 public: | 42 public: |
| 45 /** | 43 /** |
| 46 * Filter types, see https://adblockplus.org/en/filters. | 44 * Filter types, see https://adblockplus.org/en/filters. |
| 47 */ | 45 */ |
| 48 enum Type {TYPE_BLOCKING, TYPE_EXCEPTION, | 46 enum Type {TYPE_BLOCKING, TYPE_EXCEPTION, |
| 49 TYPE_ELEMHIDE, TYPE_ELEMHIDE_EXCEPTION, | 47 TYPE_ELEMHIDE, TYPE_ELEMHIDE_EXCEPTION, |
| 50 TYPE_COMMENT, TYPE_INVALID}; | 48 TYPE_COMMENT, TYPE_INVALID}; |
| 51 | 49 |
| 52 /** | 50 /** |
| (...skipping 29 matching lines...) Expand all Loading... |
| 82 Filter(JsValuePtr value); | 80 Filter(JsValuePtr value); |
| 83 }; | 81 }; |
| 84 | 82 |
| 85 /** | 83 /** |
| 86 * Wrapper for a subscription object. | 84 * Wrapper for a subscription object. |
| 87 * There are no accessors for most | 85 * There are no accessors for most |
| 88 * [subscription properties](https://adblockplus.org/jsdoc/adblockplus/symbols
/Subscription.html), | 86 * [subscription properties](https://adblockplus.org/jsdoc/adblockplus/symbols
/Subscription.html), |
| 89 * use `GetProperty()` to retrieve them by name. | 87 * use `GetProperty()` to retrieve them by name. |
| 90 */ | 88 */ |
| 91 class Subscription : public JsValue, | 89 class Subscription : public JsValue, |
| 92 public std::tr1::enable_shared_from_this<Subscription> | 90 public std::enable_shared_from_this<Subscription> |
| 93 { | 91 { |
| 94 public: | 92 public: |
| 95 /** | 93 /** |
| 96 * Checks if this subscription has been added to the list of subscriptions. | 94 * Checks if this subscription has been added to the list of subscriptions. |
| 97 * @return `true` if this subscription has been added. | 95 * @return `true` if this subscription has been added. |
| 98 */ | 96 */ |
| 99 bool IsListed(); | 97 bool IsListed(); |
| 100 | 98 |
| 101 /** | 99 /** |
| 102 * Adds this subscription to the list of subscriptions. | 100 * Adds this subscription to the list of subscriptions. |
| (...skipping 24 matching lines...) Expand all Loading... |
| 127 * Normally you shouldn't call this directly, but use | 125 * Normally you shouldn't call this directly, but use |
| 128 * FilterEngine::GetSubscription() instead. | 126 * FilterEngine::GetSubscription() instead. |
| 129 * @param value JavaScript subscription object. | 127 * @param value JavaScript subscription object. |
| 130 */ | 128 */ |
| 131 Subscription(JsValuePtr value); | 129 Subscription(JsValuePtr value); |
| 132 }; | 130 }; |
| 133 | 131 |
| 134 /** | 132 /** |
| 135 * Shared smart pointer to a `Filter` instance. | 133 * Shared smart pointer to a `Filter` instance. |
| 136 */ | 134 */ |
| 137 typedef std::tr1::shared_ptr<Filter> FilterPtr; | 135 typedef std::shared_ptr<Filter> FilterPtr; |
| 138 | 136 |
| 139 /** | 137 /** |
| 140 * Shared smart pointer to a `Subscription` instance. | 138 * Shared smart pointer to a `Subscription` instance. |
| 141 */ | 139 */ |
| 142 typedef std::tr1::shared_ptr<Subscription> SubscriptionPtr; | 140 typedef std::shared_ptr<Subscription> SubscriptionPtr; |
| 143 | 141 |
| 144 /** | 142 /** |
| 145 * Main component of libadblockplus. | 143 * Main component of libadblockplus. |
| 146 * It handles: | 144 * It handles: |
| 147 * - Filter management and matching. | 145 * - Filter management and matching. |
| 148 * - Subscription management and synchronization. | 146 * - Subscription management and synchronization. |
| 149 * - Update checks for the application. | 147 * - Update checks for the application. |
| 150 */ | 148 */ |
| 151 class FilterEngine | 149 class FilterEngine |
| 152 { | 150 { |
| 153 public: | 151 public: |
| 154 // Make sure to keep ContentType in sync with FilterEngine::contentTypes | 152 // Make sure to keep ContentType in sync with FilterEngine::contentTypes |
| 155 /** | 153 /** |
| 156 * Possible resource content types. | 154 * Possible resource content types. |
| 157 */ | 155 */ |
| 158 enum ContentType {CONTENT_TYPE_OTHER, CONTENT_TYPE_SCRIPT, | 156 enum ContentType {CONTENT_TYPE_OTHER, CONTENT_TYPE_SCRIPT, |
| 159 CONTENT_TYPE_IMAGE, CONTENT_TYPE_STYLESHEET, | 157 CONTENT_TYPE_IMAGE, CONTENT_TYPE_STYLESHEET, |
| 160 CONTENT_TYPE_OBJECT, CONTENT_TYPE_SUBDOCUMENT, | 158 CONTENT_TYPE_OBJECT, CONTENT_TYPE_SUBDOCUMENT, |
| 161 CONTENT_TYPE_DOCUMENT, CONTENT_TYPE_XMLHTTPREQUEST, | 159 CONTENT_TYPE_DOCUMENT, CONTENT_TYPE_XMLHTTPREQUEST, |
| 162 CONTENT_TYPE_OBJECT_SUBREQUEST, CONTENT_TYPE_FONT, | 160 CONTENT_TYPE_OBJECT_SUBREQUEST, CONTENT_TYPE_FONT, |
| 163 CONTENT_TYPE_MEDIA, CONTENT_TYPE_ELEMHIDE}; | 161 CONTENT_TYPE_MEDIA, CONTENT_TYPE_ELEMHIDE}; |
| 164 | 162 |
| 165 /** | 163 /** |
| 166 * Callback type invoked when an update becomes available. | 164 * Callback type invoked when an update becomes available. |
| 167 * The parameter is the download URL of the update. | 165 * The parameter is the download URL of the update. |
| 168 */ | 166 */ |
| 169 typedef std::tr1::function<void(const std::string&)> | 167 typedef std::function<void(const std::string&)> UpdateAvailableCallback; |
| 170 UpdateAvailableCallback; | |
| 171 | 168 |
| 172 /** | 169 /** |
| 173 * Callback type invoked when a manually triggered update check finishes. | 170 * Callback type invoked when a manually triggered update check finishes. |
| 174 * The parameter is an optional error message. | 171 * The parameter is an optional error message. |
| 175 */ | 172 */ |
| 176 typedef std::tr1::function<void(const std::string&)> | 173 typedef std::function<void(const std::string&)> UpdateCheckDoneCallback; |
| 177 UpdateCheckDoneCallback; | |
| 178 | 174 |
| 179 /** | 175 /** |
| 180 * Callback type invoked when the filters change. | 176 * Callback type invoked when the filters change. |
| 181 * The first parameter is the action event code (see | 177 * The first parameter is the action event code (see |
| 182 * [FilterNotifier.triggerListeners](https://adblockplus.org/jsdoc/adblockpl
us/symbols/FilterNotifier.html#.triggerListeners) | 178 * [FilterNotifier.triggerListeners](https://adblockplus.org/jsdoc/adblockpl
us/symbols/FilterNotifier.html#.triggerListeners) |
| 183 * for the full list). | 179 * for the full list). |
| 184 * The second parameter is the filter/subscription object affected, if any. | 180 * The second parameter is the filter/subscription object affected, if any. |
| 185 */ | 181 */ |
| 186 typedef std::tr1::function<void(const std::string&, const JsValuePtr)> Filte
rChangeCallback; | 182 typedef std::function<void(const std::string&, const JsValuePtr)> FilterChan
geCallback; |
| 187 | 183 |
| 188 /** | 184 /** |
| 189 * Container of name-value pairs representing a set of preferences. | 185 * Container of name-value pairs representing a set of preferences. |
| 190 */ | 186 */ |
| 191 typedef std::map<std::string, AdblockPlus::JsValuePtr> Prefs; | 187 typedef std::map<std::string, AdblockPlus::JsValuePtr> Prefs; |
| 192 | 188 |
| 193 /** | 189 /** |
| 194 * Callback type invoked when a new notification should be shown. | 190 * Callback type invoked when a new notification should be shown. |
| 195 * The parameter is the Notification object to be shown. | 191 * The parameter is the Notification object to be shown. |
| 196 */ | 192 */ |
| 197 typedef std::tr1::function<void(const NotificationPtr&)> ShowNotificationCal
lback; | 193 typedef std::function<void(const NotificationPtr&)> ShowNotificationCallback
; |
| 198 | 194 |
| 199 /** | 195 /** |
| 200 * Constructor. | 196 * Constructor. |
| 201 * @param jsEngine `JsEngine` instance used to run JavaScript code | 197 * @param jsEngine `JsEngine` instance used to run JavaScript code |
| 202 * internally. | 198 * internally. |
| 203 * @param preconfiguredPrefs `AdblockPlus::FilterEngine::Prefs` | 199 * @param preconfiguredPrefs `AdblockPlus::FilterEngine::Prefs` |
| 204 * name-value list of preconfigured prefs. | 200 * name-value list of preconfigured prefs. |
| 205 */ | 201 */ |
| 206 explicit FilterEngine(JsEnginePtr jsEngine, | 202 explicit FilterEngine(JsEnginePtr jsEngine, |
| 207 const Prefs& preconfiguredPrefs = Prefs() | 203 const Prefs& preconfiguredPrefs = Prefs() |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 * `FilterEngine` will automatically check for updates in regular intervals, | 344 * `FilterEngine` will automatically check for updates in regular intervals, |
| 349 * so applications should only call this when the user triggers an update | 345 * so applications should only call this when the user triggers an update |
| 350 * check manually. | 346 * check manually. |
| 351 * @param callback Optional callback to invoke when the update check is | 347 * @param callback Optional callback to invoke when the update check is |
| 352 * finished. The string parameter will be empty when the update check | 348 * finished. The string parameter will be empty when the update check |
| 353 * succeeded, or contain an error message if it failed. | 349 * succeeded, or contain an error message if it failed. |
| 354 * Note that the callback will be invoked whether updates are | 350 * Note that the callback will be invoked whether updates are |
| 355 * available or not - to react to updates being available, use | 351 * available or not - to react to updates being available, use |
| 356 * `FilterEngine::SetUpdateAvailableCallback()`. | 352 * `FilterEngine::SetUpdateAvailableCallback()`. |
| 357 */ | 353 */ |
| 358 void ForceUpdateCheck(UpdateCheckDoneCallback callback = 0); | 354 void ForceUpdateCheck(UpdateCheckDoneCallback callback); |
| 359 | 355 |
| 360 /** | 356 /** |
| 361 * Sets the callback invoked when the filters change. | 357 * Sets the callback invoked when the filters change. |
| 362 * @param callback Callback to invoke. | 358 * @param callback Callback to invoke. |
| 363 */ | 359 */ |
| 364 void SetFilterChangeCallback(FilterChangeCallback callback); | 360 void SetFilterChangeCallback(FilterChangeCallback callback); |
| 365 | 361 |
| 366 /** | 362 /** |
| 367 * Removes the callback invoked when the filters change. | 363 * Removes the callback invoked when the filters change. |
| 368 */ | 364 */ |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 void UpdateAvailable(UpdateAvailableCallback callback, JsValueList& params); | 406 void UpdateAvailable(UpdateAvailableCallback callback, JsValueList& params); |
| 411 void UpdateCheckDone(const std::string& eventName, | 407 void UpdateCheckDone(const std::string& eventName, |
| 412 UpdateCheckDoneCallback callback, JsValueList& params); | 408 UpdateCheckDoneCallback callback, JsValueList& params); |
| 413 void FilterChanged(FilterChangeCallback callback, JsValueList& params); | 409 void FilterChanged(FilterChangeCallback callback, JsValueList& params); |
| 414 void ShowNotification(const ShowNotificationCallback& callback, | 410 void ShowNotification(const ShowNotificationCallback& callback, |
| 415 const JsValueList& params); | 411 const JsValueList& params); |
| 416 }; | 412 }; |
| 417 } | 413 } |
| 418 | 414 |
| 419 #endif | 415 #endif |
| OLD | NEW |