Index: src/plugin/PluginWbPassThrough.cpp |
=================================================================== |
--- a/src/plugin/PluginWbPassThrough.cpp |
+++ b/src/plugin/PluginWbPassThrough.cpp |
@@ -9,6 +9,8 @@ |
#include "PluginSettings.h" |
#include "PluginClass.h" |
#include "PluginSystem.h" |
+#include "Wrapper.h" |
+#include "PluginUtil.h" |
#include "wtypes.h" |
@@ -19,75 +21,80 @@ |
{ |
m_pTargetProtocol = NULL; |
} |
-int WBPassthruSink::GetContentTypeFromMimeType(CString mimeType) |
+int WBPassthruSink::GetContentTypeFromMimeType( std::wstring mime_type ) |
{ |
- if (mimeType.Find(L"image/") >= 0) |
+ if ( mime_type.find( L"image/" ) != std::wstring::npos ) |
{ |
return CFilter::contentTypeImage; |
} |
- if (mimeType.Find(L"text/css") >= 0) |
+ if ( mime_type.find( L"text/css" ) != std::wstring::npos ) |
{ |
return CFilter::contentTypeStyleSheet; |
} |
- if ((mimeType.Find(L"application/javascript") >= 0) || (mimeType.Find(L"application/json") >= 0)) |
+ if ( mime_type.find( L"application/javascript" ) != std::wstring::npos |
+ || mime_type.find( L"application/json" ) != std::wstring::npos ) |
{ |
return CFilter::contentTypeScript; |
} |
- if (mimeType.Find(L"application/x-shockwave-flash") >= 0) |
+ if ( mime_type.find( L"application/x-shockwave-flash" ) != std::wstring::npos ) |
{ |
return CFilter::contentTypeObject; |
} |
- if (mimeType.Find(L"text/html") >= 0) |
+ if ( mime_type.find( L"text/html" ) != std::wstring::npos ) |
{ |
return CFilter::contentTypeSubdocument; |
} |
// It is important to have this check last, since it is rather generic, and might overlay text/html, for example |
- if (mimeType.Find(L"xml") >= 0) |
+ if ( mime_type.find( L"xml" ) != std::wstring::npos ) |
{ |
return CFilter::contentTypeXmlHttpRequest; |
} |
- |
return CFilter::contentTypeAny; |
} |
-int WBPassthruSink::GetContentTypeFromURL(CString src) |
+int WBPassthruSink::GetContentTypeFromURL( std::wstring src ) |
{ |
- CString srcExt = src; |
+ // Start search for extension at beginning of query, if any |
+ size_t ext_end = src.find( L'?' ); |
+ // Assert ext_end <= src.length --> src[ ext_end ] == '?' |
+ // Assert ext_end == npos --> there's no '?' character and ext_end == npos, which represents "end of string" in wstring::substr() |
- int pos = 0; |
- if ((pos = src.Find('?')) > 0) |
+ // Locate punctuation for extension, if any |
+ size_t ext_begin = src.rfind( L'.', ext_end ); |
+ if ( ext_begin == std::wstring::npos ) |
{ |
- srcExt = src.Left(pos); |
+ // No punctuation |
+ return CFilter::contentTypeAny; |
} |
+ // Adding 1 to ext_begin excludes punctuation |
+ std::wstring ext = src.substr( ext_begin + 1, ext_end ); |
+ // Assert ext contains all text after last period character to beginning of query, or if no query, to end of string |
- int lastDotIndex = srcExt.ReverseFind('.'); |
- if (lastDotIndex < 0) |
- return CFilter::contentTypeAny; |
- CString ext = srcExt.Mid(lastDotIndex); |
- if (ext == L".jpg" || ext == L".gif" || ext == L".png" || ext == L".jpeg") |
+ if (ext == L"jpg" || ext == L"gif" || ext == L"png" || ext == L"jpeg") |
{ |
return CFilter::contentTypeImage; |
} |
- else if (ext == L".css") |
+ else if (ext == L"css") |
{ |
return CFilter::contentTypeStyleSheet; |
} |
- else if (ext.Right(3) == L".js") |
+ // Test for "jsp" before "js*" below |
+ else if ( ext == L"jsp" || ext == L"php" || ABP::util::begins_with( ext, L"htm" ) ) |
+ { |
+ return CFilter::contentTypeSubdocument; |
+ } |
+ else if ( ABP::util::begins_with( ext, L"js" ) ) |
{ |
return CFilter::contentTypeScript; |
} |
- else if (ext == L".xml") |
+ else if (ext == L"xml") |
{ |
return CFilter::contentTypeXmlHttpRequest; |
} |
- else if (ext == L".swf") |
+ else if (ext == L"swf") |
{ |
return CFilter::contentTypeObject; |
} |
- else if (ext == L".jsp" || ext == L".php" || ext == L".html") |
- { |
- return CFilter::contentTypeSubdocument; |
- } |
else |
{ |
return CFilter::contentTypeAny & ~CFilter::contentTypeSubdocument; |
@@ -95,11 +102,11 @@ |
} |
-int WBPassthruSink::GetContentType(CString mimeType, CString domain, CString src) |
+int WBPassthruSink::GetContentType(std::wstring mimeType, std::wstring domain, std::wstring src) |
{ |
// No referer or mime type |
// BINDSTRING_XDR_ORIGIN works only for IE v8+ |
- if (mimeType.IsEmpty() && domain.IsEmpty() && CPluginClient::GetInstance()->GetIEVersion() >= 8) |
+ if (mimeType.empty() && domain.empty() && CPluginClient::GetInstance()->GetIEVersion() >= 8) |
{ |
return CFilter::contentTypeXmlHttpRequest; |
} |
@@ -125,40 +132,24 @@ |
bool isBlocked = false; |
m_shouldBlock = false; |
m_lastDataReported = false; |
- CString src; |
- src.Append(szUrl); |
+ std::wstring src( szUrl ); |
DEBUG_GENERAL(src); |
- CPluginClient::UnescapeUrl(src); |
+ Wrapper::Unescape_URL( src ); |
- CString boundDomain; |
- CString mimeType; |
- LPOLESTR mime[10]; |
+ std::wstring boundDomain; |
+ std::wstring mime_type; |
if (pOIBindInfo) |
{ |
- ULONG resLen = 0; |
- pOIBindInfo->GetBindString(BINDSTRING_ACCEPT_MIMES, mime, 10, &resLen); |
- if (mime && resLen > 0) |
+ Wrapper::Internet_Bind_Info bi( pOIBindInfo ); |
+ mime_type = bi.bind_string_single( BINDSTRING_ACCEPT_MIMES ); |
+ std::wstring bind_to_object = bi.bind_string_single( BINDSTRING_FLAG_BIND_TO_OBJECT ); |
+ ABP::util::to_lower( bind_to_object ); |
+ if ( bind_to_object == L"" || bind_to_object == L"false" ) |
{ |
- mimeType.SetString(mime[0]); |
- } |
- LPOLESTR bindToObject = 0; |
- pOIBindInfo->GetBindString(BINDSTRING_FLAG_BIND_TO_OBJECT, &bindToObject, 1, &resLen); |
- LPOLESTR domainRetrieved = 0; |
- if (resLen == 0 || wcscmp(bindToObject, L"FALSE") == 0) |
- { |
- HRESULT hr = pOIBindInfo->GetBindString(BINDSTRING_XDR_ORIGIN, &domainRetrieved, 1, &resLen); |
- |
- if ((hr == S_OK) && domainRetrieved && (resLen > 0)) |
- { |
- boundDomain.SetString(domainRetrieved); |
- } |
+ boundDomain = bi.bind_string_single( BINDSTRING_XDR_ORIGIN ); |
} |
} |
- CString cookie; |
- ULONG len1 = 2048; |
- ULONG len2 = 2048; |
- |
#ifdef SUPPORT_FILTER |
int contentType = CFilter::contentTypeAny; |
@@ -168,13 +159,13 @@ |
if (tab && client) |
{ |
- CString documentUrl = tab->GetDocumentUrl(); |
+ std::wstring documentUrl = tab->GetDocumentUrl(); |
// Page is identical to document => don't block |
if (documentUrl == src) |
{ |
// fall through |
} |
- else if (CPluginSettings::GetInstance()->IsPluginEnabled() && !client->IsWhitelistedUrl(std::wstring(documentUrl))) |
+ else if (CPluginSettings::GetInstance()->IsPluginEnabled() && !client->IsWhitelistedUrl( documentUrl )) |
{ |
boundDomain = tab->GetDocumentUrl(); |
@@ -187,7 +178,7 @@ |
} |
else |
#endif // SUPPORT_FRAME_CACHING |
- contentType = GetContentType(mimeType, boundDomain, src); |
+ contentType = GetContentType( mime_type, boundDomain, src ); |
if (client->ShouldBlock(src, contentType, boundDomain, true)) |
{ |
isBlocked = true; |
@@ -204,7 +195,7 @@ |
if (tab == NULL) |
{ |
- contentType = GetContentType(mimeType, boundDomain, src); |
+ contentType = GetContentType( mime_type, boundDomain, src); |
if (client->ShouldBlock(src, contentType, boundDomain, true)) |
{ |
isBlocked = true; |
@@ -212,17 +203,17 @@ |
} |
#ifdef _DEBUG |
- CString type; |
+ std::wstring type; |
- if (contentType == CFilter::contentTypeDocument) type = "DOCUMENT"; |
- else if (contentType == CFilter::contentTypeObject) type = "OBJECT"; |
- else if (contentType == CFilter::contentTypeImage) type = "IMAGE"; |
- else if (contentType == CFilter::contentTypeScript) type = "SCRIPT"; |
- else if (contentType == CFilter::contentTypeOther) type = "OTHER"; |
- else if (contentType == CFilter::contentTypeUnknown) type = "OTHER"; |
- else if (contentType == CFilter::contentTypeSubdocument) type = "SUBDOCUMENT"; |
- else if (contentType == CFilter::contentTypeStyleSheet) type = "STYLESHEET"; |
- else type = "OTHER"; |
+ if (contentType == CFilter::contentTypeDocument) type = L"DOCUMENT"; |
+ else if (contentType == CFilter::contentTypeObject) type = L"OBJECT"; |
+ else if (contentType == CFilter::contentTypeImage) type = L"IMAGE"; |
+ else if (contentType == CFilter::contentTypeScript) type = L"SCRIPT"; |
+ else if (contentType == CFilter::contentTypeOther) type = L"OTHER"; |
+ else if (contentType == CFilter::contentTypeUnknown) type = L"OTHER"; |
+ else if (contentType == CFilter::contentTypeSubdocument) type = L"SUBDOCUMENT"; |
+ else if (contentType == CFilter::contentTypeStyleSheet) type = L"STYLESHEET"; |
+ else type = L"OTHER"; |
if (isBlocked) |
{ |