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

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

Issue 4912420225024000: Issue #1234 - Convert strings associated with URL's (Closed)
Patch Set: Rebased Created Oct. 21, 2014, 6:26 p.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 #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
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
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 CComBSTR bstrSrc; 223 BSTR bstrSrc;
224 CString src; 224 std::wstring src;
225
226 if (SUCCEEDED(pFrameBrowser->get_LocationURL(&bstrSrc))) 225 if (SUCCEEDED(pFrameBrowser->get_LocationURL(&bstrSrc)))
227 { 226 {
228 src = bstrSrc; 227 src = std::wstring(bstrSrc,SysStringLen(bstrSrc));
229 CPluginClient::UnescapeUrl(src); 228 SysFreeString(bstrSrc);
229 UnescapeUrl(src);
230 } 230 }
231 231 if (!src.empty())
232 if (!src.IsEmpty())
233 { 232 {
234 TraverseDocument(pFrameBrowser, false, indent); 233 TraverseDocument(pFrameBrowser, false, indent);
235 } 234 }
236 } 235 }
237 } 236 }
238 } 237 }
239 } 238 }
240 239
241 // Iframes 240 // Iframes
242 if (hasIframes) 241 if (hasIframes)
(...skipping 14 matching lines...) Expand all
257 256
258 if (SUCCEEDED(pFrameCollection->item(vIndex, vRetIndex, &pFrameDispatch)) && pFrameDispatch) 257 if (SUCCEEDED(pFrameCollection->item(vIndex, vRetIndex, &pFrameDispatch)) && pFrameDispatch)
259 { 258 {
260 CComQIPtr<IHTMLElement> pFrameEl = pFrameDispatch; 259 CComQIPtr<IHTMLElement> pFrameEl = pFrameDispatch;
261 if (pFrameEl) 260 if (pFrameEl)
262 { 261 {
263 CComVariant vAttr; 262 CComVariant vAttr;
264 263
265 if (SUCCEEDED(pFrameEl->getAttribute(L"src", 0, &vAttr)) && vAttr.vt = = VT_BSTR && ::SysStringLen(vAttr.bstrVal) > 0) 264 if (SUCCEEDED(pFrameEl->getAttribute(L"src", 0, &vAttr)) && vAttr.vt = = VT_BSTR && ::SysStringLen(vAttr.bstrVal) > 0)
266 { 265 {
267 CString src = vAttr.bstrVal; 266 CString srcLegacy = vAttr.bstrVal;
268 267
269 // Some times, domain is missing. Should this be added on image src' s as well?'' 268 // Some times, domain is missing. Should this be added on image src' s as well?''
270 269
271 // eg. gadgetzone.com.au 270 // eg. gadgetzone.com.au
272 if (src.Left(2) == L"//") 271 if (srcLegacy.Left(2) == L"//")
273 { 272 {
274 src = L"http:" + src; 273 srcLegacy = L"http:" + srcLegacy;
275 } 274 }
276 // eg. http://w3schools.com/html/html_examples.asp 275 // eg. http://w3schools.com/html/html_examples.asp
277 else if (src.Left(4) != L"http" && src.Left(6) != L"res://") 276 else if (srcLegacy.Left(4) != L"http" && srcLegacy.Left(6) != L"res: //")
278 { 277 {
279 src = L"http://" + to_CString(m_domain) + src; 278 srcLegacy = L"http://" + to_CString(m_domain) + srcLegacy;
280 } 279 }
281 280 std::wstring src(ToWstring(srcLegacy));
282 CPluginClient::UnescapeUrl(src); 281 UnescapeUrl(src);
283 282
284 // Check if Iframe should be traversed 283 // Check if Iframe should be traversed
285 if (OnIFrame(pFrameEl, src, indent)) 284 if (OnIFrame(pFrameEl, src, indent))
286 { 285 {
287 CComQIPtr<IWebBrowser2> pFrameBrowser = pFrameDispatch; 286 CComQIPtr<IWebBrowser2> pFrameBrowser = pFrameDispatch;
288 if (pFrameBrowser) 287 if (pFrameBrowser)
289 { 288 {
290 TraverseDocument(pFrameBrowser, false, indent); 289 TraverseDocument(pFrameBrowser, false, indent);
291 } 290 }
292 } 291 }
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 { 447 {
449 m_cacheIndexLast = 0; 448 m_cacheIndexLast = 0;
450 m_cacheDocumentHasFrames.clear(); 449 m_cacheDocumentHasFrames.clear();
451 m_cacheDocumentHasIframes.clear(); 450 m_cacheDocumentHasIframes.clear();
452 } 451 }
453 m_criticalSection.Unlock(); 452 m_criticalSection.Unlock();
454 } 453 }
455 454
456 455
457 #endif // _PLUGIN_DOM_TRAVERSER_BASE_H_ 456 #endif // _PLUGIN_DOM_TRAVERSER_BASE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld