MCPcopy Create free account
hub / github.com/SeleniumHQ/selenium / GetDocumentFromWindow

Method GetDocumentFromWindow

cpp/iedriver/Browser.cpp:761–806  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

759}
760
761bool Browser::GetDocumentFromWindow(IHTMLWindow2* window,
762 IHTMLDocument2** doc) {
763 LOG(TRACE) << "Entering Browser::GetDocumentFromWindow";
764
765 HRESULT hr = window->get_document(doc);
766 if (SUCCEEDED(hr)) {
767 return true;
768 }
769
770 if (hr == E_ACCESSDENIED) {
771 // Cross-domain documents may throw Access Denied. If so,
772 // get the document through the IWebBrowser2 interface.
773 CComPtr<IServiceProvider> service_provider;
774 hr = window->QueryInterface<IServiceProvider>(&service_provider);
775 if (FAILED(hr)) {
776 LOGHR(WARN, hr) << "Unable to get browser, call to IHTMLWindow2::QueryService failed for IServiceProvider";
777 return false;
778 }
779
780 CComPtr<IWebBrowser2> window_browser;
781 hr = service_provider->QueryService(IID_IWebBrowserApp, &window_browser);
782 if (FAILED(hr)) {
783 LOGHR(WARN, hr) << "Unable to get browser, call to IServiceProvider::QueryService failed for IID_IWebBrowserApp";
784 return false;
785 }
786
787 CComPtr<IDispatch> document_dispatch;
788 hr = window_browser->get_Document(&document_dispatch);
789 if (FAILED(hr) || hr == S_FALSE) {
790 LOGHR(WARN, hr) << "Unable to get document, call to IWebBrowser2::get_Document failed";
791 return false;
792 }
793
794 hr = document_dispatch->QueryInterface(doc);
795 if (FAILED(hr)) {
796 LOGHR(WARN, hr) << "Unable to query document, call to IDispatch::QueryInterface failed.";
797 return false;
798 }
799
800 return true;
801 } else {
802 LOGHR(WARN, hr) << "Unable to get main document, IHTMLWindow2::get_document returned other than E_ACCESSDENIED";
803 }
804
805 return false;
806}
807
808HWND Browser::GetBrowserWindowHandle() {
809 LOG(TRACE) << "Entering Browser::GetBrowserWindowHandle";

Callers 2

GetDocumentMethod · 0.95
IsDocumentNavigatingMethod · 0.95

Calls 2

QueryServiceMethod · 0.80
LOGClass · 0.50

Tested by

no test coverage detected