| Index: src/plugin/AdblockPlusDomTraverser.cpp |
| =================================================================== |
| --- a/src/plugin/AdblockPlusDomTraverser.cpp |
| +++ b/src/plugin/AdblockPlusDomTraverser.cpp |
| @@ -5,6 +5,7 @@ |
| #include "PluginSettings.h" |
| #include "AdblockPlusDomTraverser.h" |
| +#include "PluginUtil.h" |
| CPluginDomTraverser::CPluginDomTraverser(CPluginTab* tab) : CPluginDomTraverserBase(tab) |
| @@ -12,7 +13,7 @@ |
| } |
| -bool CPluginDomTraverser::OnIFrame(IHTMLElement* pEl, const CString& url, CString& indent) |
| +bool CPluginDomTraverser::OnIFrame(IHTMLElement* pEl, const std::wstring & url, std::wstring & indent) |
| { |
| CPluginClient* client = CPluginClient::GetInstance(); |
| @@ -20,14 +21,14 @@ |
| bool isBlocked = client->ShouldBlock(url, CFilter::contentTypeSubdocument, m_domain); |
| if (isBlocked) |
| { |
| - HideElement(pEl, "iframe", url, true, indent); |
| + HideElement(pEl, L"iframe", url, true, indent); |
| } |
| return !isBlocked; |
| } |
| -bool CPluginDomTraverser::OnElement(IHTMLElement* pEl, const CString& tag, CPluginDomTraverserCache* cache, bool isDebug, CString& indent) |
| +bool CPluginDomTraverser::OnElement(IHTMLElement* pEl, const std::wstring & tag, CPluginDomTraverserCache* cache, bool isDebug, std::wstring & indent) |
| { |
| if (cache->m_isHidden) |
| { |
| @@ -40,66 +41,65 @@ |
| cache->m_isHidden = client->IsElementHidden(tag, pEl, m_domain, indent, m_tab->m_filter.get()); |
| if (cache->m_isHidden) |
| { |
| - HideElement(pEl, tag, "", false, indent); |
| + HideElement(pEl, tag, L"", false, indent); |
| return false; |
| } |
| // Images |
| - if (tag == "img") |
| + if (tag == L"img") |
| { |
| - CComVariant vAttr; |
| - |
| - if (SUCCEEDED(pEl->getAttribute(L"src", 0, &vAttr)) && vAttr.vt == VT_BSTR && ::SysStringLen(vAttr.bstrVal) > 0) |
| + Wrapper::HTML_Element element( pEl ); |
| + std::wstring src; |
| + if ( element.attribute( L"src", src ) && !src.empty() ) |
| { |
| - CString src = vAttr.bstrVal; |
| - CPluginClient::UnescapeUrl(src); |
| + Wrapper::Unescape_URL( src ); |
| // If src should be blocked, set style display:none on image |
| cache->m_isHidden = client->ShouldBlock(src, CFilter::contentTypeImage, m_domain); |
| if (cache->m_isHidden) |
| { |
| - HideElement(pEl, "image", src, true, indent); |
| + HideElement(pEl, L"image", src, true, indent); |
| return false; |
| } |
| } |
| } |
| // Objects |
| - else if (tag == "object") |
| + else if (tag == L"object") |
| { |
| - CComBSTR bstrInnerHtml; |
| + Wrapper::HTML_Element element( pEl ); |
| + std::wstring object_html; |
| + element.inner_HTML( object_html ); |
| + if ( element.inner_HTML( object_html ) && !object_html.empty() ) |
| + { |
| + std::wstring src; |
| - if (SUCCEEDED(pEl->get_innerHTML(&bstrInnerHtml)) && bstrInnerHtml) |
| - { |
| - CString sObjectHtml = bstrInnerHtml; |
| - CString src; |
| - |
| - int posBegin = sObjectHtml.Find(L"VALUE=\""); |
| - int posEnd = posBegin >= 0 ? sObjectHtml.Find('\"', posBegin + 7) : -1; |
| + int posBegin = object_html.find( L"VALUE=\"" ); |
| + int posEnd = ( posBegin >= 0 ) ? object_html.find( L'\"', posBegin + 7 ) : -1; |
| while (posBegin >= 0 && posEnd >= 0) |
| { |
| posBegin += 7; |
| - src = sObjectHtml.Mid(posBegin, posEnd - posBegin); |
| + src = object_html.substr( posBegin, posEnd - posBegin ); |
| // eg. http://w3schools.com/html/html_examples.asp |
| - if (src.Left(2) == "//") |
| + if ( ABP::util::begins_with( src, L"//" ) ) |
| { |
| - src = "http:" + src; |
| + src = L"http:" + src; |
| } |
| - if (!src.IsEmpty()) |
| + if ( !src.empty() ) |
| { |
| // cache->m_isHidden = client->ShouldBlock(src, CFilter::contentTypeObject, m_domain); |
| if (cache->m_isHidden) |
| { |
| - HideElement(pEl, "object", src, true, indent); |
| + HideElement(pEl, L"object", src, true, indent); |
| return false; |
| } |
| } |
| - posBegin = sObjectHtml.Find(L"VALUE=\"", posBegin); |
| - posEnd = posBegin >= 0 ? sObjectHtml.Find(L"\"", posBegin + 7) : -1; |
| + posBegin = object_html.find( L"VALUE=\"", posBegin ); |
| + posEnd = ( posBegin >= 0 ) ? object_html.find( L'\"', posBegin + 7 ) : -1; |
| } |
| } |
| } |
| @@ -116,29 +116,27 @@ |
| } |
| -void CPluginDomTraverser::HideElement(IHTMLElement* pEl, const CString& type, const CString& url, bool isDebug, CString& indent) |
| +void CPluginDomTraverser::HideElement(IHTMLElement* pEl, const std::wstring & type, const std::wstring & url, bool isDebug, std::wstring & indent) |
| { |
| CComPtr<IHTMLStyle> pStyle; |
| if (SUCCEEDED(pEl->get_style(&pStyle)) && pStyle) |
| { |
| - CComBSTR bstrDisplay; |
| - |
| - if (SUCCEEDED(pStyle->get_display(&bstrDisplay)) && bstrDisplay && CString(bstrDisplay) == L"none") |
| + std::wstring display; |
| + Wrapper::HTML_Style style( pStyle ); |
| + if ( style.display( display ) && display == L"none" ) |
| { |
| return; |
| } |
| - static const CComBSTR sbstrNone(L"none"); |
| - |
| - if (SUCCEEDED(pStyle->put_display(sbstrNone))) |
| + if ( style.assign_display( L"none" ) ) |
| { |
| DEBUG_HIDE_EL(indent + L"HideEl::Hiding " + type + L" url:" + url) |
| #ifdef ENABLE_DEBUG_RESULT |
| if (isDebug) |
| { |
| - CPluginDebug::DebugResultHiding(type, url, "-"); |
| + CPluginDebug::DebugResultHiding(type, url, L"-"); |
| } |
| #endif // ENABLE_DEBUG_RESULT |
| } |