Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 #include "PluginStdAfx.h" | 1 #include "PluginStdAfx.h" |
2 | 2 |
3 #include "PluginFilter.h" | 3 #include "PluginFilter.h" |
4 #include "PluginSettings.h" | 4 #include "PluginSettings.h" |
5 #include "PluginClient.h" | 5 #include "PluginClient.h" |
6 #include "PluginClientFactory.h" | 6 #include "PluginClientFactory.h" |
7 #include "PluginMutex.h" | 7 #include "PluginMutex.h" |
8 #include "PluginSettings.h" | 8 #include "PluginSettings.h" |
9 #include "PluginSystem.h" | 9 #include "PluginSystem.h" |
10 #include "PluginClass.h" | 10 #include "PluginClass.h" |
11 #include "mlang.h" | 11 #include "mlang.h" |
12 | 12 |
13 #include "..\shared\CriticalSection.h" | 13 #include "..\shared\CriticalSection.h" |
14 #include "..\shared\Utils.h" | 14 #include "..\shared\Utils.h" |
15 | 15 |
16 | 16 |
17 // The filters are described at http://adblockplus.org/en/filters | 17 // The filters are described at http://adblockplus.org/en/filters |
18 | 18 |
19 static CriticalSection s_criticalSectionFilterMap; | 19 static CriticalSection s_criticalSectionFilterMap; |
20 | 20 |
21 namespace | 21 namespace |
22 { | 22 { |
23 std::wstring GetAttributeValueAsString(const ATL::CComVariant& vAttr) | 23 struct GetHtmlElementAttributeResult |
Oleksandr
2014/11/19 03:24:23
Is it really required for this to be a separate fu
sergei
2014/11/19 11:53:24
It's not required. Firstly I extracted it during d
|
Felix Dahlke
2014/11/27 13:58:46
How about "HtmlAttributeMatch" or something in tha
sergei
2014/11/27 14:47:25
I also don't feel it to be a good name, but I find
Felix Dahlke
2014/11/27 14:57:27
Fair enough, yeah. Let's go with GetHtmlElementAtt
|
24 { | 24 { |
25 if (vAttr.vt == VT_BSTR && vAttr.bstrVal) | 25 GetHtmlElementAttributeResult() : isAttributeFound(false) |
26 { | 26 { |
27 return vAttr.bstrVal; | 27 } |
28 } | 28 std::wstring attributeValue; |
29 else if (vAttr.vt == VT_I4) | 29 bool isAttributeFound; |
30 { | 30 }; |
31 return std::to_wstring(vAttr.iVal); | 31 |
32 } | 32 GetHtmlElementAttributeResult GetHtmlElementAttribute(IHTMLElement& htmlElemen t, |
33 return std::wstring(); | 33 const ATL::CComBSTR& attributeName) |
34 } | 34 { |
35 | 35 GetHtmlElementAttributeResult retValue; |
36 std::pair<std::wstring, bool> GetHtmlElementAttribute(IHTMLElement& htmlElemen t, const ATL::CComBSTR& attributeName) | |
Oleksandr
2014/11/19 03:24:23
How about something like this instead
std::wstring
sergei
2014/11/19 11:53:24
- I don't think that making `htmlElement` to be po
Oleksandr
2014/11/20 10:21:56
- I think it is inconsistent. We use pointers for
sergei
2014/11/21 12:02:21
In the function we need to check that it's not nul
Felix Dahlke
2014/11/26 14:23:16
I agree with Sergei here, IMO we should go with re
| |
37 { | |
38 std::pair<std::wstring, bool> retResult; | |
39 retResult.second = false; | |
40 ATL::CComVariant vAttr; | 36 ATL::CComVariant vAttr; |
41 ATL::CComQIPtr<IHTMLElement4> htmlElement4 = &htmlElement; | 37 ATL::CComPtr<IHTMLElement4> htmlElement4; |
Oleksandr
2014/11/19 03:24:23
I prefer manually calling QueryInterface. We are c
sergei
2014/11/19 11:53:24
We don't need HRESULT here, so I would say that
AT
Oleksandr
2014/11/20 10:21:56
We do QueryInterface in a lot of places in the cod
| |
42 if (!htmlElement4) | 38 if (FAILED(htmlElement.QueryInterface(&htmlElement4)) || !htmlElement4) |
43 { | 39 { |
44 return retResult; | 40 return retValue; |
45 } | 41 } |
46 ATL::CComPtr<IHTMLDOMAttribute> attributeNode; | 42 ATL::CComPtr<IHTMLDOMAttribute> attributeNode; |
47 if (FAILED(htmlElement4->getAttributeNode(attributeName, &attributeNode)) || !attributeNode) | 43 if (FAILED(htmlElement4->getAttributeNode(attributeName, &attributeNode)) || !attributeNode) |
48 { | 44 { |
49 return retResult; | 45 return retValue; |
50 } | 46 } |
51 // we set that attribute found but it's not necessary that we can retrieve i ts value | 47 // we set that attribute found but it's not necessary that we can retrieve i ts value |
52 retResult.second = true; | 48 retValue.isAttributeFound = true; |
53 if (FAILED(attributeNode->get_nodeValue(&vAttr))) | 49 if (FAILED(attributeNode->get_nodeValue(&vAttr))) |
54 { | 50 { |
55 return retResult; | 51 return retValue; |
56 } | 52 } |
57 retResult.first = GetAttributeValueAsString(vAttr); | 53 if (vAttr.vt == VT_BSTR && vAttr.bstrVal) |
58 return retResult; | 54 { |
55 retValue.attributeValue = vAttr.bstrVal; | |
56 } | |
57 else if (vAttr.vt == VT_I4) | |
58 { | |
59 retValue.attributeValue = std::to_wstring(vAttr.iVal); | |
60 } | |
61 return retValue; | |
59 } | 62 } |
60 } | 63 } |
61 | 64 |
62 // ============================================================================ | 65 // ============================================================================ |
63 // CFilterElementHideAttrSelector | 66 // CFilterElementHideAttrSelector |
64 // ============================================================================ | 67 // ============================================================================ |
65 | 68 |
66 CFilterElementHideAttrSelector::CFilterElementHideAttrSelector() : m_type(TYPE_N ONE), m_pos(POS_NONE), m_bstrAttr(NULL) | 69 CFilterElementHideAttrSelector::CFilterElementHideAttrSelector() : m_type(TYPE_N ONE), m_pos(POS_NONE), m_bstrAttr(NULL) |
67 { | 70 { |
68 } | 71 } |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
307 } | 310 } |
308 if (!foundMatch) | 311 if (!foundMatch) |
309 { | 312 { |
310 return false; | 313 return false; |
311 } | 314 } |
312 } | 315 } |
313 } | 316 } |
314 if (!m_tag.IsEmpty()) | 317 if (!m_tag.IsEmpty()) |
315 { | 318 { |
316 CComBSTR tagName; | 319 CComBSTR tagName; |
317 hr = pEl->get_tagName(&tagName); | 320 hr = pEl->get_tagName(&tagName); |
Oleksandr
2014/11/19 03:24:23
Well this was a long living bug :D. Nice!
| |
318 tagName.ToLower(); | 321 tagName.ToLower(); |
319 if ((hr != S_OK) || (tagName != CComBSTR(m_tag))) | 322 if ((hr != S_OK) || (tagName != CComBSTR(m_tag))) |
320 { | 323 { |
321 return false; | 324 return false; |
322 } | 325 } |
323 } | 326 } |
324 | 327 |
325 // Check attributes | 328 // Check attributes |
326 for (std::vector<CFilterElementHideAttrSelector>::const_iterator attrIt = m_at tributeSelectors.begin(); | 329 for (std::vector<CFilterElementHideAttrSelector>::const_iterator attrIt = m_at tributeSelectors.begin(); |
327 attrIt != m_attributeSelectors.end(); ++ attrIt) | 330 attrIt != m_attributeSelectors.end(); ++ attrIt) |
328 { | 331 { |
329 ATL::CString value; | 332 ATL::CString value; |
Felix Dahlke
2014/11/27 13:58:46
This change seems unrelated, hm? Plus we're still
sergei
2014/11/27 14:47:25
Yes, it's not important here, just was irritating
Felix Dahlke
2014/11/27 14:57:27
Yes I agree. It's just that we should avoid unrela
| |
330 bool attrFound = false; | 333 bool attrFound = false; |
331 if (attrIt->m_type == CFilterElementHideAttrType::STYLE) | 334 if (attrIt->m_type == CFilterElementHideAttrType::STYLE) |
332 { | 335 { |
333 CComPtr<IHTMLStyle> pStyle; | 336 CComPtr<IHTMLStyle> pStyle; |
334 if (SUCCEEDED(pEl->get_style(&pStyle)) && pStyle) | 337 if (SUCCEEDED(pEl->get_style(&pStyle)) && pStyle) |
335 { | 338 { |
336 CComBSTR bstrStyle; | 339 CComBSTR bstrStyle; |
337 | 340 |
338 if (SUCCEEDED(pStyle->get_cssText(&bstrStyle)) && bstrStyle) | 341 if (SUCCEEDED(pStyle->get_cssText(&bstrStyle)) && bstrStyle) |
339 { | 342 { |
(...skipping 16 matching lines...) Expand all Loading... | |
356 { | 359 { |
357 CComBSTR bstrId; | 360 CComBSTR bstrId; |
358 if (SUCCEEDED(pEl->get_id(&bstrId)) && bstrId) | 361 if (SUCCEEDED(pEl->get_id(&bstrId)) && bstrId) |
359 { | 362 { |
360 value = bstrId; | 363 value = bstrId; |
361 attrFound = true; | 364 attrFound = true; |
362 } | 365 } |
363 } | 366 } |
364 else | 367 else |
365 { | 368 { |
366 auto attribute = GetHtmlElementAttribute(*pEl, attrIt->m_bstrAttr); | 369 auto attributeValue = GetHtmlElementAttribute(*pEl, attrIt->m_bstrAttr); |
367 if (attrFound = attribute.second) | 370 if (attrFound = attributeValue.isAttributeFound) |
368 { | 371 { |
369 value = ToCString(attribute.first); | 372 value = ToCString(attributeValue.attributeValue); |
370 } | 373 } |
371 } | 374 } |
372 | 375 |
373 if (attrFound) | 376 if (attrFound) |
374 { | 377 { |
375 if (attrIt->m_pos == CFilterElementHideAttrPos::EXACT) | 378 if (attrIt->m_pos == CFilterElementHideAttrPos::EXACT) |
376 { | 379 { |
377 // TODO: IE rearranges the style attribute completely. Figure out if any thing can be done about it. | 380 // TODO: IE rearranges the style attribute completely. Figure out if any thing can be done about it. |
378 if (value != attrIt->m_value) | 381 if (value != attrIt->m_value) |
379 return false; | 382 return false; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
447 | 450 |
448 | 451 |
449 // ============================================================================ | 452 // ============================================================================ |
450 // CPluginFilter | 453 // CPluginFilter |
451 // ============================================================================ | 454 // ============================================================================ |
452 | 455 |
453 CPluginFilter::CPluginFilter(const CString& dataPath) : m_dataPath(dataPath) | 456 CPluginFilter::CPluginFilter(const CString& dataPath) : m_dataPath(dataPath) |
454 { | 457 { |
455 m_contentMapText[CFilter::contentTypeDocument] = "DOCUMENT"; | 458 m_contentMapText[CFilter::contentTypeDocument] = "DOCUMENT"; |
456 m_contentMapText[CFilter::contentTypeObject] = "OBJECT"; | 459 m_contentMapText[CFilter::contentTypeObject] = "OBJECT"; |
457 m_contentMapText[CFilter::contentTypeObjectSubrequest] = "OBJECT-SUBREQUEST"; | 460 m_contentMapText[CFilter::contentTypeObjectSubrequest] = "OBJECT_SUBREQUEST"; |
458 m_contentMapText[CFilter::contentTypeImage] = "IMAGE"; | 461 m_contentMapText[CFilter::contentTypeImage] = "IMAGE"; |
459 m_contentMapText[CFilter::contentTypeScript] = "SCRIPT"; | 462 m_contentMapText[CFilter::contentTypeScript] = "SCRIPT"; |
460 m_contentMapText[CFilter::contentTypeOther] = "OTHER"; | 463 m_contentMapText[CFilter::contentTypeOther] = "OTHER"; |
461 m_contentMapText[CFilter::contentTypeUnknown] = "OTHER"; | 464 m_contentMapText[CFilter::contentTypeUnknown] = "OTHER"; |
462 m_contentMapText[CFilter::contentTypeSubdocument] = "SUBDOCUMENT"; | 465 m_contentMapText[CFilter::contentTypeSubdocument] = "SUBDOCUMENT"; |
463 m_contentMapText[CFilter::contentTypeStyleSheet] = "STYLESHEET"; | 466 m_contentMapText[CFilter::contentTypeStyleSheet] = "STYLESHEET"; |
464 m_contentMapText[CFilter::contentTypeXmlHttpRequest] = "XMLHTTPREQUEST"; | 467 m_contentMapText[CFilter::contentTypeXmlHttpRequest] = "XMLHTTPREQUEST"; |
465 | 468 |
466 ClearFilters(); | 469 ClearFilters(); |
467 } | 470 } |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
736 CPluginDebug::DebugResultBlocking(type, srcCString, domain); | 739 CPluginDebug::DebugResultBlocking(type, srcCString, domain); |
737 #endif | 740 #endif |
738 } | 741 } |
739 return true; | 742 return true; |
740 } | 743 } |
741 #ifdef ENABLE_DEBUG_RESULT | 744 #ifdef ENABLE_DEBUG_RESULT |
742 CPluginDebug::DebugResultIgnoring(type, srcCString, domain); | 745 CPluginDebug::DebugResultIgnoring(type, srcCString, domain); |
743 #endif | 746 #endif |
744 return false; | 747 return false; |
745 } | 748 } |
LEFT | RIGHT |