 Issue 11756012:
  Enhanced Protected Mode support  (Closed)
    
  
    Issue 11756012:
  Enhanced Protected Mode support  (Closed) 
  | Left: | ||
| Right: | 
| LEFT | RIGHT | 
|---|---|
| 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 | |
| 16 namespace | 15 namespace | 
| 17 { | 16 { | 
| 18 std::auto_ptr<AdblockPlus::FilterEngine> filterEngine; | 17 std::auto_ptr<AdblockPlus::FilterEngine> filterEngine; | 
| 19 std::auto_ptr<Updater> updater; | 18 std::auto_ptr<Updater> updater; | 
| 20 int activeConnections = 0; | 19 int activeConnections = 0; | 
| 21 CriticalSection activeConnectionsLock; | 20 CriticalSection activeConnectionsLock; | 
| 22 HWND callbackWindow; | |
| 23 | 21 | 
| 24 void WriteStrings(Communication::OutputBuffer& response, | 22 void WriteStrings(Communication::OutputBuffer& response, | 
| 25 const std::vector<std::string>& strings) | 23 const std::vector<std::string>& strings) | 
| 26 { | 24 { | 
| 27 int32_t count = static_cast<int32_t>(strings.size()); | 25 int32_t count = static_cast<int32_t>(strings.size()); | 
| 28 response << count; | 26 response << count; | 
| 29 for (int32_t i = 0; i < count; i++) | 27 for (int32_t i = 0; i < count; i++) | 
| 30 response << strings[i]; | 28 response << strings[i]; | 
| 31 } | 29 } | 
| 32 | 30 | 
| 33 void WriteSubscriptions(Communication::OutputBuffer& response, | 31 void WriteSubscriptions(Communication::OutputBuffer& response, | 
| 34 const std::vector<AdblockPlus::SubscriptionPtr>& subscriptions) | 32 const std::vector<AdblockPlus::SubscriptionPtr>& subscriptions) | 
| 35 { | 33 { | 
| 36 int32_t count = static_cast<int32_t>(subscriptions.size()); | 34 int32_t count = static_cast<int32_t>(subscriptions.size()); | 
| 37 response << count; | 35 response << count; | 
| 38 for (int32_t i = 0; i < count; i++) | 36 for (int32_t i = 0; i < count; i++) | 
| 39 { | 37 { | 
| 40 AdblockPlus::SubscriptionPtr subscription = subscriptions[i]; | 38 AdblockPlus::SubscriptionPtr subscription = subscriptions[i]; | 
| 41 response << subscription->GetProperty("url")->AsString() | 39 response << subscription->GetProperty("url")->AsString() | 
| 42 << subscription->GetProperty("title")->AsString() | 40 << subscription->GetProperty("title")->AsString() | 
| 43 << subscription->GetProperty("specialization")->AsString() | 41 << subscription->GetProperty("specialization")->AsString() | 
| 44 << subscription->IsListed(); | 42 << subscription->IsListed(); | 
| 45 } | 43 } | 
| 46 } | 44 } | 
| 47 | 45 | 
| 48 bool updateAvailable; | 46 bool updateAvailable; | 
| 49 volatile bool checkingForUpdate = false; | |
| 50 void UpdateCallback(const std::string res) | 47 void UpdateCallback(const std::string res) | 
| 51 { | 48 { | 
| 52 checkingForUpdate = false; | |
| 53 if (updateAvailable) | 49 if (updateAvailable) | 
| 54 { | |
| 55 if (callbackWindow != 0) | |
| 56 { | |
| 57 SendMessage(callbackWindow, WM_DOWNLOADING_UPDATE, 0, 0); | |
| 58 callbackWindow = 0; | |
| 59 } | |
| 60 return; | 50 return; | 
| 61 } | |
| 62 Dictionary* dictionary = Dictionary::GetInstance(); | 51 Dictionary* dictionary = Dictionary::GetInstance(); | 
| 63 if (res.length() == 0) | 52 if (res.length() == 0) | 
| 64 { | 53 { | 
| 65 if (callbackWindow != 0) | 54 std::wstring upToDateText = dictionary->Lookup("updater", "update-already- up-to-date-text"); | 
| 66 { | 55 std::wstring upToDateTitle = dictionary->Lookup("updater", "update-already -up-to-date-title"); | 
| 67 SendMessage(callbackWindow, WM_ALREADY_UP_TO_DATE, 0, 0); | 56 MessageBoxW(NULL, upToDateText.c_str(), upToDateTitle.c_str(), MB_OK); | 
| 68 } | |
| 69 } | 57 } | 
| 70 else | 58 else | 
| 71 { | 59 { | 
| 72 if (callbackWindow != 0) | 60 std::wstring errorText = dictionary->Lookup("updater", "update-error-text" ); | 
| 73 { | 61 std::wstring errorTitle = dictionary->Lookup("updater", "update-error-titl e"); | 
| 74 SendMessage(callbackWindow, WM_UPDATE_CHECK_ERROR, 0, 0); | 62 ReplaceString(errorText, L"?1?", ToUtf16String(res)); | 
| 75 } | 63 MessageBoxW(NULL, errorText.c_str(), errorTitle.c_str(), MB_OK); | 
| 76 } | 64 } | 
| 77 callbackWindow = 0; | |
| 78 return; | 65 return; | 
| 79 } | 66 } | 
| 80 | 67 | 
| 81 | 68 | 
| 82 CriticalSection firstRunLock; | 69 CriticalSection firstRunLock; | 
| 83 bool firstRunActionExecuted = false; | 70 bool firstRunActionExecuted = false; | 
| 84 Communication::OutputBuffer HandleRequest(Communication::InputBuffer& request) | 71 Communication::OutputBuffer HandleRequest(Communication::InputBuffer& request) | 
| 85 { | 72 { | 
| 86 Communication::OutputBuffer response; | 73 Communication::OutputBuffer response; | 
| 87 | 74 | 
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 249 } | 236 } | 
| 250 else | 237 else | 
| 251 { | 238 { | 
| 252 // Report failure | 239 // Report failure | 
| 253 response << false; | 240 response << false; | 
| 254 } | 241 } | 
| 255 break; | 242 break; | 
| 256 } | 243 } | 
| 257 case Communication::PROC_CHECK_FOR_UPDATES: | 244 case Communication::PROC_CHECK_FOR_UPDATES: | 
| 258 { | 245 { | 
| 259 request >> (int32_t&)callbackWindow; | |
| 260 updateAvailable = false; | 246 updateAvailable = false; | 
| 261 if (!checkingForUpdate) | 247 filterEngine->ForceUpdateCheck(UpdateCallback); | 
| 262 { | |
| 263 checkingForUpdate = true; | |
| 264 filterEngine->ForceUpdateCheck(UpdateCallback); | |
| 265 } | |
| 266 break; | 248 break; | 
| 267 } | 249 } | 
| 268 case Communication::PROC_IS_FIRST_RUN_ACTION_NEEDED: | 250 case Communication::PROC_IS_FIRST_RUN_ACTION_NEEDED: | 
| 269 { | 251 { | 
| 270 CriticalSection::Lock lock(firstRunLock); | 252 CriticalSection::Lock lock(firstRunLock); | 
| 271 if (!firstRunActionExecuted && filterEngine->IsFirstRun()) | 253 if (!firstRunActionExecuted && filterEngine->IsFirstRun()) | 
| 272 { | 254 { | 
| 273 response << true; | 255 response << true; | 
| 274 firstRunActionExecuted = true; | 256 firstRunActionExecuted = true; | 
| 275 } | 257 } | 
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 376 #endif | 358 #endif | 
| 377 | 359 | 
| 378 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::New(appInfo); | 360 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::New(appInfo); | 
| 379 jsEngine->SetEventCallback("updateAvailable", &OnUpdateAvailable); | 361 jsEngine->SetEventCallback("updateAvailable", &OnUpdateAvailable); | 
| 380 | 362 | 
| 381 std::string dataPath = ToUtf8String(GetAppDataPath()); | 363 std::string dataPath = ToUtf8String(GetAppDataPath()); | 
| 382 dynamic_cast<AdblockPlus::DefaultFileSystem*>(jsEngine->GetFileSystem().get()) ->SetBasePath(dataPath); | 364 dynamic_cast<AdblockPlus::DefaultFileSystem*>(jsEngine->GetFileSystem().get()) ->SetBasePath(dataPath); | 
| 383 std::auto_ptr<AdblockPlus::FilterEngine> filterEngine(new AdblockPlus::FilterE ngine(jsEngine)); | 365 std::auto_ptr<AdblockPlus::FilterEngine> filterEngine(new AdblockPlus::FilterE ngine(jsEngine)); | 
| 384 return filterEngine; | 366 return filterEngine; | 
| 385 } | 367 } | 
| 386 | 368 | 
| 
Felix Dahlke
2013/09/16 16:30:12
Why this extra whitespace?
 | |
