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 IE8 and simplify the code Created Nov. 10, 2014, 3:32 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') | src/plugin/PluginUtil.h » ('J')
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,54 @@
#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::wstring GetAttributeValueAsString(const ATL::CComVariant& vAttr)
Oleksandr 2014/11/19 03:24:23 Is it really required for this to be a separate fu
sergei 2014/11/19 11:53:24 It's not required. Firstly I extracted it during d
+ {
+ if (vAttr.vt == VT_BSTR && vAttr.bstrVal)
+ {
+ return vAttr.bstrVal;
+ }
+ else if (vAttr.vt == VT_I4)
+ {
+ return std::to_wstring(vAttr.iVal);
+ }
+ return std::wstring();
+ }
+
+ std::pair<std::wstring, bool> GetHtmlElementAttribute(IHTMLElement& htmlElement, const ATL::CComBSTR& attributeName)
Oleksandr 2014/11/19 03:24:23 How about something like this instead std::wstring
sergei 2014/11/19 11:53:24 - I don't think that making `htmlElement` to be po
Oleksandr 2014/11/20 10:21:56 - I think it is inconsistent. We use pointers for
sergei 2014/11/21 12:02:21 In the function we need to check that it's not nul
Felix Dahlke 2014/11/26 14:23:16 I agree with Sergei here, IMO we should go with re
+ {
+ std::pair<std::wstring, bool> retResult;
+ retResult.second = false;
+ ATL::CComVariant vAttr;
+ ATL::CComQIPtr<IHTMLElement4> htmlElement4 = &htmlElement;
Oleksandr 2014/11/19 03:24:23 I prefer manually calling QueryInterface. We are c
sergei 2014/11/19 11:53:24 We don't need HRESULT here, so I would say that AT
Oleksandr 2014/11/20 10:21:56 We do QueryInterface in a lot of places in the cod
+ 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;
+ }
+ retResult.first = GetAttributeValueAsString(vAttr);
+ return retResult;
+ }
+}
+
// ============================================================================
// CFilterElementHideAttrSelector
// ============================================================================
@@ -272,8 +314,8 @@
if (!m_tag.IsEmpty())
{
CComBSTR tagName;
+ hr = pEl->get_tagName(&tagName);
Oleksandr 2014/11/19 03:24:23 Well this was a long living bug :D. Nice!
tagName.ToLower();
- hr = pEl->get_tagName(&tagName);
if ((hr != S_OK) || (tagName != CComBSTR(m_tag)))
{
return false;
@@ -284,7 +326,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 +361,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 +469,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 +494,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 +549,7 @@
classNames = bstrClassNames;
}
- CriticalSection::Lock filterEngineLock(s_criticalSectionFilterMap);
+ CriticalSection::Lock filterEngineLock(s_criticalSectionFilterMap);
{
// Search tag/id filters
if (!id.IsEmpty())
@@ -621,7 +651,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') | src/plugin/PluginUtil.h » ('J')

Powered by Google App Engine
This is Rietveld