| 1580 | } |
| 1581 | |
| 1582 | int Element::GetContainingDocument(const bool use_dom_node, |
| 1583 | IHTMLDocument2** doc) { |
| 1584 | LOG(TRACE) << "Entering Element::GetContainingDocument"; |
| 1585 | |
| 1586 | HRESULT hr = S_OK; |
| 1587 | CComPtr<IDispatch> dispatch_doc; |
| 1588 | |
| 1589 | if (use_dom_node) { |
| 1590 | CComPtr<IHTMLDOMNode2> node; |
| 1591 | hr = this->element_->QueryInterface(&node); |
| 1592 | if (FAILED(hr)) { |
| 1593 | LOGHR(WARN, hr) << "Unable to cast element to IHTMLDomNode2"; |
| 1594 | return ENOSUCHDOCUMENT; |
| 1595 | } |
| 1596 | |
| 1597 | hr = node->get_ownerDocument(&dispatch_doc); |
| 1598 | if (FAILED(hr)) { |
| 1599 | LOGHR(WARN, hr) << "Unable to locate owning document, call to IHTMLDOMNode2::get_ownerDocument failed"; |
| 1600 | return ENOSUCHDOCUMENT; |
| 1601 | } |
| 1602 | } else { |
| 1603 | hr = this->element_->get_document(&dispatch_doc); |
| 1604 | if (FAILED(hr)) { |
| 1605 | LOGHR(WARN, hr) << "Unable to locate document property, call to IHTMLELement::get_document failed"; |
| 1606 | return ENOSUCHDOCUMENT; |
| 1607 | } |
| 1608 | } |
| 1609 | |
| 1610 | try { |
| 1611 | hr = dispatch_doc.QueryInterface<IHTMLDocument2>(doc); |
| 1612 | if (FAILED(hr)) { |
| 1613 | LOGHR(WARN, hr) << "Found document but it's not the expected type (IHTMLDocument2)"; |
| 1614 | return ENOSUCHDOCUMENT; |
| 1615 | } |
| 1616 | } catch(...) { |
| 1617 | LOG(WARN) << "Found document but it's not the expected type (IHTMLDocument2)"; |
| 1618 | return ENOSUCHDOCUMENT; |
| 1619 | } |
| 1620 | |
| 1621 | return WD_SUCCESS; |
| 1622 | } |
| 1623 | |
| 1624 | int Element::GetDocumentFromWindow(IHTMLWindow2* parent_window, |
| 1625 | IHTMLDocument2** parent_doc) { |
no test coverage detected