| Index: include/AdblockPlus/FilterEngine.h |
| =================================================================== |
| --- a/include/AdblockPlus/FilterEngine.h |
| +++ b/include/AdblockPlus/FilterEngine.h |
| @@ -1,11 +1,11 @@ |
| /* |
| * This file is part of Adblock Plus <https://adblockplus.org/>, |
| - * Copyright (C) 2006-2015 Eyeo GmbH |
| + * Copyright (C) 2006-2016 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 |
| * published by the Free Software Foundation. |
| * |
| * Adblock Plus is distributed in the hope that it will be useful, |
| * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| @@ -28,17 +28,17 @@ |
| namespace AdblockPlus |
| { |
| class FilterEngine; |
| /** |
| * Wrapper for an Adblock Plus filter object. |
| * There are no accessors for most |
| - * [filter properties](https://adblockplus.org/jsdoc/adblockplus/symbols/Filter.html), |
| + * [filter properties](https://adblockplus.org/jsdoc/adblockpluscore/Filter.html), |
| * use `GetProperty()` to retrieve them by name. |
| */ |
| class Filter : public JsValue, |
| public std::enable_shared_from_this<Filter> |
| { |
| public: |
| /** |
| * Filter types, see https://adblockplus.org/en/filters. |
| @@ -72,23 +72,23 @@ namespace AdblockPlus |
| bool operator==(const Filter& filter) const; |
| /** |
| * Creates a wrapper for an existing JavaScript filter object. |
| * Normally you shouldn't call this directly, but use |
| * FilterEngine::GetFilter() instead. |
| * @param value JavaScript filter object. |
| */ |
| - Filter(JsValuePtr value); |
| + Filter(JsValue&& value); |
| }; |
| /** |
| * Wrapper for a subscription object. |
| * There are no accessors for most |
| - * [subscription properties](https://adblockplus.org/jsdoc/adblockplus/symbols/Subscription.html), |
| + * [subscription properties](https://adblockplus.org/jsdoc/adblockpluscore/Subscription.html), |
| * use `GetProperty()` to retrieve them by name. |
| */ |
| class Subscription : public JsValue, |
| public std::enable_shared_from_this<Subscription> |
| { |
| public: |
| /** |
| * Checks if this subscription has been added to the list of subscriptions. |
| @@ -121,17 +121,17 @@ namespace AdblockPlus |
| bool operator==(const Subscription& subscription) const; |
| /** |
| * Creates a wrapper for an existing JavaScript subscription object. |
| * Normally you shouldn't call this directly, but use |
| * FilterEngine::GetSubscription() instead. |
| * @param value JavaScript subscription object. |
| */ |
| - Subscription(JsValuePtr value); |
| + Subscription(JsValue&& value); |
| }; |
| /** |
| * Shared smart pointer to a `Filter` instance. |
| */ |
| typedef std::shared_ptr<Filter> FilterPtr; |
| /** |
| @@ -145,42 +145,62 @@ namespace AdblockPlus |
| * - Filter management and matching. |
| * - Subscription management and synchronization. |
| * - Update checks for the application. |
| */ |
| class FilterEngine |
| { |
| public: |
| // Make sure to keep ContentType in sync with FilterEngine::contentTypes |
| + // and with RegExpFilter.typeMap from filterClasses.js. |
| /** |
| * Possible resource content types. |
| */ |
| - enum ContentType {CONTENT_TYPE_OTHER, CONTENT_TYPE_SCRIPT, |
| - CONTENT_TYPE_IMAGE, CONTENT_TYPE_STYLESHEET, |
| - CONTENT_TYPE_OBJECT, CONTENT_TYPE_SUBDOCUMENT, |
| - CONTENT_TYPE_DOCUMENT, CONTENT_TYPE_XMLHTTPREQUEST, |
| - CONTENT_TYPE_OBJECT_SUBREQUEST, CONTENT_TYPE_FONT, |
| - CONTENT_TYPE_MEDIA, CONTENT_TYPE_ELEMHIDE}; |
| + enum ContentType |
| + { |
| + CONTENT_TYPE_OTHER = 1, |
| + CONTENT_TYPE_SCRIPT = 2, |
| + CONTENT_TYPE_IMAGE = 4, |
| + CONTENT_TYPE_STYLESHEET = 8, |
| + CONTENT_TYPE_OBJECT = 16, |
| + CONTENT_TYPE_SUBDOCUMENT = 32, |
| + CONTENT_TYPE_DOCUMENT = 64, |
| + CONTENT_TYPE_PING = 1024, |
| + CONTENT_TYPE_XMLHTTPREQUEST = 2048, |
| + CONTENT_TYPE_OBJECT_SUBREQUEST = 4096, |
| + CONTENT_TYPE_MEDIA = 16384, |
| + CONTENT_TYPE_FONT = 32768, |
| + CONTENT_TYPE_GENERICBLOCK = 0x20000000, |
| + CONTENT_TYPE_ELEMHIDE = 0x40000000, |
| + CONTENT_TYPE_GENERICHIDE = 0x80000000 |
| + }; |
| + |
| + /** |
| + * Bitmask of `ContentType` values. |
| + * The underlying type is signed 32 bit integer because it is actually used |
| + * in JavaScript where it is converted into 32 bit signed integer. |
| + */ |
| + typedef int32_t ContentTypeMask; |
| /** |
| * Callback type invoked when an update becomes available. |
| * The parameter is the download URL of the update. |
| */ |
| typedef std::function<void(const std::string&)> UpdateAvailableCallback; |
| /** |
| * Callback type invoked when a manually triggered update check finishes. |
| * The parameter is an optional error message. |
| */ |
| typedef std::function<void(const std::string&)> UpdateCheckDoneCallback; |
| /** |
| * Callback type invoked when the filters change. |
| * The first parameter is the action event code (see |
| - * [FilterNotifier.triggerListeners](https://adblockplus.org/jsdoc/adblockplus/symbols/FilterNotifier.html#.triggerListeners) |
| + * [FilterNotifier.triggerListeners](https://adblockplus.org/jsdoc/adblockpluscore/FilterNotifier.html#.triggerListeners) |
| * for the full list). |
| * The second parameter is the filter/subscription object affected, if any. |
| */ |
| typedef std::function<void(const std::string&, const JsValuePtr)> FilterChangeCallback; |
| /** |
| * Container of name-value pairs representing a set of preferences. |
| */ |
| @@ -264,43 +284,43 @@ namespace AdblockPlus |
| /** |
| * Removes the callback invoked when a notification should be shown. |
| */ |
| void RemoveShowNotificationCallback(); |
| /** |
| * Checks if any active filter matches the supplied URL. |
| * @param url URL to match. |
| - * @param contentType Content type of the requested resource. |
| + * @param contentTypeMask Content type mask of the requested resource. |
| * @param documentUrl URL of the document requesting the resource. |
| * Note that there will be more than one document if frames are |
| * involved, see |
| * Matches(const std::string&, const std::string&, const std::vector<std::string>&) const. |
| * @return Matching filter, or `null` if there was no match. |
| * @throw `std::invalid_argument`, if an invalid `contentType` was supplied. |
| */ |
| FilterPtr Matches(const std::string& url, |
| - ContentType contentType, |
| + ContentTypeMask contentTypeMask, |
| const std::string& documentUrl) const; |
| /** |
| * Checks if any active filter matches the supplied URL. |
| * @param url URL to match. |
| - * @param contentType Content type of the requested resource. |
| + * @param contentTypeMask Content type mask of the requested resource. |
| * @param documentUrls Chain of documents requesting the resource, starting |
| * with the current resource's parent frame, ending with the |
| * top-level frame. |
| * If the application is not capable of identifying the frame |
| * structure, e.g. because it is a proxy, it can be approximated |
| * using `ReferrerMapping`. |
| * @return Matching filter, or a `null` if there was no match. |
| * @throw `std::invalid_argument`, if an invalid `contentType` was supplied. |
| */ |
| FilterPtr Matches(const std::string& url, |
| - ContentType contentType, |
| + ContentTypeMask contentTypeMask, |
| const std::vector<std::string>& documentUrls) const; |
| /** |
| * Checks whether the document at the supplied URL is whitelisted. |
| * @param url URL of the document. |
| * @param documentUrls Chain of document URLs requesting the document, |
| * starting with the current document's parent frame, ending with |
| * the top-level frame. |
| @@ -424,25 +444,25 @@ namespace AdblockPlus |
| JsEnginePtr jsEngine; |
| bool initialized; |
| bool firstRun; |
| int updateCheckId; |
| static const std::map<ContentType, std::string> contentTypes; |
| void InitDone(JsValueList& params); |
| FilterPtr CheckFilterMatch(const std::string& url, |
| - ContentType contentType, |
| + ContentTypeMask contentTypeMask, |
| const std::string& documentUrl) const; |
| void UpdateAvailable(UpdateAvailableCallback callback, JsValueList& params); |
| void UpdateCheckDone(const std::string& eventName, |
| UpdateCheckDoneCallback callback, JsValueList& params); |
| void FilterChanged(FilterChangeCallback callback, JsValueList& params); |
| void ShowNotification(const ShowNotificationCallback& callback, |
| const JsValueList& params); |
| FilterPtr GetWhitelistingFilter(const std::string& url, |
| - ContentType contentType, const std::string& documentUrl) const; |
| + ContentTypeMask contentTypeMask, const std::string& documentUrl) const; |
| FilterPtr GetWhitelistingFilter(const std::string& url, |
| - ContentType contentType, |
| + ContentTypeMask contentTypeMask, |
| const std::vector<std::string>& documentUrls) const; |
| }; |
| } |
| #endif |