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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 T textlower; | 44 T textlower; |
45 std::transform(text.begin(), text.end(), std::back_inserter(textlower), | 45 std::transform(text.begin(), text.end(), std::back_inserter(textlower), |
46 [](T::value_type ch) | 46 [](T::value_type ch) |
47 { | 47 { |
48 return std::tolower(ch, std::locale()); | 48 return std::tolower(ch, std::locale()); |
49 } | 49 } |
50 ); | 50 ); |
51 return textlower; | 51 return textlower; |
52 } | 52 } |
53 | 53 |
| 54 typedef AdblockPlus::FilterEngine::ContentType ContentType; |
| 55 |
54 template <class T> | 56 template <class T> |
55 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) |
56 { | 58 { |
57 const T allHeadersLower = ASCIIStringToLower(allHeaders); | 59 const T allHeadersLower = ASCIIStringToLower(allHeaders); |
58 auto targetHeaderBeginsAt = allHeadersLower.find(ASCIIStringToLower(targetHe
aderNameWithColon)); | 60 auto targetHeaderBeginsAt = allHeadersLower.find(ASCIIStringToLower(targetHe
aderNameWithColon)); |
59 if (targetHeaderBeginsAt == T::npos) | 61 if (targetHeaderBeginsAt == T::npos) |
60 { | 62 { |
61 return T(); | 63 return T(); |
62 } | 64 } |
63 targetHeaderBeginsAt += targetHeaderNameWithColon.length(); | 65 targetHeaderBeginsAt += targetHeaderNameWithColon.length(); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 | 100 |
99 bool IsXmlHttpRequest(const std::wstring& additionalHeaders) | 101 bool IsXmlHttpRequest(const std::wstring& additionalHeaders) |
100 { | 102 { |
101 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"); |
102 return TrimString(requestedWithHeader) == L"XMLHttpRequest"; | 104 return TrimString(requestedWithHeader) == L"XMLHttpRequest"; |
103 } | 105 } |
104 } | 106 } |
105 | 107 |
106 WBPassthruSink::WBPassthruSink() | 108 WBPassthruSink::WBPassthruSink() |
107 : m_currentPositionOfSentPage(0) | 109 : m_currentPositionOfSentPage(0) |
108 , m_contentType(CFilter::EContentType::contentTypeAny) | 110 , m_contentType(ContentType::CONTENT_TYPE_OTHER) |
109 , m_isCustomResponse(false) | 111 , m_isCustomResponse(false) |
110 { | 112 { |
111 } | 113 } |
112 | 114 |
113 int WBPassthruSink::GetContentTypeFromMimeType(const CString& mimeType) | 115 ContentType WBPassthruSink::GetContentTypeFromMimeType(const CString& mimeType) |
114 { | 116 { |
115 if (mimeType.Find(L"image/") >= 0) | 117 if (mimeType.Find(L"image/") >= 0) |
116 { | 118 { |
117 return CFilter::contentTypeImage; | 119 return ContentType::CONTENT_TYPE_IMAGE; |
118 } | 120 } |
119 if (mimeType.Find(L"text/css") >= 0) | 121 if (mimeType.Find(L"text/css") >= 0) |
120 { | 122 { |
121 return CFilter::contentTypeStyleSheet; | 123 return ContentType::CONTENT_TYPE_STYLESHEET; |
122 } | 124 } |
123 if ((mimeType.Find(L"application/javascript") >= 0) || (mimeType.Find(L"applic
ation/json") >= 0)) | 125 if ((mimeType.Find(L"application/javascript") >= 0) || (mimeType.Find(L"applic
ation/json") >= 0)) |
124 { | 126 { |
125 return CFilter::contentTypeScript; | 127 return ContentType::CONTENT_TYPE_SCRIPT; |
126 } | 128 } |
127 if (mimeType.Find(L"application/x-shockwave-flash") >= 0) | 129 if (mimeType.Find(L"application/x-shockwave-flash") >= 0) |
128 { | 130 { |
129 return CFilter::contentTypeObject; | 131 return ContentType::CONTENT_TYPE_OBJECT; |
130 } | 132 } |
131 if (mimeType.Find(L"text/html") >= 0) | 133 if (mimeType.Find(L"text/html") >= 0) |
132 { | 134 { |
133 return CFilter::contentTypeSubdocument; | 135 return ContentType::CONTENT_TYPE_SUBDOCUMENT; |
134 } | 136 } |
135 // It is important to have this check last, since it is rather generic, and mi
ght overlay text/html, for example | 137 // It is important to have this check last, since it is rather generic, and mi
ght overlay text/html, for example |
136 if (mimeType.Find(L"xml") >= 0) | 138 if (mimeType.Find(L"xml") >= 0) |
137 { | 139 { |
138 return CFilter::contentTypeXmlHttpRequest; | 140 return ContentType::CONTENT_TYPE_XMLHTTPREQUEST; |
139 } | 141 } |
140 | 142 |
141 return CFilter::contentTypeAny; | 143 return ContentType::CONTENT_TYPE_OTHER; |
142 } | 144 } |
143 | 145 |
144 int WBPassthruSink::GetContentTypeFromURL(const std::wstring& src) | 146 ContentType WBPassthruSink::GetContentTypeFromURL(const std::wstring& src) |
145 { | 147 { |
146 CString srcLegacy = ToCString(src); | 148 CString srcLegacy = ToCString(src); |
147 CString srcExt = srcLegacy; | 149 CString srcExt = srcLegacy; |
148 | 150 |
149 int pos = 0; | 151 int pos = 0; |
150 if ((pos = srcLegacy.Find('?')) > 0) | 152 if ((pos = srcLegacy.Find('?')) > 0) |
151 { | 153 { |
152 srcExt = srcLegacy.Left(pos); | 154 srcExt = srcLegacy.Left(pos); |
153 } | 155 } |
154 | 156 |
155 int lastDotIndex = srcExt.ReverseFind('.'); | 157 int lastDotIndex = srcExt.ReverseFind('.'); |
156 if (lastDotIndex < 0) | 158 if (lastDotIndex < 0) |
157 return CFilter::contentTypeAny; | 159 return ContentType::CONTENT_TYPE_OTHER; |
158 CString ext = srcExt.Mid(lastDotIndex); | 160 CString ext = srcExt.Mid(lastDotIndex); |
159 if (ext == L".jpg" || ext == L".gif" || ext == L".png" || ext == L".jpeg") | 161 if (ext == L".jpg" || ext == L".gif" || ext == L".png" || ext == L".jpeg") |
160 { | 162 { |
161 return CFilter::contentTypeImage; | 163 return ContentType::CONTENT_TYPE_IMAGE; |
162 } | 164 } |
163 else if (ext == L".css") | 165 else if (ext == L".css") |
164 { | 166 { |
165 return CFilter::contentTypeStyleSheet; | 167 return ContentType::CONTENT_TYPE_STYLESHEET; |
166 } | 168 } |
167 else if (ext.Right(3) == L".js") | 169 else if (ext.Right(3) == L".js") |
168 { | 170 { |
169 return CFilter::contentTypeScript; | 171 return ContentType::CONTENT_TYPE_SCRIPT; |
170 } | 172 } |
171 else if (ext == L".xml") | 173 else if (ext == L".xml") |
172 { | 174 { |
173 return CFilter::contentTypeXmlHttpRequest; | 175 return ContentType::CONTENT_TYPE_XMLHTTPREQUEST; |
174 } | 176 } |
175 else if (ext == L".swf") | 177 else if (ext == L".swf") |
176 { | 178 { |
177 return CFilter::contentTypeObject; | 179 return ContentType::CONTENT_TYPE_OBJECT; |
178 } | 180 } |
179 else if (ext == L".jsp" || ext == L".php" || ext == L".html") | 181 else if (ext == L".jsp" || ext == L".php" || ext == L".html") |
180 { | 182 { |
181 return CFilter::contentTypeSubdocument; | 183 return ContentType::CONTENT_TYPE_SUBDOCUMENT; |
182 } | 184 } |
183 return CFilter::contentTypeAny; | 185 return ContentType::CONTENT_TYPE_OTHER; |
184 } | 186 } |
185 | 187 |
186 int WBPassthruSink::GetContentType(const CString& mimeType, const std::wstring&
domain, const std::wstring& src) | 188 ContentType WBPassthruSink::GetContentType(const CString& mimeType, const std::w
string& domain, const std::wstring& src) |
187 { | 189 { |
188 // No referer or mime type | 190 // No referer or mime type |
189 // BINDSTRING_XDR_ORIGIN works only for IE v8+ | 191 // BINDSTRING_XDR_ORIGIN works only for IE v8+ |
190 if (mimeType.IsEmpty() && domain.empty() && AdblockPlus::IE::InstalledMajorVer
sion() >= 8) | 192 if (mimeType.IsEmpty() && domain.empty() && AdblockPlus::IE::InstalledMajorVer
sion() >= 8) |
191 { | 193 { |
192 return CFilter::contentTypeXmlHttpRequest; | 194 return ContentType::CONTENT_TYPE_XMLHTTPREQUEST; |
193 } | 195 } |
194 int contentType = GetContentTypeFromMimeType(mimeType); | 196 ContentType contentType = GetContentTypeFromMimeType(mimeType); |
195 if (contentType == CFilter::contentTypeAny) | 197 if (contentType == ContentType::CONTENT_TYPE_OTHER) |
196 { | 198 { |
197 contentType = GetContentTypeFromURL(src); | 199 contentType = GetContentTypeFromURL(src); |
198 } | 200 } |
199 return contentType; | 201 return contentType; |
200 } | 202 } |
201 | 203 |
202 ////////////////////////////////////////////////////////////////////////////////
//////// | 204 ////////////////////////////////////////////////////////////////////////////////
//////// |
203 //WBPassthruSink | 205 //WBPassthruSink |
204 //Monitor and/or cancel every request and responde | 206 //Monitor and/or cancel every request and responde |
205 //WB makes, including images, sounds, scripts, etc | 207 //WB makes, including images, sounds, scripts, etc |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 // 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. |
328 // 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. |
329 HRESULT nativeHr = httpNegotiate ? httpNegotiate->BeginningTransaction(szURL,
szHeaders, dwReserved, pszAdditionalHeaders) : S_OK; | 331 HRESULT nativeHr = httpNegotiate ? httpNegotiate->BeginningTransaction(szURL,
szHeaders, dwReserved, pszAdditionalHeaders) : S_OK; |
330 | 332 |
331 if (pszAdditionalHeaders && *pszAdditionalHeaders) | 333 if (pszAdditionalHeaders && *pszAdditionalHeaders) |
332 { | 334 { |
333 m_boundDomain = ExtractHttpHeader<std::wstring>(*pszAdditionalHeaders, L"Ref
erer:", L"\n"); | 335 m_boundDomain = ExtractHttpHeader<std::wstring>(*pszAdditionalHeaders, L"Ref
erer:", L"\n"); |
334 } | 336 } |
335 m_boundDomain = TrimString(m_boundDomain); | 337 m_boundDomain = TrimString(m_boundDomain); |
336 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); |
| 339 |
337 CPluginTab* tab = CPluginClass::GetTab(::GetCurrentThreadId()); | 340 CPluginTab* tab = CPluginClass::GetTab(::GetCurrentThreadId()); |
338 CPluginClient* client = CPluginClient::GetInstance(); | 341 CPluginClient* client = CPluginClient::GetInstance(); |
339 | 342 |
340 if (tab && client) | 343 if (tab && client) |
341 { | 344 { |
342 std::wstring documentUrl = tab->GetDocumentUrl(); | 345 std::wstring documentUrl = tab->GetDocumentUrl(); |
343 // Page is identical to document => don't block | 346 // Page is identical to document => don't block |
344 if (documentUrl == src) | 347 if (documentUrl == src) |
345 { | 348 { |
346 return nativeHr; | 349 return nativeHr; |
347 } | 350 } |
348 else if (CPluginSettings::GetInstance()->IsPluginEnabled() && !client->IsWhi
telistedUrl(documentUrl)) | 351 else if (CPluginSettings::GetInstance()->IsPluginEnabled() && !client->IsWhi
telistedUrl(documentUrl)) |
349 { | 352 { |
350 if (tab->IsFrameCached(src)) | 353 if (tab->IsFrameCached(src)) |
351 { | 354 { |
352 m_contentType = CFilter::contentTypeSubdocument; | 355 m_contentType = ContentType::CONTENT_TYPE_SUBDOCUMENT; |
353 } | 356 } |
354 } | 357 } |
355 } | 358 } |
356 | 359 |
357 if (IsFlashRequest(pszAdditionalHeaders)) | 360 if (IsFlashRequest(pszAdditionalHeaders)) |
358 { | 361 { |
359 m_contentType = CFilter::EContentType::contentTypeObjectSubrequest; | 362 m_contentType = ContentType::CONTENT_TYPE_OBJECT_SUBREQUEST; |
360 } | 363 } |
361 | 364 |
362 if (pszAdditionalHeaders && *pszAdditionalHeaders && IsXmlHttpRequest(*pszAddi
tionalHeaders)) | 365 if (pszAdditionalHeaders && *pszAdditionalHeaders && IsXmlHttpRequest(*pszAddi
tionalHeaders)) |
363 { | 366 { |
364 m_contentType = CFilter::EContentType::contentTypeXmlHttpRequest; | 367 m_contentType = ContentType::CONTENT_TYPE_XMLHTTPREQUEST; |
365 } | 368 } |
366 | 369 |
367 if (client->ShouldBlock(szURL, m_contentType, m_boundDomain, /*debug flag but
must be set*/true)) | 370 if (client->ShouldBlock(szURL, m_contentType, m_boundDomain, /*debug flag but
must be set*/true)) |
368 { | 371 { |
369 // NOTE: Feeding custom HTML to Flash, instead of original object subrequest | 372 // NOTE: Feeding custom HTML to Flash, instead of original object subrequest |
370 // doesn't have much sense. It also can manifest in unwanted result» | 373 // doesn't have much sense. It also can manifest in unwanted result |
371 // like video being blocked (See https://issues.adblockplus.org/ticket/1669)
» | 374 // like video being blocked (See https://issues.adblockplus.org/ticket/1669) |
372 // So we report blocked object subrequests as failed, not just empty HTML. | 375 // So we report blocked object subrequests as failed, not just empty HTML. |
373 m_isCustomResponse = m_contentType != CFilter::contentTypeObjectSubrequest; | 376 m_isCustomResponse = m_contentType != ContentType::CONTENT_TYPE_OBJECT_SUBRE
QUEST; |
374 return E_ABORT; | 377 return E_ABORT; |
375 } | 378 } |
376 return nativeHr; | 379 return nativeHr; |
377 } | 380 } |
378 | 381 |
379 STDMETHODIMP WBPassthruSink::OnResponse(DWORD dwResponseCode, LPCWSTR szResponse
Headers, LPCWSTR szRequestHeaders, LPWSTR *pszAdditionalRequestHeaders) | 382 STDMETHODIMP WBPassthruSink::OnResponse(DWORD dwResponseCode, LPCWSTR szResponse
Headers, LPCWSTR szRequestHeaders, LPWSTR *pszAdditionalRequestHeaders) |
380 { | 383 { |
381 if (pszAdditionalRequestHeaders) | 384 if (pszAdditionalRequestHeaders) |
382 { | 385 { |
383 *pszAdditionalRequestHeaders = 0; | 386 *pszAdditionalRequestHeaders = 0; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 } | 425 } |
423 | 426 |
424 return OnStart(szUrl, pOIProtSink, pOIBindInfo, grfPI, dwReserved, m_spInterne
tProtocol); | 427 return OnStart(szUrl, pOIProtSink, pOIBindInfo, grfPI, dwReserved, m_spInterne
tProtocol); |
425 } | 428 } |
426 | 429 |
427 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) |
428 { | 431 { |
429 WBPassthruSink* pSink = GetSink(); | 432 WBPassthruSink* pSink = GetSink(); |
430 return pSink->OnRead(pv, cb, pcbRead); | 433 return pSink->OnRead(pv, cb, pcbRead); |
431 } | 434 } |
OLD | NEW |