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: merge GetAttributeValueAsString into the caller Created Nov. 19, 2014, 11:52 a.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,48 @@
#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
+{
+ std::pair<std::wstring, bool> GetHtmlElementAttribute(IHTMLElement& htmlElement, const ATL::CComBSTR& attributeName)
+ {
+ std::pair<std::wstring, bool> retResult;
+ retResult.second = false;
+ ATL::CComVariant vAttr;
+ ATL::CComQIPtr<IHTMLElement4> htmlElement4 = &htmlElement;
+ if (!htmlElement4)
+ {
+ return retResult;
+ }
+ ATL::CComPtr<IHTMLDOMAttribute> attributeNode;
+ if (FAILED(htmlElement4->getAttributeNode(attributeName, &attributeNode)) || !attributeNode)
+ {
+ return retResult;
+ }
+ // we set that attribute found but it's not necessary that we can retrieve its value
+ retResult.second = true;
+ if (FAILED(attributeNode->get_nodeValue(&vAttr)))
+ {
+ return retResult;
+ }
+ if (vAttr.vt == VT_BSTR && vAttr.bstrVal)
+ {
+ retResult.first = vAttr.bstrVal;
+ }
+ else if (vAttr.vt == VT_I4)
+ {
+ retResult.first = std::to_wstring(vAttr.iVal);
+ }
+ return retResult;
+ }
+}
+
// ============================================================================
// CFilterElementHideAttrSelector
// ============================================================================
@@ -272,8 +308,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 +320,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 +355,12 @@
attrFound = true;
}
}
- else
+ else
{
- CComVariant vAttr;
- if (SUCCEEDED(pEl->getAttribute(attrIt->m_bstrAttr, 0, &vAttr)))
+ auto attribute = GetHtmlElementAttribute(*pEl, attrIt->m_bstrAttr);
+ if (attrFound = attribute.second)
{
- attrFound = true;
- if (vAttr.vt == VT_BSTR)
- {
- value = vAttr.bstrVal;
- }
- else if (vAttr.vt == VT_I4)
- {
- value.Format(L"%u", vAttr.iVal);
- }
+ value = ToCString(attribute.first);
}
}
@@ -435,13 +463,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 +488,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 +543,7 @@
classNames = bstrClassNames;
}
- CriticalSection::Lock filterEngineLock(s_criticalSectionFilterMap);
+ CriticalSection::Lock filterEngineLock(s_criticalSectionFilterMap);
{
// Search tag/id filters
if (!id.IsEmpty())
@@ -621,7 +645,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