diff --git a/Telegram/SourceFiles/ui/chat/attach/attach_bot_webview.cpp b/Telegram/SourceFiles/ui/chat/attach/attach_bot_webview.cpp index 421df4a6c..3f93800c6 100644 --- a/Telegram/SourceFiles/ui/chat/attach/attach_bot_webview.cpp +++ b/Telegram/SourceFiles/ui/chat/attach/attach_bot_webview.cpp @@ -33,6 +33,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace Ui::BotWebView { namespace { +constexpr auto kProcessClickTimeout = crl::time(1000); constexpr auto kProgressDuration = crl::time(200); constexpr auto kProgressOpacity = 0.3; constexpr auto kLightnessThreshold = 128; @@ -86,6 +87,30 @@ constexpr auto kLightnessDelta = 32; alpha); } +[[nodiscard]] QString EncodeForJs(const QString &text) { + auto result = QString(); + for (auto ch = text.data(), e = ch + text.size(); ch != e; ++ch) { + const auto code = ch->unicode(); + const auto hex = [&](int value) { + const auto v = value & 0x0F; + return QChar((v < 10) ? ('0' + v) : 'A' + (v - 10)); + }; + if (code >= 32 && code < 128) { + if (code == '\\' || code == '"' || code == '\'') { + result += QChar('\\'); + } + result += *ch; + } else { + result += u"\\u"_q + + hex(code >> 12) + + hex(code >> 8) + + hex(code >> 4) + + hex(code); + } + } + return result; +} + } // namespace class Panel::Button final : public RippleButton { @@ -667,7 +692,15 @@ void Panel::openExternalLink(const QJsonValue &value) { _close(); return; } - QDesktopServices::openUrl(url); + const auto now = crl::now(); + if (_mainButtonLastClick + && _mainButtonLastClick + kProcessClickTimeout >= now) { + _mainButtonLastClick = 0; + QDesktopServices::openUrl(url); + } else { + const auto string = EncodeForJs(url); + _webview->window.eval(("window.open(\"" + string + "\");").toUtf8()); + } } void Panel::openInvoice(const QJsonValue &value) { @@ -747,6 +780,7 @@ void Panel::createMainButton() { button->setClickedCallback([=] { if (!button->isDisabled()) { postEvent("main_button_pressed"); + _mainButtonLastClick = crl::now(); } }); button->hide(); diff --git a/Telegram/SourceFiles/ui/chat/attach/attach_bot_webview.h b/Telegram/SourceFiles/ui/chat/attach/attach_bot_webview.h index d89a4f82d..660ce3d86 100644 --- a/Telegram/SourceFiles/ui/chat/attach/attach_bot_webview.h +++ b/Telegram/SourceFiles/ui/chat/attach/attach_bot_webview.h @@ -97,6 +97,7 @@ private: std::unique_ptr _webviewBottom; QPointer _webviewParent; std::unique_ptr