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

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

Issue 29330403: Issue #1467, #3397 - Rewrite the map from threads to tabs (Closed)
Left Patch Set: rebase to current tip / address comments Created Feb. 3, 2016, 5:22 p.m.
Right Patch Set: add comment; new function body Created July 17, 2016, 4:01 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
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 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 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 } 135 }
136 } 136 }
137 137
138 WBPassthruSink::WBPassthruSink() 138 WBPassthruSink::WBPassthruSink()
139 : m_currentPositionOfSentPage(0) 139 : m_currentPositionOfSentPage(0)
140 , m_contentType(ContentType::CONTENT_TYPE_OTHER) 140 , m_contentType(ContentType::CONTENT_TYPE_OTHER)
141 , m_isCustomResponse(false) 141 , m_isCustomResponse(false)
142 { 142 {
143 } 143 }
144 144
145 ContentType WBPassthruSink::GetContentTypeFromMimeType(const std::wstring& mimeT ype) 145 namespace
146 { 146 {
147 if ((mimeType.find(L"text/html") != std::wstring::npos) || 147 /**
148 (mimeType.find(L"application/xhtml+xml") != std::wstring::npos)) 148 * Heuristic to infer an ABP content type from the media type list of an Accep t: header field.
149 { 149 *
150 return ContentType::CONTENT_TYPE_SUBDOCUMENT; 150 * Known IE Accept: strings for documents and images:
151 } 151 * text/html, application/xhtml+xml, image/jxr, *\/*
152 if (mimeType.find(L"image/") != std::wstring::npos) 152 * image/png, image/svg+xml, image/jxr, image/*;q=0.8, *\/*;q = 0.5
153 { 153 * In IE9 the image/jxr part is missing.
154 return ContentType::CONTENT_TYPE_IMAGE; 154 */
155 } 155 ContentType InferContentTypeFromMediaTypeList(const std::wstring& mediaTypeLis t)
156 if (mimeType.find(L"text/css") != std::wstring::npos) 156 {
157 { 157 if ((mediaTypeList.find(L"text/html") != std::wstring::npos) ||
158 return ContentType::CONTENT_TYPE_STYLESHEET; 158 (mediaTypeList.find(L"application/xhtml+xml") != std::wstring::npos))
159 } 159 {
160 if ((mimeType.find(L"application/javascript") != std::wstring::npos) || (mimeT ype.find(L"application/json") != std::wstring::npos)) 160 return ContentType::CONTENT_TYPE_SUBDOCUMENT;
161 { 161 }
162 return ContentType::CONTENT_TYPE_SCRIPT; 162 if (mediaTypeList.find(L"image/") != std::wstring::npos)
163 } 163 {
164 if (mimeType.find(L"application/x-shockwave-flash") != std::wstring::npos) 164 return ContentType::CONTENT_TYPE_IMAGE;
165 { 165 }
166 return ContentType::CONTENT_TYPE_OBJECT; 166 if (mediaTypeList.find(L"text/css") != std::wstring::npos)
167 } 167 {
168 // It is important to have this check last, since it is rather generic, and mi ght overlay text/html, for example 168 return ContentType::CONTENT_TYPE_STYLESHEET;
169 if (mimeType.find(L"xml") != std::wstring::npos) 169 }
170 { 170 if ((mediaTypeList.find(L"application/javascript") != std::wstring::npos) || (mediaTypeList.find(L"application/json") != std::wstring::npos))
171 return ContentType::CONTENT_TYPE_XMLHTTPREQUEST; 171 {
172 } 172 return ContentType::CONTENT_TYPE_SCRIPT;
173 173 }
174 return ContentType::CONTENT_TYPE_OTHER; 174 if (mediaTypeList.find(L"application/x-shockwave-flash") != std::wstring::np os)
175 } 175 {
176 176 return ContentType::CONTENT_TYPE_OBJECT;
177 ContentType WBPassthruSink::GetContentTypeFromURL(const std::wstring& src) 177 }
178 { 178 // It is important to have this check last, since it is rather generic, and might overlay text/html, for example
179 std::wstring schemeAndHierarchicalPart = GetSchemeAndHierarchicalPart(src); 179 if (mediaTypeList.find(L"xml") != std::wstring::npos)
180 auto contentType = GetContentTypeFromString(schemeAndHierarchicalPart); 180 {
181 if (contentType == ContentType::CONTENT_TYPE_OTHER && 181 return ContentType::CONTENT_TYPE_XMLHTTPREQUEST;
182 AdblockPlus::IE::InstalledMajorVersion() == 8) 182 }
183 { 183 return ContentType::CONTENT_TYPE_OTHER;
184 std::wstring queryString = GetQueryString(src); 184 }
185 wchar_t* nextToken = nullptr; 185
186 const wchar_t* token = wcstok_s(&queryString[0], L"&=", &nextToken); 186 ContentType InferContentTypeFromUrl(const std::wstring& src)
187 while (token != nullptr) 187 {
188 { 188 std::wstring schemeAndHierarchicalPart = GetSchemeAndHierarchicalPart(src);
189 contentType = GetContentTypeFromString(token); 189 auto contentType = GetContentTypeFromString(schemeAndHierarchicalPart);
190 if (contentType != ContentType::CONTENT_TYPE_OTHER) 190 if (contentType == ContentType::CONTENT_TYPE_OTHER &&
191 AdblockPlus::IE::InstalledMajorVersion() == 8)
192 {
193 std::wstring queryString = GetQueryString(src);
194 wchar_t* nextToken = nullptr;
195 const wchar_t* token = wcstok_s(&queryString[0], L"&=", &nextToken);
196 while (token != nullptr)
191 { 197 {
192 return contentType; 198 contentType = GetContentTypeFromString(token);
199 if (contentType != ContentType::CONTENT_TYPE_OTHER)
200 {
201 return contentType;
202 }
203 token = wcstok_s(nullptr, L"&=", &nextToken);
193 } 204 }
194 token = wcstok_s(nullptr, L"&=", &nextToken); 205 }
195 } 206 return contentType;
196 } 207 }
197 return contentType; 208
198 } 209 ContentType InferContentType(const std::wstring& mediaTypeList, const std::wst ring& domain, const std::wstring& src)
199 210 {
200 ContentType WBPassthruSink::GetContentType(const std::wstring& mimeType, const s td::wstring& domain, const std::wstring& src) 211 // No referer or mime type
201 { 212 // BINDSTRING_XDR_ORIGIN works only for IE v8+
202 // No referer or mime type 213 if (mediaTypeList.empty() && domain.empty() && AdblockPlus::IE::InstalledMaj orVersion() >= 8)
203 // BINDSTRING_XDR_ORIGIN works only for IE v8+ 214 {
204 if (mimeType.empty() && domain.empty() && AdblockPlus::IE::InstalledMajorVersi on() >= 8) 215 return ContentType::CONTENT_TYPE_XMLHTTPREQUEST;
205 { 216 }
206 return ContentType::CONTENT_TYPE_XMLHTTPREQUEST; 217 ContentType contentType = InferContentTypeFromMediaTypeList(mediaTypeList);
207 } 218 if (contentType == ContentType::CONTENT_TYPE_OTHER)
208 ContentType contentType = GetContentTypeFromMimeType(mimeType); 219 {
209 if (contentType == ContentType::CONTENT_TYPE_OTHER) 220 contentType = InferContentTypeFromUrl(src);
210 { 221 }
211 contentType = GetContentTypeFromURL(src); 222 return contentType;
212 } 223 }
213 return contentType;
214 } 224 }
215 225
216 //////////////////////////////////////////////////////////////////////////////// //////// 226 //////////////////////////////////////////////////////////////////////////////// ////////
217 //WBPassthruSink 227 //WBPassthruSink
218 //Monitor and/or cancel every request and responde 228 //Monitor and/or cancel every request and responde
219 //WB makes, including images, sounds, scripts, etc 229 //WB makes, including images, sounds, scripts, etc
220 //////////////////////////////////////////////////////////////////////////////// //////// 230 //////////////////////////////////////////////////////////////////////////////// ////////
221 HRESULT WBPassthruSink::OnStart(LPCWSTR szUrl, IInternetProtocolSink *pOIProtSin k, 231 HRESULT WBPassthruSink::OnStart(LPCWSTR szUrl, IInternetProtocolSink *pOIProtSin k,
222 IInternetBindInfo *pOIBindInfo, DWORD grfPI, HAN DLE_PTR dwReserved, 232 IInternetBindInfo *pOIBindInfo, DWORD grfPI, HAN DLE_PTR dwReserved,
223 IInternetProtocol* pTargetProtocol) 233 IInternetProtocol* pTargetProtocol)
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 QueryServiceFromClient(&httpNegotiate); 347 QueryServiceFromClient(&httpNegotiate);
338 // This fills the pszAdditionalHeaders with more headers. One of which is the Referer header, which we need. 348 // This fills the pszAdditionalHeaders with more headers. One of which is the Referer header, which we need.
339 // There doesn't seem to be any other way to get this header before the reques t has been made. 349 // There doesn't seem to be any other way to get this header before the reques t has been made.
340 HRESULT nativeHr = httpNegotiate ? httpNegotiate->BeginningTransaction(szURL, szHeaders, dwReserved, pszAdditionalHeaders) : S_OK; 350 HRESULT nativeHr = httpNegotiate ? httpNegotiate->BeginningTransaction(szURL, szHeaders, dwReserved, pszAdditionalHeaders) : S_OK;
341 351
342 if (pszAdditionalHeaders && *pszAdditionalHeaders) 352 if (pszAdditionalHeaders && *pszAdditionalHeaders)
343 { 353 {
344 m_boundDomain = ExtractHttpHeader<std::wstring>(*pszAdditionalHeaders, L"Ref erer:", L"\n"); 354 m_boundDomain = ExtractHttpHeader<std::wstring>(*pszAdditionalHeaders, L"Ref erer:", L"\n");
345 } 355 }
346 m_boundDomain = TrimString(m_boundDomain); 356 m_boundDomain = TrimString(m_boundDomain);
347 m_contentType = GetContentType(ToUtf16String(ExtractHttpAcceptHeader(m_spTarge tProtocol)), m_boundDomain, src); 357 m_contentType = InferContentType(ToUtf16String(ExtractHttpAcceptHeader(m_spTar getProtocol)), m_boundDomain, src);
348 358
349 CPluginTab* tab = CPluginClass::GetTabCurrentThread(); 359 CPluginTab* tab = CPluginClass::GetTabForCurrentThread();
350 CPluginClient* client = CPluginClient::GetInstance(); 360 CPluginClient* client = CPluginClient::GetInstance();
351 361
352 if (tab && client) 362 if (tab && client)
353 { 363 {
354 std::wstring documentUrl = tab->GetDocumentUrl(); 364 std::wstring documentUrl = tab->GetDocumentUrl();
355 // Page is identical to document => don't block 365 // Page is identical to document => don't block
356 if (documentUrl == src) 366 if (documentUrl == src)
357 { 367 {
358 return nativeHr; 368 return nativeHr;
359 } 369 }
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 } 455 }
446 456
447 return OnStart(szUrl, pOIProtSink, pOIBindInfo, grfPI, dwReserved, m_spInterne tProtocol); 457 return OnStart(szUrl, pOIProtSink, pOIBindInfo, grfPI, dwReserved, m_spInterne tProtocol);
448 } 458 }
449 459
450 STDMETHODIMP WbPassthroughProtocol::Read(/* [in, out] */ void *pv,/* [in] */ ULO NG cb,/* [out] */ ULONG *pcbRead) 460 STDMETHODIMP WbPassthroughProtocol::Read(/* [in, out] */ void *pv,/* [in] */ ULO NG cb,/* [out] */ ULONG *pcbRead)
451 { 461 {
452 WBPassthruSink* pSink = GetSink(); 462 WBPassthruSink* pSink = GetSink();
453 return pSink->OnRead(pv, cb, pcbRead); 463 return pSink->OnRead(pv, cb, pcbRead);
454 } 464 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld