Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-2015 Eyeo GmbH | 3 * Copyright (C) 2006-2015 Eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 20 matching lines...) Expand all Loading... | |
31 | 31 |
32 namespace | 32 namespace |
33 { | 33 { |
34 const std::string g_blockedByABPPage = "<!DOCTYPE html>" | 34 const std::string g_blockedByABPPage = "<!DOCTYPE html>" |
35 "<html>" | 35 "<html>" |
36 "<body>" | 36 "<body>" |
37 "<!-- blocked by AdblockPlus -->" | 37 "<!-- blocked by AdblockPlus -->" |
38 "</body>" | 38 "</body>" |
39 "</html>"; | 39 "</html>"; |
40 | 40 |
41 template <typename T> | |
42 T ASCIIStringToLower(const T& text) | |
43 { | |
44 T textlower; | |
45 std::transform(text.begin(), text.end(), std::back_inserter(textlower), | |
46 [](T::value_type ch) | |
47 { | |
48 return std::tolower(ch, std::locale()); | |
49 } | |
50 ); | |
51 return textlower; | |
52 } | |
53 | |
41 typedef AdblockPlus::FilterEngine::ContentType ContentType; | 54 typedef AdblockPlus::FilterEngine::ContentType ContentType; |
42 | 55 |
43 template <class T> | 56 template <class T> |
44 T ExtractHttpHeader(const T& allHeaders, const T& targetHeaderNameWithColon, c onst T& delimiter) | 57 T ExtractHttpHeader(const T& allHeaders, const T& targetHeaderNameWithColon, c onst T& delimiter) |
45 { | 58 { |
46 auto targetHeaderBeginsAt = allHeaders.find(targetHeaderNameWithColon); | 59 const T allHeadersLower = ASCIIStringToLower(allHeaders); |
60 auto targetHeaderBeginsAt = allHeadersLower.find(ASCIIStringToLower(targetHe aderNameWithColon)); | |
47 if (targetHeaderBeginsAt == T::npos) | 61 if (targetHeaderBeginsAt == T::npos) |
48 { | 62 { |
49 return T(); | 63 return T(); |
50 } | 64 } |
51 targetHeaderBeginsAt += targetHeaderNameWithColon.length(); | 65 targetHeaderBeginsAt += targetHeaderNameWithColon.length(); |
52 auto targetHeaderEndsAt = allHeaders.find(delimiter, targetHeaderBeginsAt); | 66 auto targetHeaderEndsAt = allHeadersLower.find(ASCIIStringToLower(delimiter) , targetHeaderBeginsAt); |
53 if (targetHeaderEndsAt == T::npos) | 67 if (targetHeaderEndsAt == T::npos) |
54 { | 68 { |
55 return T(); | 69 return T(); |
56 } | 70 } |
57 return allHeaders.substr(targetHeaderBeginsAt, targetHeaderEndsAt - targetHe aderBeginsAt); | 71 return allHeaders.substr(targetHeaderBeginsAt, targetHeaderEndsAt - targetHe aderBeginsAt); |
58 } | 72 } |
59 | 73 |
60 std::string ExtractHttpAcceptHeader(IInternetProtocol* internetProtocol) | 74 std::string ExtractHttpAcceptHeader(IInternetProtocol* internetProtocol) |
61 { | 75 { |
62 // Despite there being HTTP_QUERY_ACCEPT and other query info flags, they do n't work here, | 76 // Despite there being HTTP_QUERY_ACCEPT and other query info flags, they do n't work here, |
(...skipping 23 matching lines...) Expand all Loading... | |
86 | 100 |
87 bool IsXmlHttpRequest(const std::wstring& additionalHeaders) | 101 bool IsXmlHttpRequest(const std::wstring& additionalHeaders) |
88 { | 102 { |
89 auto requestedWithHeader = ExtractHttpHeader<std::wstring>(additionalHeaders , L"X-Requested-With:", L"\n"); | 103 auto requestedWithHeader = ExtractHttpHeader<std::wstring>(additionalHeaders , L"X-Requested-With:", L"\n"); |
90 return TrimString(requestedWithHeader) == L"XMLHttpRequest"; | 104 return TrimString(requestedWithHeader) == L"XMLHttpRequest"; |
91 } | 105 } |
92 } | 106 } |
93 | 107 |
94 WBPassthruSink::WBPassthruSink() | 108 WBPassthruSink::WBPassthruSink() |
95 : m_currentPositionOfSentPage(0) | 109 : m_currentPositionOfSentPage(0) |
96 , m_contentType(ContentType::CONTENT_TYPE_OTHER) | 110 , m_contentType(ContentType::CONTENT_TYPE_OTHER) |
Eric
2015/02/02 06:58:27
Removing member variables means removing initializ
| |
97 , m_isCustomResponse(false) | 111 , m_isCustomResponse(false) |
98 { | 112 { |
99 } | 113 } |
100 | 114 |
101 ContentType WBPassthruSink::GetContentTypeFromMimeType(const CString& mimeType) | 115 ContentType WBPassthruSink::GetContentTypeFromMimeType(const CString& mimeType) |
102 { | 116 { |
103 if (mimeType.Find(L"image/") >= 0) | 117 if (mimeType.Find(L"image/") >= 0) |
104 { | 118 { |
105 return ContentType::CONTENT_TYPE_IMAGE; | 119 return ContentType::CONTENT_TYPE_IMAGE; |
106 } | 120 } |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
293 return false; | 307 return false; |
294 } | 308 } |
295 | 309 |
296 STDMETHODIMP WBPassthruSink::BeginningTransaction(LPCWSTR szURL, LPCWSTR szHeade rs, DWORD dwReserved, LPWSTR* pszAdditionalHeaders) | 310 STDMETHODIMP WBPassthruSink::BeginningTransaction(LPCWSTR szURL, LPCWSTR szHeade rs, DWORD dwReserved, LPWSTR* pszAdditionalHeaders) |
297 { | 311 { |
298 if (!szURL) | 312 if (!szURL) |
299 { | 313 { |
300 return E_POINTER; | 314 return E_POINTER; |
301 } | 315 } |
302 std::wstring src = szURL; | 316 std::wstring src = szURL; |
317 UnescapeUrl(src); | |
303 DEBUG_GENERAL(ToCString(src)); | 318 DEBUG_GENERAL(ToCString(src)); |
304 | 319 |
305 std::string acceptHeader = ExtractHttpAcceptHeader(m_spTargetProtocol); | 320 std::string acceptHeader = ExtractHttpAcceptHeader(m_spTargetProtocol); |
306 | 321 |
307 if (pszAdditionalHeaders) | 322 if (pszAdditionalHeaders) |
308 { | 323 { |
309 *pszAdditionalHeaders = nullptr; | 324 *pszAdditionalHeaders = nullptr; |
310 } | 325 } |
311 | 326 |
312 CComPtr<IHttpNegotiate> httpNegotiate; | 327 CComPtr<IHttpNegotiate> httpNegotiate; |
313 QueryServiceFromClient(&httpNegotiate); | 328 QueryServiceFromClient(&httpNegotiate); |
314 // This fills the pszAdditionalHeaders with more headers. One of which is the Referer header, which we need. | 329 // This fills the pszAdditionalHeaders with more headers. One of which is the Referer header, which we need. |
315 // There doesn't seem to be any other way to get this header before the reques t has been made. | 330 // There doesn't seem to be any other way to get this header before the reques t has been made. |
316 HRESULT nativeHr = httpNegotiate ? httpNegotiate->BeginningTransaction(szURL, szHeaders, dwReserved, pszAdditionalHeaders) : S_OK; | 331 HRESULT nativeHr = httpNegotiate ? httpNegotiate->BeginningTransaction(szURL, szHeaders, dwReserved, pszAdditionalHeaders) : S_OK; |
317 | 332 |
318 if (pszAdditionalHeaders && *pszAdditionalHeaders) | 333 if (pszAdditionalHeaders && *pszAdditionalHeaders) |
319 { | 334 { |
320 m_boundDomain = ExtractHttpHeader<std::wstring>(*pszAdditionalHeaders, L"Ref erer:", L"\n"); | 335 m_boundDomain = ExtractHttpHeader<std::wstring>(*pszAdditionalHeaders, L"Ref erer:", L"\n"); |
321 } | 336 } |
322 m_boundDomain = TrimString(m_boundDomain); | 337 m_boundDomain = TrimString(m_boundDomain); |
323 m_contentType = GetContentType(ATL::CString(acceptHeader.c_str()), m_boundDoma in, src); | 338 m_contentType = GetContentType(ATL::CString(acceptHeader.c_str()), m_boundDoma in, src); |
Eric
2015/02/02 06:58:27
Declare this variable 'auto' on this line.
Well,
| |
324 | 339 |
325 CPluginTab* tab = CPluginClass::GetTab(::GetCurrentThreadId()); | 340 CPluginTab* tab = CPluginClass::GetTab(::GetCurrentThreadId()); |
326 CPluginClient* client = CPluginClient::GetInstance(); | 341 CPluginClient* client = CPluginClient::GetInstance(); |
327 | 342 |
328 if (tab && client) | 343 if (tab && client) |
329 { | 344 { |
330 std::wstring documentUrl = tab->GetDocumentUrl(); | 345 std::wstring documentUrl = tab->GetDocumentUrl(); |
331 // Page is identical to document => don't block | 346 // Page is identical to document => don't block |
332 if (documentUrl == src) | 347 if (documentUrl == src) |
333 { | 348 { |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
410 } | 425 } |
411 | 426 |
412 return OnStart(szUrl, pOIProtSink, pOIBindInfo, grfPI, dwReserved, m_spInterne tProtocol); | 427 return OnStart(szUrl, pOIProtSink, pOIBindInfo, grfPI, dwReserved, m_spInterne tProtocol); |
413 } | 428 } |
414 | 429 |
415 STDMETHODIMP WBPassthru::Read(/* [in, out] */ void *pv,/* [in] */ ULONG cb,/* [o ut] */ ULONG *pcbRead) | 430 STDMETHODIMP WBPassthru::Read(/* [in, out] */ void *pv,/* [in] */ ULONG cb,/* [o ut] */ ULONG *pcbRead) |
416 { | 431 { |
417 WBPassthruSink* pSink = GetSink(); | 432 WBPassthruSink* pSink = GetSink(); |
418 return pSink->OnRead(pv, cb, pcbRead); | 433 return pSink->OnRead(pv, cb, pcbRead); |
419 } | 434 } |
LEFT | RIGHT |