| Index: src/plugin/PluginFilter.cpp |
| =================================================================== |
| --- a/src/plugin/PluginFilter.cpp |
| +++ b/src/plugin/PluginFilter.cpp |
| @@ -11,12 +11,60 @@ |
| #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 |
| + { |
| + GetHtmlElementAttributeResult() : isAttributeFound(false) |
| + { |
| + } |
| + std::wstring attributeValue; |
| + bool isAttributeFound; |
| + }; |
| + |
| + bool GetHtmlElementAttribute(IHTMLElement* htmlElement, |
| + const ATL::CComBSTR& attributeName, GetHtmlElementAttributeResult& retValue) |
| + { |
| + if (!htmlElement) |
| + { |
| + return false; |
| + } |
| + ATL::CComVariant vAttr; |
| + ATL::CComPtr<IHTMLElement4> htmlElement4; |
| + if (FAILED(htmlElement->QueryInterface(&htmlElement4)) || !htmlElement4) |
| + { |
| + return false; |
| + } |
| + ATL::CComPtr<IHTMLDOMAttribute> attributeNode; |
| + if (FAILED(htmlElement4->getAttributeNode(attributeName, &attributeNode)) || !attributeNode) |
| + { |
| + return false; |
| + } |
| + // 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 false; |
| + } |
| + 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 true; |
| + } |
| +} |
| + |
| // ============================================================================ |
| // CFilterElementHideAttrSelector |
| // ============================================================================ |
| @@ -272,8 +320,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 +332,7 @@ |
| for (std::vector<CFilterElementHideAttrSelector>::const_iterator attrIt = m_attributeSelectors.begin(); |
| attrIt != m_attributeSelectors.end(); ++ attrIt) |
| { |
| - CString value; |
| + ATL::CString value; |
| bool attrFound = false; |
| if (attrIt->m_type == CFilterElementHideAttrType::STYLE) |
| { |
| @@ -319,20 +367,13 @@ |
| attrFound = true; |
| } |
| } |
| - else |
| + else |
| { |
| - CComVariant vAttr; |
| - if (SUCCEEDED(pEl->getAttribute(attrIt->m_bstrAttr, 0, &vAttr))) |
| + GetHtmlElementAttributeResult attributeValue; |
| + bool rc = GetHtmlElementAttribute(pEl, attrIt->m_bstrAttr, attributeValue); |
| + if (rc && (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 +476,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 +501,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 +556,7 @@ |
| classNames = bstrClassNames; |
| } |
| - CriticalSection::Lock filterEngineLock(s_criticalSectionFilterMap); |
| + CriticalSection::Lock filterEngineLock(s_criticalSectionFilterMap); |
| { |
| // Search tag/id filters |
| if (!id.IsEmpty()) |
| @@ -621,7 +658,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) |
| { |