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: 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:
View unified diff | Download patch
« no previous file with comments | « src/plugin/AdblockPlusDomTraverser.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 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
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 129
130 template <class T> 130 template <class T>
131 void CPluginDomTraverserBase<T>::TraverseDocument(IWebBrowser2* pBrowser, bool i sMainDoc, CString indent) 131 void CPluginDomTraverserBase<T>::TraverseDocument(IWebBrowser2* pBrowser, bool i sMainDoc, CString indent)
132 { 132 {
133 DWORD res = WaitForSingleObject(m_tab->m_filter->hideFiltersLoadedEvent, ENGIN E_STARTUP_TIMEOUT); 133 DWORD res = WaitForSingleObject(m_tab->m_filter->hideFiltersLoadedEvent, ENGIN E_STARTUP_TIMEOUT);
134 if (!IsEnabled()) return; 134 if (!IsEnabled()) return;
135 135
136 VARIANT_BOOL isBusy; 136 VARIANT_BOOL isBusy;
137 if (SUCCEEDED(pBrowser->get_Busy(&isBusy))) 137 if (SUCCEEDED(pBrowser->get_Busy(&isBusy)))
138 { 138 {
139 if (isBusy) 139 if (isBusy != VARIANT_FALSE)
140 { 140 {
141 return; 141 return;
142 } 142 }
143 } 143 }
144 144
145 // Get document 145 // Get document
146 CComPtr<IDispatch> pDocDispatch; 146 CComPtr<IDispatch> pDocDispatch;
147 HRESULT hr = pBrowser->get_Document(&pDocDispatch); 147 HRESULT hr = pBrowser->get_Document(&pDocDispatch);
148 if (FAILED(hr) || !pDocDispatch) 148 if (FAILED(hr) || !pDocDispatch)
149 { 149 {
(...skipping 14 matching lines...) Expand all
164 164
165 CComPtr<IHTMLElement> pBodyEl; 165 CComPtr<IHTMLElement> pBodyEl;
166 166
167 if (m_isHeaderTraversed) 167 if (m_isHeaderTraversed)
168 { 168 {
169 pBodyEl = pBody; 169 pBodyEl = pBody;
170 } 170 }
171 else 171 else
172 { 172 {
173 CComPtr<IHTMLElementCollection> pBodyCollection; 173 CComPtr<IHTMLElementCollection> pBodyCollection;
174 if (FAILED(pDoc->getElementsByTagName(L"body", &pBodyCollection)) || !pBodyC ollection) 174 if (FAILED(pDoc->getElementsByTagName(ATL::CComBSTR(L"body"), &pBodyCollecti on)) || !pBodyCollection)
175 { 175 {
176 return; 176 return;
177 } 177 }
178 178
179 CComVariant vIndex(0); 179 CComVariant vIndex(0);
180 CComPtr<IDispatch> pBodyDispatch; 180 CComPtr<IDispatch> pBodyDispatch;
181 if (FAILED(pBodyCollection->item(vIndex, vIndex, &pBodyDispatch)) || !pBodyD ispatch) 181 if (FAILED(pBodyCollection->item(vIndex, vIndex, &pBodyDispatch)) || !pBodyD ispatch)
182 { 182 {
183 return; 183 return;
184 } 184 }
185 185
186 if (FAILED(pBodyDispatch->QueryInterface(IID_IHTMLElement, (LPVOID*)&pBodyEl )) || !pBodyEl) 186 if (FAILED(pBodyDispatch->QueryInterface(IID_IHTMLElement, (LPVOID*)&pBodyEl )) || !pBodyEl)
187 { 187 {
188 return; 188 return;
189 } 189 }
190 } 190 }
191 191
192 // Clear cache (if eg. refreshing) ??? 192 // Clear cache (if eg. refreshing) ???
193 if (isMainDoc) 193 if (isMainDoc)
194 { 194 {
195 CComVariant vCacheIndex; 195 CComVariant vCacheIndex;
196 196
197 if (FAILED(pBodyEl->getAttribute(L"abp", 0, &vCacheIndex)) || vCacheIndex.vt == VT_NULL) 197 if (FAILED(pBodyEl->getAttribute(ATL::CComBSTR(L"abp"), 0, &vCacheIndex)) || vCacheIndex.vt == VT_NULL)
198 { 198 {
199 ClearCache(); 199 ClearCache();
200 } 200 }
201 } 201 }
202 202
203 // Hide elements in body part 203 // Hide elements in body part
204 TraverseChild(pBodyEl, pBrowser, indent); 204 TraverseChild(pBodyEl, pBrowser, indent);
205 205
206 // Check frames and iframes 206 // Check frames and iframes
207 bool hasFrames = false; 207 bool hasFrames = false;
208 bool hasIframes = false; 208 bool hasIframes = false;
209 209
210 m_criticalSection.Lock(); 210 m_criticalSection.Lock();
211 { 211 {
212 hasFrames = m_cacheDocumentHasFrames.find(m_documentName) != m_cacheDocument HasFrames.end(); 212 hasFrames = m_cacheDocumentHasFrames.find(m_documentName) != m_cacheDocument HasFrames.end();
213 hasIframes = m_cacheDocumentHasIframes.find(m_documentName) != m_cacheDocume ntHasIframes.end(); 213 hasIframes = m_cacheDocumentHasIframes.find(m_documentName) != m_cacheDocume ntHasIframes.end();
214 } 214 }
215 m_criticalSection.Unlock(); 215 m_criticalSection.Unlock();
216 216
217 // Frames 217 // Frames
218 if (hasFrames) 218 if (hasFrames)
219 { 219 {
220 // eg. http://gamecopyworld.com/ 220 // eg. http://gamecopyworld.com/
221 long frameCount = 0; 221 long frameCount = 0;
222 CComPtr<IHTMLElementCollection> pFrameCollection; 222 CComPtr<IHTMLElementCollection> pFrameCollection;
223 if (SUCCEEDED(pDoc->getElementsByTagName(L"frame", &pFrameCollection)) && pF rameCollection) 223 if (SUCCEEDED(pDoc->getElementsByTagName(ATL::CComBSTR(L"frame"), &pFrameCol lection)) && pFrameCollection)
224 { 224 {
225 pFrameCollection->get_length(&frameCount); 225 pFrameCollection->get_length(&frameCount);
226 } 226 }
227 227
228 // Iterate through all frames 228 // Iterate through all frames
229 for (long i = 0; i < frameCount; i++) 229 for (long i = 0; i < frameCount; i++)
230 { 230 {
231 CComVariant vIndex(i); 231 CComVariant vIndex(i);
232 CComVariant vRetIndex; 232 CComVariant vRetIndex;
233 CComPtr<IDispatch> pFrameDispatch; 233 CComPtr<IDispatch> pFrameDispatch;
(...skipping 17 matching lines...) Expand all
251 } 251 }
252 } 252 }
253 } 253 }
254 } 254 }
255 255
256 // Iframes 256 // Iframes
257 if (hasIframes) 257 if (hasIframes)
258 { 258 {
259 long frameCount = 0; 259 long frameCount = 0;
260 CComPtr<IHTMLElementCollection> pFrameCollection; 260 CComPtr<IHTMLElementCollection> pFrameCollection;
261 if (SUCCEEDED(pDoc->getElementsByTagName(L"iframe", &pFrameCollection)) && p FrameCollection) 261 if (SUCCEEDED(pDoc->getElementsByTagName(ATL::CComBSTR(L"iframe"), &pFrameCo llection)) && pFrameCollection)
262 { 262 {
263 pFrameCollection->get_length(&frameCount); 263 pFrameCollection->get_length(&frameCount);
264 } 264 }
265 265
266 // Iterate through all iframes 266 // Iterate through all iframes
267 for (long i = 0; i < frameCount; i++) 267 for (long i = 0; i < frameCount; i++)
268 { 268 {
269 CComVariant vIndex(i); 269 CComVariant vIndex(i);
270 CComVariant vRetIndex; 270 CComVariant vRetIndex;
271 CComPtr<IDispatch> pFrameDispatch; 271 CComPtr<IDispatch> pFrameDispatch;
272 272
273 if (SUCCEEDED(pFrameCollection->item(vIndex, vRetIndex, &pFrameDispatch)) && pFrameDispatch) 273 if (SUCCEEDED(pFrameCollection->item(vIndex, vRetIndex, &pFrameDispatch)) && pFrameDispatch)
274 { 274 {
275 CComQIPtr<IHTMLElement> pFrameEl = pFrameDispatch; 275 CComQIPtr<IHTMLElement> pFrameEl = pFrameDispatch;
276 if (pFrameEl) 276 if (pFrameEl)
277 { 277 {
278 CComVariant vAttr; 278 CComVariant vAttr;
279 279
280 if (SUCCEEDED(pFrameEl->getAttribute(L"src", 0, &vAttr)) && vAttr.vt = = VT_BSTR && ::SysStringLen(vAttr.bstrVal) > 0) 280 if (SUCCEEDED(pFrameEl->getAttribute(ATL::CComBSTR(L"scr"), 0, &vAttr) ) && vAttr.vt == VT_BSTR && ::SysStringLen(vAttr.bstrVal) > 0)
281 { 281 {
282 CString srcLegacy = vAttr.bstrVal; 282 CString srcLegacy = vAttr.bstrVal;
283 283
284 // Some times, domain is missing. Should this be added on image src' s as well?'' 284 // Some times, domain is missing. Should this be added on image src' s as well?''
285 285
286 // eg. gadgetzone.com.au 286 // eg. gadgetzone.com.au
287 if (srcLegacy.Left(2) == L"//") 287 if (srcLegacy.Left(2) == L"//")
288 { 288 {
289 srcLegacy = L"http:" + srcLegacy; 289 srcLegacy = L"http:" + srcLegacy;
290 } 290 }
(...skipping 24 matching lines...) Expand all
315 315
316 template <class T> 316 template <class T>
317 void CPluginDomTraverserBase<T>::TraverseChild(IHTMLElement* pEl, IWebBrowser2* pBrowser, CString& indent, bool isCached) 317 void CPluginDomTraverserBase<T>::TraverseChild(IHTMLElement* pEl, IWebBrowser2* pBrowser, CString& indent, bool isCached)
318 { 318 {
319 int cacheIndex = -1; 319 int cacheIndex = -1;
320 long cacheAllElementsCount = -1; 320 long cacheAllElementsCount = -1;
321 321
322 m_criticalSection.Lock(); 322 m_criticalSection.Lock();
323 { 323 {
324 CComVariant vCacheIndex; 324 CComVariant vCacheIndex;
325 if (isCached && SUCCEEDED(pEl->getAttribute(L"abp", 0, &vCacheIndex)) && vCa cheIndex.vt == VT_I4) 325 if (isCached && SUCCEEDED(pEl->getAttribute(ATL::CComBSTR(L"abp"), 0, &vCach eIndex)) && vCacheIndex.vt == VT_I4)
326 { 326 {
327 cacheIndex = vCacheIndex.intVal; 327 cacheIndex = vCacheIndex.intVal;
328 328
329 cacheAllElementsCount = m_cacheElements[cacheIndex].m_elements; 329 cacheAllElementsCount = m_cacheElements[cacheIndex].m_elements;
330 } 330 }
331 else 331 else
332 { 332 {
333 isCached = false; 333 isCached = false;
334 334
335 cacheIndex = m_cacheIndexLast++; 335 cacheIndex = m_cacheIndexLast++;
(...skipping 10 matching lines...) Expand all
346 m_cacheElementsMax *= 2; 346 m_cacheElementsMax *= 2;
347 347
348 delete [] oldCacheElements; 348 delete [] oldCacheElements;
349 } 349 }
350 350
351 m_cacheElements[cacheIndex].Init(); 351 m_cacheElements[cacheIndex].Init();
352 352
353 vCacheIndex.vt = VT_I4; 353 vCacheIndex.vt = VT_I4;
354 vCacheIndex.intVal = cacheIndex; 354 vCacheIndex.intVal = cacheIndex;
355 355
356 pEl->setAttribute(L"abp", vCacheIndex); 356 pEl->setAttribute(ATL::CComBSTR(L"abp"), vCacheIndex);
357 } 357 }
358 } 358 }
359 m_criticalSection.Unlock(); 359 m_criticalSection.Unlock();
360 360
361 // Get number of elements in the scope of pEl 361 // Get number of elements in the scope of pEl
362 long allElementsCount = 0; 362 long allElementsCount = 0;
363 363
364 CComPtr<IDispatch> pAllCollectionDisp; 364 CComPtr<IDispatch> pAllCollectionDisp;
365 365
366 if (SUCCEEDED(pEl->get_all(&pAllCollectionDisp)) && pAllCollectionDisp) 366 if (SUCCEEDED(pEl->get_all(&pAllCollectionDisp)) && pAllCollectionDisp)
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 { 463 {
464 m_cacheIndexLast = 0; 464 m_cacheIndexLast = 0;
465 m_cacheDocumentHasFrames.clear(); 465 m_cacheDocumentHasFrames.clear();
466 m_cacheDocumentHasIframes.clear(); 466 m_cacheDocumentHasIframes.clear();
467 } 467 }
468 m_criticalSection.Unlock(); 468 m_criticalSection.Unlock();
469 } 469 }
470 470
471 471
472 #endif // _PLUGIN_DOM_TRAVERSER_BASE_H_ 472 #endif // _PLUGIN_DOM_TRAVERSER_BASE_H_
OLDNEW
« no previous file with comments | « src/plugin/AdblockPlusDomTraverser.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld