Left: | ||
Right: |
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 #ifdef SUPPORT_FILTER | 6 #ifdef SUPPORT_FILTER |
7 #include "PluginFilter.h" | 7 #include "PluginFilter.h" |
8 #endif | 8 #endif |
9 #include "PluginSettings.h" | 9 #include "PluginSettings.h" |
10 #include "PluginClass.h" | 10 #include "PluginClass.h" |
11 #include "PluginSystem.h" | 11 #include "PluginSystem.h" |
12 | 12 #include <WinInet.h> |
13 #include "wtypes.h" | 13 #include "wtypes.h" |
14 | 14 |
15 namespace | 15 namespace |
16 { | 16 { |
17 std::string g_myPageBlocked = "<!DOCTYPE html>" | 17 std::string g_myPageBlocked = "<!DOCTYPE html>" |
18 "<html>" | 18 "<html>" |
19 "<body>" | 19 "<body>" |
20 "<!-- blocked by AdblockPlus -->" | 20 "<!-- blocked by AdblockPlus -->" |
21 "</body>" | 21 "</body>" |
22 "</html>"; | 22 "</html>"; |
23 } | 23 } |
24 | 24 |
25 WBPassthruSink::WBPassthruSink() | |
26 : m_currentPositionOfSentPage(0) | |
27 , m_contentType(CFilter::EContentType::contentTypeAny) | |
28 { | |
29 } | |
30 | |
25 int WBPassthruSink::GetContentTypeFromMimeType(const CString& mimeType) | 31 int WBPassthruSink::GetContentTypeFromMimeType(const CString& mimeType) |
26 { | 32 { |
27 if (mimeType.Find(L"image/") >= 0) | 33 if (mimeType.Find(L"image/") >= 0) |
28 { | 34 { |
29 return CFilter::contentTypeImage; | 35 return CFilter::contentTypeImage; |
30 } | 36 } |
31 if (mimeType.Find(L"text/css") >= 0) | 37 if (mimeType.Find(L"text/css") >= 0) |
32 { | 38 { |
33 return CFilter::contentTypeStyleSheet; | 39 return CFilter::contentTypeStyleSheet; |
34 } | 40 } |
35 if ((mimeType.Find(L"application/javascript") >= 0) || (mimeType.Find(L"applic ation/json") >= 0)) | 41 if ((mimeType.Find(L"application/javascript") >= 0) || (mimeType.Find(L"applic ation/json") >= 0)) |
36 { | 42 { |
37 return CFilter::contentTypeScript; | 43 return CFilter::contentTypeScript; |
38 } | 44 } |
39 if (mimeType.Find(L"application/x-shockwave-flash") >= 0) | 45 if (mimeType.Find(L"application/x-shockwave-flash") >= 0) |
40 { | 46 { |
41 return CFilter::contentTypeObject; | 47 return CFilter::contentTypeObject; |
42 } | 48 } |
43 if (mimeType.Find(L"text/html") >= 0) | 49 if (mimeType.Find(L"text/html") >= 0) |
44 { | 50 { |
45 return CFilter::contentTypeSubdocument; | 51 return CFilter::contentTypeSubdocument; |
46 } | 52 } |
47 // It is important to have this check last, since it is rather generic, and mi ght overlay text/html, for example | |
48 if (mimeType.Find(L"xml") >= 0) | |
49 { | |
50 return CFilter::contentTypeXmlHttpRequest; | |
51 } | |
52 | |
53 return CFilter::contentTypeAny; | 53 return CFilter::contentTypeAny; |
54 } | 54 } |
55 | 55 |
56 int WBPassthruSink::GetContentTypeFromURL(const CString& src) | 56 int WBPassthruSink::GetContentTypeFromURL(const CString& src) |
57 { | 57 { |
58 CString srcExt = src; | 58 CString srcExt = src; |
59 | 59 |
60 int pos = 0; | 60 int pos = 0; |
61 if ((pos = src.Find('?')) > 0) | 61 if ((pos = src.Find('?')) > 0) |
62 { | 62 { |
63 srcExt = src.Left(pos); | 63 srcExt = src.Left(pos); |
64 } | 64 } |
65 | 65 |
66 int lastDotIndex = srcExt.ReverseFind('.'); | 66 int lastDotIndex = srcExt.ReverseFind('.'); |
67 if (lastDotIndex < 0) | 67 if (lastDotIndex < 0) |
68 return CFilter::contentTypeAny; | 68 return CFilter::contentTypeAny; |
69 CString ext = srcExt.Mid(lastDotIndex); | 69 CString ext = srcExt.Mid(lastDotIndex); |
70 if (ext == L".jpg" || ext == L".gif" || ext == L".png" || ext == L".jpeg") | 70 if (ext == L".jpg" || ext == L".gif" || ext == L".png" || ext == L".jpeg") |
71 { | 71 { |
72 return CFilter::contentTypeImage; | 72 return CFilter::contentTypeImage; |
73 } | 73 } |
74 else if (ext == L".css") | 74 else if (ext == L".css") |
75 { | 75 { |
76 return CFilter::contentTypeStyleSheet; | 76 return CFilter::contentTypeStyleSheet; |
77 } | 77 } |
78 else if (ext.Right(3) == L".js") | 78 else if (ext.Right(3) == L".js") |
79 { | 79 { |
80 return CFilter::contentTypeScript; | 80 return CFilter::contentTypeScript; |
81 } | 81 } |
82 else if (ext == L".xml") | |
83 { | |
84 return CFilter::contentTypeXmlHttpRequest; | |
85 } | |
86 else if (ext == L".swf") | 82 else if (ext == L".swf") |
87 { | 83 { |
88 return CFilter::contentTypeObject; | 84 return CFilter::contentTypeObject; |
89 } | 85 } |
90 else if (ext == L".jsp" || ext == L".php" || ext == L".html") | 86 else if (ext == L".jsp" || ext == L".php" || ext == L".html") |
91 { | 87 { |
92 return CFilter::contentTypeSubdocument; | 88 return CFilter::contentTypeSubdocument; |
93 } | 89 } |
94 | 90 return CFilter::contentTypeAny; |
95 return CFilter::contentTypeAny & ~CFilter::contentTypeSubdocument; | |
96 } | 91 } |
97 | 92 |
98 int WBPassthruSink::GetContentType(const CString& mimeType, const CString& domai n, const CString& src) | 93 int WBPassthruSink::GetContentType(const CString& mimeType, const CString& domai n, const CString& src) |
99 { | 94 { |
100 // No referer or mime type | 95 // No referer or mime type |
101 // BINDSTRING_XDR_ORIGIN works only for IE v8+ | 96 // BINDSTRING_XDR_ORIGIN works only for IE v8+ |
102 if (mimeType.IsEmpty() && domain.IsEmpty() && CPluginClient::GetInstance()->Ge tIEVersion() >= 8) | 97 if (mimeType.IsEmpty() && domain.IsEmpty() && CPluginClient::GetInstance()->Ge tIEVersion() >= 8) |
103 { | 98 { |
104 return CFilter::contentTypeXmlHttpRequest; | 99 return CFilter::contentTypeXmlHttpRequest; |
105 } | 100 } |
106 int contentType = GetContentTypeFromMimeType(mimeType); | 101 int contentType = GetContentTypeFromMimeType(mimeType); |
107 if (contentType == CFilter::contentTypeAny) | 102 if (contentType == CFilter::contentTypeAny) |
108 { | 103 { |
109 contentType = GetContentTypeFromURL(src); | 104 contentType = GetContentTypeFromURL(src); |
110 } | 105 } |
111 return contentType; | 106 return contentType; |
112 } | 107 } |
113 | 108 |
114 //////////////////////////////////////////////////////////////////////////////// //////// | 109 //////////////////////////////////////////////////////////////////////////////// //////// |
115 //WBPassthruSink | 110 //WBPassthruSink |
116 //Monitor and/or cancel every request and responde | 111 //Monitor and/or cancel every request and responde |
117 //WB makes, including images, sounds, scripts, etc | 112 //WB makes, including images, sounds, scripts, etc |
118 //////////////////////////////////////////////////////////////////////////////// //////// | 113 //////////////////////////////////////////////////////////////////////////////// //////// |
119 HRESULT WBPassthruSink::OnStart(LPCWSTR szUrl, IInternetProtocolSink *pOIProtSin k, | 114 HRESULT WBPassthruSink::OnStart(LPCWSTR szUrl, IInternetProtocolSink *pOIProtSin k, |
120 IInternetBindInfo *pOIBindInfo, DWORD grfPI, HAN DLE_PTR dwReserved, | 115 IInternetBindInfo *pOIBindInfo, DWORD grfPI, HAN DLE_PTR dwReserved, |
121 IInternetProtocol* pTargetProtocol, bool& handle d) | 116 IInternetProtocol* pTargetProtocol, bool& handle d) |
122 { | 117 { |
123 m_pTargetProtocol = pTargetProtocol; | 118 m_pTargetProtocol = pTargetProtocol; |
124 bool isBlocked = false; | 119 bool isBlocked = false; |
125 m_currentPositionOfSentPage = 0; | |
126 CString src = szUrl; | 120 CString src = szUrl; |
127 DEBUG_GENERAL(src); | 121 DEBUG_GENERAL(src); |
128 CPluginClient::UnescapeUrl(src); | 122 CPluginClient::UnescapeUrl(src); |
129 | 123 |
130 CString boundDomain; | |
131 CString mimeType; | 124 CString mimeType; |
132 LPOLESTR mime[10]; | |
133 if (pOIBindInfo) | 125 if (pOIBindInfo) |
134 { | 126 { |
135 ULONG resLen = 0; | 127 ULONG resLen = 0; |
136 | 128 |
137 // Apparently IE will report random mime type if there's more then 1 in the list. | 129 // Apparently IE will report random mime type if there's more then 1 in the list. |
138 // So we get the whole list and just use the first one (top priority one) | 130 // So we get the whole list and just use the first one (top priority one) |
131 LPOLESTR mime[10]; | |
139 pOIBindInfo->GetBindString(BINDSTRING_ACCEPT_MIMES, mime, 10, &resLen); | 132 pOIBindInfo->GetBindString(BINDSTRING_ACCEPT_MIMES, mime, 10, &resLen); |
140 if (mime && resLen > 0) | 133 if (mime && resLen > 0) |
141 { | 134 { |
142 mimeType.SetString(mime[0]); | 135 mimeType.SetString(mime[0]); |
143 } | 136 } |
144 LPOLESTR bindToObject = 0; | 137 LPOLESTR bindToObject = nullptr; |
145 pOIBindInfo->GetBindString(BINDSTRING_FLAG_BIND_TO_OBJECT, &bindToObject, 1, &resLen); | 138 pOIBindInfo->GetBindString(BINDSTRING_FLAG_BIND_TO_OBJECT, &bindToObject, 1, &resLen); |
146 LPOLESTR domainRetrieved = 0; | 139 LPOLESTR domainRetrieved = nullptr; |
147 if (resLen == 0 || wcscmp(bindToObject, L"FALSE") == 0) | 140 if (resLen == 0 || wcscmp(bindToObject, L"FALSE") == 0) |
148 { | 141 { |
149 HRESULT hr = pOIBindInfo->GetBindString(BINDSTRING_XDR_ORIGIN, &domainRetr ieved, 1, &resLen); | 142 HRESULT hr = pOIBindInfo->GetBindString(BINDSTRING_XDR_ORIGIN, &domainRetr ieved, 1, &resLen); |
150 | |
151 if ((hr == S_OK) && domainRetrieved && (resLen > 0)) | 143 if ((hr == S_OK) && domainRetrieved && (resLen > 0)) |
152 { | 144 { |
153 boundDomain.SetString(domainRetrieved); | 145 m_boundDomain = domainRetrieved; |
154 } | 146 } |
155 } | 147 } |
156 } | 148 } |
157 | 149 |
158 CString cookie; | 150 CString cookie; |
159 ULONG len1 = 2048; | 151 ULONG len1 = 2048; |
160 ULONG len2 = 2048; | 152 ULONG len2 = 2048; |
161 | 153 |
162 #ifdef SUPPORT_FILTER | 154 #ifdef SUPPORT_FILTER |
163 int contentType = CFilter::contentTypeAny; | |
164 | |
165 CPluginTab* tab = CPluginClass::GetTab(::GetCurrentThreadId()); | 155 CPluginTab* tab = CPluginClass::GetTab(::GetCurrentThreadId()); |
166 CPluginClient* client = CPluginClient::GetInstance(); | 156 CPluginClient* client = CPluginClient::GetInstance(); |
167 | 157 |
168 | |
169 if (tab && client) | 158 if (tab && client) |
170 { | 159 { |
171 CString documentUrl = tab->GetDocumentUrl(); | 160 CString documentUrl = tab->GetDocumentUrl(); |
172 // Page is identical to document => don't block | 161 // Page is identical to document => don't block |
173 if (documentUrl == src) | 162 if (documentUrl == src) |
174 { | 163 { |
175 // fall through | 164 // fall through |
176 } | 165 } |
177 else if (CPluginSettings::GetInstance()->IsPluginEnabled() && !client->IsWhi telistedUrl(std::wstring(documentUrl))) | 166 else if (CPluginSettings::GetInstance()->IsPluginEnabled() && !client->IsWhi telistedUrl(std::wstring(documentUrl))) |
178 { | 167 { |
179 boundDomain = tab->GetDocumentUrl(); | 168 m_boundDomain = tab->GetDocumentUrl(); |
180 | 169 m_contentType = CFilter::contentTypeAny; |
181 contentType = CFilter::contentTypeAny; | |
182 | |
183 #ifdef SUPPORT_FRAME_CACHING | 170 #ifdef SUPPORT_FRAME_CACHING |
184 if ((tab != 0) && (tab->IsFrameCached(src))) | 171 if (nullptr != tab && tab->IsFrameCached(src)) |
185 { | 172 { |
186 contentType = CFilter::contentTypeSubdocument; | 173 m_contentType = CFilter::contentTypeSubdocument; |
187 } | 174 } |
188 else | 175 else |
189 #endif // SUPPORT_FRAME_CACHING | 176 #endif // SUPPORT_FRAME_CACHING |
190 contentType = GetContentType(mimeType, boundDomain, src); | |
191 if (client->ShouldBlock(src, contentType, boundDomain, true)) | |
192 { | 177 { |
193 isBlocked = true; | 178 m_contentType = GetContentType(mimeType, m_boundDomain, src); |
194 | |
195 DEBUG_BLOCKER("Blocker::Blocking Http-request:" + src); | |
196 } | 179 } |
197 } | 180 } |
198 if (!isBlocked) | 181 |
199 { | |
200 DEBUG_BLOCKER("Blocker::Ignoring Http-request:" + src) | |
201 } | |
202 } | 182 } |
203 | 183 |
204 | 184 if (nullptr == tab) |
205 if (tab == NULL) | |
206 { | 185 { |
207 contentType = GetContentType(mimeType, boundDomain, src); | 186 m_contentType = GetContentType(mimeType, m_boundDomain, src); |
208 if (client->ShouldBlock(src, contentType, boundDomain, true)) | |
209 { | |
210 isBlocked = true; | |
211 } | |
212 } | 187 } |
213 | 188 |
214 #ifdef _DEBUG | 189 if (nullptr != client |
215 CString type; | 190 && CFilter::EContentType::contentTypeAny != m_contentType |
Oleksandr
2014/09/11 08:58:54
This line is not clear to me. We can in theory blo
sergei
2014/09/11 09:53:25
If the type is `contentTypeAny` then the decision
| |
191 && client->ShouldBlock(src, m_contentType, m_boundDomain, true)) | |
192 { | |
193 isBlocked = true; | |
194 DEBUG_BLOCKER("Blocker::Blocking Http-request:" + src); | |
Oleksandr
2014/09/11 08:58:54
DEBUG_BLOCKER is broken here. Either use CPluginDe
sergei
2014/09/11 09:53:25
`client->ShouldBlock` already puts into the log. `
| |
195 } | |
196 if (!isBlocked) | |
197 { | |
198 DEBUG_BLOCKER("Blocker::Ignoring Http-request:" + src) | |
Oleksandr
2014/09/11 08:58:54
CPluginDebug::DebugResultIgnoring here accordingly
sergei
2014/09/11 09:53:25
The same as above, deleted.
| |
199 } | |
216 | 200 |
217 if (contentType == CFilter::contentTypeDocument) type = "DOCUMENT"; | 201 // For IE6 and earlier there is iframe back button issue, so avoid it. |
218 else if (contentType == CFilter::contentTypeObject) type = "OBJECT"; | 202 if (isBlocked && client->GetIEVersion() > 6) |
219 else if (contentType == CFilter::contentTypeImage) type = "IMAGE"; | |
220 else if (contentType == CFilter::contentTypeScript) type = "SCRIPT"; | |
221 else if (contentType == CFilter::contentTypeOther) type = "OTHER"; | |
222 else if (contentType == CFilter::contentTypeUnknown) type = "OTHER"; | |
223 else if (contentType == CFilter::contentTypeSubdocument) type = "SUBDOCUMENT"; | |
224 else if (contentType == CFilter::contentTypeStyleSheet) type = "STYLESHEET"; | |
225 else type = "OTHER"; | |
Oleksandr
2014/09/11 08:58:54
We will still need a way to convert contentType to
sergei
2014/09/11 09:53:25
It's done in `CPluginFilter`
| |
226 | |
227 if (isBlocked) | |
228 { | 203 { |
229 CPluginDebug::DebugResultBlocking(type, src, boundDomain); | 204 handled = true; |
230 } | 205 if (CFilter::EContentType::contentTypeImage == m_contentType) |
231 else | |
232 { | |
233 CPluginDebug::DebugResultIgnoring(type, src, boundDomain); | |
234 } | |
235 #endif | |
236 | |
237 //Fixes the iframe back button issue | |
238 if (client->GetIEVersion() > 6) | |
239 { | |
240 if (contentType == CFilter::contentTypeImage && isBlocked) | |
241 { | 206 { |
242 BaseClass::OnStart(szUrl, pOIProtSink, pOIBindInfo, grfPI, dwReserved, pTa rgetProtocol); | 207 BaseClass::OnStart(szUrl, pOIProtSink, pOIBindInfo, grfPI, dwReserved, pTa rgetProtocol); |
243 handled = true; | |
244 // IE shows a cross that img is not loaded | 208 // IE shows a cross that img is not loaded |
245 return INET_E_REDIRECT_FAILED; | 209 return INET_E_REDIRECT_FAILED; |
246 } | 210 } |
247 if (contentType == CFilter::contentTypeSubdocument && isBlocked) | 211 if (CFilter::EContentType::contentTypeSubdocument == m_contentType) |
248 { | 212 { |
249 PassthroughAPP::CustomSinkStartPolicy<WBPassthru, WBPassthruSink>::GetProt ocol(this)->m_shouldSupplyCustomContent = true; | 213 PassthroughAPP::CustomSinkStartPolicy<WBPassthru, WBPassthruSink>::GetProt ocol(this)->m_shouldSupplyCustomContent = true; |
250 BaseClass::OnStart(szUrl, pOIProtSink, pOIBindInfo, grfPI, dwReserved, pTa rgetProtocol); | 214 BaseClass::OnStart(szUrl, pOIProtSink, pOIBindInfo, grfPI, dwReserved, pTa rgetProtocol); |
251 | |
252 m_spInternetProtocolSink->ReportProgress(BINDSTATUS_MIMETYPEAVAILABLE, L"t ext/html"); | 215 m_spInternetProtocolSink->ReportProgress(BINDSTATUS_MIMETYPEAVAILABLE, L"t ext/html"); |
253 m_spInternetProtocolSink->ReportData(BSCF_FIRSTDATANOTIFICATION, 0, static _cast<ULONG>(g_myPageBlocked.size())); | 216 m_spInternetProtocolSink->ReportData(BSCF_FIRSTDATANOTIFICATION, 0, static _cast<ULONG>(g_myPageBlocked.size())); |
254 handled = true; | |
255 return S_OK; | 217 return S_OK; |
256 } | 218 } |
257 if (contentType == CFilter::contentTypeScript && isBlocked) | 219 if (CFilter::EContentType::contentTypeScript == m_contentType) |
258 { | 220 { |
259 BaseClass::OnStart(szUrl, pOIProtSink, pOIBindInfo, grfPI, dwReserved, pTa rgetProtocol); | 221 BaseClass::OnStart(szUrl, pOIProtSink, pOIBindInfo, grfPI, dwReserved, pTa rgetProtocol); |
260 m_spInternetProtocolSink->ReportProgress(BINDSTATUS_MIMETYPEAVAILABLE, L"t ext/javascript"); | 222 m_spInternetProtocolSink->ReportProgress(BINDSTATUS_MIMETYPEAVAILABLE, L"t ext/javascript"); |
261 m_spInternetProtocolSink->ReportResult(INET_E_REDIRECTING, 301, L"data:"); | 223 m_spInternetProtocolSink->ReportResult(INET_E_REDIRECTING, 301, L"data:"); |
262 handled = true; | |
263 return INET_E_REDIRECT_FAILED; | 224 return INET_E_REDIRECT_FAILED; |
264 } | 225 } |
265 if (contentType == CFilter::contentTypeXmlHttpRequest && isBlocked) | 226 if (CFilter::EContentType::contentTypeXmlHttpRequest == m_contentType) |
266 { | 227 { |
267 BaseClass::OnStart(szUrl, pOIProtSink, pOIBindInfo, grfPI, dwReserved, pTa rgetProtocol); | 228 BaseClass::OnStart(szUrl, pOIProtSink, pOIBindInfo, grfPI, dwReserved, pTa rgetProtocol); |
268 m_spInternetProtocolSink->ReportResult(INET_E_REDIRECTING, 301, L"data:"); | 229 m_spInternetProtocolSink->ReportResult(INET_E_REDIRECTING, 301, L"data:"); |
269 handled = true; | |
270 return INET_E_REDIRECT_FAILED; | |
271 } | |
272 if (isBlocked) | |
273 { | |
274 BaseClass::OnStart(szUrl, pOIProtSink, pOIBindInfo, grfPI, dwReserved, pTa rgetProtocol); | |
275 m_spInternetProtocolSink->ReportResult(S_FALSE, 0, L""); | |
276 handled = true; | |
277 return INET_E_REDIRECT_FAILED; | 230 return INET_E_REDIRECT_FAILED; |
278 } | 231 } |
279 } | 232 } |
280 #endif // SUPPORT_FILTER | 233 #endif // SUPPORT_FILTER |
281 | 234 |
282 return isBlocked ? S_FALSE : BaseClass::OnStart(szUrl, pOIProtSink, pOIBindInf o, grfPI, dwReserved, pTargetProtocol); | 235 return isBlocked ? S_FALSE : BaseClass::OnStart(szUrl, pOIProtSink, pOIBindInf o, grfPI, dwReserved, pTargetProtocol); |
283 } | 236 } |
284 | 237 |
285 | |
286 HRESULT WBPassthruSink::OnRead(void* pv, ULONG cb, ULONG* pcbRead) | 238 HRESULT WBPassthruSink::OnRead(void* pv, ULONG cb, ULONG* pcbRead) |
287 { | 239 { |
288 if (nullptr == pv) | 240 if (nullptr == pv) |
289 { | 241 { |
290 return E_POINTER; | 242 return E_POINTER; |
291 } | 243 } |
292 if (nullptr == pcbRead) | 244 if (nullptr == pcbRead) |
293 { | 245 { |
294 return E_POINTER; | 246 return E_POINTER; |
295 } | 247 } |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
341 PROTOCOLDATA::grfFlags, eventually URLMon will turn around and call | 293 PROTOCOLDATA::grfFlags, eventually URLMon will turn around and call |
342 IInternetProtocol::Continue on the main thread. | 294 IInternetProtocol::Continue on the main thread. |
343 | 295 |
344 Or, if you happen to have a window handy that was created on the main | 296 Or, if you happen to have a window handy that was created on the main |
345 thread, you can post yourself a message. | 297 thread, you can post yourself a message. |
346 " | 298 " |
347 */ | 299 */ |
348 return m_spInternetProtocolSink ? m_spInternetProtocolSink->Switch(pProtocolDa ta) : E_UNEXPECTED; | 300 return m_spInternetProtocolSink ? m_spInternetProtocolSink->Switch(pProtocolDa ta) : E_UNEXPECTED; |
349 } | 301 } |
350 | 302 |
351 STDMETHODIMP WBPassthruSink::BeginningTransaction(LPCWSTR szURL, LPCWSTR szHeade rs, DWORD dwReserved, LPWSTR *pszAdditionalHeaders) | 303 STDMETHODIMP WBPassthruSink::BeginningTransaction(LPCWSTR szURL, LPCWSTR szHeade rs, DWORD dwReserved, LPWSTR* pszAdditionalHeaders) |
352 { | 304 { |
353 if (pszAdditionalHeaders) | 305 if (pszAdditionalHeaders) |
354 { | 306 { |
355 *pszAdditionalHeaders = 0; | 307 *pszAdditionalHeaders = nullptr; |
356 } | 308 } |
357 | 309 |
310 CPluginClient* client = nullptr; | |
311 if (CFilter::EContentType::contentTypeAny == m_contentType && (client = CPlugi nClient::GetInstance())) | |
312 { | |
313 auto acceptHeader = [&]() -> std::string | |
Oleksandr
2014/09/11 08:58:54
I'd just like to say this looks too cool :D
sergei
2014/09/11 09:53:25
Thanks!
| |
314 { | |
315 ATL::CComPtr<IWinInetHttpInfo> winInetHttpInfo; | |
316 HRESULT hr = m_spTargetProtocol->QueryInterface(&winInetHttpInfo); | |
317 if(FAILED(hr)) | |
318 { | |
319 return ""; | |
320 } | |
321 DWORD size = 0; | |
322 DWORD flags = 0; | |
323 hr = winInetHttpInfo->QueryInfo(HTTP_QUERY_RAW_HEADERS_CRLF | HTTP_QUERY_F LAG_REQUEST_HEADERS, | |
324 /*buffer*/nullptr, /* get size */&size, &flags, /*reserved*/ 0); | |
325 if(FAILED(hr)) | |
326 { | |
327 return ""; | |
328 } | |
329 std::string buf(size, '\0'); | |
330 hr = winInetHttpInfo->QueryInfo(HTTP_QUERY_RAW_HEADERS_CRLF | HTTP_QUERY_F LAG_REQUEST_HEADERS, | |
331 &buf[0], &size, &flags, 0); | |
332 if(FAILED(hr)) | |
333 { | |
334 return ""; | |
335 } | |
336 char acceptHeader[] = "Accept:"; | |
337 auto acceptHeaderBeginsAt = buf.find(acceptHeader); | |
338 if (std::string::npos == acceptHeaderBeginsAt) | |
339 { | |
340 return ""; | |
341 } | |
342 acceptHeaderBeginsAt += sizeof(acceptHeader); | |
343 auto acceptHeaderEndsAt = buf.find("\n", acceptHeaderBeginsAt); | |
344 if (std::string::npos == acceptHeaderEndsAt) | |
345 { | |
346 return ""; | |
347 } | |
348 return buf.substr(acceptHeaderBeginsAt, acceptHeaderEndsAt - acceptHeaderB eginsAt); | |
349 }(); | |
350 m_contentType = GetContentTypeFromMimeType(ATL::CString(acceptHeader.c_str() )); | |
351 bool isBlocked = client->ShouldBlock(szURL, m_contentType, | |
352 //client->GetHostFromUrl(m_boundDomain.operator LPCWSTR()).c_str(), /*debu g flag but must be set*/true); | |
Oleksandr
2014/09/11 08:58:54
Leftover code here?
sergei
2014/09/11 09:53:25
Thanks, removed.
| |
353 m_boundDomain, /*debug flag but must be set*/true); | |
354 if (isBlocked) | |
355 { | |
Oleksandr
2014/09/11 08:58:54
Log blocking here as well
sergei
2014/09/11 09:53:25
`client->ShouldBlock` puts into log
| |
356 return E_ABORT; | |
357 } | |
358 } | |
358 CComPtr<IHttpNegotiate> spHttpNegotiate; | 359 CComPtr<IHttpNegotiate> spHttpNegotiate; |
359 QueryServiceFromClient(&spHttpNegotiate); | 360 QueryServiceFromClient(&spHttpNegotiate); |
360 return spHttpNegotiate ? spHttpNegotiate->BeginningTransaction(szURL, szHeader s,dwReserved, pszAdditionalHeaders) : S_OK; | 361 return spHttpNegotiate ? spHttpNegotiate->BeginningTransaction(szURL, szHeader s,dwReserved, pszAdditionalHeaders) : S_OK; |
361 } | 362 } |
362 | 363 |
363 STDMETHODIMP WBPassthruSink::OnResponse(DWORD dwResponseCode, LPCWSTR szResponse Headers, LPCWSTR szRequestHeaders, LPWSTR *pszAdditionalRequestHeaders) | 364 STDMETHODIMP WBPassthruSink::OnResponse(DWORD dwResponseCode, LPCWSTR szResponse Headers, LPCWSTR szRequestHeaders, LPWSTR *pszAdditionalRequestHeaders) |
364 { | 365 { |
365 if (pszAdditionalRequestHeaders) | 366 if (pszAdditionalRequestHeaders) |
366 { | 367 { |
367 *pszAdditionalRequestHeaders = 0; | 368 *pszAdditionalRequestHeaders = 0; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
411 } | 412 } |
412 | 413 |
413 STDMETHODIMP WBPassthru::UnlockRequest() | 414 STDMETHODIMP WBPassthru::UnlockRequest() |
414 { | 415 { |
415 if (m_shouldSupplyCustomContent) | 416 if (m_shouldSupplyCustomContent) |
416 { | 417 { |
417 return S_OK; | 418 return S_OK; |
418 } | 419 } |
419 return PassthroughAPP::CInternetProtocol<WBStartPolicy>::UnlockRequest(); | 420 return PassthroughAPP::CInternetProtocol<WBStartPolicy>::UnlockRequest(); |
420 } | 421 } |
OLD | NEW |