From 16a2d4ec96cd8f323cd15157ce1595865856f8f4 Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 4 Jan 2024 18:17:52 +0400 Subject: [PATCH] Fix wrong "Webview process crashed." message. --- .../SourceFiles/payments/ui/payments_panel.cpp | 15 +++++++++++++-- .../ui/chat/attach/attach_bot_webview.cpp | 14 ++++++++++++-- Telegram/lib_ui | 2 +- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/Telegram/SourceFiles/payments/ui/payments_panel.cpp b/Telegram/SourceFiles/payments/ui/payments_panel.cpp index 5e5c872de..bc2817d52 100644 --- a/Telegram/SourceFiles/payments/ui/payments_panel.cpp +++ b/Telegram/SourceFiles/payments/ui/payments_panel.cpp @@ -96,7 +96,7 @@ Panel::Panel(not_null delegate) } Panel::~Panel() { - _webview = nullptr; + base::take(_webview); _progress = nullptr; _widget = nullptr; } @@ -528,6 +528,7 @@ bool Panel::createWebview(const Webview::ThemeParams ¶ms) { auto outer = base::make_unique_q(_widget.get()); const auto container = outer.get(); _widget->showInner(std::move(outer)); + const auto webviewParent = QPointer(container); _webviewBottom = std::make_unique(_widget.get()); const auto bottom = _webviewBottom.get(); @@ -552,7 +553,7 @@ bool Panel::createWebview(const Webview::ThemeParams ¶ms) { const auto raw = &_webview->window; QObject::connect(container, &QObject::destroyed, [=] { if (_webview && &_webview->window == raw) { - _webview = nullptr; + base::take(_webview); if (_webviewProgress) { hideWebviewProgress(); if (_progress && !_progress->shown) { @@ -568,6 +569,16 @@ bool Panel::createWebview(const Webview::ThemeParams ¶ms) { return false; } QObject::connect(raw->widget(), &QObject::destroyed, [=] { + const auto parent = webviewParent.data(); + if (!_webview + || &_webview->window != raw + || !parent + || _widget->inner() != parent) { + // If we destroyed _webview ourselves, + // or if we changed _widget->inner ourselves, + // we don't show any message, nothing crashed. + return; + } crl::on_main(this, [=] { showCriticalError({ "Error: WebView has crashed." }); }); diff --git a/Telegram/SourceFiles/ui/chat/attach/attach_bot_webview.cpp b/Telegram/SourceFiles/ui/chat/attach/attach_bot_webview.cpp index 209444ff1..c94f26294 100644 --- a/Telegram/SourceFiles/ui/chat/attach/attach_bot_webview.cpp +++ b/Telegram/SourceFiles/ui/chat/attach/attach_bot_webview.cpp @@ -364,7 +364,7 @@ Panel::Panel( } Panel::~Panel() { - _webview = nullptr; + base::take(_webview); _progress = nullptr; _widget = nullptr; } @@ -587,7 +587,7 @@ bool Panel::createWebview(const Webview::ThemeParams ¶ms) { QObject::connect(container, &QObject::destroyed, [=] { if (_webview && &_webview->window == raw) { - _webview = nullptr; + base::take(_webview); if (_webviewProgress) { hideWebviewProgress(); if (_progress && !_progress->shown) { @@ -604,6 +604,16 @@ bool Panel::createWebview(const Webview::ThemeParams ¶ms) { return false; } QObject::connect(raw->widget(), &QObject::destroyed, [=] { + const auto parent = _webviewParent.data(); + if (!_webview + || &_webview->window != raw + || !parent + || _widget->inner() != parent) { + // If we destroyed _webview ourselves, + // or if we changed _widget->inner ourselves, + // we don't show any message, nothing crashed. + return; + } crl::on_main(this, [=] { showCriticalError({ "Error: WebView has crashed." }); }); diff --git a/Telegram/lib_ui b/Telegram/lib_ui index 7fef09421..30c5dfe6f 160000 --- a/Telegram/lib_ui +++ b/Telegram/lib_ui @@ -1 +1 @@ -Subproject commit 7fef09421c2b71e5ab9cf481c0fcf2a0b6d2daf0 +Subproject commit 30c5dfe6f65babf234c889959061c97c4a2f391d