Skip to content

Commit be524b6

Browse files
committed
Adding Protected Mode boundary closing mechanism in IE
When a Protected Mode boundary is crossed (entering or exiting Protected Mode), the existing browser instance is destroyed and a new one created in its place by Interent Explorer. This commit adds detection for when a browser instance is being closed, but without an explicit call to the WebDriver close() or quit() methods. When this is detected, it's likely a Protected Mode boundary is being crossed, and all subsequent commands in the WebDriver session will fail. In this case, the driver will now write to the log that the browser has been asked to exit without the user explicitly requesting it. The detection is not perfect, since it's possible to legitimately click a link that closes the browser window, and this is indistinguishable from clicking a link that navigates to a URL that causes a Protected Mode boundary crossing. Nevertheless, this logging is being added so that users can see what may be happening when they receive errors like "Unable to get current browser."
1 parent 9517a40 commit be524b6

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

cpp/iedriver/Browser.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ namespace webdriver {
3131

3232
Browser::Browser(IWebBrowser2* browser, HWND hwnd, HWND session_handle) : DocumentHost(hwnd, session_handle) {
3333
LOG(TRACE) << "Entering Browser::Browser";
34+
this->is_explicit_close_requested_ = false;
3435
this->is_navigation_started_ = false;
3536
this->browser_ = browser;
3637
this->AttachEvents();
@@ -52,6 +53,17 @@ void __stdcall Browser::BeforeNavigate2(IDispatch* pObject,
5253

5354
void __stdcall Browser::OnQuit() {
5455
LOG(TRACE) << "Entering Browser::OnQuit";
56+
if (!this->is_explicit_close_requested_) {
57+
LOG(WARN) << "This instance of Internet Explorer is exiting without an "
58+
<< "explicit request to close it. Unless you clicked a link "
59+
<< "that specifically attempts to close the page, that likely "
60+
<< "means a Protected Mode boundary has been crossed (either "
61+
<< "entering or exiting Protected Mode). It is highly likely "
62+
<< "that any subsequent commands to this driver instance will "
63+
<< "fail. THIS IS NOT A BUG IN THE IE DRIVER! Fix your code "
64+
<< "and/or browser configuration so that a Protected Mode "
65+
<< "boundary is not crossed.";
66+
}
5567
this->PostQuitMessage();
5668
}
5769

@@ -304,6 +316,7 @@ void Browser::DetachEvents() {
304316

305317
void Browser::Close() {
306318
LOG(TRACE) << "Entering Browser::Close";
319+
this->is_explicit_close_requested_ = true;
307320
// Closing the browser, so having focus on a frame doesn't
308321
// make any sense.
309322
this->SetFocusedFrameByElement(NULL);

cpp/iedriver/Browser.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ class Browser : public DocumentHost, public IDispEventSimpleImpl<1, Browser, &DI
115115
bool IsFullScreen(void);
116116
bool SetFullScreen(bool is_full_screen);
117117

118+
bool is_explicit_close_requested(void) const {
119+
return this->is_explicit_close_requested_;
120+
}
118121
IWebBrowser2* browser(void) { return this->browser_; }
119122

120123
private:
@@ -130,6 +133,7 @@ class Browser : public DocumentHost, public IDispEventSimpleImpl<1, Browser, &DI
130133

131134
CComPtr<IWebBrowser2> browser_;
132135
bool is_navigation_started_;
136+
bool is_explicit_close_requested_;
133137
};
134138

135139
} // namespace webdriver

0 commit comments

Comments
 (0)