LEFT | RIGHT |
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 "PluginDictionary.h" | 7 #include "PluginDictionary.h" |
8 #include "PluginHttpRequest.h" | 8 #include "PluginHttpRequest.h" |
9 #include "PluginMutex.h" | 9 #include "PluginMutex.h" |
10 #include "PluginClass.h" | 10 #include "PluginClass.h" |
11 #include "PluginUtil.h" | 11 #include "PluginUtil.h" |
12 | 12 |
13 #include "AdblockPlusClient.h" | 13 #include "AdblockPlusClient.h" |
14 | 14 |
15 namespace | 15 namespace |
16 { | 16 { |
17 // TODO: pipeName, bufferSize, AutoHandle, ReadMessage, WriteMessage, MarshalS
trings and UnmarshalStrings are | 17 // TODO: GetUserName, pipeName, bufferSize, AutoHandle, ReadMessage, WriteMess
age, MarshalStrings and UnmarshalStrings are |
18 // duplicated in AdblockPlusEngine. We should find a way to reuse them. | 18 // duplicated in AdblockPlusEngine. We should find a way to reuse them. |
19 | 19 |
20 const std::wstring pipeName = L"\\\\.\\pipe\\adblockplusengine"; | 20 std::wstring GetUserName() |
| 21 { |
| 22 const DWORD maxLength = UNLEN + 1; |
| 23 std::auto_ptr<wchar_t> buffer(new wchar_t[maxLength]); |
| 24 DWORD length = maxLength; |
| 25 if (!::GetUserName(buffer.get(), &length)) |
| 26 { |
| 27 std::stringstream stream; |
| 28 stream << "Failed to get the current user's name (Error code: " << GetLast
Error() << ")"; |
| 29 throw std::runtime_error("Failed to get the current user's name"); |
| 30 } |
| 31 return std::wstring(buffer.get(), length); |
| 32 } |
| 33 |
| 34 const std::wstring pipeName = L"\\\\.\\pipe\\adblockplusengine_" + GetUserName
(); |
21 const int bufferSize = 1024; | 35 const int bufferSize = 1024; |
22 | 36 |
23 class AutoHandle | 37 class AutoHandle |
24 { | 38 { |
25 public: | 39 public: |
26 AutoHandle() | 40 AutoHandle() |
27 { | 41 { |
28 } | 42 } |
29 | 43 |
30 AutoHandle(HANDLE handle) : handle(handle) | 44 AutoHandle(HANDLE handle) : handle(handle) |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 cbData = 50; | 295 cbData = 50; |
282 status = RegQueryValueEx(hKey, L"Version", NULL, &type, (BYTE*)version, &cbDat
a); | 296 status = RegQueryValueEx(hKey, L"Version", NULL, &type, (BYTE*)version, &cbDat
a); |
283 if (status != 0) | 297 if (status != 0) |
284 { | 298 { |
285 return 0; | 299 return 0; |
286 } | 300 } |
287 RegCloseKey(hKey); | 301 RegCloseKey(hKey); |
288 return (int)(version[0] - 48); | 302 return (int)(version[0] - 48); |
289 } | 303 } |
290 | 304 |
291 std::string CallAdblockPlusEngineProcedure(const std::string& name, const std::v
ector<std::string>& args) | 305 std::string CallAdblockPlusEngineProcedure(const std::vector<std::string>& args) |
292 { | 306 { |
293 AutoHandle pipe(OpenAdblockPlusEnginePipe()); | 307 AutoHandle pipe(OpenAdblockPlusEnginePipe()); |
294 std::vector<std::string> strings; | 308 WriteMessage(pipe.get(), MarshalStrings(args)); |
295 strings.push_back(name); | |
296 for (std::vector<std::string>::const_iterator it = args.begin(); it != args.en
d(); it++) | |
297 strings.push_back(*it); | |
298 WriteMessage(pipe.get(), MarshalStrings(strings)); | |
299 return ReadMessage(pipe.get()); | 309 return ReadMessage(pipe.get()); |
300 } | 310 } |
301 | 311 |
302 bool CAdblockPlusClient::Matches(const std::string& url, const std::string& cont
entType, const std::string& domain) | 312 bool CAdblockPlusClient::Matches(const std::string& url, const std::string& cont
entType, const std::string& domain) |
303 { | 313 { |
304 std::vector<std::string> args; | 314 std::vector<std::string> args; |
| 315 args.push_back("Matches"); |
305 args.push_back(url); | 316 args.push_back(url); |
306 args.push_back(contentType); | 317 args.push_back(contentType); |
307 args.push_back(domain); | 318 args.push_back(domain); |
308 | 319 |
309 try | 320 try |
310 { | 321 { |
311 std::string response = CallAdblockPlusEngineProcedure("Matches", args); | 322 std::string response = CallAdblockPlusEngineProcedure(args); |
312 return response == "1"; | 323 return response == "1"; |
313 } | 324 } |
314 catch (const std::exception& e) | 325 catch (const std::exception& e) |
315 { | 326 { |
316 DEBUG_GENERAL(e.what()); | 327 DEBUG_GENERAL(e.what()); |
317 return false; | 328 return false; |
318 } | 329 } |
319 } | 330 } |
320 | 331 |
321 std::vector<std::string> CAdblockPlusClient::GetElementHidingSelectors(std::stri
ng domain) | 332 std::vector<std::string> CAdblockPlusClient::GetElementHidingSelectors(std::stri
ng domain) |
322 { | 333 { |
323 std::vector<std::string> args; | 334 std::vector<std::string> args; |
| 335 args.push_back("GetElementHidingSelectors"); |
324 args.push_back(domain); | 336 args.push_back(domain); |
325 | 337 |
326 try | 338 try |
327 { | 339 { |
328 std::string response = CallAdblockPlusEngineProcedure("GetElementHidingSelec
tors", args); | 340 std::string response = CallAdblockPlusEngineProcedure(args); |
329 return UnmarshalStrings(response); | 341 return UnmarshalStrings(response); |
330 } | 342 } |
331 catch (const std::exception& e) | 343 catch (const std::exception& e) |
332 { | 344 { |
333 DEBUG_GENERAL(e.what()); | 345 DEBUG_GENERAL(e.what()); |
334 return std::vector<std::string>(); | 346 return std::vector<std::string>(); |
335 } | 347 } |
336 } | 348 } |
337 | 349 |
338 std::vector<AdblockPlus::SubscriptionPtr> CAdblockPlusClient::FetchAvailableSubs
criptions() | 350 std::vector<AdblockPlus::SubscriptionPtr> CAdblockPlusClient::FetchAvailableSubs
criptions() |
(...skipping 18 matching lines...) Expand all Loading... |
357 { | 369 { |
358 //TODO: implement this | 370 //TODO: implement this |
359 return std::vector<AdblockPlus::SubscriptionPtr>(); | 371 return std::vector<AdblockPlus::SubscriptionPtr>(); |
360 } | 372 } |
361 | 373 |
362 AdblockPlus::SubscriptionPtr CAdblockPlusClient::GetSubscription(std::string url
) | 374 AdblockPlus::SubscriptionPtr CAdblockPlusClient::GetSubscription(std::string url
) |
363 { | 375 { |
364 //TODO: imlement this | 376 //TODO: imlement this |
365 return AdblockPlus::SubscriptionPtr(); | 377 return AdblockPlus::SubscriptionPtr(); |
366 } | 378 } |
LEFT | RIGHT |