Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix occasional WebView2 Crash when restoring minimized app (0x80070057) #6667

Merged
merged 3 commits into from
Feb 3, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions dev/WebView2/WebView2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1255,14 +1255,25 @@ void WebView2::FireCoreWebView2Initialized(winrt::hresult exception)
m_coreWebView2InitializedEventSource(*this, *eventArgs);
}

void WebView2::HandleGotFocus(const winrt::Windows::Foundation::IInspectable&, const winrt::RoutedEventArgs&) noexcept
void WebView2::HandleGotFocus(const winrt::Windows::Foundation::IInspectable&, const winrt::RoutedEventArgs&)
{
if (m_coreWebView && m_xamlFocusChangeInfo.m_isPending)
{
// In current CoreWebView2 API, MoveFocus is not expected to fail, so set m_webHasFocus here rather than
krschau marked this conversation as resolved.
Show resolved Hide resolved
// in asynchronous (MOJO/cross-proc) CoreWebView2 GotFocus event.
m_webHasFocus = true;
m_coreWebViewController.MoveFocus(m_xamlFocusChangeInfo.m_storedMoveFocusReason);
try
{
m_coreWebViewController.MoveFocus(m_xamlFocusChangeInfo.m_storedMoveFocusReason);
}
catch (winrt::hresult_error e)
{
if (e.code().value != E_INVALIDARG)
krschau marked this conversation as resolved.
Show resolved Hide resolved
{
throw;
}
}

m_xamlFocusChangeInfo.m_isPending = false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion dev/WebView2/WebView2.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class WebView2 :
void HandlePointerCaptureLost(const winrt::Windows::Foundation::IInspectable&, const winrt::PointerRoutedEventArgs& args);
void HandleKeyDown(const winrt::Windows::Foundation::IInspectable&, const winrt::KeyRoutedEventArgs& e);
void HandleGettingFocus(const winrt::Windows::Foundation::IInspectable&, const winrt::GettingFocusEventArgs& args) noexcept;
void HandleGotFocus(const winrt::Windows::Foundation::IInspectable&, const winrt::RoutedEventArgs&) noexcept;
void HandleGotFocus(const winrt::Windows::Foundation::IInspectable&, const winrt::RoutedEventArgs&);
void HandleAcceleratorKeyActivated(const winrt::Windows::UI::Core::CoreDispatcher&, const winrt::AcceleratorKeyEventArgs& args) noexcept;
void HandleXamlRootChanged();
void HandleSizeChanged(const winrt::IInspectable& /*sender*/, const winrt::SizeChangedEventArgs& args);
Expand Down