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

Unified Diff: src/plugin/PluginFilter.cpp

Issue 6433575100481536: Issue 1148 - ABP on chrome blocks ads but IE doesnt (Closed)
Patch Set: fix according to the discussion Created Nov. 27, 2014, 1:10 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/plugin/PluginUtil.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/plugin/PluginFilter.cpp
===================================================================
--- a/src/plugin/PluginFilter.cpp
+++ b/src/plugin/PluginFilter.cpp
@@ -11,12 +11,57 @@
#include "mlang.h"
#include "..\shared\CriticalSection.h"
+#include "..\shared\Utils.h"
// The filters are described at http://adblockplus.org/en/filters
static CriticalSection s_criticalSectionFilterMap;
+namespace
+{
+ 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
+ {
+ GetHtmlElementAttributeResult() : isAttributeFound(false)
+ {
+ }
+ std::wstring attributeValue;
+ bool isAttributeFound;
+ };
+
+ GetHtmlElementAttributeResult GetHtmlElementAttribute(IHTMLElement& htmlElement,
+ const ATL::CComBSTR& attributeName)
+ {
+ GetHtmlElementAttributeResult retValue;
+ ATL::CComVariant vAttr;
+ ATL::CComPtr<IHTMLElement4> htmlElement4;
+ if (FAILED(htmlElement.QueryInterface(&htmlElement4)) || !htmlElement4)
+ {
+ return retValue;
+ }
+ ATL::CComPtr<IHTMLDOMAttribute> attributeNode;
+ if (FAILED(htmlElement4->getAttributeNode(attributeName, &attributeNode)) || !attributeNode)
+ {
+ return retValue;
+ }
+ // we set that attribute found but it's not necessary that we can retrieve its value
+ retValue.isAttributeFound = true;
+ if (FAILED(attributeNode->get_nodeValue(&vAttr)))
+ {
+ return retValue;
+ }
+ if (vAttr.vt == VT_BSTR && vAttr.bstrVal)
+ {
+ retValue.attributeValue = vAttr.bstrVal;
+ }
+ else if (vAttr.vt == VT_I4)
+ {
+ retValue.attributeValue = std::to_wstring(vAttr.iVal);
+ }
+ return retValue;
+ }
+}
+
// ============================================================================
// CFilterElementHideAttrSelector
// ============================================================================
@@ -272,8 +317,8 @@
if (!m_tag.IsEmpty())
{
CComBSTR tagName;
+ hr = pEl->get_tagName(&tagName);
tagName.ToLower();
- hr = pEl->get_tagName(&tagName);
if ((hr != S_OK) || (tagName != CComBSTR(m_tag)))
{
return false;
@@ -284,7 +329,7 @@
for (std::vector<CFilterElementHideAttrSelector>::const_iterator attrIt = m_attributeSelectors.begin();
attrIt != m_attributeSelectors.end(); ++ attrIt)
{
- CString value;
+ 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
bool attrFound = false;
if (attrIt->m_type == CFilterElementHideAttrType::STYLE)
{
@@ -319,20 +364,12 @@
attrFound = true;
}
}
- else
+ else
{
- CComVariant vAttr;
- if (SUCCEEDED(pEl->getAttribute(attrIt->m_bstrAttr, 0, &vAttr)))
+ auto attributeValue = GetHtmlElementAttribute(*pEl, attrIt->m_bstrAttr);
+ if (attrFound = attributeValue.isAttributeFound)
{
- attrFound = true;
- if (vAttr.vt == VT_BSTR)
- {
- value = vAttr.bstrVal;
- }
- else if (vAttr.vt == VT_I4)
- {
- value.Format(L"%u", vAttr.iVal);
- }
+ value = ToCString(attributeValue.attributeValue);
}
}
@@ -435,13 +472,9 @@
bool CPluginFilter::AddFilterElementHide(CString filterText)
{
-
-
DEBUG_FILTER("Input: " + filterText + " filterFile" + filterFile);
-
- CriticalSection::Lock filterEngineLock(s_criticalSectionFilterMap);
+ CriticalSection::Lock filterEngineLock(s_criticalSectionFilterMap);
{
-
CString filterString = filterText;
// Create filter descriptor
std::auto_ptr<CFilterElementHide> filter;
@@ -464,7 +497,7 @@
CString filterChunk = filterText.Left(chunkEnd).TrimRight();
std::auto_ptr<CFilterElementHide> filterParent(filter);
- filter.reset(new CFilterElementHide(filterChunk));
+ filter.reset(new CFilterElementHide(filterChunk));
if (filterParent.get() != 0)
{
@@ -519,7 +552,7 @@
classNames = bstrClassNames;
}
- CriticalSection::Lock filterEngineLock(s_criticalSectionFilterMap);
+ CriticalSection::Lock filterEngineLock(s_criticalSectionFilterMap);
{
// Search tag/id filters
if (!id.IsEmpty())
@@ -621,7 +654,7 @@
// Parse hide string
int pos = 0;
- CriticalSection::Lock filterEngineLock(s_criticalSectionFilterMap);
+ CriticalSection::Lock filterEngineLock(s_criticalSectionFilterMap);
{
for (std::vector<std::wstring>::iterator it = filters.begin(); it < filters.end(); ++it)
{
« no previous file with comments | « no previous file | src/plugin/PluginUtil.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld