| OLD | NEW | 
|---|
| 1 #include "PluginStdAfx.h" | 1 #include "PluginStdAfx.h" | 
| 2 | 2 | 
| 3 #include "PluginWbPassThrough.h" | 3 #include "PluginWbPassThrough.h" | 
| 4 #include "PluginClient.h" | 4 #include "PluginClient.h" | 
| 5 #include "PluginClientFactory.h" | 5 #include "PluginClientFactory.h" | 
| 6 #include "PluginFilter.h" | 6 #include "PluginFilter.h" | 
| 7 #include "PluginSettings.h" | 7 #include "PluginSettings.h" | 
| 8 #include "PluginClass.h" | 8 #include "PluginClass.h" | 
| 9 #include "PluginSystem.h" | 9 #include "PluginSystem.h" | 
| 10 #include <WinInet.h> | 10 #include <WinInet.h> | 
| 11 #include "wtypes.h" | 11 #include "wtypes.h" | 
| 12 #include "../shared/Utils.h" | 12 #include "../shared/Utils.h" | 
| 13 #include "../shared/IE_version.h" | 13 #include "../shared/IE_version.h" | 
| 14 | 14 | 
| 15 namespace | 15 namespace | 
| 16 { | 16 { | 
| 17   const std::string g_blockedByABPPage = "<!DOCTYPE html>" | 17   const std::string g_blockedByABPPage = "<!DOCTYPE html>" | 
| 18     "<html>" | 18     "<html>" | 
| 19         "<body>" | 19         "<body>" | 
| 20           "<!-- blocked by AdblockPlus -->" | 20           "<!-- blocked by AdblockPlus -->" | 
| 21         "</body>" | 21         "</body>" | 
| 22     "</html>"; | 22     "</html>"; | 
| 23 | 23 | 
|  | 24   typedef AdblockPlus::FilterEngine::ContentType ContentType; | 
|  | 25 | 
| 24   template <class T> | 26   template <class T> | 
| 25   T ExtractHttpHeader(const T& allHeaders, const T& targetHeaderNameWithColon, c
     onst T& delimiter) | 27   T ExtractHttpHeader(const T& allHeaders, const T& targetHeaderNameWithColon, c
     onst T& delimiter) | 
| 26   { | 28   { | 
| 27     auto targetHeaderBeginsAt = allHeaders.find(targetHeaderNameWithColon); | 29     auto targetHeaderBeginsAt = allHeaders.find(targetHeaderNameWithColon); | 
| 28     if (targetHeaderBeginsAt == T::npos) | 30     if (targetHeaderBeginsAt == T::npos) | 
| 29     { | 31     { | 
| 30       return T(); | 32       return T(); | 
| 31     } | 33     } | 
| 32     targetHeaderBeginsAt += targetHeaderNameWithColon.length(); | 34     targetHeaderBeginsAt += targetHeaderNameWithColon.length(); | 
| 33     auto targetHeaderEndsAt = allHeaders.find(delimiter, targetHeaderBeginsAt); | 35     auto targetHeaderEndsAt = allHeaders.find(delimiter, targetHeaderBeginsAt); | 
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 67 | 69 | 
| 68   bool IsXmlHttpRequest(const std::wstring& additionalHeaders) | 70   bool IsXmlHttpRequest(const std::wstring& additionalHeaders) | 
| 69   { | 71   { | 
| 70     auto requestedWithHeader = ExtractHttpHeader<std::wstring>(additionalHeaders
     , L"X-Requested-With:", L"\n"); | 72     auto requestedWithHeader = ExtractHttpHeader<std::wstring>(additionalHeaders
     , L"X-Requested-With:", L"\n"); | 
| 71     return TrimString(requestedWithHeader) == L"XMLHttpRequest"; | 73     return TrimString(requestedWithHeader) == L"XMLHttpRequest"; | 
| 72   } | 74   } | 
| 73 } | 75 } | 
| 74 | 76 | 
| 75 WBPassthruSink::WBPassthruSink() | 77 WBPassthruSink::WBPassthruSink() | 
| 76   : m_currentPositionOfSentPage(0) | 78   : m_currentPositionOfSentPage(0) | 
| 77   , m_contentType(CFilter::EContentType::contentTypeAny) | 79   , m_contentType(ContentType::CONTENT_TYPE_OTHER) | 
| 78   , m_isCustomResponse(false) | 80   , m_isCustomResponse(false) | 
| 79 { | 81 { | 
| 80 } | 82 } | 
| 81 | 83 | 
| 82 int WBPassthruSink::GetContentTypeFromMimeType(const CString& mimeType) | 84 ContentType WBPassthruSink::GetContentTypeFromMimeType(const CString& mimeType) | 
| 83 { | 85 { | 
| 84   if (mimeType.Find(L"image/") >= 0) | 86   if (mimeType.Find(L"image/") >= 0) | 
| 85   { | 87   { | 
| 86     return CFilter::contentTypeImage; | 88     return ContentType::CONTENT_TYPE_IMAGE; | 
| 87   } | 89   } | 
| 88   if (mimeType.Find(L"text/css") >= 0) | 90   if (mimeType.Find(L"text/css") >= 0) | 
| 89   { | 91   { | 
| 90     return CFilter::contentTypeStyleSheet; | 92     return ContentType::CONTENT_TYPE_STYLESHEET; | 
| 91   } | 93   } | 
| 92   if ((mimeType.Find(L"application/javascript") >= 0) || (mimeType.Find(L"applic
     ation/json") >= 0)) | 94   if ((mimeType.Find(L"application/javascript") >= 0) || (mimeType.Find(L"applic
     ation/json") >= 0)) | 
| 93   { | 95   { | 
| 94     return CFilter::contentTypeScript; | 96     return ContentType::CONTENT_TYPE_SCRIPT; | 
| 95   } | 97   } | 
| 96   if (mimeType.Find(L"application/x-shockwave-flash") >= 0) | 98   if (mimeType.Find(L"application/x-shockwave-flash") >= 0) | 
| 97   { | 99   { | 
| 98     return CFilter::contentTypeObject; | 100     return ContentType::CONTENT_TYPE_OBJECT; | 
| 99   } | 101   } | 
| 100   if (mimeType.Find(L"text/html") >= 0) | 102   if (mimeType.Find(L"text/html") >= 0) | 
| 101   { | 103   { | 
| 102     return CFilter::contentTypeSubdocument; | 104     return ContentType::CONTENT_TYPE_SUBDOCUMENT; | 
| 103   } | 105   } | 
| 104   // It is important to have this check last, since it is rather generic, and mi
     ght overlay text/html, for example | 106   // It is important to have this check last, since it is rather generic, and mi
     ght overlay text/html, for example | 
| 105   if (mimeType.Find(L"xml") >= 0) | 107   if (mimeType.Find(L"xml") >= 0) | 
| 106   { | 108   { | 
| 107     return CFilter::contentTypeXmlHttpRequest; | 109     return ContentType::CONTENT_TYPE_XMLHTTPREQUEST; | 
| 108   } | 110   } | 
| 109 | 111 | 
| 110   return CFilter::contentTypeAny; | 112   return ContentType::CONTENT_TYPE_OTHER; | 
| 111 } | 113 } | 
| 112 | 114 | 
| 113 int WBPassthruSink::GetContentTypeFromURL(const CString& src) | 115 ContentType WBPassthruSink::GetContentTypeFromURL(const CString& src) | 
| 114 { | 116 { | 
| 115   CString srcExt = src; | 117   CString srcExt = src; | 
| 116 | 118 | 
| 117   int pos = 0; | 119   int pos = 0; | 
| 118   if ((pos = src.Find('?')) > 0) | 120   if ((pos = src.Find('?')) > 0) | 
| 119   { | 121   { | 
| 120     srcExt = src.Left(pos); | 122     srcExt = src.Left(pos); | 
| 121   } | 123   } | 
| 122 | 124 | 
| 123   int lastDotIndex = srcExt.ReverseFind('.'); | 125   int lastDotIndex = srcExt.ReverseFind('.'); | 
| 124   if (lastDotIndex < 0) | 126   if (lastDotIndex < 0) | 
| 125     return CFilter::contentTypeAny; | 127     return ContentType::CONTENT_TYPE_OTHER; | 
| 126   CString ext = srcExt.Mid(lastDotIndex); | 128   CString ext = srcExt.Mid(lastDotIndex); | 
| 127   if (ext == L".jpg" || ext == L".gif" || ext == L".png" || ext == L".jpeg") | 129   if (ext == L".jpg" || ext == L".gif" || ext == L".png" || ext == L".jpeg") | 
| 128   { | 130   { | 
| 129     return CFilter::contentTypeImage; | 131     return ContentType::CONTENT_TYPE_IMAGE; | 
| 130   } | 132   } | 
| 131   else if (ext == L".css") | 133   else if (ext == L".css") | 
| 132   { | 134   { | 
| 133     return CFilter::contentTypeStyleSheet; | 135     return ContentType::CONTENT_TYPE_STYLESHEET; | 
| 134   } | 136   } | 
| 135   else if (ext.Right(3) == L".js") | 137   else if (ext.Right(3) == L".js") | 
| 136   { | 138   { | 
| 137     return CFilter::contentTypeScript; | 139     return ContentType::CONTENT_TYPE_SCRIPT; | 
| 138   } | 140   } | 
| 139   else if (ext == L".xml") | 141   else if (ext == L".xml") | 
| 140   { | 142   { | 
| 141     return CFilter::contentTypeXmlHttpRequest; | 143     return ContentType::CONTENT_TYPE_XMLHTTPREQUEST; | 
| 142   } | 144   } | 
| 143   else if (ext == L".swf") | 145   else if (ext == L".swf") | 
| 144   { | 146   { | 
| 145     return CFilter::contentTypeObject; | 147     return ContentType::CONTENT_TYPE_OBJECT; | 
| 146   } | 148   } | 
| 147   else if (ext == L".jsp" || ext == L".php" || ext == L".html") | 149   else if (ext == L".jsp" || ext == L".php" || ext == L".html") | 
| 148   { | 150   { | 
| 149     return CFilter::contentTypeSubdocument; | 151     return ContentType::CONTENT_TYPE_SUBDOCUMENT; | 
| 150   } | 152   } | 
| 151   return CFilter::contentTypeAny; | 153   return ContentType::CONTENT_TYPE_OTHER; | 
| 152 } | 154 } | 
| 153 | 155 | 
| 154 int WBPassthruSink::GetContentType(const CString& mimeType, const std::wstring& 
     domain, const CString& src) | 156 ContentType WBPassthruSink::GetContentType(const CString& mimeType, const std::w
     string& domain, const CString& src) | 
| 155 { | 157 { | 
| 156   // No referer or mime type | 158   // No referer or mime type | 
| 157   // BINDSTRING_XDR_ORIGIN works only for IE v8+ | 159   // BINDSTRING_XDR_ORIGIN works only for IE v8+ | 
| 158   if (mimeType.IsEmpty() && domain.empty() && AdblockPlus::IE::InstalledMajorVer
     sion() >= 8) | 160   if (mimeType.IsEmpty() && domain.empty() && AdblockPlus::IE::InstalledMajorVer
     sion() >= 8) | 
| 159   { | 161   { | 
| 160     return CFilter::contentTypeXmlHttpRequest; | 162     return ContentType::CONTENT_TYPE_XMLHTTPREQUEST; | 
| 161   } | 163   } | 
| 162   int contentType = GetContentTypeFromMimeType(mimeType); | 164   ContentType contentType = GetContentTypeFromMimeType(mimeType); | 
| 163   if (contentType == CFilter::contentTypeAny) | 165   if (contentType == ContentType::CONTENT_TYPE_OTHER) | 
| 164   { | 166   { | 
| 165     contentType = GetContentTypeFromURL(src); | 167     contentType = GetContentTypeFromURL(src); | 
| 166   } | 168   } | 
| 167   return contentType; | 169   return contentType; | 
| 168 } | 170 } | 
| 169 | 171 | 
| 170 ////////////////////////////////////////////////////////////////////////////////
     //////// | 172 ////////////////////////////////////////////////////////////////////////////////
     //////// | 
| 171 //WBPassthruSink | 173 //WBPassthruSink | 
| 172 //Monitor and/or cancel every request and responde | 174 //Monitor and/or cancel every request and responde | 
| 173 //WB makes, including images, sounds, scripts, etc | 175 //WB makes, including images, sounds, scripts, etc | 
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 294   // This fills the pszAdditionalHeaders with more headers. One of which is the 
     Referer header, which we need. | 296   // This fills the pszAdditionalHeaders with more headers. One of which is the 
     Referer header, which we need. | 
| 295   // There doesn't seem to be any other way to get this header before the reques
     t has been made. | 297   // There doesn't seem to be any other way to get this header before the reques
     t has been made. | 
| 296   HRESULT nativeHr = httpNegotiate ? httpNegotiate->BeginningTransaction(szURL, 
     szHeaders, dwReserved, pszAdditionalHeaders) : S_OK; | 298   HRESULT nativeHr = httpNegotiate ? httpNegotiate->BeginningTransaction(szURL, 
     szHeaders, dwReserved, pszAdditionalHeaders) : S_OK; | 
| 297 | 299 | 
| 298   if (pszAdditionalHeaders && *pszAdditionalHeaders) | 300   if (pszAdditionalHeaders && *pszAdditionalHeaders) | 
| 299   { | 301   { | 
| 300     m_boundDomain = ExtractHttpHeader<std::wstring>(*pszAdditionalHeaders, L"Ref
     erer:", L"\n"); | 302     m_boundDomain = ExtractHttpHeader<std::wstring>(*pszAdditionalHeaders, L"Ref
     erer:", L"\n"); | 
| 301   } | 303   } | 
| 302   m_boundDomain = TrimString(m_boundDomain); | 304   m_boundDomain = TrimString(m_boundDomain); | 
| 303   m_contentType = GetContentType(ATL::CString(acceptHeader.c_str()), m_boundDoma
     in, ToCString(src)); | 305   m_contentType = GetContentType(ATL::CString(acceptHeader.c_str()), m_boundDoma
     in, ToCString(src)); | 
|  | 306 | 
| 304   CPluginTab* tab = CPluginClass::GetTab(::GetCurrentThreadId()); | 307   CPluginTab* tab = CPluginClass::GetTab(::GetCurrentThreadId()); | 
| 305   CPluginClient* client = CPluginClient::GetInstance(); | 308   CPluginClient* client = CPluginClient::GetInstance(); | 
| 306 | 309 | 
| 307   if (tab && client) | 310   if (tab && client) | 
| 308   { | 311   { | 
| 309     CString documentUrl = tab->GetDocumentUrl(); | 312     CString documentUrl = tab->GetDocumentUrl(); | 
| 310     // Page is identical to document => don't block | 313     // Page is identical to document => don't block | 
| 311     if (documentUrl == ToCString(src)) | 314     if (documentUrl == ToCString(src)) | 
| 312     { | 315     { | 
| 313       return nativeHr; | 316       return nativeHr; | 
| 314     } | 317     } | 
| 315     else if (CPluginSettings::GetInstance()->IsPluginEnabled() && !client->IsWhi
     telistedUrl(std::wstring(documentUrl))) | 318     else if (CPluginSettings::GetInstance()->IsPluginEnabled() && !client->IsWhi
     telistedUrl(std::wstring(documentUrl))) | 
| 316     { | 319     { | 
| 317       if (tab->IsFrameCached(ToCString(src))) | 320       if (tab->IsFrameCached(ToCString(src))) | 
| 318       { | 321       { | 
| 319         m_contentType = CFilter::contentTypeSubdocument; | 322         m_contentType = ContentType::CONTENT_TYPE_SUBDOCUMENT; | 
| 320       } | 323       } | 
| 321     } | 324     } | 
| 322   } | 325   } | 
| 323 | 326 | 
| 324   if (IsFlashRequest(pszAdditionalHeaders)) | 327   if (IsFlashRequest(pszAdditionalHeaders)) | 
| 325   { | 328   { | 
| 326     m_contentType = CFilter::EContentType::contentTypeObjectSubrequest; | 329     m_contentType = ContentType::CONTENT_TYPE_OBJECT_SUBREQUEST; | 
| 327   } | 330   } | 
| 328 | 331 | 
| 329   if (pszAdditionalHeaders && *pszAdditionalHeaders && IsXmlHttpRequest(*pszAddi
     tionalHeaders)) | 332   if (pszAdditionalHeaders && *pszAdditionalHeaders && IsXmlHttpRequest(*pszAddi
     tionalHeaders)) | 
| 330   { | 333   { | 
| 331     m_contentType = CFilter::EContentType::contentTypeXmlHttpRequest; | 334     m_contentType = ContentType::CONTENT_TYPE_XMLHTTPREQUEST; | 
| 332   } | 335   } | 
| 333 | 336 | 
| 334   if (client->ShouldBlock(szURL, m_contentType, m_boundDomain, /*debug flag but 
     must be set*/true)) | 337   if (client->ShouldBlock(szURL, m_contentType, m_boundDomain, /*debug flag but 
     must be set*/true)) | 
| 335   { | 338   { | 
| 336     // NOTE: Feeding custom HTML to Flash, instead of original object subrequest | 339     // NOTE: Feeding custom HTML to Flash, instead of original object subrequest | 
| 337     // doesn't have much sense. It also can manifest in unwanted result» | 340     // doesn't have much sense. It also can manifest in unwanted result | 
| 338     // like video being blocked (See https://issues.adblockplus.org/ticket/1669)
     » | 341     // like video being blocked (See https://issues.adblockplus.org/ticket/1669) | 
| 339     // So we report blocked object subrequests as failed, not just empty HTML. | 342     // So we report blocked object subrequests as failed, not just empty HTML. | 
| 340     m_isCustomResponse = m_contentType != CFilter::contentTypeObjectSubrequest; | 343     m_isCustomResponse = m_contentType != ContentType::CONTENT_TYPE_OBJECT_SUBRE
     QUEST; | 
| 341     return E_ABORT; | 344     return E_ABORT; | 
| 342   } | 345   } | 
| 343   return nativeHr; | 346   return nativeHr; | 
| 344 } | 347 } | 
| 345 | 348 | 
| 346 STDMETHODIMP WBPassthruSink::OnResponse(DWORD dwResponseCode, LPCWSTR szResponse
     Headers, LPCWSTR szRequestHeaders, LPWSTR *pszAdditionalRequestHeaders) | 349 STDMETHODIMP WBPassthruSink::OnResponse(DWORD dwResponseCode, LPCWSTR szResponse
     Headers, LPCWSTR szRequestHeaders, LPWSTR *pszAdditionalRequestHeaders) | 
| 347 { | 350 { | 
| 348   if (pszAdditionalRequestHeaders) | 351   if (pszAdditionalRequestHeaders) | 
| 349   { | 352   { | 
| 350     *pszAdditionalRequestHeaders = 0; | 353     *pszAdditionalRequestHeaders = 0; | 
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 389   } | 392   } | 
| 390 | 393 | 
| 391   return OnStart(szUrl, pOIProtSink, pOIBindInfo, grfPI, dwReserved, m_spInterne
     tProtocol); | 394   return OnStart(szUrl, pOIProtSink, pOIBindInfo, grfPI, dwReserved, m_spInterne
     tProtocol); | 
| 392 } | 395 } | 
| 393 | 396 | 
| 394 STDMETHODIMP WBPassthru::Read(/* [in, out] */ void *pv,/* [in] */ ULONG cb,/* [o
     ut] */ ULONG *pcbRead) | 397 STDMETHODIMP WBPassthru::Read(/* [in, out] */ void *pv,/* [in] */ ULONG cb,/* [o
     ut] */ ULONG *pcbRead) | 
| 395 { | 398 { | 
| 396   WBPassthruSink* pSink = GetSink(); | 399   WBPassthruSink* pSink = GetSink(); | 
| 397   return pSink->OnRead(pv, cb, pcbRead); | 400   return pSink->OnRead(pv, cb, pcbRead); | 
| 398 } | 401 } | 
| OLD | NEW | 
|---|