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

Delta Between Two Patch Sets: src/plugin/AdblockPlusDomTraverser.cpp

Issue 5698769010032640: Issue #1466 - fix usage of BSTR (Closed)
Left Patch Set: Created Oct. 8, 2014, 2:48 p.m.
Right Patch Set: rebased Created Jan. 29, 2015, 5:10 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | src/plugin/PluginDomTraverserBase.h » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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), CFilter::contentTypeSubd ocument, m_domain); 37 bool isBlocked = client->ShouldBlock(url, CFilter::contentTypeSubdocument, m_d omain);
21 if (isBlocked) 38 if (isBlocked)
22 { 39 {
23 HideElement(pEl, "iframe", url, true, indent); 40 HideElement(pEl, "iframe", url, true, indent);
24 } 41 }
25 42
26 return !isBlocked; 43 return !isBlocked;
27 } 44 }
28 45
29 46
30 bool CPluginDomTraverser::OnElement(IHTMLElement* pEl, const CString& tag, CPlug inDomTraverserCache* cache, bool isDebug, CString& indent) 47 bool CPluginDomTraverser::OnElement(IHTMLElement* pEl, const CString& tag, CPlug inDomTraverserCache* cache, bool isDebug, CString& indent)
31 { 48 {
32 if (cache->m_isHidden) 49 if (cache->m_isHidden)
33 { 50 {
34 return false; 51 return false;
35 } 52 }
36 53
37 // Check if element is hidden 54 // Check if element is hidden
38 CPluginClient* client = CPluginClient::GetInstance(); 55 CPluginClient* client = CPluginClient::GetInstance();
39 56
40 cache->m_isHidden = client->IsElementHidden(to_wstring(tag), pEl, m_domain, to _wstring(indent), m_tab->m_filter.get()); 57 cache->m_isHidden = client->IsElementHidden(ToWstring(tag), pEl, m_domain, ToW string(indent), m_tab->m_filter.get());
41 if (cache->m_isHidden) 58 if (cache->m_isHidden)
42 { 59 {
43 HideElement(pEl, tag, "", false, indent); 60 HideElement(pEl, tag, L"", false, indent);
44 return false; 61 return false;
45 } 62 }
46 63
47 // Images 64 // Images
48 if (tag == "img") 65 if (tag == "img")
49 { 66 {
50 CComVariant vAttr; 67 CComVariant vAttr;
51 68
52 if (SUCCEEDED(pEl->getAttribute(ATL::CComBSTR(L"src"), 0, &vAttr)) && vAttr. vt == VT_BSTR && ::SysStringLen(vAttr.bstrVal) > 0) 69 if (SUCCEEDED(pEl->getAttribute(ATL::CComBSTR(L"src"), 0, &vAttr)) && vAttr. vt == VT_BSTR && ::SysStringLen(vAttr.bstrVal) > 0)
Eric 2014/10/09 13:54:01 As I said in the previous review, I object to usin
sergei 2014/10/16 08:53:25 - I would say that speaking about maintainability
Oleksandr 2014/10/17 07:38:02 - I agree that using ATL's class is better then ou
Eric 2014/10/20 04:06:24 The main way that the code becomes cleaner by usin
Eric 2014/10/20 04:06:24 What we decided was that there was little rush to
Eric 2014/10/20 04:06:24 From what I can tell, I don't think you spent any
Eric 2014/10/20 04:06:24 It is possible to define a class for the kind of e
Oleksandr 2014/10/21 23:53:19 I really don't think we should be having prolonged
53 { 70 {
54 CString src = vAttr.bstrVal; 71 std::wstring src(vAttr.bstrVal, SysStringLen(vAttr.bstrVal));
55 CPluginClient::UnescapeUrl(src); 72 UnescapeUrl(src);
56 73
57 // If src should be blocked, set style display:none on image 74 // If src should be blocked, set style display:none on image
58 cache->m_isHidden = client->ShouldBlock(to_wstring(src), CFilter::contentT ypeImage, m_domain); 75 cache->m_isHidden = client->ShouldBlock(src, CFilter::contentTypeImage, m_ domain);
59 if (cache->m_isHidden) 76 if (cache->m_isHidden)
60 { 77 {
61 HideElement(pEl, "image", src, true, indent); 78 HideElement(pEl, "image", src, true, indent);
62 return false; 79 return false;
63 } 80 }
64 } 81 }
65 } 82 }
66 // Objects 83 // Objects
67 else if (tag == "object") 84 else if (tag == "object")
68 { 85 {
(...skipping 16 matching lines...) Expand all
85 // eg. http://w3schools.com/html/html_examples.asp 102 // eg. http://w3schools.com/html/html_examples.asp
86 if (src.Left(2) == "//") 103 if (src.Left(2) == "//")
87 { 104 {
88 src = "http:" + src; 105 src = "http:" + src;
89 } 106 }
90 107
91 if (!src.IsEmpty()) 108 if (!src.IsEmpty())
92 { 109 {
93 if (cache->m_isHidden) 110 if (cache->m_isHidden)
94 { 111 {
95 HideElement(pEl, "object", src, true, indent); 112 HideElement(pEl, "object", ToWstring(src), true, indent);
96 return false; 113 return false;
97 } 114 }
98 } 115 }
99 116
100 posBegin = sObjectHtml.Find(L"VALUE=\"", posBegin); 117 posBegin = sObjectHtml.Find(L"VALUE=\"", posBegin);
101 posEnd = posBegin >= 0 ? sObjectHtml.Find(L"\"", posBegin + 7) : -1; 118 posEnd = posBegin >= 0 ? sObjectHtml.Find(L"\"", posBegin + 7) : -1;
102 } 119 }
103 } 120 }
104 } 121 }
105 122
106 return true; 123 return true;
107 } 124 }
108 125
109 126
110 bool CPluginDomTraverser::IsEnabled() 127 bool CPluginDomTraverser::IsEnabled()
111 { 128 {
112 CPluginClient* client = CPluginClient::GetInstance(); 129 CPluginClient* client = CPluginClient::GetInstance();
113
114 return client && CPluginSettings::GetInstance()->IsPluginEnabled() && !client- >IsWhitelistedUrl(m_domain); 130 return client && CPluginSettings::GetInstance()->IsPluginEnabled() && !client- >IsWhitelistedUrl(m_domain);
115 } 131 }
116 132
117 133
118 void CPluginDomTraverser::HideElement(IHTMLElement* pEl, const CString& type, co nst CString& url, bool isDebug, CString& indent) 134 void CPluginDomTraverser::HideElement(IHTMLElement* pEl, const CString& type, co nst std::wstring& url, bool isDebug, CString& indent)
119 { 135 {
120 CComPtr<IHTMLStyle> pStyle; 136 CComPtr<IHTMLStyle> pStyle;
121 137
122 if (SUCCEEDED(pEl->get_style(&pStyle)) && pStyle) 138 if (SUCCEEDED(pEl->get_style(&pStyle)) && pStyle)
123 { 139 {
124 CComBSTR bstrDisplay; 140 CComBSTR bstrDisplay;
125 141
126 if (SUCCEEDED(pStyle->get_display(&bstrDisplay)) && bstrDisplay && CString(b strDisplay) == L"none") 142 if (SUCCEEDED(pStyle->get_display(&bstrDisplay)) && bstrDisplay && CString(b strDisplay) == L"none")
127 { 143 {
128 return; 144 return;
129 } 145 }
130 146
131 static const CComBSTR sbstrNone(L"none"); 147 static const CComBSTR sbstrNone(L"none");
132 148
133 if (SUCCEEDED(pStyle->put_display(sbstrNone))) 149 if (SUCCEEDED(pStyle->put_display(sbstrNone)))
134 { 150 {
135 DEBUG_HIDE_EL(indent + L"HideEl::Hiding " + type + L" url:" + url) 151 DEBUG_HIDE_EL(indent + L"HideEl::Hiding " + type + L" url:" + ToCString(ur l))
136 152
137 #ifdef ENABLE_DEBUG_RESULT 153 #ifdef ENABLE_DEBUG_RESULT
138 if (isDebug) 154 if (isDebug)
139 { 155 {
140 CPluginDebug::DebugResultHiding(type, url, "-"); 156 CPluginDebug::DebugResultHiding(type, ToCString(url), "-");
141 } 157 }
142 #endif // ENABLE_DEBUG_RESULT 158 #endif // ENABLE_DEBUG_RESULT
143 } 159 }
144 } 160 }
145 } 161 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld