18 #ifndef ADBLOCK_PLUS_FILTER_ENGINE_H
19 #define ADBLOCK_PLUS_FILTER_ENGINE_H
25 #include <AdblockPlus/JsEngine.h>
26 #include <AdblockPlus/JsValue.h>
27 #include <AdblockPlus/Notification.h>
32 typedef std::shared_ptr<FilterEngine> FilterEnginePtr;
52 enum Type {TYPE_BLOCKING, TYPE_EXCEPTION,
53 TYPE_ELEMHIDE, TYPE_ELEMHIDE_EXCEPTION,
54 TYPE_ELEMHIDE_EMULATION,
55 TYPE_COMMENT, TYPE_INVALID};
79 bool operator==(
const Filter& filter)
const;
168 bool operator==(
const Subscription& subscription)
const;
202 CONTENT_TYPE_OTHER = 1,
203 CONTENT_TYPE_SCRIPT = 2,
204 CONTENT_TYPE_IMAGE = 4,
205 CONTENT_TYPE_STYLESHEET = 8,
206 CONTENT_TYPE_OBJECT = 16,
207 CONTENT_TYPE_SUBDOCUMENT = 32,
208 CONTENT_TYPE_DOCUMENT = 64,
209 CONTENT_TYPE_WEBSOCKET = 128,
210 CONTENT_TYPE_WEBRTC = 256,
211 CONTENT_TYPE_PING = 1024,
212 CONTENT_TYPE_XMLHTTPREQUEST = 2048,
213 CONTENT_TYPE_OBJECT_SUBREQUEST = 4096,
214 CONTENT_TYPE_MEDIA = 16384,
215 CONTENT_TYPE_FONT = 32768,
216 CONTENT_TYPE_GENERICBLOCK = 0x20000000,
217 CONTENT_TYPE_ELEMHIDE = 0x40000000,
218 CONTENT_TYPE_GENERICHIDE = 0x80000000
252 typedef std::map<std::string, AdblockPlus::JsValue>
Prefs;
299 const OnCreatedCallback& onCreated,
401 FilterPtr
Matches(
const std::string& url,
402 ContentTypeMask contentTypeMask,
403 const std::string& documentUrl)
const;
418 FilterPtr
Matches(
const std::string& url,
419 ContentTypeMask contentTypeMask,
420 const std::vector<std::string>& documentUrls)
const;
434 const std::vector<std::string>& documentUrls)
const;
448 const std::vector<std::string>& documentUrls)
const;
540 int CompareVersions(
const std::string& v1,
const std::string& v2)
const;
562 static const std::map<ContentType, std::string> contentTypes;
566 FilterPtr CheckFilterMatch(
const std::string& url,
567 ContentTypeMask contentTypeMask,
568 const std::string& documentUrl)
const;
569 void FilterChanged(
const FilterChangeCallback& callback,
JsValueList&& params)
const;
570 FilterPtr GetWhitelistingFilter(
const std::string& url,
571 ContentTypeMask contentTypeMask,
const std::string& documentUrl)
const;
572 FilterPtr GetWhitelistingFilter(
const std::string& url,
573 ContentTypeMask contentTypeMask,
574 const std::vector<std::string>& documentUrls)
const;
bool IsAA() const
Indicates whether the subscription is the Acceptable Ads subscription.
Subscription(const Subscription &src)
Copy constructor.
int CompareVersions(const std::string &v1, const std::string &v2) const
Compares two version strings in Mozilla toolkit version format.
void AddToList()
Adds this subscription to the list of subscriptions.
bool IsUpdating() const
Checks if the subscription is currently being updated.
void SetAAEnabled(bool enabled)
Ensures that the Acceptable Ads subscription is enabled or disabled.
void ForceUpdateCheck(const UpdateCheckDoneCallback &callback=UpdateCheckDoneCallback())
Forces an immediate update check.
bool IsElemhideWhitelisted(const std::string &url, const std::vector< std::string > &documentUrls) const
Checks whether element hiding is disabled at the supplied URL.
JavaScript engine used by FilterEngine, wraps v8.
Definition: JsEngine.h:73
static ContentType StringToContentType(const std::string &contentType)
Retrieves the ContentType for the supplied string.
Wrapper for an Adblock Plus filter object.
Definition: FilterEngine.h:40
std::vector< AdblockPlus::JsValue > JsValueList
List of JavaScript values.
Definition: JsValue.h:48
bool IsFirstRun() const
Checks if this is the first run of the application.
bool IsDisabled() const
Checks if the subscription is disabled.
std::function< void(const std::string &)> UpdateCheckDoneCallback
Callback type invoked when a manually triggered update check finishes.
Definition: FilterEngine.h:238
bool IsDocumentWhitelisted(const std::string &url, const std::vector< std::string > &documentUrls) const
Checks whether the document at the supplied URL is whitelisted.
Wrapper for JavaScript values.
Definition: JsValue.h:54
bool IsAAEnabled() const
Checks whether the Acceptable Ads subscription is enabled.
void ShowNextNotification(const std::string &url=std::string()) const
Invokes the listener set via SetNotificationAvailableCallback() with the next notification to be show...
void SetUpdateAvailableCallback(const UpdateAvailableCallback &callback)
Sets the callback invoked when an application update becomes available.
Subscription & operator=(const Subscription &src)
Assignment operator.
void SetShowNotificationCallback(const ShowNotificationCallback &value)
Sets the callback invoked when a notification should be shown.
std::map< std::string, AdblockPlus::JsValue > Prefs
Container of name-value pairs representing a set of preferences.
Definition: FilterEngine.h:252
IsConnectionAllowedAsyncCallback isSubscriptionDownloadAllowedCallback
A callback of AdblockPlus::FilterEngine::IsConnectionAllowedAsyncCallback type checking whether the r...
Definition: FilterEngine.h:282
std::string GetHostFromURL(const std::string &url) const
Extracts the host from a URL.
Main component of libadblockplus.
Definition: FilterEngine.h:192
void RemoveFromList()
Removes this filter from the list of custom filters.
Main namespace of libadblockplus.
Definition: ActiveObject.h:23
void RemoveUpdateAvailableCallback()
Removes the callback invoked when an application update becomes available.
ContentType
Possible resource content types.
Definition: FilterEngine.h:200
void SetAllowedConnectionType(const std::string *value)
Stores the value indicating what connection types are allowed, it is passed to CreateParameters::isCo...
static std::string ContentTypeToString(ContentType contentType)
Retrieves the string representation of the supplied ContentType.
void SetPref(const std::string &pref, const JsValue &value)
Sets a preference value.
void RemoveFromList()
Removes this subscription from the list of subscriptions.
std::function< void(const std::string &, JsValue &&)> FilterChangeCallback
Callback type invoked when the filters change.
Definition: FilterEngine.h:247
std::unique_ptr< Filter > FilterPtr
A smart pointer to a Filter instance.
Definition: FilterEngine.h:183
void SetFilterChangeCallback(const FilterChangeCallback &callback)
Sets the callback invoked when the filters change.
Filter GetFilter(const std::string &text) const
Retrieves a filter object from its text representation.
FilterPtr Matches(const std::string &url, ContentTypeMask contentTypeMask, const std::string &documentUrl) const
Checks if any active filter matches the supplied URL.
std::vector< std::string > GetElementHidingSelectors(const std::string &domain) const
Retrieves CSS selectors for all element hiding filters active on the supplied domain.
void SetDisabled(bool value)
Allows to enable or disable current subscription.
JsEngine & GetJsEngine() const
Retrieves the JsEngine instance associated with this FilterEngine instance.
Definition: FilterEngine.h:306
Type
Filter types, see https://adblockplus.org/en/filters.
Definition: FilterEngine.h:52
std::vector< Subscription > GetListedSubscriptions() const
Retrieves all subscriptions.
void RemoveFilterChangeCallback()
Removes the callback invoked when the filters change.
std::function< void(const FilterEnginePtr &)> OnCreatedCallback
Callback type invoked when FilterEngine is created.
Definition: FilterEngine.h:288
std::function< void(const std::string &)> UpdateAvailableCallback
Callback type invoked when an update becomes available.
Definition: FilterEngine.h:232
Type GetType() const
Retrieves the type of this filter.
FilterEngine creation parameters.
Definition: FilterEngine.h:270
std::vector< Filter > GetListedFilters() const
Retrieves the list of custom filters.
bool IsListed() const
Checks whether this filter has been added to the list of custom filters.
std::vector< Subscription > FetchAvailableSubscriptions() const
Retrieves all recommended subscriptions.
bool IsListed() const
Checks if this subscription has been added to the list of subscriptions.
void AddToList()
Adds this filter to the list of custom filters.
std::function< void(const std::string *allowedConnectionType, const std::function< void(bool)> &)> IsConnectionAllowedAsyncCallback
Asynchronous callback function passing false when current connection type does not correspond to allo...
Definition: FilterEngine.h:265
static void CreateAsync(const JsEnginePtr &jsEngine, const OnCreatedCallback &onCreated, const CreationParameters ¶meters=CreationParameters())
Asynchronously constructs FilterEngine.
void UpdateFilters()
Updates this subscription, i.e. retrieves the current filters from the subscription URL...
int32_t ContentTypeMask
Bitmask of ContentType values.
Definition: FilterEngine.h:226
std::function< void(Notification &&)> ShowNotificationCallback
Callback type invoked when a new notification should be shown.
Definition: FilterEngine.h:258
void RemoveShowNotificationCallback()
Removes the callback invoked when a notification should be shown.
Prefs preconfiguredPrefs
AdblockPlus::FilterEngine::Prefs name - value list of preconfigured prefs.
Definition: FilterEngine.h:276
std::unique_ptr< std::string > GetAllowedConnectionType() const
Retrieves previously stored allowed connection type.
JsValue GetPref(const std::string &pref) const
Retrieves a preference value.
Subscription GetSubscription(const std::string &url) const
Retrieves a subscription object for the supplied URL.
std::string GetAAUrl() const
Retrieves the URL of the Acceptable Ads subscription, what makes the URL available even if subscripti...
std::shared_ptr< JsEngine > JsEnginePtr
Shared smart pointer to a JsEngine instance.
Definition: JsEngine.h:48
Wrapper for a subscription object.
Definition: FilterEngine.h:97