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

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

Issue 5750789393874944: [IE] First round of ATL removal (Closed)
Patch Set: Created June 20, 2014, 9:22 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
OLDNEW
1 #include "PluginStdAfx.h" 1 #include "PluginStdAfx.h"
2 2
3 #include "PluginClient.h" 3 #include "PluginClient.h"
4 #include "PluginFilter.h" 4 #include "PluginFilter.h"
5 #include "PluginSettings.h" 5 #include "PluginSettings.h"
6 6
7 #include "AdblockPlusDomTraverser.h" 7 #include "AdblockPlusDomTraverser.h"
8 #include "PluginUtil.h"
8 9
9 10
10 CPluginDomTraverser::CPluginDomTraverser(CPluginTab* tab) : CPluginDomTraverserB ase(tab) 11 CPluginDomTraverser::CPluginDomTraverser(CPluginTab* tab) : CPluginDomTraverserB ase(tab)
11 { 12 {
12 } 13 }
13 14
14 15
15 bool CPluginDomTraverser::OnIFrame(IHTMLElement* pEl, const CString& url, CStrin g& indent) 16 bool CPluginDomTraverser::OnIFrame(IHTMLElement* pEl, const std::wstring & url, std::wstring & indent)
16 { 17 {
17 CPluginClient* client = CPluginClient::GetInstance(); 18 CPluginClient* client = CPluginClient::GetInstance();
18 19
19 // If src should be blocked, set style display:none on iframe 20 // If src should be blocked, set style display:none on iframe
20 bool isBlocked = client->ShouldBlock(url, CFilter::contentTypeSubdocument, m_d omain); 21 bool isBlocked = client->ShouldBlock(url, CFilter::contentTypeSubdocument, m_d omain);
21 if (isBlocked) 22 if (isBlocked)
22 { 23 {
23 HideElement(pEl, "iframe", url, true, indent); 24 HideElement(pEl, L"iframe", url, true, indent);
24 } 25 }
25 26
26 return !isBlocked; 27 return !isBlocked;
27 } 28 }
28 29
29 30
30 bool CPluginDomTraverser::OnElement(IHTMLElement* pEl, const CString& tag, CPlug inDomTraverserCache* cache, bool isDebug, CString& indent) 31 bool CPluginDomTraverser::OnElement(IHTMLElement* pEl, const std::wstring & tag, CPluginDomTraverserCache* cache, bool isDebug, std::wstring & indent)
31 { 32 {
32 if (cache->m_isHidden) 33 if (cache->m_isHidden)
33 { 34 {
34 return false; 35 return false;
35 } 36 }
36 37
37 // Check if element is hidden 38 // Check if element is hidden
38 CPluginClient* client = CPluginClient::GetInstance(); 39 CPluginClient* client = CPluginClient::GetInstance();
39 40
40 cache->m_isHidden = client->IsElementHidden(tag, pEl, m_domain, indent, m_tab- >m_filter.get()); 41 cache->m_isHidden = client->IsElementHidden(tag, pEl, m_domain, indent, m_tab- >m_filter.get());
41 if (cache->m_isHidden) 42 if (cache->m_isHidden)
42 { 43 {
43 HideElement(pEl, tag, "", false, indent); 44 HideElement(pEl, tag, L"", false, indent);
44 return false; 45 return false;
45 } 46 }
46 47
47 // Images 48 // Images
48 if (tag == "img") 49 if (tag == L"img")
49 { 50 {
50 CComVariant vAttr; 51 Wrapper::HTML_Element element( pEl );
51 52 std::wstring src;
52 if (SUCCEEDED(pEl->getAttribute(L"src", 0, &vAttr)) && vAttr.vt == VT_BSTR & & ::SysStringLen(vAttr.bstrVal) > 0) 53 if ( element.attribute( L"src", src ) && !src.empty() )
53 { 54 {
54 CString src = vAttr.bstrVal; 55 Wrapper::Unescape_URL( src );
55 CPluginClient::UnescapeUrl(src);
56 56
57 // If src should be blocked, set style display:none on image 57 // If src should be blocked, set style display:none on image
58 cache->m_isHidden = client->ShouldBlock(src, CFilter::contentTypeImage, m_ domain); 58 cache->m_isHidden = client->ShouldBlock(src, CFilter::contentTypeImage, m_ domain);
59 if (cache->m_isHidden) 59 if (cache->m_isHidden)
60 { 60 {
61 HideElement(pEl, "image", src, true, indent); 61 HideElement(pEl, L"image", src, true, indent);
62 return false; 62 return false;
63 } 63 }
64 } 64 }
65 } 65 }
66 // Objects 66 // Objects
67 else if (tag == "object") 67 else if (tag == L"object")
68 { 68 {
69 CComBSTR bstrInnerHtml; 69 Wrapper::HTML_Element element( pEl );
70 std::wstring object_html;
71 element.inner_HTML( object_html );
72 if ( element.inner_HTML( object_html ) && !object_html.empty() )
73 {
74 std::wstring src;
70 75
71 if (SUCCEEDED(pEl->get_innerHTML(&bstrInnerHtml)) && bstrInnerHtml) 76 int posBegin = object_html.find( L"VALUE=\"" );
72 { 77 int posEnd = ( posBegin >= 0 ) ? object_html.find( L'\"', posBegin + 7 ) : -1;
73 CString sObjectHtml = bstrInnerHtml;
74 CString src;
75
76 int posBegin = sObjectHtml.Find(L"VALUE=\"");
77 int posEnd = posBegin >= 0 ? sObjectHtml.Find('\"', posBegin + 7) : -1;
78 78
79 while (posBegin >= 0 && posEnd >= 0) 79 while (posBegin >= 0 && posEnd >= 0)
80 { 80 {
81 posBegin += 7; 81 posBegin += 7;
82 82
83 src = sObjectHtml.Mid(posBegin, posEnd - posBegin); 83 src = object_html.substr( posBegin, posEnd - posBegin );
84 84
85 // eg. http://w3schools.com/html/html_examples.asp 85 // eg. http://w3schools.com/html/html_examples.asp
86 if (src.Left(2) == "//") 86 if ( ABP::util::begins_with( src, L"//" ) )
87 { 87 {
88 src = "http:" + src; 88 src = L"http:" + src;
89 } 89 }
90 90
91 if (!src.IsEmpty()) 91 if ( !src.empty() )
92 { 92 {
93 // cache->m_isHidden = client->ShouldBlock( src, CFilter::contentTypeObject, m_domain); 93 // cache->m_isHidden = client->ShouldBlock( src, CFilter::contentTypeObject, m_domain);
94 if (cache->m_isHidden) 94 if (cache->m_isHidden)
95 { 95 {
96 HideElement(pEl, "object", src, true, indent); 96 HideElement(pEl, L"object", src, true, indent);
97 return false; 97 return false;
98 } 98 }
99 } 99 }
100 100
101 posBegin = sObjectHtml.Find(L"VALUE=\"", posBegin); 101 posBegin = object_html.find( L"VALUE=\"", posBegin );
102 posEnd = posBegin >= 0 ? sObjectHtml.Find(L"\"", posBegin + 7) : -1; 102 posEnd = ( posBegin >= 0 ) ? object_html.find( L'\"', posBegin + 7 ) : - 1;
103 } 103 }
104 } 104 }
105 } 105 }
106 106
107 return true; 107 return true;
108 } 108 }
109 109
110 110
111 bool CPluginDomTraverser::IsEnabled() 111 bool CPluginDomTraverser::IsEnabled()
112 { 112 {
113 CPluginClient* client = CPluginClient::GetInstance(); 113 CPluginClient* client = CPluginClient::GetInstance();
114 114
115 return client && CPluginSettings::GetInstance()->IsPluginEnabled() && !client- >IsWhitelistedUrl(std::wstring(m_domain)); 115 return client && CPluginSettings::GetInstance()->IsPluginEnabled() && !client- >IsWhitelistedUrl(std::wstring(m_domain));
116 } 116 }
117 117
118 118
119 void CPluginDomTraverser::HideElement(IHTMLElement* pEl, const CString& type, co nst CString& url, bool isDebug, CString& indent) 119 void CPluginDomTraverser::HideElement(IHTMLElement* pEl, const std::wstring & ty pe, const std::wstring & url, bool isDebug, std::wstring & indent)
120 { 120 {
121 CComPtr<IHTMLStyle> pStyle; 121 CComPtr<IHTMLStyle> pStyle;
122 122
123 if (SUCCEEDED(pEl->get_style(&pStyle)) && pStyle) 123 if (SUCCEEDED(pEl->get_style(&pStyle)) && pStyle)
124 { 124 {
125 CComBSTR bstrDisplay; 125 std::wstring display;
126 126 Wrapper::HTML_Style style( pStyle );
127 if (SUCCEEDED(pStyle->get_display(&bstrDisplay)) && bstrDisplay && CString(b strDisplay) == L"none") 127 if ( style.display( display ) && display == L"none" )
128 { 128 {
129 return; 129 return;
130 } 130 }
131 131
132 static const CComBSTR sbstrNone(L"none"); 132 if ( style.assign_display( L"none" ) )
133
134 if (SUCCEEDED(pStyle->put_display(sbstrNone)))
135 { 133 {
136 DEBUG_HIDE_EL(indent + L"HideEl::Hiding " + type + L" url:" + url) 134 DEBUG_HIDE_EL(indent + L"HideEl::Hiding " + type + L" url:" + url)
137 135
138 #ifdef ENABLE_DEBUG_RESULT 136 #ifdef ENABLE_DEBUG_RESULT
139 if (isDebug) 137 if (isDebug)
140 { 138 {
141 CPluginDebug::DebugResultHiding(type, url, "-"); 139 CPluginDebug::DebugResultHiding(type, url, L"-");
142 } 140 }
143 #endif // ENABLE_DEBUG_RESULT 141 #endif // ENABLE_DEBUG_RESULT
144 } 142 }
145 } 143 }
146 } 144 }
OLDNEW

Powered by Google App Engine
This is Rietveld