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

Delta Between Two Patch Sets: src/plugin/PluginWbPassThrough.cpp

Issue 6390087684194304: [superseded] Issue 1265 - Improve detection of mime type of the expected response (Closed)
Left Patch Set: Created Sept. 10, 2014, 7:34 a.m.
Right Patch Set: Fix missed support of other blocked types Created Sept. 12, 2014, 7:54 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « src/plugin/PluginWbPassThrough.h ('k') | src/plugin/SinkPolicy.inl » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 #ifdef SUPPORT_FILTER 6 #ifdef SUPPORT_FILTER
7 #include "PluginFilter.h" 7 #include "PluginFilter.h"
8 #endif 8 #endif
9 #include "PluginSettings.h" 9 #include "PluginSettings.h"
10 #include "PluginClass.h" 10 #include "PluginClass.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 return CFilter::contentTypeScript; 43 return CFilter::contentTypeScript;
44 } 44 }
45 if (mimeType.Find(L"application/x-shockwave-flash") >= 0) 45 if (mimeType.Find(L"application/x-shockwave-flash") >= 0)
46 { 46 {
47 return CFilter::contentTypeObject; 47 return CFilter::contentTypeObject;
48 } 48 }
49 if (mimeType.Find(L"text/html") >= 0) 49 if (mimeType.Find(L"text/html") >= 0)
50 { 50 {
51 return CFilter::contentTypeSubdocument; 51 return CFilter::contentTypeSubdocument;
52 } 52 }
53 // It is important to have this check last, since it is rather generic, and mi ght overlay text/html, for example
54 if (mimeType.Find(L"xml") >= 0)
55 {
56 return CFilter::contentTypeXmlHttpRequest;
57 }
58
53 return CFilter::contentTypeAny; 59 return CFilter::contentTypeAny;
54 } 60 }
55 61
56 int WBPassthruSink::GetContentTypeFromURL(const CString& src) 62 int WBPassthruSink::GetContentTypeFromURL(const CString& src)
57 { 63 {
58 CString srcExt = src; 64 CString srcExt = src;
59 65
60 int pos = 0; 66 int pos = 0;
61 if ((pos = src.Find('?')) > 0) 67 if ((pos = src.Find('?')) > 0)
62 { 68 {
63 srcExt = src.Left(pos); 69 srcExt = src.Left(pos);
64 } 70 }
65 71
66 int lastDotIndex = srcExt.ReverseFind('.'); 72 int lastDotIndex = srcExt.ReverseFind('.');
67 if (lastDotIndex < 0) 73 if (lastDotIndex < 0)
68 return CFilter::contentTypeAny; 74 return CFilter::contentTypeAny;
69 CString ext = srcExt.Mid(lastDotIndex); 75 CString ext = srcExt.Mid(lastDotIndex);
70 if (ext == L".jpg" || ext == L".gif" || ext == L".png" || ext == L".jpeg") 76 if (ext == L".jpg" || ext == L".gif" || ext == L".png" || ext == L".jpeg")
71 { 77 {
72 return CFilter::contentTypeImage; 78 return CFilter::contentTypeImage;
73 } 79 }
74 else if (ext == L".css") 80 else if (ext == L".css")
75 { 81 {
76 return CFilter::contentTypeStyleSheet; 82 return CFilter::contentTypeStyleSheet;
77 } 83 }
78 else if (ext.Right(3) == L".js") 84 else if (ext.Right(3) == L".js")
79 { 85 {
80 return CFilter::contentTypeScript; 86 return CFilter::contentTypeScript;
87 }
88 else if (ext == L".xml")
89 {
90 return CFilter::contentTypeXmlHttpRequest;
81 } 91 }
82 else if (ext == L".swf") 92 else if (ext == L".swf")
83 { 93 {
84 return CFilter::contentTypeObject; 94 return CFilter::contentTypeObject;
85 } 95 }
86 else if (ext == L".jsp" || ext == L".php" || ext == L".html") 96 else if (ext == L".jsp" || ext == L".php" || ext == L".html")
87 { 97 {
88 return CFilter::contentTypeSubdocument; 98 return CFilter::contentTypeSubdocument;
89 } 99 }
90 return CFilter::contentTypeAny; 100 return CFilter::contentTypeAny;
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 } 184 }
175 else 185 else
176 #endif // SUPPORT_FRAME_CACHING 186 #endif // SUPPORT_FRAME_CACHING
177 { 187 {
178 m_contentType = GetContentType(mimeType, m_boundDomain, src); 188 m_contentType = GetContentType(mimeType, m_boundDomain, src);
179 } 189 }
180 } 190 }
181 191
182 } 192 }
183 193
184 if (nullptr == tab) 194 if (nullptr == tab)
Oleksandr 2014/10/01 09:15:39 I personally don't like yoda conditions, and I thi
185 { 195 {
186 m_contentType = GetContentType(mimeType, m_boundDomain, src); 196 m_contentType = GetContentType(mimeType, m_boundDomain, src);
187 } 197 }
188 198
189 if (nullptr != client 199 if (nullptr != client
190 && CFilter::EContentType::contentTypeAny != m_contentType 200 && CFilter::EContentType::contentTypeAny != m_contentType
Oleksandr 2014/09/11 08:58:54 This line is not clear to me. We can in theory blo
sergei 2014/09/11 09:53:25 If the type is `contentTypeAny` then the decision
191 && client->ShouldBlock(src, m_contentType, m_boundDomain, true)) 201 && client->ShouldBlock(src, m_contentType, m_boundDomain, true))
Oleksandr 2014/10/01 09:15:39 Comment about yoda conditions applies here as well
192 { 202 {
193 isBlocked = true; 203 isBlocked = true;
194 DEBUG_BLOCKER("Blocker::Blocking Http-request:" + src);
Oleksandr 2014/09/11 08:58:54 DEBUG_BLOCKER is broken here. Either use CPluginDe
sergei 2014/09/11 09:53:25 `client->ShouldBlock` already puts into the log. `
195 }
196 if (!isBlocked)
197 {
198 DEBUG_BLOCKER("Blocker::Ignoring Http-request:" + src)
Oleksandr 2014/09/11 08:58:54 CPluginDebug::DebugResultIgnoring here accordingly
sergei 2014/09/11 09:53:25 The same as above, deleted.
199 } 204 }
200 205
201 // For IE6 and earlier there is iframe back button issue, so avoid it. 206 // For IE6 and earlier there is iframe back button issue, so avoid it.
202 if (isBlocked && client->GetIEVersion() > 6) 207 if (isBlocked && client->GetIEVersion() > 6)
203 { 208 {
204 handled = true; 209 handled = true;
205 if (CFilter::EContentType::contentTypeImage == m_contentType) 210 if (CFilter::EContentType::contentTypeImage == m_contentType)
206 { 211 {
207 BaseClass::OnStart(szUrl, pOIProtSink, pOIBindInfo, grfPI, dwReserved, pTa rgetProtocol); 212 BaseClass::OnStart(szUrl, pOIProtSink, pOIBindInfo, grfPI, dwReserved, pTa rgetProtocol);
208 // IE shows a cross that img is not loaded 213 // IE shows a cross that img is not loaded
209 return INET_E_REDIRECT_FAILED; 214 return INET_E_REDIRECT_FAILED;
210 } 215 }
211 if (CFilter::EContentType::contentTypeSubdocument == m_contentType) 216 if (CFilter::EContentType::contentTypeSubdocument == m_contentType)
212 { 217 {
213 PassthroughAPP::CustomSinkStartPolicy<WBPassthru, WBPassthruSink>::GetProt ocol(this)->m_shouldSupplyCustomContent = true; 218 PassthroughAPP::CustomSinkStartPolicy<WBPassthru, WBPassthruSink>::GetProt ocol(this)->m_shouldSupplyCustomContent = true;
214 BaseClass::OnStart(szUrl, pOIProtSink, pOIBindInfo, grfPI, dwReserved, pTa rgetProtocol); 219 BaseClass::OnStart(szUrl, pOIProtSink, pOIBindInfo, grfPI, dwReserved, pTa rgetProtocol);
215 m_spInternetProtocolSink->ReportProgress(BINDSTATUS_MIMETYPEAVAILABLE, L"t ext/html"); 220 m_spInternetProtocolSink->ReportProgress(BINDSTATUS_MIMETYPEAVAILABLE, L"t ext/html");
216 m_spInternetProtocolSink->ReportData(BSCF_FIRSTDATANOTIFICATION, 0, static _cast<ULONG>(g_myPageBlocked.size())); 221 m_spInternetProtocolSink->ReportData(BSCF_FIRSTDATANOTIFICATION, 0, static _cast<ULONG>(g_myPageBlocked.size()));
217 return S_OK; 222 return S_OK;
218 } 223 }
219 if (CFilter::EContentType::contentTypeScript == m_contentType) 224 if (CFilter::EContentType::contentTypeScript == m_contentType)
220 { 225 {
221 BaseClass::OnStart(szUrl, pOIProtSink, pOIBindInfo, grfPI, dwReserved, pTa rgetProtocol); 226 BaseClass::OnStart(szUrl, pOIProtSink, pOIBindInfo, grfPI, dwReserved, pTa rgetProtocol);
222 m_spInternetProtocolSink->ReportProgress(BINDSTATUS_MIMETYPEAVAILABLE, L"t ext/javascript"); 227 m_spInternetProtocolSink->ReportProgress(BINDSTATUS_MIMETYPEAVAILABLE, L"t ext/javascript");
223 m_spInternetProtocolSink->ReportResult(INET_E_REDIRECTING, 301, L"data:"); 228 m_spInternetProtocolSink->ReportResult(INET_E_REDIRECTING, 301, L"data:");
224 return INET_E_REDIRECT_FAILED; 229 return INET_E_REDIRECT_FAILED;
225 } 230 }
226 if (CFilter::EContentType::contentTypeXmlHttpRequest == m_contentType) 231 if (CFilter::EContentType::contentTypeXmlHttpRequest == m_contentType)
Oleksandr 2014/10/01 09:15:39 Looks like we don't need a special case for conten
232 {
233 BaseClass::OnStart(szUrl, pOIProtSink, pOIBindInfo, grfPI, dwReserved, pTa rgetProtocol);
234 m_spInternetProtocolSink->ReportResult(INET_E_REDIRECTING, 301, L"data:");
235 return INET_E_REDIRECT_FAILED;
236 }
237 if (CFilter::EContentType::contentTypeAny != m_contentType)
227 { 238 {
228 BaseClass::OnStart(szUrl, pOIProtSink, pOIBindInfo, grfPI, dwReserved, pTa rgetProtocol); 239 BaseClass::OnStart(szUrl, pOIProtSink, pOIBindInfo, grfPI, dwReserved, pTa rgetProtocol);
229 m_spInternetProtocolSink->ReportResult(INET_E_REDIRECTING, 301, L"data:"); 240 m_spInternetProtocolSink->ReportResult(INET_E_REDIRECTING, 301, L"data:");
Oleksandr 2014/10/01 09:15:39 I don't think redirecting all requests to 'data:'
230 return INET_E_REDIRECT_FAILED; 241 return INET_E_REDIRECT_FAILED;
231 } 242 }
232 } 243 }
233 #endif // SUPPORT_FILTER 244 #endif // SUPPORT_FILTER
234 245
235 return isBlocked ? S_FALSE : BaseClass::OnStart(szUrl, pOIProtSink, pOIBindInf o, grfPI, dwReserved, pTargetProtocol); 246 return isBlocked ? S_FALSE : BaseClass::OnStart(szUrl, pOIProtSink, pOIBindInf o, grfPI, dwReserved, pTargetProtocol);
236 } 247 }
237 248
238 HRESULT WBPassthruSink::OnRead(void* pv, ULONG cb, ULONG* pcbRead) 249 HRESULT WBPassthruSink::OnRead(void* pv, ULONG cb, ULONG* pcbRead)
239 { 250 {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 STDMETHODIMP WBPassthruSink::BeginningTransaction(LPCWSTR szURL, LPCWSTR szHeade rs, DWORD dwReserved, LPWSTR* pszAdditionalHeaders) 314 STDMETHODIMP WBPassthruSink::BeginningTransaction(LPCWSTR szURL, LPCWSTR szHeade rs, DWORD dwReserved, LPWSTR* pszAdditionalHeaders)
304 { 315 {
305 if (pszAdditionalHeaders) 316 if (pszAdditionalHeaders)
306 { 317 {
307 *pszAdditionalHeaders = nullptr; 318 *pszAdditionalHeaders = nullptr;
308 } 319 }
309 320
310 CPluginClient* client = nullptr; 321 CPluginClient* client = nullptr;
311 if (CFilter::EContentType::contentTypeAny == m_contentType && (client = CPlugi nClient::GetInstance())) 322 if (CFilter::EContentType::contentTypeAny == m_contentType && (client = CPlugi nClient::GetInstance()))
312 { 323 {
313 auto acceptHeader = [&]() -> std::string 324 auto acceptHeader = [&]() -> std::string
Oleksandr 2014/09/11 08:58:54 I'd just like to say this looks too cool :D
sergei 2014/09/11 09:53:25 Thanks!
314 { 325 {
315 ATL::CComPtr<IWinInetHttpInfo> winInetHttpInfo; 326 ATL::CComPtr<IWinInetHttpInfo> winInetHttpInfo;
316 HRESULT hr = m_spTargetProtocol->QueryInterface(&winInetHttpInfo); 327 HRESULT hr = m_spTargetProtocol->QueryInterface(&winInetHttpInfo);
317 if(FAILED(hr)) 328 if(FAILED(hr))
318 { 329 {
319 return ""; 330 return "";
320 } 331 }
321 DWORD size = 0; 332 DWORD size = 0;
322 DWORD flags = 0; 333 DWORD flags = 0;
323 hr = winInetHttpInfo->QueryInfo(HTTP_QUERY_RAW_HEADERS_CRLF | HTTP_QUERY_F LAG_REQUEST_HEADERS, 334 hr = winInetHttpInfo->QueryInfo(HTTP_QUERY_RAW_HEADERS_CRLF | HTTP_QUERY_F LAG_REQUEST_HEADERS,
(...skipping 17 matching lines...) Expand all
341 } 352 }
342 acceptHeaderBeginsAt += sizeof(acceptHeader); 353 acceptHeaderBeginsAt += sizeof(acceptHeader);
343 auto acceptHeaderEndsAt = buf.find("\n", acceptHeaderBeginsAt); 354 auto acceptHeaderEndsAt = buf.find("\n", acceptHeaderBeginsAt);
344 if (std::string::npos == acceptHeaderEndsAt) 355 if (std::string::npos == acceptHeaderEndsAt)
345 { 356 {
346 return ""; 357 return "";
347 } 358 }
348 return buf.substr(acceptHeaderBeginsAt, acceptHeaderEndsAt - acceptHeaderB eginsAt); 359 return buf.substr(acceptHeaderBeginsAt, acceptHeaderEndsAt - acceptHeaderB eginsAt);
349 }(); 360 }();
350 m_contentType = GetContentTypeFromMimeType(ATL::CString(acceptHeader.c_str() )); 361 m_contentType = GetContentTypeFromMimeType(ATL::CString(acceptHeader.c_str() ));
351 bool isBlocked = client->ShouldBlock(szURL, m_contentType, 362 bool isBlocked = client->ShouldBlock(szURL, m_contentType, m_boundDomain, /* debug flag but must be set*/true);
352 //client->GetHostFromUrl(m_boundDomain.operator LPCWSTR()).c_str(), /*debu g flag but must be set*/true);
Oleksandr 2014/09/11 08:58:54 Leftover code here?
sergei 2014/09/11 09:53:25 Thanks, removed.
353 m_boundDomain, /*debug flag but must be set*/true);
354 if (isBlocked) 363 if (isBlocked)
355 { 364 {
Oleksandr 2014/09/11 08:58:54 Log blocking here as well
sergei 2014/09/11 09:53:25 `client->ShouldBlock` puts into log
356 return E_ABORT; 365 return E_ABORT;
357 } 366 }
358 } 367 }
359 CComPtr<IHttpNegotiate> spHttpNegotiate; 368 CComPtr<IHttpNegotiate> spHttpNegotiate;
360 QueryServiceFromClient(&spHttpNegotiate); 369 QueryServiceFromClient(&spHttpNegotiate);
361 return spHttpNegotiate ? spHttpNegotiate->BeginningTransaction(szURL, szHeader s,dwReserved, pszAdditionalHeaders) : S_OK; 370 return spHttpNegotiate ? spHttpNegotiate->BeginningTransaction(szURL, szHeader s,dwReserved, pszAdditionalHeaders) : S_OK;
362 } 371 }
363 372
364 STDMETHODIMP WBPassthruSink::OnResponse(DWORD dwResponseCode, LPCWSTR szResponse Headers, LPCWSTR szRequestHeaders, LPWSTR *pszAdditionalRequestHeaders) 373 STDMETHODIMP WBPassthruSink::OnResponse(DWORD dwResponseCode, LPCWSTR szResponse Headers, LPCWSTR szRequestHeaders, LPWSTR *pszAdditionalRequestHeaders)
365 { 374 {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 } 421 }
413 422
414 STDMETHODIMP WBPassthru::UnlockRequest() 423 STDMETHODIMP WBPassthru::UnlockRequest()
415 { 424 {
416 if (m_shouldSupplyCustomContent) 425 if (m_shouldSupplyCustomContent)
417 { 426 {
418 return S_OK; 427 return S_OK;
419 } 428 }
420 return PassthroughAPP::CInternetProtocol<WBStartPolicy>::UnlockRequest(); 429 return PassthroughAPP::CInternetProtocol<WBStartPolicy>::UnlockRequest();
421 } 430 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld