MCPcopy Create free account
hub / github.com/SeleniumHQ/selenium / ThreadProc

Method ThreadProc

cpp/iedriver/IECommandExecutor.cpp:921–991  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

919}
920
921unsigned int WINAPI IECommandExecutor::ThreadProc(LPVOID lpParameter) {
922 LOG(TRACE) << "Entering IECommandExecutor::ThreadProc";
923
924 IECommandExecutorThreadContext* thread_context = reinterpret_cast<IECommandExecutorThreadContext*>(lpParameter);
925 HWND window_handle = thread_context->hwnd;
926
927 // it is better to use IECommandExecutorSessionContext instead
928 // but use ThreadContext for code minimization
929 IECommandExecutorThreadContext* session_context = new IECommandExecutorThreadContext();
930 session_context->port = thread_context->port;
931
932 DWORD error = 0;
933 HRESULT hr = ::CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
934 if (FAILED(hr)) {
935 LOGHR(DEBUG, hr) << "COM library initialization encountered an error";
936 }
937
938 IECommandExecutor new_session;
939 HWND session_window_handle = new_session.Create(/*HWND*/ HWND_MESSAGE,
940 /*_U_RECT rect*/ CWindow::rcDefault,
941 /*LPCTSTR szWindowName*/ NULL,
942 /*DWORD dwStyle*/ NULL,
943 /*DWORD dwExStyle*/ NULL,
944 /*_U_MENUorID MenuOrID*/ 0U,
945 /*LPVOID lpCreateParam*/ reinterpret_cast<LPVOID*>(session_context));
946 if (session_window_handle == NULL) {
947 LOGERR(WARN) << "Unable to create new IECommandExecutor session";
948 }
949
950 MSG msg;
951 ::PeekMessage(&msg, NULL, WM_USER, WM_USER, PM_NOREMOVE);
952
953 // Return the HWND back through lpParameter, and signal that the
954 // window is ready for messages.
955 thread_context->hwnd = session_window_handle;
956 HANDLE event_handle = ::OpenEvent(EVENT_ALL_ACCESS, FALSE, WEBDRIVER_START_EVENT_NAME);
957 if (event_handle != NULL) {
958 ::SetEvent(event_handle);
959 ::CloseHandle(event_handle);
960 } else {
961 LOGERR(DEBUG) << "Unable to signal that window is ready";
962 }
963
964 // Run the message loop
965 BOOL get_message_return_value;
966 while ((get_message_return_value = ::GetMessage(&msg, NULL, 0, 0)) != 0) {
967 if (get_message_return_value == -1) {
968 LOGERR(WARN) << "Windows GetMessage() API returned error";
969 break;
970 } else {
971 if (msg.message == WD_SHUTDOWN) {
972 LOG(DEBUG) << "Shutdown message received";
973 new_session.DestroyWindow();
974 LOG(DEBUG) << "Returned from DestroyWindow()";
975 break;
976 } else {
977 // We need to lock this mutex here to make sure only one thread is processing
978 // win32 messages at a time.

Callers

nothing calls this directly

Calls 2

LOGClass · 0.50
CreateMethod · 0.45

Tested by

no test coverage detected