Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: include/AdblockPlus/FilterEngine.h

Issue 5728380594946048: Issue 116 - Document the libadblockplus API (Closed)
Patch Set: Document JsValue and FilterEngine Created Aug. 29, 2014, 1:18 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: include/AdblockPlus/FilterEngine.h
===================================================================
--- a/include/AdblockPlus/FilterEngine.h
+++ b/include/AdblockPlus/FilterEngine.h
@@ -31,67 +31,266 @@
{
class FilterEngine;
+ /**
+ * Wrapper for a filter object.
Wladimir Palant 2014/08/29 18:18:50 "Adblock Plus filter object"? Just to make it clea
Felix Dahlke 2014/09/01 17:00:15 Done.
+ */
class Filter : public JsValue,
public std::tr1::enable_shared_from_this<Filter>
{
public:
+ /**
+ * Filter types, see https://adblockplus.org/en/filters.
+ */
enum Type {TYPE_BLOCKING, TYPE_EXCEPTION,
TYPE_ELEMHIDE, TYPE_ELEMHIDE_EXCEPTION,
TYPE_COMMENT, TYPE_INVALID};
Type GetType();
Wladimir Palant 2014/08/29 18:18:50 I think this method should be documented ;)
Felix Dahlke 2014/09/01 17:00:15 Done.
+
+ /**
+ * Checks whether this filter has been added to its subscription.
+ * @return `true` if this filter has been added to its subscription.
Wladimir Palant 2014/08/29 18:18:50 No, "Checks whether this filter has been added to
Felix Dahlke 2014/09/01 17:00:15 Done, seems I misinterpreted FilterStorage.addFilt
+ */
bool IsListed();
+
+ /**
+ * Adds this filter to its subscription.
Wladimir Palant 2014/08/29 18:18:50 No, "Adds this filter to user's custom filters."
Felix Dahlke 2014/09/01 17:00:15 Done.
+ */
void AddToList();
+
+ /**
+ * Removes this filter from its subscription.
Wladimir Palant 2014/08/29 18:18:50 No, "Removes this filter from user's custom filter
Felix Dahlke 2014/09/01 17:00:15 Done.
+ */
void RemoveFromList();
+
bool operator==(const Filter& filter) const;
Filter(JsValuePtr value);
Wladimir Palant 2014/08/29 18:18:50 Want to document this? "Creates a wrapper for a Ja
Felix Dahlke 2014/09/01 17:00:15 Done.
};
+ /**
+ * Wrapper for a subscription object.
+ */
class Subscription : public JsValue,
public std::tr1::enable_shared_from_this<Subscription>
{
public:
+ /**
+ * Checks if this subscription has been added to the known subscriptions.
+ * @return `true` if this subscription has been added to the known
+ * subscriptions.
Wladimir Palant 2014/08/29 18:18:50 What are "known subscriptions"? "Checks if the sub
Felix Dahlke 2014/09/01 17:00:15 Done.
+ */
bool IsListed();
+
+ /**
+ * Adds this subscription to the known subscriptions.
Wladimir Palant 2014/08/29 18:18:50 "Adds this subscription to user's list of subscrip
Felix Dahlke 2014/09/01 17:00:15 Done.
+ */
void AddToList();
+
+ /**
+ * Removes this subscription from the known subscriptions.
Wladimir Palant 2014/08/29 18:18:50 "Removes this subscription from user's list of sub
Felix Dahlke 2014/09/01 17:00:15 Done.
+ */
void RemoveFromList();
+
+ /**
+ * Updates this subscription, i.e.\ retrieves the latest version from the
Wladimir Palant 2014/08/29 18:18:50 "latest version" => "current filters"?
Felix Dahlke 2014/09/01 17:00:15 Done.
+ * subscription URL.
+ */
void UpdateFilters();
+
+ /**
+ * Checks if this subscriptions is currently being updated.
+ * @return `true` if this subscriptions is currently being updated.
+ */
bool IsUpdating();
+
bool operator==(const Subscription& subscription) const;
Subscription(JsValuePtr value);
Wladimir Palant 2014/08/29 18:18:50 Want to document this? "Creates a wrapper for a Ja
Felix Dahlke 2014/09/01 17:00:15 Done.
};
+ /**
+ * Shared smart pointer to a `Filter` instance.
+ */
typedef std::tr1::shared_ptr<Filter> FilterPtr;
+
+ /**
+ * Shared smart pointer to a `Subscription` instance.
+ */
typedef std::tr1::shared_ptr<Subscription> SubscriptionPtr;
+ /**
+ * Main component of Libadblockplus.
+ * It handles:
+ * - Filter management and matching.
+ * - Subscription management and synchronization.
+ * - Update checks for the application.
+ */
class FilterEngine
{
public:
+ /**
+ * Callback invoked when an update is available.
Wladimir Palant 2014/08/29 18:18:50 "Callback" => "Type of callback"? Want to note th
Felix Dahlke 2014/09/01 17:00:15 Done.
+ */
typedef std::tr1::function<void(const std::string&)> UpdaterCallback;
+
+ /**
+ * Callback invoked when the filters change.
Wladimir Palant 2014/08/29 18:18:50 "Callback" => "Type of callback"? Want to note th
Felix Dahlke 2014/09/01 17:00:15 Done.
+ */
typedef std::tr1::function<void(const std::string&, const JsValuePtr)> FilterChangeCallback;
explicit FilterEngine(JsEnginePtr jsEngine);
JsEnginePtr GetJsEngine() const { return jsEngine; }
Wladimir Palant 2014/08/29 18:18:50 I guess you plan to document these two functions l
Felix Dahlke 2014/09/01 17:00:15 Documented them now. They seemed rather obvious to
+
+ /**
+ * Checks if this is the first run of the application.
Wladimir Palant 2014/08/29 18:18:50 Want to note that this is determined by the presen
Felix Dahlke 2014/09/01 17:00:15 Libadblockplus does initialise filter lists intern
Wladimir Palant 2014/09/01 17:36:56 True, I forgot that this logic moved from the appl
+ * @return `true` if the application is running for the first time.
+ */
bool IsFirstRun() const;
+
+ /**
+ * Retrieves a filter object from its text representation.
+ * @param text Text representation of the filter,
+ * see https://adblockplus.org/en/filters.
+ * @return New filter object if the filter wasn't known, otherwise the
+ * existing one.
Wladimir Palant 2014/08/29 18:18:50 This is pretty misleading. This function will alwa
Felix Dahlke 2014/09/01 17:00:15 Done.
+ */
FilterPtr GetFilter(const std::string& text);
+
+ /**
+ * Retrieves a subscription object for the supplied URL.
+ * @param url Subscription URL.
+ * @return New subscription object if the subscription wasn't known,
+ * otherwise the existing one.
Wladimir Palant 2014/08/29 18:18:50 Same as above, IMHO we should just say that a subs
Felix Dahlke 2014/09/01 17:00:15 Done.
+ */
SubscriptionPtr GetSubscription(const std::string& url);
+
+ /**
+ * Retrieves all known filters.
+ * @return List of known filters.
Wladimir Palant 2014/08/29 18:18:50 What are "known filters"? "Retrieves user's custom
Felix Dahlke 2014/09/01 17:00:15 Done.
+ */
std::vector<FilterPtr> GetListedFilters() const;
+
+ /**
+ * Retrieves all known subscriptions.
+ * @return List of known subscriptions.
Wladimir Palant 2014/08/29 18:18:50 What are "known subscriptions"? "Retrieves user's
Felix Dahlke 2014/09/01 17:00:15 Done.
+ */
std::vector<SubscriptionPtr> GetListedSubscriptions() const;
+
+ /**
+ * Retrieves all recommended subscriptions.
+ * This will parse all subscriptions listed in `subscriptions.xml`.
Wladimir Palant 2014/08/29 18:18:50 Why document implementation details? There is no s
Felix Dahlke 2014/09/01 17:00:15 Done.
+ * @return List of recommended subscriptions.
+ */
std::vector<SubscriptionPtr> FetchAvailableSubscriptions() const;
+
+ /**
+ * Checks if any active filter matches the supplied URL.
+ * @param url URL to match.
+ * @param contentType Content type of the requested resource, possible
+ * values are:
+ * - OTHER
+ * - SCRIPT
+ * - IMAGE
+ * - STYLESHEET
+ * - OBJECT
+ * - SUBDOCUMENT
+ * - DOCUMENT
+ * - XMLHTTPREQUEST
+ * - OBJECT_SUBREQUEST
+ * - FONT
+ * - MEDIA
+ * @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.
Wladimir Palant 2014/08/29 18:18:50 Strictly speaking, is it really null? It's an empt
Felix Dahlke 2014/09/01 17:00:15 Not strictly speaking, it's a shared_ptr instance
Wladimir Palant 2014/09/01 17:36:56 I am not really sure, that's why I asked. You don'
Felix Dahlke 2014/09/02 05:24:51 I do think so. Note that: 1. There is no "null" i
+ */
FilterPtr Matches(const std::string& url,
const std::string& contentType,
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, possible
+ * values are:
+ * - OTHER
+ * - SCRIPT
+ * - IMAGE
+ * - STYLESHEET
+ * - OBJECT
+ * - SUBDOCUMENT
+ * - DOCUMENT
+ * - XMLHTTPREQUEST
+ * - OBJECT_SUBREQUEST
+ * - FONT
+ * - MEDIA
+ * @param documentUrls Chain of documents requesting the resource.
Wladimir Palant 2014/08/29 18:18:50 In which order? "starting with the top-level frame
Felix Dahlke 2014/09/01 17:00:15 I've put it slightly differently - we actually sta
+ * This will typically be the frame structure. 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 `null` if there was no match.
+ */
FilterPtr Matches(const std::string& url,
const std::string& contentType,
const std::vector<std::string>& documentUrls) const;
+
+ /**
+ * Retrieves CSS selectors for all active element hiding filters.
+ * @param domain Domain to retrieve CSS selectors for.
Wladimir Palant 2014/08/29 18:18:50 What is the relevance of the domain parameter? Thi
Felix Dahlke 2014/09/01 17:00:15 Done.
+ * @return List of CSS selectors.
+ */
std::vector<std::string> GetElementHidingSelectors(const std::string& domain) const;
+
+ /**
+ * Retrieves a preference value.
+ * @param pref Preference name.
+ * @return Preference value, or `null` if it doesn't exist.
+ */
JsValuePtr GetPref(const std::string& pref) const;
+
+ /**
+ * Sets a preference value.
+ * @param pref Preference name.
+ * @param value New value of the preference.
+ */
void SetPref(const std::string& pref, JsValuePtr value);
+
+ /**
+ * Extracts the host from an URL.
Wladimir Palant 2014/08/29 18:18:50 "from a URL" please.
Felix Dahlke 2014/09/01 17:00:15 Done.
+ * @param url URL to extract the host from.
+ * @return Extracted host.
+ */
std::string GetHostFromURL(const std::string& url);
+
+ /**
+ * Forces an immediate update check.
+ * @param Optional callback to invoke when updates are available.
Wladimir Palant 2014/08/29 18:18:50 Parameter name is missing here. The callback will
Felix Dahlke 2014/09/01 17:00:15 Done.
+ */
void ForceUpdateCheck(UpdaterCallback callback = 0);
+
+ /**
+ * Sets the callback invoked when the filters change.
+ * @param The callback to invoke.
Wladimir Palant 2014/08/29 18:18:50 Parameter name is missing here. Want to note that
Felix Dahlke 2014/09/01 17:00:15 Added the parameter. Seems obvious to me that ther
+ */
void SetFilterChangeCallback(FilterChangeCallback callback);
+
+ /**
+ * Removes the callback invoked when the filters change.
+ */
void RemoveFilterChangeCallback();
+
+ /**
+ * Compares two version strings in
+ * [Mozilla toolkit version format](https://developer.mozilla.org/en/docs/Toolkit_version_format).
+ * @param v1 First version string.
+ * @param v2 Second version string.
+ * @return
+ * - `0` if `v1` and `v2` are identical.
+ * - A negative number if `v1` is less than `v2`.
+ * - A positive number if `v1` is greater than `v2`.
+ */
int CompareVersions(const std::string& v1, const std::string& v2);
private:

Powered by Google App Engine
This is Rietveld