Skip to content

Commit

Permalink
Adding Protected Mode boundary closing mechanism in IE
Browse files Browse the repository at this point in the history
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."
  • Loading branch information
jimevans committed Mar 14, 2018
1 parent 9517a40 commit be524b6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
13 changes: 13 additions & 0 deletions cpp/iedriver/Browser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ namespace webdriver {

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

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

Expand Down Expand Up @@ -304,6 +316,7 @@ void Browser::DetachEvents() {

void Browser::Close() {
LOG(TRACE) << "Entering Browser::Close";
this->is_explicit_close_requested_ = true;
// Closing the browser, so having focus on a frame doesn't
// make any sense.
this->SetFocusedFrameByElement(NULL);
Expand Down
4 changes: 4 additions & 0 deletions cpp/iedriver/Browser.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ class Browser : public DocumentHost, public IDispEventSimpleImpl<1, Browser, &DI
bool IsFullScreen(void);
bool SetFullScreen(bool is_full_screen);

bool is_explicit_close_requested(void) const {
return this->is_explicit_close_requested_;
}
IWebBrowser2* browser(void) { return this->browser_; }

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

CComPtr<IWebBrowser2> browser_;
bool is_navigation_started_;
bool is_explicit_close_requested_;
};

} // namespace webdriver
Expand Down

0 comments on commit be524b6

Please sign in to comment.