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

Delta Between Two Patch Sets: src/plugin/PluginFilter.cpp

Issue 6433575100481536: Issue 1148 - ABP on chrome blocks ads but IE doesnt (Closed)
Left Patch Set: fix according to comments Created Nov. 21, 2014, 11:44 a.m.
Right Patch Set: fix according to the discussion Created Nov. 27, 2014, 1:10 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 | « no previous file | src/plugin/PluginUtil.h » ('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 #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 struct GetHtmlElementAttributeResult 23 struct GetHtmlElementAttributeResult
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 GetHtmlElementAttributeResult() : isAttributeFound(false) 25 GetHtmlElementAttributeResult() : isAttributeFound(false)
26 { 26 {
27 } 27 }
28 std::wstring attributeValue; 28 std::wstring attributeValue;
29 bool isAttributeFound; 29 bool isAttributeFound;
30 }; 30 };
31 31
32 bool GetHtmlElementAttribute(IHTMLElement* htmlElement, 32 GetHtmlElementAttributeResult GetHtmlElementAttribute(IHTMLElement& htmlElemen t,
33 const ATL::CComBSTR& attributeName, GetHtmlElementAttributeResult& retValue) 33 const ATL::CComBSTR& attributeName)
34 { 34 {
35 if (!htmlElement) 35 GetHtmlElementAttributeResult retValue;
36 {
37 return false;
38 }
39 ATL::CComVariant vAttr; 36 ATL::CComVariant vAttr;
40 ATL::CComPtr<IHTMLElement4> htmlElement4; 37 ATL::CComPtr<IHTMLElement4> htmlElement4;
41 if (FAILED(htmlElement->QueryInterface(&htmlElement4)) || !htmlElement4) 38 if (FAILED(htmlElement.QueryInterface(&htmlElement4)) || !htmlElement4)
42 { 39 {
43 return false; 40 return retValue;
44 } 41 }
45 ATL::CComPtr<IHTMLDOMAttribute> attributeNode; 42 ATL::CComPtr<IHTMLDOMAttribute> attributeNode;
46 if (FAILED(htmlElement4->getAttributeNode(attributeName, &attributeNode)) || !attributeNode) 43 if (FAILED(htmlElement4->getAttributeNode(attributeName, &attributeNode)) || !attributeNode)
47 { 44 {
48 return false; 45 return retValue;
49 } 46 }
50 // 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
51 retValue.isAttributeFound = true; 48 retValue.isAttributeFound = true;
52 if (FAILED(attributeNode->get_nodeValue(&vAttr))) 49 if (FAILED(attributeNode->get_nodeValue(&vAttr)))
53 { 50 {
54 return false; 51 return retValue;
55 } 52 }
56 if (vAttr.vt == VT_BSTR && vAttr.bstrVal) 53 if (vAttr.vt == VT_BSTR && vAttr.bstrVal)
57 { 54 {
58 retValue.attributeValue = vAttr.bstrVal; 55 retValue.attributeValue = vAttr.bstrVal;
59 } 56 }
60 else if (vAttr.vt == VT_I4) 57 else if (vAttr.vt == VT_I4)
61 { 58 {
62 retValue.attributeValue = std::to_wstring(vAttr.iVal); 59 retValue.attributeValue = std::to_wstring(vAttr.iVal);
63 } 60 }
64 return true; 61 return retValue;
65 } 62 }
66 } 63 }
67 64
68 // ============================================================================ 65 // ============================================================================
69 // CFilterElementHideAttrSelector 66 // CFilterElementHideAttrSelector
70 // ============================================================================ 67 // ============================================================================
71 68
72 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)
73 { 70 {
74 } 71 }
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 if ((hr != S_OK) || (tagName != CComBSTR(m_tag))) 322 if ((hr != S_OK) || (tagName != CComBSTR(m_tag)))
326 { 323 {
327 return false; 324 return false;
328 } 325 }
329 } 326 }
330 327
331 // Check attributes 328 // Check attributes
332 for (std::vector<CFilterElementHideAttrSelector>::const_iterator attrIt = m_at tributeSelectors.begin(); 329 for (std::vector<CFilterElementHideAttrSelector>::const_iterator attrIt = m_at tributeSelectors.begin();
333 attrIt != m_attributeSelectors.end(); ++ attrIt) 330 attrIt != m_attributeSelectors.end(); ++ attrIt)
334 { 331 {
335 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
336 bool attrFound = false; 333 bool attrFound = false;
337 if (attrIt->m_type == CFilterElementHideAttrType::STYLE) 334 if (attrIt->m_type == CFilterElementHideAttrType::STYLE)
338 { 335 {
339 CComPtr<IHTMLStyle> pStyle; 336 CComPtr<IHTMLStyle> pStyle;
340 if (SUCCEEDED(pEl->get_style(&pStyle)) && pStyle) 337 if (SUCCEEDED(pEl->get_style(&pStyle)) && pStyle)
341 { 338 {
342 CComBSTR bstrStyle; 339 CComBSTR bstrStyle;
343 340
344 if (SUCCEEDED(pStyle->get_cssText(&bstrStyle)) && bstrStyle) 341 if (SUCCEEDED(pStyle->get_cssText(&bstrStyle)) && bstrStyle)
345 { 342 {
(...skipping 16 matching lines...) Expand all
362 { 359 {
363 CComBSTR bstrId; 360 CComBSTR bstrId;
364 if (SUCCEEDED(pEl->get_id(&bstrId)) && bstrId) 361 if (SUCCEEDED(pEl->get_id(&bstrId)) && bstrId)
365 { 362 {
366 value = bstrId; 363 value = bstrId;
367 attrFound = true; 364 attrFound = true;
368 } 365 }
369 } 366 }
370 else 367 else
371 { 368 {
372 GetHtmlElementAttributeResult attributeValue; 369 auto attributeValue = GetHtmlElementAttribute(*pEl, attrIt->m_bstrAttr);
373 bool rc = GetHtmlElementAttribute(pEl, attrIt->m_bstrAttr, attributeValue) ; 370 if (attrFound = attributeValue.isAttributeFound)
374 if (rc && (attrFound = attributeValue.isAttributeFound))
375 { 371 {
376 value = ToCString(attributeValue.attributeValue); 372 value = ToCString(attributeValue.attributeValue);
377 } 373 }
378 } 374 }
379 375
380 if (attrFound) 376 if (attrFound)
381 { 377 {
382 if (attrIt->m_pos == CFilterElementHideAttrPos::EXACT) 378 if (attrIt->m_pos == CFilterElementHideAttrPos::EXACT)
383 { 379 {
384 // 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.
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
743 CPluginDebug::DebugResultBlocking(type, srcCString, domain); 739 CPluginDebug::DebugResultBlocking(type, srcCString, domain);
744 #endif 740 #endif
745 } 741 }
746 return true; 742 return true;
747 } 743 }
748 #ifdef ENABLE_DEBUG_RESULT 744 #ifdef ENABLE_DEBUG_RESULT
749 CPluginDebug::DebugResultIgnoring(type, srcCString, domain); 745 CPluginDebug::DebugResultIgnoring(type, srcCString, domain);
750 #endif 746 #endif
751 return false; 747 return false;
752 } 748 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld