// This file is part of Desktop App Toolkit, // a set of libraries for developing nice desktop applications. // // For license and copyright information please follow this link: // https://github.com/desktop-app/legal/blob/master/LEGAL // #pragma once #include "base/unique_qptr.h" #include "base/basic_types.h" #include "webview/webview_common.h" #include #include #include class QString; class QWidget; class QWindow; namespace Webview { extern const char kOptionWebviewDebugEnabled[]; extern const char kOptionWebviewLegacyEdge[]; struct DialogArgs; struct DialogResult; class Interface; class ZoomController; struct Config; struct DataRequest; enum class DataResult; struct NavigationHistoryState; struct WindowConfig { QColor opaqueBg; StorageId storageId; QString dataProtocolOverride; }; class Window final { public: explicit Window( QWidget *parent = nullptr, WindowConfig config = WindowConfig()); ~Window(); // May be nullptr or destroyed any time (in case webview crashed). [[nodiscard]] QWidget *widget() const; void updateTheme( QColor opaqueBg, QColor scrollBg, QColor scrollBgOver, QColor scrollBarBg, QColor scrollBarBgOver); void navigate(const QString &url); void navigateToData(const QString &id); void reload(); void setMessageHandler(Fn handler); void setMessageHandler(Fn handler); void setNavigationStartHandler(Fn handler); void setNavigationDoneHandler(Fn handler); void setDialogHandler(Fn handler); void setDataRequestHandler(Fn handler); void init(const QByteArray &js); void eval(const QByteArray &js); void focus(); void refreshNavigationHistoryState(); [[nodiscard]] auto navigationHistoryState() const -> rpl::producer; [[nodiscard]] ZoomController *zoomController() const; [[nodiscard]] rpl::lifetime &lifetime() { return _lifetime; } private: bool createWebView(QWidget *parent, const WindowConfig &config); [[nodiscard]] Fn messageHandler() const; [[nodiscard]] Fn navigationStartHandler() const; [[nodiscard]] Fn navigationDoneHandler() const; [[nodiscard]] Fn dialogHandler() const; [[nodiscard]] Fn dataRequestHandler() const; std::unique_ptr _webview; Fn _messageHandler; Fn _navigationStartHandler; Fn _navigationDoneHandler; Fn _dialogHandler; Fn _dataRequestHandler; rpl::lifetime _lifetime; }; } // namespace Webview