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 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 (AdblockPlus::IE::InstalledMajorVersion() == 8 && |
151 int pos = 0; | 185 contentType == ContentType::CONTENT_TYPE_OTHER) |
Eric
2015/02/12 17:24:41
I don't think it matters all that much, but it wou
sergei
2015/02/13 15:21:56
Changed.
| |
152 if ((pos = srcLegacy.Find('?')) > 0) | |
153 { | 186 { |
154 srcExt = srcLegacy.Left(pos); | 187 ForEachQueryStringParameter(GetQueryString(src), |
Oleksandr
2015/02/13 03:32:16
Why can't we just use strtok here? The code would
sergei
2015/02/13 15:21:56
strtok is unsafe and I would say the using of any
Eric
2015/02/13 16:33:43
For the reasons that strtok won't work here, see h
Oleksandr
2015/02/16 06:59:28
strotok_s would actually work good here. It has a
sergei
2015/02/16 10:54:33
I agree it looks good, not as I expected.
Eric
2015/02/16 18:18:07
There are two underlying observations here. The fi
sergei
2015/02/20 11:17:03
Good, but what does it give us? We use a lot of Wi
| |
188 [&contentType](const std::wstring& name, const std::wstring& value)->bool | |
189 { | |
190 if (!value.empty()) | |
191 { | |
192 contentType = GetContentTypeFromString(value); | |
193 if (contentType != ContentType::CONTENT_TYPE_OTHER) | |
194 { | |
195 return false; | |
196 } | |
197 } | |
198 contentType = GetContentTypeFromString(name); | |
199 if (contentType != ContentType::CONTENT_TYPE_OTHER) | |
200 { | |
201 return false; | |
202 } | |
203 return true; | |
204 }); | |
155 } | 205 } |
156 | 206 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 } | 207 } |
187 | 208 |
188 ContentType WBPassthruSink::GetContentType(const CString& mimeType, const std::w string& domain, const std::wstring& src) | 209 ContentType WBPassthruSink::GetContentType(const CString& mimeType, const std::w string& domain, const std::wstring& src) |
189 { | 210 { |
190 // No referer or mime type | 211 // No referer or mime type |
191 // BINDSTRING_XDR_ORIGIN works only for IE v8+ | 212 // BINDSTRING_XDR_ORIGIN works only for IE v8+ |
192 if (mimeType.IsEmpty() && domain.empty() && AdblockPlus::IE::InstalledMajorVer sion() >= 8) | 213 if (mimeType.IsEmpty() && domain.empty() && AdblockPlus::IE::InstalledMajorVer sion() >= 8) |
193 { | 214 { |
194 return ContentType::CONTENT_TYPE_XMLHTTPREQUEST; | 215 return ContentType::CONTENT_TYPE_XMLHTTPREQUEST; |
195 } | 216 } |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
425 } | 446 } |
426 | 447 |
427 return OnStart(szUrl, pOIProtSink, pOIBindInfo, grfPI, dwReserved, m_spInterne tProtocol); | 448 return OnStart(szUrl, pOIProtSink, pOIBindInfo, grfPI, dwReserved, m_spInterne tProtocol); |
428 } | 449 } |
429 | 450 |
430 STDMETHODIMP WBPassthru::Read(/* [in, out] */ void *pv,/* [in] */ ULONG cb,/* [o ut] */ ULONG *pcbRead) | 451 STDMETHODIMP WBPassthru::Read(/* [in, out] */ void *pv,/* [in] */ ULONG cb,/* [o ut] */ ULONG *pcbRead) |
431 { | 452 { |
432 WBPassthruSink* pSink = GetSink(); | 453 WBPassthruSink* pSink = GetSink(); |
433 return pSink->OnRead(pv, cb, pcbRead); | 454 return pSink->OnRead(pv, cb, pcbRead); |
434 } | 455 } |
OLD | NEW |