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

Side by Side Diff: src/FilterEngine.cpp

Issue 10171027: Compile subscriptions.xml into the libadblockplus build and make itusable (Closed)
Patch Set: Created April 19, 2013, 7:59 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« convert_js.py ('K') | « shell/src/SubscriptionsCommand.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #include <algorithm> 1 #include <algorithm>
2 #include <cctype> 2 #include <cctype>
3 #include <functional> 3 #include <functional>
4 4
5 #include <AdblockPlus.h> 5 #include <AdblockPlus.h>
6 6
7 using namespace AdblockPlus; 7 using namespace AdblockPlus;
8 8
9 #if !FILTER_ENGINE_STUBS 9 #if !FILTER_ENGINE_STUBS
10 extern const char* jsSources[]; 10 extern const char* jsSources[];
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 knownSubscriptions[url] = result; 322 knownSubscriptions[url] = result;
323 return result; 323 return result;
324 #else 324 #else
325 JsValuePtr func = jsEngine->Evaluate("API.getSubscriptionFromUrl"); 325 JsValuePtr func = jsEngine->Evaluate("API.getSubscriptionFromUrl");
326 JsValueList params; 326 JsValueList params;
327 params.push_back(jsEngine->NewValue(url)); 327 params.push_back(jsEngine->NewValue(url));
328 return SubscriptionPtr(new Subscription(func->Call(params))); 328 return SubscriptionPtr(new Subscription(func->Call(params)));
329 #endif 329 #endif
330 } 330 }
331 331
332 const std::vector<FilterPtr> FilterEngine::GetListedFilters() const 332 std::vector<FilterPtr> FilterEngine::GetListedFilters() const
333 { 333 {
334 #if FILTER_ENGINE_STUBS 334 #if FILTER_ENGINE_STUBS
335 return listedFilters; 335 return listedFilters;
336 #else 336 #else
337 JsValuePtr func = jsEngine->Evaluate("API.getListedFilters"); 337 JsValuePtr func = jsEngine->Evaluate("API.getListedFilters");
338 JsValueList values = func->Call()->AsList(); 338 JsValueList values = func->Call()->AsList();
339 std::vector<FilterPtr> result; 339 std::vector<FilterPtr> result;
340 for (JsValueList::iterator it = values.begin(); it != values.end(); it++) 340 for (JsValueList::iterator it = values.begin(); it != values.end(); it++)
341 result.push_back(FilterPtr(new Filter(*it))); 341 result.push_back(FilterPtr(new Filter(*it)));
342 return result; 342 return result;
343 #endif 343 #endif
344 } 344 }
345 345
346 const std::vector<SubscriptionPtr> FilterEngine::GetListedSubscriptions() const 346 std::vector<SubscriptionPtr> FilterEngine::GetListedSubscriptions() const
347 { 347 {
348 #if FILTER_ENGINE_STUBS 348 #if FILTER_ENGINE_STUBS
349 return listedSubscriptions; 349 return listedSubscriptions;
350 #else 350 #else
351 JsValuePtr func = jsEngine->Evaluate("API.getListedSubscriptions"); 351 JsValuePtr func = jsEngine->Evaluate("API.getListedSubscriptions");
352 JsValueList values = func->Call()->AsList(); 352 JsValueList values = func->Call()->AsList();
353 std::vector<SubscriptionPtr> result; 353 std::vector<SubscriptionPtr> result;
354 for (JsValueList::iterator it = values.begin(); it != values.end(); it++) 354 for (JsValueList::iterator it = values.begin(); it != values.end(); it++)
355 result.push_back(SubscriptionPtr(new Subscription(*it))); 355 result.push_back(SubscriptionPtr(new Subscription(*it)));
356 return result; 356 return result;
357 #endif 357 #endif
358 } 358 }
359 359
360 void FilterEngine::FetchAvailableSubscriptions(SubscriptionsCallback callback) 360 std::vector<SubscriptionPtr> FilterEngine::FetchAvailableSubscriptions() const
361 { 361 {
362 #if FILTER_ENGINE_STUBS 362 #if FILTER_ENGINE_STUBS
Felix Dahlke 2013/04/30 08:59:17 What's with this diff? FILTER_ENGINE_STUBS has bee
Wladimir Palant 2013/04/30 09:35:49 This diff is rather old as well, check the issue d
363 std::vector<SubscriptionPtr> availableSubscriptions; 363 std::vector<SubscriptionPtr> availableSubscriptions;
364 364
365 SubscriptionPtr subscription1 = GetSubscription("https://easylist-downloads.ad blockplus.org/easylist.txt"); 365 SubscriptionPtr subscription1 = GetSubscription("https://easylist-downloads.ad blockplus.org/easylist.txt");
366 subscription1->SetProperty("title", "EasyList"); 366 subscription1->SetProperty("title", "EasyList");
367 availableSubscriptions.push_back(subscription1); 367 availableSubscriptions.push_back(subscription1);
368 368
369 SubscriptionPtr subscription2 = GetSubscription("https://easylist-downloads.ad blockplus.org/easylistgermany+easylist.txt"); 369 SubscriptionPtr subscription2 = GetSubscription("https://easylist-downloads.ad blockplus.org/easylistgermany+easylist.txt");
370 subscription2->SetProperty("title", "EasyList Germany+EasyList"); 370 subscription2->SetProperty("title", "EasyList Germany+EasyList");
371 availableSubscriptions.push_back(subscription2); 371 availableSubscriptions.push_back(subscription2);
372 372
373 callback(availableSubscriptions); 373 callback(availableSubscriptions);
374 #else 374 #else
375 // TODO! 375 JsValuePtr func = jsEngine->Evaluate("API.getRecommendedSubscriptions");
376 JsValueList values = func->Call()->AsList();
377 std::vector<SubscriptionPtr> result;
378 for (JsValueList::iterator it = values.begin(); it != values.end(); it++)
379 result.push_back(SubscriptionPtr(new Subscription(*it)));
380 return result;
376 #endif 381 #endif
377 } 382 }
378 383
379 AdblockPlus::FilterPtr FilterEngine::Matches(const std::string& url, 384 AdblockPlus::FilterPtr FilterEngine::Matches(const std::string& url,
380 const std::string& contentType, 385 const std::string& contentType,
381 const std::string& documentUrl) 386 const std::string& documentUrl)
382 { 387 {
383 #if FILTER_ENGINE_STUBS 388 #if FILTER_ENGINE_STUBS
384 //For test on http://simple-adblock.com/faq/testing-your-adblocker/ 389 //For test on http://simple-adblock.com/faq/testing-your-adblocker/
385 if (url.find("adbanner.gif") != std::string::npos) 390 if (url.find("adbanner.gif") != std::string::npos)
(...skipping 30 matching lines...) Expand all
416 JsValuePtr func = jsEngine->Evaluate("API.getElementHidingSelectors"); 421 JsValuePtr func = jsEngine->Evaluate("API.getElementHidingSelectors");
417 JsValueList params; 422 JsValueList params;
418 params.push_back(jsEngine->NewValue(domain)); 423 params.push_back(jsEngine->NewValue(domain));
419 JsValueList result = func->Call(params)->AsList(); 424 JsValueList result = func->Call(params)->AsList();
420 std::vector<std::string> selectors; 425 std::vector<std::string> selectors;
421 for (JsValueList::iterator it = result.begin(); it != result.end(); ++it) 426 for (JsValueList::iterator it = result.begin(); it != result.end(); ++it)
422 selectors.push_back((*it)->AsString()); 427 selectors.push_back((*it)->AsString());
423 return selectors; 428 return selectors;
424 #endif 429 #endif
425 } 430 }
OLDNEW
« convert_js.py ('K') | « shell/src/SubscriptionsCommand.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld