| OLD | NEW |
| 1 #include <AdblockPlus.h> | 1 #include <AdblockPlus.h> |
| 2 #include <functional> | 2 #include <functional> |
| 3 #include <vector> | 3 #include <vector> |
| 4 #include <Windows.h> | 4 #include <Windows.h> |
| 5 | 5 |
| 6 #include "../shared/AutoHandle.h" | 6 #include "../shared/AutoHandle.h" |
| 7 #include "../shared/Communication.h" | 7 #include "../shared/Communication.h" |
| 8 #include "../shared/Dictionary.h" | 8 #include "../shared/Dictionary.h" |
| 9 #include "../shared/Utils.h" | 9 #include "../shared/Utils.h" |
| 10 #include "../shared/Version.h" | 10 #include "../shared/Version.h" |
| 11 #include "../shared/CriticalSection.h" | 11 #include "../shared/CriticalSection.h" |
| 12 #include "Debug.h" | 12 #include "Debug.h" |
| 13 #include "Updater.h" | 13 #include "Updater.h" |
| 14 | 14 |
| 15 namespace | 15 namespace |
| 16 { | 16 { |
| 17 std::auto_ptr<AdblockPlus::FilterEngine> filterEngine; | 17 std::auto_ptr<AdblockPlus::FilterEngine> filterEngine; |
| 18 std::auto_ptr<Updater> updater; |
| 18 | 19 |
| 19 void WriteStrings(Communication::OutputBuffer& response, | 20 void WriteStrings(Communication::OutputBuffer& response, |
| 20 const std::vector<std::string>& strings) | 21 const std::vector<std::string>& strings) |
| 21 { | 22 { |
| 22 int32_t count = strings.size(); | 23 int32_t count = strings.size(); |
| 23 response << count; | 24 response << count; |
| 24 for (int32_t i = 0; i < count; i++) | 25 for (int32_t i = 0; i < count; i++) |
| 25 response << strings[i]; | 26 response << strings[i]; |
| 26 } | 27 } |
| 27 | 28 |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 catch (const std::exception& e) | 282 catch (const std::exception& e) |
| 282 { | 283 { |
| 283 DebugException(e); | 284 DebugException(e); |
| 284 } | 285 } |
| 285 | 286 |
| 286 // TODO: Keep the pipe open until the client disconnects | 287 // TODO: Keep the pipe open until the client disconnects |
| 287 | 288 |
| 288 return 0; | 289 return 0; |
| 289 } | 290 } |
| 290 | 291 |
| 291 void OnUpdateAvailable(AdblockPlus::JsEnginePtr jsEngine, AdblockPlus::JsValue
List& params) | 292 void OnUpdateAvailable(AdblockPlus::JsValueList& params) |
| 292 { | 293 { |
| 293 updateAvailable = true; | 294 updateAvailable = true; |
| 294 if (params.size() < 1) | 295 if (params.size() < 1) |
| 295 { | 296 { |
| 296 Debug("updateAvailable event missing URL"); | 297 Debug("updateAvailable event missing URL"); |
| 297 return; | 298 return; |
| 298 } | 299 } |
| 299 | 300 |
| 300 Updater updater(jsEngine, params[0]->AsString()); | 301 updater->SetUrl(params[0]->AsString()); |
| 301 updater.Update(); | 302 updater->Update(); |
| 302 } | 303 } |
| 303 } | 304 } |
| 304 | 305 |
| 305 std::auto_ptr<AdblockPlus::FilterEngine> CreateFilterEngine(const std::wstring&
locale) | 306 std::auto_ptr<AdblockPlus::FilterEngine> CreateFilterEngine(const std::wstring&
locale) |
| 306 { | 307 { |
| 307 AdblockPlus::AppInfo appInfo; | 308 AdblockPlus::AppInfo appInfo; |
| 308 appInfo.version = ToUtf8String(IEPLUGIN_VERSION); | 309 appInfo.version = ToUtf8String(IEPLUGIN_VERSION); |
| 309 appInfo.name = "adblockplusie"; | 310 appInfo.name = "adblockplusie"; |
| 310 #ifdef _WIN64 | 311 #ifdef _WIN64 |
| 311 appInfo.platform = "msie64"; | 312 appInfo.platform = "msie64"; |
| 312 #else | 313 #else |
| 313 appInfo.platform = "msie32"; | 314 appInfo.platform = "msie32"; |
| 314 #endif | 315 #endif |
| 315 appInfo.locale = ToUtf8String(locale); | 316 appInfo.locale = ToUtf8String(locale); |
| 316 #ifdef ADBLOCK_PLUS_TEST_MODE | 317 #ifdef ADBLOCK_PLUS_TEST_MODE |
| 317 appInfo.developmentBuild = true; | 318 appInfo.developmentBuild = true; |
| 318 #else | 319 #else |
| 319 appInfo.developmentBuild = false; | 320 appInfo.developmentBuild = false; |
| 320 #endif | 321 #endif |
| 321 | 322 |
| 322 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::New(appInfo); | 323 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::New(appInfo); |
| 323 jsEngine->SetEventCallback("updateAvailable", | 324 jsEngine->SetEventCallback("updateAvailable", &OnUpdateAvailable); |
| 324 std::bind(&OnUpdateAvailable, jsEngine, std::placeholders::_1)); | |
| 325 | 325 |
| 326 std::string dataPath = ToUtf8String(GetAppDataPath()); | 326 std::string dataPath = ToUtf8String(GetAppDataPath()); |
| 327 dynamic_cast<AdblockPlus::DefaultFileSystem*>(jsEngine->GetFileSystem().get())
->SetBasePath(dataPath); | 327 dynamic_cast<AdblockPlus::DefaultFileSystem*>(jsEngine->GetFileSystem().get())
->SetBasePath(dataPath); |
| 328 std::auto_ptr<AdblockPlus::FilterEngine> filterEngine(new AdblockPlus::FilterE
ngine(jsEngine)); | 328 std::auto_ptr<AdblockPlus::FilterEngine> filterEngine(new AdblockPlus::FilterE
ngine(jsEngine)); |
| 329 return filterEngine; | 329 return filterEngine; |
| 330 } | 330 } |
| 331 | 331 |
| 332 int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) | 332 int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) |
| 333 { | 333 { |
| 334 AutoHandle mutex(CreateMutexW(0, false, L"AdblockPlusEngine")); | 334 AutoHandle mutex(CreateMutexW(0, false, L"AdblockPlusEngine")); |
| 335 if (!mutex) | 335 if (!mutex) |
| 336 { | 336 { |
| 337 DebugLastError("CreateMutex failed"); | 337 DebugLastError("CreateMutex failed"); |
| 338 return 1; | 338 return 1; |
| 339 } | 339 } |
| 340 | 340 |
| 341 if (GetLastError() == ERROR_ALREADY_EXISTS) | 341 if (GetLastError() == ERROR_ALREADY_EXISTS) |
| 342 { | 342 { |
| 343 DebugLastError("Named pipe exists, another engine instance appears to be run
ning"); | 343 DebugLastError("Named pipe exists, another engine instance appears to be run
ning"); |
| 344 return 1; | 344 return 1; |
| 345 } | 345 } |
| 346 | 346 |
| 347 int argc; | 347 int argc; |
| 348 LPWSTR* argv = CommandLineToArgvW(GetCommandLineW(), &argc); | 348 LPWSTR* argv = CommandLineToArgvW(GetCommandLineW(), &argc); |
| 349 std::wstring locale(argc >= 2 ? argv[1] : L""); | 349 std::wstring locale(argc >= 2 ? argv[1] : L""); |
| 350 LocalFree(argv); | 350 LocalFree(argv); |
| 351 Dictionary::Create(locale); | 351 Dictionary::Create(locale); |
| 352 filterEngine = CreateFilterEngine(locale); | 352 filterEngine = CreateFilterEngine(locale); |
| 353 updater.reset(new Updater(filterEngine->GetJsEngine())); |
| 353 | 354 |
| 354 for (;;) | 355 for (;;) |
| 355 { | 356 { |
| 356 try | 357 try |
| 357 { | 358 { |
| 358 Communication::Pipe* pipe = new Communication::Pipe(Communication::pipeNam
e, | 359 Communication::Pipe* pipe = new Communication::Pipe(Communication::pipeNam
e, |
| 359 Communication::Pipe::MODE_CREATE); | 360 Communication::Pipe::MODE_CREATE); |
| 360 | 361 |
| 361 // TODO: Count established connections, kill the engine when none are left | 362 // TODO: Count established connections, kill the engine when none are left |
| 362 AutoHandle thread(CreateThread(0, 0, ClientThread, static_cast<LPVOID>(pip
e), 0, 0)); | 363 AutoHandle thread(CreateThread(0, 0, ClientThread, static_cast<LPVOID>(pip
e), 0, 0)); |
| 363 if (!thread) | 364 if (!thread) |
| 364 { | 365 { |
| 365 delete pipe; | 366 delete pipe; |
| 366 DebugLastError("CreateThread failed"); | 367 DebugLastError("CreateThread failed"); |
| 367 return 1; | 368 return 1; |
| 368 } | 369 } |
| 369 } | 370 } |
| 370 catch (std::runtime_error e) | 371 catch (std::runtime_error e) |
| 371 { | 372 { |
| 372 DebugException(e); | 373 DebugException(e); |
| 373 return 1; | 374 return 1; |
| 374 } | 375 } |
| 375 } | 376 } |
| 376 | 377 |
| 377 return 0; | 378 return 0; |
| 378 } | 379 } |
| OLD | NEW |