LEFT | RIGHT |
| 1 /* |
| 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
| 3 * Copyright (C) 2006-2015 Eyeo GmbH |
| 4 * |
| 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 |
| 7 * published by the Free Software Foundation. |
| 8 * |
| 9 * Adblock Plus is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. |
| 13 * |
| 14 * You should have received a copy of the GNU General Public License |
| 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| 16 */ |
| 17 |
1 #ifndef _PLUGIN_DOM_TRAVERSER_BASE_H_ | 18 #ifndef _PLUGIN_DOM_TRAVERSER_BASE_H_ |
2 #define _PLUGIN_DOM_TRAVERSER_BASE_H_ | 19 #define _PLUGIN_DOM_TRAVERSER_BASE_H_ |
3 | 20 |
4 | 21 |
5 #include "PluginTypedef.h" | 22 #include "PluginTypedef.h" |
6 #include "PluginTab.h" | 23 #include "PluginTab.h" |
7 | 24 |
8 | 25 |
9 class CPluginDomTraverserCacheBase | 26 class CPluginDomTraverserCacheBase |
10 { | 27 { |
11 public: | 28 public: |
12 | 29 |
13 long m_elements; | 30 long m_elements; |
14 | 31 |
15 CPluginDomTraverserCacheBase() : m_elements(0) {}; | 32 CPluginDomTraverserCacheBase() : m_elements(0) {}; |
16 void Init() { m_elements=0; } | 33 void Init() { m_elements=0; } |
17 }; | 34 }; |
18 | 35 |
19 template <class T> | 36 template <class T> |
20 class CPluginDomTraverserBase | 37 class CPluginDomTraverserBase |
21 { | 38 { |
22 | 39 |
23 public: | 40 public: |
24 | 41 |
25 CPluginDomTraverserBase(CPluginTab* tab); | 42 CPluginDomTraverserBase(CPluginTab* tab); |
26 ~CPluginDomTraverserBase(); | 43 ~CPluginDomTraverserBase(); |
27 | 44 |
28 void TraverseHeader(bool isHeaderTraversed); | 45 void TraverseHeader(bool isHeaderTraversed); |
29 | 46 |
30 void TraverseDocument(IWebBrowser2* pBrowser, const std::wstring& domain, cons
t CString& documentName); | 47 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); | 48 void TraverseSubdocument(IWebBrowser2* pBrowser, const std::wstring& domain, c
onst CString& documentName); |
32 | 49 |
33 virtual void ClearCache(); | 50 virtual void ClearCache(); |
34 | 51 |
35 protected: | 52 protected: |
36 | 53 |
37 virtual bool OnIFrame(IHTMLElement* pEl, const CString& url, CString& indent)
{ return true; } | 54 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; } | 55 virtual bool OnElement(IHTMLElement* pEl, const CString& tag, T* cache, bool i
sDebug, CString& indent) { return true; } |
39 | 56 |
40 virtual bool IsEnabled(); | 57 virtual bool IsEnabled(); |
41 | 58 |
42 protected: | 59 protected: |
43 | 60 |
44 void TraverseDocument(IWebBrowser2* pBrowser, bool isMainDoc, CString indent); | 61 void TraverseDocument(IWebBrowser2* pBrowser, bool isMainDoc, CString indent); |
45 void TraverseChild(IHTMLElement* pEl, IWebBrowser2* pBrowser, CString& indent,
bool isCached=true); | 62 void TraverseChild(IHTMLElement* pEl, IWebBrowser2* pBrowser, CString& indent,
bool isCached=true); |
46 | 63 |
47 CComAutoCriticalSection m_criticalSection; | 64 CComAutoCriticalSection m_criticalSection; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 delete [] m_cacheElements; | 96 delete [] m_cacheElements; |
80 } | 97 } |
81 | 98 |
82 template <class T> | 99 template <class T> |
83 void CPluginDomTraverserBase<T>::TraverseHeader(bool isHeaderTraversed) | 100 void CPluginDomTraverserBase<T>::TraverseHeader(bool isHeaderTraversed) |
84 { | 101 { |
85 m_isHeaderTraversed = isHeaderTraversed; | 102 m_isHeaderTraversed = isHeaderTraversed; |
86 } | 103 } |
87 | 104 |
88 template <class T> | 105 template <class T> |
89 void CPluginDomTraverserBase<T>::TraverseDocument(IWebBrowser2* pBrowser, const
std::wstring& domain, const CString& documentName) | 106 void CPluginDomTraverserBase<T>::TraverseDocument(IWebBrowser2* pBrowser, const
std::wstring& domain, const std::wstring& documentName) |
90 { | 107 { |
91 m_domain = domain; | 108 m_domain = domain; |
92 | 109 |
93 TraverseDocument(pBrowser, true, ""); | 110 TraverseDocument(pBrowser, true, ""); |
94 } | 111 } |
95 | 112 |
96 | 113 |
97 template <class T> | 114 template <class T> |
98 void CPluginDomTraverserBase<T>::TraverseSubdocument(IWebBrowser2* pBrowser, con
st std::wstring& domain, const CString& documentName) | 115 void CPluginDomTraverserBase<T>::TraverseSubdocument(IWebBrowser2* pBrowser, con
st std::wstring& domain, const CString& documentName) |
99 { | 116 { |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 { | 230 { |
214 CComVariant vIndex(i); | 231 CComVariant vIndex(i); |
215 CComVariant vRetIndex; | 232 CComVariant vRetIndex; |
216 CComPtr<IDispatch> pFrameDispatch; | 233 CComPtr<IDispatch> pFrameDispatch; |
217 | 234 |
218 if (SUCCEEDED(pFrameCollection->item(vIndex, vRetIndex, &pFrameDispatch))
&& pFrameDispatch) | 235 if (SUCCEEDED(pFrameCollection->item(vIndex, vRetIndex, &pFrameDispatch))
&& pFrameDispatch) |
219 { | 236 { |
220 CComQIPtr<IWebBrowser2> pFrameBrowser = pFrameDispatch; | 237 CComQIPtr<IWebBrowser2> pFrameBrowser = pFrameDispatch; |
221 if (pFrameBrowser) | 238 if (pFrameBrowser) |
222 { | 239 { |
| 240 std::wstring src; |
223 CComBSTR bstrSrc; | 241 CComBSTR bstrSrc; |
224 CString src; | 242 if (SUCCEEDED(pFrameBrowser->get_LocationURL(&bstrSrc)) && bstrSrc) |
225 | |
226 if (SUCCEEDED(pFrameBrowser->get_LocationURL(&bstrSrc))) | |
227 { | 243 { |
228 src = bstrSrc; | 244 src = std::wstring(bstrSrc,SysStringLen(bstrSrc)); |
229 CPluginClient::UnescapeUrl(src); | 245 UnescapeUrl(src); |
230 } | 246 } |
231 | 247 if (!src.empty()) |
232 if (!src.IsEmpty()) | |
233 { | 248 { |
234 TraverseDocument(pFrameBrowser, false, indent); | 249 TraverseDocument(pFrameBrowser, false, indent); |
235 } | 250 } |
236 } | 251 } |
237 } | 252 } |
238 } | 253 } |
239 } | 254 } |
240 | 255 |
241 // Iframes | 256 // Iframes |
242 if (hasIframes) | 257 if (hasIframes) |
(...skipping 14 matching lines...) Expand all Loading... |
257 | 272 |
258 if (SUCCEEDED(pFrameCollection->item(vIndex, vRetIndex, &pFrameDispatch))
&& pFrameDispatch) | 273 if (SUCCEEDED(pFrameCollection->item(vIndex, vRetIndex, &pFrameDispatch))
&& pFrameDispatch) |
259 { | 274 { |
260 CComQIPtr<IHTMLElement> pFrameEl = pFrameDispatch; | 275 CComQIPtr<IHTMLElement> pFrameEl = pFrameDispatch; |
261 if (pFrameEl) | 276 if (pFrameEl) |
262 { | 277 { |
263 CComVariant vAttr; | 278 CComVariant vAttr; |
264 | 279 |
265 if (SUCCEEDED(pFrameEl->getAttribute(ATL::CComBSTR(L"scr"), 0, &vAttr)
) && vAttr.vt == VT_BSTR && ::SysStringLen(vAttr.bstrVal) > 0) | 280 if (SUCCEEDED(pFrameEl->getAttribute(ATL::CComBSTR(L"scr"), 0, &vAttr)
) && vAttr.vt == VT_BSTR && ::SysStringLen(vAttr.bstrVal) > 0) |
266 { | 281 { |
267 CString src = vAttr.bstrVal; | 282 CString srcLegacy = vAttr.bstrVal; |
268 | 283 |
269 // Some times, domain is missing. Should this be added on image src'
s as well?'' | 284 // Some times, domain is missing. Should this be added on image src'
s as well?'' |
270 | 285 |
271 // eg. gadgetzone.com.au | 286 // eg. gadgetzone.com.au |
272 if (src.Left(2) == L"//") | 287 if (srcLegacy.Left(2) == L"//") |
273 { | 288 { |
274 src = L"http:" + src; | 289 srcLegacy = L"http:" + srcLegacy; |
275 } | 290 } |
276 // eg. http://w3schools.com/html/html_examples.asp | 291 // eg. http://w3schools.com/html/html_examples.asp |
277 else if (src.Left(4) != L"http" && src.Left(6) != L"res://") | 292 else if (srcLegacy.Left(4) != L"http" && srcLegacy.Left(6) != L"res:
//") |
278 { | 293 { |
279 src = L"http://" + to_CString(m_domain) + src; | 294 srcLegacy = L"http://" + ToCString(m_domain) + srcLegacy; |
280 } | 295 } |
281 | 296 std::wstring src(ToWstring(srcLegacy)); |
282 CPluginClient::UnescapeUrl(src); | 297 UnescapeUrl(src); |
283 | 298 |
284 // Check if Iframe should be traversed | 299 // Check if Iframe should be traversed |
285 if (OnIFrame(pFrameEl, src, indent)) | 300 if (OnIFrame(pFrameEl, src, indent)) |
286 { | 301 { |
287 CComQIPtr<IWebBrowser2> pFrameBrowser = pFrameDispatch; | 302 CComQIPtr<IWebBrowser2> pFrameBrowser = pFrameDispatch; |
288 if (pFrameBrowser) | 303 if (pFrameBrowser) |
289 { | 304 { |
290 TraverseDocument(pFrameBrowser, false, indent); | 305 TraverseDocument(pFrameBrowser, false, indent); |
291 } | 306 } |
292 }» | 307 } |
293 } | 308 } |
294 } | 309 } |
295 } | 310 } |
296 } | 311 } |
297 } | 312 } |
298 } | 313 } |
299 | 314 |
300 | 315 |
301 template <class T> | 316 template <class T> |
302 void CPluginDomTraverserBase<T>::TraverseChild(IHTMLElement* pEl, IWebBrowser2*
pBrowser, CString& indent, bool isCached) | 317 void CPluginDomTraverserBase<T>::TraverseChild(IHTMLElement* pEl, IWebBrowser2*
pBrowser, CString& indent, bool isCached) |
303 { | 318 { |
304 int cacheIndex = -1; | 319 int cacheIndex = -1; |
305 long cacheAllElementsCount = -1; | 320 long cacheAllElementsCount = -1; |
306 | 321 |
307 m_criticalSection.Lock(); | 322 m_criticalSection.Lock(); |
308 { | 323 { |
309 CComVariant vCacheIndex; | 324 CComVariant vCacheIndex; |
310 if (isCached && SUCCEEDED(pEl->getAttribute(ATL::CComBSTR(L"abp"), 0, &vCach
eIndex)) && vCacheIndex.vt == VT_I4) | 325 if (isCached && SUCCEEDED(pEl->getAttribute(ATL::CComBSTR(L"abp"), 0, &vCach
eIndex)) && vCacheIndex.vt == VT_I4) |
311 { | 326 { |
312 cacheIndex = vCacheIndex.intVal; | 327 cacheIndex = vCacheIndex.intVal; |
313 | 328 |
314 cacheAllElementsCount = m_cacheElements[cacheIndex].m_elements; | 329 cacheAllElementsCount = m_cacheElements[cacheIndex].m_elements; |
315 } | 330 } |
316 else | 331 else |
317 { | 332 { |
318 isCached = false; | 333 isCached = false; |
319 | 334 |
320 cacheIndex = m_cacheIndexLast++; | 335 cacheIndex = m_cacheIndexLast++; |
321 | 336 |
322 // Resize cache??? | 337 // Resize cache??? |
323 if (cacheIndex >= m_cacheElementsMax) | 338 if (cacheIndex >= m_cacheElementsMax) |
324 { | 339 { |
325 T* oldCacheElements = m_cacheElements; | 340 T* oldCacheElements = m_cacheElements; |
326 | 341 |
327 m_cacheElements = new T[2*m_cacheElementsMax]; | 342 m_cacheElements = new T[2*m_cacheElementsMax]; |
328 | 343 |
329 memcpy(m_cacheElements, oldCacheElements, m_cacheElementsMax*sizeof(T)); | 344 memcpy(m_cacheElements, oldCacheElements, m_cacheElementsMax*sizeof(T)); |
330 | 345 |
331 m_cacheElementsMax *= 2; | 346 m_cacheElementsMax *= 2; |
332 | 347 |
333 delete [] oldCacheElements; | 348 delete [] oldCacheElements; |
334 } | 349 } |
335 | 350 |
336 m_cacheElements[cacheIndex].Init(); | 351 m_cacheElements[cacheIndex].Init(); |
337 | 352 |
338 vCacheIndex.vt = VT_I4; | 353 vCacheIndex.vt = VT_I4; |
339 vCacheIndex.intVal = cacheIndex; | 354 vCacheIndex.intVal = cacheIndex; |
340 | 355 |
341 pEl->setAttribute(ATL::CComBSTR(L"abp"), vCacheIndex); | 356 pEl->setAttribute(ATL::CComBSTR(L"abp"), vCacheIndex); |
342 } | 357 } |
343 } | 358 } |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 { | 463 { |
449 m_cacheIndexLast = 0; | 464 m_cacheIndexLast = 0; |
450 m_cacheDocumentHasFrames.clear(); | 465 m_cacheDocumentHasFrames.clear(); |
451 m_cacheDocumentHasIframes.clear(); | 466 m_cacheDocumentHasIframes.clear(); |
452 } | 467 } |
453 m_criticalSection.Unlock(); | 468 m_criticalSection.Unlock(); |
454 } | 469 } |
455 | 470 |
456 | 471 |
457 #endif // _PLUGIN_DOM_TRAVERSER_BASE_H_ | 472 #endif // _PLUGIN_DOM_TRAVERSER_BASE_H_ |
LEFT | RIGHT |