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

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

Issue 29331669: Issue 3237 - Whitelisted AFS ad is not shown on netzwelt.de (Closed)
Patch Set: Created Dec. 1, 2015, 2:15 a.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 /* 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 24 matching lines...) Expand all
35 class CPluginDomTraverserBase 35 class CPluginDomTraverserBase
36 { 36 {
37 37
38 public: 38 public:
39 39
40 CPluginDomTraverserBase(CPluginTab* tab); 40 CPluginDomTraverserBase(CPluginTab* tab);
41 ~CPluginDomTraverserBase(); 41 ~CPluginDomTraverserBase();
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& documentName); 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 CString& documentName); 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, CString& ind ent) { 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 CString& tag, T* cache, bool i sDebug, CString& 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, CString indent);
60 void TraverseChild(IHTMLElement* pEl, IWebBrowser2* pBrowser, CString& indent, bool isCached=true); 60 void TraverseChild(IHTMLElement* pEl, IWebBrowser2* pBrowser, CString& 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 CString m_documentName; 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;
71 71
72 int m_cacheIndexLast; 72 int m_cacheIndexLast;
73 int m_cacheElementsMax; 73 int m_cacheElementsMax;
74 std::set<CString> m_cacheDocumentHasFrames; 74 std::set<std::wstring> m_cacheDocumentHasFrames;
75 std::set<CString> m_cacheDocumentHasIframes; 75 std::set<std::wstring> m_cacheDocumentHasIframes;
76 76
77 T* m_cacheElements; 77 T* m_cacheElements;
78 78
79 CPluginTab* m_tab; 79 CPluginTab* m_tab;
80 CComPtr<IWebBrowser2> m_pBrowser; 80 CComPtr<IWebBrowser2> m_pBrowser;
81 }; 81 };
82 82
83 template <class T> 83 template <class T>
84 CPluginDomTraverserBase<T>::CPluginDomTraverserBase(CPluginTab* tab) : 84 CPluginDomTraverserBase<T>::CPluginDomTraverserBase(CPluginTab* tab) :
85 m_tab(tab), m_isHeaderTraversed(false), m_cacheDomElementCount(0), m_cacheInde xLast(0), m_cacheElementsMax(5000) 85 m_tab(tab), m_isHeaderTraversed(false), m_cacheDomElementCount(0), m_cacheInde xLast(0), m_cacheElementsMax(5000)
86 { 86 {
87 m_cacheElements = new T[m_cacheElementsMax]; 87 m_cacheElements = new T[m_cacheElementsMax];
88 } 88 }
89 89
90 90
91 template <class T> 91 template <class T>
92 CPluginDomTraverserBase<T>::~CPluginDomTraverserBase() 92 CPluginDomTraverserBase<T>::~CPluginDomTraverserBase()
93 { 93 {
94 delete [] m_cacheElements; 94 delete [] m_cacheElements;
95 } 95 }
96 96
97 template <class T> 97 template <class T>
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& documentName) 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 107 m_documentUrl = documentUrl;
108 TraverseDocument(pBrowser, true, ""); 108 TraverseDocument(pBrowser, true, "");
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 CString& documentName) 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 116 m_documentUrl = documentUrl;
117 TraverseDocument(pBrowser, false, ""); 117 TraverseDocument(pBrowser, false, "");
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
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 200
201 // Hide elements in body part 201 // Hide elements in body part
202 TraverseChild(pBodyEl, pBrowser, indent); 202 TraverseChild(pBodyEl, pBrowser, indent);
203 203
204 // Check frames and iframes 204 // Check frames and iframes
205 bool hasFrames = false; 205 bool hasFrames = false;
206 bool hasIframes = false; 206 bool hasIframes = false;
207 207
208 m_criticalSection.Lock(); 208 m_criticalSection.Lock();
209 { 209 {
210 hasFrames = m_cacheDocumentHasFrames.find(m_documentName) != m_cacheDocument HasFrames.end(); 210 hasFrames = m_cacheDocumentHasFrames.find(m_documentUrl) != m_cacheDocumentH asFrames.end();
211 hasIframes = m_cacheDocumentHasIframes.find(m_documentName) != m_cacheDocume ntHasIframes.end(); 211 hasIframes = m_cacheDocumentHasIframes.find(m_documentUrl) != m_cacheDocumen tHasIframes.end();
212 } 212 }
213 m_criticalSection.Unlock(); 213 m_criticalSection.Unlock();
214 214
215 // Frames 215 // Frames
216 if (hasFrames) 216 if (hasFrames)
217 { 217 {
218 // eg. http://gamecopyworld.com/ 218 // eg. http://gamecopyworld.com/
219 long frameCount = 0; 219 long frameCount = 0;
220 CComPtr<IHTMLElementCollection> pFrameCollection; 220 CComPtr<IHTMLElementCollection> pFrameCollection;
221 if (SUCCEEDED(pDoc->getElementsByTagName(ATL::CComBSTR(L"frame"), &pFrameCol lection)) && pFrameCollection) 221 if (SUCCEEDED(pDoc->getElementsByTagName(ATL::CComBSTR(L"frame"), &pFrameCol lection)) && pFrameCollection)
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 if (!OnElement(pEl, tag, &m_cacheElements[cacheIndex], false, indent)) 392 if (!OnElement(pEl, tag, &m_cacheElements[cacheIndex], false, indent))
393 { 393 {
394 return; 394 return;
395 } 395 }
396 396
397 // Update frame/iframe cache 397 // Update frame/iframe cache
398 if (tag == "iframe") 398 if (tag == "iframe")
399 { 399 {
400 m_criticalSection.Lock(); 400 m_criticalSection.Lock();
401 { 401 {
402 m_cacheDocumentHasIframes.insert(m_documentName); 402 m_cacheDocumentHasIframes.insert(m_documentUrl);
403 } 403 }
404 m_criticalSection.Unlock(); 404 m_criticalSection.Unlock();
405 } 405 }
406 else if (tag == "frame") 406 else if (tag == "frame")
407 { 407 {
408 m_criticalSection.Lock(); 408 m_criticalSection.Lock();
409 { 409 {
410 m_cacheDocumentHasFrames.insert(m_documentName); 410 m_cacheDocumentHasFrames.insert(m_documentUrl);
411 } 411 }
412 m_criticalSection.Unlock(); 412 m_criticalSection.Unlock();
413 } 413 }
414 414
415 // Iterate through children of this element 415 // Iterate through children of this element
416 if (allElementsCount > 0) 416 if (allElementsCount > 0)
417 { 417 {
418 long childElementsCount = 0; 418 long childElementsCount = 0;
419 419
420 CComPtr<IDispatch> pChildCollectionDisp; 420 CComPtr<IDispatch> pChildCollectionDisp;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 { 457 {
458 m_cacheIndexLast = 0; 458 m_cacheIndexLast = 0;
459 m_cacheDocumentHasFrames.clear(); 459 m_cacheDocumentHasFrames.clear();
460 m_cacheDocumentHasIframes.clear(); 460 m_cacheDocumentHasIframes.clear();
461 } 461 }
462 m_criticalSection.Unlock(); 462 m_criticalSection.Unlock();
463 } 463 }
464 464
465 465
466 #endif // _PLUGIN_DOM_TRAVERSER_BASE_H_ 466 #endif // _PLUGIN_DOM_TRAVERSER_BASE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld