/* This file is part of Telegram Desktop, the official desktop application for the Telegram messaging service. For license and copyright information please follow this link: https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once #include "base/expected.h" #include "base/object_ptr.h" #include "base/weak_ptr.h" #include "base/flags.h" #include "ui/rect_part.h" #include "ui/round_rect.h" #include "webview/webview_common.h" class QJsonObject; class QJsonValue; namespace Ui { class BoxContent; class RpWidget; class SeparatePanel; enum class LayerOption; using LayerOptions = base::flags; } // namespace Ui namespace Webview { struct Available; } // namespace Webview namespace Ui::BotWebView { [[nodiscard]] TextWithEntities ErrorText(const Webview::Available &info); enum class MenuButton { None = 0x00, OpenBot = 0x01, RemoveFromMenu = 0x02, RemoveFromMainMenu = 0x04, ShareGame = 0x08, }; inline constexpr bool is_flag_type(MenuButton) { return true; } using MenuButtons = base::flags; using CustomMethodResult = base::expected; struct CustomMethodRequest { QString method; QByteArray params; Fn callback; }; class Delegate { public: virtual Webview::ThemeParams botThemeParams() = 0; virtual bool botHandleLocalUri(QString uri, bool keepOpen) = 0; virtual void botHandleInvoice(QString slug) = 0; virtual void botHandleMenuButton(MenuButton button) = 0; virtual bool botValidateExternalLink(QString uri) = 0; virtual void botOpenIvLink(QString uri) = 0; virtual void botSendData(QByteArray data) = 0; virtual void botSwitchInlineQuery( std::vector chatTypes, QString query) = 0; virtual void botCheckWriteAccess(Fn callback) = 0; virtual void botAllowWriteAccess(Fn callback) = 0; virtual void botSharePhone(Fn callback) = 0; virtual void botInvokeCustomMethod(CustomMethodRequest request) = 0; virtual void botOpenPrivacyPolicy() = 0; virtual void botClose() = 0; }; class Panel final : public base::has_weak_ptr { public: Panel( const Webview::StorageId &storageId, rpl::producer title, object_ptr titleBadge, not_null delegate, MenuButtons menuButtons, bool allowClipboardRead); ~Panel(); void requestActivate(); void toggleProgress(bool shown); bool showWebview( const QString &url, const Webview::ThemeParams ¶ms, rpl::producer bottomText); void showBox(object_ptr box); void showBox( object_ptr box, LayerOptions options, anim::type animated); void hideLayer(anim::type animated); void showToast(TextWithEntities &&text); not_null toastParent() const; void showCriticalError(const TextWithEntities &text); void showWebviewError( const QString &text, const Webview::Available &information); void updateThemeParams(const Webview::ThemeParams ¶ms); void hideForPayment(); void invoiceClosed(const QString &slug, const QString &status); [[nodiscard]] rpl::lifetime &lifetime(); private: class Button; struct Progress; struct WebviewWithLifetime; bool createWebview(const Webview::ThemeParams ¶ms); void createWebviewBottom(); void showWebviewProgress(); void hideWebviewProgress(); void setTitle(rpl::producer title); void sendDataMessage(const QJsonObject &args); void switchInlineQueryMessage(const QJsonObject &args); void processButtonMessage( std::unique_ptr