| Left: | ||
| Right: |
| 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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 80 return ""; | 80 return ""; |
| 81 } | 81 } |
| 82 return ExtractHttpHeader<std::string>(buf, "Accept:", "\r\n"); | 82 return ExtractHttpHeader<std::string>(buf, "Accept:", "\r\n"); |
| 83 } | 83 } |
| 84 | 84 |
| 85 bool IsXmlHttpRequest(const std::wstring& additionalHeaders) | 85 bool IsXmlHttpRequest(const std::wstring& additionalHeaders) |
| 86 { | 86 { |
| 87 auto requestedWithHeader = ExtractHttpHeader<std::wstring>(additionalHeaders , L"X-Requested-With:", L"\n"); | 87 auto requestedWithHeader = ExtractHttpHeader<std::wstring>(additionalHeaders , L"X-Requested-With:", L"\n"); |
| 88 return TrimString(requestedWithHeader) == L"XMLHttpRequest"; | 88 return TrimString(requestedWithHeader) == L"XMLHttpRequest"; |
| 89 } | 89 } |
| 90 | |
| 91 int GetContentTypeFromString(const std::wstring& value) | |
| 92 { | |
| 93 auto lastDotIt = std::find(value.rbegin(), value.rend(), L'.').base(); | |
|
Eric
2015/02/02 18:41:58
It's much clearer just to call 'rfind':
auto
sergei
2015/02/12 14:44:06
Good point!
fixed
| |
| 94 if (lastDotIt == value.end()) | |
| 95 return CFilter::contentTypeAny; | |
| 96 | |
| 97 std::wstring ext(lastDotIt, value.end()); | |
| 98 if (ext == L"jpg" || ext == L"gif" || ext == L"png" || ext == L"jpeg") | |
| 99 { | |
| 100 return CFilter::contentTypeImage; | |
| 101 } | |
| 102 else if (ext == L"css") | |
| 103 { | |
| 104 return CFilter::contentTypeStyleSheet; | |
| 105 } | |
| 106 else if (ext == L"js") | |
| 107 { | |
| 108 return CFilter::contentTypeScript; | |
| 109 } | |
| 110 else if (ext == L"xml") | |
| 111 { | |
| 112 return CFilter::contentTypeXmlHttpRequest; | |
| 113 } | |
| 114 else if (ext == L"swf") | |
| 115 { | |
| 116 return CFilter::contentTypeObject; | |
| 117 } | |
| 118 else if (ext == L"jsp" || ext == L"php" || ext == L"html") | |
| 119 { | |
| 120 return CFilter::contentTypeSubdocument; | |
| 121 } | |
| 122 return CFilter::contentTypeAny; | |
| 123 } | |
| 90 } | 124 } |
| 91 | 125 |
| 92 WBPassthruSink::WBPassthruSink() | 126 WBPassthruSink::WBPassthruSink() |
| 93 : m_currentPositionOfSentPage(0) | 127 : m_currentPositionOfSentPage(0) |
| 94 , m_contentType(CFilter::EContentType::contentTypeAny) | 128 , m_contentType(CFilter::EContentType::contentTypeAny) |
| 95 , m_isCustomResponse(false) | 129 , m_isCustomResponse(false) |
| 96 { | 130 { |
| 97 } | 131 } |
| 98 | 132 |
| 99 int WBPassthruSink::GetContentTypeFromMimeType(const CString& mimeType) | 133 int WBPassthruSink::GetContentTypeFromMimeType(const CString& mimeType) |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 122 if (mimeType.Find(L"xml") >= 0) | 156 if (mimeType.Find(L"xml") >= 0) |
| 123 { | 157 { |
| 124 return CFilter::contentTypeXmlHttpRequest; | 158 return CFilter::contentTypeXmlHttpRequest; |
| 125 } | 159 } |
| 126 | 160 |
| 127 return CFilter::contentTypeAny; | 161 return CFilter::contentTypeAny; |
| 128 } | 162 } |
| 129 | 163 |
| 130 int WBPassthruSink::GetContentTypeFromURL(const std::wstring& src) | 164 int WBPassthruSink::GetContentTypeFromURL(const std::wstring& src) |
| 131 { | 165 { |
| 132 CString srcLegacy = ToCString(src); | 166 // http://en.wikipedia.org/wiki/URI_scheme |
| 133 CString srcExt = srcLegacy; | 167 auto schemeAndHierarchicalPartEndsAt = src.find(L'?'); |
| 134 | 168 if (schemeAndHierarchicalPartEndsAt == std::wstring::npos) |
| 135 int pos = 0; | |
| 136 if ((pos = srcLegacy.Find('?')) > 0) | |
| 137 { | 169 { |
| 138 srcExt = srcLegacy.Left(pos); | 170 schemeAndHierarchicalPartEndsAt = src.find(L'#'); |
| 171 } | |
| 172 std::wstring schemeAndHierarchicalPart = src.substr(0, schemeAndHierarchicalPa rtEndsAt); | |
| 173 auto contentType = GetContentTypeFromString(schemeAndHierarchicalPart); | |
| 174 if (contentType != CFilter::contentTypeAny) | |
| 175 { | |
|
Eric
2015/02/02 18:41:58
As it's already been mentioned in the comments, it
sergei
2015/02/12 14:44:06
Actually, I'm not sure that it's a problem of only
| |
| 176 return contentType; | |
| 139 } | 177 } |
| 140 | 178 |
| 141 int lastDotIndex = srcExt.ReverseFind('.'); | 179 ProcessQueryStringParameters(GetQueryString(src), |
| 142 if (lastDotIndex < 0) | 180 [&contentType](const std::wstring& name, const std::wstring& value)->bool |
| 143 return CFilter::contentTypeAny; | 181 { |
| 144 CString ext = srcExt.Mid(lastDotIndex); | 182 if (!value.empty()) |
| 145 if (ext == L".jpg" || ext == L".gif" || ext == L".png" || ext == L".jpeg") | 183 { |
| 146 { | 184 contentType = GetContentTypeFromString(value); |
| 147 return CFilter::contentTypeImage; | 185 if (contentType != CFilter::contentTypeAny) |
| 148 } | 186 { |
| 149 else if (ext == L".css") | 187 return false; |
| 150 { | 188 } |
| 151 return CFilter::contentTypeStyleSheet; | 189 } |
| 152 } | 190 contentType = GetContentTypeFromString(name); |
| 153 else if (ext.Right(3) == L".js") | 191 if (contentType != CFilter::contentTypeAny) |
| 154 { | 192 { |
| 155 return CFilter::contentTypeScript; | 193 return false; |
| 156 } | 194 } |
| 157 else if (ext == L".xml") | 195 return true; |
| 158 { | 196 }); |
| 159 return CFilter::contentTypeXmlHttpRequest; | 197 |
| 160 } | 198 return contentType; |
| 161 else if (ext == L".swf") | |
| 162 { | |
| 163 return CFilter::contentTypeObject; | |
| 164 } | |
| 165 else if (ext == L".jsp" || ext == L".php" || ext == L".html") | |
| 166 { | |
| 167 return CFilter::contentTypeSubdocument; | |
| 168 } | |
| 169 return CFilter::contentTypeAny; | |
| 170 } | 199 } |
| 171 | 200 |
| 172 int WBPassthruSink::GetContentType(const CString& mimeType, const std::wstring& domain, const std::wstring& src) | 201 int WBPassthruSink::GetContentType(const CString& mimeType, const std::wstring& domain, const std::wstring& src) |
| 173 { | 202 { |
| 174 // No referer or mime type | 203 // No referer or mime type |
| 175 // BINDSTRING_XDR_ORIGIN works only for IE v8+ | 204 // BINDSTRING_XDR_ORIGIN works only for IE v8+ |
| 176 if (mimeType.IsEmpty() && domain.empty() && AdblockPlus::IE::InstalledMajorVer sion() >= 8) | 205 if (mimeType.IsEmpty() && domain.empty() && AdblockPlus::IE::InstalledMajorVer sion() >= 8) |
| 177 { | 206 { |
| 178 return CFilter::contentTypeXmlHttpRequest; | 207 return CFilter::contentTypeXmlHttpRequest; |
| 179 } | 208 } |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 407 } | 436 } |
| 408 | 437 |
| 409 return OnStart(szUrl, pOIProtSink, pOIBindInfo, grfPI, dwReserved, m_spInterne tProtocol); | 438 return OnStart(szUrl, pOIProtSink, pOIBindInfo, grfPI, dwReserved, m_spInterne tProtocol); |
| 410 } | 439 } |
| 411 | 440 |
| 412 STDMETHODIMP WBPassthru::Read(/* [in, out] */ void *pv,/* [in] */ ULONG cb,/* [o ut] */ ULONG *pcbRead) | 441 STDMETHODIMP WBPassthru::Read(/* [in, out] */ void *pv,/* [in] */ ULONG cb,/* [o ut] */ ULONG *pcbRead) |
| 413 { | 442 { |
| 414 WBPassthruSink* pSink = GetSink(); | 443 WBPassthruSink* pSink = GetSink(); |
| 415 return pSink->OnRead(pv, cb, pcbRead); | 444 return pSink->OnRead(pv, cb, pcbRead); |
| 416 } | 445 } |
| OLD | NEW |