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 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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 | 320 |
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 DEBUG_GENERAL(src); | 328 DEBUG_GENERAL(src); |
329 | 329 |
330 std::string acceptHeader = ExtractHttpAcceptHeader(m_spTargetProtocol); | |
331 | |
332 if (pszAdditionalHeaders) | 330 if (pszAdditionalHeaders) |
333 { | 331 { |
334 *pszAdditionalHeaders = nullptr; | 332 *pszAdditionalHeaders = nullptr; |
335 } | 333 } |
336 | 334 |
337 CComPtr<IHttpNegotiate> httpNegotiate; | 335 CComPtr<IHttpNegotiate> httpNegotiate; |
338 QueryServiceFromClient(&httpNegotiate); | 336 QueryServiceFromClient(&httpNegotiate); |
339 // This fills the pszAdditionalHeaders with more headers. One of which is the
Referer header, which we need. | 337 // This fills the pszAdditionalHeaders with more headers. One of which is the
Referer header, which we need. |
340 // There doesn't seem to be any other way to get this header before the reques
t has been made. | 338 // There doesn't seem to be any other way to get this header before the reques
t has been made. |
341 HRESULT nativeHr = httpNegotiate ? httpNegotiate->BeginningTransaction(szURL,
szHeaders, dwReserved, pszAdditionalHeaders) : S_OK; | 339 HRESULT nativeHr = httpNegotiate ? httpNegotiate->BeginningTransaction(szURL,
szHeaders, dwReserved, pszAdditionalHeaders) : S_OK; |
342 | 340 |
343 if (pszAdditionalHeaders && *pszAdditionalHeaders) | 341 if (pszAdditionalHeaders && *pszAdditionalHeaders) |
344 { | 342 { |
345 m_boundDomain = ExtractHttpHeader<std::wstring>(*pszAdditionalHeaders, L"Ref
erer:", L"\n"); | 343 m_boundDomain = ExtractHttpHeader<std::wstring>(*pszAdditionalHeaders, L"Ref
erer:", L"\n"); |
346 } | 344 } |
347 m_boundDomain = TrimString(m_boundDomain); | 345 m_boundDomain = TrimString(m_boundDomain); |
348 m_contentType = GetContentType(ATL::CString(acceptHeader.c_str()), m_boundDoma
in, src); | 346 m_contentType = GetContentType(ToUtf16String(ExtractHttpAcceptHeader(m_spTarge
tProtocol)), m_boundDomain, src); |
349 | 347 |
350 CPluginTab* tab = CPluginClass::GetTab(::GetCurrentThreadId()); | 348 CPluginTab* tab = CPluginClass::GetTab(::GetCurrentThreadId()); |
351 CPluginClient* client = CPluginClient::GetInstance(); | 349 CPluginClient* client = CPluginClient::GetInstance(); |
352 | 350 |
353 if (tab && client) | 351 if (tab && client) |
354 { | 352 { |
355 std::wstring documentUrl = tab->GetDocumentUrl(); | 353 std::wstring documentUrl = tab->GetDocumentUrl(); |
356 // Page is identical to document => don't block | 354 // Page is identical to document => don't block |
357 if (documentUrl == src) | 355 if (documentUrl == src) |
358 { | 356 { |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 } | 433 } |
436 | 434 |
437 return OnStart(szUrl, pOIProtSink, pOIBindInfo, grfPI, dwReserved, m_spInterne
tProtocol); | 435 return OnStart(szUrl, pOIProtSink, pOIBindInfo, grfPI, dwReserved, m_spInterne
tProtocol); |
438 } | 436 } |
439 | 437 |
440 STDMETHODIMP WBPassthru::Read(/* [in, out] */ void *pv,/* [in] */ ULONG cb,/* [o
ut] */ ULONG *pcbRead) | 438 STDMETHODIMP WBPassthru::Read(/* [in, out] */ void *pv,/* [in] */ ULONG cb,/* [o
ut] */ ULONG *pcbRead) |
441 { | 439 { |
442 WBPassthruSink* pSink = GetSink(); | 440 WBPassthruSink* pSink = GetSink(); |
443 return pSink->OnRead(pv, cb, pcbRead); | 441 return pSink->OnRead(pv, cb, pcbRead); |
444 } | 442 } |
LEFT | RIGHT |