Index: src/plugin/PluginWbPassThrough.cpp |
diff --git a/src/plugin/PluginWbPassThrough.cpp b/src/plugin/PluginWbPassThrough.cpp |
index 204090f8480c05d288c7c4b60fe642331266bcbe..37e4a04e82d998a8a45fcefc1c883d4ff371f038 100644 |
--- a/src/plugin/PluginWbPassThrough.cpp |
+++ b/src/plugin/PluginWbPassThrough.cpp |
@@ -103,6 +103,40 @@ namespace |
auto requestedWithHeader = ExtractHttpHeader<std::wstring>(additionalHeaders, L"X-Requested-With:", L"\n"); |
return TrimString(requestedWithHeader) == L"XMLHttpRequest"; |
} |
+ |
+ ContentType GetContentTypeFromString(const std::wstring& value) |
+ { |
+ auto lastDotPos = value.rfind(L'.'); |
+ if (lastDotPos == std::wstring::npos) |
+ return ContentType::CONTENT_TYPE_OTHER; |
+ |
+ std::wstring ext = ASCIIStringToLower(value.substr(lastDotPos + 1)); |
+ if (ext == L"jpg" || ext == L"gif" || ext == L"png" || ext == L"jpeg") |
+ { |
+ return ContentType::CONTENT_TYPE_IMAGE; |
+ } |
+ else if (ext == L"css") |
+ { |
+ return ContentType::CONTENT_TYPE_STYLESHEET; |
+ } |
+ else if (ext == L"js") |
+ { |
+ return ContentType::CONTENT_TYPE_SCRIPT; |
+ } |
+ else if (ext == L"xml") |
+ { |
+ return ContentType::CONTENT_TYPE_XMLHTTPREQUEST; |
+ } |
+ else if (ext == L"swf") |
+ { |
+ return ContentType::CONTENT_TYPE_OBJECT; |
+ } |
+ else if (ext == L"jsp" || ext == L"php" || ext == L"html") |
+ { |
+ return ContentType::CONTENT_TYPE_SUBDOCUMENT; |
+ } |
+ return ContentType::CONTENT_TYPE_OTHER; |
+ } |
} |
WBPassthruSink::WBPassthruSink() |
@@ -145,44 +179,31 @@ ContentType WBPassthruSink::GetContentTypeFromMimeType(const CString& mimeType) |
ContentType WBPassthruSink::GetContentTypeFromURL(const std::wstring& src) |
{ |
- CString srcLegacy = ToCString(src); |
- CString srcExt = srcLegacy; |
- |
- int pos = 0; |
- if ((pos = srcLegacy.Find('?')) > 0) |
- { |
- srcExt = srcLegacy.Left(pos); |
- } |
- |
- int lastDotIndex = srcExt.ReverseFind('.'); |
- if (lastDotIndex < 0) |
- return ContentType::CONTENT_TYPE_OTHER; |
- CString ext = srcExt.Mid(lastDotIndex); |
- if (ext == L".jpg" || ext == L".gif" || ext == L".png" || ext == L".jpeg") |
- { |
- return ContentType::CONTENT_TYPE_IMAGE; |
- } |
- else if (ext == L".css") |
- { |
- return ContentType::CONTENT_TYPE_STYLESHEET; |
- } |
- else if (ext.Right(3) == L".js") |
- { |
- return ContentType::CONTENT_TYPE_SCRIPT; |
- } |
- else if (ext == L".xml") |
- { |
- return ContentType::CONTENT_TYPE_XMLHTTPREQUEST; |
- } |
- else if (ext == L".swf") |
+ std::wstring schemeAndHierarchicalPart = GetSchemeAndHierarchicalPart(src); |
+ auto contentType = GetContentTypeFromString(schemeAndHierarchicalPart); |
+ if (AdblockPlus::IE::InstalledMajorVersion() == 8 && |
+ 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.
|
{ |
- return ContentType::CONTENT_TYPE_OBJECT; |
- } |
- else if (ext == L".jsp" || ext == L".php" || ext == L".html") |
- { |
- return ContentType::CONTENT_TYPE_SUBDOCUMENT; |
+ 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
|
+ [&contentType](const std::wstring& name, const std::wstring& value)->bool |
+ { |
+ if (!value.empty()) |
+ { |
+ contentType = GetContentTypeFromString(value); |
+ if (contentType != ContentType::CONTENT_TYPE_OTHER) |
+ { |
+ return false; |
+ } |
+ } |
+ contentType = GetContentTypeFromString(name); |
+ if (contentType != ContentType::CONTENT_TYPE_OTHER) |
+ { |
+ return false; |
+ } |
+ return true; |
+ }); |
} |
- return ContentType::CONTENT_TYPE_OTHER; |
+ return contentType; |
} |
ContentType WBPassthruSink::GetContentType(const CString& mimeType, const std::wstring& domain, const std::wstring& src) |