Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: src/plugin/PluginWbPassThrough.cpp

Issue 5316782940225536: Issue 1557 - Update to the recent libadblockplus to reduce additional updates in the logic later. (Closed)
Patch Set: fix accoring to comments Created Jan. 13, 2015, 12:59 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/plugin/PluginWbPassThrough.cpp
diff --git a/src/plugin/PluginWbPassThrough.cpp b/src/plugin/PluginWbPassThrough.cpp
index c5be6fab4511acd8c574cfc36f2a08ddbf8b6229..01d8a665798c860a022f055dd6d97d2475d090d9 100644
--- a/src/plugin/PluginWbPassThrough.cpp
+++ b/src/plugin/PluginWbPassThrough.cpp
@@ -21,6 +21,8 @@ namespace
"</body>"
"</html>";
+ typedef AdblockPlus::FilterEngine::ContentType ContentType;
+
template <class T>
T ExtractHttpHeader(const T& allHeaders, const T& targetHeaderNameWithColon, const T& delimiter)
{
@@ -74,93 +76,93 @@ namespace
WBPassthruSink::WBPassthruSink()
: m_currentPositionOfSentPage(0)
- , m_contentType(CFilter::EContentType::contentTypeAny)
+ , m_contentType(ContentType::CONTENT_TYPE_OTHER)
, m_isCustomResponse(false)
{
}
-
-int WBPassthruSink::GetContentTypeFromMimeType(const CString& mimeType)
-{
- if (mimeType.Find(L"image/") >= 0)
- {
- return CFilter::contentTypeImage;
- }
- if (mimeType.Find(L"text/css") >= 0)
- {
- return CFilter::contentTypeStyleSheet;
- }
- if ((mimeType.Find(L"application/javascript") >= 0) || (mimeType.Find(L"application/json") >= 0))
- {
- return CFilter::contentTypeScript;
- }
- if (mimeType.Find(L"application/x-shockwave-flash") >= 0)
- {
- return CFilter::contentTypeObject;
- }
- if (mimeType.Find(L"text/html") >= 0)
- {
- 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)
- {
- return CFilter::contentTypeXmlHttpRequest;
- }
-
- return CFilter::contentTypeAny;
+
+ContentType WBPassthruSink::GetContentTypeFromMimeType(const CString& mimeType)
+{
+ if (mimeType.Find(L"image/") >= 0)
+ {
+ return ContentType::CONTENT_TYPE_IMAGE;
+ }
+ if (mimeType.Find(L"text/css") >= 0)
+ {
+ return ContentType::CONTENT_TYPE_STYLESHEET;
+ }
+ if ((mimeType.Find(L"application/javascript") >= 0) || (mimeType.Find(L"application/json") >= 0))
+ {
+ return ContentType::CONTENT_TYPE_SCRIPT;
+ }
+ if (mimeType.Find(L"application/x-shockwave-flash") >= 0)
+ {
+ return ContentType::CONTENT_TYPE_OBJECT;
+ }
+ if (mimeType.Find(L"text/html") >= 0)
+ {
+ return ContentType::CONTENT_TYPE_SUBDOCUMENT;
+ }
+ // 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)
+ {
+ return ContentType::CONTENT_TYPE_XMLHTTPREQUEST;
+ }
+
+ return ContentType::CONTENT_TYPE_OTHER;
}
-int WBPassthruSink::GetContentTypeFromURL(const CString& src)
-{
- CString srcExt = src;
-
- int pos = 0;
- if ((pos = src.Find('?')) > 0)
- {
- srcExt = src.Left(pos);
- }
-
- 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")
- {
- return CFilter::contentTypeImage;
- }
- else if (ext == L".css")
- {
- return CFilter::contentTypeStyleSheet;
- }
- else if (ext.Right(3) == L".js")
- {
- return CFilter::contentTypeScript;
- }
- else if (ext == L".xml")
- {
- return CFilter::contentTypeXmlHttpRequest;
- }
- else if (ext == L".swf")
- {
- return CFilter::contentTypeObject;
- }
- else if (ext == L".jsp" || ext == L".php" || ext == L".html")
- {
- return CFilter::contentTypeSubdocument;
- }
- return CFilter::contentTypeAny;
+ContentType WBPassthruSink::GetContentTypeFromURL(const CString& src)
+{
+ CString srcExt = src;
+
+ int pos = 0;
+ if ((pos = src.Find('?')) > 0)
+ {
+ srcExt = src.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")
+ {
+ 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;
}
-int WBPassthruSink::GetContentType(const CString& mimeType, const std::wstring& domain, const CString& src)
+ContentType WBPassthruSink::GetContentType(const CString& mimeType, const std::wstring& domain, const CString& src)
{
// No referer or mime type
// BINDSTRING_XDR_ORIGIN works only for IE v8+
if (mimeType.IsEmpty() && domain.empty() && AdblockPlus::IE::InstalledMajorVersion() >= 8)
{
- return CFilter::contentTypeXmlHttpRequest;
+ return ContentType::CONTENT_TYPE_XMLHTTPREQUEST;
}
- int contentType = GetContentTypeFromMimeType(mimeType);
- if (contentType == CFilter::contentTypeAny)
+ ContentType contentType = GetContentTypeFromMimeType(mimeType);
+ if (contentType == ContentType::CONTENT_TYPE_OTHER)
{
contentType = GetContentTypeFromURL(src);
}
@@ -301,6 +303,7 @@ STDMETHODIMP WBPassthruSink::BeginningTransaction(LPCWSTR szURL, LPCWSTR szHeade
}
m_boundDomain = TrimString(m_boundDomain);
m_contentType = GetContentType(ATL::CString(acceptHeader.c_str()), m_boundDomain, ToCString(src));
+
CPluginTab* tab = CPluginClass::GetTab(::GetCurrentThreadId());
CPluginClient* client = CPluginClient::GetInstance();
@@ -316,28 +319,28 @@ STDMETHODIMP WBPassthruSink::BeginningTransaction(LPCWSTR szURL, LPCWSTR szHeade
{
if (tab->IsFrameCached(ToCString(src)))
{
- m_contentType = CFilter::contentTypeSubdocument;
+ m_contentType = ContentType::CONTENT_TYPE_SUBDOCUMENT;
}
}
}
if (IsFlashRequest(pszAdditionalHeaders))
{
- m_contentType = CFilter::EContentType::contentTypeObjectSubrequest;
+ m_contentType = ContentType::CONTENT_TYPE_OBJECT_SUBREQUEST;
}
if (pszAdditionalHeaders && *pszAdditionalHeaders && IsXmlHttpRequest(*pszAdditionalHeaders))
{
- m_contentType = CFilter::EContentType::contentTypeXmlHttpRequest;
+ m_contentType = ContentType::CONTENT_TYPE_XMLHTTPREQUEST;
}
if (client->ShouldBlock(szURL, m_contentType, m_boundDomain, /*debug flag but must be set*/true))
{
// NOTE: Feeding custom HTML to Flash, instead of original object subrequest
- // doesn't have much sense. It also can manifest in unwanted result
- // like video being blocked (See https://issues.adblockplus.org/ticket/1669)
+ // doesn't have much sense. It also can manifest in unwanted result
+ // like video being blocked (See https://issues.adblockplus.org/ticket/1669)
// So we report blocked object subrequests as failed, not just empty HTML.
- m_isCustomResponse = m_contentType != CFilter::contentTypeObjectSubrequest;
+ m_isCustomResponse = m_contentType != ContentType::CONTENT_TYPE_OBJECT_SUBREQUEST;
return E_ABORT;
}
return nativeHr;

Powered by Google App Engine
This is Rietveld