| 146 | } |
| 147 | |
| 148 | int DocumentHost::SetFocusedFrameByElement(IHTMLElement* frame_element) { |
| 149 | LOG(TRACE) << "Entering DocumentHost::SetFocusedFrameByElement"; |
| 150 | |
| 151 | HRESULT hr = S_OK; |
| 152 | if (!frame_element) { |
| 153 | this->focused_frame_window_ = NULL; |
| 154 | return WD_SUCCESS; |
| 155 | } |
| 156 | |
| 157 | CComPtr<IHTMLWindow2> interim_result; |
| 158 | CComPtr<IHTMLObjectElement4> object_element; |
| 159 | hr = frame_element->QueryInterface<IHTMLObjectElement4>(&object_element); |
| 160 | if (SUCCEEDED(hr) && object_element) { |
| 161 | CComPtr<IDispatch> object_disp; |
| 162 | object_element->get_contentDocument(&object_disp); |
| 163 | if (!object_disp) { |
| 164 | LOG(WARN) << "Cannot get IDispatch interface from IHTMLObjectElement4 element"; |
| 165 | return ENOSUCHFRAME; |
| 166 | } |
| 167 | |
| 168 | CComPtr<IHTMLDocument2> object_doc; |
| 169 | object_disp->QueryInterface<IHTMLDocument2>(&object_doc); |
| 170 | if (!object_doc) { |
| 171 | LOG(WARN) << "Cannot get IHTMLDocument2 document from IDispatch reference"; |
| 172 | return ENOSUCHFRAME; |
| 173 | } |
| 174 | |
| 175 | hr = object_doc->get_parentWindow(&interim_result); |
| 176 | if (FAILED(hr)) { |
| 177 | LOGHR(WARN, hr) << "Cannot get parentWindow from IHTMLDocument2, call to IHTMLDocument2::get_parentWindow failed"; |
| 178 | return ENOSUCHFRAME; |
| 179 | } |
| 180 | } else { |
| 181 | CComPtr<IHTMLFrameBase2> frame_base; |
| 182 | frame_element->QueryInterface<IHTMLFrameBase2>(&frame_base); |
| 183 | if (!frame_base) { |
| 184 | LOG(WARN) << "IHTMLElement is not a FRAME or IFRAME element"; |
| 185 | return ENOSUCHFRAME; |
| 186 | } |
| 187 | |
| 188 | hr = frame_base->get_contentWindow(&interim_result); |
| 189 | if (FAILED(hr)) { |
| 190 | LOGHR(WARN, hr) << "Cannot get contentWindow from IHTMLFrameBase2, call to IHTMLFrameBase2::get_contentWindow failed"; |
| 191 | return ENOSUCHFRAME; |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | this->focused_frame_window_ = interim_result; |
| 196 | return WD_SUCCESS; |
| 197 | } |
| 198 | |
| 199 | int DocumentHost::SetFocusedFrameByName(const std::string& frame_name) { |
| 200 | LOG(TRACE) << "Entering DocumentHost::SetFocusedFrameByName"; |
no test coverage detected