diff --git a/Telegram/SourceFiles/payments/ui/payments_panel.cpp b/Telegram/SourceFiles/payments/ui/payments_panel.cpp index e8923f2bb..724cbcada 100644 --- a/Telegram/SourceFiles/payments/ui/payments_panel.cpp +++ b/Telegram/SourceFiles/payments/ui/payments_panel.cpp @@ -43,6 +43,21 @@ struct Panel::Progress { rpl::lifetime geometryLifetime; }; +struct Panel::WebviewWithLifetime { + WebviewWithLifetime( + QWidget *parent = nullptr, + Webview::WindowConfig config = Webview::WindowConfig()); + + Webview::Window window; + rpl::lifetime lifetime; +}; + +Panel::WebviewWithLifetime::WebviewWithLifetime( + QWidget *parent, + Webview::WindowConfig config) +: window(parent, std::move(config)) { +} + Panel::Progress::Progress(QWidget *parent, Fn rect) : widget(parent) , animation( @@ -68,7 +83,7 @@ Panel::Panel(not_null delegate) } Panel::~Panel() { - // Destroy _widget before _webview. + _webview = nullptr; _progress = nullptr; _widget = nullptr; } @@ -451,7 +466,7 @@ bool Panel::showWebview( } showWebviewProgress(); _widget->destroyLayer(); - _webview->navigate(url); + _webview->window.navigate(url); _widget->setBackAllowed(allowBack); if (bottomText) { const auto &padding = st::paymentsPanelPadding; @@ -490,14 +505,14 @@ bool Panel::createWebview() { }, bottom->lifetime()); container->show(); - _webview = std::make_unique( + _webview = std::make_unique( container.get(), Webview::WindowConfig{ .userDataPath = _delegate->panelWebviewDataPath(), }); - const auto raw = _webview.get(); + const auto raw = &_webview->window; QObject::connect(container.get(), &QObject::destroyed, [=] { - if (_webview.get() == raw) { + if (_webview && &_webview->window == raw) { _webview = nullptr; if (_webviewProgress) { hideWebviewProgress(); @@ -517,7 +532,7 @@ bool Panel::createWebview() { container->geometryValue( ) | rpl::start_with_next([=](QRect geometry) { raw->widget()->setGeometry(geometry); - }, container->lifetime()); + }, _webview->lifetime); raw->setMessageHandler([=](const QJsonDocument &message) { const auto save = _saveWebviewInformation diff --git a/Telegram/SourceFiles/payments/ui/payments_panel.h b/Telegram/SourceFiles/payments/ui/payments_panel.h index 11def1482..c977fe7a4 100644 --- a/Telegram/SourceFiles/payments/ui/payments_panel.h +++ b/Telegram/SourceFiles/payments/ui/payments_panel.h @@ -17,7 +17,6 @@ class Checkbox; } // namespace Ui namespace Webview { -class Window; struct Available; } // namespace Webview @@ -88,6 +87,7 @@ public: private: struct Progress; + struct WebviewWithLifetime; bool createWebview(); void showWebviewProgress(); @@ -103,7 +103,7 @@ private: const not_null _delegate; std::unique_ptr _widget; - std::unique_ptr _webview; + std::unique_ptr _webview; std::unique_ptr _webviewBottom; std::unique_ptr _progress; QPointer _saveWebviewInformation;