| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 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 std::string g_blockedByABPPage = "<!DOCTYPE html>" | 16 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 | |
| 23 template <class T> | |
| 24 T ExtractHttpHeader(const T& allHeaders, const T& targetHeaderNameWithColon, c onst T& delimiter) | |
| 25 { | |
| 26 auto targetHeaderBeginsAt = allHeaders.find(targetHeaderNameWithColon); | |
| 27 if (targetHeaderBeginsAt == T::npos) | |
| 28 { | |
| 29 return T(); | |
| 30 } | |
| 31 targetHeaderBeginsAt += targetHeaderNameWithColon.length(); | |
| 32 auto targetHeaderEndsAt = allHeaders.find(delimiter, targetHeaderBeginsAt); | |
| 33 if (targetHeaderEndsAt == T::npos) | |
| 34 { | |
| 35 return T(); | |
| 36 } | |
| 37 return allHeaders.substr(targetHeaderBeginsAt, targetHeaderEndsAt - targetHe aderBeginsAt); | |
| 38 } | |
| 39 | |
| 40 std::string ExtractHttpAcceptHeader(IInternetProtocol* internetProtocol) | |
| 41 { | |
| 42 // Despite there being HTTP_QUERY_ACCEPT and other query info flags, they do n't work here, | |
| 43 // only HTTP_QUERY_RAW_HEADERS_CRLF | HTTP_QUERY_FLAG_REQUEST_HEADERS does w ork. | |
| 44 ATL::CComPtr<IWinInetHttpInfo> winInetHttpInfo; | |
| 45 HRESULT hr = internetProtocol->QueryInterface(&winInetHttpInfo); | |
| 46 if (FAILED(hr)) | |
| 47 { | |
| 48 return ""; | |
| 49 } | |
| 50 DWORD size = 0; | |
| 51 DWORD flags = 0; | |
| 52 DWORD queryOption = HTTP_QUERY_RAW_HEADERS_CRLF | HTTP_QUERY_FLAG_REQUEST_HE ADERS; | |
| 53 hr = winInetHttpInfo->QueryInfo(queryOption, /*buffer*/ nullptr, /*get size* / &size, &flags, /*reserved*/ 0); | |
| 54 if (FAILED(hr)) | |
| 55 { | |
| 56 return ""; | |
| 57 } | |
| 58 std::string buf(size, '\0'); | |
| 59 hr = winInetHttpInfo->QueryInfo(queryOption, &buf[0], &size, &flags, 0); | |
| 60 if (FAILED(hr)) | |
| 61 { | |
| 62 return ""; | |
| 63 } | |
| 64 return ExtractHttpHeader<std::string>(buf, "Accept:", "\r\n"); | |
| 65 } | |
| 22 } | 66 } |
| 23 | 67 |
| 24 WBPassthruSink::WBPassthruSink() | 68 WBPassthruSink::WBPassthruSink() |
| 25 : m_currentPositionOfSentPage(0) | 69 : m_currentPositionOfSentPage(0) |
| 26 , m_contentType(CFilter::EContentType::contentTypeAny) | 70 , m_contentType(CFilter::EContentType::contentTypeAny) |
| 27 , m_blockedInTransaction(false) | 71 , m_blockedInTransaction(false) |
| 28 { | 72 { |
| 29 } | 73 } |
| 30 | 74 |
| 31 int WBPassthruSink::GetContentTypeFromMimeType(const CString& mimeType) | 75 int WBPassthruSink::GetContentTypeFromMimeType(const CString& mimeType) |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 186 IInternetProtocolSink::Switch with PD_FORCE_SWITCH flag in | 230 IInternetProtocolSink::Switch with PD_FORCE_SWITCH flag in |
| 187 PROTOCOLDATA::grfFlags, eventually URLMon will turn around and call | 231 PROTOCOLDATA::grfFlags, eventually URLMon will turn around and call |
| 188 IInternetProtocol::Continue on the main thread. | 232 IInternetProtocol::Continue on the main thread. |
| 189 | 233 |
| 190 Or, if you happen to have a window handy that was created on the main | 234 Or, if you happen to have a window handy that was created on the main |
| 191 thread, you can post yourself a message. | 235 thread, you can post yourself a message. |
| 192 " | 236 " |
| 193 */ | 237 */ |
| 194 return m_spInternetProtocolSink ? m_spInternetProtocolSink->Switch(pProtocolDa ta) : E_UNEXPECTED; | 238 return m_spInternetProtocolSink ? m_spInternetProtocolSink->Switch(pProtocolDa ta) : E_UNEXPECTED; |
| 195 } | 239 } |
| 196 std::string ExtractHttpAcceptHeader(IInternetProtocol* inernetProtocol) | |
|
Felix Dahlke
2014/11/04 16:13:25
internetProtocol with a t, I guess? Can you move t
| |
| 197 { | |
| 198 // Despite there being HTTP_QUERY_ACCEPT and other query info flags, they don' t work here, | |
| 199 // only HTTP_QUERY_RAW_HEADERS_CRLF | HTTP_QUERY_FLAG_REQUEST_HEADERS does dor k. | |
|
Felix Dahlke
2014/11/04 16:13:25
does dork? That a freudian? :D
| |
| 200 ATL::CComPtr<IWinInetHttpInfo> winInetHttpInfo; | |
| 201 HRESULT hr = inernetProtocol->QueryInterface(&winInetHttpInfo); | |
| 202 if (FAILED(hr)) | |
| 203 { | |
| 204 return ""; | |
| 205 } | |
| 206 DWORD size = 0; | |
| 207 DWORD flags = 0; | |
| 208 DWORD queryOption = HTTP_QUERY_RAW_HEADERS_CRLF | HTTP_QUERY_FLAG_REQUEST_HEAD ERS; | |
| 209 hr = winInetHttpInfo->QueryInfo(queryOption, /*buffer*/ nullptr, /*get size*/ &size, &flags, /*reserved*/ 0); | |
| 210 if (FAILED(hr)) | |
| 211 { | |
| 212 return ""; | |
| 213 } | |
| 214 std::string buf(size, '\0'); | |
| 215 hr = winInetHttpInfo->QueryInfo(queryOption, &buf[0], &size, &flags, 0); | |
| 216 if (FAILED(hr)) | |
| 217 { | |
| 218 return ""; | |
| 219 } | |
| 220 return ExtractHttpHeader<std::string>(buf, std::string("Accept"), "\r\n"); | |
| 221 } | |
| 222 | 240 |
| 223 // This is the heuristic which detects the requests issued by Flash.ocx. | 241 // This is the heuristic which detects the requests issued by Flash.ocx. |
| 224 // It turned out that the implementation from ''Flash.ocx'' (tested version is 1 5.0.0.152) | 242 // It turned out that the implementation from ''Flash.ocx'' (tested version is 1 5.0.0.152) |
| 225 // returns quite minimal configuration in comparison with the implementation fro m Microsofts' | 243 // returns quite minimal configuration in comparison with the implementation fro m Microsofts' |
| 226 // libraries (see grfBINDF and bindInfo.dwOptions). The impl from MS often inclu des something | 244 // libraries (see grfBINDF and bindInfo.dwOptions). The impl from MS often inclu des something |
| 227 // else. | 245 // else. |
| 228 bool WBPassthruSink::IsFlashRequest() | 246 bool WBPassthruSink::IsFlashRequest() |
| 229 { | 247 { |
| 230 ATL::CComPtr<IBindStatusCallback> bscb; | 248 ATL::CComPtr<IBindStatusCallback> bscb; |
| 231 if (SUCCEEDED(QueryServiceFromClient(&bscb)) && !!bscb) | 249 if (SUCCEEDED(QueryServiceFromClient(&bscb)) && !!bscb) |
| 232 { | 250 { |
| 233 DWORD grfBINDF = 0; | 251 DWORD grfBINDF = 0; |
| 234 BINDINFO bindInfo = {}; | 252 BINDINFO bindInfo = {}; |
| 235 bindInfo.cbSize = sizeof(bindInfo); | 253 bindInfo.cbSize = sizeof(bindInfo); |
| 236 if (SUCCEEDED(bscb->GetBindInfo(&grfBINDF, &bindInfo)) && | 254 if (SUCCEEDED(bscb->GetBindInfo(&grfBINDF, &bindInfo)) && |
| 237 (BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE| BINDF_PULLDATA) == grfBINDF && | 255 (BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE| BINDF_PULLDATA) == grfBINDF && |
| 238 (BINDINFO_OPTIONS_ENABLE_UTF8 | BINDINFO_OPTIONS_USE_IE_ENCODING) == bindI nfo.dwOptions | 256 (BINDINFO_OPTIONS_ENABLE_UTF8 | BINDINFO_OPTIONS_USE_IE_ENCODING) == bindI nfo.dwOptions |
| 239 ) | 257 ) |
| 240 { | 258 { |
| 241 return true; | 259 return true; |
| 242 } | 260 } |
| 243 } | 261 } |
| 244 return false; | 262 return false; |
| 245 } | 263 } |
| 246 | 264 |
| 247 STDMETHODIMP WBPassthruSink::BeginningTransaction(LPCWSTR szURL, LPCWSTR szHeade rs, DWORD dwReserved, LPWSTR* pszAdditionalHeaders) | 265 STDMETHODIMP WBPassthruSink::BeginningTransaction(LPCWSTR szURL, LPCWSTR szHeade rs, DWORD dwReserved, LPWSTR* pszAdditionalHeaders) |
| 248 { | 266 { |
| 249 if (pszAdditionalHeaders) | |
| 250 { | |
| 251 *pszAdditionalHeaders = nullptr; | |
| 252 } | |
| 253 std::wstring src = szURL; | 267 std::wstring src = szURL; |
| 254 DEBUG_GENERAL(ToCString(src)); | 268 DEBUG_GENERAL(ToCString(src)); |
| 269 | |
| 270 std::string acceptHeader = ExtractHttpAcceptHeader(m_spTargetProtocol); | |
| 271 m_contentType = GetContentTypeFromMimeType(ATL::CString(acceptHeader.c_str())) ; | |
| 272 | |
| 273 if (pszAdditionalHeaders) | |
| 274 { | |
| 275 *pszAdditionalHeaders = nullptr; | |
| 276 } | |
| 255 | 277 |
| 256 CComPtr<IHttpNegotiate> httpNegotiate; | 278 CComPtr<IHttpNegotiate> httpNegotiate; |
| 257 QueryServiceFromClient(&httpNegotiate); | 279 QueryServiceFromClient(&httpNegotiate); |
| 258 // This fills the pszAdditionalHeaders with more headers. One of which is the Referer header, which we need. | 280 // This fills the pszAdditionalHeaders with more headers. One of which is the Referer header, which we need. |
| 259 // There doesn't seem to be any other way to get this header before the reques t has been made. | 281 // There doesn't seem to be any other way to get this header before the reques t has been made. |
| 260 HRESULT nativeHr = httpNegotiate ? httpNegotiate->BeginningTransaction(szURL, szHeaders, dwReserved, pszAdditionalHeaders) : S_OK; | 282 HRESULT nativeHr = httpNegotiate ? httpNegotiate->BeginningTransaction(szURL, szHeaders, dwReserved, pszAdditionalHeaders) : S_OK; |
| 261 | 283 |
| 262 std::string acceptHeader = ExtractHttpAcceptHeader(m_spTargetProtocol); | |
|
Felix Dahlke
2014/11/04 16:13:25
I still think we can move this up, i.e. this and t
| |
| 263 m_contentType = GetContentTypeFromMimeType(ATL::CString(acceptHeader.c_str())) ; | |
| 264 if (*pszAdditionalHeaders != 0) | 284 if (*pszAdditionalHeaders != 0) |
| 265 { | 285 { |
| 266 m_boundDomain = ExtractHttpHeader<std::wstring>(std::wstring(*pszAdditionalH eaders), std::wstring(L"Referer")).c_str(); | 286 m_boundDomain = ExtractHttpHeader<std::wstring>(*pszAdditionalHeaders, L"Ref erer:", L"\n").c_str(); |
| 267 } | 287 } |
| 268 m_boundDomain = TrimString(m_boundDomain); | 288 m_boundDomain = TrimString(m_boundDomain); |
| 269 CPluginTab* tab = CPluginClass::GetTab(::GetCurrentThreadId()); | 289 CPluginTab* tab = CPluginClass::GetTab(::GetCurrentThreadId()); |
| 270 CPluginClient* client = CPluginClient::GetInstance(); | 290 CPluginClient* client = CPluginClient::GetInstance(); |
| 271 | 291 |
| 272 if (tab && client) | 292 if (tab && client) |
| 273 { | 293 { |
| 274 CString documentUrl = tab->GetDocumentUrl(); | 294 CString documentUrl = tab->GetDocumentUrl(); |
| 275 // Page is identical to document => don't block | 295 // Page is identical to document => don't block |
| 276 if (documentUrl == ToCString(src)) | 296 if (documentUrl == ToCString(src)) |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 355 | 375 |
| 356 STDMETHODIMP WBPassthru::LockRequest(/* [in] */ DWORD options) | 376 STDMETHODIMP WBPassthru::LockRequest(/* [in] */ DWORD options) |
| 357 { | 377 { |
| 358 return BaseClass::LockRequest(options); | 378 return BaseClass::LockRequest(options); |
| 359 } | 379 } |
| 360 | 380 |
| 361 STDMETHODIMP WBPassthru::UnlockRequest() | 381 STDMETHODIMP WBPassthru::UnlockRequest() |
| 362 { | 382 { |
| 363 return BaseClass::UnlockRequest(); | 383 return BaseClass::UnlockRequest(); |
| 364 } | 384 } |
| LEFT | RIGHT |