From 9735e1bceca921820277eefd097258c9df528b0a Mon Sep 17 00:00:00 2001 From: Michael Fabian 'Xaymar' Dirks Date: Mon, 13 Mar 2023 09:17:20 +0100 Subject: [PATCH] ui/obs-browser-widget: Pull in browser-panel.hpp to fix MacOS MacOS complains that QCefWidget is an undefined type, while all other compilers are fine. --- CMakeLists.txt | 3 ++ source/obs/browser/obs-browser-panel.hpp | 66 ++++++++++++++++++++++++ source/ui/ui-obs-browser-widget.cpp | 41 +++++++-------- source/ui/ui-obs-browser-widget.hpp | 13 ++--- 4 files changed, 94 insertions(+), 29 deletions(-) create mode 100644 source/obs/browser/obs-browser-panel.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 5df76db..6162ec8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1003,6 +1003,9 @@ endif() if(REQUIRE_OBS_FRONTEND_API AND obs-frontend-api_FOUND) list(APPEND PROJECT_LIBRARIES OBS::obs-frontend-api) + list(APPEND PROJECT_UI_SOURCE + "source/obs/browser/obs-browser-panel.hpp" + ) endif() if(REQUIRE_QT) diff --git a/source/obs/browser/obs-browser-panel.hpp b/source/obs/browser/obs-browser-panel.hpp new file mode 100644 index 0000000..29539b8 --- /dev/null +++ b/source/obs/browser/obs-browser-panel.hpp @@ -0,0 +1,66 @@ +// AUTOGENERATED COPYRIGHT HEADER START +// Copyright (C) 2023 Michael Fabian 'Xaymar' Dirks +// AUTOGENERATED COPYRIGHT HEADER END + +#pragma once +#include "warning-disable.hpp" +#include +#include +#include + +#include +#include + +#include +#include "warning-enable.hpp" + +namespace streamfx::obs { + struct QCefCookieManager { + virtual ~QCefCookieManager() {} + + virtual bool DeleteCookies(const std::string& url, const std::string& name) = 0; + virtual bool SetStoragePath(const std::string& storage_path, bool persist_session_cookies = false) = 0; + virtual bool FlushStore() = 0; + + typedef std::function cookie_exists_cb; + + virtual void CheckForCookie(const std::string& site, const std::string& cookie, cookie_exists_cb callback) = 0; + }; + + class QCefWidget : public QWidget { + Q_OBJECT + + protected: + inline QCefWidget(QWidget* parent) : QWidget(parent) {} + + public: + virtual void setURL(const std::string& url) = 0; + virtual void setStartupScript(const std::string& script) = 0; + virtual void allowAllPopups(bool allow) = 0; + virtual void closeBrowser() = 0; + virtual void reloadPage() = 0; + + signals: + void titleChanged(const QString& title); + void urlChanged(const QString& url); + }; + + struct QCef { + virtual ~QCef() {} + + virtual bool init_browser(void) = 0; + virtual bool initialized(void) = 0; + virtual bool wait_for_browser_init(void) = 0; + + virtual QCefWidget* create_widget(QWidget* parent, const std::string& url, + QCefCookieManager* cookie_manager = nullptr) = 0; + + virtual QCefCookieManager* create_cookie_manager(const std::string& storage_path, + bool persist_session_cookies = false) = 0; + + virtual BPtr get_cookie_path(const std::string& storage_path) = 0; + + virtual void add_popup_whitelist_url(const std::string& url, QObject* obj) = 0; + virtual void add_force_popup_url(const std::string& url, QObject* obj) = 0; + }; +} // namespace streamfx::obs diff --git a/source/ui/ui-obs-browser-widget.cpp b/source/ui/ui-obs-browser-widget.cpp index cf9e890..1a37124 100644 --- a/source/ui/ui-obs-browser-widget.cpp +++ b/source/ui/ui-obs-browser-widget.cpp @@ -8,8 +8,6 @@ #include #include -#include "../third-party/obs-studio/plugins/obs-browser/panel/browser-panel.hpp" - #include #include #ifdef D_PLATFORM_LINUX @@ -24,7 +22,7 @@ streamfx::ui::obs_browser_cef::obs_browser_cef() { // Load the "obs-browser" module. _module = util::library::load(obs_get_module("obs-browser")); - auto fn = reinterpret_cast(_module->load_symbol("obs_browser_create_qcef")); + auto fn = reinterpret_cast(_module->load_symbol("obs_browser_create_qcef")); if (!fn) { throw std::runtime_error("Failed to load obs-browser module."); } @@ -34,26 +32,25 @@ streamfx::ui::obs_browser_cef::obs_browser_cef() if (!_cef) { throw std::runtime_error("Failed to create or get QCef instance."); } - reinterpret_cast(_cef)->init_browser(); - reinterpret_cast(_cef)->wait_for_browser_init(); + _cef->init_browser(); + _cef->wait_for_browser_init(); // Create a generic Cookie manager for widgets. - _cookie = - reinterpret_cast(_cef)->create_cookie_manager(streamfx::config_file_path("cookies").u8string(), false); + _cookie = _cef->create_cookie_manager(streamfx::config_file_path("cookies").u8string(), false); } streamfx::ui::obs_browser_cef::~obs_browser_cef() { - delete reinterpret_cast(_cookie); - delete reinterpret_cast(_cef); + delete _cookie; + delete _cef; } -void* streamfx::ui::obs_browser_cef::cef() +streamfx::obs::QCef* streamfx::ui::obs_browser_cef::cef() { return _cef; } -void* streamfx::ui::obs_browser_cef::cookie_manager() +streamfx::obs::QCefCookieManager* streamfx::ui::obs_browser_cef::cookie_manager() { return _cookie; } @@ -82,13 +79,11 @@ streamfx::ui::obs_browser_widget::obs_browser_widget(QUrl url, QWidget* parent) // Create CEF Widget _cef = obs_browser_cef::instance(); - _widget = reinterpret_cast(_cef->cef()) - ->create_widget(this, url.toString().toStdString(), - reinterpret_cast(_cef->cookie_manager())); + _widget = _cef->cef()->create_widget(this, url.toString().toStdString(), _cef->cookie_manager()); if (!_widget) { throw std::runtime_error("Failed to create CEF Widget."); } - dynamic_cast(_widget)->allowAllPopups(false); + _widget->allowAllPopups(false); _widget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); layout->addWidget(_widget, 0, 0); @@ -101,24 +96,24 @@ streamfx::ui::obs_browser_widget::obs_browser_widget(QUrl url, QWidget* parent) streamfx::ui::obs_browser_widget::~obs_browser_widget() {} -QWidget* streamfx::ui::obs_browser_widget::cefwidget() +streamfx::obs::QCefWidget* streamfx::ui::obs_browser_widget::cefwidget() { return _widget; } void streamfx::ui::obs_browser_widget::set_url(QUrl url) { - dynamic_cast(_widget)->setURL(url.toString().toStdString()); + _widget->setURL(url.toString().toStdString()); } bool streamfx::ui::obs_browser_widget::is_available() { - #ifdef D_PLATFORM_LINUX +#ifdef D_PLATFORM_LINUX const char env_key[] = "XDG_SESSION_TYPE"; const char wayland[] = "wayland"; #ifdef __STDC_LIB_EXT1__ - char env_value[2048]; - size_t env_value_len = sizeof(env_value); + char env_value[2048]; + size_t env_value_len = sizeof(env_value); if (getenv_s(&env_value_len, env_value, sizeof(env_key), env_key) == 0) { if (sizeof(wayland) == env_value_len) { if (strncmp(wayland, env_value, sizeof(wayland)) == 0) { @@ -126,12 +121,12 @@ bool streamfx::ui::obs_browser_widget::is_available() } } } - #else +#else const char* env_value = getenv(env_key); if (strncmp(env_value, wayland, sizeof(wayland)) == 0) { return false; } - #endif - #endif +#endif +#endif return true; } diff --git a/source/ui/ui-obs-browser-widget.hpp b/source/ui/ui-obs-browser-widget.hpp index 56079ac..10cefec 100644 --- a/source/ui/ui-obs-browser-widget.hpp +++ b/source/ui/ui-obs-browser-widget.hpp @@ -10,14 +10,15 @@ #include #include "warning-enable.hpp" +#include "obs/browser/obs-browser-panel.hpp" #include "util/util-library.hpp" namespace streamfx::ui { class obs_browser_cef { std::shared_ptr<::streamfx::util::library> _module; - void* _cef; - void* _cookie; + streamfx::obs::QCef* _cef; + streamfx::obs::QCefCookieManager* _cookie; private: obs_browser_cef(); @@ -25,9 +26,9 @@ namespace streamfx::ui { public: ~obs_browser_cef(); - void* cef(); + streamfx::obs::QCef* cef(); - void* cookie_manager(); + streamfx::obs::QCefCookieManager* cookie_manager(); public: // Singleton static std::shared_ptr instance(); @@ -38,7 +39,7 @@ namespace streamfx::ui { private: std::shared_ptr _cef; - QWidget* _widget; + streamfx::obs::QCefWidget* _widget; public: obs_browser_widget(QUrl url, QWidget* parent = nullptr); @@ -46,7 +47,7 @@ namespace streamfx::ui { void set_url(QUrl url); - QWidget* cefwidget(); + streamfx::obs::QCefWidget* cefwidget(); public: static bool is_available();