| 387 | |
| 388 | |
| 389 int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) | 369 int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) | 
| 390 { | 370 { | 
| 391 AutoHandle mutex(CreateMutexW(0, false, L"AdblockPlusEngine")); | 371 AutoHandle mutex(CreateMutexW(0, false, L"AdblockPlusEngine")); | 
| 392 if (!mutex) | 372 if (!mutex) | 
| 393 { | 373 { | 
| 394 DebugLastError("CreateMutex failed"); | 374 DebugLastError("CreateMutex failed"); | 
| 395 return 1; | 375 return 1; | 
| 396 } | 376 } | 
| 397 | 377 | 
| 398 if (GetLastError() == ERROR_ALREADY_EXISTS) | 378 if (GetLastError() == ERROR_ALREADY_EXISTS) | 
| 399 { | 379 { | 
| 400 DebugLastError("Named pipe exists, another engine instance appears to be run ning"); | 380 DebugLastError("Named pipe exists, another engine instance appears to be run ning"); | 
| 401 return 1; | 381 return 1; | 
| 402 } | 382 } | 
| 403 | 383 | 
| 404 int argc; | 384 int argc; | 
| 405 LPWSTR* argv = CommandLineToArgvW(GetCommandLineW(), &argc); | 385 LPWSTR* argv = CommandLineToArgvW(GetCommandLineW(), &argc); | 
| 406 std::wstring locale(argc >= 2 ? argv[1] : L""); | 386 std::wstring locale(argc >= 2 ? argv[1] : L""); | 
| 407 Communication::browserSID = argv[2]; | 387 Communication::browserSID = argc >= 3 ? argv[2] : L""; | 
| 
Wladimir Palant
2013/09/16 13:45:07
This will cause a crash if too few parameters are
 
Felix Dahlke
2013/09/16 16:30:12
What if argc is <3?
 
Oleksandr
2013/09/17 03:11:37
<3. Teehee :)
 | |
| 408 LocalFree(argv); | 388 LocalFree(argv); | 
| 409 Dictionary::Create(locale); | 389 Dictionary::Create(locale); | 
| 410 filterEngine = CreateFilterEngine(locale); | 390 filterEngine = CreateFilterEngine(locale); | 
| 411 updater.reset(new Updater(filterEngine->GetJsEngine())); | 391 updater.reset(new Updater(filterEngine->GetJsEngine())); | 
| 412 | 392 | 
| 413 for (;;) | 393 for (;;) | 
| 414 { | 394 { | 
| 415 try | 395 try | 
| 416 { | 396 { | 
| 417 Communication::Pipe* pipe = new Communication::Pipe(Communication::pipeNam e, | 397 Communication::Pipe* pipe = new Communication::Pipe(Communication::pipeNam e, | 
| 418 Communication::Pipe::MODE_CREATE); | 398 Communication::Pipe::MODE_CREATE); | 
| 419 | 399 | 
| 420 AutoHandle thread(CreateThread(0, 0, ClientThread, static_cast<LPVOID>(pip e), 0, 0)); | 400 AutoHandle thread(CreateThread(0, 0, ClientThread, static_cast<LPVOID>(pip e), 0, 0)); | 
| 421 if (!thread) | 401 if (!thread) | 
| 422 { | 402 { | 
| 423 delete pipe; | 403 delete pipe; | 
| 424 DebugLastError("CreateThread failed"); | 404 DebugLastError("CreateThread failed"); | 
| 425 return 1; | 405 return 1; | 
| 426 } | 406 } | 
| 427 } | 407 } | 
| 428 catch (std::runtime_error e) | 408 catch (std::runtime_error e) | 
| 429 { | 409 { | 
| 430 DebugException(e); | 410 DebugException(e); | 
| 431 return 1; | 411 return 1; | 
| 432 } | 412 } | 
| 433 } | 413 } | 
| 434 | 414 | 
| 435 return 0; | 415 return 0; | 
| 436 } | 416 } | 
| LEFT | RIGHT |