OLD | NEW |
1 #include "PluginStdAfx.h" | 1 #include "PluginStdAfx.h" |
2 | 2 |
3 #include "PluginWbPassThrough.h" | 3 #include "PluginWbPassThrough.h" |
4 #include "PluginClient.h" | 4 #include "PluginClient.h" |
5 #include "PluginClientFactory.h" | 5 #include "PluginClientFactory.h" |
6 #include "PluginFilter.h" | 6 #include "PluginFilter.h" |
7 #include "PluginSettings.h" | 7 #include "PluginSettings.h" |
8 #include "PluginClass.h" | 8 #include "PluginClass.h" |
9 #include "PluginSystem.h" | 9 #include "PluginSystem.h" |
10 #include <WinInet.h> | 10 #include <WinInet.h> |
11 #include "wtypes.h" | 11 #include "wtypes.h" |
12 #include "../shared/Utils.h" | 12 #include "../shared/Utils.h" |
13 | 13 |
14 namespace | 14 namespace |
15 { | 15 { |
16 const std::string g_blockedByABPPage = "<!DOCTYPE html>" | 16 const std::string g_blockedByABPPage = "<!DOCTYPE html>" |
17 "<html>" | 17 "<html>" |
18 "<body>" | 18 "<body>" |
19 "<!-- blocked by AdblockPlus -->" | 19 "<!-- blocked by AdblockPlus -->" |
20 "</body>" | 20 "</body>" |
21 "</html>"; | 21 "</html>"; |
22 | 22 |
| 23 typedef AdblockPlus::FilterEngine::ContentType ContentType; |
| 24 |
23 template <class T> | 25 template <class T> |
24 T ExtractHttpHeader(const T& allHeaders, const T& targetHeaderNameWithColon, c
onst T& delimiter) | 26 T ExtractHttpHeader(const T& allHeaders, const T& targetHeaderNameWithColon, c
onst T& delimiter) |
25 { | 27 { |
26 auto targetHeaderBeginsAt = allHeaders.find(targetHeaderNameWithColon); | 28 auto targetHeaderBeginsAt = allHeaders.find(targetHeaderNameWithColon); |
27 if (targetHeaderBeginsAt == T::npos) | 29 if (targetHeaderBeginsAt == T::npos) |
28 { | 30 { |
29 return T(); | 31 return T(); |
30 } | 32 } |
31 targetHeaderBeginsAt += targetHeaderNameWithColon.length(); | 33 targetHeaderBeginsAt += targetHeaderNameWithColon.length(); |
32 auto targetHeaderEndsAt = allHeaders.find(delimiter, targetHeaderBeginsAt); | 34 auto targetHeaderEndsAt = allHeaders.find(delimiter, targetHeaderBeginsAt); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 | 68 |
67 bool IsXmlHttpRequest(const std::wstring& additionalHeaders) | 69 bool IsXmlHttpRequest(const std::wstring& additionalHeaders) |
68 { | 70 { |
69 auto requestedWithHeader = ExtractHttpHeader<std::wstring>(additionalHeaders
, L"X-Requested-With:", L"\n"); | 71 auto requestedWithHeader = ExtractHttpHeader<std::wstring>(additionalHeaders
, L"X-Requested-With:", L"\n"); |
70 return TrimString(requestedWithHeader) == L"XMLHttpRequest"; | 72 return TrimString(requestedWithHeader) == L"XMLHttpRequest"; |
71 } | 73 } |
72 } | 74 } |
73 | 75 |
74 WBPassthruSink::WBPassthruSink() | 76 WBPassthruSink::WBPassthruSink() |
75 : m_currentPositionOfSentPage(0) | 77 : m_currentPositionOfSentPage(0) |
76 , m_contentType(CFilter::EContentType::contentTypeAny) | 78 , m_contentType(AdblockPlus::FilterEngine::ContentType::CONTENT_TYPE_OTHER) |
77 , m_blockedInTransaction(false) | 79 , m_blockedInTransaction(false) |
78 { | 80 { |
79 } | 81 } |
80 | 82 |
81 int WBPassthruSink::GetContentTypeFromMimeType(const CString& mimeType) | 83 ContentType WBPassthruSink::GetContentTypeFromMimeType(const CString& mimeType) |
82 { | 84 { |
83 if (mimeType.Find(L"image/") >= 0) | 85 if (mimeType.Find(L"image/") >= 0) |
84 { | 86 { |
85 return CFilter::contentTypeImage; | 87 return ContentType::CONTENT_TYPE_IMAGE; |
86 } | 88 } |
87 if (mimeType.Find(L"text/css") >= 0) | 89 if (mimeType.Find(L"text/css") >= 0) |
88 { | 90 { |
89 return CFilter::contentTypeStyleSheet; | 91 return ContentType::CONTENT_TYPE_STYLESHEET; |
90 } | 92 } |
91 if ((mimeType.Find(L"application/javascript") >= 0) || (mimeType.Find(L"applic
ation/json") >= 0)) | 93 if ((mimeType.Find(L"application/javascript") >= 0) || (mimeType.Find(L"applic
ation/json") >= 0)) |
92 { | 94 { |
93 return CFilter::contentTypeScript; | 95 return ContentType::CONTENT_TYPE_SCRIPT; |
94 } | 96 } |
95 if (mimeType.Find(L"application/x-shockwave-flash") >= 0) | 97 if (mimeType.Find(L"application/x-shockwave-flash") >= 0) |
96 { | 98 { |
97 return CFilter::contentTypeObject; | 99 return ContentType::CONTENT_TYPE_OBJECT; |
98 } | 100 } |
99 if (mimeType.Find(L"text/html") >= 0) | 101 if (mimeType.Find(L"text/html") >= 0) |
100 { | 102 { |
101 return CFilter::contentTypeSubdocument; | 103 return ContentType::CONTENT_TYPE_SUBDOCUMENT; |
102 } | 104 } |
103 // It is important to have this check last, since it is rather generic, and mi
ght overlay text/html, for example | 105 // It is important to have this check last, since it is rather generic, and mi
ght overlay text/html, for example |
104 if (mimeType.Find(L"xml") >= 0) | 106 if (mimeType.Find(L"xml") >= 0) |
105 { | 107 { |
106 return CFilter::contentTypeXmlHttpRequest; | 108 return ContentType::CONTENT_TYPE_XMLHTTPREQUEST; |
107 } | 109 } |
108 | 110 |
109 return CFilter::contentTypeAny; | 111 return ContentType::CONTENT_TYPE_OTHER; |
110 } | 112 } |
111 | 113 |
112 int WBPassthruSink::GetContentTypeFromURL(const CString& src) | 114 ContentType WBPassthruSink::GetContentTypeFromURL(const CString& src) |
113 { | 115 { |
114 CString srcExt = src; | 116 CString srcExt = src; |
115 | 117 |
116 int pos = 0; | 118 int pos = 0; |
117 if ((pos = src.Find('?')) > 0) | 119 if ((pos = src.Find('?')) > 0) |
118 { | 120 { |
119 srcExt = src.Left(pos); | 121 srcExt = src.Left(pos); |
120 } | 122 } |
121 | 123 |
122 int lastDotIndex = srcExt.ReverseFind('.'); | 124 int lastDotIndex = srcExt.ReverseFind('.'); |
123 if (lastDotIndex < 0) | 125 if (lastDotIndex < 0) |
124 return CFilter::contentTypeAny; | 126 return ContentType::CONTENT_TYPE_OTHER; |
125 CString ext = srcExt.Mid(lastDotIndex); | 127 CString ext = srcExt.Mid(lastDotIndex); |
126 if (ext == L".jpg" || ext == L".gif" || ext == L".png" || ext == L".jpeg") | 128 if (ext == L".jpg" || ext == L".gif" || ext == L".png" || ext == L".jpeg") |
127 { | 129 { |
128 return CFilter::contentTypeImage; | 130 return ContentType::CONTENT_TYPE_IMAGE; |
129 } | 131 } |
130 else if (ext == L".css") | 132 else if (ext == L".css") |
131 { | 133 { |
132 return CFilter::contentTypeStyleSheet; | 134 return ContentType::CONTENT_TYPE_STYLESHEET; |
133 } | 135 } |
134 else if (ext.Right(3) == L".js") | 136 else if (ext.Right(3) == L".js") |
135 { | 137 { |
136 return CFilter::contentTypeScript; | 138 return ContentType::CONTENT_TYPE_SCRIPT; |
137 } | 139 } |
138 else if (ext == L".xml") | 140 else if (ext == L".xml") |
139 { | 141 { |
140 return CFilter::contentTypeXmlHttpRequest; | 142 return ContentType::CONTENT_TYPE_XMLHTTPREQUEST; |
141 } | 143 } |
142 else if (ext == L".swf") | 144 else if (ext == L".swf") |
143 { | 145 { |
144 return CFilter::contentTypeObject; | 146 return ContentType::CONTENT_TYPE_OBJECT; |
145 } | 147 } |
146 else if (ext == L".jsp" || ext == L".php" || ext == L".html") | 148 else if (ext == L".jsp" || ext == L".php" || ext == L".html") |
147 { | 149 { |
148 return CFilter::contentTypeSubdocument; | 150 return ContentType::CONTENT_TYPE_SUBDOCUMENT; |
149 } | 151 } |
150 return CFilter::contentTypeAny; | 152 return ContentType::CONTENT_TYPE_OTHER; |
151 } | 153 } |
152 | 154 |
153 int WBPassthruSink::GetContentType(const CString& mimeType, const std::wstring&
domain, const CString& src) | 155 ContentType WBPassthruSink::GetContentType(const CString& mimeType, const std::w
string& domain, const CString& src) |
154 { | 156 { |
155 // No referer or mime type | 157 // No referer or mime type |
156 // BINDSTRING_XDR_ORIGIN works only for IE v8+ | 158 // BINDSTRING_XDR_ORIGIN works only for IE v8+ |
157 if (mimeType.IsEmpty() && domain.empty() && CPluginClient::GetInstance()->GetI
EVersion() >= 8) | 159 if (mimeType.IsEmpty() && domain.empty() && CPluginClient::GetInstance()->GetI
EVersion() >= 8) |
158 { | 160 { |
159 return CFilter::contentTypeXmlHttpRequest; | 161 return ContentType::CONTENT_TYPE_XMLHTTPREQUEST; |
160 } | 162 } |
161 int contentType = GetContentTypeFromMimeType(mimeType); | 163 int contentType = GetContentTypeFromMimeType(mimeType); |
162 if (contentType == CFilter::contentTypeAny) | 164 if (contentType == ContentType::CONTENT_TYPE_OTHER) |
163 { | 165 { |
164 contentType = GetContentTypeFromURL(src); | 166 contentType = GetContentTypeFromURL(src); |
165 } | 167 } |
166 return contentType; | 168 return ContentType::CONTENT_TYPE_OTHER; |
167 } | 169 } |
168 | 170 |
169 ////////////////////////////////////////////////////////////////////////////////
//////// | 171 ////////////////////////////////////////////////////////////////////////////////
//////// |
170 //WBPassthruSink | 172 //WBPassthruSink |
171 //Monitor and/or cancel every request and responde | 173 //Monitor and/or cancel every request and responde |
172 //WB makes, including images, sounds, scripts, etc | 174 //WB makes, including images, sounds, scripts, etc |
173 ////////////////////////////////////////////////////////////////////////////////
//////// | 175 ////////////////////////////////////////////////////////////////////////////////
//////// |
174 HRESULT WBPassthruSink::OnStart(LPCWSTR szUrl, IInternetProtocolSink *pOIProtSin
k, | 176 HRESULT WBPassthruSink::OnStart(LPCWSTR szUrl, IInternetProtocolSink *pOIProtSin
k, |
175 IInternetBindInfo *pOIBindInfo, DWORD grfPI, HAN
DLE_PTR dwReserved, | 177 IInternetBindInfo *pOIBindInfo, DWORD grfPI, HAN
DLE_PTR dwReserved, |
176 IInternetProtocol* pTargetProtocol, bool& handle
d) | 178 IInternetProtocol* pTargetProtocol, bool& handle
d) |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 CString documentUrl = tab->GetDocumentUrl(); | 310 CString documentUrl = tab->GetDocumentUrl(); |
309 // Page is identical to document => don't block | 311 // Page is identical to document => don't block |
310 if (documentUrl == ToCString(src)) | 312 if (documentUrl == ToCString(src)) |
311 { | 313 { |
312 return nativeHr; | 314 return nativeHr; |
313 } | 315 } |
314 else if (CPluginSettings::GetInstance()->IsPluginEnabled() && !client->IsWhi
telistedUrl(std::wstring(documentUrl))) | 316 else if (CPluginSettings::GetInstance()->IsPluginEnabled() && !client->IsWhi
telistedUrl(std::wstring(documentUrl))) |
315 { | 317 { |
316 if (tab->IsFrameCached(ToCString(src))) | 318 if (tab->IsFrameCached(ToCString(src))) |
317 { | 319 { |
318 m_contentType = CFilter::contentTypeSubdocument; | 320 m_contentType = ContentType::CONTENT_TYPE_SUBDOCUMENT; |
319 } | 321 } |
320 } | 322 } |
321 } | 323 } |
322 | 324 |
323 if (IsFlashRequest(pszAdditionalHeaders)) | 325 if (IsFlashRequest(pszAdditionalHeaders)) |
324 { | 326 { |
325 m_contentType = CFilter::EContentType::contentTypeObjectSubrequest; | 327 m_contentType = ContentType::CONTENT_TYPE_OBJECT_SUBREQUEST; |
326 } | 328 } |
327 | 329 |
328 if (pszAdditionalHeaders && IsXmlHttpRequest(*pszAdditionalHeaders)) | 330 if (pszAdditionalHeaders && IsXmlHttpRequest(*pszAdditionalHeaders)) |
329 { | 331 { |
330 m_contentType = CFilter::EContentType::contentTypeXmlHttpRequest; | 332 m_contentType = ContentType::CONTENT_TYPE_XMLHTTPREQUEST; |
331 } | 333 } |
332 | 334 |
333 m_blockedInTransaction = client->ShouldBlock(szURL, m_contentType, m_boundDoma
in, /*debug flag but must be set*/true); | 335 m_blockedInTransaction = client->ShouldBlock(szURL, m_contentType, m_boundDoma
in); |
334 if (m_blockedInTransaction) | 336 if (m_blockedInTransaction) |
335 { | 337 { |
336 return E_ABORT; | 338 return E_ABORT; |
337 } | 339 } |
338 return nativeHr; | 340 return nativeHr; |
339 } | 341 } |
340 | 342 |
341 STDMETHODIMP WBPassthruSink::OnResponse(DWORD dwResponseCode, LPCWSTR szResponse
Headers, LPCWSTR szRequestHeaders, LPWSTR *pszAdditionalRequestHeaders) | 343 STDMETHODIMP WBPassthruSink::OnResponse(DWORD dwResponseCode, LPCWSTR szResponse
Headers, LPCWSTR szRequestHeaders, LPWSTR *pszAdditionalRequestHeaders) |
342 { | 344 { |
343 if (pszAdditionalRequestHeaders) | 345 if (pszAdditionalRequestHeaders) |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 } | 386 } |
385 | 387 |
386 return OnStart(szUrl, pOIProtSink, pOIBindInfo, grfPI, dwReserved, m_spInterne
tProtocol); | 388 return OnStart(szUrl, pOIProtSink, pOIBindInfo, grfPI, dwReserved, m_spInterne
tProtocol); |
387 } | 389 } |
388 | 390 |
389 STDMETHODIMP WBPassthru::Read(/* [in, out] */ void *pv,/* [in] */ ULONG cb,/* [o
ut] */ ULONG *pcbRead) | 391 STDMETHODIMP WBPassthru::Read(/* [in, out] */ void *pv,/* [in] */ ULONG cb,/* [o
ut] */ ULONG *pcbRead) |
390 { | 392 { |
391 WBPassthruSink* pSink = GetSink(); | 393 WBPassthruSink* pSink = GetSink(); |
392 return pSink->OnRead(pv, cb, pcbRead); | 394 return pSink->OnRead(pv, cb, pcbRead); |
393 } | 395 } |
OLD | NEW |