| Index: src/plugin/PluginWbPassThrough.cpp |
| =================================================================== |
| --- a/src/plugin/PluginWbPassThrough.cpp |
| +++ b/src/plugin/PluginWbPassThrough.cpp |
| @@ -14,7 +14,15 @@ |
| EXTERN_C IMAGE_DOS_HEADER __ImageBase; |
| - |
| +namespace |
| +{ |
| + std::string g_myPageBlocked = "<!DOCTYPE html>" |
| + "<html>" |
| + "<body>" |
| + "<!-- blocked by AdblockPlus -->" |
| + "</body>" |
| + "</html>"; |
| +} |
| int WBPassthruSink::GetContentTypeFromMimeType(CString mimeType) |
| { |
| @@ -115,13 +123,11 @@ |
| //////////////////////////////////////////////////////////////////////////////////////// |
| HRESULT WBPassthruSink::OnStart(LPCWSTR szUrl, IInternetProtocolSink *pOIProtSink, |
| IInternetBindInfo *pOIBindInfo, DWORD grfPI, HANDLE_PTR dwReserved, |
| - IInternetProtocol* pTargetProtocol) |
| + IInternetProtocol* pTargetProtocol, bool& handled) |
| { |
| - |
| m_pTargetProtocol = pTargetProtocol; |
| bool isBlocked = false; |
| - m_shouldBlock = false; |
| - m_lastDataReported = false; |
| + m_currentPositionOfSentPage = 0; |
| CString src; |
| src.Append(szUrl); |
| DEBUG_GENERAL(src); |
| @@ -237,51 +243,43 @@ |
| //Fixes the iframe back button issue |
| if (client->GetIEVersion() > 6) |
| { |
| - if ((contentType == CFilter::contentTypeImage) && (isBlocked)) |
| + if (contentType == CFilter::contentTypeImage && isBlocked) |
| { |
| - m_shouldBlock = true; |
| BaseClass::OnStart(szUrl, pOIProtSink, pOIBindInfo, grfPI, dwReserved, pTargetProtocol); |
| - |
| + handled = true; |
| + // IE shows a cross that img is not loaded |
| return INET_E_REDIRECT_FAILED; |
| - |
| } |
| - if (((contentType == CFilter::contentTypeSubdocument))&& (isBlocked)) |
| + if (contentType == CFilter::contentTypeSubdocument && isBlocked) |
| { |
| - m_shouldBlock = true; |
| + PassthroughAPP::CustomSinkStartPolicy<WBPassthru, WBPassthruSink>::GetProtocol(this)->m_shouldSupplyCustomContent = true; |
| BaseClass::OnStart(szUrl, pOIProtSink, pOIBindInfo, grfPI, dwReserved, pTargetProtocol); |
| m_spInternetProtocolSink->ReportProgress(BINDSTATUS_MIMETYPEAVAILABLE, L"text/html"); |
| - |
| - //Here we check if we are running on Windows 8 Consumer Preview. |
| - //For some reason on that environment the next line causes IE to crash |
| - if (CPluginSettings::GetInstance()->GetWindowsBuildNumber() != 8250) |
| - { |
| - m_spInternetProtocolSink->ReportResult(INET_E_REDIRECT_FAILED, 0, szUrl); |
| - } |
| - |
| - return INET_E_REDIRECT_FAILED; |
| + m_spInternetProtocolSink->ReportData(BSCF_FIRSTDATANOTIFICATION, 0, static_cast<ULONG>(g_myPageBlocked.size())); |
| + handled = true; |
| + return S_OK; |
| } |
| - if (((contentType == CFilter::contentTypeScript)) && (isBlocked)) |
| + if (contentType == CFilter::contentTypeScript && isBlocked) |
| { |
| - m_shouldBlock = true; |
| BaseClass::OnStart(szUrl, pOIProtSink, pOIBindInfo, grfPI, dwReserved, pTargetProtocol); |
| m_spInternetProtocolSink->ReportProgress(BINDSTATUS_MIMETYPEAVAILABLE, L"text/javascript"); |
| m_spInternetProtocolSink->ReportResult(INET_E_REDIRECTING, 301, L"data:"); |
| + handled = true; |
| return INET_E_REDIRECT_FAILED; |
| } |
| - if ((contentType == CFilter::contentTypeXmlHttpRequest) && (isBlocked)) |
| + if (contentType == CFilter::contentTypeXmlHttpRequest && isBlocked) |
| { |
| - m_shouldBlock = true; |
| BaseClass::OnStart(szUrl, pOIProtSink, pOIBindInfo, grfPI, dwReserved, pTargetProtocol); |
| m_spInternetProtocolSink->ReportResult(INET_E_REDIRECTING, 301, L"data:"); |
| + handled = true; |
| return INET_E_REDIRECT_FAILED; |
| } |
| - if ((isBlocked)) |
| + if (isBlocked) |
| { |
| - m_shouldBlock = true; |
| BaseClass::OnStart(szUrl, pOIProtSink, pOIBindInfo, grfPI, dwReserved, pTargetProtocol); |
| m_spInternetProtocolSink->ReportResult(S_FALSE, 0, L""); |
| - |
| + handled = true; |
| return INET_E_REDIRECT_FAILED; |
| } |
| } |
| @@ -291,38 +289,43 @@ |
| } |
| -HRESULT WBPassthruSink::Read(void *pv, ULONG cb, ULONG* pcbRead) |
| +HRESULT WBPassthruSink::OnRead(void* pv, ULONG cb, ULONG* pcbRead) |
| { |
| - if (m_shouldBlock) |
| + if (nullptr == pv) |
| { |
| - *pcbRead = 0; |
| - if (!m_lastDataReported) |
| + return E_POINTER; |
| + } |
| + if (nullptr == pcbRead) |
| + { |
| + return E_POINTER; |
| + } |
| + *pcbRead = 0; |
| + |
| + if (PassthroughAPP::CustomSinkStartPolicy<WBPassthru, WBPassthruSink>::GetProtocol(this)->m_shouldSupplyCustomContent) |
| + { |
| + ULONG myPageSize = static_cast<ULONG>(g_myPageBlocked.size()); |
| + auto positionGrow = std::min<ULONG>(cb, static_cast<ULONG>(g_myPageBlocked.size() - m_currentPositionOfSentPage)); |
| + if (0 == positionGrow) { |
| + return S_FALSE; |
| + } |
| + std::copy(g_myPageBlocked.begin(), g_myPageBlocked.begin() + positionGrow, |
| + stdext::make_checked_array_iterator(static_cast<char*>(pv), cb)); |
| + *pcbRead = positionGrow; |
| + m_currentPositionOfSentPage += positionGrow; |
| + |
| + if (m_spInternetProtocolSink) |
| { |
| - if (cb <= 1) |
| - { |
| - //IE must've gone nuts if this happened, but let's be cool about it and report we have no more data |
| - m_spInternetProtocolSink->ReportResult(S_FALSE, 0, NULL); |
| - return S_FALSE; |
| - } |
| - *pcbRead = 1; |
| - memcpy(pv, " ", 1); |
| - |
| - if (m_spInternetProtocolSink != NULL) |
| - { |
| - m_spInternetProtocolSink->ReportResult(S_OK, 0, NULL); |
| - } |
| - m_lastDataReported = true; |
| - m_shouldBlock = false; |
| - return S_OK; |
| + m_spInternetProtocolSink->ReportData(BSCF_INTERMEDIATEDATANOTIFICATION, |
| + static_cast<ULONG>(m_currentPositionOfSentPage), myPageSize); |
| + } |
| + if (myPageSize == m_currentPositionOfSentPage && m_spInternetProtocolSink) |
| + { |
| + m_spInternetProtocolSink->ReportData(BSCF_DATAFULLYAVAILABLE, myPageSize, myPageSize); |
| + m_spInternetProtocolSink->ReportResult(S_OK, 0, nullptr); |
| } |
| return S_OK; |
| } |
| - else |
| - { |
| - |
| - return m_pTargetProtocol->Read(pv, cb, pcbRead); |
| - } |
| - return S_OK; |
| + return m_pTargetProtocol->Read(pv, cb, pcbRead); |
| } |
| STDMETHODIMP WBPassthruSink::Switch( |
| /* [in] */ PROTOCOLDATA *pProtocolData) |
| @@ -351,7 +354,6 @@ |
| return m_spInternetProtocolSink ? m_spInternetProtocolSink->Switch(pProtocolData) : E_UNEXPECTED; |
| } |
| - |
| STDMETHODIMP WBPassthruSink::BeginningTransaction(LPCWSTR szURL, LPCWSTR szHeaders, DWORD dwReserved, LPWSTR *pszAdditionalHeaders) |
| { |
| if (pszAdditionalHeaders) |
| @@ -382,6 +384,10 @@ |
| return m_spInternetProtocolSink ? m_spInternetProtocolSink->ReportProgress(ulStatusCode, szStatusText) : S_OK; |
| } |
| +WBPassthru::WBPassthru() |
| + : m_shouldSupplyCustomContent(false) |
| +{ |
| +} |
| STDMETHODIMP WBPassthru::Start(LPCWSTR szUrl, IInternetProtocolSink *pOIProtSink, |
| IInternetBindInfo *pOIBindInfo, DWORD grfPI, HANDLE_PTR dwReserved) |
| @@ -392,13 +398,29 @@ |
| return E_UNEXPECTED; |
| } |
| - return OnStart(szUrl, pOIProtSink, pOIBindInfo, grfPI, |
| - dwReserved, m_spInternetProtocol); |
| + return OnStart(szUrl, pOIProtSink, pOIBindInfo, grfPI, dwReserved, m_spInternetProtocol); |
| } |
| - STDMETHODIMP WBPassthru::Read( /* [in, out] */ void *pv,/* [in] */ ULONG cb,/* [out] */ ULONG *pcbRead) |
| - { |
| - |
| - WBPassthruSink* pSink = GetSink(); |
| - return pSink->Read(pv, cb, pcbRead); |
| - } |
| +STDMETHODIMP WBPassthru::Read(/* [in, out] */ void *pv,/* [in] */ ULONG cb,/* [out] */ ULONG *pcbRead) |
| +{ |
| + WBPassthruSink* pSink = GetSink(); |
| + return pSink->OnRead(pv, cb, pcbRead); |
| +} |
| + |
| +STDMETHODIMP WBPassthru::LockRequest(/* [in] */ DWORD options) |
| +{ |
| + if (m_shouldSupplyCustomContent) |
| + { |
| + return S_OK; |
| + } |
| + return PassthroughAPP::CInternetProtocol<WBStartPolicy>::LockRequest(options); |
| +} |
| + |
| +STDMETHODIMP WBPassthru::UnlockRequest() |
| +{ |
| + if (m_shouldSupplyCustomContent) |
| + { |
| + return S_OK; |
| + } |
| + return PassthroughAPP::CInternetProtocol<WBStartPolicy>::UnlockRequest(); |
| +} |