OLD | NEW |
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 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 ContentTypeMap CreateContentTypeMap() | 171 ContentTypeMap CreateContentTypeMap() |
172 { | 172 { |
173 ContentTypeMap contentTypes; | 173 ContentTypeMap contentTypes; |
174 contentTypes[FilterEngine::CONTENT_TYPE_OTHER] = "OTHER"; | 174 contentTypes[FilterEngine::CONTENT_TYPE_OTHER] = "OTHER"; |
175 contentTypes[FilterEngine::CONTENT_TYPE_SCRIPT] = "SCRIPT"; | 175 contentTypes[FilterEngine::CONTENT_TYPE_SCRIPT] = "SCRIPT"; |
176 contentTypes[FilterEngine::CONTENT_TYPE_IMAGE] = "IMAGE"; | 176 contentTypes[FilterEngine::CONTENT_TYPE_IMAGE] = "IMAGE"; |
177 contentTypes[FilterEngine::CONTENT_TYPE_STYLESHEET] = "STYLESHEET"; | 177 contentTypes[FilterEngine::CONTENT_TYPE_STYLESHEET] = "STYLESHEET"; |
178 contentTypes[FilterEngine::CONTENT_TYPE_OBJECT] = "OBJECT"; | 178 contentTypes[FilterEngine::CONTENT_TYPE_OBJECT] = "OBJECT"; |
179 contentTypes[FilterEngine::CONTENT_TYPE_SUBDOCUMENT] = "SUBDOCUMENT"; | 179 contentTypes[FilterEngine::CONTENT_TYPE_SUBDOCUMENT] = "SUBDOCUMENT"; |
180 contentTypes[FilterEngine::CONTENT_TYPE_DOCUMENT] = "DOCUMENT"; | 180 contentTypes[FilterEngine::CONTENT_TYPE_DOCUMENT] = "DOCUMENT"; |
| 181 contentTypes[FilterEngine::CONTENT_TYPE_PING] = "PING"; |
181 contentTypes[FilterEngine::CONTENT_TYPE_XMLHTTPREQUEST] = "XMLHTTPREQUEST"; | 182 contentTypes[FilterEngine::CONTENT_TYPE_XMLHTTPREQUEST] = "XMLHTTPREQUEST"; |
182 contentTypes[FilterEngine::CONTENT_TYPE_OBJECT_SUBREQUEST] = "OBJECT_SUBREQU
EST"; | 183 contentTypes[FilterEngine::CONTENT_TYPE_OBJECT_SUBREQUEST] = "OBJECT_SUBREQU
EST"; |
183 contentTypes[FilterEngine::CONTENT_TYPE_FONT] = "FONT"; | 184 contentTypes[FilterEngine::CONTENT_TYPE_FONT] = "FONT"; |
184 contentTypes[FilterEngine::CONTENT_TYPE_MEDIA] = "MEDIA"; | 185 contentTypes[FilterEngine::CONTENT_TYPE_MEDIA] = "MEDIA"; |
185 contentTypes[FilterEngine::CONTENT_TYPE_ELEMHIDE] = "ELEMHIDE"; | 186 contentTypes[FilterEngine::CONTENT_TYPE_ELEMHIDE] = "ELEMHIDE"; |
| 187 contentTypes[FilterEngine::CONTENT_TYPE_GENERICBLOCK] = "GENERICBLOCK"; |
| 188 contentTypes[FilterEngine::CONTENT_TYPE_GENERICHIDE] = "GENERICHIDE"; |
186 return contentTypes; | 189 return contentTypes; |
187 } | 190 } |
188 } | 191 } |
189 | 192 |
190 const ContentTypeMap FilterEngine::contentTypes = CreateContentTypeMap(); | 193 const ContentTypeMap FilterEngine::contentTypes = CreateContentTypeMap(); |
191 | 194 |
192 std::string FilterEngine::ContentTypeToString(ContentType contentType) | 195 std::string FilterEngine::ContentTypeToString(ContentType contentType) |
193 { | 196 { |
194 ContentTypeMap::const_iterator it = contentTypes.find(contentType); | 197 ContentTypeMap::const_iterator it = contentTypes.find(contentType); |
195 if (it != contentTypes.end()) | 198 if (it != contentTypes.end()) |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 std::bind(&FilterEngine::ShowNotification, this, value, | 291 std::bind(&FilterEngine::ShowNotification, this, value, |
289 std::placeholders::_1)); | 292 std::placeholders::_1)); |
290 } | 293 } |
291 | 294 |
292 void FilterEngine::RemoveShowNotificationCallback() | 295 void FilterEngine::RemoveShowNotificationCallback() |
293 { | 296 { |
294 jsEngine->RemoveEventCallback("_showNotification"); | 297 jsEngine->RemoveEventCallback("_showNotification"); |
295 } | 298 } |
296 | 299 |
297 AdblockPlus::FilterPtr FilterEngine::Matches(const std::string& url, | 300 AdblockPlus::FilterPtr FilterEngine::Matches(const std::string& url, |
298 ContentType contentType, | 301 int32_t contentTypeMask, |
299 const std::string& documentUrl) const | 302 const std::string& documentUrl) const |
300 { | 303 { |
301 std::vector<std::string> documentUrls; | 304 std::vector<std::string> documentUrls; |
302 documentUrls.push_back(documentUrl); | 305 documentUrls.push_back(documentUrl); |
303 return Matches(url, contentType, documentUrls); | 306 return Matches(url, contentTypeMask, documentUrls); |
304 } | 307 } |
305 | 308 |
306 AdblockPlus::FilterPtr FilterEngine::Matches(const std::string& url, | 309 AdblockPlus::FilterPtr FilterEngine::Matches(const std::string& url, |
307 ContentType contentType, | 310 int32_t contentTypeMask, |
308 const std::vector<std::string>& documentUrls) const | 311 const std::vector<std::string>& documentUrls) const |
309 { | 312 { |
310 if (documentUrls.empty()) | 313 if (documentUrls.empty()) |
311 return CheckFilterMatch(url, contentType, ""); | 314 return CheckFilterMatch(url, contentTypeMask, ""); |
312 | 315 |
313 std::string lastDocumentUrl = documentUrls.front(); | 316 std::string lastDocumentUrl = documentUrls.front(); |
314 for (std::vector<std::string>::const_iterator it = documentUrls.begin(); | 317 for (std::vector<std::string>::const_iterator it = documentUrls.begin(); |
315 it != documentUrls.end(); it++) { | 318 it != documentUrls.end(); it++) { |
316 const std::string documentUrl = *it; | 319 const std::string documentUrl = *it; |
317 AdblockPlus::FilterPtr match = CheckFilterMatch(documentUrl, | 320 AdblockPlus::FilterPtr match = CheckFilterMatch(documentUrl, |
318 CONTENT_TYPE_DOCUMENT, | 321 CONTENT_TYPE_DOCUMENT, |
319 lastDocumentUrl); | 322 lastDocumentUrl); |
320 if (match && match->GetType() == AdblockPlus::Filter::TYPE_EXCEPTION) | 323 if (match && match->GetType() == AdblockPlus::Filter::TYPE_EXCEPTION) |
321 return match; | 324 return match; |
322 lastDocumentUrl = documentUrl; | 325 lastDocumentUrl = documentUrl; |
323 } | 326 } |
324 | 327 |
325 return CheckFilterMatch(url, contentType, lastDocumentUrl); | 328 return CheckFilterMatch(url, contentTypeMask, lastDocumentUrl); |
326 } | 329 } |
327 | 330 |
328 bool FilterEngine::IsDocumentWhitelisted(const std::string& url, | 331 bool FilterEngine::IsDocumentWhitelisted(const std::string& url, |
329 const std::vector<std::string>& documentUrls) const | 332 const std::vector<std::string>& documentUrls) const |
330 { | 333 { |
331 return !!GetWhitelistingFilter(url, CONTENT_TYPE_DOCUMENT, documentUrls); | 334 return !!GetWhitelistingFilter(url, CONTENT_TYPE_DOCUMENT, documentUrls); |
332 } | 335 } |
333 | 336 |
334 bool FilterEngine::IsElemhideWhitelisted(const std::string& url, | 337 bool FilterEngine::IsElemhideWhitelisted(const std::string& url, |
335 const std::vector<std::string>& documentUrls) const | 338 const std::vector<std::string>& documentUrls) const |
336 { | 339 { |
337 return !!GetWhitelistingFilter(url, CONTENT_TYPE_ELEMHIDE, documentUrls); | 340 return !!GetWhitelistingFilter(url, CONTENT_TYPE_ELEMHIDE, documentUrls); |
338 } | 341 } |
339 | 342 |
340 AdblockPlus::FilterPtr FilterEngine::CheckFilterMatch(const std::string& url, | 343 AdblockPlus::FilterPtr FilterEngine::CheckFilterMatch(const std::string& url, |
341 ContentType contentType, | 344 int32_t contentTypeMask, |
342 const std::string& documentUrl) const | 345 const std::string& documentUrl) const |
343 { | 346 { |
344 JsValuePtr func = jsEngine->Evaluate("API.checkFilterMatch"); | 347 JsValuePtr func = jsEngine->Evaluate("API.checkFilterMatch"); |
345 JsValueList params; | 348 JsValueList params; |
346 params.push_back(jsEngine->NewValue(url)); | 349 params.push_back(jsEngine->NewValue(url)); |
347 params.push_back(jsEngine->NewValue(ContentTypeToString(contentType))); | 350 params.push_back(jsEngine->NewValue(contentTypeMask)); |
348 params.push_back(jsEngine->NewValue(documentUrl)); | 351 params.push_back(jsEngine->NewValue(documentUrl)); |
349 JsValuePtr result = func->Call(params); | 352 JsValuePtr result = func->Call(params); |
350 if (!result->IsNull()) | 353 if (!result->IsNull()) |
351 return FilterPtr(new Filter(result)); | 354 return FilterPtr(new Filter(result)); |
352 else | 355 else |
353 return FilterPtr(); | 356 return FilterPtr(); |
354 } | 357 } |
355 | 358 |
356 std::vector<std::string> FilterEngine::GetElementHidingSelectors(const std::stri
ng& domain) const | 359 std::vector<std::string> FilterEngine::GetElementHidingSelectors(const std::stri
ng& domain) const |
357 { | 360 { |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 int FilterEngine::CompareVersions(const std::string& v1, const std::string& v2) | 472 int FilterEngine::CompareVersions(const std::string& v1, const std::string& v2) |
470 { | 473 { |
471 JsValueList params; | 474 JsValueList params; |
472 params.push_back(jsEngine->NewValue(v1)); | 475 params.push_back(jsEngine->NewValue(v1)); |
473 params.push_back(jsEngine->NewValue(v2)); | 476 params.push_back(jsEngine->NewValue(v2)); |
474 JsValuePtr func = jsEngine->Evaluate("API.compareVersions"); | 477 JsValuePtr func = jsEngine->Evaluate("API.compareVersions"); |
475 return func->Call(params)->AsInt(); | 478 return func->Call(params)->AsInt(); |
476 } | 479 } |
477 | 480 |
478 FilterPtr FilterEngine::GetWhitelistingFilter(const std::string& url, | 481 FilterPtr FilterEngine::GetWhitelistingFilter(const std::string& url, |
479 ContentType contentType, const std::string& documentUrl) const | 482 int32_t contentTypeMask, const std::string& documentUrl) const |
480 { | 483 { |
481 FilterPtr match = Matches(url, contentType, documentUrl); | 484 FilterPtr match = Matches(url, contentTypeMask, documentUrl); |
482 if (match && match->GetType() == Filter::TYPE_EXCEPTION) | 485 if (match && match->GetType() == Filter::TYPE_EXCEPTION) |
483 { | 486 { |
484 return match; | 487 return match; |
485 } | 488 } |
486 return FilterPtr(); | 489 return FilterPtr(); |
487 } | 490 } |
488 | 491 |
489 FilterPtr FilterEngine::GetWhitelistingFilter(const std::string& url, | 492 FilterPtr FilterEngine::GetWhitelistingFilter(const std::string& url, |
490 ContentType contentType, | 493 int32_t contentTypeMask, |
491 const std::vector<std::string>& documentUrls) const | 494 const std::vector<std::string>& documentUrls) const |
492 { | 495 { |
493 if (documentUrls.empty()) | 496 if (documentUrls.empty()) |
494 { | 497 { |
495 return GetWhitelistingFilter(url, contentType, ""); | 498 return GetWhitelistingFilter(url, contentTypeMask, ""); |
496 } | 499 } |
497 | 500 |
498 std::vector<std::string>::const_iterator urlIterator = documentUrls.begin(); | 501 std::vector<std::string>::const_iterator urlIterator = documentUrls.begin(); |
499 std::string currentUrl = url; | 502 std::string currentUrl = url; |
500 do | 503 do |
501 { | 504 { |
502 std::string parentUrl = *urlIterator++; | 505 std::string parentUrl = *urlIterator++; |
503 FilterPtr filter = GetWhitelistingFilter( | 506 FilterPtr filter = GetWhitelistingFilter(currentUrl, contentTypeMask, parent
Url); |
504 currentUrl, contentType, parentUrl); | |
505 if (filter) | 507 if (filter) |
506 { | 508 { |
507 return filter; | 509 return filter; |
508 } | 510 } |
509 currentUrl = parentUrl; | 511 currentUrl = parentUrl; |
510 } | 512 } |
511 while (urlIterator != documentUrls.end()); | 513 while (urlIterator != documentUrls.end()); |
512 return FilterPtr(); | 514 return FilterPtr(); |
513 } | 515 } |
OLD | NEW |