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

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

Issue 5171515343503360: Issue #41 - Bring method of determining IE version up to date (Closed)
Left Patch Set: reformatted Created July 26, 2014, 3:52 p.m.
Right Patch Set: Final (?) 2 Created Jan. 5, 2015, 1:02 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 #include "PluginStdAfx.h" 1 #include "PluginStdAfx.h"
2 #include "PluginSettings.h" 2 #include "PluginSettings.h"
3 #include "PluginSystem.h" 3 #include "PluginSystem.h"
4 #include "PluginFilter.h" 4 #include "PluginFilter.h"
5 #include "PluginClientFactory.h" 5 #include "PluginClientFactory.h"
6 #include "PluginMutex.h" 6 #include "PluginMutex.h"
7 #include "PluginClass.h" 7 #include "PluginClass.h"
8 8
9 #include "AdblockPlusClient.h" 9 #include "AdblockPlusClient.h"
10 10
11 #include "../shared/Utils.h" 11 #include "../shared/Utils.h"
12 12
13 namespace 13 namespace
14 { 14 {
15 void SpawnAdblockPlusEngine() 15 void SpawnAdblockPlusEngine()
16 { 16 {
17 std::wstring engineExecutablePath = GetDllDir() + L"AdblockPlusEngine.exe"; 17 std::wstring engineExecutablePath = GetDllDir() + L"AdblockPlusEngine.exe";
18 CString params = L"AdblockPlusEngine.exe " + CPluginSystem::GetInstance()->G etBrowserLanguage(); 18 CString params = to_CString(L"AdblockPlusEngine.exe " + GetBrowserLanguage() );
19 19
20 STARTUPINFO startupInfo = {}; 20 STARTUPINFO startupInfo = {};
21 PROCESS_INFORMATION processInformation = {}; 21 PROCESS_INFORMATION processInformation = {};
22 22
23 HANDLE token; 23 HANDLE token;
24 OpenProcessToken(GetCurrentProcess(), TOKEN_DUPLICATE | TOKEN_ADJUST_DEFAULT | TOKEN_QUERY | TOKEN_ASSIGN_PRIMARY, &token); 24 OpenProcessToken(GetCurrentProcess(), TOKEN_DUPLICATE | TOKEN_ADJUST_DEFAULT | TOKEN_QUERY | TOKEN_ASSIGN_PRIMARY, &token);
25 25
26 TOKEN_APPCONTAINER_INFORMATION *acs = NULL; 26 TOKEN_APPCONTAINER_INFORMATION *acs = NULL;
27 DWORD length = 0; 27 DWORD length = 0;
28 28
(...skipping 28 matching lines...) Expand all
57 57
58 PSID integritySid = 0; 58 PSID integritySid = 0;
59 ConvertStringSidToSid(L"S-1-16-4096", &integritySid); 59 ConvertStringSidToSid(L"S-1-16-4096", &integritySid);
60 std::tr1::shared_ptr<SID> sharedIntegritySid(static_cast<SID*>(integritySi d), FreeSid); // Just to simplify cleanup 60 std::tr1::shared_ptr<SID> sharedIntegritySid(static_cast<SID*>(integritySi d), FreeSid); // Just to simplify cleanup
61 61
62 TOKEN_MANDATORY_LABEL tml = {}; 62 TOKEN_MANDATORY_LABEL tml = {};
63 tml.Label.Attributes = SE_GROUP_INTEGRITY; 63 tml.Label.Attributes = SE_GROUP_INTEGRITY;
64 tml.Label.Sid = integritySid; 64 tml.Label.Sid = integritySid;
65 65
66 // Set the process integrity level 66 // Set the process integrity level
67 SetTokenInformation(newToken, TokenIntegrityLevel, &tml, sizeof(TOKEN_MAND ATORY_LABEL) + GetLengthSid(integritySid)); 67 SetTokenInformation(newToken, TokenIntegrityLevel, &tml, sizeof(tml));
68 68
69 STARTUPINFO startupInfo = {}; 69 STARTUPINFO startupInfo = {};
70 PROCESS_INFORMATION processInformation = {}; 70 PROCESS_INFORMATION processInformation = {};
71 71
72 createProcRes = CreateProcessAsUserW(newToken, engineExecutablePath.c_str( ), params.GetBuffer(params.GetLength() + 1), 72 createProcRes = CreateProcessAsUserW(newToken, engineExecutablePath.c_str( ), params.GetBuffer(params.GetLength() + 1),
73 0, 0, false, 0, 0, 0, (STARTUPINFOW*)&startupInfo, &processInformation); 73 0, 0, false, 0, 0, 0, (STARTUPINFOW*)&startupInfo, &processInformation);
74 } 74 }
75 75
76 if (!createProcRes) 76 if (!createProcRes)
77 { 77 {
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 s_instance = client; 201 s_instance = client;
202 } 202 }
203 203
204 instance = s_instance; 204 instance = s_instance;
205 } 205 }
206 s_criticalSectionLocal.Unlock(); 206 s_criticalSectionLocal.Unlock();
207 207
208 return instance; 208 return instance;
209 } 209 }
210 210
211 211 bool CAdblockPlusClient::ShouldBlock(const std::wstring& src, int contentType, c onst std::wstring& domain, bool addDebug)
212 bool CAdblockPlusClient::ShouldBlock(CString src, int contentType, const CString & domain, bool addDebug)
213 { 212 {
214 bool isBlocked = false; 213 bool isBlocked = false;
215
216 bool isCached = false; 214 bool isCached = false;
217
218 CPluginSettings* settings = CPluginSettings::GetInstance();
219
220 m_criticalSectionCache.Lock(); 215 m_criticalSectionCache.Lock();
221 { 216 {
222 std::map<CString,bool>::iterator it = m_cacheBlockedSources.find(src); 217 auto it = m_cacheBlockedSources.find(src);
223 218
224 isCached = it != m_cacheBlockedSources.end(); 219 isCached = it != m_cacheBlockedSources.end();
225 if (isCached) 220 if (isCached)
226 { 221 {
227 isBlocked = it->second; 222 isBlocked = it->second;
228 } 223 }
229 } 224 }
230 m_criticalSectionCache.Unlock(); 225 m_criticalSectionCache.Unlock();
231 226
232 if (!isCached) 227 if (!isCached)
233 { 228 {
234 m_criticalSectionFilter.Lock(); 229 m_criticalSectionFilter.Lock();
235 { 230 {
236 isBlocked = m_filter->ShouldBlock(src, contentType, domain, addDebug); 231 isBlocked = m_filter->ShouldBlock(src, contentType, domain, addDebug);
237 } 232 }
238 m_criticalSectionFilter.Unlock(); 233 m_criticalSectionFilter.Unlock();
239
240 234
241 // Cache result, if content type is defined 235 // Cache result, if content type is defined
242 if (contentType != CFilter::contentTypeAny) 236 if (contentType != CFilter::contentTypeAny)
243 { 237 {
244 m_criticalSectionCache.Lock(); 238 m_criticalSectionCache.Lock();
245 { 239 {
246 m_cacheBlockedSources[src] = isBlocked; 240 m_cacheBlockedSources[src] = isBlocked;
247 } 241 }
248 m_criticalSectionCache.Unlock(); 242 m_criticalSectionCache.Unlock();
249 } 243 }
250 } 244 }
251
252
253 return isBlocked; 245 return isBlocked;
254 } 246 }
255 247
256 bool CAdblockPlusClient::IsElementHidden(const CString& tag, IHTMLElement* pEl, const CString& domain, const CString& indent, CPluginFilter* filter) 248 bool CAdblockPlusClient::IsElementHidden(const std::wstring& tag, IHTMLElement* pEl, const std::wstring& domain, const std::wstring& indent, CPluginFilter* filt er)
257 { 249 {
258 bool isHidden; 250 bool isHidden;
259 m_criticalSectionFilter.Lock(); 251 m_criticalSectionFilter.Lock();
260 { 252 {
261 isHidden = filter && filter->IsElementHidden(tag, pEl, domain, indent); 253 isHidden = filter && filter->IsElementHidden(tag, pEl, domain, indent);
262 } 254 }
263 m_criticalSectionFilter.Unlock(); 255 m_criticalSectionFilter.Unlock();
264 return isHidden; 256 return isHidden;
265 } 257 }
266 258
267 bool CAdblockPlusClient::IsWhitelistedUrl(const std::wstring& url) 259 bool CAdblockPlusClient::IsWhitelistedUrl(const std::wstring& url)
268 { 260 {
269 DEBUG_GENERAL((L"IsWhitelistedUrl: " + url + L" start").c_str()); 261 DEBUG_GENERAL((L"IsWhitelistedUrl: " + url + L" start").c_str());
270 Communication::OutputBuffer request; 262 Communication::OutputBuffer request;
271 request << Communication::PROC_IS_WHITELISTED_URL << ToUtf8String(url); 263 request << Communication::PROC_IS_WHITELISTED_URL << ToUtf8String(url);
272 264
273 Communication::InputBuffer response; 265 Communication::InputBuffer response;
274 if (!CallEngine(request, response)) 266 if (!CallEngine(request, response))
275 return false; 267 return false;
276 268
277 bool isWhitelisted; 269 bool isWhitelisted;
278 response >> isWhitelisted; 270 response >> isWhitelisted;
279 271
280 DEBUG_GENERAL((L"IsWhitelistedUrl: " + url + L" end").c_str()); 272 DEBUG_GENERAL((L"IsWhitelistedUrl: " + url + L" end").c_str());
273 return isWhitelisted;
274 }
275
276 bool CAdblockPlusClient::IsElemhideWhitelistedOnDomain(const std::wstring& url)
277 {
278 Communication::OutputBuffer request;
279 request << Communication::PROC_IS_ELEMHIDE_WHITELISTED_ON_URL << ToUtf8String( url);
280
281 Communication::InputBuffer response;
282 if (!CallEngine(request, response))
283 return false;
284
285 bool isWhitelisted;
286 response >> isWhitelisted;
281 return isWhitelisted; 287 return isWhitelisted;
282 } 288 }
283 289
284 bool CAdblockPlusClient::Matches(const std::wstring& url, const std::wstring& co ntentType, const std::wstring& domain) 290 bool CAdblockPlusClient::Matches(const std::wstring& url, const std::wstring& co ntentType, const std::wstring& domain)
285 { 291 {
286 Communication::OutputBuffer request; 292 Communication::OutputBuffer request;
287 request << Communication::PROC_MATCHES << ToUtf8String(url) << ToUtf8String(co ntentType) << ToUtf8String(domain); 293 request << Communication::PROC_MATCHES << ToUtf8String(url) << ToUtf8String(co ntentType) << ToUtf8String(domain);
288 294
289 Communication::InputBuffer response; 295 Communication::InputBuffer response;
290 if (!CallEngine(request, response)) 296 if (!CallEngine(request, response))
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 380
375 bool CAdblockPlusClient::IsFirstRun() 381 bool CAdblockPlusClient::IsFirstRun()
376 { 382 {
377 DEBUG_GENERAL("IsFirstRun"); 383 DEBUG_GENERAL("IsFirstRun");
378 Communication::InputBuffer response; 384 Communication::InputBuffer response;
379 if (!CallEngine(Communication::PROC_IS_FIRST_RUN_ACTION_NEEDED, response)) ret urn false; 385 if (!CallEngine(Communication::PROC_IS_FIRST_RUN_ACTION_NEEDED, response)) ret urn false;
380 bool res; 386 bool res;
381 response >> res; 387 response >> res;
382 return res; 388 return res;
383 } 389 }
390
384 void CAdblockPlusClient::AddFilter(const std::wstring& text) 391 void CAdblockPlusClient::AddFilter(const std::wstring& text)
385 { 392 {
386 Communication::OutputBuffer request; 393 Communication::OutputBuffer request;
387 request << Communication::PROC_ADD_FILTER << ToUtf8String(text); 394 request << Communication::PROC_ADD_FILTER << ToUtf8String(text);
388 CallEngine(request); 395 CallEngine(request);
389 } 396 }
390 397
391 void CAdblockPlusClient::RemoveFilter(const std::wstring& text) 398 void CAdblockPlusClient::RemoveFilter(const std::wstring& text)
392 { 399 {
393 Communication::OutputBuffer request; 400 Communication::OutputBuffer request;
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 Communication::OutputBuffer request; 536 Communication::OutputBuffer request;
530 request << Communication::PROC_GET_HOST << ToUtf8String(url); 537 request << Communication::PROC_GET_HOST << ToUtf8String(url);
531 538
532 Communication::InputBuffer response; 539 Communication::InputBuffer response;
533 if (!CallEngine(request, response)) 540 if (!CallEngine(request, response))
534 return L""; 541 return L"";
535 std::string host; 542 std::string host;
536 response >> host; 543 response >> host;
537 return ToUtf16String(host); 544 return ToUtf16String(host);
538 } 545 }
546
547 int CAdblockPlusClient::CompareVersions(const std::wstring& v1, const std::wstri ng& v2)
548 {
549 DEBUG_GENERAL("CompareVersions");
550 Communication::OutputBuffer request;
551 request << Communication::PROC_COMPARE_VERSIONS << ToUtf8String(v1) << ToUtf8S tring(v2);
552 Communication::InputBuffer response;
553 if (!CallEngine(request, response))
554 return 0;
555 int result;
556 response >> result;
557 return result;
558 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld