Index: include/AdblockPlus/FilterEngine.h |
diff --git a/include/AdblockPlus/FilterEngine.h b/include/AdblockPlus/FilterEngine.h |
index 94b376eb8caadee35db2d4b96893ee5b0702b16d..11098d68d3a5c09c5e56db2298f35852a7da4697 100644 |
--- a/include/AdblockPlus/FilterEngine.h |
+++ b/include/AdblockPlus/FilterEngine.h |
@@ -1,6 +1,6 @@ |
/* |
* This file is part of Adblock Plus <https://adblockplus.org/>, |
- * Copyright (C) 2006-2016 Eyeo GmbH |
+ * Copyright (C) 2006-2017 eyeo GmbH |
* |
* Adblock Plus is free software: you can redistribute it and/or modify |
* it under the terms of the GNU General Public License version 3 as |
@@ -29,6 +29,7 @@ |
namespace AdblockPlus |
{ |
class FilterEngine; |
+ typedef std::shared_ptr<FilterEngine> FilterEnginePtr; |
/** |
* Wrapper for an Adblock Plus filter object. |
@@ -213,15 +214,52 @@ namespace AdblockPlus |
typedef std::function<void(const NotificationPtr&)> ShowNotificationCallback; |
/** |
- * Constructor. |
+ * Callback function returning false when current connection is not |
+ * allowedConnectionType, e.g. because it is a metered connection. |
+ */ |
+ typedef std::function<bool(const std::string* allowedConnectionType)> IsConnectionAllowedCallback; |
+ |
+ /** |
+ * FilterEngine creation parameters. |
+ */ |
+ struct CreationParameters |
+ { |
+ /** |
+ * `AdblockPlus::FilterEngine::Prefs` name - value list of preconfigured |
+ * prefs. |
+ */ |
+ Prefs preconfiguredPrefs; |
+ /** |
+ * `AdblockPlus::FilterEngine::IsConnectionAllowedCallback` a callback |
+ * checking whether the request from Adblock Plus should be blocked on |
+ * the current connection. |
+ */ |
+ IsConnectionAllowedCallback isConnectionAllowedCallback; |
+ }; |
+ |
+ /** |
+ * Callback type invoked when FilterEngine is created. |
+ */ |
+ typedef std::function<void(const FilterEnginePtr&)> OnCreatedCallback; |
+ |
+ /** |
+ * Asynchronously constructs FilterEngine. |
* @param jsEngine `JsEngine` instance used to run JavaScript code |
* internally. |
- * @param preconfiguredPrefs `AdblockPlus::FilterEngine::Prefs` |
- * name-value list of preconfigured prefs. |
+ * @param onCreated A callback which is called when FilterEngine is ready |
+ * for use. |
+ * @param parameters optional creation parameters. |
*/ |
- explicit FilterEngine(JsEnginePtr jsEngine, |
- const Prefs& preconfiguredPrefs = Prefs() |
- ); |
+ static void CreateAsync(const JsEnginePtr& jsEngine, |
+ const OnCreatedCallback& onCreated, |
+ const CreationParameters& parameters = CreationParameters()); |
+ |
+ /** |
+ * Synchronous interface to construct FilterEngine. For details see |
+ * asynchronous version CreateAsync. |
+ */ |
+ static FilterEnginePtr Create(const JsEnginePtr& jsEngine, |
+ const CreationParameters& params = CreationParameters()); |
/** |
* Retrieves the `JsEngine` instance associated with this `FilterEngine` |
@@ -399,7 +437,7 @@ namespace AdblockPlus |
* available or not - to react to updates being available, use |
* `FilterEngine::SetUpdateAvailableCallback()`. |
*/ |
- void ForceUpdateCheck(UpdateCheckDoneCallback callback); |
+ void ForceUpdateCheck(const UpdateCheckDoneCallback& callback = UpdateCheckDoneCallback()); |
/** |
* Sets the callback invoked when the filters change. |
@@ -413,6 +451,20 @@ namespace AdblockPlus |
void RemoveFilterChangeCallback(); |
/** |
+ * Stores the value indicating what connection types are allowed, it is |
+ * passed to CreateParameters::isConnectionAllowed callback. |
+ * @param value Stored value. nullptr means removing of any previously |
+ * stored value. |
+ */ |
+ void SetAllowedConnectionType(const std::string* value); |
+ |
+ /** |
+ * Retrieves previously stored allowed connection type. |
+ * @return Preference value, or `nullptr` if it doesn't exist. |
+ */ |
+ std::unique_ptr<std::string> GetAllowedConnectionType(); |
+ |
+ /** |
* Compares two version strings in |
* [Mozilla toolkit version format](https://developer.mozilla.org/en/docs/Toolkit_version_format). |
* @param v1 First version string. |
@@ -442,12 +494,12 @@ namespace AdblockPlus |
private: |
JsEnginePtr jsEngine; |
- bool initialized; |
bool firstRun; |
int updateCheckId; |
static const std::map<ContentType, std::string> contentTypes; |
- void InitDone(JsValueList& params); |
+ explicit FilterEngine(const JsEnginePtr& jsEngine); |
+ |
FilterPtr CheckFilterMatch(const std::string& url, |
ContentTypeMask contentTypeMask, |
const std::string& documentUrl) const; |