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

Unified Diff: include/AdblockPlus/FilterEngine.h

Issue 10100009: FilterEngine API improvements (Closed)
Patch Set: Replace GetElementHidingRules by a domain-specific GetElementHidingSelectors Created April 5, 2013, 12:22 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
« no previous file with comments | « no previous file | libadblockplus.gyp » ('j') | shell/src/FiltersCommand.cpp » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/AdblockPlus/FilterEngine.h
===================================================================
--- a/include/AdblockPlus/FilterEngine.h
+++ b/include/AdblockPlus/FilterEngine.h
@@ -1,39 +1,109 @@
#ifndef ADBLOCKPLUS_FILTER_ENGINE_H
#define ADBLOCKPLUS_FILTER_ENGINE_H
#include <vector>
+#include <map>
#include <string>
namespace AdblockPlus
{
class JsEngine;
+ class FilterEngine;
- struct Subscription
+ class JSObject
Felix Dahlke 2013/04/06 05:17:05 Should be JsObject for consistency. I've thought
{
- std::string url;
- std::string title;
+ public:
+ std::string GetProperty(const std::string& name, const std::string& defaultValue) const;
+ int GetProperty(const std::string& name, int defaultValue) const;
+ bool GetProperty(const std::string& name, bool defaultValue) const;
+ inline std::string GetProperty(const std::string& name, const char* defaultValue) const
+ {
+ return GetProperty(name, std::string(defaultValue));
+ }
- Subscription(const std::string& url, const std::string& title);
+ void SetProperty(const std::string& name, const std::string& value);
+ void SetProperty(const std::string& name, int value);
+ void SetProperty(const std::string& name, bool value);
+ inline void SetProperty(const std::string& name, const char* value)
+ {
+ SetProperty(name, std::string(value));
+ }
+
+ protected:
+#if FILTER_ENGINE_STUBS
+ JSObject(FilterEngine& filterEngine);
+
+ FilterEngine& filterEngine;
+ std::map<std::string, std::string> stringProperties;
+ std::map<std::string, int> intProperties;
+ std::map<std::string, bool> boolProperties;
+#else
+ JSObject();
+#endif
};
+ class Filter : public JSObject
+ {
+ friend class FilterEngine;
+
+ public:
+ bool IsListed() const;
+ void AddToList();
+ void RemoveFromList();
+
+ private:
+#if FILTER_ENGINE_STUBS
+ Filter(FilterEngine& filterEngine, const std::string& text);
+#else
+ Filter();
+#endif
+ };
+
+ class Subscription : public JSObject
+ {
+ friend class FilterEngine;
+
+ public:
+ bool IsListed() const;
+ void AddToList();
+ void RemoveFromList();
+ void UpdateFilters();
+
+ private:
+#if FILTER_ENGINE_STUBS
+ Subscription(FilterEngine& filterEngine, const std::string& url);
+#else
+ Subscription();
+#endif
+ };
+
+ typedef void (*SubscriptionsCallback)(const std::vector<Subscription*>&);
+
class FilterEngine
{
+ friend class Filter;
+ friend class Subscription;
public:
explicit FilterEngine(JsEngine& jsEngine);
- void AddSubscription(Subscription subscription);
- void RemoveSubscription(const Subscription& subscription);
- const Subscription* FindSubscription(const std::string& url) const;
- const std::vector<Subscription>& GetSubscriptions() const;
- void UpdateSubscriptionFilters(const Subscription& subscription);
- std::vector<Subscription> FetchAvailableSubscriptions();
- bool Matches(const std::string& url,
- const std::string& contentType) const;
- std::vector<std::string> GetElementHidingRules() const;
+ Filter& GetFilter(const std::string& text);
+ Subscription& GetSubscription(const std::string& url);
+ const std::vector<Filter*>& GetListedFilters() const;
+ const std::vector<Subscription*>& GetListedSubscriptions() const;
+ void FetchAvailableSubscriptions(SubscriptionsCallback callback);
+ Filter* Matches(const std::string& url,
+ const std::string& contentType,
+ const std::string& documentUrl);
+ std::vector<std::string> GetElementHidingSelectors(const std::string& domain) const;
private:
JsEngine& jsEngine;
- std::vector<Subscription> subscriptions;
+#if FILTER_ENGINE_STUBS
+ std::map<std::string, Filter*> knownFilters;
+ std::vector<Filter*> listedFilters;
+ std::map<std::string, Subscription*> knownSubscriptions;
+ std::vector<Subscription*> listedSubscriptions;
+#endif
};
}
#endif
« no previous file with comments | « no previous file | libadblockplus.gyp » ('j') | shell/src/FiltersCommand.cpp » ('J')

Powered by Google App Engine
This is Rietveld