Left: | ||
Right: |
LEFT | RIGHT |
---|---|
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 const std::string g_blockedByABPPage = "<!DOCTYPE html>" | 16 std::string g_blockedByABPPage = "<!DOCTYPE html>" |
Oleksandr
2014/11/13 04:44:42
Unrelated change
sergei
2014/11/13 08:49:32
removed from here
| |
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 std::pair<T, bool> ExtractHttpHeader(const T& allHeaders, const T& targetHeade rNameWithColon, const T& delimiter) | 24 T ExtractHttpHeader(const T& allHeaders, const T& targetHeaderNameWithColon, c onst T& delimiter) |
Oleksandr
2014/11/13 04:44:42
Unrelated change. Also, I think was good enough as
sergei
2014/11/13 08:49:32
Right, it's not necessary. Reverted.
| |
25 { | 25 { |
26 std::pair<T, bool> notFoundHeader; | |
27 auto targetHeaderBeginsAt = allHeaders.find(targetHeaderNameWithColon); | 26 auto targetHeaderBeginsAt = allHeaders.find(targetHeaderNameWithColon); |
28 if (targetHeaderBeginsAt == T::npos) | 27 if (targetHeaderBeginsAt == T::npos) |
29 { | 28 { |
30 return notFoundHeader; | 29 return T(); |
31 } | 30 } |
32 targetHeaderBeginsAt += targetHeaderNameWithColon.length(); | 31 targetHeaderBeginsAt += targetHeaderNameWithColon.length(); |
33 auto targetHeaderEndsAt = allHeaders.find(delimiter, targetHeaderBeginsAt); | 32 auto targetHeaderEndsAt = allHeaders.find(delimiter, targetHeaderBeginsAt); |
34 if (targetHeaderEndsAt == T::npos) | 33 if (targetHeaderEndsAt == T::npos) |
35 { | 34 { |
36 return notFoundHeader; | 35 return T(); |
37 } | 36 } |
38 return std::make_pair(allHeaders.substr(targetHeaderBeginsAt, targetHeaderEn dsAt - targetHeaderBeginsAt), true); | 37 return allHeaders.substr(targetHeaderBeginsAt, targetHeaderEndsAt - targetHe aderBeginsAt); |
39 } | 38 } |
40 | 39 |
41 std::string ExtractHttpAcceptHeader(IInternetProtocol* internetProtocol) | 40 std::string ExtractHttpAcceptHeader(IInternetProtocol* internetProtocol) |
42 { | 41 { |
43 // 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, |
44 // 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. |
45 ATL::CComPtr<IWinInetHttpInfo> winInetHttpInfo; | 44 ATL::CComPtr<IWinInetHttpInfo> winInetHttpInfo; |
46 HRESULT hr = internetProtocol->QueryInterface(&winInetHttpInfo); | 45 HRESULT hr = internetProtocol->QueryInterface(&winInetHttpInfo); |
47 if (FAILED(hr)) | 46 if (FAILED(hr)) |
48 { | 47 { |
49 return ""; | 48 return ""; |
50 } | 49 } |
51 DWORD size = 0; | 50 DWORD size = 0; |
52 DWORD flags = 0; | 51 DWORD flags = 0; |
53 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; |
54 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); |
55 if (FAILED(hr)) | 54 if (FAILED(hr)) |
56 { | 55 { |
57 return ""; | 56 return ""; |
58 } | 57 } |
59 std::string buf(size, '\0'); | 58 std::string buf(size, '\0'); |
60 hr = winInetHttpInfo->QueryInfo(queryOption, &buf[0], &size, &flags, 0); | 59 hr = winInetHttpInfo->QueryInfo(queryOption, &buf[0], &size, &flags, 0); |
61 if (FAILED(hr)) | 60 if (FAILED(hr)) |
62 { | 61 { |
63 return ""; | 62 return ""; |
64 } | 63 } |
65 auto acceptHeader = ExtractHttpHeader<std::string>(buf, "Accept:", "\r\n"); | 64 return ExtractHttpHeader<std::string>(buf, "Accept:", "\r\n"); |
66 return acceptHeader.first; | |
67 } | |
68 | |
69 bool IsXmlHttpRequest(const std::wstring& additionalHeaders) | |
70 { | |
71 auto requestedWithHeader = ExtractHttpHeader<std::wstring>(additionalHeaders , L"X-Requested-With: ", L"\n"); | |
Oleksandr
2014/11/13 04:44:42
X-Requested-With is only part of the story, I thin
| |
72 return requestedWithHeader.second && TrimString(requestedWithHeader.first) = = L"XMLHttpRequest"; | |
73 } | 65 } |
74 } | 66 } |
75 | 67 |
76 WBPassthruSink::WBPassthruSink() | 68 WBPassthruSink::WBPassthruSink() |
77 : m_currentPositionOfSentPage(0) | 69 : m_currentPositionOfSentPage(0) |
78 , m_contentType(CFilter::EContentType::contentTypeAny) | 70 , m_contentType(CFilter::EContentType::contentTypeAny) |
79 , m_blockedInTransaction(false) | 71 , m_blockedInTransaction(false) |
80 { | 72 { |
81 } | 73 } |
82 | 74 |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
248 | 240 |
249 // This is the heuristic which detects the requests issued by Flash.ocx. | 241 // This is the heuristic which detects the requests issued by Flash.ocx. |
250 // It turned out that the implementation from ''Flash.ocx'' (tested version is 1 5.0.0.152) | 242 // It turned out that the implementation from ''Flash.ocx'' (tested version is 1 5.0.0.152) |
251 // returns quite minimal configuration in comparison with the implementation fro m Microsofts' | 243 // returns quite minimal configuration in comparison with the implementation fro m Microsofts' |
252 // libraries (see grfBINDF and bindInfo.dwOptions). The impl from MS often inclu des something | 244 // libraries (see grfBINDF and bindInfo.dwOptions). The impl from MS often inclu des something |
253 // else. | 245 // else. |
254 bool WBPassthruSink::IsFlashRequest(const wchar_t* const* additionalHeaders) | 246 bool WBPassthruSink::IsFlashRequest(const wchar_t* const* additionalHeaders) |
255 { | 247 { |
256 if (additionalHeaders && *additionalHeaders) | 248 if (additionalHeaders && *additionalHeaders) |
257 { | 249 { |
258 auto flashVersionHeader = ExtractHttpHeader<std::wstring>(*additionalHeaders , L"x-flash-version: ", L"\n"); | 250 auto flashVersionHeader = ExtractHttpHeader<std::wstring>(*additionalHeaders , L"x-flash-version:", L"\n"); |
259 if (flashVersionHeader.second) | 251 if (!TrimString(flashVersionHeader).empty()) |
260 { | 252 { |
261 return true; | 253 return true; |
262 } | 254 } |
263 } | 255 } |
264 ATL::CComPtr<IBindStatusCallback> bscb; | 256 ATL::CComPtr<IBindStatusCallback> bscb; |
265 if (SUCCEEDED(QueryServiceFromClient(&bscb)) && !!bscb) | 257 if (SUCCEEDED(QueryServiceFromClient(&bscb)) && !!bscb) |
266 { | 258 { |
267 DWORD grfBINDF = 0; | 259 DWORD grfBINDF = 0; |
268 BINDINFO bindInfo = {}; | 260 BINDINFO bindInfo = {}; |
269 bindInfo.cbSize = sizeof(bindInfo); | 261 bindInfo.cbSize = sizeof(bindInfo); |
270 if (SUCCEEDED(bscb->GetBindInfo(&grfBINDF, &bindInfo)) && | 262 if (SUCCEEDED(bscb->GetBindInfo(&grfBINDF, &bindInfo)) && |
271 (BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE| BINDF_PULLDATA) == grfBINDF && | 263 (BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE| BINDF_PULLDATA) == grfBINDF && |
272 (BINDINFO_OPTIONS_ENABLE_UTF8 | BINDINFO_OPTIONS_USE_IE_ENCODING) == bindI nfo.dwOptions | 264 (BINDINFO_OPTIONS_ENABLE_UTF8 | BINDINFO_OPTIONS_USE_IE_ENCODING) == bindI nfo.dwOptions |
273 ) | 265 ) |
274 { | 266 { |
275 return true; | 267 return true; |
276 } | 268 } |
277 } | 269 } |
278 return false; | 270 return false; |
279 } | 271 } |
280 | 272 |
281 STDMETHODIMP WBPassthruSink::BeginningTransaction(LPCWSTR szURL, LPCWSTR szHeade rs, DWORD dwReserved, LPWSTR* pszAdditionalHeaders) | 273 STDMETHODIMP WBPassthruSink::BeginningTransaction(LPCWSTR szURL, LPCWSTR szHeade rs, DWORD dwReserved, LPWSTR* pszAdditionalHeaders) |
282 { | 274 { |
283 if (!szURL || !szHeaders) | |
284 { | |
285 return E_POINTER; | |
286 } | |
Oleksandr
2014/11/13 04:44:42
Unrelated change.
sergei
2014/11/13 08:49:32
Removed from here.
| |
287 std::wstring src = szURL; | 275 std::wstring src = szURL; |
288 DEBUG_GENERAL(ToCString(src)); | 276 DEBUG_GENERAL(ToCString(src)); |
289 | 277 |
290 std::string acceptHeader = ExtractHttpAcceptHeader(m_spTargetProtocol); | 278 std::string acceptHeader = ExtractHttpAcceptHeader(m_spTargetProtocol); |
291 m_contentType = GetContentTypeFromMimeType(ATL::CString(acceptHeader.c_str())) ; | 279 m_contentType = GetContentTypeFromMimeType(ATL::CString(acceptHeader.c_str())) ; |
292 | 280 |
293 if (pszAdditionalHeaders) | 281 if (pszAdditionalHeaders) |
294 { | 282 { |
295 *pszAdditionalHeaders = nullptr; | 283 *pszAdditionalHeaders = nullptr; |
296 } | 284 } |
297 | 285 |
298 CComPtr<IHttpNegotiate> httpNegotiate; | 286 CComPtr<IHttpNegotiate> httpNegotiate; |
299 QueryServiceFromClient(&httpNegotiate); | 287 QueryServiceFromClient(&httpNegotiate); |
300 // This fills the pszAdditionalHeaders with more headers. One of which is the Referer header, which we need. | 288 // This fills the pszAdditionalHeaders with more headers. One of which is the Referer header, which we need. |
301 // There doesn't seem to be any other way to get this header before the reques t has been made. | 289 // There doesn't seem to be any other way to get this header before the reques t has been made. |
302 HRESULT nativeHr = httpNegotiate ? httpNegotiate->BeginningTransaction(szURL, szHeaders, dwReserved, pszAdditionalHeaders) : S_OK; | 290 HRESULT nativeHr = httpNegotiate ? httpNegotiate->BeginningTransaction(szURL, szHeaders, dwReserved, pszAdditionalHeaders) : S_OK; |
303 | 291 |
304 if (pszAdditionalHeaders && *pszAdditionalHeaders) | 292 if (pszAdditionalHeaders && *pszAdditionalHeaders) |
305 { | 293 { |
306 m_boundDomain = ExtractHttpHeader<std::wstring>(*pszAdditionalHeaders, L"Ref erer:", L"\n").first; | 294 m_boundDomain = ExtractHttpHeader<std::wstring>(*pszAdditionalHeaders, L"Ref erer:", L"\n"); |
307 } | 295 } |
308 m_boundDomain = TrimString(m_boundDomain); | 296 m_boundDomain = TrimString(m_boundDomain); |
309 CPluginTab* tab = CPluginClass::GetTab(::GetCurrentThreadId()); | 297 CPluginTab* tab = CPluginClass::GetTab(::GetCurrentThreadId()); |
310 CPluginClient* client = CPluginClient::GetInstance(); | 298 CPluginClient* client = CPluginClient::GetInstance(); |
311 | 299 |
312 if (tab && client) | 300 if (tab && client) |
313 { | 301 { |
314 CString documentUrl = tab->GetDocumentUrl(); | 302 CString documentUrl = tab->GetDocumentUrl(); |
315 // Page is identical to document => don't block | 303 // Page is identical to document => don't block |
316 if (documentUrl == ToCString(src)) | 304 if (documentUrl == ToCString(src)) |
317 { | 305 { |
318 return nativeHr; | 306 return nativeHr; |
319 } | 307 } |
320 else if (CPluginSettings::GetInstance()->IsPluginEnabled() && !client->IsWhi telistedUrl(std::wstring(documentUrl))) | 308 else if (CPluginSettings::GetInstance()->IsPluginEnabled() && !client->IsWhi telistedUrl(std::wstring(documentUrl))) |
321 { | 309 { |
322 if (tab->IsFrameCached(ToCString(src))) | 310 if (tab->IsFrameCached(ToCString(src))) |
323 { | 311 { |
324 m_contentType = CFilter::contentTypeSubdocument; | 312 m_contentType = CFilter::contentTypeSubdocument; |
325 } | 313 } |
326 } | 314 } |
327 } | 315 } |
328 | 316 |
329 if (IsFlashRequest(pszAdditionalHeaders)) | 317 if (IsFlashRequest(pszAdditionalHeaders)) |
330 { | 318 { |
331 m_contentType = CFilter::EContentType::contentTypeObjectSubrequest; | 319 m_contentType = CFilter::EContentType::contentTypeObjectSubrequest; |
332 } | |
333 | |
334 if (pszAdditionalHeaders && IsXmlHttpRequest(*pszAdditionalHeaders)) | |
335 { | |
336 m_contentType = CFilter::EContentType::contentTypeXmlHttpRequest; | |
337 } | 320 } |
338 | 321 |
339 m_blockedInTransaction = client->ShouldBlock(szURL, m_contentType, m_boundDoma in, /*debug flag but must be set*/true); | 322 m_blockedInTransaction = client->ShouldBlock(szURL, m_contentType, m_boundDoma in, /*debug flag but must be set*/true); |
340 if (m_blockedInTransaction) | 323 if (m_blockedInTransaction) |
341 { | 324 { |
342 return E_ABORT; | 325 return E_ABORT; |
343 } | 326 } |
344 return nativeHr; | 327 return nativeHr; |
345 } | 328 } |
346 | 329 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
400 | 383 |
401 STDMETHODIMP WBPassthru::LockRequest(/* [in] */ DWORD options) | 384 STDMETHODIMP WBPassthru::LockRequest(/* [in] */ DWORD options) |
402 { | 385 { |
403 return BaseClass::LockRequest(options); | 386 return BaseClass::LockRequest(options); |
404 } | 387 } |
405 | 388 |
406 STDMETHODIMP WBPassthru::UnlockRequest() | 389 STDMETHODIMP WBPassthru::UnlockRequest() |
407 { | 390 { |
408 return BaseClass::UnlockRequest(); | 391 return BaseClass::UnlockRequest(); |
409 } | 392 } |
LEFT | RIGHT |