From 5f9bd3ecbd6bb911b4972526fa3063b43bf21763 Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Tue, 15 Sep 2020 11:03:38 -0400 Subject: [PATCH] Fix crash when sending programmatic event to a Views-hosted browser window. The |web_contents_| member was nullptr in CefBrowserPlatformDelegateNativeAura when calling methods like SendKeyEvent from CefBrowserPlatformDelegateViews. --- .../native/browser_platform_delegate_native.h | 1 - .../native/browser_platform_delegate_native_aura.cc | 2 ++ .../browser/views/browser_platform_delegate_views.cc | 12 +++++++++--- .../browser/views/browser_platform_delegate_views.h | 1 + 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/libcef/browser/native/browser_platform_delegate_native.h b/libcef/browser/native/browser_platform_delegate_native.h index e3e608818..8f279a1a9 100644 --- a/libcef/browser/native/browser_platform_delegate_native.h +++ b/libcef/browser/native/browser_platform_delegate_native.h @@ -62,7 +62,6 @@ class CefBrowserPlatformDelegateNative void set_windowless_handler(WindowlessHandler* handler) { windowless_handler_ = handler; } - void set_browser(CefBrowserHostImpl* browser) { browser_ = browser; } CefWindowInfo window_info_; const SkColor background_color_; diff --git a/libcef/browser/native/browser_platform_delegate_native_aura.cc b/libcef/browser/native/browser_platform_delegate_native_aura.cc index 89aeec53f..db8d14907 100644 --- a/libcef/browser/native/browser_platform_delegate_native_aura.cc +++ b/libcef/browser/native/browser_platform_delegate_native_aura.cc @@ -225,6 +225,8 @@ int CefBrowserPlatformDelegateNativeAura::TranslateUiChangedButtonFlags( content::RenderWidgetHostViewAura* CefBrowserPlatformDelegateNativeAura::GetHostView() const { + if (!web_contents_) + return nullptr; return static_cast( web_contents_->GetRenderWidgetHostView()); } diff --git a/libcef/browser/views/browser_platform_delegate_views.cc b/libcef/browser/views/browser_platform_delegate_views.cc index e7bb11ff4..4f8defdb2 100644 --- a/libcef/browser/views/browser_platform_delegate_views.cc +++ b/libcef/browser/views/browser_platform_delegate_views.cc @@ -69,15 +69,21 @@ void CefBrowserPlatformDelegateViews::WebContentsCreated( content::WebContents* web_contents, bool owned) { CefBrowserPlatformDelegateAlloy::WebContentsCreated(web_contents, owned); - + native_delegate_->WebContentsCreated(web_contents, /*owned=*/false); browser_view_->WebContentsCreated(web_contents); } +void CefBrowserPlatformDelegateViews::WebContentsDestroyed( + content::WebContents* web_contents) { + CefBrowserPlatformDelegateAlloy::WebContentsDestroyed(web_contents); + native_delegate_->WebContentsDestroyed(web_contents); +} + void CefBrowserPlatformDelegateViews::BrowserCreated( CefBrowserHostImpl* browser) { CefBrowserPlatformDelegateAlloy::BrowserCreated(browser); - native_delegate_->set_browser(browser); + native_delegate_->BrowserCreated(browser); browser_view_->BrowserCreated(browser, GetBoundsChangedCallback()); } @@ -99,9 +105,9 @@ void CefBrowserPlatformDelegateViews::BrowserDestroyed( CefBrowserHostImpl* browser) { CefBrowserPlatformDelegateAlloy::BrowserDestroyed(browser); - native_delegate_->set_browser(nullptr); browser_view_->BrowserDestroyed(browser); browser_view_ = nullptr; + native_delegate_->BrowserDestroyed(browser); } bool CefBrowserPlatformDelegateViews::CreateHostWindow() { diff --git a/libcef/browser/views/browser_platform_delegate_views.h b/libcef/browser/views/browser_platform_delegate_views.h index 62d6904de..2a3de031e 100644 --- a/libcef/browser/views/browser_platform_delegate_views.h +++ b/libcef/browser/views/browser_platform_delegate_views.h @@ -23,6 +23,7 @@ class CefBrowserPlatformDelegateViews // CefBrowserPlatformDelegate methods: void WebContentsCreated(content::WebContents* web_contents, bool owned) override; + void WebContentsDestroyed(content::WebContents* web_contents) override; void BrowserCreated(CefBrowserHostImpl* browser) override; void NotifyBrowserCreated() override; void NotifyBrowserDestroyed() override;