| OLD | NEW | 
|---|
| 1 #include "PluginStdAfx.h" | 1 #include "PluginStdAfx.h" | 
| 2 | 2 | 
| 3 #include "PluginClient.h" | 3 #include "PluginClient.h" | 
| 4 #include "PluginFilter.h" | 4 #include "PluginFilter.h" | 
| 5 #include "PluginSettings.h" | 5 #include "PluginSettings.h" | 
| 6 | 6 | 
| 7 #include "AdblockPlusDomTraverser.h" | 7 #include "AdblockPlusDomTraverser.h" | 
| 8 | 8 | 
| 9 | 9 | 
| 10 CPluginDomTraverser::CPluginDomTraverser(CPluginTab* tab) : CPluginDomTraverserB
     ase(tab) | 10 CPluginDomTraverser::CPluginDomTraverser(CPluginTab* tab) : CPluginDomTraverserB
     ase(tab) | 
| 11 { | 11 { | 
| 12 } | 12 } | 
| 13 | 13 | 
| 14 | 14 | 
| 15 bool CPluginDomTraverser::OnIFrame(IHTMLElement* pEl, const CString& url, CStrin
     g& indent) | 15 bool CPluginDomTraverser::OnIFrame(IHTMLElement* pEl, const std::wstring& url, C
     String& indent) | 
| 16 { | 16 { | 
| 17   CPluginClient* client = CPluginClient::GetInstance(); | 17   CPluginClient* client = CPluginClient::GetInstance(); | 
| 18 | 18 | 
| 19   // If src should be blocked, set style display:none on iframe | 19   // If src should be blocked, set style display:none on iframe | 
| 20   bool isBlocked = client->ShouldBlock(to_wstring(url), CFilter::contentTypeSubd
     ocument, m_domain); | 20   bool isBlocked = client->ShouldBlock(url, CFilter::contentTypeSubdocument, m_d
     omain); | 
| 21   if (isBlocked) | 21   if (isBlocked) | 
| 22   { | 22   { | 
| 23     HideElement(pEl, "iframe", url, true, indent); | 23     HideElement(pEl, "iframe", url, true, indent); | 
| 24   } | 24   } | 
| 25 | 25 | 
| 26   return !isBlocked; | 26   return !isBlocked; | 
| 27 } | 27 } | 
| 28 | 28 | 
| 29 | 29 | 
| 30 bool CPluginDomTraverser::OnElement(IHTMLElement* pEl, const CString& tag, CPlug
     inDomTraverserCache* cache, bool isDebug, CString& indent) | 30 bool CPluginDomTraverser::OnElement(IHTMLElement* pEl, const CString& tag, CPlug
     inDomTraverserCache* cache, bool isDebug, CString& indent) | 
