| 378 | } |
| 379 | |
| 380 | int Alert::ClickAlertButton(DialogButtonInfo button_info) { |
| 381 | LOG(TRACE) << "Entering Alert::ClickAlertButton"; |
| 382 | // Click on the appropriate button of the Alert |
| 383 | if (this->is_standard_control_alert_) { |
| 384 | ::SendMessage(this->alert_handle_, |
| 385 | WM_COMMAND, |
| 386 | button_info.button_control_id, |
| 387 | NULL); |
| 388 | } else { |
| 389 | if (button_info.use_accessibility) { |
| 390 | int status_code = ClickAlertButtonUsingAccessibility(button_info.accessibility_id); |
| 391 | if (status_code != WD_SUCCESS) { |
| 392 | return status_code; |
| 393 | } |
| 394 | } else { |
| 395 | // For non-standard alerts (that is, alerts that are not |
| 396 | // created by alert(), confirm() or prompt() JavaScript |
| 397 | // functions), we cheat. Sending the BN_CLICKED notification |
| 398 | // via WM_COMMAND makes the dialog think that the proper |
| 399 | // button was clicked, but it's not the same as sending the |
| 400 | // click message to the button. N.B., sending the BM_CLICK |
| 401 | // message to the button may fail if the dialog doesn't have |
| 402 | // focus, so we do it this way. Also, we send the notification |
| 403 | // to the immediate parent of the button, which, in turn, |
| 404 | // notifies the top-level dialog. |
| 405 | ::SendMessage(::GetParent(button_info.button_handle), |
| 406 | WM_COMMAND, |
| 407 | MAKEWPARAM(0, BN_CLICKED), |
| 408 | reinterpret_cast<LPARAM>(button_info.button_handle)); |
| 409 | } |
| 410 | } |
| 411 | // Hack to make sure alert is really closed, and browser |
| 412 | // is ready for the next operation. This may be a flawed |
| 413 | // algorithim, since the busy property of the browser may |
| 414 | // not be the right thing to check here. |
| 415 | int retry_count = 20; |
| 416 | bool is_alert_handle_valid = (::IsWindow(this->alert_handle_) == TRUE); |
| 417 | while ((is_alert_handle_valid || this->browser_->IsBusy()) && retry_count > 0) { |
| 418 | ::Sleep(50); |
| 419 | is_alert_handle_valid = (::IsWindow(this->alert_handle_) == TRUE); |
| 420 | retry_count--; |
| 421 | } |
| 422 | |
| 423 | // TODO(JimEvans): Check for the following error conditions: |
| 424 | // 1. Alert window still present (::IsWindow(this->alert_handle_) == TRUE) |
| 425 | // 2. Browser still busy (this->browser_->IsBusy() == true) |
| 426 | // and return an appropriate non-WD_SUCCESS error code. |
| 427 | LOG(DEBUG) << "IsWindow() for alert handle 0x" << this->alert_handle_ << ": " |
| 428 | << is_alert_handle_valid ? "true" : "false"; |
| 429 | return WD_SUCCESS; |
| 430 | } |
| 431 | |
| 432 | Alert::DialogButtonInfo Alert::GetDialogButton(BUTTON_TYPE button_type) { |
| 433 | LOG(TRACE) << "Entering Alert::GetDialogButton"; |