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: merge GetAttributeValueAsString into the caller Created Nov. 19, 2014, 11:52 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 std::pair<std::wstring, bool> GetHtmlElementAttribute(IHTMLElement& htmlElemen t, const ATL::CComBSTR& attributeName) 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 std::pair<std::wstring, bool> retResult; 25 GetHtmlElementAttributeResult() : isAttributeFound(false)
26 retResult.second = false; 26 {
27 }
28 std::wstring attributeValue;
29 bool isAttributeFound;
30 };
31
32 GetHtmlElementAttributeResult GetHtmlElementAttribute(IHTMLElement& htmlElemen t,
33 const ATL::CComBSTR& attributeName)
34 {
35 GetHtmlElementAttributeResult retValue;
27 ATL::CComVariant vAttr; 36 ATL::CComVariant vAttr;
28 ATL::CComQIPtr<IHTMLElement4> htmlElement4 = &htmlElement; 37 ATL::CComPtr<IHTMLElement4> htmlElement4;
29 if (!htmlElement4) 38 if (FAILED(htmlElement.QueryInterface(&htmlElement4)) || !htmlElement4)
30 { 39 {
31 return retResult; 40 return retValue;
32 } 41 }
33 ATL::CComPtr<IHTMLDOMAttribute> attributeNode; 42 ATL::CComPtr<IHTMLDOMAttribute> attributeNode;
34 if (FAILED(htmlElement4->getAttributeNode(attributeName, &attributeNode)) || !attributeNode) 43 if (FAILED(htmlElement4->getAttributeNode(attributeName, &attributeNode)) || !attributeNode)
35 { 44 {
36 return retResult; 45 return retValue;
37 } 46 }
38 // 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
39 retResult.second = true; 48 retValue.isAttributeFound = true;
40 if (FAILED(attributeNode->get_nodeValue(&vAttr))) 49 if (FAILED(attributeNode->get_nodeValue(&vAttr)))
41 { 50 {
42 return retResult; 51 return retValue;
43 } 52 }
44 if (vAttr.vt == VT_BSTR && vAttr.bstrVal) 53 if (vAttr.vt == VT_BSTR && vAttr.bstrVal)
45 { 54 {
46 retResult.first = vAttr.bstrVal; 55 retValue.attributeValue = vAttr.bstrVal;
47 } 56 }
48 else if (vAttr.vt == VT_I4) 57 else if (vAttr.vt == VT_I4)
49 { 58 {
50 retResult.first = std::to_wstring(vAttr.iVal); 59 retValue.attributeValue = std::to_wstring(vAttr.iVal);
51 } 60 }
52 return retResult; 61 return retValue;
53 } 62 }
54 } 63 }
55 64
56 // ============================================================================ 65 // ============================================================================
57 // CFilterElementHideAttrSelector 66 // CFilterElementHideAttrSelector
58 // ============================================================================ 67 // ============================================================================
59 68
60 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)
61 { 70 {
62 } 71 }
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 if ((hr != S_OK) || (tagName != CComBSTR(m_tag))) 322 if ((hr != S_OK) || (tagName != CComBSTR(m_tag)))
314 { 323 {
315 return false; 324 return false;
316 } 325 }
317 } 326 }
318 327
319 // Check attributes 328 // Check attributes
320 for (std::vector<CFilterElementHideAttrSelector>::const_iterator attrIt = m_at tributeSelectors.begin(); 329 for (std::vector<CFilterElementHideAttrSelector>::const_iterator attrIt = m_at tributeSelectors.begin();
321 attrIt != m_attributeSelectors.end(); ++ attrIt) 330 attrIt != m_attributeSelectors.end(); ++ attrIt)
322 { 331 {
323 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
324 bool attrFound = false; 333 bool attrFound = false;
325 if (attrIt->m_type == CFilterElementHideAttrType::STYLE) 334 if (attrIt->m_type == CFilterElementHideAttrType::STYLE)
326 { 335 {
327 CComPtr<IHTMLStyle> pStyle; 336 CComPtr<IHTMLStyle> pStyle;
328 if (SUCCEEDED(pEl->get_style(&pStyle)) && pStyle) 337 if (SUCCEEDED(pEl->get_style(&pStyle)) && pStyle)
329 { 338 {
330 CComBSTR bstrStyle; 339 CComBSTR bstrStyle;
331 340
332 if (SUCCEEDED(pStyle->get_cssText(&bstrStyle)) && bstrStyle) 341 if (SUCCEEDED(pStyle->get_cssText(&bstrStyle)) && bstrStyle)
333 { 342 {
(...skipping 16 matching lines...) Expand all
350 { 359 {
351 CComBSTR bstrId; 360 CComBSTR bstrId;
352 if (SUCCEEDED(pEl->get_id(&bstrId)) && bstrId) 361 if (SUCCEEDED(pEl->get_id(&bstrId)) && bstrId)
353 { 362 {
354 value = bstrId; 363 value = bstrId;
355 attrFound = true; 364 attrFound = true;
356 } 365 }
357 } 366 }
358 else 367 else
359 { 368 {
360 auto attribute = GetHtmlElementAttribute(*pEl, attrIt->m_bstrAttr); 369 auto attributeValue = GetHtmlElementAttribute(*pEl, attrIt->m_bstrAttr);
361 if (attrFound = attribute.second) 370 if (attrFound = attributeValue.isAttributeFound)
362 { 371 {
363 value = ToCString(attribute.first); 372 value = ToCString(attributeValue.attributeValue);
364 } 373 }
365 } 374 }
366 375
367 if (attrFound) 376 if (attrFound)
368 { 377 {
369 if (attrIt->m_pos == CFilterElementHideAttrPos::EXACT) 378 if (attrIt->m_pos == CFilterElementHideAttrPos::EXACT)
370 { 379 {
371 // 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.
372 if (value != attrIt->m_value) 381 if (value != attrIt->m_value)
373 return false; 382 return false;
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
730 CPluginDebug::DebugResultBlocking(type, srcCString, domain); 739 CPluginDebug::DebugResultBlocking(type, srcCString, domain);
731 #endif 740 #endif
732 } 741 }
733 return true; 742 return true;
734 } 743 }
735 #ifdef ENABLE_DEBUG_RESULT 744 #ifdef ENABLE_DEBUG_RESULT
736 CPluginDebug::DebugResultIgnoring(type, srcCString, domain); 745 CPluginDebug::DebugResultIgnoring(type, srcCString, domain);
737 #endif 746 #endif
738 return false; 747 return false;
739 } 748 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld