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

Unified Diff: src/plugin/AdblockPlusDomTraverser.cpp

Issue 5316782940225536: Issue 1557 - Update to the recent libadblockplus to reduce additional updates in the logic later. (Closed)
Patch Set: fix according to the comments Created Jan. 28, 2015, 1:22 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 | « src/plugin/AdblockPlusClient.cpp ('k') | src/plugin/PluginFilter.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/plugin/AdblockPlusDomTraverser.cpp
diff --git a/src/plugin/AdblockPlusDomTraverser.cpp b/src/plugin/AdblockPlusDomTraverser.cpp
index 296a209942052e479083599c7c8007684132d0f9..e1e495b28a9b76a739bc950e9b6de6e1f04eb06b 100644
--- a/src/plugin/AdblockPlusDomTraverser.cpp
+++ b/src/plugin/AdblockPlusDomTraverser.cpp
@@ -15,147 +15,149 @@
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "PluginStdAfx.h"
-
-#include "PluginClient.h"
-#include "PluginFilter.h"
-#include "PluginSettings.h"
-
-#include "AdblockPlusDomTraverser.h"
-
-
-CPluginDomTraverser::CPluginDomTraverser(CPluginTab* tab) : CPluginDomTraverserBase(tab)
-{
-}
-
-
-bool CPluginDomTraverser::OnIFrame(IHTMLElement* pEl, const std::wstring& url, CString& indent)
-{
- CPluginClient* client = CPluginClient::GetInstance();
-
- // If src should be blocked, set style display:none on iframe
- bool isBlocked = client->ShouldBlock(url, CFilter::contentTypeSubdocument, m_domain);
- if (isBlocked)
- {
- HideElement(pEl, "iframe", url, true, indent);
- }
-
- return !isBlocked;
-}
-
-
-bool CPluginDomTraverser::OnElement(IHTMLElement* pEl, const CString& tag, CPluginDomTraverserCache* cache, bool isDebug, CString& indent)
-{
- if (cache->m_isHidden)
- {
- return false;
- }
-
- // Check if element is hidden
- CPluginClient* client = CPluginClient::GetInstance();
-
- cache->m_isHidden = client->IsElementHidden(ToWstring(tag), pEl, m_domain, ToWstring(indent), m_tab->m_filter.get());
- if (cache->m_isHidden)
- {
- HideElement(pEl, tag, L"", false, indent);
- return false;
- }
-
- // Images
- if (tag == "img")
- {
- CComVariant vAttr;
-
- if (SUCCEEDED(pEl->getAttribute(L"src", 0, &vAttr)) && vAttr.vt == VT_BSTR && ::SysStringLen(vAttr.bstrVal) > 0)
- {
- std::wstring src(vAttr.bstrVal, SysStringLen(vAttr.bstrVal));
- UnescapeUrl(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);
- return false;
- }
- }
- }
- // Objects
- else if (tag == "object")
- {
- CComBSTR bstrInnerHtml;
-
- 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;
-
- while (posBegin >= 0 && posEnd >= 0)
- {
- posBegin += 7;
-
- src = sObjectHtml.Mid(posBegin, posEnd - posBegin);
-
- // eg. http://w3schools.com/html/html_examples.asp
- if (src.Left(2) == "//")
- {
- src = "http:" + src;
- }
-
- if (!src.IsEmpty())
- {
- if (cache->m_isHidden)
- {
- HideElement(pEl, "object", ToWstring(src), true, indent);
- return false;
- }
- }
-
- posBegin = sObjectHtml.Find(L"VALUE=\"", posBegin);
- posEnd = posBegin >= 0 ? sObjectHtml.Find(L"\"", posBegin + 7) : -1;
- }
- }
- }
-
- return true;
-}
-
-
-bool CPluginDomTraverser::IsEnabled()
-{
- CPluginClient* client = CPluginClient::GetInstance();
- return client && CPluginSettings::GetInstance()->IsPluginEnabled() && !client->IsWhitelistedUrl(m_domain);
-}
-
-
-void CPluginDomTraverser::HideElement(IHTMLElement* pEl, const CString& type, const std::wstring& url, bool isDebug, CString& indent)
-{
- CComPtr<IHTMLStyle> pStyle;
-
- if (SUCCEEDED(pEl->get_style(&pStyle)) && pStyle)
- {
- CComBSTR bstrDisplay;
-
- if (SUCCEEDED(pStyle->get_display(&bstrDisplay)) && bstrDisplay && CString(bstrDisplay) == L"none")
- {
- return;
- }
-
- static const CComBSTR sbstrNone(L"none");
-
- if (SUCCEEDED(pStyle->put_display(sbstrNone)))
- {
- DEBUG_HIDE_EL(indent + L"HideEl::Hiding " + type + L" url:" + ToCString(url))
-
-#ifdef ENABLE_DEBUG_RESULT
- if (isDebug)
- {
- CPluginDebug::DebugResultHiding(type, ToCString(url), "-");
- }
-#endif // ENABLE_DEBUG_RESULT
- }
- }
-}
+#include "PluginStdAfx.h"
+
+#include "PluginClient.h"
+#include "PluginFilter.h"
+#include "PluginSettings.h"
+
+#include "AdblockPlusDomTraverser.h"
+
+
+CPluginDomTraverser::CPluginDomTraverser(CPluginTab* tab) : CPluginDomTraverserBase(tab)
+{
+}
+
+
+bool CPluginDomTraverser::OnIFrame(IHTMLElement* pEl, const std::wstring& url, CString& indent)
+{
+ CPluginClient* client = CPluginClient::GetInstance();
+
+ // If src should be blocked, set style display:none on iframe
+ bool isBlocked = client->ShouldBlock(url,
+ AdblockPlus::FilterEngine::ContentType::CONTENT_TYPE_SUBDOCUMENT, m_domain);
+ if (isBlocked)
+ {
+ HideElement(pEl, "iframe", url, true, indent);
+ }
+
+ return !isBlocked;
+}
+
+
+bool CPluginDomTraverser::OnElement(IHTMLElement* pEl, const CString& tag, CPluginDomTraverserCache* cache, bool isDebug, CString& indent)
+{
+ if (cache->m_isHidden)
+ {
+ return false;
+ }
+
+ // Check if element is hidden
+ CPluginClient* client = CPluginClient::GetInstance();
+
+ cache->m_isHidden = client->IsElementHidden(ToWstring(tag), pEl, m_domain, ToWstring(indent), m_tab->m_filter.get());
+ if (cache->m_isHidden)
+ {
+ HideElement(pEl, tag, L"", false, indent);
+ return false;
+ }
+
+ // Images
+ if (tag == "img")
+ {
+ CComVariant vAttr;
+
+ if (SUCCEEDED(pEl->getAttribute(L"src", 0, &vAttr)) && vAttr.vt == VT_BSTR && ::SysStringLen(vAttr.bstrVal) > 0)
+ {
+ std::wstring src(vAttr.bstrVal, SysStringLen(vAttr.bstrVal));
+ UnescapeUrl(src);
+
+ // If src should be blocked, set style display:none on image
+ cache->m_isHidden = client->ShouldBlock(src,
+ AdblockPlus::FilterEngine::ContentType::CONTENT_TYPE_IMAGE, m_domain);
+ if (cache->m_isHidden)
+ {
+ HideElement(pEl, "image", src, true, indent);
+ return false;
+ }
+ }
+ }
+ // Objects
+ else if (tag == "object")
+ {
+ CComBSTR bstrInnerHtml;
+
+ 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;
+
+ while (posBegin >= 0 && posEnd >= 0)
+ {
+ posBegin += 7;
+
+ src = sObjectHtml.Mid(posBegin, posEnd - posBegin);
+
+ // eg. http://w3schools.com/html/html_examples.asp
+ if (src.Left(2) == "//")
+ {
+ src = "http:" + src;
+ }
+
+ if (!src.IsEmpty())
+ {
+ if (cache->m_isHidden)
+ {
+ HideElement(pEl, "object", ToWstring(src), true, indent);
+ return false;
+ }
+ }
+
+ posBegin = sObjectHtml.Find(L"VALUE=\"", posBegin);
+ posEnd = posBegin >= 0 ? sObjectHtml.Find(L"\"", posBegin + 7) : -1;
+ }
+ }
+ }
+
+ return true;
+}
+
+
+bool CPluginDomTraverser::IsEnabled()
+{
+ CPluginClient* client = CPluginClient::GetInstance();
+ return client && CPluginSettings::GetInstance()->IsPluginEnabled() && !client->IsWhitelistedUrl(m_domain);
+}
+
+
+void CPluginDomTraverser::HideElement(IHTMLElement* pEl, const CString& type, const std::wstring& url, bool isDebug, CString& indent)
+{
+ CComPtr<IHTMLStyle> pStyle;
+
+ if (SUCCEEDED(pEl->get_style(&pStyle)) && pStyle)
+ {
+ CComBSTR bstrDisplay;
+
+ if (SUCCEEDED(pStyle->get_display(&bstrDisplay)) && bstrDisplay && CString(bstrDisplay) == L"none")
+ {
+ return;
+ }
+
+ static const CComBSTR sbstrNone(L"none");
+
+ if (SUCCEEDED(pStyle->put_display(sbstrNone)))
+ {
+ DEBUG_HIDE_EL(indent + L"HideEl::Hiding " + type + L" url:" + ToCString(url))
+
+#ifdef ENABLE_DEBUG_RESULT
+ if (isDebug)
+ {
+ CPluginDebug::DebugResultHiding(type, ToCString(url), "-");
+ }
+#endif // ENABLE_DEBUG_RESULT
+ }
+ }
+}
« no previous file with comments | « src/plugin/AdblockPlusClient.cpp ('k') | src/plugin/PluginFilter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld