| OLD | NEW |
| 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 22 matching lines...) Expand all Loading... |
| 33 "<!-- blocked by AdblockPlus -->" | 33 "<!-- blocked by AdblockPlus -->" |
| 34 "</body>" | 34 "</body>" |
| 35 "</html>"; | 35 "</html>"; |
| 36 | 36 |
| 37 template <typename T> | 37 template <typename T> |
| 38 T ASCIIStringToLower(const T& text) | 38 T ASCIIStringToLower(const T& text) |
| 39 { | 39 { |
| 40 T textlower; | 40 T textlower; |
| 41 std::transform(text.begin(), text.end(), std::back_inserter(textlower), | 41 std::transform(text.begin(), text.end(), std::back_inserter(textlower), |
| 42 [](T::value_type ch) | 42 [](T::value_type ch) |
| 43 » { | 43 { |
| 44 » return std::tolower(ch, std::locale()); | 44 return std::tolower(ch, std::locale()); |
| 45 » } | 45 } |
| 46 » ); | 46 ); |
| 47 return textlower; | 47 return textlower; |
| 48 } | 48 } |
| 49 | 49 |
| 50 typedef AdblockPlus::FilterEngine::ContentType ContentType; | 50 typedef AdblockPlus::FilterEngine::ContentType ContentType; |
| 51 | 51 |
| 52 template <class T> | 52 template <class T> |
| 53 T ExtractHttpHeader(const T& allHeaders, const T& targetHeaderNameWithColon, c
onst T& delimiter) | 53 T ExtractHttpHeader(const T& allHeaders, const T& targetHeaderNameWithColon, c
onst T& delimiter) |
| 54 { | 54 { |
| 55 const T allHeadersLower = ASCIIStringToLower(allHeaders); | 55 const T allHeadersLower = ASCIIStringToLower(allHeaders); |
| 56 auto targetHeaderBeginsAt = allHeadersLower.find(ASCIIStringToLower(targetHe
aderNameWithColon)); | 56 auto targetHeaderBeginsAt = allHeadersLower.find(ASCIIStringToLower(targetHe
aderNameWithColon)); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 } | 135 } |
| 136 } | 136 } |
| 137 | 137 |
| 138 WBPassthruSink::WBPassthruSink() | 138 WBPassthruSink::WBPassthruSink() |
| 139 : m_currentPositionOfSentPage(0) | 139 : m_currentPositionOfSentPage(0) |
| 140 , m_contentType(ContentType::CONTENT_TYPE_OTHER) | 140 , m_contentType(ContentType::CONTENT_TYPE_OTHER) |
| 141 , m_isCustomResponse(false) | 141 , m_isCustomResponse(false) |
| 142 { | 142 { |
| 143 } | 143 } |
| 144 | 144 |
| 145 ContentType WBPassthruSink::GetContentTypeFromMimeType(const CString& mimeType) | 145 ContentType WBPassthruSink::GetContentTypeFromMimeType(const std::wstring& mimeT
ype) |
| 146 { | 146 { |
| 147 if (mimeType.Find(L"image/") >= 0) | 147 if (mimeType.find(L"image/") != std::wstring::npos) |
| 148 { | 148 { |
| 149 return ContentType::CONTENT_TYPE_IMAGE; | 149 return ContentType::CONTENT_TYPE_IMAGE; |
| 150 } | 150 } |
| 151 if (mimeType.Find(L"text/css") >= 0) | 151 if (mimeType.find(L"text/css") != std::wstring::npos) |
| 152 { | 152 { |
| 153 return ContentType::CONTENT_TYPE_STYLESHEET; | 153 return ContentType::CONTENT_TYPE_STYLESHEET; |
| 154 } | 154 } |
| 155 if ((mimeType.Find(L"application/javascript") >= 0) || (mimeType.Find(L"applic
ation/json") >= 0)) | 155 if ((mimeType.find(L"application/javascript") != std::wstring::npos) || (mimeT
ype.find(L"application/json") != std::wstring::npos)) |
| 156 { | 156 { |
| 157 return ContentType::CONTENT_TYPE_SCRIPT; | 157 return ContentType::CONTENT_TYPE_SCRIPT; |
| 158 } | 158 } |
| 159 if (mimeType.Find(L"application/x-shockwave-flash") >= 0) | 159 if (mimeType.find(L"application/x-shockwave-flash") != std::wstring::npos) |
| 160 { | 160 { |
| 161 return ContentType::CONTENT_TYPE_OBJECT; | 161 return ContentType::CONTENT_TYPE_OBJECT; |
| 162 } | 162 } |
| 163 if (mimeType.Find(L"text/html") >= 0) | 163 if (mimeType.find(L"text/html") != std::wstring::npos) |
| 164 { | 164 { |
| 165 return ContentType::CONTENT_TYPE_SUBDOCUMENT; | 165 return ContentType::CONTENT_TYPE_SUBDOCUMENT; |
| 166 } | 166 } |
| 167 // It is important to have this check last, since it is rather generic, and mi
ght overlay text/html, for example | 167 // It is important to have this check last, since it is rather generic, and mi
ght overlay text/html, for example |
| 168 if (mimeType.Find(L"xml") >= 0) | 168 if (mimeType.find(L"xml") != std::wstring::npos) |
| 169 { | 169 { |
| 170 return ContentType::CONTENT_TYPE_XMLHTTPREQUEST; | 170 return ContentType::CONTENT_TYPE_XMLHTTPREQUEST; |
| 171 } | 171 } |
| 172 | 172 |
| 173 return ContentType::CONTENT_TYPE_OTHER; | 173 return ContentType::CONTENT_TYPE_OTHER; |
| 174 } | 174 } |
| 175 | 175 |
| 176 ContentType WBPassthruSink::GetContentTypeFromURL(const std::wstring& src) | 176 ContentType WBPassthruSink::GetContentTypeFromURL(const std::wstring& src) |
| 177 { | 177 { |
| 178 std::wstring schemeAndHierarchicalPart = GetSchemeAndHierarchicalPart(src); | 178 std::wstring schemeAndHierarchicalPart = GetSchemeAndHierarchicalPart(src); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 189 if (contentType != ContentType::CONTENT_TYPE_OTHER) | 189 if (contentType != ContentType::CONTENT_TYPE_OTHER) |
| 190 { | 190 { |
| 191 return contentType; | 191 return contentType; |
| 192 } | 192 } |
| 193 token = wcstok_s(nullptr, L"&=", &nextToken); | 193 token = wcstok_s(nullptr, L"&=", &nextToken); |
| 194 } | 194 } |
| 195 } | 195 } |
| 196 return contentType; | 196 return contentType; |
| 197 } | 197 } |
| 198 | 198 |
| 199 ContentType WBPassthruSink::GetContentType(const CString& mimeType, const std::w
string& domain, const std::wstring& src) | 199 ContentType WBPassthruSink::GetContentType(const std::wstring& mimeType, const s
td::wstring& domain, const std::wstring& src) |
| 200 { | 200 { |
| 201 // No referer or mime type | 201 // No referer or mime type |
| 202 // BINDSTRING_XDR_ORIGIN works only for IE v8+ | 202 // BINDSTRING_XDR_ORIGIN works only for IE v8+ |
| 203 if (mimeType.IsEmpty() && domain.empty() && AdblockPlus::IE::InstalledMajorVer
sion() >= 8) | 203 if (mimeType.empty() && domain.empty() && AdblockPlus::IE::InstalledMajorVersi
on() >= 8) |
| 204 { | 204 { |
| 205 return ContentType::CONTENT_TYPE_XMLHTTPREQUEST; | 205 return ContentType::CONTENT_TYPE_XMLHTTPREQUEST; |
| 206 } | 206 } |
| 207 ContentType contentType = GetContentTypeFromMimeType(mimeType); | 207 ContentType contentType = GetContentTypeFromMimeType(mimeType); |
| 208 if (contentType == ContentType::CONTENT_TYPE_OTHER) | 208 if (contentType == ContentType::CONTENT_TYPE_OTHER) |
| 209 { | 209 { |
| 210 contentType = GetContentTypeFromURL(src); | 210 contentType = GetContentTypeFromURL(src); |
| 211 } | 211 } |
| 212 return contentType; | 212 return contentType; |
| 213 } | 213 } |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 STDMETHODIMP WBPassthruSink::BeginningTransaction(LPCWSTR szURL, LPCWSTR szHeade
rs, DWORD dwReserved, LPWSTR* pszAdditionalHeaders) | 321 STDMETHODIMP WBPassthruSink::BeginningTransaction(LPCWSTR szURL, LPCWSTR szHeade
rs, DWORD dwReserved, LPWSTR* pszAdditionalHeaders) |
| 322 { | 322 { |
| 323 if (!szURL) | 323 if (!szURL) |
| 324 { | 324 { |
| 325 return E_POINTER; | 325 return E_POINTER; |
| 326 } | 326 } |
| 327 std::wstring src = szURL; | 327 std::wstring src = szURL; |
| 328 UnescapeUrl(src); | 328 UnescapeUrl(src); |
| 329 DEBUG_GENERAL(src); | 329 DEBUG_GENERAL(src); |
| 330 | 330 |
| 331 std::string acceptHeader = ExtractHttpAcceptHeader(m_spTargetProtocol); | |
| 332 | |
| 333 if (pszAdditionalHeaders) | 331 if (pszAdditionalHeaders) |
| 334 { | 332 { |
| 335 *pszAdditionalHeaders = nullptr; | 333 *pszAdditionalHeaders = nullptr; |
| 336 } | 334 } |
| 337 | 335 |
| 338 CComPtr<IHttpNegotiate> httpNegotiate; | 336 CComPtr<IHttpNegotiate> httpNegotiate; |
| 339 QueryServiceFromClient(&httpNegotiate); | 337 QueryServiceFromClient(&httpNegotiate); |
| 340 // This fills the pszAdditionalHeaders with more headers. One of which is the
Referer header, which we need. | 338 // This fills the pszAdditionalHeaders with more headers. One of which is the
Referer header, which we need. |
| 341 // There doesn't seem to be any other way to get this header before the reques
t has been made. | 339 // There doesn't seem to be any other way to get this header before the reques
t has been made. |
| 342 HRESULT nativeHr = httpNegotiate ? httpNegotiate->BeginningTransaction(szURL,
szHeaders, dwReserved, pszAdditionalHeaders) : S_OK; | 340 HRESULT nativeHr = httpNegotiate ? httpNegotiate->BeginningTransaction(szURL,
szHeaders, dwReserved, pszAdditionalHeaders) : S_OK; |
| 343 | 341 |
| 344 if (pszAdditionalHeaders && *pszAdditionalHeaders) | 342 if (pszAdditionalHeaders && *pszAdditionalHeaders) |
| 345 { | 343 { |
| 346 m_boundDomain = ExtractHttpHeader<std::wstring>(*pszAdditionalHeaders, L"Ref
erer:", L"\n"); | 344 m_boundDomain = ExtractHttpHeader<std::wstring>(*pszAdditionalHeaders, L"Ref
erer:", L"\n"); |
| 347 } | 345 } |
| 348 m_boundDomain = TrimString(m_boundDomain); | 346 m_boundDomain = TrimString(m_boundDomain); |
| 349 m_contentType = GetContentType(ATL::CString(acceptHeader.c_str()), m_boundDoma
in, src); | 347 m_contentType = GetContentType(ToUtf16String(ExtractHttpAcceptHeader(m_spTarge
tProtocol)), m_boundDomain, src); |
| 350 | 348 |
| 351 CPluginTab* tab = CPluginClass::GetTab(::GetCurrentThreadId()); | 349 CPluginTab* tab = CPluginClass::GetTab(::GetCurrentThreadId()); |
| 352 CPluginClient* client = CPluginClient::GetInstance(); | 350 CPluginClient* client = CPluginClient::GetInstance(); |
| 353 | 351 |
| 354 if (tab && client) | 352 if (tab && client) |
| 355 { | 353 { |
| 356 std::wstring documentUrl = tab->GetDocumentUrl(); | 354 std::wstring documentUrl = tab->GetDocumentUrl(); |
| 357 // Page is identical to document => don't block | 355 // Page is identical to document => don't block |
| 358 if (documentUrl == src) | 356 if (documentUrl == src) |
| 359 { | 357 { |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 436 } | 434 } |
| 437 | 435 |
| 438 return OnStart(szUrl, pOIProtSink, pOIBindInfo, grfPI, dwReserved, m_spInterne
tProtocol); | 436 return OnStart(szUrl, pOIProtSink, pOIBindInfo, grfPI, dwReserved, m_spInterne
tProtocol); |
| 439 } | 437 } |
| 440 | 438 |
| 441 STDMETHODIMP WBPassthru::Read(/* [in, out] */ void *pv,/* [in] */ ULONG cb,/* [o
ut] */ ULONG *pcbRead) | 439 STDMETHODIMP WBPassthru::Read(/* [in, out] */ void *pv,/* [in] */ ULONG cb,/* [o
ut] */ ULONG *pcbRead) |
| 442 { | 440 { |
| 443 WBPassthruSink* pSink = GetSink(); | 441 WBPassthruSink* pSink = GetSink(); |
| 444 return pSink->OnRead(pv, cb, pcbRead); | 442 return pSink->OnRead(pv, cb, pcbRead); |
| 445 } | 443 } |
| OLD | NEW |