| 31 { | 31 { | 
| 32   if (cache->m_isHidden) | 32   if (cache->m_isHidden) | 
| 33   { | 33   { | 
| 34     return false; | 34     return false; | 
| 35   } | 35   } | 
| 36 | 36 | 
| 37   // Check if element is hidden | 37   // Check if element is hidden | 
| 38   CPluginClient* client = CPluginClient::GetInstance(); | 38   CPluginClient* client = CPluginClient::GetInstance(); | 
| 39 | 39 | 
| 40   cache->m_isHidden = client->IsElementHidden(to_wstring(tag), pEl, m_domain, to
     _wstring(indent), m_tab->m_filter.get()); | 40   cache->m_isHidden = client->IsElementHidden(to_wstring(tag), pEl, m_domain, to
     _wstring(indent), m_tab->m_filter.get()); | 
| 41   if (cache->m_isHidden) | 41   if (cache->m_isHidden) | 
| 42   { | 42   { | 
| 43     HideElement(pEl, tag, "", false, indent); | 43     HideElement(pEl, tag, L"", false, indent); | 
| 44     return false; | 44     return false; | 
| 45   } | 45   } | 
| 46 | 46 | 
| 47   // Images | 47   // Images | 
| 48   if (tag == "img") | 48   if (tag == "img") | 
| 49   { | 49   { | 
| 50     CComVariant vAttr; | 50     CComVariant vAttr; | 
| 51 | 51 | 
| 52     if (SUCCEEDED(pEl->getAttribute(L"src", 0, &vAttr)) && vAttr.vt == VT_BSTR &
     & ::SysStringLen(vAttr.bstrVal) > 0) | 52     if (SUCCEEDED(pEl->getAttribute(L"src", 0, &vAttr)) && vAttr.vt == VT_BSTR &
     & ::SysStringLen(vAttr.bstrVal) > 0) | 
| 53     { | 53     { | 
| 54       CString src = vAttr.bstrVal; | 54       std::wstring src(vAttr.bstrVal, SysStringLen(vAttr.bstrVal)); | 
| 55       CPluginClient::UnescapeUrl(src); | 55       UnescapeUrl(src); | 
| 56 | 56 | 
| 57       // If src should be blocked, set style display:none on image | 57       // If src should be blocked, set style display:none on image | 
| 58       cache->m_isHidden = client->ShouldBlock(to_wstring(src), CFilter::contentT
     ypeImage, m_domain); | 58       cache->m_isHidden = client->ShouldBlock(src, CFilter::contentTypeImage, m_
     domain); | 
| 59       if (cache->m_isHidden) | 59       if (cache->m_isHidden) | 
| 60       { | 60       { | 
| 61         HideElement(pEl, "image", src, true, indent); | 61         HideElement(pEl, "image", src, true, indent); | 
| 62         return false; | 62         return false; | 
| 63       } | 63       } | 
| 64     } | 64     } | 
| 65   } | 65   } | 
| 66   // Objects | 66   // Objects | 
| 67   else if (tag == "object") | 67   else if (tag == "object") | 
| 68   { | 68   { | 
| (...skipping 16 matching lines...) Expand all  Loading... | 
| 85         // eg. http://w3schools.com/html/html_examples.asp | 85         // eg. http://w3schools.com/html/html_examples.asp | 
| 86         if (src.Left(2) == "//") | 86         if (src.Left(2) == "//") | 
| 87         { | 87         { | 
| 88           src = "http:" + src; | 88           src = "http:" + src; | 
| 89         } | 89         } | 
| 90 | 90 | 
| 91         if (!src.IsEmpty()) | 91         if (!src.IsEmpty()) | 
| 92         { | 92         { | 
| 93           if (cache->m_isHidden) | 93           if (cache->m_isHidden) | 
| 94           { | 94           { | 
| 95             HideElement(pEl, "object", src, true, indent); | 95             HideElement(pEl, "object", ToWstring(src), true, indent); | 
| 96             return false; | 96             return false; | 
| 97           } | 97           } | 
| 98         } | 98         } | 
| 99 | 99 | 
| 100         posBegin = sObjectHtml.Find(L"VALUE=\"", posBegin); | 100         posBegin = sObjectHtml.Find(L"VALUE=\"", posBegin); | 
| 101         posEnd = posBegin >= 0 ? sObjectHtml.Find(L"\"", posBegin + 7) : -1; | 101         posEnd = posBegin >= 0 ? sObjectHtml.Find(L"\"", posBegin + 7) : -1; | 
| 102       } | 102       } | 
| 103     } | 103     } | 
| 104   } | 104   } | 
| 105 | 105 | 
| 106   return true; | 106   return true; | 
| 107 } | 107 } | 
| 108 | 108 | 
| 109 | 109 | 
| 110 bool CPluginDomTraverser::IsEnabled() | 110 bool CPluginDomTraverser::IsEnabled() | 
| 111 { | 111 { | 
| 112   CPluginClient* client = CPluginClient::GetInstance(); | 112   CPluginClient* client = CPluginClient::GetInstance(); | 
| 113 | 113 | 
| 114   return client && CPluginSettings::GetInstance()->IsPluginEnabled() && !client-
     >IsWhitelistedUrl(m_domain); | 114   return client && CPluginSettings::GetInstance()->IsPluginEnabled() && !client-
     >IsWhitelistedUrl(m_domain); | 
| 115 } | 115 } | 
| 116 | 116 | 
| 117 | 117 | 
| 118 void CPluginDomTraverser::HideElement(IHTMLElement* pEl, const CString& type, co
     nst CString& url, bool isDebug, CString& indent) | 118 void CPluginDomTraverser::HideElement(IHTMLElement* pEl, const CString& type, co
     nst std::wstring& url, bool isDebug, CString& indent) | 
| 119 { | 119 { | 
| 120   CComPtr<IHTMLStyle> pStyle; | 120   CComPtr<IHTMLStyle> pStyle; | 
| 121 | 121 | 
| 122   if (SUCCEEDED(pEl->get_style(&pStyle)) && pStyle) | 122   if (SUCCEEDED(pEl->get_style(&pStyle)) && pStyle) | 
| 123   { | 123   { | 
| 124     CComBSTR bstrDisplay; | 124     CComBSTR bstrDisplay; | 
| 125 | 125 | 
| 126     if (SUCCEEDED(pStyle->get_display(&bstrDisplay)) && bstrDisplay && CString(b
     strDisplay) == L"none") | 126     if (SUCCEEDED(pStyle->get_display(&bstrDisplay)) && bstrDisplay && CString(b
     strDisplay) == L"none") | 
| 127     { | 127     { | 
| 128       return; | 128       return; | 
| 129     } | 129     } | 
| 130 | 130 | 
| 131     static const CComBSTR sbstrNone(L"none"); | 131     static const CComBSTR sbstrNone(L"none"); | 
| 132 | 132 | 
| 133     if (SUCCEEDED(pStyle->put_display(sbstrNone))) | 133     if (SUCCEEDED(pStyle->put_display(sbstrNone))) | 
| 134     { | 134     { | 
| 135       DEBUG_HIDE_EL(indent + L"HideEl::Hiding " + type + L" url:" + url) | 135       DEBUG_HIDE_EL(indent + L"HideEl::Hiding " + type + L" url:" + ToCString(ur
     l)) | 
| 136 | 136 | 
| 137 #ifdef ENABLE_DEBUG_RESULT | 137 #ifdef ENABLE_DEBUG_RESULT | 
| 138         if (isDebug) | 138         if (isDebug) | 
| 139         { | 139         { | 
| 140           CPluginDebug::DebugResultHiding(type, url, "-"); | 140           CPluginDebug::DebugResultHiding(type, ToCString(url), "-"); | 
| 141         } | 141         } | 
| 142 #endif // ENABLE_DEBUG_RESULT | 142 #endif // ENABLE_DEBUG_RESULT | 
| 143     } | 143     } | 
| 144   } | 144   } | 
| 145 } | 145 } | 
| OLD | NEW | 
|---|