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

Side by Side Diff: src/plugin/PluginDomTraverserBase.h

Issue 5698769010032640: Issue #1466 - fix usage of BSTR (Closed)
Patch Set: Created Oct. 8, 2014, 2:48 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 #ifndef _PLUGIN_DOM_TRAVERSER_BASE_H_ 1 #ifndef _PLUGIN_DOM_TRAVERSER_BASE_H_
2 #define _PLUGIN_DOM_TRAVERSER_BASE_H_ 2 #define _PLUGIN_DOM_TRAVERSER_BASE_H_
3 3
4 4
5 #include "PluginTypedef.h" 5 #include "PluginTypedef.h"
6 #include "PluginTab.h" 6 #include "PluginTab.h"
7 7
8 8
9 class CPluginDomTraverserCacheBase 9 class CPluginDomTraverserCacheBase
10 { 10 {
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 return CPluginSettings::GetInstance()->IsPluginEnabled(); 109 return CPluginSettings::GetInstance()->IsPluginEnabled();
110 } 110 }
111 111
112 112
113 template <class T> 113 template <class T>
114 void CPluginDomTraverserBase<T>::TraverseDocument(IWebBrowser2* pBrowser, bool i sMainDoc, CString indent) 114 void CPluginDomTraverserBase<T>::TraverseDocument(IWebBrowser2* pBrowser, bool i sMainDoc, CString indent)
115 { 115 {
116 DWORD res = WaitForSingleObject(m_tab->m_filter->hideFiltersLoadedEvent, ENGIN E_STARTUP_TIMEOUT); 116 DWORD res = WaitForSingleObject(m_tab->m_filter->hideFiltersLoadedEvent, ENGIN E_STARTUP_TIMEOUT);
117 if (!IsEnabled()) return; 117 if (!IsEnabled()) return;
118 118
119 VARIANT_BOOL isBusy; 119 VARIANT_BOOL isBusy;
120 if (SUCCEEDED(pBrowser->get_Busy(&isBusy))) 120 if (SUCCEEDED(pBrowser->get_Busy(&isBusy)))
121 { 121 {
122 if (isBusy) 122 if (isBusy != VARIANT_FALSE)
123 { 123 {
124 return; 124 return;
125 } 125 }
126 } 126 }
127 127
128 // Get document 128 // Get document
129 CComPtr<IDispatch> pDocDispatch; 129 CComPtr<IDispatch> pDocDispatch;
130 HRESULT hr = pBrowser->get_Document(&pDocDispatch); 130 HRESULT hr = pBrowser->get_Document(&pDocDispatch);
131 if (FAILED(hr) || !pDocDispatch) 131 if (FAILED(hr) || !pDocDispatch)
132 { 132 {
(...skipping 14 matching lines...) Expand all
147 147
148 CComPtr<IHTMLElement> pBodyEl; 148 CComPtr<IHTMLElement> pBodyEl;
149 149
150 if (m_isHeaderTraversed) 150 if (m_isHeaderTraversed)
151 { 151 {
152 pBodyEl = pBody; 152 pBodyEl = pBody;
153 } 153 }
154 else 154 else
155 { 155 {
156 CComPtr<IHTMLElementCollection> pBodyCollection; 156 CComPtr<IHTMLElementCollection> pBodyCollection;
157 if (FAILED(pDoc->getElementsByTagName(L"body", &pBodyCollection)) || !pBodyC ollection) 157 if (FAILED(pDoc->getElementsByTagName(ATL::CComBSTR(L"body"), &pBodyCollecti on)) || !pBodyCollection)
158 { 158 {
159 return; 159 return;
160 } 160 }
161 161
162 CComVariant vIndex(0); 162 CComVariant vIndex(0);
163 CComPtr<IDispatch> pBodyDispatch; 163 CComPtr<IDispatch> pBodyDispatch;
164 if (FAILED(pBodyCollection->item(vIndex, vIndex, &pBodyDispatch)) || !pBodyD ispatch) 164 if (FAILED(pBodyCollection->item(vIndex, vIndex, &pBodyDispatch)) || !pBodyD ispatch)
165 { 165 {
166 return; 166 return;
167 } 167 }
168 168
169 if (FAILED(pBodyDispatch->QueryInterface(IID_IHTMLElement, (LPVOID*)&pBodyEl )) || !pBodyEl) 169 if (FAILED(pBodyDispatch->QueryInterface(IID_IHTMLElement, (LPVOID*)&pBodyEl )) || !pBodyEl)
170 { 170 {
171 return; 171 return;
172 } 172 }
173 } 173 }
174 174
175 // Clear cache (if eg. refreshing) ??? 175 // Clear cache (if eg. refreshing) ???
176 if (isMainDoc) 176 if (isMainDoc)
177 { 177 {
178 CComVariant vCacheIndex; 178 CComVariant vCacheIndex;
179 179
180 if (FAILED(pBodyEl->getAttribute(L"abp", 0, &vCacheIndex)) || vCacheIndex.vt == VT_NULL) 180 if (FAILED(pBodyEl->getAttribute(ATL::CComBSTR(L"abp"), 0, &vCacheIndex)) || vCacheIndex.vt == VT_NULL)
181 { 181 {
182 ClearCache(); 182 ClearCache();
183 } 183 }
184 } 184 }
185 185
186 // Hide elements in body part 186 // Hide elements in body part
187 TraverseChild(pBodyEl, pBrowser, indent); 187 TraverseChild(pBodyEl, pBrowser, indent);
188 188
189 // Check frames and iframes 189 // Check frames and iframes
190 bool hasFrames = false; 190 bool hasFrames = false;
191 bool hasIframes = false; 191 bool hasIframes = false;
192 192
193 m_criticalSection.Lock(); 193 m_criticalSection.Lock();
194 { 194 {
195 hasFrames = m_cacheDocumentHasFrames.find(m_documentName) != m_cacheDocument HasFrames.end(); 195 hasFrames = m_cacheDocumentHasFrames.find(m_documentName) != m_cacheDocument HasFrames.end();
196 hasIframes = m_cacheDocumentHasIframes.find(m_documentName) != m_cacheDocume ntHasIframes.end(); 196 hasIframes = m_cacheDocumentHasIframes.find(m_documentName) != m_cacheDocume ntHasIframes.end();
197 } 197 }
198 m_criticalSection.Unlock(); 198 m_criticalSection.Unlock();
199 199
200 // Frames 200 // Frames
201 if (hasFrames) 201 if (hasFrames)
202 { 202 {
203 // eg. http://gamecopyworld.com/ 203 // eg. http://gamecopyworld.com/
204 long frameCount = 0; 204 long frameCount = 0;
205 CComPtr<IHTMLElementCollection> pFrameCollection; 205 CComPtr<IHTMLElementCollection> pFrameCollection;
206 if (SUCCEEDED(pDoc->getElementsByTagName(L"frame", &pFrameCollection)) && pF rameCollection) 206 if (SUCCEEDED(pDoc->getElementsByTagName(ATL::CComBSTR(L"frame"), &pFrameCol lection)) && pFrameCollection)
207 { 207 {
208 pFrameCollection->get_length(&frameCount); 208 pFrameCollection->get_length(&frameCount);
209 } 209 }
210 210
211 // Iterate through all frames 211 // Iterate through all frames
212 for (long i = 0; i < frameCount; i++) 212 for (long i = 0; i < frameCount; i++)
213 { 213 {
214 CComVariant vIndex(i); 214 CComVariant vIndex(i);
215 CComVariant vRetIndex; 215 CComVariant vRetIndex;
216 CComPtr<IDispatch> pFrameDispatch; 216 CComPtr<IDispatch> pFrameDispatch;
(...skipping 19 matching lines...) Expand all
236 } 236 }
237 } 237 }
238 } 238 }
239 } 239 }
240 240
241 // Iframes 241 // Iframes
242 if (hasIframes) 242 if (hasIframes)
243 { 243 {
244 long frameCount = 0; 244 long frameCount = 0;
245 CComPtr<IHTMLElementCollection> pFrameCollection; 245 CComPtr<IHTMLElementCollection> pFrameCollection;
246 if (SUCCEEDED(pDoc->getElementsByTagName(L"iframe", &pFrameCollection)) && p FrameCollection) 246 if (SUCCEEDED(pDoc->getElementsByTagName(ATL::CComBSTR(L"iframe"), &pFrameCo llection)) && pFrameCollection)
247 { 247 {
248 pFrameCollection->get_length(&frameCount); 248 pFrameCollection->get_length(&frameCount);
249 } 249 }
250 250
251 // Iterate through all iframes 251 // Iterate through all iframes
252 for (long i = 0; i < frameCount; i++) 252 for (long i = 0; i < frameCount; i++)
253 { 253 {
254 CComVariant vIndex(i); 254 CComVariant vIndex(i);
255 CComVariant vRetIndex; 255 CComVariant vRetIndex;
256 CComPtr<IDispatch> pFrameDispatch; 256 CComPtr<IDispatch> pFrameDispatch;
257 257
258 if (SUCCEEDED(pFrameCollection->item(vIndex, vRetIndex, &pFrameDispatch)) && pFrameDispatch) 258 if (SUCCEEDED(pFrameCollection->item(vIndex, vRetIndex, &pFrameDispatch)) && pFrameDispatch)
259 { 259 {
260 CComQIPtr<IHTMLElement> pFrameEl = pFrameDispatch; 260 CComQIPtr<IHTMLElement> pFrameEl = pFrameDispatch;
261 if (pFrameEl) 261 if (pFrameEl)
262 { 262 {
263 CComVariant vAttr; 263 CComVariant vAttr;
264 264
265 if (SUCCEEDED(pFrameEl->getAttribute(L"src", 0, &vAttr)) && vAttr.vt = = VT_BSTR && ::SysStringLen(vAttr.bstrVal) > 0) 265 if (SUCCEEDED(pFrameEl->getAttribute(ATL::CComBSTR(L"scr"), 0, &vAttr) ) && vAttr.vt == VT_BSTR && ::SysStringLen(vAttr.bstrVal) > 0)
266 { 266 {
267 CString src = vAttr.bstrVal; 267 CString src = vAttr.bstrVal;
268 268
269 // Some times, domain is missing. Should this be added on image src' s as well?'' 269 // Some times, domain is missing. Should this be added on image src' s as well?''
270 270
271 // eg. gadgetzone.com.au 271 // eg. gadgetzone.com.au
272 if (src.Left(2) == L"//") 272 if (src.Left(2) == L"//")
273 { 273 {
274 src = L"http:" + src; 274 src = L"http:" + src;
275 } 275 }
(...skipping 24 matching lines...) Expand all
300 300
301 template <class T> 301 template <class T>
302 void CPluginDomTraverserBase<T>::TraverseChild(IHTMLElement* pEl, IWebBrowser2* pBrowser, CString& indent, bool isCached) 302 void CPluginDomTraverserBase<T>::TraverseChild(IHTMLElement* pEl, IWebBrowser2* pBrowser, CString& indent, bool isCached)
303 { 303 {
304 int cacheIndex = -1; 304 int cacheIndex = -1;
305 long cacheAllElementsCount = -1; 305 long cacheAllElementsCount = -1;
306 306
307 m_criticalSection.Lock(); 307 m_criticalSection.Lock();
308 { 308 {
309 CComVariant vCacheIndex; 309 CComVariant vCacheIndex;
310 if (isCached && SUCCEEDED(pEl->getAttribute(L"abp", 0, &vCacheIndex)) && vCa cheIndex.vt == VT_I4) 310 if (isCached && SUCCEEDED(pEl->getAttribute(ATL::CComBSTR(L"abp"), 0, &vCach eIndex)) && vCacheIndex.vt == VT_I4)
311 { 311 {
312 cacheIndex = vCacheIndex.intVal; 312 cacheIndex = vCacheIndex.intVal;
313 313
314 cacheAllElementsCount = m_cacheElements[cacheIndex].m_elements; 314 cacheAllElementsCount = m_cacheElements[cacheIndex].m_elements;
315 } 315 }
316 else 316 else
317 { 317 {
318 isCached = false; 318 isCached = false;
319 319
320 cacheIndex = m_cacheIndexLast++; 320 cacheIndex = m_cacheIndexLast++;
(...skipping 10 matching lines...) Expand all
331 m_cacheElementsMax *= 2; 331 m_cacheElementsMax *= 2;
332 332
333 delete [] oldCacheElements; 333 delete [] oldCacheElements;
334 } 334 }
335 335
336 m_cacheElements[cacheIndex].Init(); 336 m_cacheElements[cacheIndex].Init();
337 337
338 vCacheIndex.vt = VT_I4; 338 vCacheIndex.vt = VT_I4;
339 vCacheIndex.intVal = cacheIndex; 339 vCacheIndex.intVal = cacheIndex;
340 340
341 pEl->setAttribute(L"abp", vCacheIndex); 341 pEl->setAttribute(ATL::CComBSTR(L"abp"), vCacheIndex);
342 } 342 }
343 } 343 }
344 m_criticalSection.Unlock(); 344 m_criticalSection.Unlock();
345 345
346 // Get number of elements in the scope of pEl 346 // Get number of elements in the scope of pEl
347 long allElementsCount = 0; 347 long allElementsCount = 0;
348 348
349 CComPtr<IDispatch> pAllCollectionDisp; 349 CComPtr<IDispatch> pAllCollectionDisp;
350 350
351 if (SUCCEEDED(pEl->get_all(&pAllCollectionDisp)) && pAllCollectionDisp) 351 if (SUCCEEDED(pEl->get_all(&pAllCollectionDisp)) && pAllCollectionDisp)
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 { 448 {
449 m_cacheIndexLast = 0; 449 m_cacheIndexLast = 0;
450 m_cacheDocumentHasFrames.clear(); 450 m_cacheDocumentHasFrames.clear();
451 m_cacheDocumentHasIframes.clear(); 451 m_cacheDocumentHasIframes.clear();
452 } 452 }
453 m_criticalSection.Unlock(); 453 m_criticalSection.Unlock();
454 } 454 }
455 455
456 456
457 #endif // _PLUGIN_DOM_TRAVERSER_BASE_H_ 457 #endif // _PLUGIN_DOM_TRAVERSER_BASE_H_
OLDNEW
« src/plugin/AdblockPlusDomTraverser.cpp ('K') | « src/plugin/AdblockPlusDomTraverser.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld