Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: src/plugin/PluginWbPassThrough.cpp

Issue 5020125841326080: Issue 1669 - Report blocked object subrequests as failed, not as empty HTML (Closed)
Patch Set: Added comment Created Dec. 9, 2014, 10:27 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/plugin/PluginWbPassThrough.h ('k') | src/plugin/SinkPolicy.inl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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)
335 { 334 {
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 return S_OK; 370 return S_OK;
367 } 371 }
368 return BaseClass::ReportResult(hrResult, dwError, szResult); 372 return BaseClass::ReportResult(hrResult, dwError, szResult);
369 } 373 }
370 374
371 375
(...skipping 12 matching lines...) Expand all
384 } 388 }
385 389
386 return OnStart(szUrl, pOIProtSink, pOIBindInfo, grfPI, dwReserved, m_spInterne tProtocol); 390 return OnStart(szUrl, pOIProtSink, pOIBindInfo, grfPI, dwReserved, m_spInterne tProtocol);
387 } 391 }
388 392
389 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)
390 { 394 {
391 WBPassthruSink* pSink = GetSink(); 395 WBPassthruSink* pSink = GetSink();
392 return pSink->OnRead(pv, cb, pcbRead); 396 return pSink->OnRead(pv, cb, pcbRead);
393 } 397 }
OLDNEW
« no previous file with comments | « src/plugin/PluginWbPassThrough.h ('k') | src/plugin/SinkPolicy.inl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld