BOOL CALLBACK HtmlDialog::FindChildDialogWindow(HWND hwnd, LPARAM arg) { DialogWindowInfo* window_info = reinterpret_cast<DialogWindowInfo*>(arg); if (::GetWindow(hwnd, GW_OWNER) != window_info->hwndOwner) { return TRUE; } std::vector<char> window_class_name(34); if (::GetClassNameA(hwnd, &window_class_name[0], 34) == 0) { // No match found. Skip return TRUE; } if (strcmp(ALERT_WINDOW_CLASS, &window_class_name[0]) != 0 && strcmp(HTML_DIALOG_WINDOW_CLASS, &window_class_name[0]) != 0) { return TRUE; } else { // If the window style has the WS_DISABLED bit set or the // WS_VISIBLE bit unset, it can't be handled via the UI, // and must not be a visible dialog. if ((::GetWindowLong(hwnd, GWL_STYLE) & WS_DISABLED) != 0 || (::GetWindowLong(hwnd, GWL_STYLE) & WS_VISIBLE) == 0) { return TRUE; } } window_info->hwndDialog = hwnd; return FALSE; }
HWND HtmlDialog::GetActiveDialogWindowHandle() { LOG(TRACE) << "Entering HtmlDialog::GetActiveDialogWindowHandle"; DialogWindowInfo info; info.hwndOwner = this->GetTopLevelWindowHandle(); info.hwndDialog = NULL; if (info.hwndOwner != NULL) { ::EnumWindows(&HtmlDialog::FindChildDialogWindow, reinterpret_cast<LPARAM>(&info)); } if (info.hwndDialog != NULL) { std::vector<char> window_class_name(34); if (::GetClassNameA(info.hwndDialog, &window_class_name[0], 34)) { if (strcmp(HTML_DIALOG_WINDOW_CLASS, &window_class_name[0]) == 0) { HWND content_window_handle = this->FindContentWindowHandle(info.hwndDialog); if (content_window_handle != NULL) { // Must have a sleep here to give IE a chance to draw the window. ::Sleep(250); ::PostMessage(this->executor_handle(), WD_NEW_HTML_DIALOG, NULL, reinterpret_cast<LPARAM>(content_window_handle)); } } } } return info.hwndDialog; }
void Browser::CheckDialogType(HWND dialog_window_handle) { vector<char> window_class_name(34); if (GetClassNameA(dialog_window_handle, &window_class_name[0], 34)) { if (strcmp("Internet Explorer_TridentDlgFrame", &window_class_name[0]) == 0) { HWND content_window_handle = this->FindContentWindowHandle(dialog_window_handle); ::PostMessage(this->session_handle(), WD_NEW_HTML_DIALOG, NULL, reinterpret_cast<LPARAM>(content_window_handle)); } } }
//____________________________________________________________________ Configuration Factory::configuration( const Client& client ) { QString window_title; QString class_name; for( ExceptionList::const_iterator iter = _exceptions.constBegin(); iter != _exceptions.constEnd(); ++iter ) { // discard disabled exceptions if( !iter->enabled() ) continue; /* decide which value is to be compared to the regular expression, based on exception type */ QString value; switch( iter->type() ) { case Exception::WindowTitle: { value = window_title.isEmpty() ? (window_title = client.caption()):window_title; break; } case Exception::WindowClassName: { if( class_name.isEmpty() ) { // retrieve class name KWindowInfo info( client.windowId(), 0, NET::WM2WindowClass ); QString window_class_name( info.windowClassName() ); QString window_class( info.windowClassClass() ); class_name = window_class_name + ' ' + window_class; } value = class_name; break; } default: assert( false ); } if( iter->regExp().indexIn( value ) < 0 ) continue; Configuration configuration( defaultConfiguration() ); configuration.readException( *iter ); configuration.setTransparencyEnabled( iter->transparencyEnabled() ); return configuration; } return defaultConfiguration(); }
void IECommandExecutor::DispatchCommand() { Response response(this->session_id_); CommandHandlerMap::const_iterator found_iterator = this->command_handlers_.find(this->current_command_.command_type()); if (found_iterator == this->command_handlers_.end()) { response.SetErrorResponse(501, "Command not implemented"); } else { BrowserHandle browser; int status_code = this->GetCurrentBrowser(&browser); if (status_code == SUCCESS) { bool alert_is_active = false; HWND alert_handle = browser->GetActiveDialogWindowHandle(); if (alert_handle != NULL) { // Found a window handle, make sure it's an actual alert, // and not a showModalDialog() window. vector<char> window_class_name(34); ::GetClassNameA(alert_handle, &window_class_name[0], 34); if (strcmp("#32770", &window_class_name[0]) == 0) { alert_is_active = true; } } int command_type = this->current_command_.command_type(); if (alert_is_active && command_type != GetAlertText && command_type != SendKeysToAlert && command_type != AcceptAlert && command_type != DismissAlert) { response.SetErrorResponse(EMODALDIALOGOPENED, "Modal dialog present"); ::SendMessage(alert_handle, WM_COMMAND, IDCANCEL, NULL); this->serialized_response_ = response.Serialize(); return; } } CommandHandlerHandle command_handler = found_iterator->second; command_handler->Execute(*this, this->current_command_, &response); status_code = this->GetCurrentBrowser(&browser); if (status_code == SUCCESS) { this->is_waiting_ = browser->wait_required(); if (this->is_waiting_) { ::PostMessage(this->m_hWnd, WD_WAIT, NULL, NULL); } } } this->serialized_response_ = response.Serialize(); }
void Browser::CheckDialogType(HWND dialog_window_handle) { LOG(TRACE) << "Entering Browser::CheckDialogType"; std::vector<char> window_class_name(34); if (GetClassNameA(dialog_window_handle, &window_class_name[0], 34)) { if (strcmp(HTML_DIALOG_WINDOW_CLASS, &window_class_name[0]) == 0) { HWND content_window_handle = this->FindContentWindowHandle(dialog_window_handle); ::PostMessage(this->executor_handle(), WD_NEW_HTML_DIALOG, NULL, reinterpret_cast<LPARAM>(content_window_handle)); } } }
bool HtmlDialog::Wait() { // If the window handle is no longer valid, the window is closing, // the wait is completed, and we must post the quit message. if (!this->is_closing() && !::IsWindow(this->GetTopLevelWindowHandle())) { this->is_navigating_ = false; this->DetachEvents(); this->PostQuitMessage(); return true; } // If we're not navigating to a new location, we should check to see if // a new modal dialog or alert has been opened. If one has, the wait is complete, // so we must set the flag indicating to the message loop not to call wait // anymore. if (!this->is_navigating_) { HWND child_dialog_handle = this->GetActiveDialogWindowHandle(); if (child_dialog_handle != NULL) { // Check to see if the dialog opened is another HTML dialog. If so, // notify the IECommandExecutor that a new window exists. std::vector<char> window_class_name(34); if (::GetClassNameA(child_dialog_handle, &window_class_name[0], 34)) { if (strcmp(HTML_DIALOG_WINDOW_CLASS, &window_class_name[0]) == 0) { HWND content_window_handle = this->FindContentWindowHandle(child_dialog_handle); if (content_window_handle != NULL) { // Must have a sleep here to give IE a chance to draw the window. ::Sleep(250); ::PostMessage(this->executor_handle(), WD_NEW_HTML_DIALOG, NULL, reinterpret_cast<LPARAM>(content_window_handle)); } } } this->set_wait_required(false); return true; } } // Otherwise, we wait until navigation is complete. ::Sleep(250); return !this->is_navigating_; }
void IECommandExecutor::DispatchCommand() { LOG(TRACE) << "Entering IECommandExecutor::DispatchCommand"; Response response(this->session_id_); CommandHandlerMap::const_iterator found_iterator = this->command_handlers_.find(this->current_command_.command_type()); if (found_iterator == this->command_handlers_.end()) { LOG(WARN) << "Unable to find command handler for " << this->current_command_.command_type(); response.SetErrorResponse(501, "Command not implemented"); } else { BrowserHandle browser; int status_code = WD_SUCCESS; if (this->current_command_.command_type() != webdriver::CommandType::NewSession) { // There should never be a modal dialog or alert to check for if the command // is the "newSession" command. status_code = this->GetCurrentBrowser(&browser); if (status_code == WD_SUCCESS) { bool alert_is_active = false; HWND alert_handle = browser->GetActiveDialogWindowHandle(); if (alert_handle != NULL) { // Found a window handle, make sure it's an actual alert, // and not a showModalDialog() window. vector<char> window_class_name(34); ::GetClassNameA(alert_handle, &window_class_name[0], 34); if (strcmp(ALERT_WINDOW_CLASS, &window_class_name[0]) == 0) { alert_is_active = true; } else { LOG(WARN) << "Found alert handle does not have a window class consistent with an alert"; } } else { LOG(DEBUG) << "No alert handle is found"; } if (alert_is_active) { Alert dialog(browser, alert_handle); std::string command_type = this->current_command_.command_type(); if (command_type == webdriver::CommandType::GetAlertText || command_type == webdriver::CommandType::SendKeysToAlert || command_type == webdriver::CommandType::AcceptAlert || command_type == webdriver::CommandType::DismissAlert) { LOG(DEBUG) << "Alert is detected, and the sent command is valid"; } else { LOG(DEBUG) << "Unexpected alert is detected, and the sent command is invalid when an alert is present"; std::string alert_text = dialog.GetText(); if (this->unexpected_alert_behavior_ == ACCEPT_UNEXPECTED_ALERTS) { LOG(DEBUG) << "Automatically accepting the alert"; dialog.Accept(); } else if (this->unexpected_alert_behavior_ == DISMISS_UNEXPECTED_ALERTS || command_type == webdriver::CommandType::Quit) { // If a quit command was issued, we should not ignore an unhandled // alert, even if the alert behavior is set to "ignore". LOG(DEBUG) << "Automatically dismissing the alert"; if (dialog.is_standard_alert()) { dialog.Dismiss(); } else { // The dialog was non-standard. The most common case of this is // an onBeforeUnload dialog, which must be accepted to continue. dialog.Accept(); } } if (command_type != webdriver::CommandType::Quit) { // To keep pace with what Firefox does, we'll return the text of the // alert in the error response. Json::Value response_value; response_value["message"] = "Modal dialog present"; response_value["alert"]["text"] = alert_text; response.SetResponse(EMODALDIALOGOPENED, response_value); this->serialized_response_ = response.Serialize(); return; } else { LOG(DEBUG) << "Quit command was issued. Continuing with command after automatically closing alert."; } } } } else { LOG(WARN) << "Unable to find current browser"; } } CommandHandlerHandle command_handler = found_iterator->second; command_handler->Execute(*this, this->current_command_, &response); status_code = this->GetCurrentBrowser(&browser); if (status_code == WD_SUCCESS) { this->is_waiting_ = browser->wait_required(); if (this->is_waiting_) { if (this->page_load_timeout_ >= 0) { this->wait_timeout_ = clock() + (this->page_load_timeout_ / 1000 * CLOCKS_PER_SEC); } ::PostMessage(this->m_hWnd, WD_WAIT, NULL, NULL); } } else { if (this->current_command_.command_type() != webdriver::CommandType::Quit) { LOG(WARN) << "Unable to get current browser"; } } } this->serialized_response_ = response.Serialize(); }