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

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

Issue 5748224216268800: No issue - some cleanup in PluginWbPassThrough (Closed)
Patch Set: Created Nov. 13, 2014, 10:20 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') | no next file » | 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>
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 const 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& targetHeaderNameWithColon, c onst T& delimiter) 24 T ExtractHttpHeader(const T& allHeaders, const T& targetHeaderNameWithColon, c onst T& delimiter)
25 { 25 {
26 auto targetHeaderBeginsAt = allHeaders.find(targetHeaderNameWithColon); 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 += targetHeaderNameWithColon.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 {
42 // 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,
43 // 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.
44 ATL::CComPtr<IWinInetHttpInfo> winInetHttpInfo; 44 ATL::CComPtr<IWinInetHttpInfo> winInetHttpInfo;
45 HRESULT hr = internetProtocol->QueryInterface(&winInetHttpInfo); 45 HRESULT hr = internetProtocol->QueryInterface(&winInetHttpInfo);
46 if (FAILED(hr)) 46 if (FAILED(hr) || !winInetHttpInfo)
47 { 47 {
48 return ""; 48 return "";
49 } 49 }
50 DWORD size = 0; 50 DWORD size = 0;
51 DWORD flags = 0; 51 DWORD flags = 0;
52 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;
53 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);
54 if (FAILED(hr)) 54 if (FAILED(hr))
55 { 55 {
56 return ""; 56 return "";
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 HRESULT WBPassthruSink::OnStart(LPCWSTR szUrl, IInternetProtocolSink *pOIProtSin k, 174 HRESULT WBPassthruSink::OnStart(LPCWSTR szUrl, IInternetProtocolSink *pOIProtSin k,
175 IInternetBindInfo *pOIBindInfo, DWORD grfPI, HAN DLE_PTR dwReserved, 175 IInternetBindInfo *pOIBindInfo, DWORD grfPI, HAN DLE_PTR dwReserved,
176 IInternetProtocol* pTargetProtocol, bool& handle d) 176 IInternetProtocol* pTargetProtocol, bool& handle d)
177 { 177 {
178 m_pTargetProtocol = pTargetProtocol; 178 m_pTargetProtocol = pTargetProtocol;
179 return BaseClass::OnStart(szUrl, pOIProtSink, pOIBindInfo, grfPI, dwReserved, pTargetProtocol); 179 return BaseClass::OnStart(szUrl, pOIProtSink, pOIBindInfo, grfPI, dwReserved, pTargetProtocol);
180 } 180 }
181 181
182 HRESULT WBPassthruSink::OnRead(void* pv, ULONG cb, ULONG* pcbRead) 182 HRESULT WBPassthruSink::OnRead(void* pv, ULONG cb, ULONG* pcbRead)
183 { 183 {
184 if (pv == nullptr) 184 if (!pv || !pcbRead)
185 { 185 {
186 return E_POINTER; 186 return E_POINTER;
187 } 187 }
188 if (pcbRead == nullptr)
189 {
190 return E_POINTER;
191 }
192 *pcbRead = 0; 188 *pcbRead = 0;
193 189
194 if (PassthroughAPP::CustomSinkStartPolicy<WBPassthru, WBPassthruSink>::GetProt ocol(this)->m_shouldSupplyCustomContent) 190 if (PassthroughAPP::CustomSinkStartPolicy<WBPassthru, WBPassthruSink>::GetProt ocol(this)->m_shouldSupplyCustomContent)
195 { 191 {
196 ULONG blockedByABPPageSize = static_cast<ULONG>(g_blockedByABPPage.size()); 192 ULONG blockedByABPPageSize = static_cast<ULONG>(g_blockedByABPPage.size());
197 auto positionGrow = std::min<ULONG>(cb, static_cast<ULONG>(blockedByABPPageS ize - m_currentPositionOfSentPage)); 193 auto positionGrow = std::min<ULONG>(cb, static_cast<ULONG>(blockedByABPPageS ize - m_currentPositionOfSentPage));
198 if (positionGrow == 0) { 194 if (positionGrow == 0) {
199 return S_FALSE; 195 return S_FALSE;
200 } 196 }
201 std::copy(g_blockedByABPPage.begin(), g_blockedByABPPage.begin() + positionG row, 197 std::copy(g_blockedByABPPage.begin(), g_blockedByABPPage.begin() + positionG row,
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 ) 267 )
272 { 268 {
273 return true; 269 return true;
274 } 270 }
275 } 271 }
276 return false; 272 return false;
277 } 273 }
278 274
279 STDMETHODIMP WBPassthruSink::BeginningTransaction(LPCWSTR szURL, LPCWSTR szHeade rs, DWORD dwReserved, LPWSTR* pszAdditionalHeaders) 275 STDMETHODIMP WBPassthruSink::BeginningTransaction(LPCWSTR szURL, LPCWSTR szHeade rs, DWORD dwReserved, LPWSTR* pszAdditionalHeaders)
280 { 276 {
277 if (!szURL || !szHeaders)
Oleksandr 2014/11/19 02:34:59 Why can't szHeaders be nullptr? I think it may hap
sergei 2014/11/19 11:05:02 May be it can. I assumed that if it's [in] paramet
278 {
279 return E_POINTER;
280 }
281 std::wstring src = szURL; 281 std::wstring src = szURL;
282 DEBUG_GENERAL(ToCString(src)); 282 DEBUG_GENERAL(ToCString(src));
283 283
284 std::string acceptHeader = ExtractHttpAcceptHeader(m_spTargetProtocol); 284 std::string acceptHeader = ExtractHttpAcceptHeader(m_spTargetProtocol);
285 m_contentType = GetContentTypeFromMimeType(ATL::CString(acceptHeader.c_str())) ; 285 m_contentType = GetContentTypeFromMimeType(ATL::CString(acceptHeader.c_str())) ;
286 286
287 if (pszAdditionalHeaders) 287 if (pszAdditionalHeaders)
288 { 288 {
289 *pszAdditionalHeaders = nullptr; 289 *pszAdditionalHeaders = nullptr;
290 } 290 }
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 return E_UNEXPECTED; 383 return E_UNEXPECTED;
384 } 384 }
385 385
386 return OnStart(szUrl, pOIProtSink, pOIBindInfo, grfPI, dwReserved, m_spInterne tProtocol); 386 return OnStart(szUrl, pOIProtSink, pOIBindInfo, grfPI, dwReserved, m_spInterne tProtocol);
387 } 387 }
388 388
389 STDMETHODIMP WBPassthru::Read(/* [in, out] */ void *pv,/* [in] */ ULONG cb,/* [o ut] */ ULONG *pcbRead) 389 STDMETHODIMP WBPassthru::Read(/* [in, out] */ void *pv,/* [in] */ ULONG cb,/* [o ut] */ ULONG *pcbRead)
390 { 390 {
391 WBPassthruSink* pSink = GetSink(); 391 WBPassthruSink* pSink = GetSink();
392 return pSink->OnRead(pv, cb, pcbRead); 392 return pSink->OnRead(pv, cb, pcbRead);
393 }
394
395 STDMETHODIMP WBPassthru::LockRequest(/* [in] */ DWORD options)
396 {
397 return BaseClass::LockRequest(options);
398 }
399
400 STDMETHODIMP WBPassthru::UnlockRequest()
401 {
402 return BaseClass::UnlockRequest();
403 } 393 }
OLDNEW
« no previous file with comments | « src/plugin/PluginWbPassThrough.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld