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 #include "Wrapper.h" |
| 13 #include "PluginUtil.h" |
12 | 14 |
13 #include "wtypes.h" | 15 #include "wtypes.h" |
14 | 16 |
15 EXTERN_C IMAGE_DOS_HEADER __ImageBase; | 17 EXTERN_C IMAGE_DOS_HEADER __ImageBase; |
16 | 18 |
17 | 19 |
18 WBPassthruSink::WBPassthruSink() | 20 WBPassthruSink::WBPassthruSink() |
19 { | 21 { |
20 m_pTargetProtocol = NULL; | 22 m_pTargetProtocol = NULL; |
21 } | 23 } |
22 int WBPassthruSink::GetContentTypeFromMimeType(CString mimeType) | 24 int WBPassthruSink::GetContentTypeFromMimeType( std::wstring mime_type ) |
23 { | 25 { |
24 if (mimeType.Find(L"image/") >= 0) | 26 if ( mime_type.find( L"image/" ) != std::wstring::npos ) |
25 { | 27 { |
26 return CFilter::contentTypeImage; | 28 return CFilter::contentTypeImage; |
27 } | 29 } |
28 if (mimeType.Find(L"text/css") >= 0) | 30 if ( mime_type.find( L"text/css" ) != std::wstring::npos ) |
29 { | 31 { |
30 return CFilter::contentTypeStyleSheet; | 32 return CFilter::contentTypeStyleSheet; |
31 } | 33 } |
32 if ((mimeType.Find(L"application/javascript") >= 0) || (mimeType.Find(L"applic
ation/json") >= 0)) | 34 if ( mime_type.find( L"application/javascript" ) != std::wstring::npos |
| 35 || mime_type.find( L"application/json" ) != std::wstring::npos ) |
33 { | 36 { |
34 return CFilter::contentTypeScript; | 37 return CFilter::contentTypeScript; |
35 } | 38 } |
36 if (mimeType.Find(L"application/x-shockwave-flash") >= 0) | 39 if ( mime_type.find( L"application/x-shockwave-flash" ) != std::wstring::npos
) |
37 { | 40 { |
38 return CFilter::contentTypeObject; | 41 return CFilter::contentTypeObject; |
39 } | 42 } |
40 if (mimeType.Find(L"text/html") >= 0) | 43 if ( mime_type.find( L"text/html" ) != std::wstring::npos ) |
41 { | 44 { |
42 return CFilter::contentTypeSubdocument; | 45 return CFilter::contentTypeSubdocument; |
43 } | 46 } |
44 // It is important to have this check last, since it is rather generic, and mi
ght overlay text/html, for example | 47 // It is important to have this check last, since it is rather generic, and mi
ght overlay text/html, for example |
45 if (mimeType.Find(L"xml") >= 0) | 48 if ( mime_type.find( L"xml" ) != std::wstring::npos ) |
46 { | 49 { |
47 return CFilter::contentTypeXmlHttpRequest; | 50 return CFilter::contentTypeXmlHttpRequest; |
48 } | 51 } |
49 | |
50 return CFilter::contentTypeAny; | 52 return CFilter::contentTypeAny; |
51 } | 53 } |
52 | 54 |
53 int WBPassthruSink::GetContentTypeFromURL(CString src) | 55 int WBPassthruSink::GetContentTypeFromURL( std::wstring src ) |
54 { | 56 { |
55 CString srcExt = src; | 57 // Start search for extension at beginning of query, if any |
| 58 size_t ext_end = src.find( L'?' ); |
| 59 // Assert ext_end <= src.length --> src[ ext_end ] == '?' |
| 60 // Assert ext_end == npos --> there's no '?' character and ext_end == npos, wh
ich represents "end of string" in wstring::substr() |
56 | 61 |
57 int pos = 0; | 62 // Locate punctuation for extension, if any |
58 if ((pos = src.Find('?')) > 0) | 63 size_t ext_begin = src.rfind( L'.', ext_end ); |
| 64 if ( ext_begin == std::wstring::npos ) |
59 { | 65 { |
60 srcExt = src.Left(pos); | 66 // No punctuation |
| 67 return CFilter::contentTypeAny; |
61 } | 68 } |
| 69 // Adding 1 to ext_begin excludes punctuation |
| 70 std::wstring ext = src.substr( ext_begin + 1, ext_end ); |
| 71 // Assert ext contains all text after last period character to beginning of qu
ery, or if no query, to end of string |
62 | 72 |
63 int lastDotIndex = srcExt.ReverseFind('.'); | 73 if (ext == L"jpg" || ext == L"gif" || ext == L"png" || ext == L"jpeg") |
64 if (lastDotIndex < 0) | |
65 return CFilter::contentTypeAny; | |
66 CString ext = srcExt.Mid(lastDotIndex); | |
67 if (ext == L".jpg" || ext == L".gif" || ext == L".png" || ext == L".jpeg") | |
68 { | 74 { |
69 return CFilter::contentTypeImage; | 75 return CFilter::contentTypeImage; |
70 } | 76 } |
71 else if (ext == L".css") | 77 else if (ext == L"css") |
72 { | 78 { |
73 return CFilter::contentTypeStyleSheet; | 79 return CFilter::contentTypeStyleSheet; |
74 } | 80 } |
75 else if (ext.Right(3) == L".js") | 81 // Test for "jsp" before "js*" below |
| 82 else if ( ext == L"jsp" || ext == L"php" || ABP::util::begins_with( ext, L"htm
" ) ) |
| 83 { |
| 84 return CFilter::contentTypeSubdocument; |
| 85 } |
| 86 else if ( ABP::util::begins_with( ext, L"js" ) ) |
76 { | 87 { |
77 return CFilter::contentTypeScript; | 88 return CFilter::contentTypeScript; |
78 } | 89 } |
79 else if (ext == L".xml") | 90 else if (ext == L"xml") |
80 { | 91 { |
81 return CFilter::contentTypeXmlHttpRequest; | 92 return CFilter::contentTypeXmlHttpRequest; |
82 } | 93 } |
83 else if (ext == L".swf") | 94 else if (ext == L"swf") |
84 { | 95 { |
85 return CFilter::contentTypeObject; | 96 return CFilter::contentTypeObject; |
86 } | 97 } |
87 else if (ext == L".jsp" || ext == L".php" || ext == L".html") | |
88 { | |
89 return CFilter::contentTypeSubdocument; | |
90 } | |
91 else | 98 else |
92 { | 99 { |
93 return CFilter::contentTypeAny & ~CFilter::contentTypeSubdocument; | 100 return CFilter::contentTypeAny & ~CFilter::contentTypeSubdocument; |
94 } | 101 } |
95 | 102 |
96 } | 103 } |
97 | 104 |
98 int WBPassthruSink::GetContentType(CString mimeType, CString domain, CString src
) | 105 int WBPassthruSink::GetContentType(std::wstring mimeType, std::wstring domain, s
td::wstring src) |
99 { | 106 { |
100 // No referer or mime type | 107 // No referer or mime type |
101 // BINDSTRING_XDR_ORIGIN works only for IE v8+ | 108 // BINDSTRING_XDR_ORIGIN works only for IE v8+ |
102 if (mimeType.IsEmpty() && domain.IsEmpty() && CPluginClient::GetInstance()->Ge
tIEVersion() >= 8) | 109 if (mimeType.empty() && domain.empty() && CPluginClient::GetInstance()->GetIEV
ersion() >= 8) |
103 { | 110 { |
104 return CFilter::contentTypeXmlHttpRequest; | 111 return CFilter::contentTypeXmlHttpRequest; |
105 } | 112 } |
106 int contentType = GetContentTypeFromMimeType(mimeType); | 113 int contentType = GetContentTypeFromMimeType(mimeType); |
107 if (contentType == CFilter::contentTypeAny) | 114 if (contentType == CFilter::contentTypeAny) |
108 { | 115 { |
109 contentType = GetContentTypeFromURL(src); | 116 contentType = GetContentTypeFromURL(src); |
110 } | 117 } |
111 return contentType; | 118 return contentType; |
112 } | 119 } |
113 | 120 |
114 ////////////////////////////////////////////////////////////////////////////////
//////// | 121 ////////////////////////////////////////////////////////////////////////////////
//////// |
115 //WBPassthruSink | 122 //WBPassthruSink |
116 //Monitor and/or cancel every request and responde | 123 //Monitor and/or cancel every request and responde |
117 //WB makes, including images, sounds, scripts, etc | 124 //WB makes, including images, sounds, scripts, etc |
118 ////////////////////////////////////////////////////////////////////////////////
//////// | 125 ////////////////////////////////////////////////////////////////////////////////
//////// |
119 HRESULT WBPassthruSink::OnStart(LPCWSTR szUrl, IInternetProtocolSink *pOIProtSin
k, | 126 HRESULT WBPassthruSink::OnStart(LPCWSTR szUrl, IInternetProtocolSink *pOIProtSin
k, |
120 IInternetBindInfo *pOIBindInfo, DWORD grfPI, DWO
RD dwReserved, | 127 IInternetBindInfo *pOIBindInfo, DWORD grfPI, DWO
RD dwReserved, |
121 IInternetProtocol* pTargetProtocol) | 128 IInternetProtocol* pTargetProtocol) |
122 { | 129 { |
123 | 130 |
124 m_pTargetProtocol = pTargetProtocol; | 131 m_pTargetProtocol = pTargetProtocol; |
125 bool isBlocked = false; | 132 bool isBlocked = false; |
126 m_shouldBlock = false; | 133 m_shouldBlock = false; |
127 m_lastDataReported = false; | 134 m_lastDataReported = false; |
128 CString src; | 135 std::wstring src( szUrl ); |
129 src.Append(szUrl); | |
130 DEBUG_GENERAL(src); | 136 DEBUG_GENERAL(src); |
131 CPluginClient::UnescapeUrl(src); | 137 Wrapper::Unescape_URL( src ); |
132 | 138 |
133 CString boundDomain; | 139 std::wstring boundDomain; |
134 CString mimeType; | 140 std::wstring mime_type; |
135 LPOLESTR mime[10]; | |
136 if (pOIBindInfo) | 141 if (pOIBindInfo) |
137 { | 142 { |
138 ULONG resLen = 0; | 143 Wrapper::Internet_Bind_Info bi( pOIBindInfo ); |
139 pOIBindInfo->GetBindString(BINDSTRING_ACCEPT_MIMES, mime, 10, &resLen); | 144 mime_type = bi.bind_string_single( BINDSTRING_ACCEPT_MIMES ); |
140 if (mime && resLen > 0) | 145 std::wstring bind_to_object = bi.bind_string_single( BINDSTRING_FLAG_BIND_TO
_OBJECT ); |
| 146 ABP::util::to_lower( bind_to_object ); |
| 147 if ( bind_to_object == L"" || bind_to_object == L"false" ) |
141 { | 148 { |
142 mimeType.SetString(mime[0]); | 149 boundDomain = bi.bind_string_single( BINDSTRING_XDR_ORIGIN ); |
143 } | |
144 LPOLESTR bindToObject = 0; | |
145 pOIBindInfo->GetBindString(BINDSTRING_FLAG_BIND_TO_OBJECT, &bindToObject, 1,
&resLen); | |
146 LPOLESTR domainRetrieved = 0; | |
147 if (resLen == 0 || wcscmp(bindToObject, L"FALSE") == 0) | |
148 { | |
149 HRESULT hr = pOIBindInfo->GetBindString(BINDSTRING_XDR_ORIGIN, &domainRetr
ieved, 1, &resLen); | |
150 | |
151 if ((hr == S_OK) && domainRetrieved && (resLen > 0)) | |
152 { | |
153 boundDomain.SetString(domainRetrieved); | |
154 } | |
155 } | 150 } |
156 } | 151 } |
157 | 152 |
158 CString cookie; | |
159 ULONG len1 = 2048; | |
160 ULONG len2 = 2048; | |
161 | |
162 #ifdef SUPPORT_FILTER | 153 #ifdef SUPPORT_FILTER |
163 int contentType = CFilter::contentTypeAny; | 154 int contentType = CFilter::contentTypeAny; |
164 | 155 |
165 CPluginTab* tab = CPluginClass::GetTab(::GetCurrentThreadId()); | 156 CPluginTab* tab = CPluginClass::GetTab(::GetCurrentThreadId()); |
166 CPluginClient* client = CPluginClient::GetInstance(); | 157 CPluginClient* client = CPluginClient::GetInstance(); |
167 | 158 |
168 | 159 |
169 if (tab && client) | 160 if (tab && client) |
170 { | 161 { |
171 CString documentUrl = tab->GetDocumentUrl(); | 162 std::wstring documentUrl = tab->GetDocumentUrl(); |
172 // Page is identical to document => don't block | 163 // Page is identical to document => don't block |
173 if (documentUrl == src) | 164 if (documentUrl == src) |
174 { | 165 { |
175 // fall through | 166 // fall through |
176 } | 167 } |
177 else if (CPluginSettings::GetInstance()->IsPluginEnabled() && !client->IsWhi
telistedUrl(std::wstring(documentUrl))) | 168 else if (CPluginSettings::GetInstance()->IsPluginEnabled() && !client->IsWhi
telistedUrl( documentUrl )) |
178 { | 169 { |
179 boundDomain = tab->GetDocumentUrl(); | 170 boundDomain = tab->GetDocumentUrl(); |
180 | 171 |
181 contentType = CFilter::contentTypeAny; | 172 contentType = CFilter::contentTypeAny; |
182 | 173 |
183 #ifdef SUPPORT_FRAME_CACHING | 174 #ifdef SUPPORT_FRAME_CACHING |
184 if ((tab != 0) && (tab->IsFrameCached(src))) | 175 if ((tab != 0) && (tab->IsFrameCached(src))) |
185 { | 176 { |
186 contentType = CFilter::contentTypeSubdocument; | 177 contentType = CFilter::contentTypeSubdocument; |
187 } | 178 } |
188 else | 179 else |
189 #endif // SUPPORT_FRAME_CACHING | 180 #endif // SUPPORT_FRAME_CACHING |
190 contentType = GetContentType(mimeType, boundDomain, src); | 181 contentType = GetContentType( mime_type, boundDomain, src ); |
191 if (client->ShouldBlock(src, contentType, boundDomain, true)) | 182 if (client->ShouldBlock(src, contentType, boundDomain, true)) |
192 { | 183 { |
193 isBlocked = true; | 184 isBlocked = true; |
194 | 185 |
195 DEBUG_BLOCKER("Blocker::Blocking Http-request:" + src); | 186 DEBUG_BLOCKER("Blocker::Blocking Http-request:" + src); |
196 } | 187 } |
197 } | 188 } |
198 if (!isBlocked) | 189 if (!isBlocked) |
199 { | 190 { |
200 DEBUG_BLOCKER("Blocker::Ignoring Http-request:" + src) | 191 DEBUG_BLOCKER("Blocker::Ignoring Http-request:" + src) |
201 } | 192 } |
202 } | 193 } |
203 | 194 |
204 | 195 |
205 if (tab == NULL) | 196 if (tab == NULL) |
206 { | 197 { |
207 contentType = GetContentType(mimeType, boundDomain, src); | 198 contentType = GetContentType( mime_type, boundDomain, src); |
208 if (client->ShouldBlock(src, contentType, boundDomain, true)) | 199 if (client->ShouldBlock(src, contentType, boundDomain, true)) |
209 { | 200 { |
210 isBlocked = true; | 201 isBlocked = true; |
211 } | 202 } |
212 } | 203 } |
213 | 204 |
214 #ifdef _DEBUG | 205 #ifdef _DEBUG |
215 CString type; | 206 std::wstring type; |
216 | 207 |
217 if (contentType == CFilter::contentTypeDocument) type = "DOCUMENT"; | 208 if (contentType == CFilter::contentTypeDocument) type = L"DOCUMENT"; |
218 else if (contentType == CFilter::contentTypeObject) type = "OBJECT"; | 209 else if (contentType == CFilter::contentTypeObject) type = L"OBJECT"; |
219 else if (contentType == CFilter::contentTypeImage) type = "IMAGE"; | 210 else if (contentType == CFilter::contentTypeImage) type = L"IMAGE"; |
220 else if (contentType == CFilter::contentTypeScript) type = "SCRIPT"; | 211 else if (contentType == CFilter::contentTypeScript) type = L"SCRIPT"; |
221 else if (contentType == CFilter::contentTypeOther) type = "OTHER"; | 212 else if (contentType == CFilter::contentTypeOther) type = L"OTHER"; |
222 else if (contentType == CFilter::contentTypeUnknown) type = "OTHER"; | 213 else if (contentType == CFilter::contentTypeUnknown) type = L"OTHER"; |
223 else if (contentType == CFilter::contentTypeSubdocument) type = "SUBDOCUMENT"; | 214 else if (contentType == CFilter::contentTypeSubdocument) type = L"SUBDOCUMENT"
; |
224 else if (contentType == CFilter::contentTypeStyleSheet) type = "STYLESHEET"; | 215 else if (contentType == CFilter::contentTypeStyleSheet) type = L"STYLESHEET"; |
225 else type = "OTHER"; | 216 else type = L"OTHER"; |
226 | 217 |
227 if (isBlocked) | 218 if (isBlocked) |
228 { | 219 { |
229 CPluginDebug::DebugResultBlocking(type, src, boundDomain); | 220 CPluginDebug::DebugResultBlocking(type, src, boundDomain); |
230 } | 221 } |
231 else | 222 else |
232 { | 223 { |
233 CPluginDebug::DebugResultIgnoring(type, src, boundDomain); | 224 CPluginDebug::DebugResultIgnoring(type, src, boundDomain); |
234 } | 225 } |
235 #endif | 226 #endif |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 CComPtr<IHttpNegotiate> spHttpNegotiate; | 363 CComPtr<IHttpNegotiate> spHttpNegotiate; |
373 QueryServiceFromClient(&spHttpNegotiate); | 364 QueryServiceFromClient(&spHttpNegotiate); |
374 | 365 |
375 return spHttpNegotiate ? spHttpNegotiate->OnResponse(dwResponseCode, szRespons
eHeaders, szRequestHeaders, pszAdditionalRequestHeaders) : S_OK; | 366 return spHttpNegotiate ? spHttpNegotiate->OnResponse(dwResponseCode, szRespons
eHeaders, szRequestHeaders, pszAdditionalRequestHeaders) : S_OK; |
376 } | 367 } |
377 | 368 |
378 STDMETHODIMP WBPassthruSink::ReportProgress(ULONG ulStatusCode, LPCWSTR szStatus
Text) | 369 STDMETHODIMP WBPassthruSink::ReportProgress(ULONG ulStatusCode, LPCWSTR szStatus
Text) |
379 { | 370 { |
380 return m_spInternetProtocolSink ? m_spInternetProtocolSink->ReportProgress(ulS
tatusCode, szStatusText) : S_OK; | 371 return m_spInternetProtocolSink ? m_spInternetProtocolSink->ReportProgress(ulS
tatusCode, szStatusText) : S_OK; |
381 } | 372 } |
OLD | NEW |