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

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

Issue 29332057: Issue #1234 - Replace CString in the traverser (Closed)
Patch Set: rebase Created Dec. 14, 2015, 11:56 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 25 matching lines...) Expand all
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& documentName);
46 void TraverseSubdocument(IWebBrowser2* pBrowser, const std::wstring& domain, c onst CString& documentName); 46 void TraverseSubdocument(IWebBrowser2* pBrowser, const std::wstring& domain);
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 CString m_documentName; 65 std::wstring m_documentName;
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)
(...skipping 12 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& documentName) 104 void CPluginDomTraverserBase<T>::TraverseDocument(IWebBrowser2* pBrowser, const std::wstring& domain, const std::wstring& documentName)
105 { 105 {
106 m_domain = domain; 106 m_domain = domain;
107 107
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 CString& documentName) 113 void CPluginDomTraverserBase<T>::TraverseSubdocument(IWebBrowser2* pBrowser, con st std::wstring& domain)
Oleksandr 2015/12/14 12:49:07 We still need this parameter. I would be better of
114 { 114 {
115 m_domain = domain; 115 m_domain = domain;
116 116
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 159 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
310 template <class T> 309 template <class T>
311 void CPluginDomTraverserBase<T>::TraverseChild(IHTMLElement* pEl, IWebBrowser2* pBrowser, CString& indent, bool isCached) 310 void CPluginDomTraverserBase<T>::TraverseChild(IHTMLElement* pEl, IWebBrowser2* pBrowser, const std::wstring& 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
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_documentName); 399 m_cacheDocumentHasIframes.insert(m_documentName);
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_documentName); 407 m_cacheDocumentHasFrames.insert(m_documentName);
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)
(...skipping 16 matching lines...) Expand all
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(&pChildEl)) && pChild El) 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_
OLDNEW

Powered by Google App Engine
This is Rietveld