Skip to content

Commit 36a412e

Browse files
committed
Internal API addition for IE driver to get browser window handle
This commit introduces an API for getting the browser window handle. In IE6, this would be the top-level window handle. In IE7 and above, this will be the handle of the tab window. This is separate from the window which renders the content, which has a window class of 'InternetExplorer_Server'. There is a need to locate both window handles distinctly in the internal operation of the IE driver.
1 parent 9315578 commit 36a412e

File tree

5 files changed

+46
-7
lines changed

5 files changed

+46
-7
lines changed

cpp/iedriver/Browser.cpp

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,12 @@ HWND Browser::GetContentWindowHandle() {
203203

204204
if (this->window_handle() == NULL) {
205205
LOG(INFO) << "Restore window handle from tab";
206-
this->set_window_handle(this->GetTabWindowHandle());
206+
// GetBrowserWindowHandle gets the TabWindowClass window in IE 7 and 8,
207+
// and the top-level window frame in IE 6. The window we need is the
208+
// InternetExplorer_Server window.
209+
HWND tab_window_handle = this->GetBrowserWindowHandle();
210+
HWND content_window_handle = this->FindContentWindowHandle(tab_window_handle);
211+
this->set_window_handle(content_window_handle);
207212
}
208213

209214
return this->window_handle();
@@ -616,8 +621,8 @@ bool Browser::GetDocumentFromWindow(IHTMLWindow2* window,
616621
return false;
617622
}
618623

619-
HWND Browser::GetTabWindowHandle() {
620-
LOG(TRACE) << "Entering Browser::GetTabWindowHandle";
624+
HWND Browser::GetBrowserWindowHandle() {
625+
LOG(TRACE) << "Entering Browser::GetBrowserWindowHandle";
621626

622627
HWND hwnd = NULL;
623628
CComPtr<IServiceProvider> service_provider;
@@ -630,10 +635,8 @@ HWND Browser::GetTabWindowHandle() {
630635
reinterpret_cast<void**>(&window));
631636
if (SUCCEEDED(hr)) {
632637
// This gets the TabWindowClass window in IE 7 and 8,
633-
// and the top-level window frame in IE 6. The window
634-
// we need is the InternetExplorer_Server window.
638+
// and the top-level window frame in IE 6.
635639
window->GetWindow(&hwnd);
636-
hwnd = this->FindContentWindowHandle(hwnd);
637640
} else {
638641
LOGHR(WARN, hr) << "Unable to get window, call to IOleWindow::QueryService for SID_SShellBrowser failed";
639642
}
@@ -644,6 +647,34 @@ HWND Browser::GetTabWindowHandle() {
644647
return hwnd;
645648
}
646649

650+
//HWND Browser::GetTabWindowHandle() {
651+
// LOG(TRACE) << "Entering Browser::GetTabWindowHandle";
652+
//
653+
// HWND hwnd = NULL;
654+
// CComPtr<IServiceProvider> service_provider;
655+
// HRESULT hr = this->browser_->QueryInterface(IID_IServiceProvider,
656+
// reinterpret_cast<void**>(&service_provider));
657+
// if (SUCCEEDED(hr)) {
658+
// CComPtr<IOleWindow> window;
659+
// hr = service_provider->QueryService(SID_SShellBrowser,
660+
// IID_IOleWindow,
661+
// reinterpret_cast<void**>(&window));
662+
// if (SUCCEEDED(hr)) {
663+
// // This gets the TabWindowClass window in IE 7 and 8,
664+
// // and the top-level window frame in IE 6. The window
665+
// // we need is the InternetExplorer_Server window.
666+
// window->GetWindow(&hwnd);
667+
// hwnd = this->FindContentWindowHandle(hwnd);
668+
// } else {
669+
// LOGHR(WARN, hr) << "Unable to get window, call to IOleWindow::QueryService for SID_SShellBrowser failed";
670+
// }
671+
// } else {
672+
// LOGHR(WARN, hr) << "Unable to get service, call to IWebBrowser2::QueryInterface for IID_IServiceProvider failed";
673+
// }
674+
//
675+
// return hwnd;
676+
//}
677+
647678
HWND Browser::GetActiveDialogWindowHandle() {
648679
LOG(TRACE) << "Entering Browser::GetActiveDialogWindowHandle";
649680

cpp/iedriver/Browser.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ class Browser : public DocumentHost, public IDispEventSimpleImpl<1, Browser, &DI
9292
std::string GetTitle(void);
9393
std::string GetBrowserUrl(void);
9494
HWND GetContentWindowHandle(void);
95+
HWND GetBrowserWindowHandle(void);
9596
HWND GetTopLevelWindowHandle(void);
9697
HWND GetActiveDialogWindowHandle(void);
9798

@@ -114,7 +115,7 @@ class Browser : public DocumentHost, public IDispEventSimpleImpl<1, Browser, &DI
114115
void DetachEvents(void);
115116
bool IsDocumentNavigating(IHTMLDocument2* doc);
116117
bool GetDocumentFromWindow(IHTMLWindow2* window, IHTMLDocument2** doc);
117-
HWND GetTabWindowHandle(void);
118+
//HWND GetTabWindowHandle(void);
118119
void CheckDialogType(HWND dialog_window_handle);
119120

120121
static unsigned int WINAPI GoBackThreadProc(LPVOID param);

cpp/iedriver/DocumentHost.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class DocumentHost {
3434
virtual bool Wait(void) = 0;
3535
virtual bool IsBusy(void) = 0;
3636
virtual HWND GetContentWindowHandle(void) = 0;
37+
virtual HWND GetBrowserWindowHandle(void) = 0;
3738
virtual std::string GetWindowName(void) = 0;
3839
virtual std::string GetTitle(void) = 0;
3940
virtual std::string GetBrowserUrl(void) = 0;

cpp/iedriver/HtmlDialog.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ HWND HtmlDialog::GetContentWindowHandle() {
132132
return this->window_handle();
133133
}
134134

135+
HWND HtmlDialog::GetBrowserWindowHandle() {
136+
LOG(TRACE) << "Entering HtmlDialog::GetBrowserWindowHandle";
137+
return this->window_handle();
138+
}
139+
135140
std::string HtmlDialog::GetWindowName() {
136141
LOG(TRACE) << "Entering HtmlDialog::GetWindowName";
137142
return "";

cpp/iedriver/HtmlDialog.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class HtmlDialog : public DocumentHost, public IDispEventSimpleImpl<1, HtmlDialo
5151
bool Wait(void);
5252
bool IsBusy(void);
5353
HWND GetContentWindowHandle(void);
54+
HWND GetBrowserWindowHandle(void);
5455
std::string GetWindowName(void);
5556
std::string GetTitle(void);
5657
std::string GetBrowserUrl(void);

0 commit comments

Comments
 (0)