void IESession::Initialize(void* init_params) { LOG(TRACE) << "Entering IESession::Initialize"; unsigned int thread_id = 0; HWND executor_window_handle = NULL; HANDLE event_handle = ::CreateEvent(NULL, TRUE, FALSE, EVENT_NAME); HANDLE thread_handle = reinterpret_cast<HANDLE>(_beginthreadex(NULL, 0, &IECommandExecutor::ThreadProc, reinterpret_cast<void*>(&executor_window_handle), 0, &thread_id)); if (event_handle != NULL) { ::WaitForSingleObject(event_handle, INFINITE); ::CloseHandle(event_handle); } if (thread_handle != NULL) { ::CloseHandle(thread_handle); } int* int_param = reinterpret_cast<int*>(init_params); int port = *int_param; ::SendMessage(executor_window_handle, WD_INIT, static_cast<WPARAM>(port), NULL); vector<TCHAR> window_text_buffer(37); ::GetWindowText(executor_window_handle, &window_text_buffer[0], 37); std::string session_id = CW2A(&window_text_buffer[0], CP_UTF8); this->executor_window_handle_ = executor_window_handle; this->set_session_id(session_id); }
std::wstring IEDriverServer::CreateSession() { unsigned int thread_id; HWND manager_window_handle = NULL; HANDLE event_handle = ::CreateEvent(NULL, TRUE, FALSE, EVENT_NAME); HANDLE thread_handle = reinterpret_cast<HANDLE>(_beginthreadex(NULL, 0, &BrowserManager::ThreadProc, (void *)&manager_window_handle, 0, &thread_id)); if (event_handle != NULL) { ::WaitForSingleObject(event_handle, INFINITE); ::CloseHandle(event_handle); } if (thread_handle != NULL) { ::CloseHandle(thread_handle); } ::SendMessage(manager_window_handle, WD_INIT, (WPARAM)this->port_, NULL); vector<TCHAR> window_text_buffer(37); ::GetWindowText(manager_window_handle, &window_text_buffer[0], 37); std::wstring manager_id = &window_text_buffer[0]; this->sessions_[manager_id] = manager_window_handle; return manager_id; }
void IESession::Initialize(void* init_params) { LOG(TRACE) << "Entering IESession::Initialize"; unsigned int thread_id = 0; HWND executor_window_handle = NULL; HANDLE mutex = ::CreateMutex(NULL, FALSE, MUTEX_NAME); if (mutex != NULL) { // Wait for up to the timeout (currently 30 seconds) for other sessions // to completely initialize. DWORD mutex_wait_status = ::WaitForSingleObject(mutex, MUTEX_WAIT_TIMEOUT); if (mutex_wait_status == WAIT_ABANDONED) { LOG(WARN) << "Acquired mutex, but received wait abandoned status. This " << "could mean the process previously owning the mutex was " << "unexpectedly terminated."; } else if (mutex_wait_status == WAIT_TIMEOUT) { LOG(WARN) << "Could not acquire mutex within the timeout. Multiple " << "instances may hang or behave unpredictably"; } else if (mutex_wait_status == WAIT_OBJECT_0) { LOG(DEBUG) << "Mutex acquired for session initalization"; } } else { LOG(WARN) << "Could not create session initialization mutex. Multiple " << "instances will behave unpredictably."; } HANDLE event_handle = ::CreateEvent(NULL, TRUE, FALSE, EVENT_NAME); HANDLE thread_handle = reinterpret_cast<HANDLE>(_beginthreadex(NULL, 0, &IECommandExecutor::ThreadProc, reinterpret_cast<void*>(&executor_window_handle), 0, &thread_id)); if (event_handle != NULL) { ::WaitForSingleObject(event_handle, INFINITE); ::CloseHandle(event_handle); } if (thread_handle != NULL) { ::CloseHandle(thread_handle); } int* int_param = reinterpret_cast<int*>(init_params); int port = *int_param; ::SendMessage(executor_window_handle, WD_INIT, static_cast<WPARAM>(port), NULL); vector<TCHAR> window_text_buffer(37); ::GetWindowText(executor_window_handle, &window_text_buffer[0], 37); std::string session_id = CW2A(&window_text_buffer[0], CP_UTF8); if (mutex != NULL) { LOG(DEBUG) << "Releasing session initialization mutex"; ::ReleaseMutex(mutex); ::CloseHandle(mutex); } this->executor_window_handle_ = executor_window_handle; this->set_session_id(session_id); }
void IESession::Initialize(void* init_params) { LOG(TRACE) << "Entering IESession::Initialize"; HANDLE mutex = ::CreateMutex(NULL, FALSE, MUTEX_NAME); if (mutex != NULL) { // Wait for up to the timeout (currently 30 seconds) for other sessions // to completely initialize. DWORD mutex_wait_status = ::WaitForSingleObject(mutex, MUTEX_WAIT_TIMEOUT); if (mutex_wait_status == WAIT_ABANDONED) { LOG(WARN) << "Acquired mutex, but received wait abandoned status. This " << "could mean the process previously owning the mutex was " << "unexpectedly terminated."; } else if (mutex_wait_status == WAIT_TIMEOUT) { LOG(WARN) << "Could not acquire mutex within the timeout. Multiple " << "instances may hang or behave unpredictably"; } else if (mutex_wait_status == WAIT_OBJECT_0) { LOG(DEBUG) << "Mutex acquired for session initalization"; } else if (mutex_wait_status == WAIT_FAILED) { LOGERR(WARN) << "Mutex acquire waiting is failed"; } } else { LOGERR(WARN) << "Could not create session initialization mutex. Multiple " << "instances will behave unpredictably. "; } SessionParameters* params = reinterpret_cast<SessionParameters*>(init_params); int port = params->port; this->driver_implementation_ = params->implementation; IECommandExecutorThreadContext thread_context; thread_context.port = port; thread_context.hwnd = NULL; unsigned int thread_id = 0; HANDLE event_handle = ::CreateEvent(NULL, TRUE, FALSE, EVENT_NAME); if (event_handle == NULL) { LOGERR(DEBUG) << "Unable to create event " << EVENT_NAME; } ThreadProcedure thread_proc = &IECommandExecutor::ThreadProc; if (this->driver_implementation_ != LegacyImplementation) { BrowserFactory factory; int browser_version = factory.browser_version(); bool is_component_registered = IEWebDriverManagerCommandExecutor::IsComponentRegistered(); if (this->driver_implementation_ == VendorImplementation) { LOG(DEBUG) << "Attempting to use vendor-provided driver implementation per user request"; thread_proc = &IEWebDriverManagerCommandExecutor::ThreadProc; } else if (this->driver_implementation_ == AutoDetectImplementation && browser_version >= 11 && is_component_registered) { LOG(DEBUG) << "Using vendor-provided driver implementation per autodetection"; thread_proc = &IEWebDriverManagerCommandExecutor::ThreadProc; } else { LOG(DEBUG) << "Falling back to legacy driver implementation per autodetection (" << "detected IE version: " << browser_version << ", vendor driver install is " << (is_component_registered ? "" : "not") << " registered)."; } } else { LOG(DEBUG) << "Using legacy driver implementation per user request"; } HANDLE thread_handle = reinterpret_cast<HANDLE>(_beginthreadex(NULL, 0, thread_proc, reinterpret_cast<void*>(&thread_context), 0, &thread_id)); if (event_handle != NULL) { DWORD thread_wait_status = ::WaitForSingleObject(event_handle, THREAD_WAIT_TIMEOUT); if (thread_wait_status != WAIT_OBJECT_0) { LOGERR(WARN) << "Unable to wait until created thread notification: '" << thread_wait_status << "'."; } ::CloseHandle(event_handle); } if (thread_handle != NULL) { ::CloseHandle(thread_handle); } else { LOG(DEBUG) << "Unable to create thread for command executor"; } std::string session_id = ""; if (thread_context.hwnd != NULL) { LOG(TRACE) << "Created thread for command executor returns HWND: '" << thread_context.hwnd << "'"; std::vector<wchar_t> window_text_buffer(37); ::GetWindowText(thread_context.hwnd, &window_text_buffer[0], 37); session_id = StringUtilities::ToString(&window_text_buffer[0]); LOG(TRACE) << "Session id is retrived from command executor window: '" << session_id << "'"; } else { LOG(DEBUG) << "Created thread does not return HWND of created session"; } if (mutex != NULL) { LOG(DEBUG) << "Releasing session initialization mutex"; ::ReleaseMutex(mutex); ::CloseHandle(mutex); } this->executor_window_handle_ = thread_context.hwnd; this->set_session_id(session_id); }
void IESession::Initialize(void* init_params) { LOG(TRACE) << "Entering IESession::Initialize"; HANDLE mutex = ::CreateMutex(NULL, FALSE, MUTEX_NAME); if (mutex != NULL) { // Wait for up to the timeout (currently 30 seconds) for other sessions // to completely initialize. DWORD mutex_wait_status = ::WaitForSingleObject(mutex, MUTEX_WAIT_TIMEOUT); if (mutex_wait_status == WAIT_ABANDONED) { LOG(WARN) << "Acquired mutex, but received wait abandoned status. This " << "could mean the process previously owning the mutex was " << "unexpectedly terminated."; } else if (mutex_wait_status == WAIT_TIMEOUT) { LOG(WARN) << "Could not acquire mutex within the timeout. Multiple " << "instances may hang or behave unpredictably"; } else if (mutex_wait_status == WAIT_OBJECT_0) { LOG(DEBUG) << "Mutex acquired for session initalization"; } else if (mutex_wait_status == WAIT_FAILED) { LOGERR(WARN) << "Mutex acquire waiting is failed"; } } else { LOGERR(WARN) << "Could not create session initialization mutex. Multiple " << "instances will behave unpredictably. "; } SessionParameters* params = reinterpret_cast<SessionParameters*>(init_params); int port = params->port; IECommandExecutorThreadContext thread_context; thread_context.port = port; thread_context.hwnd = NULL; unsigned int thread_id = 0; HANDLE event_handle = ::CreateEvent(NULL, TRUE, FALSE, EVENT_NAME); if (event_handle == NULL) { LOGERR(DEBUG) << "Unable to create event " << EVENT_NAME; } HANDLE thread_handle = reinterpret_cast<HANDLE>(_beginthreadex(NULL, 0, &IECommandExecutor::ThreadProc, reinterpret_cast<void*>(&thread_context), 0, &thread_id)); if (event_handle != NULL) { DWORD thread_wait_status = ::WaitForSingleObject(event_handle, THREAD_WAIT_TIMEOUT); if (thread_wait_status != WAIT_OBJECT_0) { LOGERR(WARN) << "Unable to wait until created thread notification: '" << thread_wait_status << "'."; } ::CloseHandle(event_handle); } if (thread_handle != NULL) { ::CloseHandle(thread_handle); } else { LOG(DEBUG) << "Unable to create thread for command executor"; } std::string session_id = ""; if (thread_context.hwnd != NULL) { LOG(TRACE) << "Created thread for command executor returns HWND: '" << thread_context.hwnd << "'"; // Send INIT to window with port as WPARAM // It is already deprecated ::SendMessage(thread_context.hwnd, WD_INIT, static_cast<WPARAM>(port), NULL); std::vector<wchar_t> window_text_buffer(37); ::GetWindowText(thread_context.hwnd, &window_text_buffer[0], 37); session_id = StringUtilities::ToString(&window_text_buffer[0]); LOG(TRACE) << "Session id is retrived from command executor window: '" << session_id << "'"; } else { LOG(DEBUG) << "Created thread does not return HWND of created session"; } if (mutex != NULL) { LOG(DEBUG) << "Releasing session initialization mutex"; ::ReleaseMutex(mutex); ::CloseHandle(mutex); } this->executor_window_handle_ = thread_context.hwnd; this->set_session_id(session_id); }