| 254 | } |
| 255 | |
| 256 | std::string Alert::GetDirectUIDialogText() { |
| 257 | LOG(TRACE) << "Entering Alert::GetDirectUIDialogText"; |
| 258 | std::string alert_text_value = ""; |
| 259 | HWND direct_ui_child_handle = this->GetDirectUIChild(); |
| 260 | |
| 261 | CComPtr<IAccessible> window_object; |
| 262 | HRESULT hr = ::AccessibleObjectFromWindow( |
| 263 | direct_ui_child_handle, |
| 264 | OBJID_WINDOW, |
| 265 | IID_IAccessible, |
| 266 | reinterpret_cast<void**>(&window_object)); |
| 267 | if (FAILED(hr)) { |
| 268 | LOGHR(WARN, hr) << "Failed to get Active Accessibility window object from dialog"; |
| 269 | return alert_text_value; |
| 270 | } |
| 271 | |
| 272 | // ASSUMPTION: There is an object with the role of "pane" as a child of |
| 273 | // the window object. |
| 274 | CComPtr<IAccessible> pane_object = this->GetChildWithRole(window_object, |
| 275 | ROLE_SYSTEM_PANE, |
| 276 | 0); |
| 277 | if (!pane_object) { |
| 278 | LOG(WARN) << "Failed to get Active Accessibility pane child object from window"; |
| 279 | return alert_text_value; |
| 280 | } |
| 281 | |
| 282 | int child_index = 0; |
| 283 | if (!this->is_standard_alert_) { |
| 284 | // ASSUMPTION: This means the alert is from onbeforeunload, and |
| 285 | // the second "static text" accessibility object is the one |
| 286 | // that contains the message. |
| 287 | child_index = 1; |
| 288 | } |
| 289 | |
| 290 | CComPtr<IAccessible> message_text_object = this->GetChildWithRole( |
| 291 | pane_object, |
| 292 | ROLE_SYSTEM_STATICTEXT, |
| 293 | child_index); |
| 294 | if (!message_text_object) { |
| 295 | LOG(WARN) << "Failed to get Active Accessibility text child object from pane"; |
| 296 | return alert_text_value; |
| 297 | } |
| 298 | |
| 299 | CComVariant child_id; |
| 300 | child_id.vt = VT_I4; |
| 301 | child_id.lVal = CHILDID_SELF; |
| 302 | |
| 303 | CComBSTR text_bstr; |
| 304 | hr = message_text_object->get_accName(child_id, &text_bstr); |
| 305 | if (FAILED(hr)) { |
| 306 | LOGHR(WARN, hr) << "Failed to get accName property from text object"; |
| 307 | return alert_text_value; |
| 308 | } else if (hr != S_OK) { |
| 309 | // N.B., get_accName can return an error value without it being a |
| 310 | // standard COM error. |
| 311 | LOG(WARN) << "Getting accName property from text object returned an error " |
| 312 | << "(value: " << hr << "). The text object may not have a name."; |
| 313 | return alert_text_value; |
no test coverage detected