| Index: src/plugin/PluginDomTraverserBase.h |
| =================================================================== |
| --- a/src/plugin/PluginDomTraverserBase.h |
| +++ b/src/plugin/PluginDomTraverserBase.h |
| @@ -1,10 +1,10 @@ |
| #ifndef _PLUGIN_DOM_TRAVERSER_BASE_H_ |
| #define _PLUGIN_DOM_TRAVERSER_BASE_H_ |
| - |
| #include "PluginTypedef.h" |
| #include "PluginTab.h" |
| - |
| +#include "COM_Client.h" |
| +#include "Wrapper.h" |
| class CPluginDomTraverserCacheBase |
| { |
| @@ -27,8 +27,8 @@ |
| void TraverseHeader(bool isHeaderTraversed); |
| - void TraverseDocument(IWebBrowser2* pBrowser, const CString& domain, const CString& documentName); |
| - void TraverseSubdocument(IWebBrowser2* pBrowser, const CString& domain, const CString& documentName); |
| + void TraverseDocument(IWebBrowser2* pBrowser, const std::wstring & domain, const std::wstring & documentName); |
| + void TraverseSubdocument(IWebBrowser2* pBrowser, const std::wstring & domain, const std::wstring & documentName); |
| virtual void ClearCache(); |
| @@ -36,20 +36,20 @@ |
| protected: |
| - virtual bool OnIFrame(IHTMLElement* pEl, const CString& url, CString& indent) { return true; } |
| - virtual bool OnElement(IHTMLElement* pEl, const CString& tag, T* cache, bool isDebug, CString& indent) { return true; } |
| + virtual bool OnIFrame(IHTMLElement* pEl, const std::wstring & url, std::wstring & indent) { return true; } |
| + virtual bool OnElement(IHTMLElement* pEl, const std::wstring & tag, T* cache, bool isDebug, std::wstring & indent) { return true; } |
| virtual bool IsEnabled(); |
| protected: |
| - void TraverseDocument(IWebBrowser2* pBrowser, bool isMainDoc, CString indent); |
| - void TraverseChild(IHTMLElement* pEl, IWebBrowser2* pBrowser, CString& indent, bool isCached=true); |
| + void TraverseDocument(IWebBrowser2* pBrowser, bool isMainDoc, std::wstring indent); |
| + void TraverseChild(IHTMLElement* pEl, IWebBrowser2* pBrowser, std::wstring & indent, bool isCached=true); |
| CComAutoCriticalSection m_criticalSection; |
| - CString m_domain; |
| - CString m_documentName; |
| + std::wstring m_domain; |
| + std::wstring m_documentName; |
| bool m_isHeaderTraversed; |
| @@ -58,8 +58,8 @@ |
| int m_cacheIndexLast; |
| int m_cacheElementsMax; |
| - std::set<CString> m_cacheDocumentHasFrames; |
| - std::set<CString> m_cacheDocumentHasIframes; |
| + std::set< std::wstring > m_cacheDocumentHasFrames; |
| + std::set< std::wstring > m_cacheDocumentHasIframes; |
| T* m_cacheElements; |
| @@ -88,20 +88,20 @@ |
| } |
| template <class T> |
| -void CPluginDomTraverserBase<T>::TraverseDocument(IWebBrowser2* pBrowser, const CString& domain, const CString& documentName) |
| +void CPluginDomTraverserBase<T>::TraverseDocument(IWebBrowser2* pBrowser, const std::wstring & domain, const std::wstring & documentName) |
| { |
| m_domain = domain; |
| - TraverseDocument(pBrowser, true, ""); |
| + TraverseDocument(pBrowser, true, L""); |
| } |
| template <class T> |
| -void CPluginDomTraverserBase<T>::TraverseSubdocument(IWebBrowser2* pBrowser, const CString& domain, const CString& documentName) |
| +void CPluginDomTraverserBase<T>::TraverseSubdocument(IWebBrowser2* pBrowser, const std::wstring & domain, const std::wstring & documentName) |
| { |
| m_domain = domain; |
| - TraverseDocument(pBrowser, false, ""); |
| + TraverseDocument(pBrowser, false, L""); |
| } |
| @@ -113,7 +113,7 @@ |
| template <class T> |
| -void CPluginDomTraverserBase<T>::TraverseDocument(IWebBrowser2* pBrowser, bool isMainDoc, CString indent) |
| +void CPluginDomTraverserBase<T>::TraverseDocument(IWebBrowser2* pBrowser, bool isMainDoc, std::wstring indent) |
| { |
| DWORD res = WaitForSingleObject(m_tab->m_filter->hideFiltersLoadedEvent, ENGINE_STARTUP_TIMEOUT); |
| if (!IsEnabled()) return; |
| @@ -160,10 +160,9 @@ |
| { |
| return; |
| } |
| - |
| - CComVariant vIndex(0); |
| - CComPtr<IDispatch> pBodyDispatch; |
| - if (FAILED(pBodyCollection->item(vIndex, vIndex, &pBodyDispatch)) || !pBodyDispatch) |
| + Wrapper::HTML_Element_Collection body_elements( pBodyCollection ); |
| + CComPtr<IDispatch> pBodyDispatch = body_elements.at( 0 ); |
| + if ( !pBodyDispatch ) |
| { |
| return; |
| } |
| @@ -177,9 +176,9 @@ |
| // Clear cache (if eg. refreshing) ??? |
| if (isMainDoc) |
| { |
| - CComVariant vCacheIndex; |
| - |
| - if (FAILED(pBodyEl->getAttribute(L"abp", 0, &vCacheIndex)) || vCacheIndex.vt == VT_NULL) |
| + Wrapper::HTML_Element body_element( pBodyEl ); |
| + std::wstring cache_attr; |
| + if ( !body_element.attribute( L"abp", cache_attr ) || cache_attr.empty() ) |
| { |
| ClearCache(); |
| } |
| @@ -209,29 +208,25 @@ |
| { |
| pFrameCollection->get_length(&frameCount); |
| } |
| + Wrapper::HTML_Element_Collection frames( pFrameCollection ); |
| // Iterate through all frames |
| for (long i = 0; i < frameCount; i++) |
| { |
| - CComVariant vIndex(i); |
| - CComVariant vRetIndex; |
| - CComPtr<IDispatch> pFrameDispatch; |
| - |
| - if (SUCCEEDED(pFrameCollection->item(vIndex, vRetIndex, &pFrameDispatch)) && pFrameDispatch) |
| + CComPtr<IDispatch> pFrameDispatch = frames.at( i ); |
| + if ( pFrameDispatch ) |
| { |
| CComQIPtr<IWebBrowser2> pFrameBrowser = pFrameDispatch; |
| if (pFrameBrowser) |
| { |
| - CComBSTR bstrSrc; |
| - CString src; |
| - |
| - if (SUCCEEDED(pFrameBrowser->get_LocationURL(&bstrSrc))) |
| + Wrapper::Browser frame_browser( pFrameBrowser ); |
| + std::wstring src; |
| + if ( frame_browser.Location_URL( src ) ) |
| { |
| - src = bstrSrc; |
| - CPluginClient::UnescapeUrl(src); |
| + Wrapper::Unescape_URL( src ); |
| } |
| - if (!src.IsEmpty()) |
| + if (!src.empty()) |
| { |
| TraverseDocument(pFrameBrowser, false, indent); |
| } |
| @@ -251,37 +246,32 @@ |
| } |
| // Iterate through all iframes |
| + Wrapper::HTML_Element_Collection frames( pFrameCollection ); |
| for (long i = 0; i < frameCount; i++) |
| { |
| - CComVariant vIndex(i); |
| - CComVariant vRetIndex; |
| - CComPtr<IDispatch> pFrameDispatch; |
| - |
| - if (SUCCEEDED(pFrameCollection->item(vIndex, vRetIndex, &pFrameDispatch)) && pFrameDispatch) |
| + CComPtr<IDispatch> pFrameDispatch = frames.at( i ); |
| + if ( pFrameDispatch ) |
| { |
| CComQIPtr<IHTMLElement> pFrameEl = pFrameDispatch; |
| if (pFrameEl) |
| { |
| - CComVariant vAttr; |
| + Wrapper::HTML_Element element( pFrameEl ); |
| + std::wstring src; |
| + if ( element.attribute( L"src", src ) && !src.empty() ) |
| + { |
| + // Some times, domain is missing. Should this be added on image src's as well?'' |
| + // eg. gadgetzone.com.au |
| - if (SUCCEEDED(pFrameEl->getAttribute(L"src", 0, &vAttr)) && vAttr.vt == VT_BSTR && ::SysStringLen(vAttr.bstrVal) > 0) |
| - { |
| - CString src = vAttr.bstrVal; |
| - |
| - // Some times, domain is missing. Should this be added on image src's as well?'' |
| - |
| - // eg. gadgetzone.com.au |
| - if (src.Left(2) == L"//") |
| + if ( ABP::util::begins_with( src, L"//" ) ) |
| { |
| src = L"http:" + src; |
| } |
| // eg. http://w3schools.com/html/html_examples.asp |
| - else if (src.Left(4) != L"http" && src.Left(6) != L"res://") |
| + else if ( !ABP::util::begins_with( src, L"http" ) && !ABP::util::begins_with( src, L"res://" ) ) |
| { |
| src = L"http://" + m_domain + src; |
| } |
| - |
| - CPluginClient::UnescapeUrl(src); |
| + Wrapper::Unescape_URL( src ); |
| // Check if Iframe should be traversed |
| if (OnIFrame(pFrameEl, src, indent)) |
| @@ -301,18 +291,16 @@ |
| template <class T> |
| -void CPluginDomTraverserBase<T>::TraverseChild(IHTMLElement* pEl, IWebBrowser2* pBrowser, CString& indent, bool isCached) |
| +void CPluginDomTraverserBase<T>::TraverseChild(IHTMLElement* pEl, IWebBrowser2* pBrowser, std::wstring & indent, bool isCached) |
| { |
| int cacheIndex = -1; |
| long cacheAllElementsCount = -1; |
| + Wrapper::HTML_Element element( pEl ); |
| m_criticalSection.Lock(); |
| { |
| - CComVariant vCacheIndex; |
| - if (isCached && SUCCEEDED(pEl->getAttribute(L"abp", 0, &vCacheIndex)) && vCacheIndex.vt == VT_I4) |
| + if ( isCached && element.attribute( L"abp", cacheIndex ) ) |
| { |
| - cacheIndex = vCacheIndex.intVal; |
| - |
| cacheAllElementsCount = m_cacheElements[cacheIndex].m_elements; |
| } |
| else |
| @@ -337,6 +325,7 @@ |
| m_cacheElements[cacheIndex].Init(); |
| + VARIANT vCacheIndex; |
| vCacheIndex.vt = VT_I4; |
| vCacheIndex.intVal = cacheIndex; |
| @@ -372,14 +361,12 @@ |
| m_criticalSection.Unlock(); |
| // Get tag |
| - CComBSTR bstrTag; |
| - if (FAILED(pEl->get_tagName(&bstrTag)) || !bstrTag) |
| + std::wstring tag; |
| + if ( ! element.tag_name( tag ) || tag.empty() ) |
| { |
| return; |
| } |
| - |
| - CString tag = bstrTag; |
| - tag.MakeLower(); |
| + ABP::util::to_lower( tag ); |
| // Custom OnElement |
| if (!OnElement(pEl, tag, &m_cacheElements[cacheIndex], false, indent)) |
| @@ -388,7 +375,7 @@ |
| } |
| // Update frame/iframe cache |
| - if (tag == "iframe") |
| + if (tag == L"iframe") |
| { |
| m_criticalSection.Lock(); |
| { |
| @@ -396,7 +383,7 @@ |
| } |
| m_criticalSection.Unlock(); |
| } |
| - else if (tag == "frame") |
| + else if (tag == L"frame") |
| { |
| m_criticalSection.Lock(); |
| { |
| @@ -416,24 +403,20 @@ |
| CComPtr<IHTMLElementCollection> pChildCollection; |
| if (SUCCEEDED(pChildCollectionDisp->QueryInterface(IID_IHTMLElementCollection, (LPVOID*)&pChildCollection)) && pChildCollection) |
| { |
| + Wrapper::HTML_Element_Collection child_elements( pChildCollection ); |
| pChildCollection->get_length(&childElementsCount); |
| - CComVariant vIndex(0); |
| - |
| // Iterate through all children |
| for (long i = 0; i < childElementsCount; i++) |
| { |
| CComPtr<IDispatch> pChildElDispatch; |
| - CComVariant vRetIndex; |
| - |
| - vIndex.intVal = i; |
| - |
| - if (SUCCEEDED(pChildCollection->item(vIndex, vRetIndex, &pChildElDispatch)) && pChildElDispatch) |
| + pChildElDispatch = child_elements.at( i ); |
| + if ( pChildElDispatch ) |
| { |
| CComPtr<IHTMLElement> pChildEl; |
| if (SUCCEEDED(pChildElDispatch->QueryInterface(IID_IHTMLElement, (LPVOID*)&pChildEl)) && pChildEl) |
| { |
| - TraverseChild(pChildEl, pBrowser, indent + " ", isCached); |
| + TraverseChild(pChildEl, pBrowser, indent + L" ", isCached); |
| } |
| } |
| } |