| 417 | } |
| 418 | |
| 419 | unsigned int WINAPI AsyncScriptExecutor::ThreadProc(LPVOID lpParameter) { |
| 420 | LOG(TRACE) << "Entering AsyncScriptExecutor::ThreadProc"; |
| 421 | |
| 422 | AsyncScriptExecutorThreadContext* thread_context = reinterpret_cast<AsyncScriptExecutorThreadContext*>(lpParameter); |
| 423 | HWND window_handle = thread_context->hwnd; |
| 424 | |
| 425 | DWORD error = 0; |
| 426 | HRESULT hr = ::CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); |
| 427 | if (FAILED(hr)) { |
| 428 | LOGHR(DEBUG, hr) << "COM library initialization has some problem"; |
| 429 | } |
| 430 | |
| 431 | AsyncScriptExecutor async_executor; |
| 432 | HWND async_executor_window_handle = async_executor.Create(/*HWND*/ HWND_MESSAGE, |
| 433 | /*_U_RECT rect*/ CWindow::rcDefault, |
| 434 | /*LPCTSTR szWindowName*/ NULL, |
| 435 | /*DWORD dwStyle*/ NULL, |
| 436 | /*DWORD dwExStyle*/ NULL, |
| 437 | /*_U_MENUorID MenuOrID*/ 0U, |
| 438 | /*LPVOID lpCreateParam*/ reinterpret_cast<LPVOID*>(thread_context)); |
| 439 | if (async_executor_window_handle == NULL) { |
| 440 | LOGERR(WARN) << "Unable to create new AsyncScriptExecutor"; |
| 441 | } |
| 442 | |
| 443 | MSG msg; |
| 444 | ::PeekMessage(&msg, NULL, WM_USER, WM_USER, PM_NOREMOVE); |
| 445 | |
| 446 | // Return the HWND back through lpParameter, and signal that the |
| 447 | // window is ready for messages. |
| 448 | thread_context->hwnd = async_executor_window_handle; |
| 449 | HANDLE event_handle = ::OpenEvent(EVENT_ALL_ACCESS, |
| 450 | FALSE, |
| 451 | ASYNC_SCRIPT_EVENT_NAME); |
| 452 | if (event_handle != NULL) { |
| 453 | ::SetEvent(event_handle); |
| 454 | ::CloseHandle(event_handle); |
| 455 | } else { |
| 456 | LOGERR(DEBUG) << "Unable to signal that window is ready"; |
| 457 | } |
| 458 | |
| 459 | // Run the message loop |
| 460 | while (::GetMessage(&msg, NULL, 0, 0) > 0) { |
| 461 | ::TranslateMessage(&msg); |
| 462 | ::DispatchMessage(&msg); |
| 463 | } |
| 464 | |
| 465 | ::CoUninitialize(); |
| 466 | return 0; |
| 467 | } |
| 468 | |
| 469 | } // namespace webdriver |