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: Coding style changes Created Nov. 5, 2014, 12:25 a.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);
Felix Dahlke 2014/11/05 09:04:52 I still find it unintuitive that the colon is part
Oleksandr 2014/11/05 10:01:58 1. Colon is part of header name because this is a
sergei 2014/11/05 10:28:59 1. T is std::string or std::wstring. The variant w
Oleksandr 2014/11/05 16:42:50 Created https://issues.adblockplus.org/ticket/1529
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
40 std::string ExtractHttpAcceptHeader(IInternetProtocol* internetProtocol) 40 std::string ExtractHttpAcceptHeader(IInternetProtocol* internetProtocol)
41 { 41 {
(...skipping 215 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));
Felix Dahlke 2014/11/05 09:04:52 Hehe, still not quite what I meant :D Wouldn't it
Oleksandr 2014/11/05 10:01:58 That makes sense, yes.
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>(*pszAdditionalHeaders, L"Ref erer:", L"\n").c_str(); 286 m_boundDomain = ExtractHttpHeader<std::wstring>(*pszAdditionalHeaders, L"Ref erer:", L"\n").c_str();
(...skipping 88 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