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

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

Issue 5447868882092032: Issue 1793 - check whether the frame is whitelisted before injecting CSS (Closed)
Left Patch Set: fix according to comments Created May 15, 2015, 11:55 a.m.
Right Patch Set: rebase and rename webBrowser to parentBrowser Created Nov. 30, 2015, 3:27 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/AdblockPlusClient.h ('k') | src/plugin/PluginTabBase.cpp » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 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/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 #include "PluginStdAfx.h" 18 #include "PluginStdAfx.h"
19 #include "AdblockPlusClient.h"
19 #include "PluginSettings.h" 20 #include "PluginSettings.h"
20 #include "PluginSystem.h" 21 #include "PluginSystem.h"
21 #include "PluginFilter.h" 22 #include "PluginFilter.h"
22 #include "PluginClientFactory.h"
23 #include "PluginMutex.h" 23 #include "PluginMutex.h"
24 #include "PluginClass.h" 24 #include "PluginClass.h"
25
26 #include "AdblockPlusClient.h"
27
28 #include "../shared/Utils.h" 25 #include "../shared/Utils.h"
29 26
30 namespace 27 namespace
31 { 28 {
29 class ScopedProcessInformation : public PROCESS_INFORMATION {
30 public:
31 ScopedProcessInformation()
32 {
33 hProcess = hThread = 0;
34 dwProcessId = dwThreadId = 0;
35 }
36 ~ScopedProcessInformation()
37 {
38 if (hThread != nullptr)
39 {
40 CloseHandle(hThread);
41 }
42 if (hProcess != nullptr)
43 {
44 CloseHandle(hProcess);
45 }
46 }
47 };
48
32 void SpawnAdblockPlusEngine() 49 void SpawnAdblockPlusEngine()
33 { 50 {
34 std::wstring engineExecutablePath = GetDllDir() + L"AdblockPlusEngine.exe"; 51 std::wstring engineExecutablePath = GetDllDir() + L"AdblockPlusEngine.exe";
35 CString params = ToCString(L"AdblockPlusEngine.exe " + GetBrowserLanguage()) ; 52 std::wstring params = L"AdblockPlusEngine.exe " + GetBrowserLanguage();
36 53
37 STARTUPINFO startupInfo = {}; 54 STARTUPINFO startupInfo = {};
38 PROCESS_INFORMATION processInformation = {}; 55 ScopedProcessInformation processInformation;
39 56
40 HANDLE token; 57 // We need to break out from AppContainer. Launch with default security - re gistry entry will eat the user prompt
41 OpenProcessToken(GetCurrentProcess(), TOKEN_DUPLICATE | TOKEN_ADJUST_DEFAULT | TOKEN_QUERY | TOKEN_ASSIGN_PRIMARY, &token); 58 // See http://msdn.microsoft.com/en-us/library/bb250462(v=vs.85).aspx#wpm_el ebp
42 59 BOOL createProcRes = CreateProcessW(engineExecutablePath.c_str(), &params[0] ,
43 TOKEN_APPCONTAINER_INFORMATION *acs = NULL; 60 0, 0, false, 0, 0, 0, &startupInfo, &processInformation);
44 DWORD length = 0;
45
46 // Get AppContainer SID
47 if (!GetTokenInformation(token, TokenAppContainerSid, acs, 0, &length) && Ge tLastError() == ERROR_INSUFFICIENT_BUFFER)
48 {
49 acs = (TOKEN_APPCONTAINER_INFORMATION*) HeapAlloc(GetProcessHeap(), HEAP _ZERO_MEMORY, length);
50 if (acs != NULL)
51 {
52 GetTokenInformation(token, TokenAppContainerSid, acs, length, &length) ;
53 }
54 else
55 {
56 throw std::runtime_error("Out of memory");
57 }
58 }
59
60 BOOL createProcRes = 0;
61 // Running inside AppContainer or in Windows XP
62 if ((acs != NULL && acs->TokenAppContainer != NULL) || !IsWindowsVistaOrLate r())
63 {
64 // We need to break out from AppContainer. Launch with default security - registry entry will eat the user prompt
65 // See http://msdn.microsoft.com/en-us/library/bb250462(v=vs.85).aspx#wpm_ elebp
66 createProcRes = CreateProcessW(engineExecutablePath.c_str(), params.GetBuf fer(params.GetLength() + 1),
67 0, 0, false, 0, 0, 0, (STARTUPINFOW*)&startupInfo, &processInformation);
68 }
69 else
70 {
71 // Launch with Low Integrity explicitly
72 HANDLE newToken;
73 DuplicateTokenEx(token, 0, 0, SecurityImpersonation, TokenPrimary, &newTok en);
74
75 PSID integritySid = 0;
76 ConvertStringSidToSid(L"S-1-16-4096", &integritySid);
77 std::tr1::shared_ptr<SID> sharedIntegritySid(static_cast<SID*>(integritySi d), FreeSid); // Just to simplify cleanup
78
79 TOKEN_MANDATORY_LABEL tml = {};
80 tml.Label.Attributes = SE_GROUP_INTEGRITY;
81 tml.Label.Sid = integritySid;
82
83 // Set the process integrity level
84 SetTokenInformation(newToken, TokenIntegrityLevel, &tml, sizeof(tml));
85
86 STARTUPINFO startupInfo = {};
87 PROCESS_INFORMATION processInformation = {};
88
89 createProcRes = CreateProcessAsUserW(newToken, engineExecutablePath.c_str( ), params.GetBuffer(params.GetLength() + 1),
90 0, 0, false, 0, 0, 0, (STARTUPINFOW*)&startupInfo, &processInformation);
91 }
92
93 if (!createProcRes) 61 if (!createProcRes)
94 { 62 {
95 throw std::runtime_error("Failed to start Adblock Plus Engine"); 63 throw std::runtime_error("Failed to start Adblock Plus Engine");
96 } 64 }
97
98 CloseHandle(processInformation.hProcess);
99 CloseHandle(processInformation.hThread);
100 } 65 }
101 66
102 Communication::Pipe* OpenEnginePipe() 67 Communication::Pipe* OpenEnginePipe()
103 { 68 {
104 try 69 try
105 { 70 {
106 return new Communication::Pipe(Communication::pipeName, Communication::Pip e::MODE_CONNECT); 71 return new Communication::Pipe(Communication::pipeName, Communication::Pip e::MODE_CONNECT);
107 } 72 }
108 catch (Communication::PipeConnectionError e) 73 catch (Communication::PipeConnectionError e)
109 { 74 {
(...skipping 17 matching lines...) Expand all
127 92
128 std::vector<SubscriptionDescription> ReadSubscriptions(Communication::InputBuf fer& message) 93 std::vector<SubscriptionDescription> ReadSubscriptions(Communication::InputBuf fer& message)
129 { 94 {
130 int32_t count; 95 int32_t count;
131 message >> count; 96 message >> count;
132 97
133 std::vector<SubscriptionDescription> result; 98 std::vector<SubscriptionDescription> result;
134 for (int32_t i = 0; i < count; i++) 99 for (int32_t i = 0; i < count; i++)
135 { 100 {
136 SubscriptionDescription description; 101 SubscriptionDescription description;
137 message >> description.url; 102 std::string url;
138 message >> description.title; 103 message >> url;
139 message >> description.specialization; 104 description.url = ToUtf16String(url);
105 std::string title;
106 message >> title;
107 description.title = ToUtf16String(title);
108 std::string specialization;
109 message >> specialization;
110 description.specialization = ToUtf16String(specialization);
140 message >> description.listed; 111 message >> description.listed;
141 result.push_back(description); 112 result.push_back(description);
142 } 113 }
143 return result; 114 return result;
144 } 115 }
145 } 116 }
146 117
147 CAdblockPlusClient* CAdblockPlusClient::s_instance = NULL; 118 CAdblockPlusClient* CAdblockPlusClient::s_instance = NULL;
148 CComAutoCriticalSection CAdblockPlusClient::s_criticalSectionLocal; 119 CComAutoCriticalSection CAdblockPlusClient::s_criticalSectionLocal;
149 120
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 return isHidden; 224 return isHidden;
254 } 225 }
255 226
256 bool CAdblockPlusClient::IsWhitelistedUrl(const std::wstring& url, const std::ve ctor<std::string>& frameHierarchy) 227 bool CAdblockPlusClient::IsWhitelistedUrl(const std::wstring& url, const std::ve ctor<std::string>& frameHierarchy)
257 { 228 {
258 return !GetWhitelistingFilter(url, frameHierarchy).empty(); 229 return !GetWhitelistingFilter(url, frameHierarchy).empty();
259 } 230 }
260 231
261 std::string CAdblockPlusClient::GetWhitelistingFilter(const std::wstring& url, c onst std::vector<std::string>& frameHierarchy) 232 std::string CAdblockPlusClient::GetWhitelistingFilter(const std::wstring& url, c onst std::vector<std::string>& frameHierarchy)
262 { 233 {
263 DEBUG_GENERAL((L"GetWhitelistingFilter: " + url + L" start").c_str()); 234 DEBUG_GENERAL((L"IsWhitelistedUrl: " + url + L" start").c_str());
264 Communication::OutputBuffer request; 235 Communication::OutputBuffer request;
265 request << Communication::PROC_GET_WHITELISTING_FITER << url << frameHierarchy ; 236 request << Communication::PROC_GET_WHITELISTING_FITER << ToUtf8String(url) << frameHierarchy;
266 237
267 Communication::InputBuffer response; 238 Communication::InputBuffer response;
268 if (!CallEngine(request, response)) 239 if (!CallEngine(request, response))
269 return ""; 240 return "";
270 241
271 std::string filterText; 242 std::string filterText;
272 response >> filterText; 243 response >> filterText;
273 244
274 DEBUG_GENERAL((L"GetWhitelistingFilter: " + url + L" end").c_str()); 245 DEBUG_GENERAL((L"IsWhitelistedUrl: " + url + L" end").c_str());
275 return filterText; 246 return filterText;
276 } 247 }
277 248
278 bool CAdblockPlusClient::IsElemhideWhitelistedOnDomain(const std::wstring& url, const std::vector<std::string>& frameHierarchy) 249 bool CAdblockPlusClient::IsElemhideWhitelistedOnDomain(const std::wstring& url, const std::vector<std::string>& frameHierarchy)
279 { 250 {
280 Communication::OutputBuffer request; 251 Communication::OutputBuffer request;
281 request << Communication::PROC_IS_ELEMHIDE_WHITELISTED_ON_URL << url << frameH ierarchy; 252 request << Communication::PROC_IS_ELEMHIDE_WHITELISTED_ON_URL << ToUtf8String( url) << frameHierarchy;
282 253
283 Communication::InputBuffer response; 254 Communication::InputBuffer response;
284 if (!CallEngine(request, response)) 255 if (!CallEngine(request, response))
285 return false; 256 return false;
286 257
287 bool isWhitelisted; 258 bool isWhitelisted;
288 response >> isWhitelisted; 259 response >> isWhitelisted;
289 return isWhitelisted; 260 return isWhitelisted;
290 } 261 }
291 262
292 bool CAdblockPlusClient::Matches(const std::wstring& url, AdblockPlus::FilterEng ine::ContentType contentType, const std::wstring& domain) 263 bool CAdblockPlusClient::Matches(const std::wstring& url, AdblockPlus::FilterEng ine::ContentType contentType, const std::wstring& domain)
293 { 264 {
294 Communication::OutputBuffer request; 265 Communication::OutputBuffer request;
295 request << Communication::PROC_MATCHES << url << contentType << domain; 266 request << Communication::PROC_MATCHES << ToUtf8String(url) << static_cast<int 32_t>(contentType) << ToUtf8String(domain);
296 267
297 Communication::InputBuffer response; 268 Communication::InputBuffer response;
298 if (!CallEngine(request, response)) 269 if (!CallEngine(request, response))
299 return false; 270 return false;
300 271
301 bool match; 272 bool match;
302 response >> match; 273 response >> match;
303 return match; 274 return match;
304 } 275 }
305 276
306 std::vector<std::wstring> CAdblockPlusClient::GetElementHidingSelectors(const st d::wstring& domain) 277 std::vector<std::wstring> CAdblockPlusClient::GetElementHidingSelectors(const st d::wstring& domain)
307 { 278 {
308 Communication::OutputBuffer request; 279 Communication::OutputBuffer request;
309 request << Communication::PROC_GET_ELEMHIDE_SELECTORS << domain; 280 request << Communication::PROC_GET_ELEMHIDE_SELECTORS << ToUtf8String(domain);
310 281
311 Communication::InputBuffer response; 282 Communication::InputBuffer response;
312 if (!CallEngine(request, response)) 283 if (!CallEngine(request, response))
313 return std::vector<std::wstring>(); 284 return std::vector<std::wstring>();
314 285
315 std::vector<std::wstring> selectors; 286 std::vector<std::string> selectors;
316 response >> selectors; 287 response >> selectors;
317 return selectors; 288 return ToUtf16Strings(selectors);
318 } 289 }
319 290
320 std::vector<SubscriptionDescription> CAdblockPlusClient::FetchAvailableSubscript ions() 291 std::vector<SubscriptionDescription> CAdblockPlusClient::FetchAvailableSubscript ions()
321 { 292 {
322 Communication::InputBuffer response; 293 Communication::InputBuffer response;
323 if (!CallEngine(Communication::PROC_AVAILABLE_SUBSCRIPTIONS, response)) 294 if (!CallEngine(Communication::PROC_AVAILABLE_SUBSCRIPTIONS, response))
324 return std::vector<SubscriptionDescription>(); 295 return std::vector<SubscriptionDescription>();
325 return ReadSubscriptions(response); 296 return ReadSubscriptions(response);
326 } 297 }
327 298
(...skipping 16 matching lines...) Expand all
344 { 315 {
345 return true; 316 return true;
346 } 317 }
347 } 318 }
348 return false; 319 return false;
349 } 320 }
350 321
351 void CAdblockPlusClient::SetSubscription(const std::wstring& url) 322 void CAdblockPlusClient::SetSubscription(const std::wstring& url)
352 { 323 {
353 Communication::OutputBuffer request; 324 Communication::OutputBuffer request;
354 request << Communication::PROC_SET_SUBSCRIPTION << url; 325 request << Communication::PROC_SET_SUBSCRIPTION << ToUtf8String(url);
355 CallEngine(request); 326 CallEngine(request);
356 } 327 }
357 328
358 void CAdblockPlusClient::AddSubscription(const std::wstring& url) 329 void CAdblockPlusClient::AddSubscription(const std::wstring& url)
359 { 330 {
360 Communication::OutputBuffer request; 331 Communication::OutputBuffer request;
361 request << Communication::PROC_ADD_SUBSCRIPTION << url; 332 request << Communication::PROC_ADD_SUBSCRIPTION << ToUtf8String(url);
362 CallEngine(request); 333 CallEngine(request);
363 } 334 }
364 335
365 void CAdblockPlusClient::RemoveSubscription(const std::wstring& url) 336 void CAdblockPlusClient::RemoveSubscription(const std::wstring& url)
366 { 337 {
367 Communication::OutputBuffer request; 338 Communication::OutputBuffer request;
368 request << Communication::PROC_REMOVE_SUBSCRIPTION << url; 339 request << Communication::PROC_REMOVE_SUBSCRIPTION << ToUtf8String(url);
369 CallEngine(request); 340 CallEngine(request);
370 } 341 }
371 342
372 343
373 void CAdblockPlusClient::UpdateAllSubscriptions() 344 void CAdblockPlusClient::UpdateAllSubscriptions()
374 { 345 {
375 CallEngine(Communication::PROC_UPDATE_ALL_SUBSCRIPTIONS); 346 CallEngine(Communication::PROC_UPDATE_ALL_SUBSCRIPTIONS);
376 } 347 }
377 348
378 std::vector<std::wstring> CAdblockPlusClient::GetExceptionDomains() 349 std::vector<std::wstring> CAdblockPlusClient::GetExceptionDomains()
379 { 350 {
380 Communication::InputBuffer response; 351 Communication::InputBuffer response;
381 if (!CallEngine(Communication::PROC_GET_EXCEPTION_DOMAINS, response)) 352 if (!CallEngine(Communication::PROC_GET_EXCEPTION_DOMAINS, response))
382 return std::vector<std::wstring>(); 353 return std::vector<std::wstring>();
383 354
384 std::vector<std::wstring> domains; 355 std::vector<std::string> domains;
385 response >> domains; 356 response >> domains;
386 return domains; 357 return ToUtf16Strings(domains);
387 } 358 }
388 359
389 bool CAdblockPlusClient::IsFirstRun() 360 bool CAdblockPlusClient::IsFirstRun()
390 { 361 {
391 DEBUG_GENERAL("IsFirstRun"); 362 DEBUG_GENERAL("IsFirstRun");
392 Communication::InputBuffer response; 363 Communication::InputBuffer response;
393 if (!CallEngine(Communication::PROC_IS_FIRST_RUN_ACTION_NEEDED, response)) ret urn false; 364 if (!CallEngine(Communication::PROC_IS_FIRST_RUN_ACTION_NEEDED, response)) ret urn false;
394 bool res; 365 bool res;
395 response >> res; 366 response >> res;
396 return res; 367 return res;
397 } 368 }
398 369
399 void CAdblockPlusClient::AddFilter(const std::wstring& text) 370 void CAdblockPlusClient::AddFilter(const std::wstring& text)
400 { 371 {
401 Communication::OutputBuffer request; 372 Communication::OutputBuffer request;
402 request << Communication::PROC_ADD_FILTER << text; 373 request << Communication::PROC_ADD_FILTER << ToUtf8String(text);
403 CallEngine(request); 374 CallEngine(request);
404 } 375 }
405 376
406 void CAdblockPlusClient::RemoveFilter(const std::wstring& text) 377 void CAdblockPlusClient::RemoveFilter(const std::wstring& text)
407 { 378 {
408 RemoveFilter(ToUtf8String(text)); 379 RemoveFilter(ToUtf8String(text));
409 } 380 }
410 381
411 void CAdblockPlusClient::RemoveFilter(const std::string& text) 382 void CAdblockPlusClient::RemoveFilter(const std::string& text)
412 { 383 {
413 Communication::OutputBuffer request; 384 Communication::OutputBuffer request;
414 request << Communication::PROC_REMOVE_FILTER << text; 385 request << Communication::PROC_REMOVE_FILTER << text;
415 CallEngine(request); 386 CallEngine(request);
416 } 387 }
417 388
418 void CAdblockPlusClient::SetPref(const std::wstring& name, const std::wstring& v alue) 389 void CAdblockPlusClient::SetPref(const std::wstring& name, const std::wstring& v alue)
419 { 390 {
420 Communication::OutputBuffer request; 391 Communication::OutputBuffer request;
421 request << Communication::PROC_SET_PREF << name << value; 392 request << Communication::PROC_SET_PREF << ToUtf8String(name) << ToUtf8String( value);
422 CallEngine(request); 393 CallEngine(request);
423 } 394 }
424 395
425 void CAdblockPlusClient::SetPref(const std::wstring& name, const int64_t & value ) 396 void CAdblockPlusClient::SetPref(const std::wstring& name, const int64_t & value )
426 { 397 {
427 Communication::OutputBuffer request; 398 Communication::OutputBuffer request;
428 request << Communication::PROC_SET_PREF << name << value; 399 request << Communication::PROC_SET_PREF << ToUtf8String(name) << value;
429 CallEngine(request); 400 CallEngine(request);
430 } 401 }
431 402
432 void CAdblockPlusClient::SetPref(const std::wstring& name, bool value) 403 void CAdblockPlusClient::SetPref(const std::wstring& name, bool value)
433 { 404 {
434 Communication::OutputBuffer request; 405 Communication::OutputBuffer request;
435 request << Communication::PROC_SET_PREF << name << value; 406 request << Communication::PROC_SET_PREF << ToUtf8String(name) << value;
436 CallEngine(request); 407 CallEngine(request);
437 } 408 }
438 409
439 std::wstring CAdblockPlusClient::GetPref(const std::wstring& name, const wchar_t * defaultValue) 410 std::wstring CAdblockPlusClient::GetPref(const std::wstring& name, const wchar_t * defaultValue)
440 { 411 {
441 return GetPref(name, std::wstring(defaultValue)); 412 return GetPref(name, std::wstring(defaultValue));
442 } 413 }
443 std::wstring CAdblockPlusClient::GetPref(const std::wstring& name, const std::ws tring& defaultValue) 414 std::wstring CAdblockPlusClient::GetPref(const std::wstring& name, const std::ws tring& defaultValue)
444 { 415 {
445 DEBUG_GENERAL((L"GetPref: " + name + L" start").c_str()); 416 DEBUG_GENERAL((L"GetPref: " + name + L" start").c_str());
446 Communication::OutputBuffer request; 417 Communication::OutputBuffer request;
447 request << Communication::PROC_GET_PREF << name; 418 request << Communication::PROC_GET_PREF << ToUtf8String(name);
448 419
449 Communication::InputBuffer response; 420 Communication::InputBuffer response;
450 if (!CallEngine(request, response)) 421 if (!CallEngine(request, response))
451 return defaultValue; 422 return defaultValue;
452 bool success; 423 bool success;
453 response >> success; 424 response >> success;
454 if (success) 425 if (success)
455 { 426 {
456 std::wstring value; 427 std::string value;
457 response >> value; 428 response >> value;
458 DEBUG_GENERAL((L"GetPref: " + name + L" end").c_str()); 429 DEBUG_GENERAL((L"GetPref: " + name + L" end").c_str());
459 return value; 430 return ToUtf16String(value);
460 } 431 }
461 else 432 else
462 { 433 {
463 DEBUG_GENERAL((L"GetPref: " + name + L" end").c_str()); 434 DEBUG_GENERAL((L"GetPref: " + name + L" end").c_str());
464 return defaultValue; 435 return defaultValue;
465 } 436 }
466 } 437 }
467 438
468 bool CAdblockPlusClient::GetPref(const std::wstring& name, bool defaultValue) 439 bool CAdblockPlusClient::GetPref(const std::wstring& name, bool defaultValue)
469 { 440 {
470 DEBUG_GENERAL((L"GetPref: " + name + L" start").c_str()); 441 DEBUG_GENERAL((L"GetPref: " + name + L" start").c_str());
471 Communication::OutputBuffer request; 442 Communication::OutputBuffer request;
472 request << Communication::PROC_GET_PREF << name; 443 request << Communication::PROC_GET_PREF << ToUtf8String(name);
473 444
474 Communication::InputBuffer response; 445 Communication::InputBuffer response;
475 if (!CallEngine(request, response)) 446 if (!CallEngine(request, response))
476 return defaultValue; 447 return defaultValue;
477 bool success; 448 bool success;
478 response >> success; 449 response >> success;
479 if (success) 450 if (success)
480 { 451 {
481 bool value; 452 bool value;
482 response >> value; 453 response >> value;
483 DEBUG_GENERAL((L"GetPref: " + name + L" end").c_str()); 454 DEBUG_GENERAL((L"GetPref: " + name + L" end").c_str());
484 return value; 455 return value;
485 } 456 }
486 else 457 else
487 { 458 {
488 DEBUG_GENERAL((L"GetPref: " + name + L" end").c_str()); 459 DEBUG_GENERAL((L"GetPref: " + name + L" end").c_str());
489 return defaultValue; 460 return defaultValue;
490 } 461 }
491 } 462 }
492 int64_t CAdblockPlusClient::GetPref(const std::wstring& name, int64_t defaultVal ue) 463 int64_t CAdblockPlusClient::GetPref(const std::wstring& name, int64_t defaultVal ue)
493 { 464 {
494 DEBUG_GENERAL((L"GetPref: " + name + L" start").c_str()); 465 DEBUG_GENERAL((L"GetPref: " + name + L" start").c_str());
495 Communication::OutputBuffer request; 466 Communication::OutputBuffer request;
496 request << Communication::PROC_GET_PREF << name; 467 request << Communication::PROC_GET_PREF << ToUtf8String(name);
497 468
498 Communication::InputBuffer response; 469 Communication::InputBuffer response;
499 if (!CallEngine(request, response)) 470 if (!CallEngine(request, response))
500 return defaultValue; 471 return defaultValue;
501 bool success; 472 bool success;
502 response >> success; 473 response >> success;
503 if (success) 474 if (success)
504 { 475 {
505 int64_t value; 476 int64_t value;
506 response >> value; 477 response >> value;
(...skipping 13 matching lines...) Expand all
520 request << Communication::PROC_CHECK_FOR_UPDATES << reinterpret_cast<int32_t>( callbackWindow); 491 request << Communication::PROC_CHECK_FOR_UPDATES << reinterpret_cast<int32_t>( callbackWindow);
521 CallEngine(request); 492 CallEngine(request);
522 } 493 }
523 494
524 std::wstring CAdblockPlusClient::GetDocumentationLink() 495 std::wstring CAdblockPlusClient::GetDocumentationLink()
525 { 496 {
526 DEBUG_GENERAL("GetDocumentationLink"); 497 DEBUG_GENERAL("GetDocumentationLink");
527 Communication::InputBuffer response; 498 Communication::InputBuffer response;
528 if (!CallEngine(Communication::PROC_GET_DOCUMENTATION_LINK, response)) 499 if (!CallEngine(Communication::PROC_GET_DOCUMENTATION_LINK, response))
529 return L""; 500 return L"";
530 std::wstring docLink; 501 std::string docLink;
531 response >> docLink; 502 response >> docLink;
532 return docLink; 503 return ToUtf16String(docLink);
533 } 504 }
534 505
535 bool CAdblockPlusClient::TogglePluginEnabled() 506 bool CAdblockPlusClient::TogglePluginEnabled()
536 { 507 {
537 DEBUG_GENERAL("TogglePluginEnabled"); 508 DEBUG_GENERAL("TogglePluginEnabled");
538 Communication::InputBuffer response; 509 Communication::InputBuffer response;
539 if (!CallEngine(Communication::PROC_TOGGLE_PLUGIN_ENABLED, response)) 510 if (!CallEngine(Communication::PROC_TOGGLE_PLUGIN_ENABLED, response))
540 return false; 511 return false;
541 bool currentEnabledState; 512 bool currentEnabledState;
542 response >> currentEnabledState; 513 response >> currentEnabledState;
543 return currentEnabledState; 514 return currentEnabledState;
544 } 515 }
545 516
546 std::wstring CAdblockPlusClient::GetHostFromUrl(const std::wstring& url) 517 std::wstring CAdblockPlusClient::GetHostFromUrl(const std::wstring& url)
547 { 518 {
548 DEBUG_GENERAL("GetHostFromUrl"); 519 DEBUG_GENERAL("GetHostFromUrl");
549 Communication::OutputBuffer request; 520 Communication::OutputBuffer request;
550 request << Communication::PROC_GET_HOST << url; 521 request << Communication::PROC_GET_HOST << ToUtf8String(url);
551 522
552 Communication::InputBuffer response; 523 Communication::InputBuffer response;
553 if (!CallEngine(request, response)) 524 if (!CallEngine(request, response))
554 return L""; 525 return L"";
555 std::wstring host; 526 std::string host;
556 response >> host; 527 response >> host;
557 return host; 528 return ToUtf16String(host);
558 } 529 }
559 530
560 int CAdblockPlusClient::CompareVersions(const std::wstring& v1, const std::wstri ng& v2) 531 int CAdblockPlusClient::CompareVersions(const std::wstring& v1, const std::wstri ng& v2)
561 { 532 {
562 DEBUG_GENERAL("CompareVersions"); 533 DEBUG_GENERAL("CompareVersions");
563 Communication::OutputBuffer request; 534 Communication::OutputBuffer request;
564 request << Communication::PROC_COMPARE_VERSIONS << v1 << v2; 535 request << Communication::PROC_COMPARE_VERSIONS << ToUtf8String(v1) << ToUtf8S tring(v2);
565 Communication::InputBuffer response; 536 Communication::InputBuffer response;
566 if (!CallEngine(request, response)) 537 if (!CallEngine(request, response))
567 return 0; 538 return 0;
568 int result; 539 int result;
569 response >> result; 540 response >> result;
570 return result; 541 return result;
571 } 542 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld