Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 /* | |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | |
3 * Copyright (C) 2006-2015 Eyeo GmbH | |
4 * | |
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 | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * Adblock Plus is distributed in the hope that it will be useful, | |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 * GNU General Public License for more details. | |
13 * | |
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/>. | |
16 */ | |
17 | |
1 #include "PluginStdAfx.h" | 18 #include "PluginStdAfx.h" |
2 | 19 |
3 #include "PluginClient.h" | 20 #include "PluginClient.h" |
4 #include "PluginFilter.h" | 21 #include "PluginFilter.h" |
5 #include "PluginSettings.h" | 22 #include "PluginSettings.h" |
6 | 23 |
7 #include "AdblockPlusDomTraverser.h" | 24 #include "AdblockPlusDomTraverser.h" |
8 | 25 |
9 | 26 |
10 CPluginDomTraverser::CPluginDomTraverser(CPluginTab* tab) : CPluginDomTraverserB ase(tab) | 27 CPluginDomTraverser::CPluginDomTraverser(CPluginTab* tab) : CPluginDomTraverserB ase(tab) |
11 { | 28 { |
12 } | 29 } |
13 | 30 |
14 | 31 |
15 bool CPluginDomTraverser::OnIFrame(IHTMLElement* pEl, const CString& url, CStrin g& indent) | 32 bool CPluginDomTraverser::OnIFrame(IHTMLElement* pEl, const std::wstring& url, C String& indent) |
16 { | 33 { |
17 CPluginClient* client = CPluginClient::GetInstance(); | 34 CPluginClient* client = CPluginClient::GetInstance(); |
18 | 35 |
19 // If src should be blocked, set style display:none on iframe | 36 // If src should be blocked, set style display:none on iframe |
20 bool isBlocked = client->ShouldBlock(to_wstring(url), | 37 bool isBlocked = client->ShouldBlock(url, |
Eric
2014/12/30 16:56:08
ToWstring
| |
21 AdblockPlus::FilterEngine::ContentType::CONTENT_TYPE_SUBDOCUMENT, m_domain); | 38 AdblockPlus::FilterEngine::ContentType::CONTENT_TYPE_SUBDOCUMENT, m_domain); |
22 if (isBlocked) | 39 if (isBlocked) |
23 { | 40 { |
24 HideElement(pEl, "iframe", url, true, indent); | 41 HideElement(pEl, "iframe", url, true, indent); |
25 } | 42 } |
26 | 43 |
27 return !isBlocked; | 44 return !isBlocked; |
28 } | 45 } |
29 | 46 |
30 | 47 |
31 bool CPluginDomTraverser::OnElement(IHTMLElement* pEl, const CString& tag, CPlug inDomTraverserCache* cache, bool isDebug, CString& indent) | 48 bool CPluginDomTraverser::OnElement(IHTMLElement* pEl, const CString& tag, CPlug inDomTraverserCache* cache, bool isDebug, CString& indent) |
32 { | 49 { |
33 if (cache->m_isHidden) | 50 if (cache->m_isHidden) |
34 { | 51 { |
35 return false; | 52 return false; |
36 } | 53 } |
37 | 54 |
38 // Check if element is hidden | 55 // Check if element is hidden |
39 CPluginClient* client = CPluginClient::GetInstance(); | 56 CPluginClient* client = CPluginClient::GetInstance(); |
40 | 57 |
41 cache->m_isHidden = client->IsElementHidden(to_wstring(tag), pEl, m_domain, to _wstring(indent), m_tab->m_filter.get()); | 58 cache->m_isHidden = client->IsElementHidden(ToWstring(tag), pEl, m_domain, ToW string(indent), m_tab->m_filter.get()); |
42 if (cache->m_isHidden) | 59 if (cache->m_isHidden) |
43 { | 60 { |
44 HideElement(pEl, tag, "", false, indent); | 61 HideElement(pEl, tag, L"", false, indent); |
45 return false; | 62 return false; |
46 } | 63 } |
47 | 64 |
48 // Images | 65 // Images |
49 if (tag == "img") | 66 if (tag == "img") |
50 { | 67 { |
51 CComVariant vAttr; | 68 CComVariant vAttr; |
52 | 69 |
53 if (SUCCEEDED(pEl->getAttribute(L"src", 0, &vAttr)) && vAttr.vt == VT_BSTR & & ::SysStringLen(vAttr.bstrVal) > 0) | 70 if (SUCCEEDED(pEl->getAttribute(ATL::CComBSTR(L"src"), 0, &vAttr)) && vAttr. vt == VT_BSTR && ::SysStringLen(vAttr.bstrVal) > 0) |
54 { | 71 { |
55 CString src = vAttr.bstrVal; | 72 std::wstring src(vAttr.bstrVal, SysStringLen(vAttr.bstrVal)); |
56 CPluginClient::UnescapeUrl(src); | 73 UnescapeUrl(src); |
57 | 74 |
58 // If src should be blocked, set style display:none on image | 75 // If src should be blocked, set style display:none on image |
59 cache->m_isHidden = client->ShouldBlock(to_wstring(src), | 76 cache->m_isHidden = client->ShouldBlock(src, |
Eric
2014/12/30 16:56:08
ToWstring
| |
60 AdblockPlus::FilterEngine::ContentType::CONTENT_TYPE_IMAGE, m_domain); | 77 AdblockPlus::FilterEngine::ContentType::CONTENT_TYPE_IMAGE, m_domain); |
61 if (cache->m_isHidden) | 78 if (cache->m_isHidden) |
62 { | 79 { |
63 HideElement(pEl, "image", src, true, indent); | 80 HideElement(pEl, "image", src, true, indent); |
64 return false; | 81 return false; |
65 } | 82 } |
66 } | 83 } |
67 } | 84 } |
68 // Objects | 85 // Objects |
69 else if (tag == "object") | 86 else if (tag == "object") |
(...skipping 17 matching lines...) Expand all Loading... | |
87 // eg. http://w3schools.com/html/html_examples.asp | 104 // eg. http://w3schools.com/html/html_examples.asp |
88 if (src.Left(2) == "//") | 105 if (src.Left(2) == "//") |
89 { | 106 { |
90 src = "http:" + src; | 107 src = "http:" + src; |
91 } | 108 } |
92 | 109 |
93 if (!src.IsEmpty()) | 110 if (!src.IsEmpty()) |
94 { | 111 { |
95 if (cache->m_isHidden) | 112 if (cache->m_isHidden) |
96 { | 113 { |
97 HideElement(pEl, "object", src, true, indent); | 114 HideElement(pEl, "object", ToWstring(src), true, indent); |
98 return false; | 115 return false; |
99 } | 116 } |
100 } | 117 } |
101 | 118 |
102 posBegin = sObjectHtml.Find(L"VALUE=\"", posBegin); | 119 posBegin = sObjectHtml.Find(L"VALUE=\"", posBegin); |
103 posEnd = posBegin >= 0 ? sObjectHtml.Find(L"\"", posBegin + 7) : -1; | 120 posEnd = posBegin >= 0 ? sObjectHtml.Find(L"\"", posBegin + 7) : -1; |
104 } | 121 } |
105 } | 122 } |
106 } | 123 } |
107 | 124 |
108 return true; | 125 return true; |
109 } | 126 } |
110 | 127 |
111 | 128 |
112 bool CPluginDomTraverser::IsEnabled() | 129 bool CPluginDomTraverser::IsEnabled() |
113 { | 130 { |
114 CPluginClient* client = CPluginClient::GetInstance(); | 131 CPluginClient* client = CPluginClient::GetInstance(); |
115 return client && CPluginSettings::GetInstance()->IsPluginEnabled() && !client- >IsWhitelistedUrl(m_domain); | 132 return client && CPluginSettings::GetInstance()->IsPluginEnabled() && !client- >IsWhitelistedUrl(m_domain); |
116 } | 133 } |
117 | 134 |
118 | 135 |
119 void CPluginDomTraverser::HideElement(IHTMLElement* pEl, const CString& type, co nst CString& url, bool isDebug, CString& indent) | 136 void CPluginDomTraverser::HideElement(IHTMLElement* pEl, const CString& type, co nst std::wstring& url, bool isDebug, CString& indent) |
120 { | 137 { |
121 CComPtr<IHTMLStyle> pStyle; | 138 CComPtr<IHTMLStyle> pStyle; |
122 | 139 |
123 if (SUCCEEDED(pEl->get_style(&pStyle)) && pStyle) | 140 if (SUCCEEDED(pEl->get_style(&pStyle)) && pStyle) |
124 { | 141 { |
125 CComBSTR bstrDisplay; | 142 CComBSTR bstrDisplay; |
126 | 143 |
127 if (SUCCEEDED(pStyle->get_display(&bstrDisplay)) && bstrDisplay && CString(b strDisplay) == L"none") | 144 if (SUCCEEDED(pStyle->get_display(&bstrDisplay)) && bstrDisplay && CString(b strDisplay) == L"none") |
128 { | 145 { |
129 return; | 146 return; |
130 } | 147 } |
131 | 148 |
132 static const CComBSTR sbstrNone(L"none"); | 149 static const CComBSTR sbstrNone(L"none"); |
133 | 150 |
134 if (SUCCEEDED(pStyle->put_display(sbstrNone))) | 151 if (SUCCEEDED(pStyle->put_display(sbstrNone))) |
135 { | 152 { |
136 DEBUG_HIDE_EL(indent + L"HideEl::Hiding " + type + L" url:" + url) | 153 DEBUG_HIDE_EL(indent + L"HideEl::Hiding " + type + L" url:" + ToCString(ur l)) |
137 | 154 |
138 #ifdef ENABLE_DEBUG_RESULT | 155 #ifdef ENABLE_DEBUG_RESULT |
139 if (isDebug) | 156 if (isDebug) |
140 { | 157 { |
141 CPluginDebug::DebugResultHiding(type, url, "-"); | 158 CPluginDebug::DebugResultHiding(type, ToCString(url), "-"); |
142 } | 159 } |
143 #endif // ENABLE_DEBUG_RESULT | 160 #endif // ENABLE_DEBUG_RESULT |
144 } | 161 } |
145 } | 162 } |
146 } | 163 } |
LEFT | RIGHT |