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

Delta Between Two Patch Sets: src/FilterEngine.cpp

Issue 29335462: Issue 3337 - Update adblockplus reference in libadblockplus to revision hg:813682c7161e (Closed)
Left Patch Set: Created Feb. 3, 2016, 1:26 p.m.
Right Patch Set: rebase Created April 19, 2016, 9:27 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « libadblockplus.gyp ('k') | test/FilterEngine.cpp » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 std::bind(&FilterEngine::ShowNotification, this, value, 291 std::bind(&FilterEngine::ShowNotification, this, value,
292 std::placeholders::_1)); 292 std::placeholders::_1));
293 } 293 }
294 294
295 void FilterEngine::RemoveShowNotificationCallback() 295 void FilterEngine::RemoveShowNotificationCallback()
296 { 296 {
297 jsEngine->RemoveEventCallback("_showNotification"); 297 jsEngine->RemoveEventCallback("_showNotification");
298 } 298 }
299 299
300 AdblockPlus::FilterPtr FilterEngine::Matches(const std::string& url, 300 AdblockPlus::FilterPtr FilterEngine::Matches(const std::string& url,
301 int32_t contentTypeMask, 301 ContentTypeMask contentTypeMask,
302 const std::string& documentUrl) const 302 const std::string& documentUrl) const
303 { 303 {
304 std::vector<std::string> documentUrls; 304 std::vector<std::string> documentUrls;
305 documentUrls.push_back(documentUrl); 305 documentUrls.push_back(documentUrl);
306 return Matches(url, contentTypeMask, documentUrls); 306 return Matches(url, contentTypeMask, documentUrls);
307 } 307 }
308 308
309 AdblockPlus::FilterPtr FilterEngine::Matches(const std::string& url, 309 AdblockPlus::FilterPtr FilterEngine::Matches(const std::string& url,
310 int32_t contentTypeMask, 310 ContentTypeMask contentTypeMask,
311 const std::vector<std::string>& documentUrls) const 311 const std::vector<std::string>& documentUrls) const
312 { 312 {
313 if (documentUrls.empty()) 313 if (documentUrls.empty())
314 return CheckFilterMatch(url, contentTypeMask, ""); 314 return CheckFilterMatch(url, contentTypeMask, "");
315 315
316 std::string lastDocumentUrl = documentUrls.front(); 316 std::string lastDocumentUrl = documentUrls.front();
317 for (std::vector<std::string>::const_iterator it = documentUrls.begin(); 317 for (std::vector<std::string>::const_iterator it = documentUrls.begin();
318 it != documentUrls.end(); it++) { 318 it != documentUrls.end(); it++) {
319 const std::string documentUrl = *it; 319 const std::string documentUrl = *it;
320 AdblockPlus::FilterPtr match = CheckFilterMatch(documentUrl, 320 AdblockPlus::FilterPtr match = CheckFilterMatch(documentUrl,
(...skipping 13 matching lines...) Expand all
334 return !!GetWhitelistingFilter(url, CONTENT_TYPE_DOCUMENT, documentUrls); 334 return !!GetWhitelistingFilter(url, CONTENT_TYPE_DOCUMENT, documentUrls);
335 } 335 }
336 336
337 bool FilterEngine::IsElemhideWhitelisted(const std::string& url, 337 bool FilterEngine::IsElemhideWhitelisted(const std::string& url,
338 const std::vector<std::string>& documentUrls) const 338 const std::vector<std::string>& documentUrls) const
339 { 339 {
340 return !!GetWhitelistingFilter(url, CONTENT_TYPE_ELEMHIDE, documentUrls); 340 return !!GetWhitelistingFilter(url, CONTENT_TYPE_ELEMHIDE, documentUrls);
341 } 341 }
342 342
343 AdblockPlus::FilterPtr FilterEngine::CheckFilterMatch(const std::string& url, 343 AdblockPlus::FilterPtr FilterEngine::CheckFilterMatch(const std::string& url,
344 int32_t contentTypeMask, 344 ContentTypeMask contentTypeMask,
345 const std::string& documentUrl) const 345 const std::string& documentUrl) const
346 { 346 {
347 JsValuePtr func = jsEngine->Evaluate("API.checkFilterMatch"); 347 JsValuePtr func = jsEngine->Evaluate("API.checkFilterMatch");
348 JsValueList params; 348 JsValueList params;
349 params.push_back(jsEngine->NewValue(url)); 349 params.push_back(jsEngine->NewValue(url));
350 params.push_back(jsEngine->NewValue(contentTypeMask)); 350 params.push_back(jsEngine->NewValue(contentTypeMask));
351 params.push_back(jsEngine->NewValue(documentUrl)); 351 params.push_back(jsEngine->NewValue(documentUrl));
352 JsValuePtr result = func->Call(params); 352 JsValuePtr result = func->Call(params);
353 if (!result->IsNull()) 353 if (!result->IsNull())
354 return FilterPtr(new Filter(result)); 354 return FilterPtr(new Filter(result));
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 int FilterEngine::CompareVersions(const std::string& v1, const std::string& v2) 472 int FilterEngine::CompareVersions(const std::string& v1, const std::string& v2)
473 { 473 {
474 JsValueList params; 474 JsValueList params;
475 params.push_back(jsEngine->NewValue(v1)); 475 params.push_back(jsEngine->NewValue(v1));
476 params.push_back(jsEngine->NewValue(v2)); 476 params.push_back(jsEngine->NewValue(v2));
477 JsValuePtr func = jsEngine->Evaluate("API.compareVersions"); 477 JsValuePtr func = jsEngine->Evaluate("API.compareVersions");
478 return func->Call(params)->AsInt(); 478 return func->Call(params)->AsInt();
479 } 479 }
480 480
481 FilterPtr FilterEngine::GetWhitelistingFilter(const std::string& url, 481 FilterPtr FilterEngine::GetWhitelistingFilter(const std::string& url,
482 int32_t contentTypeMask, const std::string& documentUrl) const 482 ContentTypeMask contentTypeMask, const std::string& documentUrl) const
483 { 483 {
484 FilterPtr match = Matches(url, contentTypeMask, documentUrl); 484 FilterPtr match = Matches(url, contentTypeMask, documentUrl);
485 if (match && match->GetType() == Filter::TYPE_EXCEPTION) 485 if (match && match->GetType() == Filter::TYPE_EXCEPTION)
486 { 486 {
487 return match; 487 return match;
488 } 488 }
489 return FilterPtr(); 489 return FilterPtr();
490 } 490 }
491 491
492 FilterPtr FilterEngine::GetWhitelistingFilter(const std::string& url, 492 FilterPtr FilterEngine::GetWhitelistingFilter(const std::string& url,
493 int32_t contentTypeMask, 493 ContentTypeMask contentTypeMask,
494 const std::vector<std::string>& documentUrls) const 494 const std::vector<std::string>& documentUrls) const
495 { 495 {
496 if (documentUrls.empty()) 496 if (documentUrls.empty())
497 { 497 {
498 return GetWhitelistingFilter(url, contentTypeMask, ""); 498 return GetWhitelistingFilter(url, contentTypeMask, "");
499 } 499 }
500 500
501 std::vector<std::string>::const_iterator urlIterator = documentUrls.begin(); 501 std::vector<std::string>::const_iterator urlIterator = documentUrls.begin();
502 std::string currentUrl = url; 502 std::string currentUrl = url;
503 do 503 do
504 { 504 {
505 std::string parentUrl = *urlIterator++; 505 std::string parentUrl = *urlIterator++;
506 FilterPtr filter = GetWhitelistingFilter(currentUrl, contentTypeMask, parent Url); 506 FilterPtr filter = GetWhitelistingFilter(currentUrl, contentTypeMask, parent Url);
507 if (filter) 507 if (filter)
508 { 508 {
509 return filter; 509 return filter;
510 } 510 }
511 currentUrl = parentUrl; 511 currentUrl = parentUrl;
512 } 512 }
513 while (urlIterator != documentUrls.end()); 513 while (urlIterator != documentUrls.end());
514 return FilterPtr(); 514 return FilterPtr();
515 } 515 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld