LEFT | RIGHT |
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> |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 bool IsXmlHttpRequest(const std::wstring& additionalHeaders) | 67 bool IsXmlHttpRequest(const std::wstring& additionalHeaders) |
68 { | 68 { |
69 auto requestedWithHeader = ExtractHttpHeader<std::wstring>(additionalHeaders
, L"X-Requested-With:", L"\n"); | 69 auto requestedWithHeader = ExtractHttpHeader<std::wstring>(additionalHeaders
, L"X-Requested-With:", L"\n"); |
70 return TrimString(requestedWithHeader) == L"XMLHttpRequest"; | 70 return TrimString(requestedWithHeader) == L"XMLHttpRequest"; |
71 } | 71 } |
72 } | 72 } |
73 | 73 |
74 WBPassthruSink::WBPassthruSink() | 74 WBPassthruSink::WBPassthruSink() |
75 : m_currentPositionOfSentPage(0) | 75 : m_currentPositionOfSentPage(0) |
76 , m_contentType(CFilter::EContentType::contentTypeAny) | 76 , m_contentType(CFilter::EContentType::contentTypeAny) |
77 , m_blockedInTransaction(false) | 77 , m_isCustomResponse(false) |
78 { | 78 { |
79 } | 79 } |
80 | 80 |
81 int WBPassthruSink::GetContentTypeFromMimeType(const CString& mimeType) | 81 int WBPassthruSink::GetContentTypeFromMimeType(const CString& mimeType) |
82 { | 82 { |
83 if (mimeType.Find(L"image/") >= 0) | 83 if (mimeType.Find(L"image/") >= 0) |
84 { | 84 { |
85 return CFilter::contentTypeImage; | 85 return CFilter::contentTypeImage; |
86 } | 86 } |
87 if (mimeType.Find(L"text/css") >= 0) | 87 if (mimeType.Find(L"text/css") >= 0) |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 if (IsFlashRequest(pszAdditionalHeaders)) | 323 if (IsFlashRequest(pszAdditionalHeaders)) |
324 { | 324 { |
325 m_contentType = CFilter::EContentType::contentTypeObjectSubrequest; | 325 m_contentType = CFilter::EContentType::contentTypeObjectSubrequest; |
326 } | 326 } |
327 | 327 |
328 if (pszAdditionalHeaders && *pszAdditionalHeaders && IsXmlHttpRequest(*pszAddi
tionalHeaders)) | 328 if (pszAdditionalHeaders && *pszAdditionalHeaders && IsXmlHttpRequest(*pszAddi
tionalHeaders)) |
329 { | 329 { |
330 m_contentType = CFilter::EContentType::contentTypeXmlHttpRequest; | 330 m_contentType = CFilter::EContentType::contentTypeXmlHttpRequest; |
331 } | 331 } |
332 | 332 |
333 m_blockedInTransaction = client->ShouldBlock(szURL, m_contentType, m_boundDoma
in, /*debug flag but must be set*/true); | 333 if (client->ShouldBlock(szURL, m_contentType, m_boundDomain, /*debug flag but
must be set*/true)) |
334 if (m_blockedInTransaction) | 334 { |
335 { | 335 // NOTE: Feeding custom HTML to Flash, instead of original object subrequest |
| 336 // doesn't have much sense. It also can manifest in unwanted result» |
| 337 // like video being blocked (See https://issues.adblockplus.org/ticket/1669)
» |
| 338 // So we report blocked object subrequests as failed, not just empty HTML. |
| 339 m_isCustomResponse = m_contentType != CFilter::contentTypeObjectSubrequest; |
336 return E_ABORT; | 340 return E_ABORT; |
337 } | 341 } |
338 return nativeHr; | 342 return nativeHr; |
339 } | 343 } |
340 | 344 |
341 STDMETHODIMP WBPassthruSink::OnResponse(DWORD dwResponseCode, LPCWSTR szResponse
Headers, LPCWSTR szRequestHeaders, LPWSTR *pszAdditionalRequestHeaders) | 345 STDMETHODIMP WBPassthruSink::OnResponse(DWORD dwResponseCode, LPCWSTR szResponse
Headers, LPCWSTR szRequestHeaders, LPWSTR *pszAdditionalRequestHeaders) |
342 { | 346 { |
343 if (pszAdditionalRequestHeaders) | 347 if (pszAdditionalRequestHeaders) |
344 { | 348 { |
345 *pszAdditionalRequestHeaders = 0; | 349 *pszAdditionalRequestHeaders = 0; |
346 } | 350 } |
347 | 351 |
348 CComPtr<IHttpNegotiate> spHttpNegotiate; | 352 CComPtr<IHttpNegotiate> spHttpNegotiate; |
349 QueryServiceFromClient(&spHttpNegotiate); | 353 QueryServiceFromClient(&spHttpNegotiate); |
350 | 354 |
351 return spHttpNegotiate ? spHttpNegotiate->OnResponse(dwResponseCode, szRespons
eHeaders, szRequestHeaders, pszAdditionalRequestHeaders) : S_OK; | 355 return spHttpNegotiate ? spHttpNegotiate->OnResponse(dwResponseCode, szRespons
eHeaders, szRequestHeaders, pszAdditionalRequestHeaders) : S_OK; |
352 } | 356 } |
353 | 357 |
354 STDMETHODIMP WBPassthruSink::ReportProgress(ULONG ulStatusCode, LPCWSTR szStatus
Text) | 358 STDMETHODIMP WBPassthruSink::ReportProgress(ULONG ulStatusCode, LPCWSTR szStatus
Text) |
355 { | 359 { |
356 return m_spInternetProtocolSink ? m_spInternetProtocolSink->ReportProgress(ulS
tatusCode, szStatusText) : S_OK; | 360 return m_spInternetProtocolSink ? m_spInternetProtocolSink->ReportProgress(ulS
tatusCode, szStatusText) : S_OK; |
357 } | 361 } |
358 | 362 |
359 STDMETHODIMP WBPassthruSink::ReportResult(/* [in] */ HRESULT hrResult, /* [in] *
/ DWORD dwError, /* [in] */ LPCWSTR szResult) | 363 STDMETHODIMP WBPassthruSink::ReportResult(/* [in] */ HRESULT hrResult, /* [in] *
/ DWORD dwError, /* [in] */ LPCWSTR szResult) |
360 { | 364 { |
361 if (m_blockedInTransaction) | 365 if (m_isCustomResponse) |
362 { | 366 { |
363 // Don't notify the client about aborting of the operation, thus don't call
BaseClass::ReportResult. | 367 // Don't notify the client about aborting of the operation, thus don't call
BaseClass::ReportResult. |
364 // Current method is called by the original protocol implementation and we a
re intercepting the | 368 // Current method is called by the original protocol implementation and we a
re intercepting the |
365 // call here and eating it, we will call the proper ReportResult later by ou
rself. | 369 // call here and eating it, we will call the proper ReportResult later by ou
rself. |
366 // NOTE: Feeding custom HTML to Flash, instead of original object subrequest | 370 return S_OK; |
367 // doesn't have much sense. It also can manifest in unwanted result | |
368 // like video being blocked (See https://issues.adblockplus.org/ticket/1669) | |
369 // So we report blocked object subrequests as failed, not just empty HTML. | |
370 if (m_contentType != CFilter::contentTypeObjectSubrequest) | |
371 { | |
372 return S_OK; | |
373 } | |
374 } | 371 } |
375 return BaseClass::ReportResult(hrResult, dwError, szResult); | 372 return BaseClass::ReportResult(hrResult, dwError, szResult); |
376 } | 373 } |
377 | 374 |
378 | 375 |
379 WBPassthru::WBPassthru() | 376 WBPassthru::WBPassthru() |
380 : m_shouldSupplyCustomContent(false) | 377 : m_shouldSupplyCustomContent(false) |
381 { | 378 { |
382 } | 379 } |
383 | 380 |
384 STDMETHODIMP WBPassthru::Start(LPCWSTR szUrl, IInternetProtocolSink *pOIProtSink
, | 381 STDMETHODIMP WBPassthru::Start(LPCWSTR szUrl, IInternetProtocolSink *pOIProtSink
, |
385 IInternetBindInfo *pOIBindInfo, DWORD grfPI, HANDLE_PTR dwReserved) | 382 IInternetBindInfo *pOIBindInfo, DWORD grfPI, HANDLE_PTR dwReserved) |
386 { | 383 { |
387 ATLASSERT(m_spInternetProtocol != 0); | 384 ATLASSERT(m_spInternetProtocol != 0); |
388 if (!m_spInternetProtocol) | 385 if (!m_spInternetProtocol) |
389 { | 386 { |
390 return E_UNEXPECTED; | 387 return E_UNEXPECTED; |
391 } | 388 } |
392 | 389 |
393 return OnStart(szUrl, pOIProtSink, pOIBindInfo, grfPI, dwReserved, m_spInterne
tProtocol); | 390 return OnStart(szUrl, pOIProtSink, pOIBindInfo, grfPI, dwReserved, m_spInterne
tProtocol); |
394 } | 391 } |
395 | 392 |
396 STDMETHODIMP WBPassthru::Read(/* [in, out] */ void *pv,/* [in] */ ULONG cb,/* [o
ut] */ ULONG *pcbRead) | 393 STDMETHODIMP WBPassthru::Read(/* [in, out] */ void *pv,/* [in] */ ULONG cb,/* [o
ut] */ ULONG *pcbRead) |
397 { | 394 { |
398 WBPassthruSink* pSink = GetSink(); | 395 WBPassthruSink* pSink = GetSink(); |
399 return pSink->OnRead(pv, cb, pcbRead); | 396 return pSink->OnRead(pv, cb, pcbRead); |
400 } | 397 } |
LEFT | RIGHT |