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: Second version Created June 25, 2014, 6:53 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 #include <memory>
14
15 namespace 13 namespace
16 { 14 {
17 /**
18 * A temporary wchar buffer, initialized from a wstring.
19 * Used to pass parameters to CreateProcess* API functions, which may modify t he buffer contents.
20 *
21 * This class is a wrapper around unique_ptr.
22 */
23 class temporary_wchar_buffer {
24 /**
25 * Length of input string, not including terminating null character.
26 */
27 size_t len ;
28
29 /**
30 * The underlying unique_ptr
31 */
32 std::unique_ptr< wchar_t[] > buffer ;
33
34 public:
35 /**
36 * Ordinary constructor.
37 */
38 temporary_wchar_buffer( std::wstring s )
39 : len( s.length() ), buffer( new wchar_t[ len + 1 ] )
40 {
41 s.copy( buffer.get(), len );
42 buffer[ len ] = L'\0' ;
43 }
44
45 /**
46 * Conversion operator returns pointer to allocated buffer.
47 */
48 operator wchar_t *()
49 {
50 return buffer.get();
51 }
52 };
53
54 void SpawnAdblockPlusEngine() 15 void SpawnAdblockPlusEngine()
55 { 16 {
56 std::wstring engineExecutablePath = GetDllDir() + L"AdblockPlusEngine.exe"; 17 std::wstring engineExecutablePath = GetDllDir() + L"AdblockPlusEngine.exe";
57 temporary_wchar_buffer params( L"AdblockPlusEngine.exe " + CPluginSystem::Ge tInstance()->GetBrowserLanguage() ); 18 CString params = to_CString(L"AdblockPlusEngine.exe " + GetBrowserLanguage() );
58 19
59 STARTUPINFO startupInfo = {}; 20 STARTUPINFO startupInfo = {};
60 PROCESS_INFORMATION processInformation = {}; 21 PROCESS_INFORMATION processInformation = {};
61 22
62 HANDLE token; 23 HANDLE token;
63 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);
64 25
65 TOKEN_APPCONTAINER_INFORMATION *acs = NULL; 26 TOKEN_APPCONTAINER_INFORMATION *acs = NULL;
66 DWORD length = 0; 27 DWORD length = 0;
67 28
68 // Get AppContainer SID 29 // Get AppContainer SID
69 if (!GetTokenInformation(token, TokenAppContainerSid, acs, 0, &length) && Ge tLastError() == ERROR_INSUFFICIENT_BUFFER) 30 if (!GetTokenInformation(token, TokenAppContainerSid, acs, 0, &length) && Ge tLastError() == ERROR_INSUFFICIENT_BUFFER)
70 { 31 {
71 acs = (TOKEN_APPCONTAINER_INFORMATION*) HeapAlloc(GetProcessHeap(), HEAP _ZERO_MEMORY, length); 32 acs = (TOKEN_APPCONTAINER_INFORMATION*) HeapAlloc(GetProcessHeap(), HEAP _ZERO_MEMORY, length);
72 if (acs != NULL) 33 if (acs != NULL)
73 { 34 {
74 GetTokenInformation(token, TokenAppContainerSid, acs, length, &length) ; 35 GetTokenInformation(token, TokenAppContainerSid, acs, length, &length) ;
75 } 36 }
76 else 37 else
77 { 38 {
78 throw std::runtime_error("Out of memory"); 39 throw std::runtime_error("Out of memory");
79 } 40 }
80 } 41 }
81 42
82 BOOL createProcRes = 0; 43 BOOL createProcRes = 0;
83 // Running inside AppContainer or in Windows XP 44 // Running inside AppContainer or in Windows XP
84 if ((acs != NULL && acs->TokenAppContainer != NULL) || (!IsWindowsVistaOrLat er())) 45 if ((acs != NULL && acs->TokenAppContainer != NULL) || !IsWindowsVistaOrLate r())
85 { 46 {
86 // We need to break out from AppContainer. Launch with default security - registry entry will eat the user prompt 47 // We need to break out from AppContainer. Launch with default security - registry entry will eat the user prompt
87 // See http://msdn.microsoft.com/en-us/library/bb250462(v=vs.85).aspx#wpm_ elebp 48 // See http://msdn.microsoft.com/en-us/library/bb250462(v=vs.85).aspx#wpm_ elebp
88 createProcRes = CreateProcessW(engineExecutablePath.c_str(), (LPWSTR) para ms, 49 createProcRes = CreateProcessW(engineExecutablePath.c_str(), params.GetBuf fer(params.GetLength() + 1),
89 0, 0, false, 0, 0, 0, (STARTUPINFOW*)&startupInfo, &processInformation); 50 0, 0, false, 0, 0, 0, (STARTUPINFOW*)&startupInfo, &processInformation);
90 } 51 }
91 else 52 else
92 { 53 {
93 // Launch with Low Integrity explicitly 54 // Launch with Low Integrity explicitly
94 HANDLE newToken; 55 HANDLE newToken;
95 DuplicateTokenEx(token, 0, 0, SecurityImpersonation, TokenPrimary, &newTok en); 56 DuplicateTokenEx(token, 0, 0, SecurityImpersonation, TokenPrimary, &newTok en);
96 57
97 PSID integritySid = 0; 58 PSID integritySid = 0;
98 ConvertStringSidToSid(L"S-1-16-4096", &integritySid); 59 ConvertStringSidToSid(L"S-1-16-4096", &integritySid);
99 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
100 61
101 TOKEN_MANDATORY_LABEL tml = {}; 62 TOKEN_MANDATORY_LABEL tml = {};
102 tml.Label.Attributes = SE_GROUP_INTEGRITY; 63 tml.Label.Attributes = SE_GROUP_INTEGRITY;
103 tml.Label.Sid = integritySid; 64 tml.Label.Sid = integritySid;
104 65
105 // Set the process integrity level 66 // Set the process integrity level
106 SetTokenInformation(newToken, TokenIntegrityLevel, &tml, sizeof(TOKEN_MAND ATORY_LABEL) + GetLengthSid(integritySid)); 67 SetTokenInformation(newToken, TokenIntegrityLevel, &tml, sizeof(tml));
107 68
108 STARTUPINFO startupInfo = {}; 69 STARTUPINFO startupInfo = {};
109 PROCESS_INFORMATION processInformation = {}; 70 PROCESS_INFORMATION processInformation = {};
110 71
111 createProcRes = CreateProcessAsUserW(newToken, engineExecutablePath.c_str( ), (LPWSTR) params, 72 createProcRes = CreateProcessAsUserW(newToken, engineExecutablePath.c_str( ), params.GetBuffer(params.GetLength() + 1),
112 0, 0, false, 0, 0, 0, (STARTUPINFOW*)&startupInfo, &processInformation); 73 0, 0, false, 0, 0, 0, (STARTUPINFOW*)&startupInfo, &processInformation);
113 } 74 }
114 75
115 if (!createProcRes) 76 if (!createProcRes)
116 { 77 {
117 throw std::runtime_error("Failed to start Adblock Plus Engine"); 78 throw std::runtime_error("Failed to start Adblock Plus Engine");
118 } 79 }
119 80
120 CloseHandle(processInformation.hProcess); 81 CloseHandle(processInformation.hProcess);
121 CloseHandle(processInformation.hThread); 82 CloseHandle(processInformation.hThread);
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 150
190 CAdblockPlusClient* CAdblockPlusClient::s_instance = NULL; 151 CAdblockPlusClient* CAdblockPlusClient::s_instance = NULL;
191 152
192 CAdblockPlusClient::CAdblockPlusClient() : CPluginClientBase() 153 CAdblockPlusClient::CAdblockPlusClient() : CPluginClientBase()
193 { 154 {
194 m_filter = std::auto_ptr<CPluginFilter>(new CPluginFilter()); 155 m_filter = std::auto_ptr<CPluginFilter>(new CPluginFilter());
195 } 156 }
196 157
197 bool CAdblockPlusClient::CallEngine(Communication::OutputBuffer& message, Commun ication::InputBuffer& inputBuffer) 158 bool CAdblockPlusClient::CallEngine(Communication::OutputBuffer& message, Commun ication::InputBuffer& inputBuffer)
198 { 159 {
199 DEBUG_GENERAL(L"CallEngine start"); 160 DEBUG_GENERAL("CallEngine start");
200 CriticalSection::Lock lock(enginePipeLock); 161 CriticalSection::Lock lock(enginePipeLock);
201 try 162 try
202 { 163 {
203 if (!enginePipe) 164 if (!enginePipe)
204 enginePipe.reset(OpenEnginePipe()); 165 enginePipe.reset(OpenEnginePipe());
205 enginePipe->WriteMessage(message); 166 enginePipe->WriteMessage(message);
206 inputBuffer = enginePipe->ReadMessage(); 167 inputBuffer = enginePipe->ReadMessage();
207 } 168 }
208 catch (const std::exception& e) 169 catch (const std::exception& e)
209 { 170 {
210 DEBUG_GENERAL( ABP::debug::widen( e.what() ) ); 171 DEBUG_GENERAL(e.what());
211 return false; 172 return false;
212 } 173 }
213 DEBUG_GENERAL(L"CallEngine end"); 174 DEBUG_GENERAL("CallEngine end");
214 return true; 175 return true;
215 } 176 }
216 177
217 bool CAdblockPlusClient::CallEngine(Communication::ProcType proc, Communication: :InputBuffer& inputBuffer) 178 bool CAdblockPlusClient::CallEngine(Communication::ProcType proc, Communication: :InputBuffer& inputBuffer)
218 { 179 {
219 Communication::OutputBuffer message; 180 Communication::OutputBuffer message;
220 message << proc; 181 message << proc;
221 return CallEngine(message, inputBuffer); 182 return CallEngine(message, inputBuffer);
222 } 183 }
223 184
(...skipping 16 matching lines...) Expand all
240 s_instance = client; 201 s_instance = client;
241 } 202 }
242 203
243 instance = s_instance; 204 instance = s_instance;
244 } 205 }
245 s_criticalSectionLocal.Unlock(); 206 s_criticalSectionLocal.Unlock();
246 207
247 return instance; 208 return instance;
248 } 209 }
249 210
250 211 bool CAdblockPlusClient::ShouldBlock(const std::wstring& src, int contentType, c onst std::wstring& domain, bool addDebug)
251 bool CAdblockPlusClient::ShouldBlock( std::wstring src, int contentType, const s td::wstring & domain, bool addDebug)
252 { 212 {
253 bool isBlocked = false; 213 bool isBlocked = false;
254
255 bool isCached = false; 214 bool isCached = false;
256
257 CPluginSettings* settings = CPluginSettings::GetInstance();
258
259 m_criticalSectionCache.Lock(); 215 m_criticalSectionCache.Lock();
260 { 216 {
261 std::map< std::wstring, bool >::iterator it = m_cacheBlockedSources.find(src ); 217 auto it = m_cacheBlockedSources.find(src);
262 218
263 isCached = it != m_cacheBlockedSources.end(); 219 isCached = it != m_cacheBlockedSources.end();
264 if (isCached) 220 if (isCached)
265 { 221 {
266 isBlocked = it->second; 222 isBlocked = it->second;
267 } 223 }
268 } 224 }
269 m_criticalSectionCache.Unlock(); 225 m_criticalSectionCache.Unlock();
270 226
271 if (!isCached) 227 if (!isCached)
272 { 228 {
273 m_criticalSectionFilter.Lock(); 229 m_criticalSectionFilter.Lock();
274 { 230 {
275 isBlocked = m_filter->ShouldBlock(src, contentType, domain, addDebug); 231 isBlocked = m_filter->ShouldBlock(src, contentType, domain, addDebug);
276 } 232 }
277 m_criticalSectionFilter.Unlock(); 233 m_criticalSectionFilter.Unlock();
278
279 234
280 // Cache result, if content type is defined 235 // Cache result, if content type is defined
281 if (contentType != CFilter::contentTypeAny) 236 if (contentType != CFilter::contentTypeAny)
282 { 237 {
283 m_criticalSectionCache.Lock(); 238 m_criticalSectionCache.Lock();
284 { 239 {
285 m_cacheBlockedSources[src] = isBlocked; 240 m_cacheBlockedSources[src] = isBlocked;
286 } 241 }
287 m_criticalSectionCache.Unlock(); 242 m_criticalSectionCache.Unlock();
288 } 243 }
289 } 244 }
290
291
292 return isBlocked; 245 return isBlocked;
293 } 246 }
294 247
295 bool CAdblockPlusClient::IsElementHidden(const std::wstring & tag, IHTMLElement* pEl, const std::wstring & domain, const std::wstring & indent, CPluginFilter* f ilter) 248 bool CAdblockPlusClient::IsElementHidden(const std::wstring& tag, IHTMLElement* pEl, const std::wstring& domain, const std::wstring& indent, CPluginFilter* filt er)
296 { 249 {
297 bool isHidden; 250 bool isHidden;
298 m_criticalSectionFilter.Lock(); 251 m_criticalSectionFilter.Lock();
299 { 252 {
300 isHidden = filter && filter->IsElementHidden(tag, pEl, domain, indent); 253 isHidden = filter && filter->IsElementHidden(tag, pEl, domain, indent);
301 } 254 }
302 m_criticalSectionFilter.Unlock(); 255 m_criticalSectionFilter.Unlock();
303 return isHidden; 256 return isHidden;
304 } 257 }
305 258
306 bool CAdblockPlusClient::IsWhitelistedUrl(const std::wstring& url) 259 bool CAdblockPlusClient::IsWhitelistedUrl(const std::wstring& url)
307 { 260 {
308 DEBUG_GENERAL(L"IsWhitelistedUrl: " + url + L" start"); 261 DEBUG_GENERAL((L"IsWhitelistedUrl: " + url + L" start").c_str());
309 Communication::OutputBuffer request; 262 Communication::OutputBuffer request;
310 request << Communication::PROC_IS_WHITELISTED_URL << ToUtf8String(url); 263 request << Communication::PROC_IS_WHITELISTED_URL << ToUtf8String(url);
311 264
312 Communication::InputBuffer response; 265 Communication::InputBuffer response;
313 if (!CallEngine(request, response)) 266 if (!CallEngine(request, response))
314 return false; 267 return false;
315 268
316 bool isWhitelisted; 269 bool isWhitelisted;
317 response >> isWhitelisted; 270 response >> isWhitelisted;
318 271
319 DEBUG_GENERAL(L"IsWhitelistedUrl: " + url + L" end"); 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;
320 return isWhitelisted; 287 return isWhitelisted;
321 } 288 }
322 289
323 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)
324 { 291 {
325 Communication::OutputBuffer request; 292 Communication::OutputBuffer request;
326 request << Communication::PROC_MATCHES << ToUtf8String(url) << ToUtf8String(co ntentType) << ToUtf8String(domain); 293 request << Communication::PROC_MATCHES << ToUtf8String(url) << ToUtf8String(co ntentType) << ToUtf8String(domain);
327 294
328 Communication::InputBuffer response; 295 Communication::InputBuffer response;
329 if (!CallEngine(request, response)) 296 if (!CallEngine(request, response))
(...skipping 24 matching lines...) Expand all
354 } 321 }
355 322
356 std::vector<SubscriptionDescription> CAdblockPlusClient::GetListedSubscriptions( ) 323 std::vector<SubscriptionDescription> CAdblockPlusClient::GetListedSubscriptions( )
357 { 324 {
358 Communication::InputBuffer response; 325 Communication::InputBuffer response;
359 if (!CallEngine(Communication::PROC_LISTED_SUBSCRIPTIONS, response)) 326 if (!CallEngine(Communication::PROC_LISTED_SUBSCRIPTIONS, response))
360 return std::vector<SubscriptionDescription>(); 327 return std::vector<SubscriptionDescription>();
361 return ReadSubscriptions(response); 328 return ReadSubscriptions(response);
362 } 329 }
363 330
331 // Returns true if Acceptable Ads are enabled, false otherwise.
332 bool CAdblockPlusClient::IsAcceptableAdsEnabled()
333 {
334 std::vector<SubscriptionDescription> subscriptions = GetListedSubscriptions();
335 std::wstring aaUrl = GetPref(L"subscriptions_exceptionsurl", L"");
336 for (std::vector<SubscriptionDescription>::iterator subscription = subscriptio ns.begin(); subscription != subscriptions.end(); subscription++)
337 {
338 if (subscription->url == aaUrl)
339 {
340 return true;
341 }
342 }
343 return false;
344 }
345
364 void CAdblockPlusClient::SetSubscription(const std::wstring& url) 346 void CAdblockPlusClient::SetSubscription(const std::wstring& url)
365 { 347 {
366 Communication::OutputBuffer request; 348 Communication::OutputBuffer request;
367 request << Communication::PROC_SET_SUBSCRIPTION << ToUtf8String(url); 349 request << Communication::PROC_SET_SUBSCRIPTION << ToUtf8String(url);
368 CallEngine(request); 350 CallEngine(request);
369 } 351 }
352
353 void CAdblockPlusClient::AddSubscription(const std::wstring& url)
354 {
355 Communication::OutputBuffer request;
356 request << Communication::PROC_ADD_SUBSCRIPTION << ToUtf8String(url);
357 CallEngine(request);
358 }
359
360 void CAdblockPlusClient::RemoveSubscription(const std::wstring& url)
361 {
362 Communication::OutputBuffer request;
363 request << Communication::PROC_REMOVE_SUBSCRIPTION << ToUtf8String(url);
364 CallEngine(request);
365 }
366
370 367
371 void CAdblockPlusClient::UpdateAllSubscriptions() 368 void CAdblockPlusClient::UpdateAllSubscriptions()
372 { 369 {
373 CallEngine(Communication::PROC_UPDATE_ALL_SUBSCRIPTIONS); 370 CallEngine(Communication::PROC_UPDATE_ALL_SUBSCRIPTIONS);
374 } 371 }
375 372
376 std::vector<std::wstring> CAdblockPlusClient::GetExceptionDomains() 373 std::vector<std::wstring> CAdblockPlusClient::GetExceptionDomains()
377 { 374 {
378 Communication::InputBuffer response; 375 Communication::InputBuffer response;
379 if (!CallEngine(Communication::PROC_GET_EXCEPTION_DOMAINS, response)) 376 if (!CallEngine(Communication::PROC_GET_EXCEPTION_DOMAINS, response))
380 return std::vector<std::wstring>(); 377 return std::vector<std::wstring>();
381 return ReadStrings(response); 378 return ReadStrings(response);
382 } 379 }
383 380
384 bool CAdblockPlusClient::IsFirstRun() 381 bool CAdblockPlusClient::IsFirstRun()
385 { 382 {
386 DEBUG_GENERAL(L"IsFirstRun"); 383 DEBUG_GENERAL("IsFirstRun");
387 Communication::InputBuffer response; 384 Communication::InputBuffer response;
388 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;
389 bool res; 386 bool res;
390 response >> res; 387 response >> res;
391 return res; 388 return res;
392 } 389 }
390
393 void CAdblockPlusClient::AddFilter(const std::wstring& text) 391 void CAdblockPlusClient::AddFilter(const std::wstring& text)
394 { 392 {
395 Communication::OutputBuffer request; 393 Communication::OutputBuffer request;
396 request << Communication::PROC_ADD_FILTER << ToUtf8String(text); 394 request << Communication::PROC_ADD_FILTER << ToUtf8String(text);
397 CallEngine(request); 395 CallEngine(request);
398 } 396 }
399 397
400 void CAdblockPlusClient::RemoveFilter(const std::wstring& text) 398 void CAdblockPlusClient::RemoveFilter(const std::wstring& text)
401 { 399 {
402 Communication::OutputBuffer request; 400 Communication::OutputBuffer request;
(...skipping 21 matching lines...) Expand all
424 request << Communication::PROC_SET_PREF << ToUtf8String(name) << value; 422 request << Communication::PROC_SET_PREF << ToUtf8String(name) << value;
425 CallEngine(request); 423 CallEngine(request);
426 } 424 }
427 425
428 std::wstring CAdblockPlusClient::GetPref(const std::wstring& name, const wchar_t * defaultValue) 426 std::wstring CAdblockPlusClient::GetPref(const std::wstring& name, const wchar_t * defaultValue)
429 { 427 {
430 return GetPref(name, std::wstring(defaultValue)); 428 return GetPref(name, std::wstring(defaultValue));
431 } 429 }
432 std::wstring CAdblockPlusClient::GetPref(const std::wstring& name, const std::ws tring& defaultValue) 430 std::wstring CAdblockPlusClient::GetPref(const std::wstring& name, const std::ws tring& defaultValue)
433 { 431 {
434 DEBUG_GENERAL(L"GetPref: " + name + L" start"); 432 DEBUG_GENERAL((L"GetPref: " + name + L" start").c_str());
435 Communication::OutputBuffer request; 433 Communication::OutputBuffer request;
436 request << Communication::PROC_GET_PREF << ToUtf8String(name); 434 request << Communication::PROC_GET_PREF << ToUtf8String(name);
437 435
438 Communication::InputBuffer response; 436 Communication::InputBuffer response;
439 if (!CallEngine(request, response)) 437 if (!CallEngine(request, response))
440 return defaultValue; 438 return defaultValue;
441 bool success; 439 bool success;
442 response >> success; 440 response >> success;
443 if (success) 441 if (success)
444 { 442 {
445 std::string value; 443 std::string value;
446 response >> value; 444 response >> value;
447 DEBUG_GENERAL(L"GetPref: " + name + L" end"); 445 DEBUG_GENERAL((L"GetPref: " + name + L" end").c_str());
448 return ToUtf16String(value); 446 return ToUtf16String(value);
449 } 447 }
450 else 448 else
451 { 449 {
452 DEBUG_GENERAL(L"GetPref: " + name + L" end"); 450 DEBUG_GENERAL((L"GetPref: " + name + L" end").c_str());
453 return defaultValue; 451 return defaultValue;
454 } 452 }
455 } 453 }
456 454
457 bool CAdblockPlusClient::GetPref(const std::wstring& name, bool defaultValue) 455 bool CAdblockPlusClient::GetPref(const std::wstring& name, bool defaultValue)
458 { 456 {
459 DEBUG_GENERAL(L"GetPref: " + name + L" start"); 457 DEBUG_GENERAL((L"GetPref: " + name + L" start").c_str());
460 Communication::OutputBuffer request; 458 Communication::OutputBuffer request;
461 request << Communication::PROC_GET_PREF << ToUtf8String(name); 459 request << Communication::PROC_GET_PREF << ToUtf8String(name);
462 460
463 Communication::InputBuffer response; 461 Communication::InputBuffer response;
464 if (!CallEngine(request, response)) 462 if (!CallEngine(request, response))
465 return defaultValue; 463 return defaultValue;
466 bool success; 464 bool success;
467 response >> success; 465 response >> success;
468 if (success) 466 if (success)
469 { 467 {
470 bool value; 468 bool value;
471 response >> value; 469 response >> value;
472 DEBUG_GENERAL(L"GetPref: " + name + L" end"); 470 DEBUG_GENERAL((L"GetPref: " + name + L" end").c_str());
473 return value; 471 return value;
474 } 472 }
475 else 473 else
476 { 474 {
477 DEBUG_GENERAL(L"GetPref: " + name + L" end"); 475 DEBUG_GENERAL((L"GetPref: " + name + L" end").c_str());
478 return defaultValue; 476 return defaultValue;
479 } 477 }
480 } 478 }
481 int64_t CAdblockPlusClient::GetPref(const std::wstring& name, int64_t defaultVal ue) 479 int64_t CAdblockPlusClient::GetPref(const std::wstring& name, int64_t defaultVal ue)
482 { 480 {
483 DEBUG_GENERAL(L"GetPref: " + name + L" start"); 481 DEBUG_GENERAL((L"GetPref: " + name + L" start").c_str());
484 Communication::OutputBuffer request; 482 Communication::OutputBuffer request;
485 request << Communication::PROC_GET_PREF << ToUtf8String(name); 483 request << Communication::PROC_GET_PREF << ToUtf8String(name);
486 484
487 Communication::InputBuffer response; 485 Communication::InputBuffer response;
488 if (!CallEngine(request, response)) 486 if (!CallEngine(request, response))
489 return defaultValue; 487 return defaultValue;
490 bool success; 488 bool success;
491 response >> success; 489 response >> success;
492 if (success) 490 if (success)
493 { 491 {
494 int64_t value; 492 int64_t value;
495 response >> value; 493 response >> value;
496 DEBUG_GENERAL(L"GetPref: " + name + L" end"); 494 DEBUG_GENERAL((L"GetPref: " + name + L" end").c_str());
497 return value; 495 return value;
498 } 496 }
499 else 497 else
500 { 498 {
501 DEBUG_GENERAL(L"GetPref: " + name + L" end"); 499 DEBUG_GENERAL((L"GetPref: " + name + L" end").c_str());
502 return defaultValue; 500 return defaultValue;
503 } 501 }
504 } 502 }
505 503
506 void CAdblockPlusClient::CheckForUpdates(HWND callbackWindow) 504 void CAdblockPlusClient::CheckForUpdates(HWND callbackWindow)
507 { 505 {
508 Communication::OutputBuffer request; 506 Communication::OutputBuffer request;
509 request << Communication::PROC_CHECK_FOR_UPDATES << reinterpret_cast<int32_t>( callbackWindow); 507 request << Communication::PROC_CHECK_FOR_UPDATES << reinterpret_cast<int32_t>( callbackWindow);
510 CallEngine(request); 508 CallEngine(request);
511 } 509 }
512 510
513 std::wstring CAdblockPlusClient::GetDocumentationLink() 511 std::wstring CAdblockPlusClient::GetDocumentationLink()
514 { 512 {
515 DEBUG_GENERAL(L"GetDocumentationLink"); 513 DEBUG_GENERAL("GetDocumentationLink");
516 Communication::InputBuffer response; 514 Communication::InputBuffer response;
517 if (!CallEngine(Communication::PROC_GET_DOCUMENTATION_LINK, response)) 515 if (!CallEngine(Communication::PROC_GET_DOCUMENTATION_LINK, response))
518 return L""; 516 return L"";
519 std::wstring docLink; 517 std::wstring docLink;
520 response >> docLink; 518 response >> docLink;
521 return docLink; 519 return docLink;
522 } 520 }
523 521
524 bool CAdblockPlusClient::TogglePluginEnabled() 522 bool CAdblockPlusClient::TogglePluginEnabled()
525 { 523 {
526 DEBUG_GENERAL(L"TogglePluginEnabled"); 524 DEBUG_GENERAL("TogglePluginEnabled");
527 Communication::InputBuffer response; 525 Communication::InputBuffer response;
528 if (!CallEngine(Communication::PROC_TOGGLE_PLUGIN_ENABLED, response)) 526 if (!CallEngine(Communication::PROC_TOGGLE_PLUGIN_ENABLED, response))
529 return false; 527 return false;
530 bool currentEnabledState; 528 bool currentEnabledState;
531 response >> currentEnabledState; 529 response >> currentEnabledState;
532 return currentEnabledState; 530 return currentEnabledState;
533 } 531 }
532
534 std::wstring CAdblockPlusClient::GetHostFromUrl(const std::wstring& url) 533 std::wstring CAdblockPlusClient::GetHostFromUrl(const std::wstring& url)
535 { 534 {
536 DEBUG_GENERAL(L"GetHostFromUrl"); 535 DEBUG_GENERAL("GetHostFromUrl");
537 Communication::OutputBuffer request; 536 Communication::OutputBuffer request;
538 request << Communication::PROC_GET_HOST << ToUtf8String(url); 537 request << Communication::PROC_GET_HOST << ToUtf8String(url);
539 538
540 Communication::InputBuffer response; 539 Communication::InputBuffer response;
541 if (!CallEngine(request, response)) 540 if (!CallEngine(request, response))
542 return L""; 541 return L"";
543 std::string host; 542 std::string host;
544 response >> host; 543 response >> host;
545 return ToUtf16String(host); 544 return ToUtf16String(host);
546 } 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