| 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 124 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 std::wstring& mimeT
ype) | 145 namespace |
| 146 { | 146 { |
| 147 if ((mimeType.find(L"text/html") != std::wstring::npos) || | 147 /** |
| 148 (mimeType.find(L"application/xhtml+xml") != std::wstring::npos)) | 148 * Heuristic to infer an ABP content type from the media type list of an Accep
t: header field. |
| 149 * |
| 150 * Known IE Accept: strings for documents and images: |
| 151 * text/html, application/xhtml+xml, image/jxr, *\/* |
| 152 * image/png, image/svg+xml, image/jxr, image/*;q=0.8, *\/*;q = 0.5 |
| 153 * In IE9 the image/jxr part is missing. |
| 154 */ |
| 155 ContentType InferContentTypeFromMediaTypeList(const std::wstring& mediaTypeLis
t) |
| 149 { | 156 { |
| 150 return ContentType::CONTENT_TYPE_SUBDOCUMENT; | 157 if ((mediaTypeList.find(L"text/html") != std::wstring::npos) || |
| 151 } | 158 (mediaTypeList.find(L"application/xhtml+xml") != std::wstring::npos)) |
| 152 if (mimeType.find(L"image/") != std::wstring::npos) | 159 { |
| 153 { | 160 return ContentType::CONTENT_TYPE_SUBDOCUMENT; |
| 154 return ContentType::CONTENT_TYPE_IMAGE; | 161 } |
| 155 } | 162 if (mediaTypeList.find(L"image/") != std::wstring::npos) |
| 156 if (mimeType.find(L"text/css") != std::wstring::npos) | 163 { |
| 157 { | 164 return ContentType::CONTENT_TYPE_IMAGE; |
| 158 return ContentType::CONTENT_TYPE_STYLESHEET; | 165 } |
| 159 } | 166 if (mediaTypeList.find(L"text/css") != std::wstring::npos) |
| 160 if ((mimeType.find(L"application/javascript") != std::wstring::npos) || (mimeT
ype.find(L"application/json") != std::wstring::npos)) | 167 { |
| 161 { | 168 return ContentType::CONTENT_TYPE_STYLESHEET; |
| 162 return ContentType::CONTENT_TYPE_SCRIPT; | 169 } |
| 163 } | 170 if ((mediaTypeList.find(L"application/javascript") != std::wstring::npos) ||
(mediaTypeList.find(L"application/json") != std::wstring::npos)) |
| 164 if (mimeType.find(L"application/x-shockwave-flash") != std::wstring::npos) | 171 { |
| 165 { | 172 return ContentType::CONTENT_TYPE_SCRIPT; |
| 166 return ContentType::CONTENT_TYPE_OBJECT; | 173 } |
| 167 } | 174 if (mediaTypeList.find(L"application/x-shockwave-flash") != std::wstring::np
os) |
| 168 // It is important to have this check last, since it is rather generic, and mi
ght overlay text/html, for example | 175 { |
| 169 if (mimeType.find(L"xml") != std::wstring::npos) | 176 return ContentType::CONTENT_TYPE_OBJECT; |
| 170 { | 177 } |
| 171 return ContentType::CONTENT_TYPE_XMLHTTPREQUEST; | 178 // It is important to have this check last, since it is rather generic, and
might overlay text/html, for example |
| 179 if (mediaTypeList.find(L"xml") != std::wstring::npos) |
| 180 { |
| 181 return ContentType::CONTENT_TYPE_XMLHTTPREQUEST; |
| 182 } |
| 183 return ContentType::CONTENT_TYPE_OTHER; |
| 172 } | 184 } |
| 173 | 185 |
| 174 return ContentType::CONTENT_TYPE_OTHER; | 186 ContentType InferContentTypeFromUrl(const std::wstring& src) |
| 175 } | 187 { |
| 188 std::wstring schemeAndHierarchicalPart = GetSchemeAndHierarchicalPart(src); |
| 189 auto contentType = GetContentTypeFromString(schemeAndHierarchicalPart); |
| 190 if (contentType == ContentType::CONTENT_TYPE_OTHER && |
| 191 AdblockPlus::IE::InstalledMajorVersion() == 8) |
| 192 { |
| 193 std::wstring queryString = GetQueryString(src); |
| 194 wchar_t* nextToken = nullptr; |
| 195 const wchar_t* token = wcstok_s(&queryString[0], L"&=", &nextToken); |
| 196 while (token != nullptr) |
| 197 { |
| 198 contentType = GetContentTypeFromString(token); |
| 199 if (contentType != ContentType::CONTENT_TYPE_OTHER) |
| 200 { |
| 201 return contentType; |
| 202 } |
| 203 token = wcstok_s(nullptr, L"&=", &nextToken); |
| 204 } |
| 205 } |
| 206 return contentType; |
| 207 } |
| 176 | 208 |
| 177 ContentType WBPassthruSink::GetContentTypeFromURL(const std::wstring& src) | 209 ContentType InferContentType(const std::wstring& mediaTypeList, const std::wst
ring& domain, const std::wstring& src) |
| 178 { | |
| 179 std::wstring schemeAndHierarchicalPart = GetSchemeAndHierarchicalPart(src); | |
| 180 auto contentType = GetContentTypeFromString(schemeAndHierarchicalPart); | |
| 181 if (contentType == ContentType::CONTENT_TYPE_OTHER && | |
| 182 AdblockPlus::IE::InstalledMajorVersion() == 8) | |
| 183 { | 210 { |
| 184 std::wstring queryString = GetQueryString(src); | 211 // No referer or mime type |
| 185 wchar_t* nextToken = nullptr; | 212 // BINDSTRING_XDR_ORIGIN works only for IE v8+ |
| 186 const wchar_t* token = wcstok_s(&queryString[0], L"&=", &nextToken); | 213 if (mediaTypeList.empty() && domain.empty() && AdblockPlus::IE::InstalledMaj
orVersion() >= 8) |
| 187 while (token != nullptr) | |
| 188 { | 214 { |
| 189 contentType = GetContentTypeFromString(token); | 215 return ContentType::CONTENT_TYPE_XMLHTTPREQUEST; |
| 190 if (contentType != ContentType::CONTENT_TYPE_OTHER) | |
| 191 { | |
| 192 return contentType; | |
| 193 } | |
| 194 token = wcstok_s(nullptr, L"&=", &nextToken); | |
| 195 } | 216 } |
| 217 ContentType contentType = InferContentTypeFromMediaTypeList(mediaTypeList); |
| 218 if (contentType == ContentType::CONTENT_TYPE_OTHER) |
| 219 { |
| 220 contentType = InferContentTypeFromUrl(src); |
| 221 } |
| 222 return contentType; |
| 196 } | 223 } |
| 197 return contentType; | |
| 198 } | |
| 199 | |
| 200 ContentType WBPassthruSink::GetContentType(const std::wstring& mimeType, const s
td::wstring& domain, const std::wstring& src) | |
| 201 { | |
| 202 // No referer or mime type | |
| 203 // BINDSTRING_XDR_ORIGIN works only for IE v8+ | |
| 204 if (mimeType.empty() && domain.empty() && AdblockPlus::IE::InstalledMajorVersi
on() >= 8) | |
| 205 { | |
| 206 return ContentType::CONTENT_TYPE_XMLHTTPREQUEST; | |
| 207 } | |
| 208 ContentType contentType = GetContentTypeFromMimeType(mimeType); | |
| 209 if (contentType == ContentType::CONTENT_TYPE_OTHER) | |
| 210 { | |
| 211 contentType = GetContentTypeFromURL(src); | |
| 212 } | |
| 213 return contentType; | |
| 214 } | 224 } |
| 215 | 225 |
| 216 ////////////////////////////////////////////////////////////////////////////////
//////// | 226 ////////////////////////////////////////////////////////////////////////////////
//////// |
| 217 //WBPassthruSink | 227 //WBPassthruSink |
| 218 //Monitor and/or cancel every request and responde | 228 //Monitor and/or cancel every request and responde |
| 219 //WB makes, including images, sounds, scripts, etc | 229 //WB makes, including images, sounds, scripts, etc |
| 220 ////////////////////////////////////////////////////////////////////////////////
//////// | 230 ////////////////////////////////////////////////////////////////////////////////
//////// |
| 221 HRESULT WBPassthruSink::OnStart(LPCWSTR szUrl, IInternetProtocolSink *pOIProtSin
k, | 231 HRESULT WBPassthruSink::OnStart(LPCWSTR szUrl, IInternetProtocolSink *pOIProtSin
k, |
| 222 IInternetBindInfo *pOIBindInfo, DWORD grfPI, HAN
DLE_PTR dwReserved, | 232 IInternetBindInfo *pOIBindInfo, DWORD grfPI, HAN
DLE_PTR dwReserved, |
| 223 IInternetProtocol* pTargetProtocol) | 233 IInternetProtocol* pTargetProtocol) |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 QueryServiceFromClient(&httpNegotiate); | 347 QueryServiceFromClient(&httpNegotiate); |
| 338 // This fills the pszAdditionalHeaders with more headers. One of which is the
Referer header, which we need. | 348 // This fills the pszAdditionalHeaders with more headers. One of which is the
Referer header, which we need. |
| 339 // There doesn't seem to be any other way to get this header before the reques
t has been made. | 349 // There doesn't seem to be any other way to get this header before the reques
t has been made. |
| 340 HRESULT nativeHr = httpNegotiate ? httpNegotiate->BeginningTransaction(szURL,
szHeaders, dwReserved, pszAdditionalHeaders) : S_OK; | 350 HRESULT nativeHr = httpNegotiate ? httpNegotiate->BeginningTransaction(szURL,
szHeaders, dwReserved, pszAdditionalHeaders) : S_OK; |
| 341 | 351 |
| 342 if (pszAdditionalHeaders && *pszAdditionalHeaders) | 352 if (pszAdditionalHeaders && *pszAdditionalHeaders) |
| 343 { | 353 { |
| 344 m_boundDomain = ExtractHttpHeader<std::wstring>(*pszAdditionalHeaders, L"Ref
erer:", L"\n"); | 354 m_boundDomain = ExtractHttpHeader<std::wstring>(*pszAdditionalHeaders, L"Ref
erer:", L"\n"); |
| 345 } | 355 } |
| 346 m_boundDomain = TrimString(m_boundDomain); | 356 m_boundDomain = TrimString(m_boundDomain); |
| 347 m_contentType = GetContentType(ToUtf16String(ExtractHttpAcceptHeader(m_spTarge
tProtocol)), m_boundDomain, src); | 357 m_contentType = InferContentType(ToUtf16String(ExtractHttpAcceptHeader(m_spTar
getProtocol)), m_boundDomain, src); |
| 348 | 358 |
| 349 CPluginTab* tab = CPluginClass::GetTab(::GetCurrentThreadId()); | 359 CPluginTab* tab = CPluginClass::GetTab(::GetCurrentThreadId()); |
| 350 CPluginClient* client = CPluginClient::GetInstance(); | 360 CPluginClient* client = CPluginClient::GetInstance(); |
| 351 | 361 |
| 352 if (tab && client) | 362 if (tab && client) |
| 353 { | 363 { |
| 354 std::wstring documentUrl = tab->GetDocumentUrl(); | 364 std::wstring documentUrl = tab->GetDocumentUrl(); |
| 355 // Page is identical to document => don't block | 365 // Page is identical to document => don't block |
| 356 if (documentUrl == src) | 366 if (documentUrl == src) |
| 357 { | 367 { |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 } | 444 } |
| 435 | 445 |
| 436 return OnStart(szUrl, pOIProtSink, pOIBindInfo, grfPI, dwReserved, m_spInterne
tProtocol); | 446 return OnStart(szUrl, pOIProtSink, pOIBindInfo, grfPI, dwReserved, m_spInterne
tProtocol); |
| 437 } | 447 } |
| 438 | 448 |
| 439 STDMETHODIMP WBPassthru::Read(/* [in, out] */ void *pv,/* [in] */ ULONG cb,/* [o
ut] */ ULONG *pcbRead) | 449 STDMETHODIMP WBPassthru::Read(/* [in, out] */ void *pv,/* [in] */ ULONG cb,/* [o
ut] */ ULONG *pcbRead) |
| 440 { | 450 { |
| 441 WBPassthruSink* pSink = GetSink(); | 451 WBPassthruSink* pSink = GetSink(); |
| 442 return pSink->OnRead(pv, cb, pcbRead); | 452 return pSink->OnRead(pv, cb, pcbRead); |
| 443 } | 453 } |
| OLD | NEW |