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

Unified Diff: src/FilterEngine.cpp

Issue 9987009: Interface for the libadblockplus API (Closed)
Patch Set: Use new API in the shell Created March 27, 2013, 4:58 a.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 | « shell/src/SubscriptionsCommand.cpp ('k') | test/FilterEngineStubs.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/FilterEngine.cpp
===================================================================
new file mode 100644
--- /dev/null
+++ b/src/FilterEngine.cpp
@@ -0,0 +1,70 @@
+#include <AdblockPlus.h>
+
+using namespace AdblockPlus;
+
+Subscription::Subscription(const std::string& url, const std::string& title)
+ : url(url), title(title)
+{
+}
+
+FilterEngine::FilterEngine(JsEngine& jsEngine) : jsEngine(jsEngine)
+{
+ // TODO: Load ABP:
+ // jsEngine.Load("adblockplus_compat.js");
+ // jsEngine.Load("adblockplus.js");
+}
+
+void FilterEngine::AddSubscription(Subscription subscription)
+{
+ subscriptions.push_back(subscription);
+}
+
+void FilterEngine::RemoveSubscription(const Subscription& subscription)
+{
+ for (std::vector<Subscription>::iterator it = subscriptions.begin();
+ it != subscriptions.end();)
+ if (it->url == subscription.url)
+ it = subscriptions.erase(it);
+ else
+ it++;
+}
+
+const Subscription* FilterEngine::FindSubscription(const std::string& url) const
+{
+ for (std::vector<Subscription>::const_iterator it = subscriptions.begin();
+ it != subscriptions.end(); it++)
+ if (it->url == url)
+ return &(*it);
+ return 0;
+}
+
+const std::vector<Subscription>& FilterEngine::GetSubscriptions() const
+{
+ return subscriptions;
+}
+
+void FilterEngine::UpdateSubscriptionFilters(const Subscription& subscription)
+{
+}
+
+std::vector<Subscription> FilterEngine::FetchAvailableSubscriptions()
+{
+ std::vector<Subscription> availableSubscriptions;
+ availableSubscriptions.push_back(Subscription("https://easylist-downloads.adblockplus.org/easylist.txt", "EasyList"));
+ availableSubscriptions.push_back(Subscription("https://easylist-downloads.adblockplus.org/easylistgermany+easylist.txt", "EasyList Germany+EasyList"));
+ return availableSubscriptions;
+}
+
+bool FilterEngine::MatchesFilters(const std::string& url,
+ const std::string& contentType) const
+{
+ return subscriptions.size() && url.length() % 2;
+}
+
+std::vector<std::string> FilterEngine::GetElementHidingRules() const
+{
+ std::vector<std::string> hidingRules;
+ hidingRules.push_back("###ad");
+ hidingRules.push_back("##.ad");
+ return hidingRules;
+}
« no previous file with comments | « shell/src/SubscriptionsCommand.cpp ('k') | test/FilterEngineStubs.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld