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

Delta Between Two Patch Sets: src/plugin/PluginDomTraverserBase.h

Issue 29331669: Issue 3237 - Whitelisted AFS ad is not shown on netzwelt.de (Closed)
Left Patch Set: Created Dec. 1, 2015, 2:15 a.m.
Right Patch Set: Move subdocument detection to the top. Created Dec. 15, 2015, 2:05 a.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
LEFTRIGHT
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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 42
43 void TraverseHeader(bool isHeaderTraversed); 43 void TraverseHeader(bool isHeaderTraversed);
44 44
45 void TraverseDocument(IWebBrowser2* pBrowser, const std::wstring& domain, cons t std::wstring& documentUrl); 45 void TraverseDocument(IWebBrowser2* pBrowser, const std::wstring& domain, cons t std::wstring& documentUrl);
46 void TraverseSubdocument(IWebBrowser2* pBrowser, const std::wstring& domain, c onst std::wstring& documentUrl); 46 void TraverseSubdocument(IWebBrowser2* pBrowser, const std::wstring& domain, c onst std::wstring& documentUrl);
47 47
48 virtual void ClearCache(); 48 virtual void ClearCache();
49 49
50 protected: 50 protected:
51 51
52 virtual bool OnIFrame(IHTMLElement* pEl, const std::wstring& url, CString& ind ent) { return true; } 52 virtual bool OnIFrame(IHTMLElement* pEl, const std::wstring& url, const std::w string& indent) { return true; }
53 virtual bool OnElement(IHTMLElement* pEl, const CString& tag, T* cache, bool i sDebug, CString& indent) { return true; } 53 virtual bool OnElement(IHTMLElement* pEl, const std::wstring& tag, T* cache, b ool isDebug, const std::wstring& indent) { return true; }
54 54
55 virtual bool IsEnabled(); 55 virtual bool IsEnabled();
56 56
57 protected: 57 protected:
58 58
59 void TraverseDocument(IWebBrowser2* pBrowser, bool isMainDoc, CString indent); 59 void TraverseDocument(IWebBrowser2* pBrowser, bool isMainDoc, const std::wstri ng& indent);
60 void TraverseChild(IHTMLElement* pEl, IWebBrowser2* pBrowser, CString& indent, bool isCached=true); 60 void TraverseChild(IHTMLElement* pEl, IWebBrowser2* pBrowser, const std::wstri ng& indent, bool isCached=true);
61 61
62 CComAutoCriticalSection m_criticalSection; 62 CComAutoCriticalSection m_criticalSection;
63 63
64 std::wstring m_domain; 64 std::wstring m_domain;
65 std::wstring m_documentUrl; 65 std::wstring m_documentUrl;
66 66
67 bool m_isHeaderTraversed; 67 bool m_isHeaderTraversed;
68 68
69 // Caching 69 // Caching
70 long m_cacheDomElementCount; 70 long m_cacheDomElementCount;
(...skipping 27 matching lines...) Expand all
98 void CPluginDomTraverserBase<T>::TraverseHeader(bool isHeaderTraversed) 98 void CPluginDomTraverserBase<T>::TraverseHeader(bool isHeaderTraversed)
99 { 99 {
100 m_isHeaderTraversed = isHeaderTraversed; 100 m_isHeaderTraversed = isHeaderTraversed;
101 } 101 }
102 102
103 template <class T> 103 template <class T>
104 void CPluginDomTraverserBase<T>::TraverseDocument(IWebBrowser2* pBrowser, const std::wstring& domain, const std::wstring& documentUrl) 104 void CPluginDomTraverserBase<T>::TraverseDocument(IWebBrowser2* pBrowser, const std::wstring& domain, const std::wstring& documentUrl)
105 { 105 {
106 m_domain = domain; 106 m_domain = domain;
107 m_documentUrl = documentUrl; 107 m_documentUrl = documentUrl;
108 TraverseDocument(pBrowser, true, ""); 108 TraverseDocument(pBrowser, true, L"");
109 } 109 }
110 110
111 111
112 template <class T> 112 template <class T>
113 void CPluginDomTraverserBase<T>::TraverseSubdocument(IWebBrowser2* pBrowser, con st std::wstring& domain, const std::wstring& documentUrl) 113 void CPluginDomTraverserBase<T>::TraverseSubdocument(IWebBrowser2* pBrowser, con st std::wstring& domain, const std::wstring& documentUrl)
114 { 114 {
115 m_domain = domain; 115 m_domain = domain;
116 m_documentUrl = documentUrl; 116 m_documentUrl = documentUrl;
117 TraverseDocument(pBrowser, false, ""); 117 TraverseDocument(pBrowser, false, L"");
118 } 118 }
119 119
120 120
121 template <class T> 121 template <class T>
122 bool CPluginDomTraverserBase<T>::IsEnabled() 122 bool CPluginDomTraverserBase<T>::IsEnabled()
123 { 123 {
124 return CPluginSettings::GetInstance()->IsPluginEnabled(); 124 return CPluginSettings::GetInstance()->IsPluginEnabled();
125 } 125 }
126 126
127 127
128 template <class T> 128 template <class T>
129 void CPluginDomTraverserBase<T>::TraverseDocument(IWebBrowser2* pBrowser, bool i sMainDoc, CString indent) 129 void CPluginDomTraverserBase<T>::TraverseDocument(IWebBrowser2* pBrowser, bool i sMainDoc, const std::wstring& indent)
130 { 130 {
131 DWORD res = WaitForSingleObject(m_tab->m_filter->hideFiltersLoadedEvent, ENGIN E_STARTUP_TIMEOUT); 131 DWORD res = WaitForSingleObject(m_tab->m_filter->hideFiltersLoadedEvent, ENGIN E_STARTUP_TIMEOUT);
132 if (!IsEnabled()) return; 132 if (!IsEnabled()) return;
133 133
134 VARIANT_BOOL isBusy; 134 VARIANT_BOOL isBusy;
135 if (SUCCEEDED(pBrowser->get_Busy(&isBusy))) 135 if (SUCCEEDED(pBrowser->get_Busy(&isBusy)))
136 { 136 {
137 if (isBusy != VARIANT_FALSE) 137 if (isBusy != VARIANT_FALSE)
138 { 138 {
139 return; 139 return;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 return; 174 return;
175 } 175 }
176 176
177 CComVariant vIndex(0); 177 CComVariant vIndex(0);
178 CComPtr<IDispatch> pBodyDispatch; 178 CComPtr<IDispatch> pBodyDispatch;
179 if (FAILED(pBodyCollection->item(vIndex, vIndex, &pBodyDispatch)) || !pBodyD ispatch) 179 if (FAILED(pBodyCollection->item(vIndex, vIndex, &pBodyDispatch)) || !pBodyD ispatch)
180 { 180 {
181 return; 181 return;
182 } 182 }
183 183
184 if (FAILED(pBodyDispatch->QueryInterface(IID_IHTMLElement, (LPVOID*)&pBodyEl )) || !pBodyEl) 184 if (FAILED(pBodyDispatch->QueryInterface(&pBodyEl)) || !pBodyEl)
185 { 185 {
186 return; 186 return;
187 } 187 }
188 } 188 }
189 189
190 // Clear cache (if eg. refreshing) ??? 190 // Clear cache (if eg. refreshing) ???
191 if (isMainDoc) 191 if (isMainDoc)
192 { 192 {
193 CComVariant vCacheIndex; 193 CComVariant vCacheIndex;
194 194
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 TraverseDocument(pFrameBrowser, false, indent); 299 TraverseDocument(pFrameBrowser, false, indent);
300 } 300 }
301 } 301 }
302 } 302 }
303 } 303 }
304 } 304 }
305 } 305 }
306 } 306 }
307 } 307 }
308 308
309 309 template <class T>
310 template <class T> 310 void CPluginDomTraverserBase<T>::TraverseChild(IHTMLElement* pEl, IWebBrowser2* pBrowser, const std::wstring& indent, bool isCached)
311 void CPluginDomTraverserBase<T>::TraverseChild(IHTMLElement* pEl, IWebBrowser2* pBrowser, CString& indent, bool isCached)
312 { 311 {
313 int cacheIndex = -1; 312 int cacheIndex = -1;
314 long cacheAllElementsCount = -1; 313 long cacheAllElementsCount = -1;
315 314
316 m_criticalSection.Lock(); 315 m_criticalSection.Lock();
317 { 316 {
318 CComVariant vCacheIndex; 317 CComVariant vCacheIndex;
319 if (isCached && SUCCEEDED(pEl->getAttribute(ATL::CComBSTR(L"abp"), 0, &vCach eIndex)) && vCacheIndex.vt == VT_I4) 318 if (isCached && SUCCEEDED(pEl->getAttribute(ATL::CComBSTR(L"abp"), 0, &vCach eIndex)) && vCacheIndex.vt == VT_I4)
320 { 319 {
321 cacheIndex = vCacheIndex.intVal; 320 cacheIndex = vCacheIndex.intVal;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 353
355 // Get number of elements in the scope of pEl 354 // Get number of elements in the scope of pEl
356 long allElementsCount = 0; 355 long allElementsCount = 0;
357 356
358 CComPtr<IDispatch> pAllCollectionDisp; 357 CComPtr<IDispatch> pAllCollectionDisp;
359 358
360 if (SUCCEEDED(pEl->get_all(&pAllCollectionDisp)) && pAllCollectionDisp) 359 if (SUCCEEDED(pEl->get_all(&pAllCollectionDisp)) && pAllCollectionDisp)
361 { 360 {
362 CComPtr<IHTMLElementCollection> pAllCollection; 361 CComPtr<IHTMLElementCollection> pAllCollection;
363 362
364 if (SUCCEEDED(pAllCollectionDisp->QueryInterface(IID_IHTMLElementCollection, (LPVOID*)&pAllCollection)) && pAllCollection) 363 if (SUCCEEDED(pAllCollectionDisp->QueryInterface(&pAllCollection)) && pAllCo llection)
365 { 364 {
366 // If number of elements = cached number, return 365 // If number of elements = cached number, return
367 if (SUCCEEDED(pAllCollection->get_length(&allElementsCount)) && allElement sCount == cacheAllElementsCount) 366 if (SUCCEEDED(pAllCollection->get_length(&allElementsCount)) && allElement sCount == cacheAllElementsCount)
368 { 367 {
369 return; 368 return;
370 } 369 }
371 } 370 }
372 } 371 }
373 372
374 // Update cache 373 // Update cache
375 m_criticalSection.Lock(); 374 m_criticalSection.Lock();
376 { 375 {
377 m_cacheElements[cacheIndex].m_elements = allElementsCount; 376 m_cacheElements[cacheIndex].m_elements = allElementsCount;
378 } 377 }
379 m_criticalSection.Unlock(); 378 m_criticalSection.Unlock();
380 379
381 // Get tag 380 // Get tag
382 CComBSTR bstrTag; 381 CComBSTR bstrTag;
383 if (FAILED(pEl->get_tagName(&bstrTag)) || !bstrTag) 382 if (FAILED(pEl->get_tagName(&bstrTag)) || !bstrTag)
384 { 383 {
385 return; 384 return;
386 } 385 }
387 386 std::wstring tag = ToLowerString(ToWstring(bstrTag));
388 CString tag = bstrTag;
389 tag.MakeLower();
390 387
391 // Custom OnElement 388 // Custom OnElement
392 if (!OnElement(pEl, tag, &m_cacheElements[cacheIndex], false, indent)) 389 if (!OnElement(pEl, tag, &m_cacheElements[cacheIndex], false, indent))
393 { 390 {
394 return; 391 return;
395 } 392 }
396 393
397 // Update frame/iframe cache 394 // Update frame/iframe cache
398 if (tag == "iframe") 395 if (tag == L"iframe")
399 { 396 {
400 m_criticalSection.Lock(); 397 m_criticalSection.Lock();
401 { 398 {
402 m_cacheDocumentHasIframes.insert(m_documentUrl); 399 m_cacheDocumentHasIframes.insert(m_documentUrl);
403 } 400 }
404 m_criticalSection.Unlock(); 401 m_criticalSection.Unlock();
405 } 402 }
406 else if (tag == "frame") 403 else if (tag == L"frame")
407 { 404 {
408 m_criticalSection.Lock(); 405 m_criticalSection.Lock();
409 { 406 {
410 m_cacheDocumentHasFrames.insert(m_documentUrl); 407 m_cacheDocumentHasFrames.insert(m_documentUrl);
411 } 408 }
412 m_criticalSection.Unlock(); 409 m_criticalSection.Unlock();
413 } 410 }
414 411
415 // Iterate through children of this element 412 // Iterate through children of this element
416 if (allElementsCount > 0) 413 if (allElementsCount > 0)
417 { 414 {
418 long childElementsCount = 0; 415 long childElementsCount = 0;
419 416
420 CComPtr<IDispatch> pChildCollectionDisp; 417 CComPtr<IDispatch> pChildCollectionDisp;
421 if (SUCCEEDED(pEl->get_children(&pChildCollectionDisp)) && pChildCollectionD isp) 418 if (SUCCEEDED(pEl->get_children(&pChildCollectionDisp)) && pChildCollectionD isp)
422 { 419 {
423 CComPtr<IHTMLElementCollection> pChildCollection; 420 CComPtr<IHTMLElementCollection> pChildCollection;
424 if (SUCCEEDED(pChildCollectionDisp->QueryInterface(IID_IHTMLElementCollect ion, (LPVOID*)&pChildCollection)) && pChildCollection) 421 if (SUCCEEDED(pChildCollectionDisp->QueryInterface(&pChildCollection)) && pChildCollection)
425 { 422 {
426 pChildCollection->get_length(&childElementsCount); 423 pChildCollection->get_length(&childElementsCount);
427 424
428 CComVariant vIndex(0); 425 CComVariant vIndex(0);
429 426
430 // Iterate through all children 427 // Iterate through all children
431 for (long i = 0; i < childElementsCount; i++) 428 for (long i = 0; i < childElementsCount; i++)
432 { 429 {
433 CComPtr<IDispatch> pChildElDispatch; 430 CComPtr<IDispatch> pChildElDispatch;
434 CComVariant vRetIndex; 431 CComVariant vRetIndex;
435 432
436 vIndex.intVal = i; 433 vIndex.intVal = i;
437 434
438 if (SUCCEEDED(pChildCollection->item(vIndex, vRetIndex, &pChildElDispa tch)) && pChildElDispatch) 435 if (SUCCEEDED(pChildCollection->item(vIndex, vRetIndex, &pChildElDispa tch)) && pChildElDispatch)
439 { 436 {
440 CComPtr<IHTMLElement> pChildEl; 437 CComPtr<IHTMLElement> pChildEl;
441 if (SUCCEEDED(pChildElDispatch->QueryInterface(IID_IHTMLElement, (LP VOID*)&pChildEl)) && pChildEl) 438 if (SUCCEEDED(pChildElDispatch->QueryInterface(&pChildEl)) && pChild El)
442 { 439 {
443 TraverseChild(pChildEl, pBrowser, indent + " ", isCached); 440 TraverseChild(pChildEl, pBrowser, indent + L" ", isCached);
444 } 441 }
445 } 442 }
446 } 443 }
447 } 444 }
448 } 445 }
449 } 446 }
450 } 447 }
451 448
452 449
453 template <class T> 450 template <class T>
454 void CPluginDomTraverserBase<T>::ClearCache() 451 void CPluginDomTraverserBase<T>::ClearCache()
455 { 452 {
456 m_criticalSection.Lock(); 453 m_criticalSection.Lock();
457 { 454 {
458 m_cacheIndexLast = 0; 455 m_cacheIndexLast = 0;
459 m_cacheDocumentHasFrames.clear(); 456 m_cacheDocumentHasFrames.clear();
460 m_cacheDocumentHasIframes.clear(); 457 m_cacheDocumentHasIframes.clear();
461 } 458 }
462 m_criticalSection.Unlock(); 459 m_criticalSection.Unlock();
463 } 460 }
464 461
465 462
466 #endif // _PLUGIN_DOM_TRAVERSER_BASE_H_ 463 #endif // _PLUGIN_DOM_TRAVERSER_BASE_H_
LEFTRIGHT

Powered by Google App Engine
This is Rietveld