| OLD | NEW |
| 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" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 } | 71 } |
| 72 } | 72 } |
| 73 } | 73 } |
| 74 } | 74 } |
| 75 catch(std::exception e) | 75 catch(std::exception e) |
| 76 { | 76 { |
| 77 DEBUG_GENERAL(e.what()); | 77 DEBUG_GENERAL(e.what()); |
| 78 } | 78 } |
| 79 return result; | 79 return result; |
| 80 } | 80 } |
| 81 |
| 82 std::vector<std::string> ReadStrings(Communication::InputBuffer& message) |
| 83 { |
| 84 int32_t count; |
| 85 message >> count; |
| 86 |
| 87 std::vector<std::string> result; |
| 88 for (int32_t i = 0; i < count; i++) |
| 89 { |
| 90 std::string str; |
| 91 message >> str; |
| 92 result.push_back(str); |
| 93 } |
| 94 return result; |
| 95 } |
| 96 |
| 97 std::vector<SubscriptionDescription> ReadSubscriptions(Communication::InputBuf
fer& message) |
| 98 { |
| 99 int32_t count; |
| 100 message >> count; |
| 101 |
| 102 std::vector<SubscriptionDescription> result; |
| 103 for (int32_t i = 0; i < count; i++) |
| 104 { |
| 105 SubscriptionDescription description; |
| 106 message >> description.url >> description.title |
| 107 >> description.specialization >> description.listed; |
| 108 result.push_back(description); |
| 109 } |
| 110 return result; |
| 111 } |
| 81 } | 112 } |
| 82 | 113 |
| 83 CAdblockPlusClient* CAdblockPlusClient::s_instance = NULL; | 114 CAdblockPlusClient* CAdblockPlusClient::s_instance = NULL; |
| 84 | 115 |
| 85 CAdblockPlusClient::CAdblockPlusClient() : CPluginClientBase() | 116 CAdblockPlusClient::CAdblockPlusClient() : CPluginClientBase() |
| 86 { | 117 { |
| 87 m_filter = std::auto_ptr<CPluginFilter>(new CPluginFilter()); | 118 m_filter = std::auto_ptr<CPluginFilter>(new CPluginFilter()); |
| 88 } | 119 } |
| 89 | 120 |
| 90 CAdblockPlusClient::~CAdblockPlusClient() | 121 CAdblockPlusClient::~CAdblockPlusClient() |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 return (int)(version[0] - 48); | 241 return (int)(version[0] - 48); |
| 211 } | 242 } |
| 212 | 243 |
| 213 Communication::InputBuffer CallAdblockPlusEngineProcedure(Communication::OutputB
uffer& message) | 244 Communication::InputBuffer CallAdblockPlusEngineProcedure(Communication::OutputB
uffer& message) |
| 214 { | 245 { |
| 215 std::auto_ptr<Communication::Pipe> pipe = OpenAdblockPlusEnginePipe(); | 246 std::auto_ptr<Communication::Pipe> pipe = OpenAdblockPlusEnginePipe(); |
| 216 pipe->WriteMessage(message); | 247 pipe->WriteMessage(message); |
| 217 return pipe->ReadMessage(); | 248 return pipe->ReadMessage(); |
| 218 } | 249 } |
| 219 | 250 |
| 251 Communication::InputBuffer CallAdblockPlusEngineProcedure(const std::string& pro
c) |
| 252 { |
| 253 Communication::OutputBuffer message; |
| 254 message << proc; |
| 255 return CallAdblockPlusEngineProcedure(message); |
| 256 } |
| 257 |
| 220 bool CAdblockPlusClient::Matches(const std::string& url, const std::string& cont
entType, const std::string& domain) | 258 bool CAdblockPlusClient::Matches(const std::string& url, const std::string& cont
entType, const std::string& domain) |
| 221 { | 259 { |
| 222 Communication::OutputBuffer request; | 260 Communication::OutputBuffer request; |
| 223 request << std::string("Matches") << url << contentType << domain; | 261 request << std::string("Matches") << url << contentType << domain; |
| 224 | 262 |
| 225 try | 263 try |
| 226 { | 264 { |
| 227 Communication::InputBuffer response = CallAdblockPlusEngineProcedure(request
); | 265 Communication::InputBuffer response = CallAdblockPlusEngineProcedure(request
); |
| 228 | 266 |
| 229 bool match; | 267 bool match; |
| 230 response >> match; | 268 response >> match; |
| 231 return match; | 269 return match; |
| 232 } | 270 } |
| 233 catch (const std::exception& e) | 271 catch (const std::exception& e) |
| 234 { | 272 { |
| 235 DEBUG_GENERAL(e.what()); | 273 DEBUG_GENERAL(e.what()); |
| 236 return false; | 274 return false; |
| 237 } | 275 } |
| 238 } | 276 } |
| 239 | 277 |
| 240 std::vector<std::string> CAdblockPlusClient::GetElementHidingSelectors(const std
::string& domain) | 278 std::vector<std::string> CAdblockPlusClient::GetElementHidingSelectors(const std
::string& domain) |
| 241 { | 279 { |
| 242 Communication::OutputBuffer request; | 280 Communication::OutputBuffer request; |
| 243 request << std::string("GetElementHidingSelectors") << domain; | 281 request << std::string("GetElementHidingSelectors") << domain; |
| 244 | 282 |
| 245 try | 283 try |
| 246 { | 284 { |
| 247 Communication::InputBuffer response = CallAdblockPlusEngineProcedure(request
); | 285 Communication::InputBuffer response = CallAdblockPlusEngineProcedure(request
); |
| 248 | 286 return ReadStrings(response); |
| 249 std::vector<std::string> selectors; | |
| 250 int32_t length; | |
| 251 response >> length; | |
| 252 for (int32_t i = 0; i < length; i++) | |
| 253 { | |
| 254 std::string selector; | |
| 255 response >> selector; | |
| 256 selectors.push_back(selector); | |
| 257 } | |
| 258 return selectors; | |
| 259 } | 287 } |
| 260 catch (const std::exception& e) | 288 catch (const std::exception& e) |
| 261 { | 289 { |
| 262 DEBUG_GENERAL(e.what()); | 290 DEBUG_GENERAL(e.what()); |
| 263 return std::vector<std::string>(); | 291 return std::vector<std::string>(); |
| 264 } | 292 } |
| 265 } | 293 } |
| 266 | 294 |
| 267 std::vector<AdblockPlus::SubscriptionPtr> CAdblockPlusClient::FetchAvailableSubs
criptions() | 295 std::vector<SubscriptionDescription> CAdblockPlusClient::FetchAvailableSubscript
ions() |
| 268 { | 296 { |
| 269 //TODO: implement this | 297 try |
| 270 return std::vector<AdblockPlus::SubscriptionPtr>(); | 298 { |
| 299 Communication::InputBuffer response = CallAdblockPlusEngineProcedure("FetchA
vailableSubscriptions"); |
| 300 return ReadSubscriptions(response); |
| 301 } |
| 302 catch (const std::exception& e) |
| 303 { |
| 304 DEBUG_GENERAL(e.what()); |
| 305 return std::vector<SubscriptionDescription>(); |
| 306 } |
| 271 } | 307 } |
| 272 | 308 |
| 273 std::vector<AdblockPlus::FilterPtr> CAdblockPlusClient::GetListedFilters() | 309 std::vector<SubscriptionDescription> CAdblockPlusClient::GetListedSubscriptions(
) |
| 274 { | 310 { |
| 275 //TODO: implement this | 311 try |
| 276 return std::vector<AdblockPlus::FilterPtr>(); | 312 { |
| 313 Communication::InputBuffer response = CallAdblockPlusEngineProcedure("GetLis
tedSubscriptions"); |
| 314 return ReadSubscriptions(response); |
| 315 } |
| 316 catch (const std::exception& e) |
| 317 { |
| 318 DEBUG_GENERAL(e.what()); |
| 319 return std::vector<SubscriptionDescription>(); |
| 320 } |
| 277 } | 321 } |
| 278 | 322 |
| 279 AdblockPlus::FilterPtr CAdblockPlusClient::GetFilter(std::string text) | 323 void CAdblockPlusClient::SetSubscription(std::string url) |
| 280 { | 324 { |
| 281 //TODO: implement this | 325 Communication::OutputBuffer request; |
| 282 return AdblockPlus::FilterPtr(); | 326 request << std::string("SetSubscription") << url; |
| 327 |
| 328 try |
| 329 { |
| 330 CallAdblockPlusEngineProcedure(request); |
| 331 } |
| 332 catch (const std::exception& e) |
| 333 { |
| 334 DEBUG_GENERAL(e.what()); |
| 335 } |
| 283 } | 336 } |
| 284 | 337 |
| 285 std::vector<AdblockPlus::SubscriptionPtr> CAdblockPlusClient::GetListedSubscript
ions() | 338 void CAdblockPlusClient::UpdateAllSubscriptions() |
| 286 { | 339 { |
| 287 //TODO: implement this | 340 try |
| 288 return std::vector<AdblockPlus::SubscriptionPtr>(); | 341 { |
| 342 CallAdblockPlusEngineProcedure("UpdateAllSubscriptions"); |
| 343 } |
| 344 catch (const std::exception& e) |
| 345 { |
| 346 DEBUG_GENERAL(e.what()); |
| 347 } |
| 289 } | 348 } |
| 290 | 349 |
| 291 AdblockPlus::SubscriptionPtr CAdblockPlusClient::GetSubscription(std::string url
) | 350 std::vector<std::string> CAdblockPlusClient::GetExceptionDomains() |
| 292 { | 351 { |
| 293 //TODO: imlement this | 352 try |
| 294 return AdblockPlus::SubscriptionPtr(); | 353 { |
| 354 Communication::InputBuffer response = CallAdblockPlusEngineProcedure("GetExc
eptionDomains"); |
| 355 return ReadStrings(response); |
| 356 } |
| 357 catch (const std::exception& e) |
| 358 { |
| 359 DEBUG_GENERAL(e.what()); |
| 360 return std::vector<std::string>(); |
| 361 } |
| 295 } | 362 } |
| 363 |
| 364 void CAdblockPlusClient::AddFilter(const std::string& text) |
| 365 { |
| 366 Communication::OutputBuffer request; |
| 367 request << std::string("AddFilter") << text; |
| 368 |
| 369 try |
| 370 { |
| 371 CallAdblockPlusEngineProcedure(request); |
| 372 } |
| 373 catch (const std::exception& e) |
| 374 { |
| 375 DEBUG_GENERAL(e.what()); |
| 376 } |
| 377 } |
| 378 |
| OLD | NEW |