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

Delta Between Two Patch Sets: src/plugin/PluginWbPassThrough.cpp

Issue 5316782940225536: Issue 1557 - Update to the recent libadblockplus to reduce additional updates in the logic later. (Closed)
Left Patch Set: fix accoring to comments Created Jan. 13, 2015, 12:59 p.m.
Right Patch Set: rebase and remove member of CFilter Created Feb. 4, 2015, 12:50 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « src/plugin/PluginWbPassThrough.h ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2015 Eyeo GmbH
4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */
17
1 #include "PluginStdAfx.h" 18 #include "PluginStdAfx.h"
2 19
3 #include "PluginWbPassThrough.h" 20 #include "PluginWbPassThrough.h"
4 #include "PluginClient.h" 21 #include "PluginClient.h"
5 #include "PluginClientFactory.h" 22 #include "PluginClientFactory.h"
6 #include "PluginFilter.h" 23 #include "PluginFilter.h"
7 #include "PluginSettings.h" 24 #include "PluginSettings.h"
8 #include "PluginClass.h" 25 #include "PluginClass.h"
9 #include "PluginSystem.h" 26 #include "PluginSystem.h"
10 #include <WinInet.h> 27 #include <WinInet.h>
11 #include "wtypes.h" 28 #include "wtypes.h"
12 #include "../shared/Utils.h" 29 #include "../shared/Utils.h"
13 #include "../shared/IE_version.h" 30 #include "../shared/IE_version.h"
14 31
15 namespace 32 namespace
16 { 33 {
17 const std::string g_blockedByABPPage = "<!DOCTYPE html>" 34 const std::string g_blockedByABPPage = "<!DOCTYPE html>"
18 "<html>" 35 "<html>"
19 "<body>" 36 "<body>"
20 "<!-- blocked by AdblockPlus -->" 37 "<!-- blocked by AdblockPlus -->"
21 "</body>" 38 "</body>"
22 "</html>"; 39 "</html>";
23 40
41 template <typename T>
42 T ASCIIStringToLower(const T& text)
43 {
44 T textlower;
45 std::transform(text.begin(), text.end(), std::back_inserter(textlower),
46 [](T::value_type ch)
47 {
48 return std::tolower(ch, std::locale());
49 }
50 );
51 return textlower;
52 }
53
24 typedef AdblockPlus::FilterEngine::ContentType ContentType; 54 typedef AdblockPlus::FilterEngine::ContentType ContentType;
25 55
26 template <class T> 56 template <class T>
27 T ExtractHttpHeader(const T& allHeaders, const T& targetHeaderNameWithColon, c onst T& delimiter) 57 T ExtractHttpHeader(const T& allHeaders, const T& targetHeaderNameWithColon, c onst T& delimiter)
28 { 58 {
29 auto targetHeaderBeginsAt = allHeaders.find(targetHeaderNameWithColon); 59 const T allHeadersLower = ASCIIStringToLower(allHeaders);
60 auto targetHeaderBeginsAt = allHeadersLower.find(ASCIIStringToLower(targetHe aderNameWithColon));
30 if (targetHeaderBeginsAt == T::npos) 61 if (targetHeaderBeginsAt == T::npos)
31 { 62 {
32 return T(); 63 return T();
33 } 64 }
34 targetHeaderBeginsAt += targetHeaderNameWithColon.length(); 65 targetHeaderBeginsAt += targetHeaderNameWithColon.length();
35 auto targetHeaderEndsAt = allHeaders.find(delimiter, targetHeaderBeginsAt); 66 auto targetHeaderEndsAt = allHeadersLower.find(ASCIIStringToLower(delimiter) , targetHeaderBeginsAt);
36 if (targetHeaderEndsAt == T::npos) 67 if (targetHeaderEndsAt == T::npos)
37 { 68 {
38 return T(); 69 return T();
39 } 70 }
40 return allHeaders.substr(targetHeaderBeginsAt, targetHeaderEndsAt - targetHe aderBeginsAt); 71 return allHeaders.substr(targetHeaderBeginsAt, targetHeaderEndsAt - targetHe aderBeginsAt);
41 } 72 }
42 73
43 std::string ExtractHttpAcceptHeader(IInternetProtocol* internetProtocol) 74 std::string ExtractHttpAcceptHeader(IInternetProtocol* internetProtocol)
44 { 75 {
45 // Despite there being HTTP_QUERY_ACCEPT and other query info flags, they do n't work here, 76 // Despite there being HTTP_QUERY_ACCEPT and other query info flags, they do n't work here,
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 } 136 }
106 // It is important to have this check last, since it is rather generic, and mi ght overlay text/html, for example 137 // It is important to have this check last, since it is rather generic, and mi ght overlay text/html, for example
107 if (mimeType.Find(L"xml") >= 0) 138 if (mimeType.Find(L"xml") >= 0)
108 { 139 {
109 return ContentType::CONTENT_TYPE_XMLHTTPREQUEST; 140 return ContentType::CONTENT_TYPE_XMLHTTPREQUEST;
110 } 141 }
111 142
112 return ContentType::CONTENT_TYPE_OTHER; 143 return ContentType::CONTENT_TYPE_OTHER;
113 } 144 }
114 145
115 ContentType WBPassthruSink::GetContentTypeFromURL(const CString& src) 146 ContentType WBPassthruSink::GetContentTypeFromURL(const std::wstring& src)
116 { 147 {
117 CString srcExt = src; 148 CString srcLegacy = ToCString(src);
149 CString srcExt = srcLegacy;
118 150
119 int pos = 0; 151 int pos = 0;
120 if ((pos = src.Find('?')) > 0) 152 if ((pos = srcLegacy.Find('?')) > 0)
121 { 153 {
122 srcExt = src.Left(pos); 154 srcExt = srcLegacy.Left(pos);
123 } 155 }
124 156
125 int lastDotIndex = srcExt.ReverseFind('.'); 157 int lastDotIndex = srcExt.ReverseFind('.');
126 if (lastDotIndex < 0) 158 if (lastDotIndex < 0)
127 return ContentType::CONTENT_TYPE_OTHER; 159 return ContentType::CONTENT_TYPE_OTHER;
128 CString ext = srcExt.Mid(lastDotIndex); 160 CString ext = srcExt.Mid(lastDotIndex);
129 if (ext == L".jpg" || ext == L".gif" || ext == L".png" || ext == L".jpeg") 161 if (ext == L".jpg" || ext == L".gif" || ext == L".png" || ext == L".jpeg")
130 { 162 {
131 return ContentType::CONTENT_TYPE_IMAGE; 163 return ContentType::CONTENT_TYPE_IMAGE;
132 } 164 }
(...skipping 13 matching lines...) Expand all
146 { 178 {
147 return ContentType::CONTENT_TYPE_OBJECT; 179 return ContentType::CONTENT_TYPE_OBJECT;
148 } 180 }
149 else if (ext == L".jsp" || ext == L".php" || ext == L".html") 181 else if (ext == L".jsp" || ext == L".php" || ext == L".html")
150 { 182 {
151 return ContentType::CONTENT_TYPE_SUBDOCUMENT; 183 return ContentType::CONTENT_TYPE_SUBDOCUMENT;
152 } 184 }
153 return ContentType::CONTENT_TYPE_OTHER; 185 return ContentType::CONTENT_TYPE_OTHER;
154 } 186 }
155 187
156 ContentType WBPassthruSink::GetContentType(const CString& mimeType, const std::w string& domain, const CString& src) 188 ContentType WBPassthruSink::GetContentType(const CString& mimeType, const std::w string& domain, const std::wstring& src)
157 { 189 {
158 // No referer or mime type 190 // No referer or mime type
159 // BINDSTRING_XDR_ORIGIN works only for IE v8+ 191 // BINDSTRING_XDR_ORIGIN works only for IE v8+
160 if (mimeType.IsEmpty() && domain.empty() && AdblockPlus::IE::InstalledMajorVer sion() >= 8) 192 if (mimeType.IsEmpty() && domain.empty() && AdblockPlus::IE::InstalledMajorVer sion() >= 8)
161 { 193 {
162 return ContentType::CONTENT_TYPE_XMLHTTPREQUEST; 194 return ContentType::CONTENT_TYPE_XMLHTTPREQUEST;
163 } 195 }
164 ContentType contentType = GetContentTypeFromMimeType(mimeType); 196 ContentType contentType = GetContentTypeFromMimeType(mimeType);
165 if (contentType == ContentType::CONTENT_TYPE_OTHER) 197 if (contentType == ContentType::CONTENT_TYPE_OTHER)
166 { 198 {
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 return false; 307 return false;
276 } 308 }
277 309
278 STDMETHODIMP WBPassthruSink::BeginningTransaction(LPCWSTR szURL, LPCWSTR szHeade rs, DWORD dwReserved, LPWSTR* pszAdditionalHeaders) 310 STDMETHODIMP WBPassthruSink::BeginningTransaction(LPCWSTR szURL, LPCWSTR szHeade rs, DWORD dwReserved, LPWSTR* pszAdditionalHeaders)
279 { 311 {
280 if (!szURL) 312 if (!szURL)
281 { 313 {
282 return E_POINTER; 314 return E_POINTER;
283 } 315 }
284 std::wstring src = szURL; 316 std::wstring src = szURL;
317 UnescapeUrl(src);
285 DEBUG_GENERAL(ToCString(src)); 318 DEBUG_GENERAL(ToCString(src));
286 319
287 std::string acceptHeader = ExtractHttpAcceptHeader(m_spTargetProtocol); 320 std::string acceptHeader = ExtractHttpAcceptHeader(m_spTargetProtocol);
288 321
289 if (pszAdditionalHeaders) 322 if (pszAdditionalHeaders)
290 { 323 {
291 *pszAdditionalHeaders = nullptr; 324 *pszAdditionalHeaders = nullptr;
292 } 325 }
293 326
294 CComPtr<IHttpNegotiate> httpNegotiate; 327 CComPtr<IHttpNegotiate> httpNegotiate;
295 QueryServiceFromClient(&httpNegotiate); 328 QueryServiceFromClient(&httpNegotiate);
296 // This fills the pszAdditionalHeaders with more headers. One of which is the Referer header, which we need. 329 // This fills the pszAdditionalHeaders with more headers. One of which is the Referer header, which we need.
297 // There doesn't seem to be any other way to get this header before the reques t has been made. 330 // There doesn't seem to be any other way to get this header before the reques t has been made.
298 HRESULT nativeHr = httpNegotiate ? httpNegotiate->BeginningTransaction(szURL, szHeaders, dwReserved, pszAdditionalHeaders) : S_OK; 331 HRESULT nativeHr = httpNegotiate ? httpNegotiate->BeginningTransaction(szURL, szHeaders, dwReserved, pszAdditionalHeaders) : S_OK;
299 332
300 if (pszAdditionalHeaders && *pszAdditionalHeaders) 333 if (pszAdditionalHeaders && *pszAdditionalHeaders)
301 { 334 {
302 m_boundDomain = ExtractHttpHeader<std::wstring>(*pszAdditionalHeaders, L"Ref erer:", L"\n"); 335 m_boundDomain = ExtractHttpHeader<std::wstring>(*pszAdditionalHeaders, L"Ref erer:", L"\n");
303 } 336 }
304 m_boundDomain = TrimString(m_boundDomain); 337 m_boundDomain = TrimString(m_boundDomain);
305 m_contentType = GetContentType(ATL::CString(acceptHeader.c_str()), m_boundDoma in, ToCString(src)); 338 m_contentType = GetContentType(ATL::CString(acceptHeader.c_str()), m_boundDoma in, src);
306 339
307 CPluginTab* tab = CPluginClass::GetTab(::GetCurrentThreadId()); 340 CPluginTab* tab = CPluginClass::GetTab(::GetCurrentThreadId());
308 CPluginClient* client = CPluginClient::GetInstance(); 341 CPluginClient* client = CPluginClient::GetInstance();
309 342
310 if (tab && client) 343 if (tab && client)
311 { 344 {
312 CString documentUrl = tab->GetDocumentUrl(); 345 std::wstring documentUrl = tab->GetDocumentUrl();
313 // Page is identical to document => don't block 346 // Page is identical to document => don't block
314 if (documentUrl == ToCString(src)) 347 if (documentUrl == src)
315 { 348 {
316 return nativeHr; 349 return nativeHr;
317 } 350 }
318 else if (CPluginSettings::GetInstance()->IsPluginEnabled() && !client->IsWhi telistedUrl(std::wstring(documentUrl))) 351 else if (CPluginSettings::GetInstance()->IsPluginEnabled() && !client->IsWhi telistedUrl(documentUrl))
319 { 352 {
320 if (tab->IsFrameCached(ToCString(src))) 353 if (tab->IsFrameCached(src))
321 { 354 {
322 m_contentType = ContentType::CONTENT_TYPE_SUBDOCUMENT; 355 m_contentType = ContentType::CONTENT_TYPE_SUBDOCUMENT;
323 } 356 }
324 } 357 }
325 } 358 }
326 359
327 if (IsFlashRequest(pszAdditionalHeaders)) 360 if (IsFlashRequest(pszAdditionalHeaders))
328 { 361 {
329 m_contentType = ContentType::CONTENT_TYPE_OBJECT_SUBREQUEST; 362 m_contentType = ContentType::CONTENT_TYPE_OBJECT_SUBREQUEST;
330 } 363 }
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 } 425 }
393 426
394 return OnStart(szUrl, pOIProtSink, pOIBindInfo, grfPI, dwReserved, m_spInterne tProtocol); 427 return OnStart(szUrl, pOIProtSink, pOIBindInfo, grfPI, dwReserved, m_spInterne tProtocol);
395 } 428 }
396 429
397 STDMETHODIMP WBPassthru::Read(/* [in, out] */ void *pv,/* [in] */ ULONG cb,/* [o ut] */ ULONG *pcbRead) 430 STDMETHODIMP WBPassthru::Read(/* [in, out] */ void *pv,/* [in] */ ULONG cb,/* [o ut] */ ULONG *pcbRead)
398 { 431 {
399 WBPassthruSink* pSink = GetSink(); 432 WBPassthruSink* pSink = GetSink();
400 return pSink->OnRead(pv, cb, pcbRead); 433 return pSink->OnRead(pv, cb, pcbRead);
401 } 434 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld