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

Unified Diff: src/plugin/PluginDomTraverserBase.h

Issue 29334386: Issue #2230 - Refactor filter life cycle and use
Patch Set: rebase only Created May 17, 2016, 7:45 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/plugin/AdblockPlusDomTraverser.cpp ('k') | src/plugin/PluginFilter.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/plugin/PluginDomTraverserBase.h
===================================================================
--- a/src/plugin/PluginDomTraverserBase.h
+++ b/src/plugin/PluginDomTraverserBase.h
@@ -18,7 +18,7 @@
#ifndef _PLUGIN_DOM_TRAVERSER_BASE_H_
#define _PLUGIN_DOM_TRAVERSER_BASE_H_
-#include "PluginTabBase.h"
+#include "PluginFilter.h"
#include "PluginUtil.h"
class CPluginDomTraverserCacheBase
@@ -37,16 +37,12 @@
public:
- CPluginDomTraverserBase(CPluginTab* tab);
+ CPluginDomTraverserBase(CPluginFilter* filterSet);
~CPluginDomTraverserBase();
- void TraverseHeader(bool isHeaderTraversed);
-
- void TraverseDocument(IWebBrowser2* pBrowser, const std::wstring& domain, const std::wstring& documentUrl);
+ void TraverseDocumentRoot(IWebBrowser2* pBrowser, const std::wstring& domain, const std::wstring& documentUrl);
void TraverseSubdocument(IWebBrowser2* pBrowser, const std::wstring& domain, const std::wstring& documentUrl);
- virtual void ClearCache();
-
protected:
virtual bool OnIFrame(IHTMLElement* pEl, const std::wstring& url, const std::wstring& indent) { return true; }
@@ -56,7 +52,7 @@
protected:
- void TraverseDocument(IWebBrowser2* pBrowser, bool isMainDoc, const std::wstring& indent);
+ void TraverseDocument(IWebBrowser2* pBrowser, const std::wstring& indent);
void TraverseChild(IHTMLElement* pEl, IWebBrowser2* pBrowser, const std::wstring& indent, bool isCached=true);
CComAutoCriticalSection m_criticalSection;
@@ -64,11 +60,7 @@
std::wstring m_domain;
std::wstring m_documentUrl;
- bool m_isHeaderTraversed;
-
// Caching
- long m_cacheDomElementCount;
-
int m_cacheIndexLast;
int m_cacheElementsMax;
std::set<std::wstring> m_cacheDocumentHasFrames;
@@ -76,13 +68,12 @@
T* m_cacheElements;
- CPluginTab* m_tab;
- CComPtr<IWebBrowser2> m_pBrowser;
+ CPluginFilter* filterSet;
};
template <class T>
-CPluginDomTraverserBase<T>::CPluginDomTraverserBase(CPluginTab* tab) :
- m_tab(tab), m_isHeaderTraversed(false), m_cacheDomElementCount(0), m_cacheIndexLast(0), m_cacheElementsMax(5000)
+CPluginDomTraverserBase<T>::CPluginDomTraverserBase(CPluginFilter* filterSet) :
+ filterSet(filterSet), m_cacheIndexLast(0), m_cacheElementsMax(5000)
{
m_cacheElements = new T[m_cacheElementsMax];
}
@@ -95,26 +86,11 @@
}
template <class T>
-void CPluginDomTraverserBase<T>::TraverseHeader(bool isHeaderTraversed)
-{
- m_isHeaderTraversed = isHeaderTraversed;
-}
-
-template <class T>
-void CPluginDomTraverserBase<T>::TraverseDocument(IWebBrowser2* pBrowser, const std::wstring& domain, const std::wstring& documentUrl)
+void CPluginDomTraverserBase<T>::TraverseDocumentRoot(IWebBrowser2* pBrowser, const std::wstring& domain, const std::wstring& documentUrl)
{
m_domain = domain;
m_documentUrl = documentUrl;
- TraverseDocument(pBrowser, true, L"");
-}
-
-
-template <class T>
-void CPluginDomTraverserBase<T>::TraverseSubdocument(IWebBrowser2* pBrowser, const std::wstring& domain, const std::wstring& documentUrl)
-{
- m_domain = domain;
- m_documentUrl = documentUrl;
- TraverseDocument(pBrowser, false, L"");
+ TraverseDocument(pBrowser, L"");
}
@@ -126,9 +102,9 @@
template <class T>
-void CPluginDomTraverserBase<T>::TraverseDocument(IWebBrowser2* pBrowser, bool isMainDoc, const std::wstring& indent)
+void CPluginDomTraverserBase<T>::TraverseDocument(IWebBrowser2* pBrowser, const std::wstring& indent)
{
- DWORD res = WaitForSingleObject(m_tab->m_filter.hideFiltersLoadedEvent, ENGINE_STARTUP_TIMEOUT);
+ DWORD res = WaitForSingleObject(filterSet->hideFiltersLoadedEvent, ENGINE_STARTUP_TIMEOUT);
if (!IsEnabled()) return;
VARIANT_BOOL isBusy;
@@ -161,41 +137,22 @@
}
CComPtr<IHTMLElement> pBodyEl;
-
- if (m_isHeaderTraversed)
+ CComPtr<IHTMLElementCollection> pBodyCollection;
+ if (FAILED(pDoc->getElementsByTagName(ATL::CComBSTR(L"body"), &pBodyCollection)) || !pBodyCollection)
{
- pBodyEl = pBody;
- }
- else
- {
- CComPtr<IHTMLElementCollection> pBodyCollection;
- if (FAILED(pDoc->getElementsByTagName(ATL::CComBSTR(L"body"), &pBodyCollection)) || !pBodyCollection)
- {
- return;
- }
-
- CComVariant vIndex(0);
- CComPtr<IDispatch> pBodyDispatch;
- if (FAILED(pBodyCollection->item(vIndex, vIndex, &pBodyDispatch)) || !pBodyDispatch)
- {
- return;
- }
-
- if (FAILED(pBodyDispatch->QueryInterface(&pBodyEl)) || !pBodyEl)
- {
- return;
- }
+ return;
}
- // Clear cache (if eg. refreshing) ???
- if (isMainDoc)
+ CComVariant vIndex(0);
+ CComPtr<IDispatch> pBodyDispatch;
+ if (FAILED(pBodyCollection->item(vIndex, vIndex, &pBodyDispatch)) || !pBodyDispatch)
{
- CComVariant vCacheIndex;
+ return;
+ }
- if (FAILED(pBodyEl->getAttribute(ATL::CComBSTR(L"abp"), 0, &vCacheIndex)) || vCacheIndex.vt == VT_NULL)
- {
- ClearCache();
- }
+ if (FAILED(pBodyDispatch->QueryInterface(&pBodyEl)) || !pBodyEl)
+ {
+ return;
}
// Hide elements in body part
@@ -243,7 +200,7 @@
}
if (!src.empty())
{
- TraverseDocument(pFrameBrowser, false, indent);
+ TraverseDocument(pFrameBrowser, indent);
}
}
}
@@ -297,7 +254,7 @@
CComQIPtr<IWebBrowser2> pFrameBrowser = pFrameDispatch;
if (pFrameBrowser)
{
- TraverseDocument(pFrameBrowser, false, indent);
+ TraverseDocument(pFrameBrowser, indent);
}
}
}
@@ -449,17 +406,4 @@
}
-template <class T>
-void CPluginDomTraverserBase<T>::ClearCache()
-{
- m_criticalSection.Lock();
- {
- m_cacheIndexLast = 0;
- m_cacheDocumentHasFrames.clear();
- m_cacheDocumentHasIframes.clear();
- }
- m_criticalSection.Unlock();
-}
-
-
#endif // _PLUGIN_DOM_TRAVERSER_BASE_H_
« no previous file with comments | « src/plugin/AdblockPlusDomTraverser.cpp ('k') | src/plugin/PluginFilter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld