OLD | NEW |
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-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 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 |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
16 */ | 16 */ |
17 | 17 |
18 #include "PluginStdAfx.h" | 18 #include "PluginStdAfx.h" |
19 #include "AdblockPlusDomTraverser.h" | 19 #include "AdblockPlusDomTraverser.h" |
20 #include "AdblockPlusClient.h" | 20 #include "AdblockPlusClient.h" |
21 #include "PluginFilter.h" | 21 #include "PluginFilter.h" |
22 #include "PluginSettings.h" | 22 #include "PluginSettings.h" |
23 #include "..\shared\Utils.h" | 23 #include "..\shared\Utils.h" |
24 | 24 |
25 | 25 |
26 CPluginDomTraverser::CPluginDomTraverser(CPluginTab* tab) : CPluginDomTraverserB
ase(tab) | 26 CPluginDomTraverser::CPluginDomTraverser(CPluginFilter* filterSet) : CPluginDomT
raverserBase(filterSet) |
27 { | 27 { |
28 } | 28 } |
29 | 29 |
30 | 30 |
31 bool CPluginDomTraverser::OnIFrame(IHTMLElement* pEl, const std::wstring& url, c
onst std::wstring& indent) | 31 bool CPluginDomTraverser::OnIFrame(IHTMLElement* pEl, const std::wstring& url, c
onst std::wstring& indent) |
32 { | 32 { |
33 CPluginClient* client = CPluginClient::GetInstance(); | 33 CPluginClient* client = CPluginClient::GetInstance(); |
34 | 34 |
35 // If src should be blocked, set style display:none on iframe | 35 // If src should be blocked, set style display:none on iframe |
36 bool isBlocked = client->ShouldBlock(url, | 36 bool isBlocked = client->ShouldBlock(url, |
37 AdblockPlus::FilterEngine::ContentType::CONTENT_TYPE_SUBDOCUMENT, m_document
Url); | 37 AdblockPlus::FilterEngine::ContentType::CONTENT_TYPE_SUBDOCUMENT, m_document
Url); |
38 if (isBlocked) | 38 if (isBlocked) |
39 { | 39 { |
40 HideElement(pEl, L"iframe", url, true, indent); | 40 HideElement(pEl, L"iframe", url, true, indent); |
41 } | 41 } |
42 | 42 |
43 return !isBlocked; | 43 return !isBlocked; |
44 } | 44 } |
45 | 45 |
46 | 46 |
47 bool CPluginDomTraverser::OnElement(IHTMLElement* pEl, const std::wstring& tag,
CPluginDomTraverserCache* cache, bool isDebug, const std::wstring& indent) | 47 bool CPluginDomTraverser::OnElement(IHTMLElement* pEl, const std::wstring& tag,
CPluginDomTraverserCache* cache, bool isDebug, const std::wstring& indent) |
48 { | 48 { |
49 if (cache->m_isHidden) | 49 if (cache->m_isHidden) |
50 { | 50 { |
51 return false; | 51 return false; |
52 } | 52 } |
53 | 53 |
54 // Check if element is hidden | 54 // Check if element is hidden |
55 CPluginClient* client = CPluginClient::GetInstance(); | 55 cache->m_isHidden = filterSet->IsElementHidden(tag, pEl, m_domain, indent); |
56 | |
57 cache->m_isHidden = client->IsElementHidden(tag, pEl, m_domain, indent, &(m_ta
b->m_filter)); | |
58 if (cache->m_isHidden) | 56 if (cache->m_isHidden) |
59 { | 57 { |
60 HideElement(pEl, tag, L"", false, indent); | 58 HideElement(pEl, tag, L"", false, indent); |
61 return false; | 59 return false; |
62 } | 60 } |
63 | 61 |
64 // Images | 62 // Images |
65 if (tag == L"img") | 63 if (tag == L"img") |
66 { | 64 { |
67 CComVariant vAttr; | 65 CComVariant vAttr; |
68 if (SUCCEEDED(pEl->getAttribute(ATL::CComBSTR(L"src"), 0, &vAttr)) && vAttr.
vt == VT_BSTR) | 66 if (SUCCEEDED(pEl->getAttribute(ATL::CComBSTR(L"src"), 0, &vAttr)) && vAttr.
vt == VT_BSTR) |
69 { | 67 { |
70 std::wstring src = ToWstring(vAttr.bstrVal); | 68 std::wstring src = ToWstring(vAttr.bstrVal); |
71 if (!src.empty()) | 69 if (!src.empty()) |
72 { | 70 { |
73 // If src should be blocked, set style display:none on image | 71 // If src should be blocked, set style display:none on image |
| 72 CPluginClient* client = CPluginClient::GetInstance(); |
74 cache->m_isHidden = client->ShouldBlock(src, | 73 cache->m_isHidden = client->ShouldBlock(src, |
75 AdblockPlus::FilterEngine::ContentType::CONTENT_TYPE_IMAGE, m_document
Url); | 74 AdblockPlus::FilterEngine::ContentType::CONTENT_TYPE_IMAGE, m_document
Url); |
76 if (cache->m_isHidden) | 75 if (cache->m_isHidden) |
77 { | 76 { |
78 HideElement(pEl, L"image", src, true, indent); | 77 HideElement(pEl, L"image", src, true, indent); |
79 return false; | 78 return false; |
80 } | 79 } |
81 } | 80 } |
82 } | 81 } |
83 } | 82 } |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 DEBUG_HIDE_EL(ToWstring(indent) + L"HideEl::Hiding " + ToWstring(type) + L
" url:" + url) | 148 DEBUG_HIDE_EL(ToWstring(indent) + L"HideEl::Hiding " + ToWstring(type) + L
" url:" + url) |
150 #ifdef ENABLE_DEBUG_RESULT | 149 #ifdef ENABLE_DEBUG_RESULT |
151 if (isDebug) | 150 if (isDebug) |
152 { | 151 { |
153 CPluginDebug::DebugResultHiding(type, url, L"-"); | 152 CPluginDebug::DebugResultHiding(type, url, L"-"); |
154 } | 153 } |
155 #endif // ENABLE_DEBUG_RESULT | 154 #endif // ENABLE_DEBUG_RESULT |
156 } | 155 } |
157 } | 156 } |
158 } | 157 } |
OLD | NEW |