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

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

Issue 4974480757620736: Issue #1356 - Improve detection of the issuer of the request (Closed)
Left Patch Set: Revert refactoring of ExtractHttpHeaders. Keeping it simple. Typo fixes. Created Nov. 4, 2014, 11:46 p.m.
Right Patch Set: Rename the parameter Created Nov. 5, 2014, 4:51 p.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 #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 13
14 namespace 14 namespace
15 { 15 {
16 std::string g_blockedByABPPage = "<!DOCTYPE html>" 16 std::string g_blockedByABPPage = "<!DOCTYPE html>"
17 "<html>" 17 "<html>"
18 "<body>" 18 "<body>"
19 "<!-- blocked by AdblockPlus -->" 19 "<!-- blocked by AdblockPlus -->"
20 "</body>" 20 "</body>"
21 "</html>"; 21 "</html>";
22 22
23 template <class T> 23 template <class T>
24 T ExtractHttpHeader(const T& allHeaders, const T& targetHeaderName, const T& d elimiter) 24 T ExtractHttpHeader(const T& allHeaders, const T& targetHeaderNameWithColon, c onst T& delimiter)
25 { 25 {
26 auto targetHeaderBeginsAt = allHeaders.find(targetHeaderName); 26 auto targetHeaderBeginsAt = allHeaders.find(targetHeaderNameWithColon);
27 if (targetHeaderBeginsAt == T::npos) 27 if (targetHeaderBeginsAt == T::npos)
28 { 28 {
29 return T(); 29 return T();
30 } 30 }
31 targetHeaderBeginsAt += targetHeaderName.length(); 31 targetHeaderBeginsAt += targetHeaderNameWithColon.length();
32 auto targetHeaderEndsAt = allHeaders.find(delimiter, targetHeaderBeginsAt); 32 auto targetHeaderEndsAt = allHeaders.find(delimiter, targetHeaderBeginsAt);
33 if (targetHeaderEndsAt == T::npos) 33 if (targetHeaderEndsAt == T::npos)
34 { 34 {
35 return T(); 35 return T();
36 } 36 }
37 return allHeaders.substr(targetHeaderBeginsAt, targetHeaderEndsAt - targetHe aderBeginsAt); 37 return allHeaders.substr(targetHeaderBeginsAt, targetHeaderEndsAt - targetHe aderBeginsAt);
38 } 38 }
39
39 std::string ExtractHttpAcceptHeader(IInternetProtocol* internetProtocol) 40 std::string ExtractHttpAcceptHeader(IInternetProtocol* internetProtocol)
sergei 2014/11/05 00:19:36 Would you shift this function one line below, so o
40 { 41 {
41 // Despite there being HTTP_QUERY_ACCEPT and other query info flags, they do n't work here, 42 // Despite there being HTTP_QUERY_ACCEPT and other query info flags, they do n't work here,
42 // only HTTP_QUERY_RAW_HEADERS_CRLF | HTTP_QUERY_FLAG_REQUEST_HEADERS does w ork. 43 // only HTTP_QUERY_RAW_HEADERS_CRLF | HTTP_QUERY_FLAG_REQUEST_HEADERS does w ork.
43 ATL::CComPtr<IWinInetHttpInfo> winInetHttpInfo; 44 ATL::CComPtr<IWinInetHttpInfo> winInetHttpInfo;
44 HRESULT hr = internetProtocol->QueryInterface(&winInetHttpInfo); 45 HRESULT hr = internetProtocol->QueryInterface(&winInetHttpInfo);
45 if (FAILED(hr)) 46 if (FAILED(hr))
46 { 47 {
47 return ""; 48 return "";
48 } 49 }
49 DWORD size = 0; 50 DWORD size = 0;
50 DWORD flags = 0; 51 DWORD flags = 0;
51 DWORD queryOption = HTTP_QUERY_RAW_HEADERS_CRLF | HTTP_QUERY_FLAG_REQUEST_HE ADERS; 52 DWORD queryOption = HTTP_QUERY_RAW_HEADERS_CRLF | HTTP_QUERY_FLAG_REQUEST_HE ADERS;
52 hr = winInetHttpInfo->QueryInfo(queryOption, /*buffer*/ nullptr, /*get size* / &size, &flags, /*reserved*/ 0); 53 hr = winInetHttpInfo->QueryInfo(queryOption, /*buffer*/ nullptr, /*get size* / &size, &flags, /*reserved*/ 0);
53 if (FAILED(hr)) 54 if (FAILED(hr))
54 { 55 {
55 return ""; 56 return "";
56 } 57 }
57 std::string buf(size, '\0'); 58 std::string buf(size, '\0');
58 hr = winInetHttpInfo->QueryInfo(queryOption, &buf[0], &size, &flags, 0); 59 hr = winInetHttpInfo->QueryInfo(queryOption, &buf[0], &size, &flags, 0);
59 if (FAILED(hr)) 60 if (FAILED(hr))
60 { 61 {
61 return ""; 62 return "";
62 } 63 }
63 return ExtractHttpHeader<std::string>(buf, std::string("Accept:"), "\r\n"); 64 return ExtractHttpHeader<std::string>(buf, "Accept:", "\r\n");
sergei 2014/11/05 00:19:36 It's not necessary to explicitly construct std::st
64 } 65 }
65
sergei 2014/11/05 00:19:36 this line
66 } 66 }
67 67
68 WBPassthruSink::WBPassthruSink() 68 WBPassthruSink::WBPassthruSink()
69 : m_currentPositionOfSentPage(0) 69 : m_currentPositionOfSentPage(0)
70 , m_contentType(CFilter::EContentType::contentTypeAny) 70 , m_contentType(CFilter::EContentType::contentTypeAny)
71 , m_blockedInTransaction(false) 71 , m_blockedInTransaction(false)
72 { 72 {
73 } 73 }
74 74
75 int WBPassthruSink::GetContentTypeFromMimeType(const CString& mimeType) 75 int WBPassthruSink::GetContentTypeFromMimeType(const CString& mimeType)
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 ) 257 )
258 { 258 {
259 return true; 259 return true;
260 } 260 }
261 } 261 }
262 return false; 262 return false;
263 } 263 }
264 264
265 STDMETHODIMP WBPassthruSink::BeginningTransaction(LPCWSTR szURL, LPCWSTR szHeade rs, DWORD dwReserved, LPWSTR* pszAdditionalHeaders) 265 STDMETHODIMP WBPassthruSink::BeginningTransaction(LPCWSTR szURL, LPCWSTR szHeade rs, DWORD dwReserved, LPWSTR* pszAdditionalHeaders)
266 { 266 {
267 if (pszAdditionalHeaders)
268 {
269 *pszAdditionalHeaders = nullptr;
270 }
271 std::wstring src = szURL; 267 std::wstring src = szURL;
272 DEBUG_GENERAL(ToCString(src)); 268 DEBUG_GENERAL(ToCString(src));
273 269
274 std::string acceptHeader = ExtractHttpAcceptHeader(m_spTargetProtocol); 270 std::string acceptHeader = ExtractHttpAcceptHeader(m_spTargetProtocol);
275 m_contentType = GetContentTypeFromMimeType(ATL::CString(acceptHeader.c_str())) ; 271 m_contentType = GetContentTypeFromMimeType(ATL::CString(acceptHeader.c_str())) ;
272
273 if (pszAdditionalHeaders)
274 {
275 *pszAdditionalHeaders = nullptr;
276 }
276 277
277 CComPtr<IHttpNegotiate> httpNegotiate; 278 CComPtr<IHttpNegotiate> httpNegotiate;
278 QueryServiceFromClient(&httpNegotiate); 279 QueryServiceFromClient(&httpNegotiate);
279 // This fills the pszAdditionalHeaders with more headers. One of which is the Referer header, which we need. 280 // This fills the pszAdditionalHeaders with more headers. One of which is the Referer header, which we need.
280 // There doesn't seem to be any other way to get this header before the reques t has been made. 281 // There doesn't seem to be any other way to get this header before the reques t has been made.
281 HRESULT nativeHr = httpNegotiate ? httpNegotiate->BeginningTransaction(szURL, szHeaders, dwReserved, pszAdditionalHeaders) : S_OK; 282 HRESULT nativeHr = httpNegotiate ? httpNegotiate->BeginningTransaction(szURL, szHeaders, dwReserved, pszAdditionalHeaders) : S_OK;
282 283
283 if (*pszAdditionalHeaders != 0) 284 if (*pszAdditionalHeaders != 0)
284 { 285 {
285 m_boundDomain = ExtractHttpHeader<std::wstring>(std::wstring(*pszAdditionalH eaders), std::wstring(L"Referer:"), L"\n").c_str(); 286 m_boundDomain = ExtractHttpHeader<std::wstring>(*pszAdditionalHeaders, L"Ref erer:", L"\n").c_str();
286 } 287 }
287 m_boundDomain = TrimString(m_boundDomain); 288 m_boundDomain = TrimString(m_boundDomain);
288 CPluginTab* tab = CPluginClass::GetTab(::GetCurrentThreadId()); 289 CPluginTab* tab = CPluginClass::GetTab(::GetCurrentThreadId());
289 CPluginClient* client = CPluginClient::GetInstance(); 290 CPluginClient* client = CPluginClient::GetInstance();
290 291
291 if (tab && client) 292 if (tab && client)
292 { 293 {
293 CString documentUrl = tab->GetDocumentUrl(); 294 CString documentUrl = tab->GetDocumentUrl();
294 // Page is identical to document => don't block 295 // Page is identical to document => don't block
295 if (documentUrl == ToCString(src)) 296 if (documentUrl == ToCString(src))
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 375
375 STDMETHODIMP WBPassthru::LockRequest(/* [in] */ DWORD options) 376 STDMETHODIMP WBPassthru::LockRequest(/* [in] */ DWORD options)
376 { 377 {
377 return BaseClass::LockRequest(options); 378 return BaseClass::LockRequest(options);
378 } 379 }
379 380
380 STDMETHODIMP WBPassthru::UnlockRequest() 381 STDMETHODIMP WBPassthru::UnlockRequest()
381 { 382 {
382 return BaseClass::UnlockRequest(); 383 return BaseClass::UnlockRequest();
383 } 384 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld