OLD | NEW |
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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 virtual bool IsEnabled(); | 55 virtual bool IsEnabled(); |
56 | 56 |
57 protected: | 57 protected: |
58 | 58 |
59 void TraverseDocument(IWebBrowser2* pBrowser, bool isMainDoc, const std::wstri
ng& indent); | 59 void TraverseDocument(IWebBrowser2* pBrowser, bool isMainDoc, const std::wstri
ng& indent); |
60 void TraverseChild(IHTMLElement* pEl, IWebBrowser2* pBrowser, const std::wstri
ng& 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_documentName; | |
66 | 65 |
67 bool m_isHeaderTraversed; | 66 bool m_isHeaderTraversed; |
68 | 67 |
69 // Caching | 68 // Caching |
70 long m_cacheDomElementCount; | 69 long m_cacheDomElementCount; |
71 | 70 |
72 int m_cacheIndexLast; | 71 int m_cacheIndexLast; |
73 int m_cacheElementsMax; | 72 int m_cacheElementsMax; |
74 std::set<std::wstring> m_cacheDocumentHasFrames; | 73 bool cacheHasFrames; |
75 std::set<std::wstring> m_cacheDocumentHasIframes; | 74 bool cacheHasIframes; |
76 | 75 |
77 T* m_cacheElements; | 76 T* m_cacheElements; |
78 | 77 |
79 CPluginTab* m_tab; | 78 CPluginTab* m_tab; |
80 CComPtr<IWebBrowser2> m_pBrowser; | 79 CComPtr<IWebBrowser2> m_pBrowser; |
81 }; | 80 }; |
82 | 81 |
83 template <class T> | 82 template <class T> |
84 CPluginDomTraverserBase<T>::CPluginDomTraverserBase(CPluginTab* tab) : | 83 CPluginDomTraverserBase<T>::CPluginDomTraverserBase(CPluginTab* tab) |
85 m_tab(tab), m_isHeaderTraversed(false), m_cacheDomElementCount(0), m_cacheInde
xLast(0), m_cacheElementsMax(5000) | 84 : m_tab(tab), m_isHeaderTraversed(false), m_cacheDomElementCount(0), m_cacheIn
dexLast(0), m_cacheElementsMax(5000) |
| 85 , cacheHasFrames(false), cacheHasIframes(false) |
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 } |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 = cacheHasFrames; |
211 hasIframes = m_cacheDocumentHasIframes.find(m_documentName) != m_cacheDocume
ntHasIframes.end(); | 211 hasIframes = cacheHasIframes; |
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 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 if (!OnElement(pEl, tag, &m_cacheElements[cacheIndex], false, indent)) | 389 if (!OnElement(pEl, tag, &m_cacheElements[cacheIndex], false, indent)) |
390 { | 390 { |
391 return; | 391 return; |
392 } | 392 } |
393 | 393 |
394 // Update frame/iframe cache | 394 // Update frame/iframe cache |
395 if (tag == L"iframe") | 395 if (tag == L"iframe") |
396 { | 396 { |
397 m_criticalSection.Lock(); | 397 m_criticalSection.Lock(); |
398 { | 398 { |
399 m_cacheDocumentHasIframes.insert(m_documentName); | 399 cacheHasIframes = true; |
400 } | 400 } |
401 m_criticalSection.Unlock(); | 401 m_criticalSection.Unlock(); |
402 } | 402 } |
403 else if (tag == L"frame") | 403 else if (tag == L"frame") |
404 { | 404 { |
405 m_criticalSection.Lock(); | 405 m_criticalSection.Lock(); |
406 { | 406 { |
407 m_cacheDocumentHasFrames.insert(m_documentName); | 407 cacheHasFrames = true; |
408 } | 408 } |
409 m_criticalSection.Unlock(); | 409 m_criticalSection.Unlock(); |
410 } | 410 } |
411 | 411 |
412 // Iterate through children of this element | 412 // Iterate through children of this element |
413 if (allElementsCount > 0) | 413 if (allElementsCount > 0) |
414 { | 414 { |
415 long childElementsCount = 0; | 415 long childElementsCount = 0; |
416 | 416 |
417 CComPtr<IDispatch> pChildCollectionDisp; | 417 CComPtr<IDispatch> pChildCollectionDisp; |
(...skipping 28 matching lines...) Expand all Loading... |
446 } | 446 } |
447 } | 447 } |
448 | 448 |
449 | 449 |
450 template <class T> | 450 template <class T> |
451 void CPluginDomTraverserBase<T>::ClearCache() | 451 void CPluginDomTraverserBase<T>::ClearCache() |
452 { | 452 { |
453 m_criticalSection.Lock(); | 453 m_criticalSection.Lock(); |
454 { | 454 { |
455 m_cacheIndexLast = 0; | 455 m_cacheIndexLast = 0; |
456 m_cacheDocumentHasFrames.clear(); | 456 cacheHasFrames = false; |
457 m_cacheDocumentHasIframes.clear(); | 457 cacheHasIframes = false; |
458 } | 458 } |
459 m_criticalSection.Unlock(); | 459 m_criticalSection.Unlock(); |
460 } | 460 } |
461 | 461 |
462 | 462 |
463 #endif // _PLUGIN_DOM_TRAVERSER_BASE_H_ | 463 #endif // _PLUGIN_DOM_TRAVERSER_BASE_H_ |
OLD | NEW |