Index: include/AdblockPlus/JsEngine.h |
diff --git a/include/AdblockPlus/JsEngine.h b/include/AdblockPlus/JsEngine.h |
index 34f7d80eacce44466299c444e16d064c6d05aa79..37f04dd51e5dd5ea520f6e946614844971b74d26 100644 |
--- a/include/AdblockPlus/JsEngine.h |
+++ b/include/AdblockPlus/JsEngine.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 |
@@ -23,6 +23,7 @@ |
#include <stdexcept> |
#include <stdint.h> |
#include <string> |
+#include <mutex> |
#include <AdblockPlus/AppInfo.h> |
#include <AdblockPlus/LogSystem.h> |
#include <AdblockPlus/FileSystem.h> |
@@ -88,6 +89,12 @@ namespace AdblockPlus |
typedef std::function<void(JsValueList& params)> EventCallback; |
/** |
+ * Callback function returning false when current connection is not allowed |
+ * e.g. because it is a metered connection. |
+ */ |
+ typedef std::function<bool()> IsConnectionAllowedCallback; |
+ |
+ /** |
* Maps events to callback functions. |
*/ |
typedef std::map<std::string, EventCallback> EventMap; |
@@ -222,6 +229,19 @@ namespace AdblockPlus |
void SetWebRequest(WebRequestPtr val); |
/** |
+ * Registers the callback function to check whether current connection is |
+ * allowed for network requests. |
+ * @param callback callback function. |
+ */ |
+ void SetIsConnectionAllowedCallback(const IsConnectionAllowedCallback& callback); |
+ |
+ /** |
+ * Checks whether current connection is allowed. If |
+ * IsConnectionAllowedCallback is not set then then it returns true. |
+ */ |
+ bool IsConnectionAllowed(); |
+ |
+ /** |
* @see `SetLogSystem()`. |
*/ |
LogSystemPtr GetLogSystem(); |
@@ -264,6 +284,9 @@ namespace AdblockPlus |
LogSystemPtr logSystem; |
std::unique_ptr<v8::Persistent<v8::Context>> context; |
EventMap eventCallbacks; |
+ std::mutex eventCallbacksMutex; |
+ std::mutex isConnectionAllowedMutex; |
+ IsConnectionAllowedCallback isConnectionAllowed; |
}; |
} |