From 4fe33a194ad4780baa07d7d9bbac4b6ef8ce7d77 Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Thu, 21 Jan 2021 13:32:46 -0500 Subject: [PATCH] Add workaround for crash on Views popup window creation (see issue #3040) --- libcef/browser/views/browser_view_impl.cc | 14 +++++++++++++- libcef/browser/views/browser_view_impl.h | 6 ++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/libcef/browser/views/browser_view_impl.cc b/libcef/browser/views/browser_view_impl.cc index 605723009..b5d289452 100644 --- a/libcef/browser/views/browser_view_impl.cc +++ b/libcef/browser/views/browser_view_impl.cc @@ -132,6 +132,14 @@ void CefBrowserViewImpl::SetPreferAccelerators(bool prefer_accelerators) { root_view()->set_allow_accelerators(prefer_accelerators); } +void CefBrowserViewImpl::RequestFocus() { + CEF_REQUIRE_VALID_RETURN_VOID(); + // Always execute asynchronously to work around issue #3040. + CEF_POST_TASK(CEF_UIT, + base::BindOnce(&CefBrowserViewImpl::RequestFocusInternal, + weak_ptr_factory_.GetWeakPtr())); +} + void CefBrowserViewImpl::SetBackgroundColor(cef_color_t color) { CEF_REQUIRE_VALID_RETURN_VOID(); ParentClass::SetBackgroundColor(color); @@ -182,7 +190,7 @@ void CefBrowserViewImpl::OnBoundsChanged() { CefBrowserViewImpl::CefBrowserViewImpl( CefRefPtr delegate) - : ParentClass(delegate) {} + : ParentClass(delegate), weak_ptr_factory_(this) {} void CefBrowserViewImpl::SetPendingBrowserCreateParams( CefRefPtr client, @@ -248,3 +256,7 @@ bool CefBrowserViewImpl::HandleAccelerator( return false; } + +void CefBrowserViewImpl::RequestFocusInternal() { + ParentClass::RequestFocus(); +} diff --git a/libcef/browser/views/browser_view_impl.h b/libcef/browser/views/browser_view_impl.h index f128a61ba..15ae54467 100644 --- a/libcef/browser/views/browser_view_impl.h +++ b/libcef/browser/views/browser_view_impl.h @@ -14,6 +14,7 @@ #include "libcef/browser/views/view_impl.h" #include "base/callback_forward.h" +#include "base/memory/weak_ptr.h" #include "ui/views/controls/webview/unhandled_keyboard_event_handler.h" class CefBrowserHostBase; @@ -59,6 +60,7 @@ class CefBrowserViewImpl : public CefViewImpl AsBrowserView() override { return this; } + void RequestFocus() override; void SetBackgroundColor(cef_color_t color) override; // CefViewAdapter methods: @@ -96,6 +98,8 @@ class CefBrowserViewImpl : public CefViewImpl pending_browser_create_params_; CefRefPtr browser_; @@ -105,6 +109,8 @@ class CefBrowserViewImpl : public CefViewImpl weak_ptr_factory_; + IMPLEMENT_REFCOUNTING_DELETE_ON_UIT(CefBrowserViewImpl); DISALLOW_COPY_AND_ASSIGN(CefBrowserViewImpl); };