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

Side by Side Diff: src/plugin/AdblockPlusClient.cpp

Issue 11062004: Don't use std::string in the plugin, convert when communicating with the engine (Closed)
Patch Set: Created June 27, 2013, 10:37 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 #include "PluginStdAfx.h" 1 #include "PluginStdAfx.h"
2 2
3 #include "PluginSettings.h" 3 #include "PluginSettings.h"
4 #include "PluginSystem.h" 4 #include "PluginSystem.h"
5 #include "PluginFilter.h" 5 #include "PluginFilter.h"
6 #include "PluginClientFactory.h" 6 #include "PluginClientFactory.h"
7 #include "PluginHttpRequest.h" 7 #include "PluginHttpRequest.h"
8 #include "PluginMutex.h" 8 #include "PluginMutex.h"
9 #include "PluginClass.h" 9 #include "PluginClass.h"
10 10
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 return std::auto_ptr<Communication::Pipe>(new Communication::Pipe(Comm unication::pipeName, Communication::Pipe::MODE_CONNECT)); 59 return std::auto_ptr<Communication::Pipe>(new Communication::Pipe(Comm unication::pipeName, Communication::Pipe::MODE_CONNECT));
60 } 60 }
61 catch (Communication::PipeConnectionError e) 61 catch (Communication::PipeConnectionError e)
62 { 62 {
63 } 63 }
64 } 64 }
65 throw std::runtime_error("Unable to open Adblock Plus Engine pipe"); 65 throw std::runtime_error("Unable to open Adblock Plus Engine pipe");
66 } 66 }
67 } 67 }
68 68
69 std::vector<std::string> ReadStrings(Communication::InputBuffer& message) 69 std::vector<std::wstring> ReadStrings(Communication::InputBuffer& message)
70 { 70 {
71 int32_t count; 71 int32_t count;
72 message >> count; 72 message >> count;
73 73
74 std::vector<std::string> result; 74 std::vector<std::wstring> result;
75 for (int32_t i = 0; i < count; i++) 75 for (int32_t i = 0; i < count; i++)
76 { 76 {
77 std::string str; 77 std::string str;
78 message >> str; 78 message >> str;
79 result.push_back(str); 79 result.push_back(ToUtf16String(str));
80 } 80 }
81 return result; 81 return result;
82 } 82 }
83 83
84 std::vector<SubscriptionDescription> ReadSubscriptions(Communication::InputBuf fer& message) 84 std::vector<SubscriptionDescription> ReadSubscriptions(Communication::InputBuf fer& message)
85 { 85 {
86 int32_t count; 86 int32_t count;
87 message >> count; 87 message >> count;
88 88
89 std::vector<SubscriptionDescription> result; 89 std::vector<SubscriptionDescription> result;
90 for (int32_t i = 0; i < count; i++) 90 for (int32_t i = 0; i < count; i++)
91 { 91 {
92 SubscriptionDescription description; 92 SubscriptionDescription description;
93 message >> description.url >> description.title 93 std::string url;
94 >> description.specialization >> description.listed; 94 message >> url;
95 description.url = ToUtf16String(url);
96 std::string title;
97 message >> title;
98 description.title = ToUtf16String(title);
99 std::string specialization;
100 message >> specialization;
101 description.specialization = ToUtf16String(specialization);
102 message >> description.listed;
95 result.push_back(description); 103 result.push_back(description);
96 } 104 }
97 return result; 105 return result;
98 } 106 }
99 107
100 Communication::InputBuffer CallAdblockPlusEngineProcedure(Communication::Outpu tBuffer& message) 108 Communication::InputBuffer CallAdblockPlusEngineProcedure(Communication::Outpu tBuffer& message)
101 { 109 {
102 std::auto_ptr<Communication::Pipe> pipe = OpenAdblockPlusEnginePipe(); 110 std::auto_ptr<Communication::Pipe> pipe = OpenAdblockPlusEnginePipe();
103 pipe->WriteMessage(message); 111 pipe->WriteMessage(message);
104 return pipe->ReadMessage(); 112 return pipe->ReadMessage();
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 { 202 {
195 bool isHidden; 203 bool isHidden;
196 m_criticalSectionFilter.Lock(); 204 m_criticalSectionFilter.Lock();
197 { 205 {
198 isHidden = filter && filter->IsElementHidden(tag, pEl, domain, indent); 206 isHidden = filter && filter->IsElementHidden(tag, pEl, domain, indent);
199 } 207 }
200 m_criticalSectionFilter.Unlock(); 208 m_criticalSectionFilter.Unlock();
201 return isHidden; 209 return isHidden;
202 } 210 }
203 211
204 bool CAdblockPlusClient::IsWhitelistedUrl(const std::string& url) 212 bool CAdblockPlusClient::IsWhitelistedUrl(const std::wstring& url)
205 { 213 {
206 Communication::OutputBuffer request; 214 Communication::OutputBuffer request;
207 request << Communication::PROC_IS_WHITELISTED_URL << url; 215 request << Communication::PROC_IS_WHITELISTED_URL << ToUtf8String(url);
208 216
209 try 217 try
210 { 218 {
211 Communication::InputBuffer response = CallAdblockPlusEngineProcedure(request ); 219 Communication::InputBuffer response = CallAdblockPlusEngineProcedure(request );
212 220
213 bool isWhitelisted; 221 bool isWhitelisted;
214 response >> isWhitelisted; 222 response >> isWhitelisted;
215 return isWhitelisted; 223 return isWhitelisted;
216 } 224 }
217 catch (const std::exception& e) 225 catch (const std::exception& e)
(...skipping 17 matching lines...) Expand all
235 cbData = 50; 243 cbData = 50;
236 status = RegQueryValueEx(hKey, L"Version", NULL, &type, (BYTE*)version, &cbDat a); 244 status = RegQueryValueEx(hKey, L"Version", NULL, &type, (BYTE*)version, &cbDat a);
237 if (status != 0) 245 if (status != 0)
238 { 246 {
239 return 0; 247 return 0;
240 } 248 }
241 RegCloseKey(hKey); 249 RegCloseKey(hKey);
242 return (int)(version[0] - 48); 250 return (int)(version[0] - 48);
243 } 251 }
244 252
245 bool CAdblockPlusClient::Matches(const std::string& url, const std::string& cont entType, const std::string& domain) 253 bool CAdblockPlusClient::Matches(const std::wstring& url, const std::wstring& co ntentType, const std::wstring& domain)
246 { 254 {
247 Communication::OutputBuffer request; 255 Communication::OutputBuffer request;
248 request << Communication::PROC_MATCHES << url << contentType << domain; 256 request << Communication::PROC_MATCHES << ToUtf8String(url) << ToUtf8String(co ntentType) << ToUtf8String(domain);
249 257
250 try 258 try
251 { 259 {
252 Communication::InputBuffer response = CallAdblockPlusEngineProcedure(request ); 260 Communication::InputBuffer response = CallAdblockPlusEngineProcedure(request );
253 261
254 bool match; 262 bool match;
255 response >> match; 263 response >> match;
256 return match; 264 return match;
257 } 265 }
258 catch (const std::exception& e) 266 catch (const std::exception& e)
259 { 267 {
260 DEBUG_GENERAL(e.what()); 268 DEBUG_GENERAL(e.what());
261 return false; 269 return false;
262 } 270 }
263 } 271 }
264 272
265 std::vector<std::string> CAdblockPlusClient::GetElementHidingSelectors(const std ::string& domain) 273 std::vector<std::wstring> CAdblockPlusClient::GetElementHidingSelectors(const st d::wstring& domain)
266 { 274 {
267 Communication::OutputBuffer request; 275 Communication::OutputBuffer request;
268 request << Communication::PROC_GET_ELEMHIDE_SELECTORS << domain; 276 request << Communication::PROC_GET_ELEMHIDE_SELECTORS << ToUtf8String(domain);
269 277
270 try 278 try
271 { 279 {
272 Communication::InputBuffer response = CallAdblockPlusEngineProcedure(request ); 280 Communication::InputBuffer response = CallAdblockPlusEngineProcedure(request );
273 return ReadStrings(response); 281 return ReadStrings(response);
274 } 282 }
275 catch (const std::exception& e) 283 catch (const std::exception& e)
276 { 284 {
277 DEBUG_GENERAL(e.what()); 285 DEBUG_GENERAL(e.what());
278 return std::vector<std::string>(); 286 return std::vector<std::wstring>();
279 } 287 }
280 } 288 }
281 289
282 std::vector<SubscriptionDescription> CAdblockPlusClient::FetchAvailableSubscript ions() 290 std::vector<SubscriptionDescription> CAdblockPlusClient::FetchAvailableSubscript ions()
283 { 291 {
284 try 292 try
285 { 293 {
286 Communication::InputBuffer response = CallAdblockPlusEngineProcedure(Communi cation::PROC_AVAILABLE_SUBSCRIPTIONS); 294 Communication::InputBuffer response = CallAdblockPlusEngineProcedure(Communi cation::PROC_AVAILABLE_SUBSCRIPTIONS);
287 return ReadSubscriptions(response); 295 return ReadSubscriptions(response);
288 } 296 }
(...skipping 11 matching lines...) Expand all
300 Communication::InputBuffer response = CallAdblockPlusEngineProcedure(Communi cation::PROC_LISTED_SUBSCRIPTIONS); 308 Communication::InputBuffer response = CallAdblockPlusEngineProcedure(Communi cation::PROC_LISTED_SUBSCRIPTIONS);
301 return ReadSubscriptions(response); 309 return ReadSubscriptions(response);
302 } 310 }
303 catch (const std::exception& e) 311 catch (const std::exception& e)
304 { 312 {
305 DEBUG_GENERAL(e.what()); 313 DEBUG_GENERAL(e.what());
306 return std::vector<SubscriptionDescription>(); 314 return std::vector<SubscriptionDescription>();
307 } 315 }
308 } 316 }
309 317
310 void CAdblockPlusClient::SetSubscription(std::string url) 318 void CAdblockPlusClient::SetSubscription(const std::wstring& url)
311 { 319 {
312 Communication::OutputBuffer request; 320 Communication::OutputBuffer request;
313 request << Communication::PROC_SET_SUBSCRIPTION << url; 321 request << Communication::PROC_SET_SUBSCRIPTION << ToUtf8String(url);
314 322
315 try 323 try
316 { 324 {
317 CallAdblockPlusEngineProcedure(request); 325 CallAdblockPlusEngineProcedure(request);
318 } 326 }
319 catch (const std::exception& e) 327 catch (const std::exception& e)
320 { 328 {
321 DEBUG_GENERAL(e.what()); 329 DEBUG_GENERAL(e.what());
322 } 330 }
323 } 331 }
324 332
325 void CAdblockPlusClient::UpdateAllSubscriptions() 333 void CAdblockPlusClient::UpdateAllSubscriptions()
326 { 334 {
327 try 335 try
328 { 336 {
329 CallAdblockPlusEngineProcedure(Communication::PROC_UPDATE_ALL_SUBSCRIPTIONS) ; 337 CallAdblockPlusEngineProcedure(Communication::PROC_UPDATE_ALL_SUBSCRIPTIONS) ;
330 } 338 }
331 catch (const std::exception& e) 339 catch (const std::exception& e)
332 { 340 {
333 DEBUG_GENERAL(e.what()); 341 DEBUG_GENERAL(e.what());
334 } 342 }
335 } 343 }
336 344
337 std::vector<std::string> CAdblockPlusClient::GetExceptionDomains() 345 std::vector<std::wstring> CAdblockPlusClient::GetExceptionDomains()
338 { 346 {
339 try 347 try
340 { 348 {
341 Communication::InputBuffer response = CallAdblockPlusEngineProcedure(Communi cation::PROC_GET_EXCEPTION_DOMAINS); 349 Communication::InputBuffer response = CallAdblockPlusEngineProcedure(Communi cation::PROC_GET_EXCEPTION_DOMAINS);
342 return ReadStrings(response); 350 return ReadStrings(response);
343 } 351 }
344 catch (const std::exception& e) 352 catch (const std::exception& e)
345 { 353 {
346 DEBUG_GENERAL(e.what()); 354 DEBUG_GENERAL(e.what());
347 return std::vector<std::string>(); 355 return std::vector<std::wstring>();
348 } 356 }
349 } 357 }
350 358
351 void CAdblockPlusClient::AddFilter(const std::string& text) 359 void CAdblockPlusClient::AddFilter(const std::wstring& text)
352 { 360 {
353 Communication::OutputBuffer request; 361 Communication::OutputBuffer request;
354 request << Communication::PROC_ADD_FILTER << text; 362 request << Communication::PROC_ADD_FILTER << ToUtf8String(text);
355 363
356 try 364 try
357 { 365 {
358 CallAdblockPlusEngineProcedure(request); 366 CallAdblockPlusEngineProcedure(request);
359 } 367 }
360 catch (const std::exception& e) 368 catch (const std::exception& e)
361 { 369 {
362 DEBUG_GENERAL(e.what()); 370 DEBUG_GENERAL(e.what());
363 } 371 }
364 } 372 }
365 373
366 void CAdblockPlusClient::RemoveFilter(const std::string& text) 374 void CAdblockPlusClient::RemoveFilter(const std::wstring& text)
367 { 375 {
368 Communication::OutputBuffer request; 376 Communication::OutputBuffer request;
369 request << Communication::PROC_REMOVE_FILTER << text; 377 request << Communication::PROC_REMOVE_FILTER << ToUtf8String(text);
370 378
371 try 379 try
372 { 380 {
373 CallAdblockPlusEngineProcedure(request); 381 CallAdblockPlusEngineProcedure(request);
374 } 382 }
375 catch (const std::exception& e) 383 catch (const std::exception& e)
376 { 384 {
377 DEBUG_GENERAL(e.what()); 385 DEBUG_GENERAL(e.what());
378 } 386 }
379 } 387 }
OLDNEW

Powered by Google App Engine
This is Rietveld