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

Method OnBrowserCloseWait

cpp/iedriver/IECommandExecutor.cpp:421–477  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

419}
420
421LRESULT IECommandExecutor::OnBrowserCloseWait(UINT uMsg,
422 WPARAM wParam,
423 LPARAM lParam,
424 BOOL& bHandled) {
425 LOG(TRACE) << "Entering IECommandExecutor::OnBrowserCloseWait";
426
427 LPCSTR str = reinterpret_cast<LPCSTR>(lParam);
428 std::string browser_id(str);
429 delete[] str;
430 BrowserMap::iterator found_iterator = this->managed_browsers_.find(browser_id);
431 if (found_iterator != this->managed_browsers_.end()) {
432 HWND alert_handle;
433 bool is_alert_active = this->IsAlertActive(found_iterator->second,
434 &alert_handle);
435 if (is_alert_active) {
436 // If there's an alert window active, the browser's Quit event does
437 // not fire until any alerts are handled. Note that OnBeforeUnload
438 // alerts must be handled here; the driver contains the ability to
439 // handle other standard alerts on the next received command. We rely
440 // on the browser's Quit command to remove the driver from the list of
441 // managed browsers.
442 Alert dialog(found_iterator->second, alert_handle);
443 if (!dialog.is_standard_alert()) {
444 dialog.Accept();
445 is_alert_active = false;
446 }
447 }
448 if (!is_alert_active) {
449 ::Sleep(100);
450 // If no alert is present, repost the message to the message pump, so
451 // that we can wait until the browser is fully closed to return the
452 // proper still-open list of window handles.
453 LPSTR message_payload = new CHAR[browser_id.size() + 1];
454 strcpy_s(message_payload, browser_id.size() + 1, browser_id.c_str());
455 ::PostMessage(this->m_hWnd,
456 WD_BROWSER_CLOSE_WAIT,
457 NULL,
458 reinterpret_cast<LPARAM>(message_payload));
459 return 0;
460 }
461 } else {
462 LOG(WARN) << "Unable to find browser to quit with ID " << browser_id;
463 }
464 Json::Value handles(Json::arrayValue);
465 std::vector<std::string> handle_list;
466 this->GetManagedBrowserHandles(&handle_list);
467 std::vector<std::string>::const_iterator handle_iterator = handle_list.begin();
468 for (; handle_iterator != handle_list.end(); ++handle_iterator) {
469 handles.append(*handle_iterator);
470 }
471
472 Response close_window_response;
473 close_window_response.SetSuccessResponse(handles);
474 this->serialized_response_ = close_window_response.Serialize();
475 this->is_waiting_ = false;
476 return 0;
477}
478

Callers

nothing calls this directly

Calls 11

IsAlertActiveMethod · 0.95
findMethod · 0.80
endMethod · 0.80
is_standard_alertMethod · 0.80
SetSuccessResponseMethod · 0.80
LOGClass · 0.50
AcceptMethod · 0.45
sizeMethod · 0.45
appendMethod · 0.45
SerializeMethod · 0.45

Tested by

no test coverage detected