Left: | ||
Right: |
OLD | NEW |
---|---|
1 #ifndef _PLUGIN_DOM_TRAVERSER_BASE_H_ | 1 #ifndef _PLUGIN_DOM_TRAVERSER_BASE_H_ |
2 #define _PLUGIN_DOM_TRAVERSER_BASE_H_ | 2 #define _PLUGIN_DOM_TRAVERSER_BASE_H_ |
3 | 3 |
4 | 4 |
5 #include "PluginTypedef.h" | 5 #include "PluginTypedef.h" |
6 #include "PluginTab.h" | 6 #include "PluginTab.h" |
7 | 7 |
8 | 8 |
9 class CPluginDomTraverserCacheBase | 9 class CPluginDomTraverserCacheBase |
10 { | 10 { |
11 public: | 11 public: |
12 | 12 |
13 long m_elements; | 13 long m_elements; |
14 | 14 |
15 CPluginDomTraverserCacheBase() : m_elements(0) {}; | 15 CPluginDomTraverserCacheBase() : m_elements(0) {}; |
16 void Init() { m_elements=0; } | 16 void Init() { m_elements=0; } |
17 }; | 17 }; |
18 | 18 |
19 template <class T> | 19 template <class T> |
20 class CPluginDomTraverserBase | 20 class CPluginDomTraverserBase |
21 { | 21 { |
22 | 22 |
23 public: | 23 public: |
24 | 24 |
25 CPluginDomTraverserBase(CPluginTab* tab); | 25 CPluginDomTraverserBase(CPluginTab* tab); |
26 ~CPluginDomTraverserBase(); | 26 ~CPluginDomTraverserBase(); |
27 | 27 |
28 void TraverseHeader(bool isHeaderTraversed); | 28 void TraverseHeader(bool isHeaderTraversed); |
29 | 29 |
30 void TraverseDocument(IWebBrowser2* pBrowser, const std::wstring& domain, cons t CString& documentName); | 30 void TraverseDocument(IWebBrowser2* pBrowser, const std::wstring& domain, cons t std::wstring& documentName); |
31 void TraverseSubdocument(IWebBrowser2* pBrowser, const std::wstring& domain, c onst CString& documentName); | 31 void TraverseSubdocument(IWebBrowser2* pBrowser, const std::wstring& domain, c onst CString& documentName); |
32 | 32 |
33 virtual void ClearCache(); | 33 virtual void ClearCache(); |
34 | 34 |
35 protected: | 35 protected: |
36 | 36 |
37 virtual bool OnIFrame(IHTMLElement* pEl, const CString& url, CString& indent) { return true; } | 37 virtual bool OnIFrame(IHTMLElement* pEl, const std::wstring& url, CString& ind ent) { return true; } |
38 virtual bool OnElement(IHTMLElement* pEl, const CString& tag, T* cache, bool i sDebug, CString& indent) { return true; } | 38 virtual bool OnElement(IHTMLElement* pEl, const CString& tag, T* cache, bool i sDebug, CString& indent) { return true; } |
39 | 39 |
40 virtual bool IsEnabled(); | 40 virtual bool IsEnabled(); |
41 | 41 |
42 protected: | 42 protected: |
43 | 43 |
44 void TraverseDocument(IWebBrowser2* pBrowser, bool isMainDoc, CString indent); | 44 void TraverseDocument(IWebBrowser2* pBrowser, bool isMainDoc, CString indent); |
45 void TraverseChild(IHTMLElement* pEl, IWebBrowser2* pBrowser, CString& indent, bool isCached=true); | 45 void TraverseChild(IHTMLElement* pEl, IWebBrowser2* pBrowser, CString& indent, bool isCached=true); |
46 | 46 |
47 CComAutoCriticalSection m_criticalSection; | 47 CComAutoCriticalSection m_criticalSection; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
79 delete [] m_cacheElements; | 79 delete [] m_cacheElements; |
80 } | 80 } |
81 | 81 |
82 template <class T> | 82 template <class T> |
83 void CPluginDomTraverserBase<T>::TraverseHeader(bool isHeaderTraversed) | 83 void CPluginDomTraverserBase<T>::TraverseHeader(bool isHeaderTraversed) |
84 { | 84 { |
85 m_isHeaderTraversed = isHeaderTraversed; | 85 m_isHeaderTraversed = isHeaderTraversed; |
86 } | 86 } |
87 | 87 |
88 template <class T> | 88 template <class T> |
89 void CPluginDomTraverserBase<T>::TraverseDocument(IWebBrowser2* pBrowser, const std::wstring& domain, const CString& documentName) | 89 void CPluginDomTraverserBase<T>::TraverseDocument(IWebBrowser2* pBrowser, const std::wstring& domain, const std::wstring& documentName) |
90 { | 90 { |
91 m_domain = domain; | 91 m_domain = domain; |
92 | 92 |
93 TraverseDocument(pBrowser, true, ""); | 93 TraverseDocument(pBrowser, true, ""); |
94 } | 94 } |
95 | 95 |
96 | 96 |
97 template <class T> | 97 template <class T> |
98 void CPluginDomTraverserBase<T>::TraverseSubdocument(IWebBrowser2* pBrowser, con st std::wstring& domain, const CString& documentName) | 98 void CPluginDomTraverserBase<T>::TraverseSubdocument(IWebBrowser2* pBrowser, con st std::wstring& domain, const CString& documentName) |
99 { | 99 { |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
213 { | 213 { |
214 CComVariant vIndex(i); | 214 CComVariant vIndex(i); |
215 CComVariant vRetIndex; | 215 CComVariant vRetIndex; |
216 CComPtr<IDispatch> pFrameDispatch; | 216 CComPtr<IDispatch> pFrameDispatch; |
217 | 217 |
218 if (SUCCEEDED(pFrameCollection->item(vIndex, vRetIndex, &pFrameDispatch)) && pFrameDispatch) | 218 if (SUCCEEDED(pFrameCollection->item(vIndex, vRetIndex, &pFrameDispatch)) && pFrameDispatch) |
219 { | 219 { |
220 CComQIPtr<IWebBrowser2> pFrameBrowser = pFrameDispatch; | 220 CComQIPtr<IWebBrowser2> pFrameBrowser = pFrameDispatch; |
221 if (pFrameBrowser) | 221 if (pFrameBrowser) |
222 { | 222 { |
223 std::wstring src; | |
223 CComBSTR bstrSrc; | 224 CComBSTR bstrSrc; |
224 CString src; | 225 if (SUCCEEDED(pFrameBrowser->get_LocationURL(&bstrSrc)) && bstrSrc) |
225 | |
226 if (SUCCEEDED(pFrameBrowser->get_LocationURL(&bstrSrc))) | |
227 { | 226 { |
228 src = bstrSrc; | 227 src = std::wstring(bstrSrc,SysStringLen(bstrSrc)); |
229 CPluginClient::UnescapeUrl(src); | 228 UnescapeUrl(src); |
230 } | 229 } |
231 | 230 if (!src.empty()) |
232 if (!src.IsEmpty()) | |
233 { | 231 { |
234 TraverseDocument(pFrameBrowser, false, indent); | 232 TraverseDocument(pFrameBrowser, false, indent); |
235 } | 233 } |
236 } | 234 } |
237 } | 235 } |
238 } | 236 } |
239 } | 237 } |
240 | 238 |
241 // Iframes | 239 // Iframes |
242 if (hasIframes) | 240 if (hasIframes) |
(...skipping 14 matching lines...) Expand all Loading... | |
257 | 255 |
258 if (SUCCEEDED(pFrameCollection->item(vIndex, vRetIndex, &pFrameDispatch)) && pFrameDispatch) | 256 if (SUCCEEDED(pFrameCollection->item(vIndex, vRetIndex, &pFrameDispatch)) && pFrameDispatch) |
259 { | 257 { |
260 CComQIPtr<IHTMLElement> pFrameEl = pFrameDispatch; | 258 CComQIPtr<IHTMLElement> pFrameEl = pFrameDispatch; |
261 if (pFrameEl) | 259 if (pFrameEl) |
262 { | 260 { |
263 CComVariant vAttr; | 261 CComVariant vAttr; |
264 | 262 |
265 if (SUCCEEDED(pFrameEl->getAttribute(L"src", 0, &vAttr)) && vAttr.vt = = VT_BSTR && ::SysStringLen(vAttr.bstrVal) > 0) | 263 if (SUCCEEDED(pFrameEl->getAttribute(L"src", 0, &vAttr)) && vAttr.vt = = VT_BSTR && ::SysStringLen(vAttr.bstrVal) > 0) |
266 { | 264 { |
267 CString src = vAttr.bstrVal; | 265 CString srcLegacy = vAttr.bstrVal; |
268 | 266 |
269 // Some times, domain is missing. Should this be added on image src' s as well?'' | 267 // Some times, domain is missing. Should this be added on image src' s as well?'' |
270 | 268 |
271 // eg. gadgetzone.com.au | 269 // eg. gadgetzone.com.au |
272 if (src.Left(2) == L"//") | 270 if (srcLegacy.Left(2) == L"//") |
273 { | 271 { |
274 src = L"http:" + src; | 272 srcLegacy = L"http:" + srcLegacy; |
275 } | 273 } |
276 // eg. http://w3schools.com/html/html_examples.asp | 274 // eg. http://w3schools.com/html/html_examples.asp |
277 else if (src.Left(4) != L"http" && src.Left(6) != L"res://") | 275 else if (srcLegacy.Left(4) != L"http" && srcLegacy.Left(6) != L"res: //") |
278 { | 276 { |
279 src = L"http://" + to_CString(m_domain) + src; | 277 srcLegacy = L"http://" + to_CString(m_domain) + srcLegacy; |
sergei
2015/01/06 13:18:18
should ToCString be instead of to_CString here?
Eric
2015/01/06 19:38:59
It's time to do a wholesale replacement, which was
Oleksandr
2015/01/13 10:08:06
Would be great to not commit to_CString anyway tho
| |
280 } | 278 } |
281 | 279 std::wstring src(ToWstring(srcLegacy)); |
282 CPluginClient::UnescapeUrl(src); | 280 UnescapeUrl(src); |
283 | 281 |
284 // Check if Iframe should be traversed | 282 // Check if Iframe should be traversed |
285 if (OnIFrame(pFrameEl, src, indent)) | 283 if (OnIFrame(pFrameEl, src, indent)) |
286 { | 284 { |
287 CComQIPtr<IWebBrowser2> pFrameBrowser = pFrameDispatch; | 285 CComQIPtr<IWebBrowser2> pFrameBrowser = pFrameDispatch; |
288 if (pFrameBrowser) | 286 if (pFrameBrowser) |
289 { | 287 { |
290 TraverseDocument(pFrameBrowser, false, indent); | 288 TraverseDocument(pFrameBrowser, false, indent); |
291 } | 289 } |
292 } | 290 } |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
448 { | 446 { |
449 m_cacheIndexLast = 0; | 447 m_cacheIndexLast = 0; |
450 m_cacheDocumentHasFrames.clear(); | 448 m_cacheDocumentHasFrames.clear(); |
451 m_cacheDocumentHasIframes.clear(); | 449 m_cacheDocumentHasIframes.clear(); |
452 } | 450 } |
453 m_criticalSection.Unlock(); | 451 m_criticalSection.Unlock(); |
454 } | 452 } |
455 | 453 |
456 | 454 |
457 #endif // _PLUGIN_DOM_TRAVERSER_BASE_H_ | 455 #endif // _PLUGIN_DOM_TRAVERSER_BASE_H_ |
OLD | NEW |