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

Side by Side Diff: src/plugin/AdblockPlusDomTraverser.cpp

Issue 29333350: Issue #3562 - Use 'ToWstring()' to convert BSTR values (Closed)
Patch Set: fix up error log message Created Jan. 11, 2016, 3:57 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/plugin/PluginClass.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 if (cache->m_isHidden) 58 if (cache->m_isHidden)
59 { 59 {
60 HideElement(pEl, tag, L"", false, indent); 60 HideElement(pEl, tag, L"", false, indent);
61 return false; 61 return false;
62 } 62 }
63 63
64 // Images 64 // Images
65 if (tag == L"img") 65 if (tag == L"img")
66 { 66 {
67 CComVariant vAttr; 67 CComVariant vAttr;
68 68 if (SUCCEEDED(pEl->getAttribute(ATL::CComBSTR(L"src"), 0, &vAttr)) && vAttr. vt == VT_BSTR)
69 if (SUCCEEDED(pEl->getAttribute(ATL::CComBSTR(L"src"), 0, &vAttr)) && vAttr. vt == VT_BSTR && ::SysStringLen(vAttr.bstrVal) > 0)
70 { 69 {
71 std::wstring src(vAttr.bstrVal, SysStringLen(vAttr.bstrVal)); 70 std::wstring src = ToWstring(vAttr.bstrVal);
72 71 if (!src.empty())
73 // If src should be blocked, set style display:none on image
74 cache->m_isHidden = client->ShouldBlock(src,
75 AdblockPlus::FilterEngine::ContentType::CONTENT_TYPE_IMAGE, m_documentUr l);
76 if (cache->m_isHidden)
77 { 72 {
78 HideElement(pEl, L"image", src, true, indent); 73 // If src should be blocked, set style display:none on image
79 return false; 74 cache->m_isHidden = client->ShouldBlock(src,
75 AdblockPlus::FilterEngine::ContentType::CONTENT_TYPE_IMAGE, m_document Url);
76 if (cache->m_isHidden)
77 {
78 HideElement(pEl, L"image", src, true, indent);
79 return false;
80 }
80 } 81 }
81 } 82 }
82 } 83 }
83 // Objects 84 // Objects
84 else if (tag == L"object") 85 else if (tag == L"object")
85 { 86 {
86 CComBSTR bstrInnerHtml; 87 CComBSTR bstrInnerHtml;
87 if (SUCCEEDED(pEl->get_innerHTML(&bstrInnerHtml)) && bstrInnerHtml) 88 if (SUCCEEDED(pEl->get_innerHTML(&bstrInnerHtml)) && bstrInnerHtml)
88 { 89 {
89 const std::wstring objectInnerHtml(ToWstring(bstrInnerHtml)); 90 const std::wstring objectInnerHtml(ToWstring(bstrInnerHtml));
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 } 132 }
132 133
133 134
134 void CPluginDomTraverser::HideElement(IHTMLElement* pEl, const std::wstring& typ e, const std::wstring& url, bool isDebug, const std::wstring& indent) 135 void CPluginDomTraverser::HideElement(IHTMLElement* pEl, const std::wstring& typ e, const std::wstring& url, bool isDebug, const std::wstring& indent)
135 { 136 {
136 CComPtr<IHTMLStyle> pStyle; 137 CComPtr<IHTMLStyle> pStyle;
137 138
138 if (SUCCEEDED(pEl->get_style(&pStyle)) && pStyle) 139 if (SUCCEEDED(pEl->get_style(&pStyle)) && pStyle)
139 { 140 {
140 CComBSTR bstrDisplay; 141 CComBSTR bstrDisplay;
141 if (SUCCEEDED(pStyle->get_display(&bstrDisplay)) && bstrDisplay && ToWstring (bstrDisplay) == L"none") 142 if (SUCCEEDED(pStyle->get_display(&bstrDisplay)) && ToWstring(bstrDisplay) = = L"none")
142 { 143 {
143 return; 144 return;
144 } 145 }
145
146 static const CComBSTR sbstrNone(L"none"); 146 static const CComBSTR sbstrNone(L"none");
147
148 if (SUCCEEDED(pStyle->put_display(sbstrNone))) 147 if (SUCCEEDED(pStyle->put_display(sbstrNone)))
149 { 148 {
150 DEBUG_HIDE_EL(ToWstring(indent) + L"HideEl::Hiding " + ToWstring(type) + L " url:" + url) 149 DEBUG_HIDE_EL(ToWstring(indent) + L"HideEl::Hiding " + ToWstring(type) + L " url:" + url)
151
152 #ifdef ENABLE_DEBUG_RESULT 150 #ifdef ENABLE_DEBUG_RESULT
153 if (isDebug) 151 if (isDebug)
154 { 152 {
155 CPluginDebug::DebugResultHiding(type, url, L"-"); 153 CPluginDebug::DebugResultHiding(type, url, L"-");
156 } 154 }
157 #endif // ENABLE_DEBUG_RESULT 155 #endif // ENABLE_DEBUG_RESULT
158 } 156 }
159 } 157 }
160 } 158 }
OLDNEW
« no previous file with comments | « no previous file | src/plugin/PluginClass.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld