| 1230 | } |
| 1231 | |
| 1232 | bool IECommandExecutor::HandleUnexpectedAlert(BrowserHandle browser, |
| 1233 | HWND alert_handle, |
| 1234 | bool force_use_dismiss, |
| 1235 | std::string* alert_text) { |
| 1236 | LOG(TRACE) << "Entering IECommandExecutor::HandleUnexpectedAlert"; |
| 1237 | clock_t end = clock() + 5 * CLOCKS_PER_SEC; |
| 1238 | bool is_visible = (::IsWindowVisible(alert_handle) == TRUE); |
| 1239 | while (!is_visible && clock() < end) { |
| 1240 | ::Sleep(50); |
| 1241 | is_visible = (::IsWindowVisible(alert_handle) == TRUE); |
| 1242 | } |
| 1243 | Alert dialog(browser, alert_handle); |
| 1244 | *alert_text = dialog.GetText(); |
| 1245 | if (!dialog.is_standard_alert()) { |
| 1246 | // The dialog was non-standard. The most common case of this is |
| 1247 | // an onBeforeUnload dialog, which must be accepted to continue. |
| 1248 | dialog.Accept(); |
| 1249 | return false; |
| 1250 | } |
| 1251 | if (this->unexpected_alert_behavior_ == ACCEPT_UNEXPECTED_ALERTS || |
| 1252 | this->unexpected_alert_behavior_ == ACCEPT_AND_NOTIFY_UNEXPECTED_ALERTS) { |
| 1253 | LOG(DEBUG) << "Automatically accepting the alert"; |
| 1254 | dialog.Accept(); |
| 1255 | } else if (this->unexpected_alert_behavior_.size() == 0 || |
| 1256 | this->unexpected_alert_behavior_ == DISMISS_UNEXPECTED_ALERTS || |
| 1257 | this->unexpected_alert_behavior_ == DISMISS_AND_NOTIFY_UNEXPECTED_ALERTS || |
| 1258 | force_use_dismiss) { |
| 1259 | // If a quit command was issued, we should not ignore an unhandled |
| 1260 | // alert, even if the alert behavior is set to "ignore". |
| 1261 | LOG(DEBUG) << "Automatically dismissing the alert"; |
| 1262 | if (dialog.is_standard_alert() || dialog.is_security_alert()) { |
| 1263 | dialog.Dismiss(); |
| 1264 | } else { |
| 1265 | // The dialog was non-standard. The most common case of this is |
| 1266 | // an onBeforeUnload dialog, which must be accepted to continue. |
| 1267 | dialog.Accept(); |
| 1268 | } |
| 1269 | } |
| 1270 | |
| 1271 | bool is_notify_unexpected_alert = |
| 1272 | this->unexpected_alert_behavior_.size() == 0 || |
| 1273 | this->unexpected_alert_behavior_ == IGNORE_UNEXPECTED_ALERTS || |
| 1274 | this->unexpected_alert_behavior_ == DISMISS_AND_NOTIFY_UNEXPECTED_ALERTS || |
| 1275 | this->unexpected_alert_behavior_ == ACCEPT_AND_NOTIFY_UNEXPECTED_ALERTS; |
| 1276 | is_notify_unexpected_alert = is_notify_unexpected_alert && dialog.is_standard_alert(); |
| 1277 | return is_notify_unexpected_alert; |
| 1278 | } |
| 1279 | |
| 1280 | void IECommandExecutor::PostBrowserReattachMessage(const DWORD current_process_id, |
| 1281 | const std::string& browser_id, |
no test coverage detected