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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 return ""; | 96 return ""; |
97 } | 97 } |
98 return ExtractHttpHeader<std::string>(buf, "Accept:", "\r\n"); | 98 return ExtractHttpHeader<std::string>(buf, "Accept:", "\r\n"); |
99 } | 99 } |
100 | 100 |
101 bool IsXmlHttpRequest(const std::wstring& additionalHeaders) | 101 bool IsXmlHttpRequest(const std::wstring& additionalHeaders) |
102 { | 102 { |
103 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"); |
104 return TrimString(requestedWithHeader) == L"XMLHttpRequest"; | 104 return TrimString(requestedWithHeader) == L"XMLHttpRequest"; |
105 } | 105 } |
| 106 |
| 107 ContentType GetContentTypeFromString(const std::wstring& value) |
| 108 { |
| 109 auto lastDotPos = value.rfind(L'.'); |
| 110 if (lastDotPos == std::wstring::npos) |
| 111 return ContentType::CONTENT_TYPE_OTHER; |
| 112 |
| 113 std::wstring ext = ASCIIStringToLower(value.substr(lastDotPos + 1)); |
| 114 if (ext == L"jpg" || ext == L"gif" || ext == L"png" || ext == L"jpeg") |
| 115 { |
| 116 return ContentType::CONTENT_TYPE_IMAGE; |
| 117 } |
| 118 else if (ext == L"css") |
| 119 { |
| 120 return ContentType::CONTENT_TYPE_STYLESHEET; |
| 121 } |
| 122 else if (ext == L"js") |
| 123 { |
| 124 return ContentType::CONTENT_TYPE_SCRIPT; |
| 125 } |
| 126 else if (ext == L"xml") |
| 127 { |
| 128 return ContentType::CONTENT_TYPE_XMLHTTPREQUEST; |
| 129 } |
| 130 else if (ext == L"swf") |
| 131 { |
| 132 return ContentType::CONTENT_TYPE_OBJECT; |
| 133 } |
| 134 else if (ext == L"jsp" || ext == L"php" || ext == L"html") |
| 135 { |
| 136 return ContentType::CONTENT_TYPE_SUBDOCUMENT; |
| 137 } |
| 138 return ContentType::CONTENT_TYPE_OTHER; |
| 139 } |
106 } | 140 } |
107 | 141 |
108 WBPassthruSink::WBPassthruSink() | 142 WBPassthruSink::WBPassthruSink() |
109 : m_currentPositionOfSentPage(0) | 143 : m_currentPositionOfSentPage(0) |
110 , m_contentType(ContentType::CONTENT_TYPE_OTHER) | 144 , m_contentType(ContentType::CONTENT_TYPE_OTHER) |
111 , m_isCustomResponse(false) | 145 , m_isCustomResponse(false) |
112 { | 146 { |
113 } | 147 } |
114 | 148 |
115 ContentType WBPassthruSink::GetContentTypeFromMimeType(const CString& mimeType) | 149 ContentType WBPassthruSink::GetContentTypeFromMimeType(const CString& mimeType) |
(...skipping 22 matching lines...) Expand all Loading... |
138 if (mimeType.Find(L"xml") >= 0) | 172 if (mimeType.Find(L"xml") >= 0) |
139 { | 173 { |
140 return ContentType::CONTENT_TYPE_XMLHTTPREQUEST; | 174 return ContentType::CONTENT_TYPE_XMLHTTPREQUEST; |
141 } | 175 } |
142 | 176 |
143 return ContentType::CONTENT_TYPE_OTHER; | 177 return ContentType::CONTENT_TYPE_OTHER; |
144 } | 178 } |
145 | 179 |
146 ContentType WBPassthruSink::GetContentTypeFromURL(const std::wstring& src) | 180 ContentType WBPassthruSink::GetContentTypeFromURL(const std::wstring& src) |
147 { | 181 { |
148 CString srcLegacy = ToCString(src); | 182 std::wstring schemeAndHierarchicalPart = GetSchemeAndHierarchicalPart(src); |
149 CString srcExt = srcLegacy; | 183 auto contentType = GetContentTypeFromString(schemeAndHierarchicalPart); |
150 | 184 if (contentType == ContentType::CONTENT_TYPE_OTHER && |
151 int pos = 0; | 185 AdblockPlus::IE::InstalledMajorVersion() == 8) |
152 if ((pos = srcLegacy.Find('?')) > 0) | |
153 { | 186 { |
154 srcExt = srcLegacy.Left(pos); | 187 std::wstring queryString = GetQueryString(src); |
| 188 wchar_t* nextToken = nullptr; |
| 189 const wchar_t* token = wcstok_s(&queryString[0], L"&=", &nextToken); |
| 190 while (token != nullptr) |
| 191 { |
| 192 contentType = GetContentTypeFromString(token); |
| 193 if (contentType != ContentType::CONTENT_TYPE_OTHER) |
| 194 { |
| 195 return contentType; |
| 196 } |
| 197 token = wcstok_s(nullptr, L"&=", &nextToken); |
| 198 } |
155 } | 199 } |
156 | 200 return contentType; |
157 int lastDotIndex = srcExt.ReverseFind('.'); | |
158 if (lastDotIndex < 0) | |
159 return ContentType::CONTENT_TYPE_OTHER; | |
160 CString ext = srcExt.Mid(lastDotIndex); | |
161 if (ext == L".jpg" || ext == L".gif" || ext == L".png" || ext == L".jpeg") | |
162 { | |
163 return ContentType::CONTENT_TYPE_IMAGE; | |
164 } | |
165 else if (ext == L".css") | |
166 { | |
167 return ContentType::CONTENT_TYPE_STYLESHEET; | |
168 } | |
169 else if (ext.Right(3) == L".js") | |
170 { | |
171 return ContentType::CONTENT_TYPE_SCRIPT; | |
172 } | |
173 else if (ext == L".xml") | |
174 { | |
175 return ContentType::CONTENT_TYPE_XMLHTTPREQUEST; | |
176 } | |
177 else if (ext == L".swf") | |
178 { | |
179 return ContentType::CONTENT_TYPE_OBJECT; | |
180 } | |
181 else if (ext == L".jsp" || ext == L".php" || ext == L".html") | |
182 { | |
183 return ContentType::CONTENT_TYPE_SUBDOCUMENT; | |
184 } | |
185 return ContentType::CONTENT_TYPE_OTHER; | |
186 } | 201 } |
187 | 202 |
188 ContentType WBPassthruSink::GetContentType(const CString& mimeType, const std::w
string& domain, const std::wstring& src) | 203 ContentType WBPassthruSink::GetContentType(const CString& mimeType, const std::w
string& domain, const std::wstring& src) |
189 { | 204 { |
190 // No referer or mime type | 205 // No referer or mime type |
191 // BINDSTRING_XDR_ORIGIN works only for IE v8+ | 206 // BINDSTRING_XDR_ORIGIN works only for IE v8+ |
192 if (mimeType.IsEmpty() && domain.empty() && AdblockPlus::IE::InstalledMajorVer
sion() >= 8) | 207 if (mimeType.IsEmpty() && domain.empty() && AdblockPlus::IE::InstalledMajorVer
sion() >= 8) |
193 { | 208 { |
194 return ContentType::CONTENT_TYPE_XMLHTTPREQUEST; | 209 return ContentType::CONTENT_TYPE_XMLHTTPREQUEST; |
195 } | 210 } |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
425 } | 440 } |
426 | 441 |
427 return OnStart(szUrl, pOIProtSink, pOIBindInfo, grfPI, dwReserved, m_spInterne
tProtocol); | 442 return OnStart(szUrl, pOIProtSink, pOIBindInfo, grfPI, dwReserved, m_spInterne
tProtocol); |
428 } | 443 } |
429 | 444 |
430 STDMETHODIMP WBPassthru::Read(/* [in, out] */ void *pv,/* [in] */ ULONG cb,/* [o
ut] */ ULONG *pcbRead) | 445 STDMETHODIMP WBPassthru::Read(/* [in, out] */ void *pv,/* [in] */ ULONG cb,/* [o
ut] */ ULONG *pcbRead) |
431 { | 446 { |
432 WBPassthruSink* pSink = GetSink(); | 447 WBPassthruSink* pSink = GetSink(); |
433 return pSink->OnRead(pv, cb, pcbRead); | 448 return pSink->OnRead(pv, cb, pcbRead); |
434 } | 449 } |
OLD | NEW |