From 07255f14effd6e068b7925a8b2cdd840e9f0476b Mon Sep 17 00:00:00 2001 From: Matt Gajownik Date: Sun, 9 Jun 2024 15:41:52 +1000 Subject: [PATCH 01/38] Enable building with CEF 5938 on macOS At some point between 5563 and 5938, the parameter's type changed. --- browser-app.cpp | 4 ++++ browser-app.hpp | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/browser-app.cpp b/browser-app.cpp index 582b1c6ee..576a3f7b8 100644 --- a/browser-app.cpp +++ b/browser-app.cpp @@ -517,7 +517,11 @@ void ProcessCef() #define MAX_DELAY (1000 / 30) +#if CHROME_VERSION_BUILD < 5938 void BrowserApp::OnScheduleMessagePumpWork(int64 delay_ms) +#else +void BrowserApp::OnScheduleMessagePumpWork(int64_t delay_ms) +#endif { if (delay_ms < 0) delay_ms = 0; diff --git a/browser-app.hpp b/browser-app.hpp index e23156e02..035f13857 100644 --- a/browser-app.hpp +++ b/browser-app.hpp @@ -110,7 +110,11 @@ class BrowserApp : public CefApp, CefString &exception) override; #ifdef ENABLE_BROWSER_QT_LOOP +#if CHROME_VERSION_BUILD < 5938 virtual void OnScheduleMessagePumpWork(int64 delay_ms) override; +#else + virtual void OnScheduleMessagePumpWork(int64_t delay_ms) override; +#endif QTimer frameTimer; #endif From 5db6494a77093634ac664c81ff3a9cdd0b23b831 Mon Sep 17 00:00:00 2001 From: Matt Gajownik Date: Sun, 4 Feb 2024 23:12:55 +1100 Subject: [PATCH 02/38] Enable building with CEF 6261 This allows compiling OBS Browser with Chromium 122-based CEF versions. Sources: - https://github.com/chromiumembedded/cef/blame/d3a483ef59f8f40c624967361e05edda413bbf5b/libcef_dll/ctocpp/browser_ctocpp.h#L57 - https://bitbucket.org/chromiumembedded/cef/commits/f3b570c --- browser-app.cpp | 14 ++++++++++++-- obs-browser-page/obs-browser-page-main.cpp | 2 ++ obs-browser-plugin.cpp | 5 ++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/browser-app.cpp b/browser-app.cpp index 576a3f7b8..fb1c3a8a6 100644 --- a/browser-app.cpp +++ b/browser-app.cpp @@ -147,7 +147,12 @@ void BrowserApp::ExecuteJSFunction(CefRefPtr browser, std::vector names; browser->GetFrameNames(names); for (auto &name : names) { - CefRefPtr frame = browser->GetFrame(name); + CefRefPtr frame = +#if CHROME_VERSION_BUILD >= 6261 + browser->GetFrameByName(name); +#else + browser->GetFrame(name); +#endif CefRefPtr context = frame->GetV8Context(); context->Enter(); @@ -346,7 +351,12 @@ bool BrowserApp::OnProcessMessageReceived(CefRefPtr browser, std::vector names; browser->GetFrameNames(names); for (auto &name : names) { - CefRefPtr frame = browser->GetFrame(name); + CefRefPtr frame = +#if CHROME_VERSION_BUILD >= 6261 + browser->GetFrameByName(name); +#else + browser->GetFrame(name); +#endif CefRefPtr context = frame->GetV8Context(); context->Enter(); diff --git a/obs-browser-page/obs-browser-page-main.cpp b/obs-browser-page/obs-browser-page-main.cpp index 6a3906c5d..97bf0ee61 100644 --- a/obs-browser-page/obs-browser-page-main.cpp +++ b/obs-browser-page/obs-browser-page-main.cpp @@ -79,8 +79,10 @@ int CALLBACK WinMain(HINSTANCE, HINSTANCE, LPSTR, int) std::thread shutdown_check; CefMainArgs mainArgs(nullptr); +#if CHROME_VERSION_BUILD < 5615 if (!SetHighDPIv2Scaling()) CefEnableHighDPISupport(); +#endif CefRefPtr command_line = CefCommandLine::CreateCommandLine(); diff --git a/obs-browser-plugin.cpp b/obs-browser-plugin.cpp index 188958efe..8cf67e013 100644 --- a/obs-browser-plugin.cpp +++ b/obs-browser-plugin.cpp @@ -748,9 +748,12 @@ bool obs_module_load(void) os_event_init(&cef_started_event, OS_EVENT_TYPE_MANUAL); -#ifdef _WIN32 +#if defined(_WIN32) && CHROME_VERSION_BUILD < 5615 /* CefEnableHighDPISupport doesn't do anything on OS other than Windows. Would also crash macOS at this point as CEF is not directly linked */ CefEnableHighDPISupport(); +#endif + +#ifdef _WIN32 EnumAdapterCount(); #else #if defined(__APPLE__) && !defined(ENABLE_BROWSER_LEGACY) From 879a9d218361d6fd4a2b6c323f526507a6307976 Mon Sep 17 00:00:00 2001 From: Matt Gajownik Date: Sun, 28 Apr 2024 21:34:22 +1000 Subject: [PATCH 03/38] Enable building with CEF 6367 This allows compiling OBS Browser with Chromium 124-based CEF versions. This also enables basic support for the new, official, shared texture API, purely because building without it would be *more* difficult. Sources: - https://bitbucket.org/chromiumembedded/cef/commits/260dd0ca2 --- browser-client.cpp | 22 ++++++++++++++++++++-- browser-client.hpp | 12 ++++++++---- obs-browser-source.cpp | 2 +- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/browser-client.cpp b/browser-client.cpp index d91ca7024..1c0ca264e 100644 --- a/browser-client.cpp +++ b/browser-client.cpp @@ -373,7 +373,11 @@ void BrowserClient::UpdateExtraTexture() void BrowserClient::OnAcceleratedPaint(CefRefPtr, PaintElementType type, const RectList &, +#if CHROME_VERSION_BUILD >= 6367 + const CefAcceleratedPaintInfo &info) +#else void *shared_handle) +#endif { if (type != PET_VIEW) { // TODO Overlay texture on top of bs->texture @@ -384,7 +388,7 @@ void BrowserClient::OnAcceleratedPaint(CefRefPtr, return; } -#ifndef _WIN32 +#if !defined(_WIN32) && CHROME_VERSION_BUILD < 6367 if (shared_handle == bs->last_handle) return; #endif @@ -399,12 +403,20 @@ void BrowserClient::OnAcceleratedPaint(CefRefPtr, bs->texture = nullptr; } -#if defined(__APPLE__) && CHROME_VERSION_BUILD > 4183 +#if defined(__APPLE__) && CHROME_VERSION_BUILD > 6367 + bs->texture = gs_texture_create_from_iosurface( + (IOSurfaceRef)(uintptr_t)info.shared_texture_io_surface); +#elif defined(__APPLE__) && CHROME_VERSION_BUILD > 4183 bs->texture = gs_texture_create_from_iosurface( (IOSurfaceRef)(uintptr_t)shared_handle); #elif defined(_WIN32) && CHROME_VERSION_BUILD > 4183 bs->texture = +#if CHROME_VERSION_BUILD >= 6367 + gs_texture_open_nt_shared( + (uint32_t)(uintptr_t)info.shared_texture_handle); +#else gs_texture_open_nt_shared((uint32_t)(uintptr_t)shared_handle); +#endif //if (bs->texture) // gs_texture_acquire_sync(bs->texture, 1, INFINITE); @@ -415,7 +427,13 @@ void BrowserClient::OnAcceleratedPaint(CefRefPtr, UpdateExtraTexture(); obs_leave_graphics(); +#if defined(__APPLE__) && CHROME_VERSION_BUILD >= 6367 + bs->last_handle = info.shared_texture_io_surface; +#elif CHROME_VERSION_BUILD >= 6367 + bs->last_handle = info.shared_texture_handle; +#else bs->last_handle = shared_handle; +#endif } #ifdef CEF_ON_ACCELERATED_PAINT2 diff --git a/browser-client.hpp b/browser-client.hpp index cbff1201e..36dd5d89c 100644 --- a/browser-client.hpp +++ b/browser-client.hpp @@ -135,10 +135,14 @@ class BrowserClient : public CefClient, const void *buffer, int width, int height) override; #ifdef ENABLE_BROWSER_SHARED_TEXTURE - virtual void OnAcceleratedPaint(CefRefPtr browser, - PaintElementType type, - const RectList &dirtyRects, - void *shared_handle) override; + virtual void + OnAcceleratedPaint(CefRefPtr browser, PaintElementType type, + const RectList &dirtyRects, +#if CHROME_VERSION_BUILD >= 6367 + const CefAcceleratedPaintInfo &info) override; +#else + void *shared_handle) override; +#endif #ifdef CEF_ON_ACCELERATED_PAINT2 virtual void OnAcceleratedPaint2(CefRefPtr browser, PaintElementType type, diff --git a/obs-browser-source.cpp b/obs-browser-source.cpp index 09b301718..258bbcd86 100644 --- a/obs-browser-source.cpp +++ b/obs-browser-source.cpp @@ -658,7 +658,7 @@ extern void ProcessCef(); void BrowserSource::Render() { bool flip = false; -#ifdef ENABLE_BROWSER_SHARED_TEXTURE +#if defined(ENABLE_BROWSER_SHARED_TEXTURE) && CHROME_VERSION_BUILD < 6367 flip = hwaccel; #endif From 75d3eb113714985743cd14176b0c82ce25798ede Mon Sep 17 00:00:00 2001 From: Matt Gajownik Date: Wed, 31 Jul 2024 20:44:10 +1000 Subject: [PATCH 04/38] Update version to 2.24.0 --- browser-version.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/browser-version.h b/browser-version.h index eebde628e..fea2874a3 100644 --- a/browser-version.h +++ b/browser-version.h @@ -1,8 +1,8 @@ #pragma once #define OBS_BROWSER_VERSION_MAJOR 2 -#define OBS_BROWSER_VERSION_MINOR 23 -#define OBS_BROWSER_VERSION_PATCH 5 +#define OBS_BROWSER_VERSION_MINOR 24 +#define OBS_BROWSER_VERSION_PATCH 0 #ifndef MAKE_SEMANTIC_VERSION #define MAKE_SEMANTIC_VERSION(major, minor, patch) \ From d18fc7a747a0e068468ec1def31cd611d5c362e2 Mon Sep 17 00:00:00 2001 From: Matt Gajownik Date: Thu, 1 Aug 2024 19:31:56 +1000 Subject: [PATCH 05/38] Enable building with CEF 6533 & 6613 Chromium 128 removes the `persist_user_preferences` setting entirely. Chrome runtime is used by default, so to disable 'Cast..' and more, explicitly use the Alloy runtime. DevTools popups can no longer be windowless. --- obs-browser-plugin.cpp | 2 ++ panel/browser-panel-client.cpp | 2 +- panel/browser-panel.cpp | 8 ++++++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/obs-browser-plugin.cpp b/obs-browser-plugin.cpp index 8cf67e013..09ff8a37e 100644 --- a/obs-browser-plugin.cpp +++ b/obs-browser-plugin.cpp @@ -366,7 +366,9 @@ static void BrowserInit(void) BPtr conf_path_abs = os_get_abs_path_ptr(conf_path); CefString(&settings.locale) = obs_get_locale(); CefString(&settings.accept_language_list) = accepted_languages; +#if CHROME_VERSION_BUILD <= 6533 settings.persist_user_preferences = 1; +#endif CefString(&settings.cache_path) = conf_path_abs; #if !defined(__APPLE__) || defined(ENABLE_BROWSER_LEGACY) char *abs_path = os_get_abs_path_ptr(path.c_str()); diff --git a/panel/browser-panel-client.cpp b/panel/browser-panel-client.cpp index 202e15f52..bd7eedc7c 100644 --- a/panel/browser-panel-client.cpp +++ b/panel/browser-panel-client.cpp @@ -348,7 +348,7 @@ bool QCefBrowserClient::OnContextMenuCommand( QString title; switch (command_id) { case MENU_ITEM_DEVTOOLS: -#if defined(_WIN32) +#if defined(_WIN32) && CHROME_VERSION_BUILD < 6533 title = QString(obs_module_text("DevTools")) .arg(widget->parentWidget()->windowTitle()); windowInfo.SetAsPopup(host->GetWindowHandle(), diff --git a/panel/browser-panel.cpp b/panel/browser-panel.cpp index 45282a711..9e635c1d5 100644 --- a/panel/browser-panel.cpp +++ b/panel/browser-panel.cpp @@ -84,7 +84,9 @@ struct QCefCookieManagerInternal : QCefCookieManager { BPtr path = os_get_abs_path_ptr(rpath.Get()); CefRequestContextSettings settings; +#if CHROME_VERSION_BUILD <= 6533 settings.persist_user_preferences = 1; +#endif CefString(&settings.cache_path) = path.Get(); rc = CefRequestContext::CreateContext( settings, CefRefPtr()); @@ -107,7 +109,9 @@ struct QCefCookieManagerInternal : QCefCookieManager { BPtr path = os_get_abs_path_ptr(rpath.Get()); CefRequestContextSettings settings; +#if CHROME_VERSION_BUILD <= 6533 settings.persist_user_preferences = 1; +#endif CefString(&settings.cache_path) = storage_path; rc = CefRequestContext::CreateContext( settings, CefRefPtr()); @@ -314,6 +318,10 @@ void QCefWidgetInternal::Init() QSize size = this->size(); #endif +#if CHROME_VERSION_BUILD >= 6533 + windowInfo.runtime_style = CEF_RUNTIME_STYLE_ALLOY; +#endif + #if CHROME_VERSION_BUILD < 4430 #ifdef __APPLE__ windowInfo.SetAsChild((CefWindowHandle)handle, 0, 0, From 22db20b694c144286d4e09d2ca3a148c6b495379 Mon Sep 17 00:00:00 2001 From: vvto33 <54504675+vvto33@users.noreply.github.com> Date: Thu, 1 Aug 2024 23:47:11 +0900 Subject: [PATCH 06/38] Fix CSS injection for sites with strict CSP This fix addresses an issue occurring on some pages where the response header includes `content-security-policy: require-trusted-types-for 'script'`. --- browser-client.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/browser-client.cpp b/browser-client.cpp index 1c0ca264e..4bd478091 100644 --- a/browser-client.cpp +++ b/browser-client.cpp @@ -679,8 +679,9 @@ void BrowserClient::OnLoadEnd(CefRefPtr, CefRefPtr frame, std::string script; script += "const obsCSS = document.createElement('style');"; - script += "obsCSS.innerHTML = decodeURIComponent(\"" + - uriEncodedCSS + "\");"; + script += "obsCSS.appendChild(document.createTextNode(" + "decodeURIComponent(\"" + + uriEncodedCSS + "\")));"; script += "document.querySelector('head').appendChild(obsCSS);"; frame->ExecuteJavaScript(script, "", 0); From be9f1b646406d2250b402581b043f1558042d7f0 Mon Sep 17 00:00:00 2001 From: Ryan Foster Date: Wed, 14 Aug 2024 14:36:43 -0400 Subject: [PATCH 07/38] Update version to 2.24.1 --- browser-version.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/browser-version.h b/browser-version.h index fea2874a3..2376acc2c 100644 --- a/browser-version.h +++ b/browser-version.h @@ -2,7 +2,7 @@ #define OBS_BROWSER_VERSION_MAJOR 2 #define OBS_BROWSER_VERSION_MINOR 24 -#define OBS_BROWSER_VERSION_PATCH 0 +#define OBS_BROWSER_VERSION_PATCH 1 #ifndef MAKE_SEMANTIC_VERSION #define MAKE_SEMANTIC_VERSION(major, minor, patch) \ From 98d94a432264c1754e4dea1501a5ce36b04b1718 Mon Sep 17 00:00:00 2001 From: tytan652 Date: Thu, 1 Aug 2024 14:45:34 +0200 Subject: [PATCH 08/38] Enable Qt message loop on Linux This fixes issues cause by building CEF with use_gtk=true which is the default. --- cmake/os-linux.cmake | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cmake/os-linux.cmake b/cmake/os-linux.cmake index 7c95a9efe..d80f9d4ad 100644 --- a/cmake/os-linux.cmake +++ b/cmake/os-linux.cmake @@ -1,5 +1,7 @@ find_package(X11 REQUIRED) +target_compile_definitions(obs-browser PRIVATE ENABLE_BROWSER_QT_LOOP) + target_link_libraries(obs-browser PRIVATE CEF::Wrapper CEF::Library X11::X11) set_target_properties(obs-browser PROPERTIES BUILD_RPATH "$ORIGIN/" INSTALL_RPATH "$ORIGIN/") From 8e2b31f53b8a43cd816e37b4abae6d43de941207 Mon Sep 17 00:00:00 2001 From: tytan652 Date: Thu, 1 Aug 2024 15:13:32 +0200 Subject: [PATCH 09/38] Set the right Ozone platform on Linux Forcing CEF to use the right Ozone platform allows to avoid having a dependency on XWayland (a X11 socket) under Wayland. --- browser-app.cpp | 3 +++ browser-app.hpp | 10 ++++++++++ obs-browser-plugin.cpp | 10 ++++++++++ 3 files changed, 23 insertions(+) diff --git a/browser-app.cpp b/browser-app.cpp index fb1c3a8a6..af8a3442d 100644 --- a/browser-app.cpp +++ b/browser-app.cpp @@ -96,6 +96,9 @@ void BrowserApp::OnBeforeCommandLineProcessing( "no-user-gesture-required"); #ifdef __APPLE__ command_line->AppendSwitch("use-mock-keychain"); +#elif !defined(_WIN32) + command_line->AppendSwitchWithValue("ozone-platform", + wayland ? "wayland" : "x11"); #endif } diff --git a/browser-app.hpp b/browser-app.hpp index 035f13857..241e233c9 100644 --- a/browser-app.hpp +++ b/browser-app.hpp @@ -77,10 +77,20 @@ class BrowserApp : public CefApp, bool shared_texture_available; CallbackMap callbackMap; int callbackId; +#if !defined(__APPLE__) && !defined(_WIN32) + bool wayland; +#endif public: +#if defined(__APPLE__) || defined(_WIN32) inline BrowserApp(bool shared_texture_available_ = false) : shared_texture_available(shared_texture_available_) +#else + inline BrowserApp(bool shared_texture_available_ = false, + bool wayland_ = false) + : shared_texture_available(shared_texture_available_), + wayland(wayland_) +#endif { } diff --git a/obs-browser-plugin.cpp b/obs-browser-plugin.cpp index 09ff8a37e..0278089b5 100644 --- a/obs-browser-plugin.cpp +++ b/obs-browser-plugin.cpp @@ -46,6 +46,10 @@ #include "signal-restore.hpp" #endif +#ifdef ENABLE_WAYLAND +#include +#endif + #ifdef ENABLE_BROWSER_QT_LOOP #include #include @@ -386,7 +390,13 @@ static void BrowserInit(void) } #endif +#if defined(__APPLE__) || defined(_WIN32) || !defined(ENABLE_WAYLAND) app = new BrowserApp(tex_sharing_avail); +#else + app = new BrowserApp(tex_sharing_avail, + obs_get_nix_platform() == + OBS_NIX_PLATFORM_WAYLAND); +#endif #ifdef _WIN32 CefExecuteProcess(args, app, nullptr); From 64519418a8cdab7f3bb4695c31e13ed11013ff03 Mon Sep 17 00:00:00 2001 From: Matt Gajownik Date: Sun, 18 Aug 2024 18:37:21 +1000 Subject: [PATCH 10/38] Wait on shutdown for docks to close on Linux Temporary solution to allow a CEF upgrade. Ideally we should track open docks & count `OnBeforeClose` calls. --- panel/browser-panel.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/panel/browser-panel.cpp b/panel/browser-panel.cpp index 9e635c1d5..6df9c2b06 100644 --- a/panel/browser-panel.cpp +++ b/panel/browser-panel.cpp @@ -181,6 +181,12 @@ void QCefWidgetInternal::closeBrowser() } cefBrowser->GetHost()->CloseBrowser(true); + +#if !defined(_WIN32) && !defined(__APPLE__) && CHROME_VERSION_BUILD >= 6533 + while (cefBrowser && cefBrowser->IsValid()) { + os_sleep_ms(10); + } +#endif }; /* So you're probably wondering what's going on here. If you From 174e6a80172ca531d20afc376194cc13b3bb4464 Mon Sep 17 00:00:00 2001 From: tytan652 Date: Thu, 29 Aug 2024 09:39:44 +0200 Subject: [PATCH 11/38] Remove CMake legacy code path --- CMakeLists.txt | 2 - FindCEF.cmake | 160 --------------------------- cmake/legacy.cmake | 261 --------------------------------------------- 3 files changed, 423 deletions(-) delete mode 100644 FindCEF.cmake delete mode 100644 cmake/legacy.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 240d1d6cf..0d669744f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,5 @@ cmake_minimum_required(VERSION 3.16...3.25) -legacy_check() - option(ENABLE_BROWSER "Enable browser source plugin (required Chromium Embedded Framework)" OFF) if(NOT ENABLE_BROWSER) diff --git a/FindCEF.cmake b/FindCEF.cmake deleted file mode 100644 index 00d020328..000000000 --- a/FindCEF.cmake +++ /dev/null @@ -1,160 +0,0 @@ -include(FindPackageHandleStandardArgs) - -set_property(CACHE CEF_ROOT_DIR PROPERTY HELPSTRING - "Path to CEF distributed build") -if(NOT DEFINED CEF_ROOT_DIR OR CEF_ROOT_DIR STREQUAL "") - message( - FATAL_ERROR - "CEF_ROOT_DIR is not set - if ENABLE_BROWSER is enabled, a CEF distribution with compiled wrapper library is required.\n" - "Please download a CEF distribution for your appropriate architecture and specify CEF_ROOT_DIR to its location" - ) -endif() - -find_path(CEF_INCLUDE_DIR "include/cef_version.h" HINTS "${CEF_ROOT_DIR}") - -if(OS_MACOS) - find_library( - CEF_LIBRARY - NAMES cef libcef cef.lib libcef.o "Chromium Embedded Framework" - NO_DEFAULT_PATH - PATHS "${CEF_ROOT_DIR}" "${CEF_ROOT_DIR}/Release") - - find_library( - CEFWRAPPER_LIBRARY - NAMES cef_dll_wrapper libcef_dll_wrapper - NO_DEFAULT_PATH - PATHS "${CEF_ROOT_DIR}/build/libcef_dll/Release" - "${CEF_ROOT_DIR}/build/libcef_dll_wrapper/Release" - "${CEF_ROOT_DIR}/build/libcef_dll" - "${CEF_ROOT_DIR}/build/libcef_dll_wrapper") - -elseif(OS_POSIX) - find_library( - CEF_LIBRARY - NAMES libcef.so "Chromium Embedded Framework" - NO_DEFAULT_PATH - PATHS "${CEF_ROOT_DIR}" "${CEF_ROOT_DIR}/Release") - - find_library( - CEFWRAPPER_LIBRARY - NAMES libcef_dll_wrapper.a - NO_DEFAULT_PATH - PATHS "${CEF_ROOT_DIR}/build/libcef_dll_wrapper" - "${CEF_ROOT_DIR}/libcef_dll_wrapper") - -else() - find_library( - CEF_LIBRARY - NAMES cef libcef cef.lib libcef.o "Chromium Embedded Framework" - PATHS "${CEF_ROOT_DIR}" "${CEF_ROOT_DIR}/Release") - - find_library( - CEFWRAPPER_LIBRARY - NAMES cef_dll_wrapper libcef_dll_wrapper - PATHS "${CEF_ROOT_DIR}/build/libcef_dll/Release" - "${CEF_ROOT_DIR}/build/libcef_dll_wrapper/Release" - "${CEF_ROOT_DIR}/build/libcef_dll" - "${CEF_ROOT_DIR}/build/libcef_dll_wrapper") - - if(OS_WINDOWS) - find_library( - CEFWRAPPER_LIBRARY_DEBUG - NAMES cef_dll_wrapper libcef_dll_wrapper - PATHS "${CEF_ROOT_DIR}/build/libcef_dll/Debug" - "${CEF_ROOT_DIR}/build/libcef_dll_wrapper/Debug") - endif() -endif() - -mark_as_advanced(CEFWRAPPER_LIBRARY CEFWRAPPER_LIBRARY_DEBUG) - -if(NOT CEF_LIBRARY) - message( - WARNING - " Could NOT find Chromium Embedded Framework library (missing: CEF_LIBRARY)" - ) - set(CEF_FOUND FALSE) - return() -endif() - -if(NOT CEFWRAPPER_LIBRARY) - message( - WARNING - " Could NOT find Chromium Embedded Framework wrapper library (missing: CEFWRAPPER_LIBRARY)" - ) - set(CEF_FOUND FALSE) - return() -endif() - -message( - STATUS - "Found Chromium Embedded Framework: ${CEF_LIBRARY};${CEF_WRAPPER_LIBRARY}") - -if(OS_WINDOWS) - set(CEF_LIBRARIES ${CEF_LIBRARY} ${CEFWRAPPER_LIBRARY}) - -elseif(OS_MACOS) - if(BROWSER_LEGACY) - set(CEF_LIBRARIES ${CEFWRAPPER_LIBRARY} ${CEF_LIBRARY}) - else() - set(CEF_LIBRARIES ${CEFWRAPPER_LIBRARY}) - endif() -else() - set(CEF_LIBRARIES ${CEF_LIBRARY} optimized ${CEFWRAPPER_LIBRARY}) - - if(CEFWRAPPER_LIBRARY_DEBUG) - list(APPEND CEF_LIBRARIES debug ${CEFWRAPPER_LIBRARY_DEBUG}) - endif() -endif() - -find_package_handle_standard_args(CEF DEFAULT_MSG CEF_LIBRARY - CEFWRAPPER_LIBRARY CEF_INCLUDE_DIR) - -mark_as_advanced(CEF_LIBRARY CEF_WRAPPER_LIBRARY CEF_LIBRARIES CEF_INCLUDE_DIR) - -if(NOT TARGET CEF::Wrapper) - if(IS_ABSOLUTE "${CEF_LIBRARIES}") - add_library(CEF::Wrapper UNKNOWN IMPORTED) - add_library(CEF::Library UNKNOWN IMPORTED) - - set_target_properties(CEF::Wrapper PROPERTIES IMPORTED_LOCATION - ${CEFWRAPPER_LIBRARY}) - - set_target_properties(CEF::Library PROPERTIES IMPORTED_LOCATION - ${CEF_LIBRARY}) - - if(DEFINED CEFWRAPPER_LIBRARY_DEBUG) - add_library(CEF::Wrapper_Debug UNKNOWN IMPORTED) - set_target_properties( - CEF::Wrapper_Debug PROPERTIES IMPORTED_LOCATION - ${CEFWRAPPER_LIBRARY_DEBUG}) - endif() - else() - add_library(CEF::Wrapper INTERFACE IMPORTED) - add_library(CEF::Library INTERFACE IMPORTED) - - set_target_properties(CEF::Wrapper PROPERTIES IMPORTED_LIBNAME - ${CEFWRAPPER_LIBRARY}) - - set_target_properties(CEF::Library PROPERTIES IMPORTED_LIBNAME - ${CEF_LIBRARY}) - - if(DEFINED CEFWRAPPER_LIBRARY_DEBUG) - add_library(CEF::Wrapper_Debug INTERFACE IMPORTED) - set_target_properties( - CEF::Wrapper_Debug PROPERTIES IMPORTED_LIBNAME - ${CEFWRAPPER_LIBRARY_DEBUG}) - endif() - endif() - - set_target_properties(CEF::Wrapper PROPERTIES INTERFACE_INCLUDE_DIRECTORIES - "${CEF_INCLUDE_DIR}") - - set_target_properties(CEF::Library PROPERTIES INTERFACE_INCLUDE_DIRECTORIES - "${CEF_INCLUDE_DIR}") - - if(DEFINED CEFWRAPPER_LIBRARY_DEBUG) - set_target_properties( - CEF::Wrapper_Debug PROPERTIES INTERFACE_INCLUDE_DIRECTORIES - "${CEF_INCLUDE_DIR}") - endif() -endif() diff --git a/cmake/legacy.cmake b/cmake/legacy.cmake deleted file mode 100644 index 6560de8a6..000000000 --- a/cmake/legacy.cmake +++ /dev/null @@ -1,261 +0,0 @@ -project(obs-browser) - -option(ENABLE_BROWSER "Enable building OBS with browser source plugin (required Chromium Embedded Framework)" - ${OS_LINUX}) - -if(NOT ENABLE_BROWSER OR NOT ENABLE_UI) - message(STATUS "OBS: DISABLED obs-browser") - message( - WARNING - "Browser source support is not enabled by default - please switch ENABLE_BROWSER to ON and specify CEF_ROOT_DIR to enable this functionality." - ) - return() -endif() - -if(OS_WINDOWS) - option(ENABLE_BROWSER_LEGACY "Use legacy CEF version 3770 for browser source plugin" OFF) -endif() - -if(OS_MACOS OR OS_WINDOWS) - option(ENABLE_BROWSER_SHARED_TEXTURE "Enable shared texture support for browser source plugin" ON) -endif() - -option(ENABLE_BROWSER_PANELS "Enable Qt web browser panel support" ON) -option(ENABLE_BROWSER_QT_LOOP "Enable running CEF on the main UI thread alongside Qt" ${OS_MACOS}) - -mark_as_advanced(ENABLE_BROWSER_LEGACY ENABLE_BROWSER_SHARED_TEXTURE ENABLE_BROWSER_PANELS ENABLE_BROWSER_QT_LOOP) - -find_package(CEF REQUIRED 95) - -if(NOT TARGET CEF::Wrapper) - message( - FATAL_ERROR "OBS: - Unable to find CEF Libraries - set CEF_ROOT_DIR or configure with ENABLE_BROWSER=OFF") -endif() - -find_package(nlohmann_json REQUIRED) - -add_library(obs-browser MODULE) -add_library(OBS::browser ALIAS obs-browser) - -if(ENABLE_BROWSER_LEGACY) - target_compile_definitions(obs-browser PRIVATE ENABLE_BROWSER_LEGACY) -endif() - -if(ENABLE_BROWSER_SHARED_TEXTURE) - target_compile_definitions(obs-browser PRIVATE ENABLE_BROWSER_SHARED_TEXTURE) -endif() - -if(ENABLE_BROWSER_QT_LOOP) - target_compile_definitions(obs-browser PRIVATE ENABLE_BROWSER_QT_LOOP) -endif() - -configure_file(${CMAKE_CURRENT_SOURCE_DIR}/browser-config.h.in ${CMAKE_BINARY_DIR}/config/browser-config.h) - -target_sources( - obs-browser - PRIVATE obs-browser-plugin.cpp - obs-browser-source.cpp - obs-browser-source.hpp - obs-browser-source-audio.cpp - browser-app.cpp - browser-app.hpp - browser-client.cpp - browser-client.hpp - browser-scheme.cpp - browser-scheme.hpp - browser-version.h - cef-headers.hpp - deps/base64/base64.cpp - deps/base64/base64.hpp - deps/wide-string.cpp - deps/wide-string.hpp - deps/signal-restore.cpp - deps/signal-restore.hpp - deps/obs-websocket-api/obs-websocket-api.h - ${CMAKE_BINARY_DIR}/config/browser-config.h) - -target_include_directories(obs-browser PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/deps ${CMAKE_BINARY_DIR}/config) - -target_link_libraries(obs-browser PRIVATE OBS::libobs OBS::frontend-api nlohmann_json::nlohmann_json) - -target_compile_features(obs-browser PRIVATE cxx_std_17) - -if(ENABLE_BROWSER_PANELS OR ENABLE_BROWSER_QT_LOOP) - find_qt(COMPONENTS Widgets) - - set_target_properties( - obs-browser - PROPERTIES AUTOMOC ON - AUTOUIC ON - AUTORCC ON) - - target_link_libraries(obs-browser PRIVATE Qt::Widgets) -endif() - -if(NOT OS_MACOS OR ENABLE_BROWSER_LEGACY) - add_executable(obs-browser-page) - - target_sources(obs-browser-page PRIVATE cef-headers.hpp obs-browser-page/obs-browser-page-main.cpp browser-app.cpp - browser-app.hpp) - - target_link_libraries(obs-browser-page PRIVATE CEF::Library nlohmann_json::nlohmann_json) - - target_include_directories(obs-browser-page PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/deps - ${CMAKE_CURRENT_SOURCE_DIR}/obs-browser-page) - - target_compile_features(obs-browser-page PRIVATE cxx_std_17) - - if(OS_WINDOWS) - - if(TARGET CEF::Wrapper_Debug) - target_link_libraries(obs-browser-page PRIVATE optimized CEF::Wrapper) - target_link_libraries(obs-browser-page PRIVATE debug CEF::Wrapper_Debug) - else() - target_link_libraries(obs-browser-page PRIVATE CEF::Wrapper) - endif() - - target_sources(obs-browser-page PRIVATE obs-browser-page.manifest) - else() - target_link_libraries(obs-browser-page PRIVATE CEF::Wrapper) - endif() - - if(ENABLE_BROWSER_LEGACY) - target_compile_definitions(obs-browser-page PRIVATE ENABLE_BROWSER_LEGACY) - endif() - - if(ENABLE_BROWSER_SHARED_TEXTURE) - target_compile_definitions(obs-browser-page PRIVATE ENABLE_BROWSER_SHARED_TEXTURE) - endif() - - if(ENABLE_BROWSER_QT_LOOP) - target_compile_definitions(obs-browser-page PRIVATE ENABLE_BROWSER_QT_LOOP) - endif() - - set_target_properties(obs-browser-page PROPERTIES FOLDER "plugins/obs-browser") - - setup_plugin_target(obs-browser-page) -endif() - -if(OS_WINDOWS) - if(MSVC) - target_compile_options(obs-browser PRIVATE $,/MTd,/MT>) - - target_compile_options(obs-browser-page PRIVATE $,/MTd,/MT>) - endif() - - target_link_libraries(obs-browser PRIVATE CEF::Library d3d11 dxgi) - - if(TARGET CEF::Wrapper_Debug) - target_link_libraries(obs-browser PRIVATE optimized CEF::Wrapper) - target_link_libraries(obs-browser PRIVATE debug CEF::Wrapper_Debug) - else() - target_link_libraries(obs-browser PRIVATE CEF::Wrapper) - endif() - - target_link_options(obs-browser PRIVATE "LINKER:/IGNORE:4099") - - target_link_options(obs-browser-page PRIVATE "LINKER:/IGNORE:4099" "LINKER:/SUBSYSTEM:WINDOWS") - - list(APPEND obs-browser_LIBRARIES d3d11 dxgi) - -elseif(OS_MACOS) - find_library(COREFOUNDATION CoreFoundation) - find_library(APPKIT AppKit) - mark_as_advanced(COREFOUNDATION APPKIT) - - target_link_libraries(obs-browser PRIVATE ${COREFOUNDATION} ${APPKIT} CEF::Wrapper) - - target_sources(obs-browser PRIVATE macutil.mm) - - set(CEF_HELPER_TARGET "obs-browser-helper") - set(CEF_HELPER_OUTPUT_NAME "OBS Helper") - set(CEF_HELPER_APP_SUFFIXES "::" " (GPU):_gpu:.gpu" " (Plugin):_plugin:.plugin" " (Renderer):_renderer:.renderer") - - foreach(_SUFFIXES ${CEF_HELPER_APP_SUFFIXES}) - string(REPLACE ":" ";" _SUFFIXES ${_SUFFIXES}) - list(GET _SUFFIXES 0 _NAME_SUFFIX) - list(GET _SUFFIXES 1 _TARGET_SUFFIX) - list(GET _SUFFIXES 2 _PLIST_SUFFIX) - - set(_HELPER_TARGET "${CEF_HELPER_TARGET}${_TARGET_SUFFIX}") - set(_HELPER_OUTPUT_NAME "${CEF_HELPER_OUTPUT_NAME}${_NAME_SUFFIX}") - - set(_HELPER_INFO_PLIST "${CMAKE_CURRENT_BINARY_DIR}/helper-info${_PLIST_SUFFIX}.plist") - file(READ "${CMAKE_CURRENT_SOURCE_DIR}/helper-info.plist" _PLIST_CONTENTS) - string(REPLACE "\${EXECUTABLE_NAME}" "${_HELPER_OUTPUT_NAME}" _PLIST_CONTENTS ${_PLIST_CONTENTS}) - string(REPLACE "\${PRODUCT_NAME}" "${_HELPER_OUTPUT_NAME}" _PLIST_CONTENTS ${_PLIST_CONTENTS}) - string(REPLACE "\${BUNDLE_ID_SUFFIX}" "${_PLIST_SUFFIX}" _PLIST_CONTENTS ${_PLIST_CONTENTS}) - string(REPLACE "\${MINIMUM_VERSION}" "${CMAKE_OSX_DEPLOYMENT_TARGET}" _PLIST_CONTENTS ${_PLIST_CONTENTS}) - string(REPLACE "\${CURRENT_YEAR}" "${CURRENT_YEAR}" _PLIST_CONTENTS ${_PLIST_CONTENTS}) - file(WRITE ${_HELPER_INFO_PLIST} ${_PLIST_CONTENTS}) - - set(MACOSX_BUNDLE_GUI_IDENTIFIER "${MACOSX_BUNDLE_GUI_IDENTIFIER}.helper${_PLIST_SUFFIX}") - - add_executable(${_HELPER_TARGET} MACOSX_BUNDLE) - add_executable(OBS::browser-helper${_TARGET_SUFFIX} ALIAS ${_HELPER_TARGET}) - target_sources(${_HELPER_TARGET} PRIVATE browser-app.cpp browser-app.hpp obs-browser-page/obs-browser-page-main.cpp - cef-headers.hpp) - - target_link_libraries(${_HELPER_TARGET} PRIVATE CEF::Wrapper nlohmann_json::nlohmann_json) - - target_include_directories(${_HELPER_TARGET} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/deps - ${CMAKE_CURRENT_SOURCE_DIR}/obs-browser-page) - - target_compile_features(${_HELPER_TARGET} PRIVATE cxx_std_17) - - if(ENABLE_BROWSER_SHARED_TEXTURE) - target_compile_definitions(${_HELPER_TARGET} PRIVATE ENABLE_BROWSER_SHARED_TEXTURE) - endif() - - set_target_properties( - ${_HELPER_TARGET} - PROPERTIES MACOSX_BUNDLE_INFO_PLIST ${_HELPER_INFO_PLIST} - OUTPUT_NAME ${_HELPER_OUTPUT_NAME} - FOLDER "plugins/obs-browser/helpers/" - XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER "com.obsproject.obs-studio.helper${_PLIST_SUFFIX}" - XCODE_ATTRIBUTE_CODE_SIGN_ENTITLEMENTS - "${CMAKE_SOURCE_DIR}/cmake/bundle/macOS/entitlements-helper${_PLIST_SUFFIX}.plist") - endforeach() - -elseif(OS_POSIX) - find_package(X11 REQUIRED) - - target_link_libraries(obs-browser PRIVATE CEF::Wrapper CEF::Library X11::X11) - - get_target_property(_CEF_DIRECTORY CEF::Library INTERFACE_LINK_DIRECTORIES) - - set_target_properties(obs-browser PROPERTIES BUILD_RPATH "$ORIGIN/") - - set_target_properties(obs-browser-page PROPERTIES BUILD_RPATH "$ORIGIN/") - - set_target_properties(obs-browser PROPERTIES INSTALL_RPATH "$ORIGIN/") - set_target_properties(obs-browser-page PROPERTIES INSTALL_RPATH "$ORIGIN/") -endif() - -if(ENABLE_BROWSER_PANELS) - add_library(obs-browser-panels INTERFACE) - add_library(OBS::browser-panels ALIAS obs-browser-panels) - target_sources( - obs-browser-panels INTERFACE panel/browser-panel.cpp panel/browser-panel.hpp panel/browser-panel-client.cpp - panel/browser-panel-client.hpp panel/browser-panel-internal.hpp) - - target_include_directories(obs-browser-panels INTERFACE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/panel) - - target_link_libraries(obs-browser-panels INTERFACE CEF::Wrapper) - - if(OS_MACOS) - target_link_libraries(obs-browser-panels INTERFACE objc) - endif() - - target_link_libraries(obs-browser PRIVATE obs-browser-panels) - - target_compile_definitions(obs-browser-panels INTERFACE BROWSER_AVAILABLE) - - if(ENABLE_BROWSER_QT_LOOP) - target_compile_definitions(obs-browser-panels INTERFACE ENABLE_BROWSER_QT_LOOP) - endif() -endif() - -set_target_properties(obs-browser PROPERTIES FOLDER "plugins/obs-browser" PREFIX "") - -setup_plugin_target(obs-browser) From e4e523df775bd6fa216d40a7488b76f3b21c1733 Mon Sep 17 00:00:00 2001 From: Ryan Foster Date: Fri, 30 Aug 2024 18:22:13 -0400 Subject: [PATCH 12/38] Update version to 2.24.2 --- browser-version.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/browser-version.h b/browser-version.h index 2376acc2c..5158b6590 100644 --- a/browser-version.h +++ b/browser-version.h @@ -2,7 +2,7 @@ #define OBS_BROWSER_VERSION_MAJOR 2 #define OBS_BROWSER_VERSION_MINOR 24 -#define OBS_BROWSER_VERSION_PATCH 1 +#define OBS_BROWSER_VERSION_PATCH 2 #ifndef MAKE_SEMANTIC_VERSION #define MAKE_SEMANTIC_VERSION(major, minor, patch) \ From c794b64be90c87387973098ca012a7f79483e1ff Mon Sep 17 00:00:00 2001 From: Translation Updater <> Date: Fri, 4 Oct 2024 23:09:26 +0000 Subject: [PATCH 13/38] Update translations from Crowdin --- data/locale/de-DE.ini | 2 +- data/locale/et-EE.ini | 5 +++++ data/locale/gl-ES.ini | 8 ++++++++ data/locale/he-IL.ini | 4 ++-- data/locale/id-ID.ini | 2 +- data/locale/th-TH.ini | 2 +- data/locale/tt-RU.ini | 2 ++ data/locale/ug-CN.ini | 4 ++-- 8 files changed, 22 insertions(+), 7 deletions(-) diff --git a/data/locale/de-DE.ini b/data/locale/de-DE.ini index 57b867ebf..f2f7fe9dd 100644 --- a/data/locale/de-DE.ini +++ b/data/locale/de-DE.ini @@ -38,4 +38,4 @@ ErrorCode.ERR_FAILED="Verbindung fehlgeschlagen" ErrorCode.ERR_NETWORK_CHANGED="Netzwerk geändert" ErrorCode.ERR_SSL_VERSION_INTERFERENCE="SSL-Versionsinterferenz. TLS 1.3 ist möglicherweise blockiert oder verändert." ErrorCode.ERR_SSL_PROTOCOL_ERROR="SSL-Protokollfehler. Es konnte keine sichere Verbindung hergestellt werden." -ErrorCode.ERR_CERT_DATE_INVALID="Entweder ist das SSL-Zertifikat des Servers veraltet oder die Uhrzeit Ihres Computers falsch." +ErrorCode.ERR_CERT_DATE_INVALID="Entweder ist das SSL-Zertifikat des Servers veraltet oder die Uhrzeit Ihres Computers nicht korrekt." diff --git a/data/locale/et-EE.ini b/data/locale/et-EE.ini index 95f44c4a3..058493940 100644 --- a/data/locale/et-EE.ini +++ b/data/locale/et-EE.ini @@ -14,9 +14,14 @@ Dialog.Alert="JavaScript hoiatus" Dialog.Confirm="JavaScript kinnitus" Dialog.Prompt="JavaScript küsimus" Dialog.BrowserDock="Brauseri dokk" +Error.Code="Viga: %1" +Zoom.Out="Vähenda" +Zoom.In="Suurenda" ErrorCode.ERR_NAME_NOT_RESOLVED="Server IP aadressi ei leitud" +ErrorCode.ERR_CONNECTION_TIMED_OUT="Ühendus on aegunud" ErrorCode.ERR_TIMED_OUT="Toiming on aegunud" ErrorCode.ERR_FILE_NOT_FOUND="Faili ei leitud" +ErrorCode.ERR_FAILED="Ühendamine ei õnnestunud" ErrorCode.ERR_SSL_VERSION_INTERFERENCE="SSL-i versiooni häired. TLS 1.3 võib olla blokeeritud või muudetud." ErrorCode.ERR_SSL_PROTOCOL_ERROR="SSL protokolli viga. Ei õnnestunud luua turvalist ühendust." ErrorCode.ERR_CERT_DATE_INVALID="Serveri SSL-sertifikaat on vananenud või sinu arvuti kellaaeg on vale." diff --git a/data/locale/gl-ES.ini b/data/locale/gl-ES.ini index 0ecb28f3e..c3765bd29 100644 --- a/data/locale/gl-ES.ini +++ b/data/locale/gl-ES.ini @@ -8,6 +8,9 @@ RefreshNoCache="Actualizar a caché da páxina actual" BrowserSource="Navegador" CustomFrameRate="Usar unha taxa de fotogramas personalizada" RerouteAudio="Controlar o son mediante OBS" +Inspect="Inspeccionar" +DevTools="Inspeccionar o panel do navegador '%1'" +CopyUrl="Copiar a dirección actual" WebpageControlLevel="Paxina de permisos" WebpageControlLevel.Level.None="Non hai acceso a OBS" WebpageControlLevel.Level.ReadObs="Acceder á información do estado de OBS" @@ -24,11 +27,16 @@ Error.Title="Non se pode cargar a páxina!" Error.Description="Asegúrate de que o enderezo é correcto e de que o sitio non teña problemas." Error.Retry="Prema aqui para reintentar" Error.Code="Erro: %1" +Zoom.Reset="Restablecer Zoom" +Zoom.Out="Reducir" +Zoom.In="Ampliar" ErrorCode.ERR_CONNECTION_REFUSED="Conexión rexeitada polo servidor" ErrorCode.ERR_NAME_NOT_RESOLVED="Non se atopa a dirección IP do Servidor" ErrorCode.ERR_CONNECTION_TIMED_OUT="Tempo de conexión esgotada" +ErrorCode.ERR_TIMED_OUT="A operación esgotou o tempo" ErrorCode.ERR_FILE_NOT_FOUND="Non se atopa o ficheiro" ErrorCode.ERR_FAILED="Erro na conexión" ErrorCode.ERR_NETWORK_CHANGED="Cambio de rede" ErrorCode.ERR_SSL_VERSION_INTERFERENCE="Interferencia da versión SSL. É posible que TLS 1.3 estea bloqueado ou modificado." ErrorCode.ERR_SSL_PROTOCOL_ERROR="Erro no protocolo SSL. Non se pode crear unha conexión segura." +ErrorCode.ERR_CERT_DATE_INVALID="O certificado SSL do servidor está desactualizado ou a hora do teu ordenador é incorrecta." diff --git a/data/locale/he-IL.ini b/data/locale/he-IL.ini index 968e2b443..bdc851545 100644 --- a/data/locale/he-IL.ini +++ b/data/locale/he-IL.ini @@ -16,8 +16,8 @@ WebpageControlLevel="הרשאות דף" WebpageControlLevel.Level.None="אין גישה ל-OBS" WebpageControlLevel.Level.ReadObs="גישת קריאה לפרטי המצב של OBS" WebpageControlLevel.Level.ReadUser="גישת קריאה לפרטי המשתמש (אוסף סצנות נוכחי, מעברונים)" -WebpageControlLevel.Level.Basic="גישה בסיסית ל-OBS (שמירת אוגר ההילוך החוזר, וכו')" -WebpageControlLevel.Level.Advanced="גישה מתקדמת ל-OBS (שינוי סצינות, התחלת/הפסקת אוגר ההילוך החוזר, וכו')" +WebpageControlLevel.Level.Basic="גישה בסיסית אל OBS (שמירת מטמון ההשמעה החוזרת, וכו׳)" +WebpageControlLevel.Level.Advanced="גישה מתקדמת אל OBS (שינוי סצינות, הפעלה/כיבוי של מטמון ההשמעה החוזרת, וכו׳)" WebpageControlLevel.Level.All="גישה מלאה ל-OBS (התחלת/הפסקת שידור חי ללא אזהרה, וכו')" Dialog.Alert="התראת JavaScript" Dialog.Confirm="אישור JavaScript" diff --git a/data/locale/id-ID.ini b/data/locale/id-ID.ini index 055126d81..afbba22a7 100644 --- a/data/locale/id-ID.ini +++ b/data/locale/id-ID.ini @@ -38,5 +38,5 @@ ErrorCode.ERR_FILE_NOT_FOUND="Berkas tidak ditemukan" ErrorCode.ERR_FAILED="Gagal terhubung" ErrorCode.ERR_NETWORK_CHANGED="Jaringan berubah" ErrorCode.ERR_SSL_VERSION_INTERFERENCE="Gangguan versi SSL. TLS 1.3 mungkin terblokir atau dimodifikasi." -ErrorCode.ERR_SSL_PROTOCOL_ERROR="Kesalahan protokol SSL. Tidak dapat membuat sambungan aman." +ErrorCode.ERR_SSL_PROTOCOL_ERROR="Galat protokol SSL. Tidak dapat melakukan sambungan aman." ErrorCode.ERR_CERT_DATE_INVALID="Sertifikat server SSL sudah usang atau jam pada komputer Anda tidak benar." diff --git a/data/locale/th-TH.ini b/data/locale/th-TH.ini index dcdb9b324..f8a26df3b 100644 --- a/data/locale/th-TH.ini +++ b/data/locale/th-TH.ini @@ -3,7 +3,7 @@ Width="ความกว้าง" Height="ความสูง" FPS="อัตราเฟรม" CSS="CSS ที่กำหนดเอง" -ShutdownSourceNotVisible="วิดีโอจะหยุดทำงานถ้าคุณซ่อนแหล่งที่มา" +ShutdownSourceNotVisible="วิดีโอจะหยุดทำงานถ้าคุณซ่อนแหล่ง" RefreshBrowserActive="วิดีโอที่จะทำงานต่อไปแม้จะไม่ปรากฏบนหน้าจอ" RefreshNoCache="รีเฟรชแคชของหน้าปัจจุบัน" BrowserSource="เว็บเบราว์เซอร์" diff --git a/data/locale/tt-RU.ini b/data/locale/tt-RU.ini index 3e62bd502..0519eafc0 100644 --- a/data/locale/tt-RU.ini +++ b/data/locale/tt-RU.ini @@ -1,7 +1,9 @@ LocalFile="Локаль файл" Width="Киңлек" Height="Биеклек" +BrowserSource="Браузер" Error.Code="Хата: %1" +Error.URL="Сылтама: %2" ErrorCode.ERR_FILE_NOT_FOUND="Файл табылмады" ErrorCode.ERR_FAILED="Тоташылып булмады" ErrorCode.ERR_NETWORK_CHANGED="Челтәр үзгәртелде" diff --git a/data/locale/ug-CN.ini b/data/locale/ug-CN.ini index 3c5d14d44..69bd1ac8e 100644 --- a/data/locale/ug-CN.ini +++ b/data/locale/ug-CN.ini @@ -11,7 +11,7 @@ BrowserSource="توركۆرگۈ" CustomFrameRate="ئىختىيارى كاندۇك نىسىبىتىنى ئىشلىتىدۇ" RerouteAudio="ئۈننى OBS ئارقىلىق تىزگىنلەيدۇ" Inspect="تەكشۈر" -DevTools="توركۆرگۈ سۇپىسى «%1» نى تەكشۈرىدۇ" +DevTools="توركۆرگۈ لەڭگەر «%1» نى تەكشۈرىدۇ" CopyUrl="نۆۋەتتىكى ئادرېسنى كۆچۈر" WebpageControlLevel="بەت ئىجازىتى" WebpageControlLevel.Level.None="OBS زىيارەت ئىجازىتى يوق" @@ -23,7 +23,7 @@ WebpageControlLevel.Level.All="OBS تولۇق زىيارەت ئىجازىتى ( Dialog.Alert="JavaScript ئاگاھلاندۇرۇش" Dialog.Confirm="JavaScript جەزملەش" Dialog.Prompt="JavaScript ئەسكەرتىش" -Dialog.BrowserDock="توركۆرگۈچ سۇپىسى" +Dialog.BrowserDock="توركۆرگۈچ لەڭگەر" Dialog.ReceivedFrom="«%1» تاپشۇرۇۋالدى" Error.Title="ئۇ بەتنى يۈكلىيەلمەيدۇ!" Error.Description="ئادرېسنىڭ توغرىلىقى ۋە تور بېكەتتە مەسىلە يوقلۇقىنى جەزملەڭ." From c31adcee6a83246cfcd13ee90c56867361370c68 Mon Sep 17 00:00:00 2001 From: stephematician Date: Mon, 9 Sep 2024 15:18:41 +1000 Subject: [PATCH 14/38] Bump nlohmann/json required Need >= 3.11 for *_WITH_DEFAULT macros --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0d669744f..0c88480c1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,7 +10,7 @@ if(NOT ENABLE_BROWSER) endif() find_package(CEF REQUIRED 95) -find_package(nlohmann_json REQUIRED) +find_package(nlohmann_json 3.11 REQUIRED) add_library(obs-browser MODULE) add_library(OBS::browser ALIAS obs-browser) From aa8953c166106341ae5bc711d455c67060a60073 Mon Sep 17 00:00:00 2001 From: Matt Gajownik Date: Thu, 10 Oct 2024 15:09:11 +1100 Subject: [PATCH 15/38] clang-format: Increase column limit from 80 to 120 --- .clang-format | 2 +- browser-app.cpp | 165 +++++--------- browser-app.hpp | 68 ++---- browser-client.cpp | 187 ++++++--------- browser-client.hpp | 125 ++++------- browser-scheme.cpp | 17 +- browser-scheme.hpp | 5 +- browser-version.h | 16 +- deps/signal-restore.cpp | 5 +- linux-keyboard-helpers.hpp | 39 ++-- obs-browser-page/obs-browser-page-main.cpp | 16 +- obs-browser-plugin.cpp | 250 +++++++-------------- obs-browser-source-audio.cpp | 12 +- obs-browser-source.cpp | 136 ++++------- obs-browser-source.hpp | 18 +- panel/browser-panel-client.cpp | 242 ++++++++------------ panel/browser-panel-client.hpp | 99 +++----- panel/browser-panel-internal.hpp | 8 +- panel/browser-panel.cpp | 126 ++++------- panel/browser-panel.hpp | 32 +-- 20 files changed, 546 insertions(+), 1022 deletions(-) diff --git a/.clang-format b/.clang-format index 33e9770ab..5c7b99e5a 100644 --- a/.clang-format +++ b/.clang-format @@ -45,7 +45,7 @@ BreakBeforeBraces: Custom BreakBeforeTernaryOperators: true BreakConstructorInitializers: BeforeColon BreakStringLiterals: false # apparently unpredictable -ColumnLimit: 80 +ColumnLimit: 120 CompactNamespaces: false ConstructorInitializerAllOnOneLineOrOnePerLine: true ConstructorInitializerIndentWidth: 8 diff --git a/browser-app.cpp b/browser-app.cpp index af8a3442d..ba155df95 100644 --- a/browser-app.cpp +++ b/browser-app.cpp @@ -50,13 +50,10 @@ CefRefPtr BrowserApp::GetBrowserProcessHandler() void BrowserApp::OnRegisterCustomSchemes(CefRawPtr registrar) { - registrar->AddCustomScheme("http", - CEF_SCHEME_OPTION_STANDARD | - CEF_SCHEME_OPTION_CORS_ENABLED); + registrar->AddCustomScheme("http", CEF_SCHEME_OPTION_STANDARD | CEF_SCHEME_OPTION_CORS_ENABLED); } -void BrowserApp::OnBeforeChildProcessLaunch( - CefRefPtr command_line) +void BrowserApp::OnBeforeChildProcessLaunch(CefRefPtr command_line) { #ifdef _WIN32 std::string pid = std::to_string(GetCurrentProcessId()); @@ -66,8 +63,7 @@ void BrowserApp::OnBeforeChildProcessLaunch( #endif } -void BrowserApp::OnBeforeCommandLineProcessing( - const CefString &, CefRefPtr command_line) +void BrowserApp::OnBeforeCommandLineProcessing(const CefString &, CefRefPtr command_line) { if (!shared_texture_available) { bool enableGPU = command_line->HasSwitch("enable-gpu"); @@ -80,56 +76,43 @@ void BrowserApp::OnBeforeCommandLineProcessing( if (command_line->HasSwitch("disable-features")) { // Don't override existing, as this can break OSR - std::string disableFeatures = - command_line->GetSwitchValue("disable-features"); + std::string disableFeatures = command_line->GetSwitchValue("disable-features"); disableFeatures += ",HardwareMediaKeyHandling"; disableFeatures += ",WebBluetooth"; - command_line->AppendSwitchWithValue("disable-features", - disableFeatures); + command_line->AppendSwitchWithValue("disable-features", disableFeatures); } else { - command_line->AppendSwitchWithValue("disable-features", - "WebBluetooth," - "HardwareMediaKeyHandling"); + command_line->AppendSwitchWithValue("disable-features", "WebBluetooth," + "HardwareMediaKeyHandling"); } - command_line->AppendSwitchWithValue("autoplay-policy", - "no-user-gesture-required"); + command_line->AppendSwitchWithValue("autoplay-policy", "no-user-gesture-required"); #ifdef __APPLE__ command_line->AppendSwitch("use-mock-keychain"); #elif !defined(_WIN32) - command_line->AppendSwitchWithValue("ozone-platform", - wayland ? "wayland" : "x11"); + command_line->AppendSwitchWithValue("ozone-platform", wayland ? "wayland" : "x11"); #endif } -std::vector exposedFunctions = { - "getControlLevel", "getCurrentScene", "getStatus", - "startRecording", "stopRecording", "startStreaming", - "stopStreaming", "pauseRecording", "unpauseRecording", - "startReplayBuffer", "stopReplayBuffer", "saveReplayBuffer", - "startVirtualcam", "stopVirtualcam", "getScenes", - "setCurrentScene", "getTransitions", "getCurrentTransition", - "setCurrentTransition"}; - -void BrowserApp::OnContextCreated(CefRefPtr browser, - CefRefPtr, - CefRefPtr context) +std::vector exposedFunctions = {"getControlLevel", "getCurrentScene", "getStatus", + "startRecording", "stopRecording", "startStreaming", + "stopStreaming", "pauseRecording", "unpauseRecording", + "startReplayBuffer", "stopReplayBuffer", "saveReplayBuffer", + "startVirtualcam", "stopVirtualcam", "getScenes", + "setCurrentScene", "getTransitions", "getCurrentTransition", + "setCurrentTransition"}; + +void BrowserApp::OnContextCreated(CefRefPtr browser, CefRefPtr, CefRefPtr context) { CefRefPtr globalObj = context->GetGlobal(); - CefRefPtr obsStudioObj = - CefV8Value::CreateObject(nullptr, nullptr); - globalObj->SetValue("obsstudio", obsStudioObj, - V8_PROPERTY_ATTRIBUTE_NONE); + CefRefPtr obsStudioObj = CefV8Value::CreateObject(nullptr, nullptr); + globalObj->SetValue("obsstudio", obsStudioObj, V8_PROPERTY_ATTRIBUTE_NONE); - CefRefPtr pluginVersion = - CefV8Value::CreateString(OBS_BROWSER_VERSION_STRING); - obsStudioObj->SetValue("pluginVersion", pluginVersion, - V8_PROPERTY_ATTRIBUTE_NONE); + CefRefPtr pluginVersion = CefV8Value::CreateString(OBS_BROWSER_VERSION_STRING); + obsStudioObj->SetValue("pluginVersion", pluginVersion, V8_PROPERTY_ATTRIBUTE_NONE); for (std::string name : exposedFunctions) { - CefRefPtr func = - CefV8Value::CreateFunction(name, this); + CefRefPtr func = CefV8Value::CreateFunction(name, this); obsStudioObj->SetValue(name, func, V8_PROPERTY_ATTRIBUTE_NONE); } @@ -143,9 +126,7 @@ void BrowserApp::OnContextCreated(CefRefPtr browser, #endif } -void BrowserApp::ExecuteJSFunction(CefRefPtr browser, - const char *functionName, - CefV8ValueList arguments) +void BrowserApp::ExecuteJSFunction(CefRefPtr browser, const char *functionName, CefV8ValueList arguments) { std::vector names; browser->GetFrameNames(names); @@ -161,10 +142,8 @@ void BrowserApp::ExecuteJSFunction(CefRefPtr browser, context->Enter(); CefRefPtr globalObj = context->GetGlobal(); - CefRefPtr obsStudioObj = - globalObj->GetValue("obsstudio"); - CefRefPtr jsFunction = - obsStudioObj->GetValue(functionName); + CefRefPtr obsStudioObj = globalObj->GetValue("obsstudio"); + CefRefPtr jsFunction = obsStudioObj->GetValue(functionName); if (jsFunction && jsFunction->IsFunction()) jsFunction->ExecuteFunction(nullptr, arguments); @@ -174,9 +153,7 @@ void BrowserApp::ExecuteJSFunction(CefRefPtr browser, } #if !ENABLE_WASHIDDEN -void BrowserApp::SetFrameDocumentVisibility(CefRefPtr browser, - CefRefPtr frame, - bool isVisible) +void BrowserApp::SetFrameDocumentVisibility(CefRefPtr browser, CefRefPtr frame, bool isVisible) { UNUSED_PARAMETER(browser); @@ -189,15 +166,10 @@ void BrowserApp::SetFrameDocumentVisibility(CefRefPtr browser, CefRefPtr documentObject = globalObj->GetValue("document"); if (!!documentObject) { - documentObject->SetValue("hidden", - CefV8Value::CreateBool(!isVisible), - V8_PROPERTY_ATTRIBUTE_READONLY); + documentObject->SetValue("hidden", CefV8Value::CreateBool(!isVisible), V8_PROPERTY_ATTRIBUTE_READONLY); - documentObject->SetValue( - "visibilityState", - CefV8Value::CreateString(isVisible ? "visible" - : "hidden"), - V8_PROPERTY_ATTRIBUTE_READONLY); + documentObject->SetValue("visibilityState", CefV8Value::CreateString(isVisible ? "visible" : "hidden"), + V8_PROPERTY_ATTRIBUTE_READONLY); std::string script = "new CustomEvent('visibilitychange', {});"; @@ -206,28 +178,24 @@ void BrowserApp::SetFrameDocumentVisibility(CefRefPtr browser, /* Create the CustomEvent object * We have to use eval to invoke the new operator */ - bool success = context->Eval(script, frame->GetURL(), 0, - returnValue, exception); + bool success = context->Eval(script, frame->GetURL(), 0, returnValue, exception); if (success) { CefV8ValueList arguments; arguments.push_back(returnValue); - CefRefPtr dispatchEvent = - documentObject->GetValue("dispatchEvent"); + CefRefPtr dispatchEvent = documentObject->GetValue("dispatchEvent"); /* Dispatch visibilitychange event on the document * object */ - dispatchEvent->ExecuteFunction(documentObject, - arguments); + dispatchEvent->ExecuteFunction(documentObject, arguments); } } context->Exit(); } -void BrowserApp::SetDocumentVisibility(CefRefPtr browser, - bool isVisible) +void BrowserApp::SetDocumentVisibility(CefRefPtr browser, bool isVisible) { /* This method might be called before OnContextCreated * call is made. We'll save the requested visibility @@ -291,9 +259,7 @@ CefRefPtr CefValueToCefV8Value(CefRefPtr value) dict->GetKeys(keys); for (unsigned int i = 0; i < keys.size(); i++) { CefString key = keys[i]; - result->SetValue( - key, CefValueToCefV8Value(dict->GetValue(key)), - V8_PROPERTY_ATTRIBUTE_NONE); + result->SetValue(key, CefValueToCefV8Value(dict->GetValue(key)), V8_PROPERTY_ATTRIBUTE_NONE); } } break; case VTYPE_LIST: { @@ -301,18 +267,15 @@ CefRefPtr CefValueToCefV8Value(CefRefPtr value) size_t size = list->GetSize(); result = CefV8Value::CreateArray((int)size); for (size_t i = 0; i < size; i++) { - result->SetValue((int)i, CefValueToCefV8Value( - list->GetValue(i))); + result->SetValue((int)i, CefValueToCefV8Value(list->GetValue(i))); } } break; } return result; } -bool BrowserApp::OnProcessMessageReceived(CefRefPtr browser, - CefRefPtr frame, - CefProcessId source_process, - CefRefPtr message) +bool BrowserApp::OnProcessMessageReceived(CefRefPtr browser, CefRefPtr frame, + CefProcessId source_process, CefRefPtr message) { UNUSED_PARAMETER(frame); DCHECK(source_process == PID_BROWSER); @@ -336,8 +299,7 @@ bool BrowserApp::OnProcessMessageReceived(CefRefPtr browser, ExecuteJSFunction(browser, "onActiveChange", arguments); } else if (message->GetName() == "DispatchJSEvent") { - nlohmann::json payloadJson = nlohmann::json::parse( - args->GetString(1).ToString(), nullptr, false); + nlohmann::json payloadJson = nlohmann::json::parse(args->GetString(1).ToString(), nullptr, false); nlohmann::json wrapperJson; if (args->GetSize() > 1) @@ -371,22 +333,19 @@ bool BrowserApp::OnProcessMessageReceived(CefRefPtr browser, /* Create the CustomEvent object * We have to use eval to invoke the new operator */ - context->Eval(script, browser->GetMainFrame()->GetURL(), - 0, returnValue, exception); + context->Eval(script, browser->GetMainFrame()->GetURL(), 0, returnValue, exception); CefV8ValueList arguments; arguments.push_back(returnValue); - CefRefPtr dispatchEvent = - globalObj->GetValue("dispatchEvent"); + CefRefPtr dispatchEvent = globalObj->GetValue("dispatchEvent"); dispatchEvent->ExecuteFunction(nullptr, arguments); context->Exit(); } } else if (message->GetName() == "executeCallback") { - CefRefPtr context = - browser->GetMainFrame()->GetV8Context(); + CefRefPtr context = browser->GetMainFrame()->GetV8Context(); context->Enter(); @@ -394,8 +353,7 @@ bool BrowserApp::OnProcessMessageReceived(CefRefPtr browser, int callbackID = arguments->GetInt(0); CefString jsonString = arguments->GetString(1); - CefRefPtr json = - CefParseJSON(arguments->GetString(1).ToString(), {}); + CefRefPtr json = CefParseJSON(arguments->GetString(1).ToString(), {}); CefRefPtr callback = callbackMap[callbackID]; CefV8ValueList args; @@ -421,13 +379,11 @@ bool BrowserApp::OnProcessMessageReceived(CefRefPtr browser, bool IsValidFunction(std::string function) { std::vector::iterator iterator; - iterator = std::find(exposedFunctions.begin(), exposedFunctions.end(), - function); + iterator = std::find(exposedFunctions.begin(), exposedFunctions.end(), function); return iterator != exposedFunctions.end(); } -bool BrowserApp::Execute(const CefString &name, CefRefPtr, - const CefV8ValueList &arguments, +bool BrowserApp::Execute(const CefString &name, CefRefPtr, const CefV8ValueList &arguments, CefRefPtr &, CefString &) { if (IsValidFunction(name.ToString())) { @@ -436,8 +392,7 @@ bool BrowserApp::Execute(const CefString &name, CefRefPtr, callbackMap[callbackId] = arguments[0]; } - CefRefPtr msg = - CefProcessMessage::Create(name); + CefRefPtr msg = CefProcessMessage::Create(name); CefRefPtr args = msg->GetArgumentList(); args->SetInt(0, callbackId); @@ -450,20 +405,16 @@ bool BrowserApp::Execute(const CefString &name, CefRefPtr, pos = l + 1; if (arguments[l]->IsString()) - args->SetString(pos, - arguments[l]->GetStringValue()); + args->SetString(pos, arguments[l]->GetStringValue()); else if (arguments[l]->IsInt()) args->SetInt(pos, arguments[l]->GetIntValue()); else if (arguments[l]->IsBool()) - args->SetBool(pos, - arguments[l]->GetBoolValue()); + args->SetBool(pos, arguments[l]->GetBoolValue()); else if (arguments[l]->IsDouble()) - args->SetDouble(pos, - arguments[l]->GetDoubleValue()); + args->SetDouble(pos, arguments[l]->GetDoubleValue()); } - CefRefPtr browser = - CefV8Context::GetCurrentContext()->GetBrowser(); + CefRefPtr browser = CefV8Context::GetCurrentContext()->GetBrowser(); SendBrowserProcessMessage(browser, PID_BROWSER, msg); } else { @@ -483,8 +434,7 @@ void QueueBrowserTask(CefRefPtr browser, BrowserFunc func) std::lock_guard lock(messageObject.browserTaskMutex); messageObject.browserTasks.emplace_back(browser, func); - QMetaObject::invokeMethod(&messageObject, "ExecuteNextBrowserTask", - Qt::QueuedConnection); + QMetaObject::invokeMethod(&messageObject, "ExecuteNextBrowserTask", Qt::QueuedConnection); } bool MessageObject::ExecuteNextBrowserTask() @@ -511,8 +461,7 @@ void MessageObject::ExecuteTask(MessageTask task) void MessageObject::DoCefMessageLoop(int ms) { if (ms) - QTimer::singleShot((int)ms + 2, - []() { CefDoMessageLoopWork(); }); + QTimer::singleShot((int)ms + 2, []() { CefDoMessageLoopWork(); }); else CefDoMessageLoopWork(); } @@ -524,8 +473,7 @@ void MessageObject::Process() void ProcessCef() { - QMetaObject::invokeMethod(&messageObject, "DoCefMessageLoop", - Qt::QueuedConnection, Q_ARG(int, (int)0)); + QMetaObject::invokeMethod(&messageObject, "DoCefMessageLoop", Qt::QueuedConnection, Q_ARG(int, (int)0)); } #define MAX_DELAY (1000 / 30) @@ -542,14 +490,11 @@ void BrowserApp::OnScheduleMessagePumpWork(int64_t delay_ms) delay_ms = MAX_DELAY; if (!frameTimer.isActive()) { - QObject::connect(&frameTimer, &QTimer::timeout, &messageObject, - &MessageObject::Process); + QObject::connect(&frameTimer, &QTimer::timeout, &messageObject, &MessageObject::Process); frameTimer.setSingleShot(false); frameTimer.start(33); } - QMetaObject::invokeMethod(&messageObject, "DoCefMessageLoop", - Qt::QueuedConnection, - Q_ARG(int, (int)delay_ms)); + QMetaObject::invokeMethod(&messageObject, "DoCefMessageLoop", Qt::QueuedConnection, Q_ARG(int, (int)delay_ms)); } #endif diff --git a/browser-app.hpp b/browser-app.hpp index 241e233c9..db1202b0c 100644 --- a/browser-app.hpp +++ b/browser-app.hpp @@ -36,18 +36,14 @@ typedef std::function MessageTask; class MessageObject : public QObject { Q_OBJECT - friend void QueueBrowserTask(CefRefPtr browser, - BrowserFunc func); + friend void QueueBrowserTask(CefRefPtr browser, BrowserFunc func); struct Task { CefRefPtr browser; BrowserFunc func; inline Task() {} - inline Task(CefRefPtr browser_, BrowserFunc func_) - : browser(browser_), func(func_) - { - } + inline Task(CefRefPtr browser_, BrowserFunc func_) : browser(browser_), func(func_) {} }; std::mutex browserTaskMutex; @@ -63,14 +59,9 @@ public slots: extern void QueueBrowserTask(CefRefPtr browser, BrowserFunc func); #endif -class BrowserApp : public CefApp, - public CefRenderProcessHandler, - public CefBrowserProcessHandler, - public CefV8Handler { +class BrowserApp : public CefApp, public CefRenderProcessHandler, public CefBrowserProcessHandler, public CefV8Handler { - void ExecuteJSFunction(CefRefPtr browser, - const char *functionName, - CefV8ValueList arguments); + void ExecuteJSFunction(CefRefPtr browser, const char *functionName, CefV8ValueList arguments); typedef std::map> CallbackMap; @@ -83,41 +74,27 @@ class BrowserApp : public CefApp, public: #if defined(__APPLE__) || defined(_WIN32) - inline BrowserApp(bool shared_texture_available_ = false) - : shared_texture_available(shared_texture_available_) + inline BrowserApp(bool shared_texture_available_ = false) : shared_texture_available(shared_texture_available_) #else - inline BrowserApp(bool shared_texture_available_ = false, - bool wayland_ = false) - : shared_texture_available(shared_texture_available_), - wayland(wayland_) + inline BrowserApp(bool shared_texture_available_ = false, bool wayland_ = false) + : shared_texture_available(shared_texture_available_), wayland(wayland_) #endif { } - virtual CefRefPtr - GetRenderProcessHandler() override; - virtual CefRefPtr - GetBrowserProcessHandler() override; - virtual void OnBeforeChildProcessLaunch( - CefRefPtr command_line) override; - virtual void OnRegisterCustomSchemes( - CefRawPtr registrar) override; - virtual void OnBeforeCommandLineProcessing( - const CefString &process_type, - CefRefPtr command_line) override; - virtual void OnContextCreated(CefRefPtr browser, - CefRefPtr frame, + virtual CefRefPtr GetRenderProcessHandler() override; + virtual CefRefPtr GetBrowserProcessHandler() override; + virtual void OnBeforeChildProcessLaunch(CefRefPtr command_line) override; + virtual void OnRegisterCustomSchemes(CefRawPtr registrar) override; + virtual void OnBeforeCommandLineProcessing(const CefString &process_type, + CefRefPtr command_line) override; + virtual void OnContextCreated(CefRefPtr browser, CefRefPtr frame, CefRefPtr context) override; - virtual bool - OnProcessMessageReceived(CefRefPtr browser, - CefRefPtr frame, - CefProcessId source_process, - CefRefPtr message) override; - virtual bool Execute(const CefString &name, - CefRefPtr object, - const CefV8ValueList &arguments, - CefRefPtr &retval, - CefString &exception) override; + virtual bool OnProcessMessageReceived(CefRefPtr browser, CefRefPtr frame, + CefProcessId source_process, + CefRefPtr message) override; + virtual bool Execute(const CefString &name, CefRefPtr object, const CefV8ValueList &arguments, + CefRefPtr &retval, CefString &exception) override; #ifdef ENABLE_BROWSER_QT_LOOP #if CHROME_VERSION_BUILD < 5938 @@ -131,11 +108,8 @@ class BrowserApp : public CefApp, #if !ENABLE_WASHIDDEN std::unordered_map browserVis; - void SetFrameDocumentVisibility(CefRefPtr browser, - CefRefPtr frame, - bool isVisible); - void SetDocumentVisibility(CefRefPtr browser, - bool isVisible); + void SetFrameDocumentVisibility(CefRefPtr browser, CefRefPtr frame, bool isVisible); + void SetDocumentVisibility(CefRefPtr browser, bool isVisible); #endif IMPLEMENT_REFCOUNTING(BrowserApp); diff --git a/browser-client.cpp b/browser-client.cpp index 4bd478091..5a067dec5 100644 --- a/browser-client.cpp +++ b/browser-client.cpp @@ -71,9 +71,10 @@ CefRefPtr BrowserClient::GetRequestHandler() return this; } -CefRefPtr BrowserClient::GetResourceRequestHandler( - CefRefPtr, CefRefPtr, - CefRefPtr request, bool, bool, const CefString &, bool &) +CefRefPtr BrowserClient::GetResourceRequestHandler(CefRefPtr, + CefRefPtr, + CefRefPtr request, bool, bool, + const CefString &, bool &) { if (request->GetHeaderByName("origin") == "null") { return this; @@ -82,38 +83,31 @@ CefRefPtr BrowserClient::GetResourceRequestHandler( return nullptr; } -CefResourceRequestHandler::ReturnValue -BrowserClient::OnBeforeResourceLoad(CefRefPtr, CefRefPtr, - CefRefPtr, - CefRefPtr) +CefResourceRequestHandler::ReturnValue BrowserClient::OnBeforeResourceLoad(CefRefPtr, CefRefPtr, + CefRefPtr, + CefRefPtr) { return RV_CONTINUE; } #endif -bool BrowserClient::OnBeforePopup(CefRefPtr, CefRefPtr, - const CefString &, const CefString &, - cef_window_open_disposition_t, bool, - const CefPopupFeatures &, CefWindowInfo &, - CefRefPtr &, CefBrowserSettings &, - CefRefPtr &, bool *) +bool BrowserClient::OnBeforePopup(CefRefPtr, CefRefPtr, const CefString &, const CefString &, + cef_window_open_disposition_t, bool, const CefPopupFeatures &, CefWindowInfo &, + CefRefPtr &, CefBrowserSettings &, CefRefPtr &, bool *) { /* block popups */ return true; } -void BrowserClient::OnBeforeContextMenu(CefRefPtr, - CefRefPtr, - CefRefPtr, +void BrowserClient::OnBeforeContextMenu(CefRefPtr, CefRefPtr, CefRefPtr, CefRefPtr model) { /* remove all context menu contributions */ model->Clear(); } -bool BrowserClient::OnProcessMessageReceived( - CefRefPtr browser, CefRefPtr, CefProcessId, - CefRefPtr message) +bool BrowserClient::OnProcessMessageReceived(CefRefPtr browser, CefRefPtr, CefProcessId, + CefRefPtr message) { const std::string &name = message->GetName(); CefRefPtr input_args = message->GetArgumentList(); @@ -150,35 +144,27 @@ bool BrowserClient::OnProcessMessageReceived( } else if (name == "stopReplayBuffer") { obs_frontend_replay_buffer_stop(); } else if (name == "setCurrentScene") { - const std::string scene_name = - input_args->GetString(1).ToString(); - OBSSourceAutoRelease source = - obs_get_source_by_name(scene_name.c_str()); + const std::string scene_name = input_args->GetString(1).ToString(); + OBSSourceAutoRelease source = obs_get_source_by_name(scene_name.c_str()); if (!source) { blog(LOG_WARNING, "Browser source '%s' tried to switch to scene '%s' which doesn't exist", - obs_source_get_name(bs->source), - scene_name.c_str()); + obs_source_get_name(bs->source), scene_name.c_str()); } else if (!obs_source_is_scene(source)) { - blog(LOG_WARNING, - "Browser source '%s' tried to switch to '%s' which isn't a scene", - obs_source_get_name(bs->source), - scene_name.c_str()); + blog(LOG_WARNING, "Browser source '%s' tried to switch to '%s' which isn't a scene", + obs_source_get_name(bs->source), scene_name.c_str()); } else { obs_frontend_set_current_scene(source); } } else if (name == "setCurrentTransition") { - const std::string transition_name = - input_args->GetString(1).ToString(); + const std::string transition_name = input_args->GetString(1).ToString(); obs_frontend_source_list transitions = {}; obs_frontend_get_transitions(&transitions); OBSSourceAutoRelease transition; for (size_t i = 0; i < transitions.sources.num; i++) { - obs_source_t *source = - transitions.sources.array[i]; - if (obs_source_get_name(source) == - transition_name) { + obs_source_t *source = transitions.sources.array[i]; + if (obs_source_get_name(source) == transition_name) { transition = obs_source_get_ref(source); break; } @@ -191,8 +177,7 @@ bool BrowserClient::OnProcessMessageReceived( else blog(LOG_WARNING, "Browser source '%s' tried to change the current transition to '%s' which doesn't exist", - obs_source_get_name(bs->source), - transition_name.c_str()); + obs_source_get_name(bs->source), transition_name.c_str()); } [[fallthrough]]; case ControlLevel::Basic: @@ -207,14 +192,12 @@ bool BrowserClient::OnProcessMessageReceived( std::vector scenes_vector; for (size_t i = 0; i < list.sources.num; i++) { obs_source_t *source = list.sources.array[i]; - scenes_vector.push_back( - obs_source_get_name(source)); + scenes_vector.push_back(obs_source_get_name(source)); } json = scenes_vector; obs_frontend_source_list_free(&list); } else if (name == "getCurrentScene") { - OBSSourceAutoRelease current_scene = - obs_frontend_get_current_scene(); + OBSSourceAutoRelease current_scene = obs_frontend_get_current_scene(); if (!current_scene) return false; @@ -225,22 +208,19 @@ bool BrowserClient::OnProcessMessageReceived( json = {{"name", name}, {"width", obs_source_get_width(current_scene)}, - {"height", - obs_source_get_height(current_scene)}}; + {"height", obs_source_get_height(current_scene)}}; } else if (name == "getTransitions") { struct obs_frontend_source_list list = {}; obs_frontend_get_transitions(&list); std::vector transitions_vector; for (size_t i = 0; i < list.sources.num; i++) { obs_source_t *source = list.sources.array[i]; - transitions_vector.push_back( - obs_source_get_name(source)); + transitions_vector.push_back(obs_source_get_name(source)); } json = transitions_vector; obs_frontend_source_list_free(&list); } else if (name == "getCurrentTransition") { - OBSSourceAutoRelease source = - obs_frontend_get_current_transition(); + OBSSourceAutoRelease source = obs_frontend_get_current_transition(); json = obs_source_get_name(source); } [[fallthrough]]; @@ -248,12 +228,9 @@ bool BrowserClient::OnProcessMessageReceived( if (name == "getStatus") { json = {{"recording", obs_frontend_recording_active()}, {"streaming", obs_frontend_streaming_active()}, - {"recordingPaused", - obs_frontend_recording_paused()}, - {"replaybuffer", - obs_frontend_replay_buffer_active()}, - {"virtualcam", - obs_frontend_virtualcam_active()}}; + {"recordingPaused", obs_frontend_recording_paused()}, + {"replaybuffer", obs_frontend_replay_buffer_active()}, + {"virtualcam", obs_frontend_virtualcam_active()}}; } [[fallthrough]]; case ControlLevel::None: @@ -262,8 +239,7 @@ bool BrowserClient::OnProcessMessageReceived( } } - CefRefPtr msg = - CefProcessMessage::Create("executeCallback"); + CefRefPtr msg = CefProcessMessage::Create("executeCallback"); CefRefPtr execute_args = msg->GetArgumentList(); execute_args->SetInt(0, input_args->GetInt(0)); @@ -281,23 +257,19 @@ void BrowserClient::GetViewRect(CefRefPtr, CefRect &rect) return; } - rect.Set(0, 0, bs->width < 1 ? 1 : bs->width, - bs->height < 1 ? 1 : bs->height); + rect.Set(0, 0, bs->width < 1 ? 1 : bs->width, bs->height < 1 ? 1 : bs->height); } bool BrowserClient::OnTooltip(CefRefPtr, CefString &text) { std::string str_text = text; - QMetaObject::invokeMethod( - QCoreApplication::instance()->thread(), [str_text]() { - QToolTip::showText(QCursor::pos(), str_text.c_str()); - }); + QMetaObject::invokeMethod(QCoreApplication::instance()->thread(), + [str_text]() { QToolTip::showText(QCursor::pos(), str_text.c_str()); }); return true; } -void BrowserClient::OnPaint(CefRefPtr, PaintElementType type, - const RectList &, const void *buffer, int width, - int height) +void BrowserClient::OnPaint(CefRefPtr, PaintElementType type, const RectList &, const void *buffer, + int width, int height) { if (type != PET_VIEW) { // TODO Overlay texture on top of bs->texture @@ -322,16 +294,13 @@ void BrowserClient::OnPaint(CefRefPtr, PaintElementType type, if (!bs->texture && width && height) { obs_enter_graphics(); - bs->texture = gs_texture_create(width, height, GS_BGRA, 1, - (const uint8_t **)&buffer, - GS_DYNAMIC); + bs->texture = gs_texture_create(width, height, GS_BGRA, 1, (const uint8_t **)&buffer, GS_DYNAMIC); bs->width = width; bs->height = height; obs_leave_graphics(); } else { obs_enter_graphics(); - gs_texture_set_image(bs->texture, (const uint8_t *)buffer, - width * 4, false); + gs_texture_set_image(bs->texture, (const uint8_t *)buffer, width * 4, false); obs_leave_graphics(); } } @@ -342,21 +311,17 @@ void BrowserClient::UpdateExtraTexture() if (bs->texture) { const uint32_t cx = gs_texture_get_width(bs->texture); const uint32_t cy = gs_texture_get_height(bs->texture); - const gs_color_format format = - gs_texture_get_color_format(bs->texture); - const gs_color_format linear_format = - gs_generalize_format(format); + const gs_color_format format = gs_texture_get_color_format(bs->texture); + const gs_color_format linear_format = gs_generalize_format(format); if (linear_format != format) { - if (!bs->extra_texture || - bs->last_format != linear_format || - bs->last_cx != cx || bs->last_cy != cy) { + if (!bs->extra_texture || bs->last_format != linear_format || bs->last_cx != cx || + bs->last_cy != cy) { if (bs->extra_texture) { gs_texture_destroy(bs->extra_texture); bs->extra_texture = nullptr; } - bs->extra_texture = gs_texture_create( - cx, cy, linear_format, 1, nullptr, 0); + bs->extra_texture = gs_texture_create(cx, cy, linear_format, 1, nullptr, 0); bs->last_cx = cx; bs->last_cy = cy; bs->last_format = linear_format; @@ -371,8 +336,7 @@ void BrowserClient::UpdateExtraTexture() } } -void BrowserClient::OnAcceleratedPaint(CefRefPtr, - PaintElementType type, const RectList &, +void BrowserClient::OnAcceleratedPaint(CefRefPtr, PaintElementType type, const RectList &, #if CHROME_VERSION_BUILD >= 6367 const CefAcceleratedPaintInfo &info) #else @@ -404,16 +368,13 @@ void BrowserClient::OnAcceleratedPaint(CefRefPtr, } #if defined(__APPLE__) && CHROME_VERSION_BUILD > 6367 - bs->texture = gs_texture_create_from_iosurface( - (IOSurfaceRef)(uintptr_t)info.shared_texture_io_surface); + bs->texture = gs_texture_create_from_iosurface((IOSurfaceRef)(uintptr_t)info.shared_texture_io_surface); #elif defined(__APPLE__) && CHROME_VERSION_BUILD > 4183 - bs->texture = gs_texture_create_from_iosurface( - (IOSurfaceRef)(uintptr_t)shared_handle); + bs->texture = gs_texture_create_from_iosurface((IOSurfaceRef)(uintptr_t)shared_handle); #elif defined(_WIN32) && CHROME_VERSION_BUILD > 4183 bs->texture = #if CHROME_VERSION_BUILD >= 6367 - gs_texture_open_nt_shared( - (uint32_t)(uintptr_t)info.shared_texture_handle); + gs_texture_open_nt_shared((uint32_t)(uintptr_t)info.shared_texture_handle); #else gs_texture_open_nt_shared((uint32_t)(uintptr_t)shared_handle); #endif @@ -421,8 +382,7 @@ void BrowserClient::OnAcceleratedPaint(CefRefPtr, // gs_texture_acquire_sync(bs->texture, 1, INFINITE); #else - bs->texture = - gs_texture_open_shared((uint32_t)(uintptr_t)shared_handle); + bs->texture = gs_texture_open_shared((uint32_t)(uintptr_t)shared_handle); #endif UpdateExtraTexture(); obs_leave_graphics(); @@ -437,8 +397,7 @@ void BrowserClient::OnAcceleratedPaint(CefRefPtr, } #ifdef CEF_ON_ACCELERATED_PAINT2 -void BrowserClient::OnAcceleratedPaint2(CefRefPtr, - PaintElementType type, const RectList &, +void BrowserClient::OnAcceleratedPaint2(CefRefPtr, PaintElementType type, const RectList &, void *shared_handle, bool new_texture) { if (type != PET_VIEW) { @@ -462,15 +421,12 @@ void BrowserClient::OnAcceleratedPaint2(CefRefPtr, } #if defined(__APPLE__) && CHROME_VERSION_BUILD > 4183 - bs->texture = gs_texture_create_from_iosurface( - (IOSurfaceRef)(uintptr_t)shared_handle); + bs->texture = gs_texture_create_from_iosurface((IOSurfaceRef)(uintptr_t)shared_handle); #elif defined(_WIN32) && CHROME_VERSION_BUILD > 4183 - bs->texture = - gs_texture_open_nt_shared((uint32_t)(uintptr_t)shared_handle); + bs->texture = gs_texture_open_nt_shared((uint32_t)(uintptr_t)shared_handle); #else - bs->texture = - gs_texture_open_shared((uint32_t)(uintptr_t)shared_handle); + bs->texture = gs_texture_open_shared((uint32_t)(uintptr_t)shared_handle); #endif UpdateExtraTexture(); obs_leave_graphics(); @@ -510,8 +466,7 @@ static speaker_layout GetSpeakerLayout(CefAudioHandler::ChannelLayout cefLayout) } #if CHROME_VERSION_BUILD >= 4103 -void BrowserClient::OnAudioStreamStarted(CefRefPtr browser, - const CefAudioParameters ¶ms_, +void BrowserClient::OnAudioStreamStarted(CefRefPtr browser, const CefAudioParameters ¶ms_, int channels_) { UNUSED_PARAMETER(browser); @@ -521,9 +476,7 @@ void BrowserClient::OnAudioStreamStarted(CefRefPtr browser, frames_per_buffer = params_.frames_per_buffer; } -void BrowserClient::OnAudioStreamPacket(CefRefPtr browser, - const float **data, int frames, - int64_t pts) +void BrowserClient::OnAudioStreamPacket(CefRefPtr browser, const float **data, int frames, int64_t pts) { UNUSED_PARAMETER(browser); if (!valid()) { @@ -548,8 +501,7 @@ void BrowserClient::OnAudioStreamStopped(CefRefPtr browser) UNUSED_PARAMETER(browser); } -void BrowserClient::OnAudioStreamError(CefRefPtr browser, - const CefString &message) +void BrowserClient::OnAudioStreamError(CefRefPtr browser, const CefString &message) { UNUSED_PARAMETER(browser); UNUSED_PARAMETER(message); @@ -577,8 +529,7 @@ static CefAudioHandler::ChannelLayout Convert2CEFSpeakerLayout(int channels) } } -bool BrowserClient::GetAudioParameters(CefRefPtr browser, - CefAudioParameters ¶ms) +bool BrowserClient::GetAudioParameters(CefRefPtr browser, CefAudioParameters ¶ms) { UNUSED_PARAMETER(browser); int channels = (int)audio_output_get_channels(obs_get_audio()); @@ -588,8 +539,7 @@ bool BrowserClient::GetAudioParameters(CefRefPtr browser, return true; } #elif CHROME_VERSION_BUILD < 4103 -void BrowserClient::OnAudioStreamStarted(CefRefPtr browser, int id, - int, ChannelLayout channel_layout, +void BrowserClient::OnAudioStreamStarted(CefRefPtr browser, int id, int, ChannelLayout channel_layout, int sample_rate, int) { UNUSED_PARAMETER(browser); @@ -599,8 +549,7 @@ void BrowserClient::OnAudioStreamStarted(CefRefPtr browser, int id, AudioStream &stream = bs->audio_streams[id]; if (!stream.source) { - stream.source = obs_source_create_private("audio_line", nullptr, - nullptr); + stream.source = obs_source_create_private("audio_line", nullptr, nullptr); obs_source_add_active_child(bs->source, stream.source); @@ -613,8 +562,7 @@ void BrowserClient::OnAudioStreamStarted(CefRefPtr browser, int id, stream.sample_rate = sample_rate; } -void BrowserClient::OnAudioStreamPacket(CefRefPtr browser, int id, - const float **data, int frames, +void BrowserClient::OnAudioStreamPacket(CefRefPtr browser, int id, const float **data, int frames, int64_t pts) { UNUSED_PARAMETER(browser); @@ -656,8 +604,7 @@ void BrowserClient::OnAudioStreamStopped(CefRefPtr browser, int id) for (size_t i = 0; i < bs->audio_sources.size(); i++) { obs_source_t *source = bs->audio_sources[i]; if (source == stream.source) { - bs->audio_sources.erase( - bs->audio_sources.begin() + i); + bs->audio_sources.erase(bs->audio_sources.begin() + i); break; } } @@ -666,16 +613,14 @@ void BrowserClient::OnAudioStreamStopped(CefRefPtr browser, int id) } #endif -void BrowserClient::OnLoadEnd(CefRefPtr, CefRefPtr frame, - int) +void BrowserClient::OnLoadEnd(CefRefPtr, CefRefPtr frame, int) { if (!valid()) { return; } if (frame->IsMain() && bs->css.length()) { - std::string uriEncodedCSS = - CefURIEncode(bs->css, false).ToString(); + std::string uriEncodedCSS = CefURIEncode(bs->css, false).ToString(); std::string script; script += "const obsCSS = document.createElement('style');"; @@ -688,9 +633,7 @@ void BrowserClient::OnLoadEnd(CefRefPtr, CefRefPtr frame, } } -bool BrowserClient::OnConsoleMessage(CefRefPtr, - cef_log_severity_t level, - const CefString &message, +bool BrowserClient::OnConsoleMessage(CefRefPtr, cef_log_severity_t level, const CefString &message, const CefString &source, int line) { int errorLevel = LOG_INFO; @@ -713,7 +656,7 @@ bool BrowserClient::OnConsoleMessage(CefRefPtr, if (bs && bs->source) sourceName = obs_source_get_name(bs->source); - blog(errorLevel, "[obs-browser: '%s'] %s: %s (%s:%d)", sourceName, code, - message.ToString().c_str(), source.ToString().c_str(), line); + blog(errorLevel, "[obs-browser: '%s'] %s: %s (%s:%d)", sourceName, code, message.ToString().c_str(), + source.ToString().c_str(), line); return false; } diff --git a/browser-client.hpp b/browser-client.hpp index 36dd5d89c..933843584 100644 --- a/browser-client.hpp +++ b/browser-client.hpp @@ -56,8 +56,7 @@ class BrowserClient : public CefClient, ChannelLayout channel_layout; int frames_per_buffer; #endif - inline BrowserClient(BrowserSource *bs_, bool sharing_avail, - bool reroute_audio_, + inline BrowserClient(BrowserSource *bs_, bool sharing_avail, bool reroute_audio_, ControlLevel webpage_control_level_) : sharing_available(sharing_avail), reroute_audio(reroute_audio_), @@ -74,118 +73,84 @@ class BrowserClient : public CefClient, #if CHROME_VERSION_BUILD >= 4638 virtual CefRefPtr GetRequestHandler() override; #endif - virtual CefRefPtr - GetContextMenuHandler() override; + virtual CefRefPtr GetContextMenuHandler() override; virtual CefRefPtr GetAudioHandler() override; - virtual bool - OnProcessMessageReceived(CefRefPtr browser, - CefRefPtr frame, - CefProcessId source_process, - CefRefPtr message) override; + virtual bool OnProcessMessageReceived(CefRefPtr browser, CefRefPtr frame, + CefProcessId source_process, + CefRefPtr message) override; /* CefDisplayHandler */ - virtual bool OnConsoleMessage(CefRefPtr browser, - cef_log_severity_t level, - const CefString &message, - const CefString &source, - int line) override; - virtual bool OnTooltip(CefRefPtr browser, - CefString &text) override; + virtual bool OnConsoleMessage(CefRefPtr browser, cef_log_severity_t level, const CefString &message, + const CefString &source, int line) override; + virtual bool OnTooltip(CefRefPtr browser, CefString &text) override; /* CefLifeSpanHandler */ - virtual bool - OnBeforePopup(CefRefPtr browser, CefRefPtr frame, - const CefString &target_url, - const CefString &target_frame_name, - cef_window_open_disposition_t target_disposition, - bool user_gesture, const CefPopupFeatures &popupFeatures, - CefWindowInfo &windowInfo, CefRefPtr &client, - CefBrowserSettings &settings, - CefRefPtr &extra_info, - bool *no_javascript_access) override; + virtual bool OnBeforePopup(CefRefPtr browser, CefRefPtr frame, + const CefString &target_url, const CefString &target_frame_name, + cef_window_open_disposition_t target_disposition, bool user_gesture, + const CefPopupFeatures &popupFeatures, CefWindowInfo &windowInfo, + CefRefPtr &client, CefBrowserSettings &settings, + CefRefPtr &extra_info, bool *no_javascript_access) override; #if CHROME_VERSION_BUILD >= 4638 /* CefRequestHandler */ - virtual CefRefPtr GetResourceRequestHandler( - CefRefPtr browser, CefRefPtr frame, - CefRefPtr request, bool is_navigation, - bool is_download, const CefString &request_initiator, - bool &disable_default_handling) override; + virtual CefRefPtr + GetResourceRequestHandler(CefRefPtr browser, CefRefPtr frame, + CefRefPtr request, bool is_navigation, bool is_download, + const CefString &request_initiator, bool &disable_default_handling) override; /* CefResourceRequestHandler */ - virtual CefResourceRequestHandler::ReturnValue - OnBeforeResourceLoad(CefRefPtr browser, - CefRefPtr frame, - CefRefPtr request, - CefRefPtr callback) override; + virtual CefResourceRequestHandler::ReturnValue OnBeforeResourceLoad(CefRefPtr browser, + CefRefPtr frame, + CefRefPtr request, + CefRefPtr callback) override; #endif /* CefContextMenuHandler */ - virtual void - OnBeforeContextMenu(CefRefPtr browser, - CefRefPtr frame, - CefRefPtr params, - CefRefPtr model) override; + virtual void OnBeforeContextMenu(CefRefPtr browser, CefRefPtr frame, + CefRefPtr params, + CefRefPtr model) override; /* CefRenderHandler */ - virtual void GetViewRect(CefRefPtr browser, - CefRect &rect) override; - virtual void OnPaint(CefRefPtr browser, - PaintElementType type, const RectList &dirtyRects, - const void *buffer, int width, - int height) override; + virtual void GetViewRect(CefRefPtr browser, CefRect &rect) override; + virtual void OnPaint(CefRefPtr browser, PaintElementType type, const RectList &dirtyRects, + const void *buffer, int width, int height) override; #ifdef ENABLE_BROWSER_SHARED_TEXTURE - virtual void - OnAcceleratedPaint(CefRefPtr browser, PaintElementType type, - const RectList &dirtyRects, + virtual void OnAcceleratedPaint(CefRefPtr browser, PaintElementType type, + const RectList &dirtyRects, #if CHROME_VERSION_BUILD >= 6367 - const CefAcceleratedPaintInfo &info) override; + const CefAcceleratedPaintInfo &info) override; #else - void *shared_handle) override; + void *shared_handle) override; #endif #ifdef CEF_ON_ACCELERATED_PAINT2 - virtual void OnAcceleratedPaint2(CefRefPtr browser, - PaintElementType type, - const RectList &dirtyRects, - void *shared_handle, - bool new_texture) override; + virtual void OnAcceleratedPaint2(CefRefPtr browser, PaintElementType type, + const RectList &dirtyRects, void *shared_handle, bool new_texture) override; #endif #endif #if CHROME_VERSION_BUILD >= 4103 - virtual void OnAudioStreamPacket(CefRefPtr browser, - const float **data, int frames, + virtual void OnAudioStreamPacket(CefRefPtr browser, const float **data, int frames, int64_t pts) override; - virtual void - OnAudioStreamStopped(CefRefPtr browser) override; + virtual void OnAudioStreamStopped(CefRefPtr browser) override; - virtual void OnAudioStreamStarted(CefRefPtr browser, - const CefAudioParameters ¶ms, + virtual void OnAudioStreamStarted(CefRefPtr browser, const CefAudioParameters ¶ms, int channels) override; - virtual void OnAudioStreamError(CefRefPtr browser, - const CefString &message) override; + virtual void OnAudioStreamError(CefRefPtr browser, const CefString &message) override; const int kFramesPerBuffer = 1024; - virtual bool GetAudioParameters(CefRefPtr browser, - CefAudioParameters ¶ms) override; + virtual bool GetAudioParameters(CefRefPtr browser, CefAudioParameters ¶ms) override; #else - virtual void OnAudioStreamPacket(CefRefPtr browser, - int audio_stream_id, - const float **data, int frames, - int64_t pts) override; + virtual void OnAudioStreamPacket(CefRefPtr browser, int audio_stream_id, const float **data, + int frames, int64_t pts) override; - virtual void OnAudioStreamStopped(CefRefPtr browser, - int audio_stream_id); + virtual void OnAudioStreamStopped(CefRefPtr browser, int audio_stream_id); - virtual void OnAudioStreamStarted(CefRefPtr browser, - int audio_stream_id, int channels, - ChannelLayout channel_layout, - int sample_rate, + virtual void OnAudioStreamStarted(CefRefPtr browser, int audio_stream_id, int channels, + ChannelLayout channel_layout, int sample_rate, int frames_per_buffer) override; #endif /* CefLoadHandler */ - virtual void OnLoadEnd(CefRefPtr browser, - CefRefPtr frame, - int httpStatusCode) override; + virtual void OnLoadEnd(CefRefPtr browser, CefRefPtr frame, int httpStatusCode) override; IMPLEMENT_REFCOUNTING(BrowserClient); }; diff --git a/browser-scheme.cpp b/browser-scheme.cpp index db745aef0..88d51d584 100644 --- a/browser-scheme.cpp +++ b/browser-scheme.cpp @@ -21,10 +21,8 @@ #include #if !ENABLE_LOCAL_FILE_URL_SCHEME -CefRefPtr -BrowserSchemeHandlerFactory::Create(CefRefPtr browser, - CefRefPtr, const CefString &, - CefRefPtr request) +CefRefPtr BrowserSchemeHandlerFactory::Create(CefRefPtr browser, CefRefPtr, + const CefString &, CefRefPtr request) { if (!browser || !request) return nullptr; @@ -35,10 +33,7 @@ BrowserSchemeHandlerFactory::Create(CefRefPtr browser, std::string path = CefString(&parts.path); path = CefURIDecode(path, true, cef_uri_unescape_rule_t::UU_SPACES); - path = CefURIDecode( - path, true, - cef_uri_unescape_rule_t:: - UU_URL_SPECIAL_CHARS_EXCEPT_PATH_SEPARATORS); + path = CefURIDecode(path, true, cef_uri_unescape_rule_t::UU_URL_SPECIAL_CHARS_EXCEPT_PATH_SEPARATORS); std::string fileExtension = path.substr(path.find_last_of(".") + 1); @@ -48,11 +43,9 @@ BrowserSchemeHandlerFactory::Create(CefRefPtr browser, fileExtension = "woff"; #ifdef _WIN32 - CefRefPtr stream = - CefStreamReader::CreateForFile(path.substr(1)); + CefRefPtr stream = CefStreamReader::CreateForFile(path.substr(1)); #else - CefRefPtr stream = - CefStreamReader::CreateForFile(path); + CefRefPtr stream = CefStreamReader::CreateForFile(path); #endif if (stream) { diff --git a/browser-scheme.hpp b/browser-scheme.hpp index 6a183a02a..2b7f6fdd2 100644 --- a/browser-scheme.hpp +++ b/browser-scheme.hpp @@ -31,9 +31,8 @@ #if !ENABLE_LOCAL_FILE_URL_SCHEME class BrowserSchemeHandlerFactory : public CefSchemeHandlerFactory { public: - virtual CefRefPtr - Create(CefRefPtr browser, CefRefPtr, - const CefString &, CefRefPtr request) override; + virtual CefRefPtr Create(CefRefPtr browser, CefRefPtr, + const CefString &, CefRefPtr request) override; IMPLEMENT_REFCOUNTING(BrowserSchemeHandlerFactory); }; diff --git a/browser-version.h b/browser-version.h index 5158b6590..973a8b9f5 100644 --- a/browser-version.h +++ b/browser-version.h @@ -5,19 +5,15 @@ #define OBS_BROWSER_VERSION_PATCH 2 #ifndef MAKE_SEMANTIC_VERSION -#define MAKE_SEMANTIC_VERSION(major, minor, patch) \ - ((major << 24) | (minor << 16) | patch) +#define MAKE_SEMANTIC_VERSION(major, minor, patch) ((major << 24) | (minor << 16) | patch) #endif -#define OBS_BROWSER_VERSION_INT \ - MAKE_SEMANTIC_VERSION(OBS_BROWSER_VERSION_MAJOR, \ - OBS_BROWSER_VERSION_MINOR, \ - OBS_BROWSER_VERSION_PATCH) +#define OBS_BROWSER_VERSION_INT \ + MAKE_SEMANTIC_VERSION(OBS_BROWSER_VERSION_MAJOR, OBS_BROWSER_VERSION_MINOR, OBS_BROWSER_VERSION_PATCH) #define OBS_BROWSER_MACRO_STR_(x) #x #define OBS_BROWSER_MACRO_STR(x) OBS_BROWSER_MACRO_STR_(x) -#define OBS_BROWSER_VERSION_STRING \ - OBS_BROWSER_MACRO_STR(OBS_BROWSER_VERSION_MAJOR) \ - "." OBS_BROWSER_MACRO_STR(OBS_BROWSER_VERSION_MINOR) "." OBS_BROWSER_MACRO_STR( \ - OBS_BROWSER_VERSION_PATCH) +#define OBS_BROWSER_VERSION_STRING \ + OBS_BROWSER_MACRO_STR(OBS_BROWSER_VERSION_MAJOR) \ + "." OBS_BROWSER_MACRO_STR(OBS_BROWSER_VERSION_MINOR) "." OBS_BROWSER_MACRO_STR(OBS_BROWSER_VERSION_PATCH) diff --git a/deps/signal-restore.cpp b/deps/signal-restore.cpp index c3bd8a028..6195dbb4c 100644 --- a/deps/signal-restore.cpp +++ b/deps/signal-restore.cpp @@ -26,9 +26,8 @@ template char (&ArraySizeHelper(T (&array)[N]))[N]; #define arraysize(array) (sizeof(ArraySizeHelper(array))) -const int signals_to_restore[] = {SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGABRT, - SIGFPE, SIGSEGV, SIGALRM, SIGTERM, SIGCHLD, - SIGBUS, SIGTRAP, SIGPIPE}; +const int signals_to_restore[] = {SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGABRT, SIGFPE, SIGSEGV, + SIGALRM, SIGTERM, SIGCHLD, SIGBUS, SIGTRAP, SIGPIPE}; struct sigaction signal_handlers[arraysize(signals_to_restore)]; void BackupSignalHandlers() diff --git a/linux-keyboard-helpers.hpp b/linux-keyboard-helpers.hpp index ac752114e..d9b3e1e12 100644 --- a/linux-keyboard-helpers.hpp +++ b/linux-keyboard-helpers.hpp @@ -250,26 +250,24 @@ #define VKEY_LMENU 0xA4 #define VKEY_RMENU 0xA5 -#define VKEY_BROWSER_BACK 0xA6 // Windows 2000/XP: Browser Back key -#define VKEY_BROWSER_FORWARD 0xA7 // Windows 2000/XP: Browser Forward key -#define VKEY_BROWSER_REFRESH 0xA8 // Windows 2000/XP: Browser Refresh key -#define VKEY_BROWSER_STOP 0xA9 // Windows 2000/XP: Browser Stop key -#define VKEY_BROWSER_SEARCH 0xAA // Windows 2000/XP: Browser Search key -#define VKEY_BROWSER_FAVORITES 0xAB // Windows 2000/XP: Browser Favorites key -#define VKEY_BROWSER_HOME 0xAC // Windows 2000/XP: Browser Start and Home key -#define VKEY_VOLUME_MUTE 0xAD // Windows 2000/XP: Volume Mute key -#define VKEY_VOLUME_DOWN 0xAE // Windows 2000/XP: Volume Down key -#define VKEY_VOLUME_UP 0xAF // Windows 2000/XP: Volume Up key -#define VKEY_MEDIA_NEXT_TRACK 0xB0 // Windows 2000/XP: Next Track key -#define VKEY_MEDIA_PREV_TRACK 0xB1 // Windows 2000/XP: Previous Track key -#define VKEY_MEDIA_STOP 0xB2 // Windows 2000/XP: Stop Media key -#define VKEY_MEDIA_PLAY_PAUSE 0xB3 // Windows 2000/XP: Play/Pause Media key -#define VKEY_MEDIA_LAUNCH_MAIL 0xB4 // Windows 2000/XP: Start Mail key +#define VKEY_BROWSER_BACK 0xA6 // Windows 2000/XP: Browser Back key +#define VKEY_BROWSER_FORWARD 0xA7 // Windows 2000/XP: Browser Forward key +#define VKEY_BROWSER_REFRESH 0xA8 // Windows 2000/XP: Browser Refresh key +#define VKEY_BROWSER_STOP 0xA9 // Windows 2000/XP: Browser Stop key +#define VKEY_BROWSER_SEARCH 0xAA // Windows 2000/XP: Browser Search key +#define VKEY_BROWSER_FAVORITES 0xAB // Windows 2000/XP: Browser Favorites key +#define VKEY_BROWSER_HOME 0xAC // Windows 2000/XP: Browser Start and Home key +#define VKEY_VOLUME_MUTE 0xAD // Windows 2000/XP: Volume Mute key +#define VKEY_VOLUME_DOWN 0xAE // Windows 2000/XP: Volume Down key +#define VKEY_VOLUME_UP 0xAF // Windows 2000/XP: Volume Up key +#define VKEY_MEDIA_NEXT_TRACK 0xB0 // Windows 2000/XP: Next Track key +#define VKEY_MEDIA_PREV_TRACK 0xB1 // Windows 2000/XP: Previous Track key +#define VKEY_MEDIA_STOP 0xB2 // Windows 2000/XP: Stop Media key +#define VKEY_MEDIA_PLAY_PAUSE 0xB3 // Windows 2000/XP: Play/Pause Media key +#define VKEY_MEDIA_LAUNCH_MAIL 0xB4 // Windows 2000/XP: Start Mail key #define VKEY_MEDIA_LAUNCH_MEDIA_SELECT 0xB5 // Windows 2000/XP: Select Media key -#define VKEY_MEDIA_LAUNCH_APP1 \ - 0xB6 // VKEY_LAUNCH_APP1 (B6) Windows 2000/XP: Start Application 1 key -#define VKEY_MEDIA_LAUNCH_APP2 \ - 0xB7 // VKEY_LAUNCH_APP2 (B7) Windows 2000/XP: Start Application 2 key +#define VKEY_MEDIA_LAUNCH_APP1 0xB6 // VKEY_LAUNCH_APP1 (B6) Windows 2000/XP: Start Application 1 key +#define VKEY_MEDIA_LAUNCH_APP2 0xB7 // VKEY_LAUNCH_APP2 (B7) Windows 2000/XP: Start Application 2 key // VKEY_OEM_1 (BA) Used for miscellaneous characters; it can vary by keyboard. // Windows 2000/XP: For the US standard keyboard, the ';:' key @@ -534,8 +532,7 @@ static uint32_t KeyboardCodeFromXKeysym(unsigned int keysym) case XK_KP_7: case XK_KP_8: case XK_KP_9: - return static_cast(VKEY_NUMPAD0 + - (keysym - XK_KP_0)); + return static_cast(VKEY_NUMPAD0 + (keysym - XK_KP_0)); case XK_multiply: case XK_KP_Multiply: diff --git a/obs-browser-page/obs-browser-page-main.cpp b/obs-browser-page/obs-browser-page-main.cpp index 97bf0ee61..e1c2ebb79 100644 --- a/obs-browser-page/obs-browser-page-main.cpp +++ b/obs-browser-page/obs-browser-page-main.cpp @@ -36,16 +36,14 @@ static bool thread_initialized = false; DECLARE_HANDLE(OBS_DPI_AWARENESS_CONTEXT); #define OBS_DPI_AWARENESS_CONTEXT_UNAWARE ((OBS_DPI_AWARENESS_CONTEXT)-1) #define OBS_DPI_AWARENESS_CONTEXT_SYSTEM_AWARE ((OBS_DPI_AWARENESS_CONTEXT)-2) -#define OBS_DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE \ - ((OBS_DPI_AWARENESS_CONTEXT)-3) -#define OBS_DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 \ - ((OBS_DPI_AWARENESS_CONTEXT)-4) +#define OBS_DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE ((OBS_DPI_AWARENESS_CONTEXT)-3) +#define OBS_DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 ((OBS_DPI_AWARENESS_CONTEXT)-4) static bool SetHighDPIv2Scaling() { static BOOL(WINAPI * func)(OBS_DPI_AWARENESS_CONTEXT) = nullptr; - func = reinterpret_cast(GetProcAddress( - GetModuleHandleW(L"USER32"), "SetProcessDpiAwarenessContext")); + func = reinterpret_cast( + GetProcAddress(GetModuleHandleW(L"USER32"), "SetProcessDpiAwarenessContext")); if (!func) { return false; } @@ -84,8 +82,7 @@ int CALLBACK WinMain(HINSTANCE, HINSTANCE, LPSTR, int) CefEnableHighDPISupport(); #endif - CefRefPtr command_line = - CefCommandLine::CreateCommandLine(); + CefRefPtr command_line = CefCommandLine::CreateCommandLine(); command_line->InitFromString(::GetCommandLineW()); std::string parent_pid_str = command_line->GetSwitchValue("parent_pid"); @@ -93,8 +90,7 @@ int CALLBACK WinMain(HINSTANCE, HINSTANCE, LPSTR, int) if (!parent_pid_str.empty()) { shutdown_event = CreateEvent(nullptr, true, false, nullptr); DWORD parent_pid = (DWORD)std::stoi(parent_pid_str); - shutdown_check = std::thread(shutdown_check_thread, parent_pid, - GetCurrentThreadId()); + shutdown_check = std::thread(shutdown_check_thread, parent_pid, GetCurrentThreadId()); thread_initialized = true; } diff --git a/obs-browser-plugin.cpp b/obs-browser-plugin.cpp index 0278089b5..7d27c3936 100644 --- a/obs-browser-plugin.cpp +++ b/obs-browser-plugin.cpp @@ -92,8 +92,7 @@ class BrowserTask : public CefTask { /* you have to put the tasks on the Qt event queue after this * call otherwise the CEF message pump may stop functioning * correctly, it's only supposed to take 10ms max */ - QMetaObject::invokeMethod(&messageObject, "ExecuteTask", - Qt::QueuedConnection, + QMetaObject::invokeMethod(&messageObject, "ExecuteTask", Qt::QueuedConnection, Q_ARG(MessageTask, task)); #else task(); @@ -105,8 +104,7 @@ class BrowserTask : public CefTask { bool QueueCEFTask(std::function task) { - return CefPostTask(TID_UI, - CefRefPtr(new BrowserTask(task))); + return CefPostTask(TID_UI, CefRefPtr(new BrowserTask(task))); } /* ========================================================================= */ @@ -120,8 +118,7 @@ overflow: hidden; \ static void browser_source_get_defaults(obs_data_t *settings) { - obs_data_set_default_string(settings, "url", - "https://obsproject.com/browser-source"); + obs_data_set_default_string(settings, "url", "https://obsproject.com/browser-source"); obs_data_set_default_int(settings, "width", 800); obs_data_set_default_int(settings, "height", 600); obs_data_set_default_int(settings, "fps", 30); @@ -132,14 +129,12 @@ static void browser_source_get_defaults(obs_data_t *settings) #endif obs_data_set_default_bool(settings, "shutdown", false); obs_data_set_default_bool(settings, "restart_when_active", false); - obs_data_set_default_int(settings, "webpage_control_level", - (int)DEFAULT_CONTROL_LEVEL); + obs_data_set_default_int(settings, "webpage_control_level", (int)DEFAULT_CONTROL_LEVEL); obs_data_set_default_string(settings, "css", default_css); obs_data_set_default_bool(settings, "reroute_audio", false); } -static bool is_local_file_modified(obs_properties_t *props, obs_property_t *, - obs_data_t *settings) +static bool is_local_file_modified(obs_properties_t *props, obs_property_t *, obs_data_t *settings) { bool enabled = obs_data_get_bool(settings, "is_local_file"); obs_property_t *url = obs_properties_get(props, "url"); @@ -150,8 +145,7 @@ static bool is_local_file_modified(obs_properties_t *props, obs_property_t *, return true; } -static bool is_fps_custom(obs_properties_t *props, obs_property_t *, - obs_data_t *settings) +static bool is_fps_custom(obs_properties_t *props, obs_property_t *, obs_data_t *settings) { bool enabled = obs_data_get_bool(settings, "fps_custom"); obs_property_t *fps = obs_properties_get(props, "fps"); @@ -167,8 +161,7 @@ static obs_properties_t *browser_source_get_properties(void *data) DStr path; obs_properties_set_flags(props, OBS_PROPERTIES_DEFER_UPDATE); - obs_property_t *prop = obs_properties_add_bool( - props, "is_local_file", obs_module_text("LocalFile")); + obs_property_t *prop = obs_properties_add_bool(props, "is_local_file", obs_module_text("LocalFile")); if (bs && !bs->url.empty()) { const char *slash; @@ -181,22 +174,15 @@ static obs_properties_t *browser_source_get_properties(void *data) } obs_property_set_modified_callback(prop, is_local_file_modified); - obs_properties_add_path(props, "local_file", - obs_module_text("LocalFile"), OBS_PATH_FILE, - "*.*", path->array); - obs_properties_add_text(props, "url", obs_module_text("URL"), - OBS_TEXT_DEFAULT); - - obs_properties_add_int(props, "width", obs_module_text("Width"), 1, - 8192, 1); - obs_properties_add_int(props, "height", obs_module_text("Height"), 1, - 8192, 1); - - obs_properties_add_bool(props, "reroute_audio", - obs_module_text("RerouteAudio")); - - obs_property_t *fps_set = obs_properties_add_bool( - props, "fps_custom", obs_module_text("CustomFrameRate")); + obs_properties_add_path(props, "local_file", obs_module_text("LocalFile"), OBS_PATH_FILE, "*.*", path->array); + obs_properties_add_text(props, "url", obs_module_text("URL"), OBS_TEXT_DEFAULT); + + obs_properties_add_int(props, "width", obs_module_text("Width"), 1, 8192, 1); + obs_properties_add_int(props, "height", obs_module_text("Height"), 1, 8192, 1); + + obs_properties_add_bool(props, "reroute_audio", obs_module_text("RerouteAudio")); + + obs_property_t *fps_set = obs_properties_add_bool(props, "fps_custom", obs_module_text("CustomFrameRate")); obs_property_set_modified_callback(fps_set, is_fps_custom); #ifndef ENABLE_BROWSER_SHARED_TEXTURE @@ -205,48 +191,33 @@ static obs_properties_t *browser_source_get_properties(void *data) obs_properties_add_int(props, "fps", obs_module_text("FPS"), 1, 60, 1); - obs_property_t *p = obs_properties_add_text( - props, "css", obs_module_text("CSS"), OBS_TEXT_MULTILINE); + obs_property_t *p = obs_properties_add_text(props, "css", obs_module_text("CSS"), OBS_TEXT_MULTILINE); obs_property_text_set_monospace(p, true); - obs_properties_add_bool(props, "shutdown", - obs_module_text("ShutdownSourceNotVisible")); - obs_properties_add_bool(props, "restart_when_active", - obs_module_text("RefreshBrowserActive")); - - obs_property_t *controlLevel = obs_properties_add_list( - props, "webpage_control_level", - obs_module_text("WebpageControlLevel"), OBS_COMBO_TYPE_LIST, - OBS_COMBO_FORMAT_INT); - - obs_property_list_add_int( - controlLevel, obs_module_text("WebpageControlLevel.Level.None"), - (int)ControlLevel::None); - obs_property_list_add_int( - controlLevel, - obs_module_text("WebpageControlLevel.Level.ReadObs"), - (int)ControlLevel::ReadObs); - obs_property_list_add_int( - controlLevel, - obs_module_text("WebpageControlLevel.Level.ReadUser"), - (int)ControlLevel::ReadUser); - obs_property_list_add_int( - controlLevel, - obs_module_text("WebpageControlLevel.Level.Basic"), - (int)ControlLevel::Basic); - obs_property_list_add_int( - controlLevel, - obs_module_text("WebpageControlLevel.Level.Advanced"), - (int)ControlLevel::Advanced); - obs_property_list_add_int( - controlLevel, obs_module_text("WebpageControlLevel.Level.All"), - (int)ControlLevel::All); - - obs_properties_add_button( - props, "refreshnocache", obs_module_text("RefreshNoCache"), - [](obs_properties_t *, obs_property_t *, void *data) { - static_cast(data)->Refresh(); - return false; - }); + obs_properties_add_bool(props, "shutdown", obs_module_text("ShutdownSourceNotVisible")); + obs_properties_add_bool(props, "restart_when_active", obs_module_text("RefreshBrowserActive")); + + obs_property_t *controlLevel = obs_properties_add_list(props, "webpage_control_level", + obs_module_text("WebpageControlLevel"), + OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_INT); + + obs_property_list_add_int(controlLevel, obs_module_text("WebpageControlLevel.Level.None"), + (int)ControlLevel::None); + obs_property_list_add_int(controlLevel, obs_module_text("WebpageControlLevel.Level.ReadObs"), + (int)ControlLevel::ReadObs); + obs_property_list_add_int(controlLevel, obs_module_text("WebpageControlLevel.Level.ReadUser"), + (int)ControlLevel::ReadUser); + obs_property_list_add_int(controlLevel, obs_module_text("WebpageControlLevel.Level.Basic"), + (int)ControlLevel::Basic); + obs_property_list_add_int(controlLevel, obs_module_text("WebpageControlLevel.Level.Advanced"), + (int)ControlLevel::Advanced); + obs_property_list_add_int(controlLevel, obs_module_text("WebpageControlLevel.Level.All"), + (int)ControlLevel::All); + + obs_properties_add_button(props, "refreshnocache", obs_module_text("RefreshNoCache"), + [](obs_properties_t *, obs_property_t *, void *data) { + static_cast(data)->Refresh(); + return false; + }); return props; } @@ -278,11 +249,8 @@ static obs_missing_files_t *browser_source_missingfiles(void *data) if (enabled && strcmp(path, "") != 0) { if (!os_file_exists(path)) { - obs_missing_file_t *file = - obs_missing_file_create( - path, missing_file_callback, - OBS_MISSING_FILE_SOURCE, - bs->source, NULL); + obs_missing_file_t *file = obs_missing_file_create( + path, missing_file_callback, OBS_MISSING_FILE_SOURCE, bs->source, NULL); obs_missing_files_add_file(files, file); } @@ -329,13 +297,10 @@ static void BrowserInit(void) * browser sources are coming from OBS. */ std::stringstream prod_ver; prod_ver << "Chrome/"; - prod_ver << std::to_string(cef_version_info(4)) << "." - << std::to_string(cef_version_info(5)) << "." - << std::to_string(cef_version_info(6)) << "." - << std::to_string(cef_version_info(7)); + prod_ver << std::to_string(cef_version_info(4)) << "." << std::to_string(cef_version_info(5)) << "." + << std::to_string(cef_version_info(6)) << "." << std::to_string(cef_version_info(7)); prod_ver << " OBS/"; - prod_ver << std::to_string(obs_maj) << "." << std::to_string(obs_min) - << "." << std::to_string(obs_pat); + prod_ver << std::to_string(obs_maj) << "." << std::to_string(obs_min) << "." << std::to_string(obs_pat); #if CHROME_VERSION_BUILD >= 4472 CefString(&settings.user_agent_product) = prod_ver.str(); @@ -393,9 +358,7 @@ static void BrowserInit(void) #if defined(__APPLE__) || defined(_WIN32) || !defined(ENABLE_WAYLAND) app = new BrowserApp(tex_sharing_avail); #else - app = new BrowserApp(tex_sharing_avail, - obs_get_nix_platform() == - OBS_NIX_PLATFORM_WAYLAND); + app = new BrowserApp(tex_sharing_avail, obs_get_nix_platform() == OBS_NIX_PLATFORM_WAYLAND); #endif #ifdef _WIN32 @@ -422,8 +385,7 @@ static void BrowserInit(void) #if !ENABLE_LOCAL_FILE_URL_SCHEME /* Register http://absolute/ scheme handler for older * CEF builds which do not support file:// URLs */ - CefRegisterSchemeHandlerFactory("http", "absolute", - new BrowserSchemeHandlerFactory()); + CefRegisterSchemeHandlerFactory("http", "absolute", new BrowserSchemeHandlerFactory()); #endif os_event_signal(cef_started_event); } @@ -467,8 +429,7 @@ void RegisterBrowserSource() struct obs_source_info info = {}; info.id = "browser_source"; info.type = OBS_SOURCE_TYPE_INPUT; - info.output_flags = OBS_SOURCE_VIDEO | OBS_SOURCE_AUDIO | - OBS_SOURCE_CUSTOM_DRAW | OBS_SOURCE_INTERACTION | + info.output_flags = OBS_SOURCE_VIDEO | OBS_SOURCE_AUDIO | OBS_SOURCE_CUSTOM_DRAW | OBS_SOURCE_INTERACTION | OBS_SOURCE_DO_NOT_DUPLICATE | OBS_SOURCE_SRGB; info.get_properties = browser_source_get_properties; info.get_defaults = browser_source_get_defaults; @@ -479,83 +440,52 @@ void RegisterBrowserSource() obs_browser_initialize(); return new BrowserSource(settings, source); }; - info.destroy = [](void *data) { - static_cast(data)->Destroy(); - }; + info.destroy = [](void *data) { static_cast(data)->Destroy(); }; info.missing_files = browser_source_missingfiles; - info.update = [](void *data, obs_data_t *settings) { - static_cast(data)->Update(settings); - }; - info.get_width = [](void *data) { - return (uint32_t) static_cast(data)->width; - }; - info.get_height = [](void *data) { - return (uint32_t) static_cast(data)->height; - }; - info.video_tick = [](void *data, float) { - static_cast(data)->Tick(); - }; - info.video_render = [](void *data, gs_effect_t *) { - static_cast(data)->Render(); - }; + info.update = [](void *data, obs_data_t *settings) { static_cast(data)->Update(settings); }; + info.get_width = [](void *data) { return (uint32_t) static_cast(data)->width; }; + info.get_height = [](void *data) { return (uint32_t) static_cast(data)->height; }; + info.video_tick = [](void *data, float) { static_cast(data)->Tick(); }; + info.video_render = [](void *data, gs_effect_t *) { static_cast(data)->Render(); }; #if CHROME_VERSION_BUILD < 4103 - info.audio_mix = [](void *data, uint64_t *ts_out, - struct audio_output_data *audio_output, - size_t channels, size_t sample_rate) { - return static_cast(data)->AudioMix( - ts_out, audio_output, channels, sample_rate); + info.audio_mix = [](void *data, uint64_t *ts_out, struct audio_output_data *audio_output, size_t channels, + size_t sample_rate) { + return static_cast(data)->AudioMix(ts_out, audio_output, channels, sample_rate); }; - info.enum_active_sources = [](void *data, obs_source_enum_proc_t cb, - void *param) { + info.enum_active_sources = [](void *data, obs_source_enum_proc_t cb, void *param) { static_cast(data)->EnumAudioStreams(cb, param); }; #endif - info.mouse_click = [](void *data, const struct obs_mouse_event *event, - int32_t type, bool mouse_up, + info.mouse_click = [](void *data, const struct obs_mouse_event *event, int32_t type, bool mouse_up, uint32_t click_count) { - static_cast(data)->SendMouseClick( - event, type, mouse_up, click_count); - }; - info.mouse_move = [](void *data, const struct obs_mouse_event *event, - bool mouse_leave) { - static_cast(data)->SendMouseMove(event, - mouse_leave); + static_cast(data)->SendMouseClick(event, type, mouse_up, click_count); }; - info.mouse_wheel = [](void *data, const struct obs_mouse_event *event, - int x_delta, int y_delta) { - static_cast(data)->SendMouseWheel( - event, x_delta, y_delta); + info.mouse_move = [](void *data, const struct obs_mouse_event *event, bool mouse_leave) { + static_cast(data)->SendMouseMove(event, mouse_leave); }; - info.focus = [](void *data, bool focus) { - static_cast(data)->SendFocus(focus); + info.mouse_wheel = [](void *data, const struct obs_mouse_event *event, int x_delta, int y_delta) { + static_cast(data)->SendMouseWheel(event, x_delta, y_delta); }; - info.key_click = [](void *data, const struct obs_key_event *event, - bool key_up) { + info.focus = [](void *data, bool focus) { static_cast(data)->SendFocus(focus); }; + info.key_click = [](void *data, const struct obs_key_event *event, bool key_up) { static_cast(data)->SendKeyClick(event, key_up); }; - info.show = [](void *data) { - static_cast(data)->SetShowing(true); - }; - info.hide = [](void *data) { - static_cast(data)->SetShowing(false); - }; + info.show = [](void *data) { static_cast(data)->SetShowing(true); }; + info.hide = [](void *data) { static_cast(data)->SetShowing(false); }; info.activate = [](void *data) { BrowserSource *bs = static_cast(data); if (bs->restart) bs->Refresh(); bs->SetActive(true); }; - info.deactivate = [](void *data) { - static_cast(data)->SetActive(false); - }; + info.deactivate = [](void *data) { static_cast(data)->SetActive(false); }; obs_register_source(&info); } /* ========================================================================= */ -extern void DispatchJSEvent(std::string eventName, std::string jsonString, - BrowserSource *browser = nullptr); +extern void DispatchJSEvent(std::string eventName, std::string jsonString, BrowserSource *browser = nullptr); static void handle_obs_frontend_event(enum obs_frontend_event event, void *) { @@ -623,8 +553,7 @@ static void handle_obs_frontend_event(enum obs_frontend_event event, void *) nlohmann::json json = {{"name", name}, {"width", obs_source_get_width(source)}, - {"height", - obs_source_get_height(source)}}; + {"height", obs_source_get_height(source)}}; DispatchJSEvent("obsSceneChanged", json.dump()); break; @@ -644,8 +573,7 @@ static void handle_obs_frontend_event(enum obs_frontend_event event, void *) break; } case OBS_FRONTEND_EVENT_TRANSITION_CHANGED: { - OBSSourceAutoRelease source = - obs_frontend_get_current_transition(); + OBSSourceAutoRelease source = obs_frontend_get_current_transition(); if (!source) break; @@ -665,8 +593,7 @@ static void handle_obs_frontend_event(enum obs_frontend_event event, void *) std::vector transitions_vector; for (size_t i = 0; i < list.sources.num; i++) { obs_source_t *source = list.sources.array[i]; - transitions_vector.push_back( - obs_source_get_name(source)); + transitions_vector.push_back(obs_source_get_name(source)); } nlohmann::json json = transitions_vector; obs_frontend_source_list_free(&list); @@ -714,8 +641,7 @@ static inline void EnumAdapterCount() #ifdef ENABLE_BROWSER_SHARED_TEXTURE #ifdef _WIN32 -static const wchar_t *blacklisted_devices[] = { - L"Intel", L"Microsoft", L"Radeon HD 8850M", L"Radeon HD 7660", nullptr}; +static const wchar_t *blacklisted_devices[] = {L"Intel", L"Microsoft", L"Radeon HD 8850M", L"Radeon HD 7660", nullptr}; static inline bool is_intel(const std::wstring &str) { @@ -776,10 +702,8 @@ bool obs_module_load(void) #endif #endif blog(LOG_INFO, "[obs-browser]: Version %s", OBS_BROWSER_VERSION_STRING); - blog(LOG_INFO, - "[obs-browser]: CEF Version %i.%i.%i.%i (runtime), %s (compiled)", - cef_version_info(4), cef_version_info(5), cef_version_info(6), - cef_version_info(7), CEF_VERSION); + blog(LOG_INFO, "[obs-browser]: CEF Version %i.%i.%i.%i (runtime), %s (compiled)", cef_version_info(4), + cef_version_info(5), cef_version_info(6), cef_version_info(7), CEF_VERSION); RegisterBrowserSource(); obs_frontend_add_event_callback(handle_obs_frontend_event, nullptr); @@ -807,25 +731,19 @@ void obs_module_post_load(void) if (!vendor) return; - auto emit_event_request_cb = [](obs_data_t *request_data, obs_data_t *, - void *) { - const char *event_name = - obs_data_get_string(request_data, "event_name"); + auto emit_event_request_cb = [](obs_data_t *request_data, obs_data_t *, void *) { + const char *event_name = obs_data_get_string(request_data, "event_name"); if (!event_name) return; - OBSDataAutoRelease event_data = - obs_data_get_obj(request_data, "event_data"); - const char *event_data_string = - event_data ? obs_data_get_json(event_data) : "{}"; + OBSDataAutoRelease event_data = obs_data_get_obj(request_data, "event_data"); + const char *event_data_string = event_data ? obs_data_get_json(event_data) : "{}"; DispatchJSEvent(event_name, event_data_string, nullptr); }; - if (!obs_websocket_vendor_register_request( - vendor, "emit_event", emit_event_request_cb, nullptr)) - blog(LOG_WARNING, - "[obs-browser]: Failed to register obs-websocket request emit_event"); + if (!obs_websocket_vendor_register_request(vendor, "emit_event", emit_event_request_cb, nullptr)) + blog(LOG_WARNING, "[obs-browser]: Failed to register obs-websocket request emit_event"); } void obs_module_unload(void) diff --git a/obs-browser-source-audio.cpp b/obs-browser-source-audio.cpp index dcb78ffb2..58309714d 100644 --- a/obs-browser-source-audio.cpp +++ b/obs-browser-source-audio.cpp @@ -25,9 +25,7 @@ void BrowserSource::EnumAudioStreams(obs_source_enum_proc_t cb, void *param) } } -static inline void mix_audio(float *__restrict p_out, - const float *__restrict p_in, size_t pos, - size_t count) +static inline void mix_audio(float *__restrict p_out, const float *__restrict p_in, size_t pos, size_t count) { float *__restrict out = p_out; const float *__restrict in = p_in + pos; @@ -37,9 +35,8 @@ static inline void mix_audio(float *__restrict p_out, *out++ += *in++; } -bool BrowserSource::AudioMix(uint64_t *ts_out, - struct audio_output_data *audio_output, - size_t channels, size_t sample_rate) +bool BrowserSource::AudioMix(uint64_t *ts_out, struct audio_output_data *audio_output, size_t channels, + size_t sample_rate) { uint64_t timestamp = 0; struct obs_source_audio_mix child_audio; @@ -70,8 +67,7 @@ bool BrowserSource::AudioMix(uint64_t *ts_out, continue; } - pos = (size_t)ns_to_audio_frames(sample_rate, - source_ts - timestamp); + pos = (size_t)ns_to_audio_frames(sample_rate, source_ts - timestamp); count = AUDIO_OUTPUT_FRAMES - pos; obs_source_get_audio_mix(s, &child_audio); diff --git a/obs-browser-source.cpp b/obs-browser-source.cpp index 258bbcd86..f4a1e4d96 100644 --- a/obs-browser-source.cpp +++ b/obs-browser-source.cpp @@ -59,32 +59,27 @@ static void SendBrowserVisibility(CefRefPtr browser, bool isVisible) } #endif - CefRefPtr msg = - CefProcessMessage::Create("Visibility"); + CefRefPtr msg = CefProcessMessage::Create("Visibility"); CefRefPtr args = msg->GetArgumentList(); args->SetBool(0, isVisible); SendBrowserProcessMessage(browser, PID_RENDERER, msg); } -void DispatchJSEvent(std::string eventName, std::string jsonString, - BrowserSource *browser = nullptr); +void DispatchJSEvent(std::string eventName, std::string jsonString, BrowserSource *browser = nullptr); -BrowserSource::BrowserSource(obs_data_t *, obs_source_t *source_) - : source(source_) +BrowserSource::BrowserSource(obs_data_t *, obs_source_t *source_) : source(source_) { /* Register Refresh hotkey */ - auto refreshFunction = [](void *data, obs_hotkey_id, obs_hotkey_t *, - bool pressed) { + auto refreshFunction = [](void *data, obs_hotkey_id, obs_hotkey_t *, bool pressed) { if (pressed) { BrowserSource *bs = (BrowserSource *)data; bs->Refresh(); } }; - obs_hotkey_register_source(source, "ObsBrowser.Refresh", - obs_module_text("RefreshNoCache"), - refreshFunction, (void *)this); + obs_hotkey_register_source(source, "ObsBrowser.Refresh", obs_module_text("RefreshNoCache"), refreshFunction, + (void *)this); auto jsEventFunction = [](void *p, calldata_t *calldata) { const auto eventName = calldata_string(calldata, "eventName"); @@ -97,10 +92,8 @@ BrowserSource::BrowserSource(obs_data_t *, obs_source_t *source_) }; proc_handler_t *ph = obs_source_get_proc_handler(source); - proc_handler_add( - ph, - "void javascript_event(string eventName, string jsonString)", - jsEventFunction, (void *)this); + proc_handler_add(ph, "void javascript_event(string eventName, string jsonString)", jsEventFunction, + (void *)this); /* defer update */ obs_source_update(source, nullptr); @@ -196,8 +189,7 @@ bool BrowserSource::CreateBrowser() #endif CefRefPtr browserClient = - new BrowserClient(this, hwaccel && tex_sharing_avail, - reroute_audio, webpage_control_level); + new BrowserClient(this, hwaccel && tex_sharing_avail, reroute_audio, webpage_control_level); CefWindowInfo windowInfo; #if CHROME_VERSION_BUILD < 4430 @@ -227,8 +219,7 @@ bool BrowserSource::CreateBrowser() struct obs_video_info ovi; obs_get_video_info(&ovi); canvas_fps = (double)ovi.fps_num / (double)ovi.fps_den; - cefBrowserSettings.windowless_frame_rate = - (fps_custom) ? fps : canvas_fps; + cefBrowserSettings.windowless_frame_rate = (fps_custom) ? fps : canvas_fps; #endif #else cefBrowserSettings.windowless_frame_rate = fps; @@ -244,9 +235,8 @@ bool BrowserSource::CreateBrowser() cefBrowserSettings.web_security = STATE_DISABLED; } #endif - auto browser = CefBrowserHost::CreateBrowserSync( - windowInfo, browserClient, url, cefBrowserSettings, - CefRefPtr(), nullptr); + auto browser = CefBrowserHost::CreateBrowserSync(windowInfo, browserClient, url, cefBrowserSettings, + CefRefPtr(), nullptr); SetBrowser(browser); @@ -274,8 +264,7 @@ void BrowserSource::ClearAudioStreams() }); } #endif -void BrowserSource::SendMouseClick(const struct obs_mouse_event *event, - int32_t type, bool mouse_up, +void BrowserSource::SendMouseClick(const struct obs_mouse_event *event, int32_t type, bool mouse_up, uint32_t click_count) { uint32_t modifiers = event->modifiers; @@ -288,16 +277,13 @@ void BrowserSource::SendMouseClick(const struct obs_mouse_event *event, e.modifiers = modifiers; e.x = x; e.y = y; - CefBrowserHost::MouseButtonType buttonType = - (CefBrowserHost::MouseButtonType)type; - cefBrowser->GetHost()->SendMouseClickEvent( - e, buttonType, mouse_up, click_count); + CefBrowserHost::MouseButtonType buttonType = (CefBrowserHost::MouseButtonType)type; + cefBrowser->GetHost()->SendMouseClickEvent(e, buttonType, mouse_up, click_count); }, true); } -void BrowserSource::SendMouseMove(const struct obs_mouse_event *event, - bool mouse_leave) +void BrowserSource::SendMouseMove(const struct obs_mouse_event *event, bool mouse_leave) { uint32_t modifiers = event->modifiers; int32_t x = event->x; @@ -309,14 +295,12 @@ void BrowserSource::SendMouseMove(const struct obs_mouse_event *event, e.modifiers = modifiers; e.x = x; e.y = y; - cefBrowser->GetHost()->SendMouseMoveEvent(e, - mouse_leave); + cefBrowser->GetHost()->SendMouseMoveEvent(e, mouse_leave); }, true); } -void BrowserSource::SendMouseWheel(const struct obs_mouse_event *event, - int x_delta, int y_delta) +void BrowserSource::SendMouseWheel(const struct obs_mouse_event *event, int x_delta, int y_delta) { uint32_t modifiers = event->modifiers; int32_t x = event->x; @@ -328,8 +312,7 @@ void BrowserSource::SendMouseWheel(const struct obs_mouse_event *event, e.modifiers = modifiers; e.x = x; e.y = y; - cefBrowser->GetHost()->SendMouseWheelEvent(e, x_delta, - y_delta); + cefBrowser->GetHost()->SendMouseWheelEvent(e, x_delta, y_delta); }, true); } @@ -388,8 +371,7 @@ void BrowserSource::SendKeyClick(const struct obs_key_event *event, bool key_up) if (!text.empty() && !key_up) { e.type = KEYEVENT_CHAR; #ifdef __linux__ - e.windows_key_code = - KeyboardCodeFromXKeysym(e.character); + e.windows_key_code = KeyboardCodeFromXKeysym(e.character); #elif defined(_WIN32) e.windows_key_code = e.character; #elif !defined(__APPLE__) @@ -417,20 +399,16 @@ void BrowserSource::SetShowing(bool showing) } else { ExecuteOnBrowser( [=](CefRefPtr cefBrowser) { - CefRefPtr msg = - CefProcessMessage::Create("Visibility"); - CefRefPtr args = - msg->GetArgumentList(); + CefRefPtr msg = CefProcessMessage::Create("Visibility"); + CefRefPtr args = msg->GetArgumentList(); args->SetBool(0, showing); - SendBrowserProcessMessage(cefBrowser, - PID_RENDERER, msg); + SendBrowserProcessMessage(cefBrowser, PID_RENDERER, msg); }, true); nlohmann::json json; json["visible"] = showing; DispatchJSEvent("obsSourceVisibleChanged", json.dump(), this); -#if defined(BROWSER_EXTERNAL_BEGIN_FRAME_ENABLED) && \ - defined(ENABLE_BROWSER_SHARED_TEXTURE) +#if defined(BROWSER_EXTERNAL_BEGIN_FRAME_ENABLED) && defined(ENABLE_BROWSER_SHARED_TEXTURE) if (showing && !fps_custom) { reset_frame = false; } @@ -455,12 +433,10 @@ void BrowserSource::SetActive(bool active) { ExecuteOnBrowser( [=](CefRefPtr cefBrowser) { - CefRefPtr msg = - CefProcessMessage::Create("Active"); + CefRefPtr msg = CefProcessMessage::Create("Active"); CefRefPtr args = msg->GetArgumentList(); args->SetBool(0, active); - SendBrowserProcessMessage(cefBrowser, PID_RENDERER, - msg); + SendBrowserProcessMessage(cefBrowser, PID_RENDERER, msg); }, true); nlohmann::json json; @@ -470,11 +446,7 @@ void BrowserSource::SetActive(bool active) void BrowserSource::Refresh() { - ExecuteOnBrowser( - [](CefRefPtr cefBrowser) { - cefBrowser->ReloadIgnoreCache(); - }, - true); + ExecuteOnBrowser([](CefRefPtr cefBrowser) { cefBrowser->ReloadIgnoreCache(); }, true); } void BrowserSource::SetBrowser(CefRefPtr b) @@ -495,9 +467,7 @@ inline void BrowserSource::SignalBeginFrame() { if (reset_frame) { ExecuteOnBrowser( - [](CefRefPtr cefBrowser) { - cefBrowser->GetHost()->SendExternalBeginFrame(); - }, + [](CefRefPtr cefBrowser) { cefBrowser->GetHost()->SendExternalBeginFrame(); }, true); reset_frame = false; @@ -529,11 +499,10 @@ void BrowserSource::Update(obs_data_t *settings) n_shutdown = obs_data_get_bool(settings, "shutdown"); n_restart = obs_data_get_bool(settings, "restart_when_active"); n_css = obs_data_get_string(settings, "css"); - n_url = obs_data_get_string(settings, - n_is_local ? "local_file" : "url"); + n_url = obs_data_get_string(settings, n_is_local ? "local_file" : "url"); n_reroute = obs_data_get_bool(settings, "reroute_audio"); - n_webpage_control_level = static_cast( - obs_data_get_int(settings, "webpage_control_level")); + n_webpage_control_level = + static_cast(obs_data_get_int(settings, "webpage_control_level")); if (n_is_local && !n_url.empty()) { n_url = CefURIEncode(n_url, false); @@ -542,8 +511,7 @@ void BrowserSource::Update(obs_data_t *settings) size_t slash = n_url.find("%2F"); size_t colon = n_url.find("%3A"); - if (slash != std::string::npos && - colon != std::string::npos && colon < slash) + if (slash != std::string::npos && colon != std::string::npos && colon < slash) n_url.replace(colon, 3, ":"); #endif @@ -576,11 +544,9 @@ void BrowserSource::Update(obs_data_t *settings) } #endif - if (n_is_local == is_local && n_fps_custom == fps_custom && - n_fps == fps && n_shutdown == shutdown_on_invisible && - n_restart == restart && n_css == css && n_url == url && - n_reroute == reroute_audio && - n_webpage_control_level == webpage_control_level) { + if (n_is_local == is_local && n_fps_custom == fps_custom && n_fps == fps && + n_shutdown == shutdown_on_invisible && n_restart == restart && n_css == css && n_url == url && + n_reroute == reroute_audio && n_webpage_control_level == webpage_control_level) { if (n_width == width && n_height == height) return; @@ -590,14 +556,10 @@ void BrowserSource::Update(obs_data_t *settings) ExecuteOnBrowser( [=](CefRefPtr cefBrowser) { const CefSize cefSize(width, height); - cefBrowser->GetHost() - ->GetClient() - ->GetDisplayHandler() - ->OnAutoResize(cefBrowser, - cefSize); + cefBrowser->GetHost()->GetClient()->GetDisplayHandler()->OnAutoResize( + cefBrowser, cefSize); cefBrowser->GetHost()->WasResized(); - cefBrowser->GetHost()->Invalidate( - PET_VIEW); + cefBrowser->GetHost()->Invalidate(PET_VIEW); }, true); return; @@ -644,8 +606,7 @@ void BrowserSource::Tick() if (!fps_custom) { if (!!cefBrowser && canvas_fps != video_fps) { - cefBrowser->GetHost()->SetWindowlessFrameRate( - video_fps); + cefBrowser->GetHost()->SetWindowlessFrameRate(video_fps); canvas_fps = video_fps; } } @@ -664,17 +625,14 @@ void BrowserSource::Render() if (texture) { #ifdef __APPLE__ - gs_effect_t *effect = - obs_get_base_effect((hwaccel) ? OBS_EFFECT_DEFAULT_RECT - : OBS_EFFECT_DEFAULT); + gs_effect_t *effect = obs_get_base_effect((hwaccel) ? OBS_EFFECT_DEFAULT_RECT : OBS_EFFECT_DEFAULT); #else gs_effect_t *effect = obs_get_base_effect(OBS_EFFECT_DEFAULT); #endif bool linear_sample = extra_texture == NULL; gs_texture_t *draw_texture = texture; - if (!linear_sample && - !obs_source_get_texcoords_centered(source)) { + if (!linear_sample && !obs_source_get_texcoords_centered(source)) { gs_copy_texture(extra_texture, texture); draw_texture = extra_texture; @@ -687,8 +645,7 @@ void BrowserSource::Render() gs_blend_state_push(); gs_blend_function(GS_BLEND_ONE, GS_BLEND_INVSRCALPHA); - gs_eparam_t *const image = - gs_effect_get_param_by_name(effect, "image"); + gs_eparam_t *const image = gs_effect_get_param_by_name(effect, "image"); const char *tech; if (linear_sample) { @@ -708,8 +665,7 @@ void BrowserSource::Render() gs_enable_framebuffer_srgb(previous); } -#if defined(BROWSER_EXTERNAL_BEGIN_FRAME_ENABLED) && \ - defined(ENABLE_BROWSER_SHARED_TEXTURE) +#if defined(BROWSER_EXTERNAL_BEGIN_FRAME_ENABLED) && defined(ENABLE_BROWSER_SHARED_TEXTURE) SignalBeginFrame(); #elif defined(ENABLE_BROWSER_QT_LOOP) ProcessCef(); @@ -738,12 +694,10 @@ static void ExecuteOnAllBrowsers(BrowserFunc func) } } -void DispatchJSEvent(std::string eventName, std::string jsonString, - BrowserSource *browser) +void DispatchJSEvent(std::string eventName, std::string jsonString, BrowserSource *browser) { const auto jsEvent = [=](CefRefPtr cefBrowser) { - CefRefPtr msg = - CefProcessMessage::Create("DispatchJSEvent"); + CefRefPtr msg = CefProcessMessage::Create("DispatchJSEvent"); CefRefPtr args = msg->GetArgumentList(); args->SetString(0, eventName); diff --git a/obs-browser-source.hpp b/obs-browser-source.hpp index 7c77f2e6d..1aa2da6ae 100644 --- a/obs-browser-source.hpp +++ b/obs-browser-source.hpp @@ -91,8 +91,7 @@ struct BrowserSource { bool reroute_audio = true; std::atomic destroying = false; ControlLevel webpage_control_level = DEFAULT_CONTROL_LEVEL; -#if defined(BROWSER_EXTERNAL_BEGIN_FRAME_ENABLED) && \ - defined(ENABLE_BROWSER_SHARED_TEXTURE) +#if defined(BROWSER_EXTERNAL_BEGIN_FRAME_ENABLED) && defined(ENABLE_BROWSER_SHARED_TEXTURE) bool reset_frame = false; #endif bool is_showing = false; @@ -133,26 +132,21 @@ struct BrowserSource { #if CHROME_VERSION_BUILD < 4103 void ClearAudioStreams(); void EnumAudioStreams(obs_source_enum_proc_t cb, void *param); - bool AudioMix(uint64_t *ts_out, struct audio_output_data *audio_output, - size_t channels, size_t sample_rate); + bool AudioMix(uint64_t *ts_out, struct audio_output_data *audio_output, size_t channels, size_t sample_rate); std::mutex audio_sources_mutex; std::vector audio_sources; std::unordered_map audio_streams; #endif - void SendMouseClick(const struct obs_mouse_event *event, int32_t type, - bool mouse_up, uint32_t click_count); - void SendMouseMove(const struct obs_mouse_event *event, - bool mouse_leave); - void SendMouseWheel(const struct obs_mouse_event *event, int x_delta, - int y_delta); + void SendMouseClick(const struct obs_mouse_event *event, int32_t type, bool mouse_up, uint32_t click_count); + void SendMouseMove(const struct obs_mouse_event *event, bool mouse_leave); + void SendMouseWheel(const struct obs_mouse_event *event, int x_delta, int y_delta); void SendFocus(bool focus); void SendKeyClick(const struct obs_key_event *event, bool key_up); void SetShowing(bool showing); void SetActive(bool active); void Refresh(); -#if defined(BROWSER_EXTERNAL_BEGIN_FRAME_ENABLED) && \ - defined(ENABLE_BROWSER_SHARED_TEXTURE) +#if defined(BROWSER_EXTERNAL_BEGIN_FRAME_ENABLED) && defined(ENABLE_BROWSER_SHARED_TEXTURE) inline void SignalBeginFrame(); #endif diff --git a/panel/browser-panel-client.cpp b/panel/browser-panel-client.cpp index bd7eedc7c..9992ff6a6 100644 --- a/panel/browser-panel-client.cpp +++ b/panel/browser-panel-client.cpp @@ -69,14 +69,12 @@ CefRefPtr QCefBrowserClient::GetJSDialogHandler() } /* CefDisplayHandler */ -void QCefBrowserClient::OnTitleChange(CefRefPtr browser, - const CefString &title) +void QCefBrowserClient::OnTitleChange(CefRefPtr browser, const CefString &title) { if (widget && widget->cefBrowser->IsSame(browser)) { std::string str_title = title; QString qt_title = QString::fromUtf8(str_title.c_str()); - QMetaObject::invokeMethod(widget, "titleChanged", - Q_ARG(QString, qt_title)); + QMetaObject::invokeMethod(widget, "titleChanged", Q_ARG(QString, qt_title)); } else { /* handle popup title */ if (title.compare("DevTools") == 0) return; @@ -93,10 +91,8 @@ void QCefBrowserClient::OnTitleChange(CefRefPtr browser, } /* CefRequestHandler */ -bool QCefBrowserClient::OnBeforeBrowse(CefRefPtr browser, - CefRefPtr, - CefRefPtr request, bool, - bool) +bool QCefBrowserClient::OnBeforeBrowse(CefRefPtr browser, CefRefPtr, + CefRefPtr request, bool, bool) { std::string str_url = request->GetURL(); @@ -120,15 +116,13 @@ bool QCefBrowserClient::OnBeforeBrowse(CefRefPtr browser, if (widget) { QString qt_url = QString::fromUtf8(str_url.c_str()); - QMetaObject::invokeMethod(widget, "urlChanged", - Q_ARG(QString, qt_url)); + QMetaObject::invokeMethod(widget, "urlChanged", Q_ARG(QString, qt_url)); } return false; } -bool QCefBrowserClient::OnOpenURLFromTab( - CefRefPtr, CefRefPtr, const CefString &target_url, - CefRequestHandler::WindowOpenDisposition, bool) +bool QCefBrowserClient::OnOpenURLFromTab(CefRefPtr, CefRefPtr, const CefString &target_url, + CefRequestHandler::WindowOpenDisposition, bool) { std::string str_url = target_url; @@ -138,10 +132,8 @@ bool QCefBrowserClient::OnOpenURLFromTab( return true; } -void QCefBrowserClient::OnLoadError(CefRefPtr browser, - CefRefPtr frame, - CefLoadHandler::ErrorCode errorCode, - const CefString &errorText, +void QCefBrowserClient::OnLoadError(CefRefPtr browser, CefRefPtr frame, + CefLoadHandler::ErrorCode errorCode, const CefString &errorText, const CefString &failedUrl) { UNUSED_PARAMETER(browser); @@ -157,23 +149,18 @@ void QCefBrowserClient::OnLoadError(CefRefPtr browser, dstr_replace(&html, "%%ERROR_URL%%", failedUrl.ToString().c_str()); dstr_replace(&html, "Error.Title", obs_module_text("Error.Title")); - dstr_replace(&html, "Error.Description", - obs_module_text("Error.Description")); + dstr_replace(&html, "Error.Description", obs_module_text("Error.Description")); dstr_replace(&html, "Error.Retry", obs_module_text("Error.Retry")); const char *translError; std::string errorKey = "ErrorCode." + errorText.ToString(); - if (obs_module_get_string(errorKey.c_str(), - (const char **)&translError)) { + if (obs_module_get_string(errorKey.c_str(), (const char **)&translError)) { dstr_replace(&html, "%%ERROR_CODE%%", translError); } else { - dstr_replace(&html, "%%ERROR_CODE%%", - errorText.ToString().c_str()); + dstr_replace(&html, "%%ERROR_CODE%%", errorText.ToString().c_str()); } - frame->LoadURL( - "data:text/html;base64," + - CefURIEncode(CefBase64Encode(html.array, html.len), false) - .ToString()); + frame->LoadURL("data:text/html;base64," + + CefURIEncode(CefBase64Encode(html.array, html.len), false).ToString()); dstr_free(&html); bfree(path); @@ -181,12 +168,10 @@ void QCefBrowserClient::OnLoadError(CefRefPtr browser, } /* CefLifeSpanHandler */ -bool QCefBrowserClient::OnBeforePopup( - CefRefPtr, CefRefPtr, const CefString &target_url, - const CefString &, CefLifeSpanHandler::WindowOpenDisposition, bool, - const CefPopupFeatures &, CefWindowInfo &windowInfo, - CefRefPtr &, CefBrowserSettings &, - CefRefPtr &, bool *) +bool QCefBrowserClient::OnBeforePopup(CefRefPtr, CefRefPtr, const CefString &target_url, + const CefString &, CefLifeSpanHandler::WindowOpenDisposition, bool, + const CefPopupFeatures &, CefWindowInfo &windowInfo, CefRefPtr &, + CefBrowserSettings &, CefRefPtr &, bool *) { if (allowAllPopups) { #ifdef _WIN32 @@ -205,8 +190,7 @@ bool QCefBrowserClient::OnBeforePopup( PopupWhitelistInfo &info = popup_whitelist[i - 1]; if (!info.obj) { - popup_whitelist.erase(popup_whitelist.begin() + - (i - 1)); + popup_whitelist.erase(popup_whitelist.begin() + (i - 1)); continue; } @@ -225,8 +209,7 @@ bool QCefBrowserClient::OnBeforePopup( return true; } -bool QCefBrowserClient::OnSetFocus(CefRefPtr, - CefFocusHandler::FocusSource source) +bool QCefBrowserClient::OnSetFocus(CefRefPtr, CefFocusHandler::FocusSource source) { /* Don't steal focus when the webpage navigates. This is especially obvious on startup when the user has many browser docks defined, @@ -240,17 +223,12 @@ bool QCefBrowserClient::OnSetFocus(CefRefPtr, } } -void QCefBrowserClient::OnBeforeContextMenu(CefRefPtr browser, - CefRefPtr, - CefRefPtr, - CefRefPtr model) +void QCefBrowserClient::OnBeforeContextMenu(CefRefPtr browser, CefRefPtr, + CefRefPtr, CefRefPtr model) { if (model->IsVisible(MENU_ID_BACK) && - (!model->IsVisible(MENU_ID_RELOAD) && - !model->IsVisible(MENU_ID_RELOAD_NOCACHE))) { - model->InsertItemAt( - 2, MENU_ID_RELOAD_NOCACHE, - QObject::tr("RefreshBrowser").toUtf8().constData()); + (!model->IsVisible(MENU_ID_RELOAD) && !model->IsVisible(MENU_ID_RELOAD_NOCACHE))) { + model->InsertItemAt(2, MENU_ID_RELOAD_NOCACHE, QObject::tr("RefreshBrowser").toUtf8().constData()); } if (model->IsVisible(MENU_ID_PRINT)) { model->Remove(MENU_ID_PRINT); @@ -260,85 +238,70 @@ void QCefBrowserClient::OnBeforeContextMenu(CefRefPtr browser, } model->AddItem(MENU_ITEM_ZOOM_IN, obs_module_text("Zoom.In")); if (browser->GetHost()->GetZoomLevel() != 0) { - model->AddItem(MENU_ITEM_ZOOM_RESET, - obs_module_text("Zoom.Reset")); + model->AddItem(MENU_ITEM_ZOOM_RESET, obs_module_text("Zoom.Reset")); } model->AddItem(MENU_ITEM_ZOOM_OUT, obs_module_text("Zoom.Out")); model->AddSeparator(); - model->InsertItemAt(model->GetCount(), MENU_ITEM_COPY_URL, - obs_module_text("CopyUrl")); - model->InsertItemAt(model->GetCount(), MENU_ITEM_DEVTOOLS, - obs_module_text("Inspect")); - model->InsertCheckItemAt(model->GetCount(), MENU_ITEM_MUTE, - QObject::tr("Mute").toUtf8().constData()); + model->InsertItemAt(model->GetCount(), MENU_ITEM_COPY_URL, obs_module_text("CopyUrl")); + model->InsertItemAt(model->GetCount(), MENU_ITEM_DEVTOOLS, obs_module_text("Inspect")); + model->InsertCheckItemAt(model->GetCount(), MENU_ITEM_MUTE, QObject::tr("Mute").toUtf8().constData()); model->SetChecked(MENU_ITEM_MUTE, browser->GetHost()->IsAudioMuted()); } #if defined(_WIN32) -bool QCefBrowserClient::RunContextMenu( - CefRefPtr, CefRefPtr, - CefRefPtr, CefRefPtr model, - CefRefPtr callback) +bool QCefBrowserClient::RunContextMenu(CefRefPtr, CefRefPtr, CefRefPtr, + CefRefPtr model, CefRefPtr callback) { std::vector> menu_items; menu_items.reserve(model->GetCount()); for (int i = 0; i < model->GetCount(); i++) { - menu_items.push_back( - {model->GetLabelAt(i), model->GetCommandIdAt(i), - model->IsEnabledAt(i), model->GetTypeAt(i), - model->IsCheckedAt(i)}); + menu_items.push_back({model->GetLabelAt(i), model->GetCommandIdAt(i), model->IsEnabledAt(i), + model->GetTypeAt(i), model->IsCheckedAt(i)}); } - QMetaObject::invokeMethod( - QCoreApplication::instance()->thread(), - [menu_items, callback]() { - QMenu contextMenu; - std::string name; - int command_id; - bool enabled; - int type_id; - bool check; - - for (const std::tuple - &menu_item : menu_items) { - std::tie(name, command_id, enabled, type_id, - check) = menu_item; - switch (type_id) { - case MENUITEMTYPE_CHECK: - case MENUITEMTYPE_COMMAND: { - QAction *item = - new QAction(name.c_str()); - item->setEnabled(enabled); - if (type_id == MENUITEMTYPE_CHECK) { - item->setCheckable(true); - item->setChecked(check); - } - item->setProperty("cmd_id", command_id); - contextMenu.addAction(item); - } break; - case MENUITEMTYPE_SEPARATOR: - contextMenu.addSeparator(); - break; + QMetaObject::invokeMethod(QCoreApplication::instance()->thread(), [menu_items, callback]() { + QMenu contextMenu; + std::string name; + int command_id; + bool enabled; + int type_id; + bool check; + + for (const std::tuple &menu_item : menu_items) { + std::tie(name, command_id, enabled, type_id, check) = menu_item; + switch (type_id) { + case MENUITEMTYPE_CHECK: + case MENUITEMTYPE_COMMAND: { + QAction *item = new QAction(name.c_str()); + item->setEnabled(enabled); + if (type_id == MENUITEMTYPE_CHECK) { + item->setCheckable(true); + item->setChecked(check); } + item->setProperty("cmd_id", command_id); + contextMenu.addAction(item); + } break; + case MENUITEMTYPE_SEPARATOR: + contextMenu.addSeparator(); + break; } + } - QAction *action = contextMenu.exec(QCursor::pos()); - if (action) { - QVariant cmdId = action->property("cmd_id"); - callback.get()->Continue(cmdId.toInt(), - EVENTFLAG_NONE); - } else { - callback.get()->Cancel(); - } - }); + QAction *action = contextMenu.exec(QCursor::pos()); + if (action) { + QVariant cmdId = action->property("cmd_id"); + callback.get()->Continue(cmdId.toInt(), EVENTFLAG_NONE); + } else { + callback.get()->Cancel(); + } + }); return true; } #endif -bool QCefBrowserClient::OnContextMenuCommand( - CefRefPtr browser, CefRefPtr, - CefRefPtr params, int command_id, - CefContextMenuHandler::EventFlags) +bool QCefBrowserClient::OnContextMenuCommand(CefRefPtr browser, CefRefPtr, + CefRefPtr params, int command_id, + CefContextMenuHandler::EventFlags) { if (command_id < MENU_ID_CUSTOM_FIRST) return false; @@ -349,19 +312,16 @@ bool QCefBrowserClient::OnContextMenuCommand( switch (command_id) { case MENU_ITEM_DEVTOOLS: #if defined(_WIN32) && CHROME_VERSION_BUILD < 6533 - title = QString(obs_module_text("DevTools")) - .arg(widget->parentWidget()->windowTitle()); - windowInfo.SetAsPopup(host->GetWindowHandle(), - title.toUtf8().constData()); + title = QString(obs_module_text("DevTools")).arg(widget->parentWidget()->windowTitle()); + windowInfo.SetAsPopup(host->GetWindowHandle(), title.toUtf8().constData()); #endif pos = widget->mapToGlobal(QPoint(0, 0)); windowInfo.bounds.x = pos.x(); windowInfo.bounds.y = pos.y() + 30; windowInfo.bounds.width = 900; windowInfo.bounds.height = 700; - host->ShowDevTools( - windowInfo, host->GetClient(), CefBrowserSettings(), - {params.get()->GetXCoord(), params.get()->GetYCoord()}); + host->ShowDevTools(windowInfo, host->GetClient(), CefBrowserSettings(), + {params.get()->GetXCoord(), params.get()->GetYCoord()}); return true; case MENU_ITEM_MUTE: host->SetAudioMuted(!host->IsAudioMuted()); @@ -383,20 +343,17 @@ bool QCefBrowserClient::OnContextMenuCommand( clipboard->setText(url.c_str(), QClipboard::Clipboard); if (clipboard->supportsSelection()) { - clipboard->setText(url.c_str(), - QClipboard::Selection); + clipboard->setText(url.c_str(), QClipboard::Selection); } }; - QMetaObject::invokeMethod( - QCoreApplication::instance()->thread(), saveClipboard); + QMetaObject::invokeMethod(QCoreApplication::instance()->thread(), saveClipboard); return true; break; } return false; } -void QCefBrowserClient::OnLoadStart(CefRefPtr, - CefRefPtr frame, TransitionType) +void QCefBrowserClient::OnLoadStart(CefRefPtr, CefRefPtr frame, TransitionType) { if (!frame->IsMain()) return; @@ -408,8 +365,7 @@ void QCefBrowserClient::OnLoadStart(CefRefPtr, frame->ExecuteJavaScript(script, "", 0); } -void QCefBrowserClient::OnLoadEnd(CefRefPtr, - CefRefPtr frame, int) +void QCefBrowserClient::OnLoadEnd(CefRefPtr, CefRefPtr frame, int) { if (!frame->IsMain()) return; @@ -421,10 +377,8 @@ void QCefBrowserClient::OnLoadEnd(CefRefPtr, } bool QCefBrowserClient::OnJSDialog(CefRefPtr, const CefString &, - CefJSDialogHandler::JSDialogType dialog_type, - const CefString &message_text, - const CefString &default_prompt_text, - CefRefPtr callback, + CefJSDialogHandler::JSDialogType dialog_type, const CefString &message_text, + const CefString &default_prompt_text, CefRefPtr callback, bool &) { QString parentTitle = widget->parentWidget()->windowTitle(); @@ -432,31 +386,26 @@ bool QCefBrowserClient::OnJSDialog(CefRefPtr, const CefString &, QString msg_raw(message_text.ToString().c_str()); // Replace
with standard newline as we will render in plaintext msg_raw.replace(QRegularExpression(""), "\n"); - QString submsg = - QString(obs_module_text("Dialog.ReceivedFrom")).arg(parentTitle); + QString submsg = QString(obs_module_text("Dialog.ReceivedFrom")).arg(parentTitle); QString msg = QString("%1\n\n\n%2").arg(msg_raw).arg(submsg); if (dialog_type == JSDIALOGTYPE_PROMPT) { auto msgbox = [msg, default_value, callback]() { QInputDialog *dlg = new QInputDialog(nullptr); dlg->setWindowFlag(Qt::WindowStaysOnTopHint, true); - dlg->setWindowFlag(Qt::WindowContextHelpButtonHint, - false); + dlg->setWindowFlag(Qt::WindowContextHelpButtonHint, false); std::stringstream title; - title << obs_module_text("Dialog.Prompt") << ": " - << obs_module_text("Dialog.BrowserDock"); + title << obs_module_text("Dialog.Prompt") << ": " << obs_module_text("Dialog.BrowserDock"); dlg->setWindowTitle(title.str().c_str()); if (!default_value.empty()) dlg->setTextValue(default_value.c_str()); auto finished = [callback, dlg](int result) { - callback.get()->Continue( - result == QDialog::Accepted, - dlg->textValue().toUtf8().constData()); + callback.get()->Continue(result == QDialog::Accepted, + dlg->textValue().toUtf8().constData()); }; - QWidget::connect(dlg, &QInputDialog::finished, - finished); + QWidget::connect(dlg, &QInputDialog::finished, finished); dlg->open(); if (QLabel *lbl = dlg->findChild()) { // Force plaintext manually @@ -464,8 +413,7 @@ bool QCefBrowserClient::OnJSDialog(CefRefPtr, const CefString &, } dlg->setLabelText(msg); }; - QMetaObject::invokeMethod( - QCoreApplication::instance()->thread(), msgbox); + QMetaObject::invokeMethod(QCoreApplication::instance()->thread(), msgbox); return true; } auto msgbox = [msg, dialog_type, callback]() { @@ -490,22 +438,17 @@ bool QCefBrowserClient::OnJSDialog(CefRefPtr, const CefString &, title << ": " << obs_module_text("Dialog.BrowserDock"); dlg->setWindowTitle(title.str().c_str()); - auto finished = [callback](int result) { - callback.get()->Continue(result == QMessageBox::Ok, ""); - }; + auto finished = [callback](int result) { callback.get()->Continue(result == QMessageBox::Ok, ""); }; QWidget::connect(dlg, &QMessageBox::finished, finished); dlg->open(); }; - QMetaObject::invokeMethod(QCoreApplication::instance()->thread(), - msgbox); + QMetaObject::invokeMethod(QCoreApplication::instance()->thread(), msgbox); return true; } -bool QCefBrowserClient::OnPreKeyEvent(CefRefPtr browser, - const CefKeyEvent &event, CefEventHandle, - bool *) +bool QCefBrowserClient::OnPreKeyEvent(CefRefPtr browser, const CefKeyEvent &event, CefEventHandle, bool *) { if (event.type != KEYEVENT_RAWKEYDOWN) return false; @@ -518,18 +461,15 @@ bool QCefBrowserClient::OnPreKeyEvent(CefRefPtr browser, #endif browser->ReloadIgnoreCache(); return true; - } else if ((event.windows_key_code == 189 || - event.windows_key_code == 109) && + } else if ((event.windows_key_code == 189 || event.windows_key_code == 109) && (event.modifiers & EVENTFLAG_CONTROL_DOWN) != 0) { // Zoom out return widget->zoomPage(-1); - } else if ((event.windows_key_code == 187 || - event.windows_key_code == 107) && + } else if ((event.windows_key_code == 187 || event.windows_key_code == 107) && (event.modifiers & EVENTFLAG_CONTROL_DOWN) != 0) { // Zoom in return widget->zoomPage(1); - } else if ((event.windows_key_code == 48 || - event.windows_key_code == 96) && + } else if ((event.windows_key_code == 48 || event.windows_key_code == 96) && (event.modifiers & EVENTFLAG_CONTROL_DOWN) != 0) { // Reset zoom return widget->zoomPage(0); diff --git a/panel/browser-panel-client.hpp b/panel/browser-panel-client.hpp index c099fd6d1..dc81177d4 100644 --- a/panel/browser-panel-client.hpp +++ b/panel/browser-panel-client.hpp @@ -16,12 +16,8 @@ class QCefBrowserClient : public CefClient, public CefJSDialogHandler { public: - inline QCefBrowserClient(QCefWidgetInternal *widget_, - const std::string &script_, - bool allowAllPopups_) - : widget(widget_), - script(script_), - allowAllPopups(allowAllPopups_) + inline QCefBrowserClient(QCefWidgetInternal *widget_, const std::string &script_, bool allowAllPopups_) + : widget(widget_), script(script_), allowAllPopups(allowAllPopups_) { } @@ -32,90 +28,65 @@ class QCefBrowserClient : public CefClient, virtual CefRefPtr GetLifeSpanHandler() override; virtual CefRefPtr GetKeyboardHandler() override; virtual CefRefPtr GetFocusHandler() override; - virtual CefRefPtr - GetContextMenuHandler() override; + virtual CefRefPtr GetContextMenuHandler() override; virtual CefRefPtr GetJSDialogHandler() override; /* CefDisplayHandler */ - virtual void OnTitleChange(CefRefPtr browser, - const CefString &title) override; + virtual void OnTitleChange(CefRefPtr browser, const CefString &title) override; /* CefRequestHandler */ - virtual bool OnBeforeBrowse(CefRefPtr browser, - CefRefPtr frame, - CefRefPtr request, - bool user_gesture, - bool is_redirect) override; - - virtual void OnLoadError(CefRefPtr browser, - CefRefPtr frame, - CefLoadHandler::ErrorCode errorCode, - const CefString &errorText, + virtual bool OnBeforeBrowse(CefRefPtr browser, CefRefPtr frame, + CefRefPtr request, bool user_gesture, bool is_redirect) override; + + virtual void OnLoadError(CefRefPtr browser, CefRefPtr frame, + CefLoadHandler::ErrorCode errorCode, const CefString &errorText, const CefString &failedUrl) override; - virtual bool OnOpenURLFromTab( - CefRefPtr browser, CefRefPtr frame, - const CefString &target_url, - CefRequestHandler::WindowOpenDisposition target_disposition, - bool user_gesture) override; + virtual bool OnOpenURLFromTab(CefRefPtr browser, CefRefPtr frame, + const CefString &target_url, + CefRequestHandler::WindowOpenDisposition target_disposition, + bool user_gesture) override; /* CefLifeSpanHandler */ - virtual bool OnBeforePopup( - CefRefPtr browser, CefRefPtr frame, - const CefString &target_url, const CefString &target_frame_name, - CefLifeSpanHandler::WindowOpenDisposition target_disposition, - bool user_gesture, const CefPopupFeatures &popupFeatures, - CefWindowInfo &windowInfo, CefRefPtr &client, - CefBrowserSettings &settings, - CefRefPtr &extra_info, - bool *no_javascript_access) override; + virtual bool OnBeforePopup(CefRefPtr browser, CefRefPtr frame, + const CefString &target_url, const CefString &target_frame_name, + CefLifeSpanHandler::WindowOpenDisposition target_disposition, bool user_gesture, + const CefPopupFeatures &popupFeatures, CefWindowInfo &windowInfo, + CefRefPtr &client, CefBrowserSettings &settings, + CefRefPtr &extra_info, bool *no_javascript_access) override; /* CefFocusHandler */ - virtual bool OnSetFocus(CefRefPtr browser, - CefFocusHandler::FocusSource source) override; + virtual bool OnSetFocus(CefRefPtr browser, CefFocusHandler::FocusSource source) override; /* CefContextMenuHandler */ - virtual void - OnBeforeContextMenu(CefRefPtr browser, - CefRefPtr frame, - CefRefPtr params, - CefRefPtr model) override; + virtual void OnBeforeContextMenu(CefRefPtr browser, CefRefPtr frame, + CefRefPtr params, + CefRefPtr model) override; #if defined(_WIN32) - virtual bool - RunContextMenu(CefRefPtr browser, CefRefPtr frame, - CefRefPtr params, - CefRefPtr model, - CefRefPtr callback) override; + virtual bool RunContextMenu(CefRefPtr browser, CefRefPtr frame, + CefRefPtr params, CefRefPtr model, + CefRefPtr callback) override; #endif - virtual bool OnContextMenuCommand( - CefRefPtr browser, CefRefPtr frame, - CefRefPtr params, int command_id, - CefContextMenuHandler::EventFlags event_flags) override; + virtual bool OnContextMenuCommand(CefRefPtr browser, CefRefPtr frame, + CefRefPtr params, int command_id, + CefContextMenuHandler::EventFlags event_flags) override; /* CefLoadHandler */ - virtual void OnLoadStart(CefRefPtr browser, - CefRefPtr frame, + virtual void OnLoadStart(CefRefPtr browser, CefRefPtr frame, TransitionType transition_type) override; - virtual void OnLoadEnd(CefRefPtr browser, - CefRefPtr frame, - int httpStatusCode) override; + virtual void OnLoadEnd(CefRefPtr browser, CefRefPtr frame, int httpStatusCode) override; /* CefKeyboardHandler */ - virtual bool OnPreKeyEvent(CefRefPtr browser, - const CefKeyEvent &event, - CefEventHandle os_event, + virtual bool OnPreKeyEvent(CefRefPtr browser, const CefKeyEvent &event, CefEventHandle os_event, bool *is_keyboard_shortcut) override; /* CefJSDialogHandler */ - virtual bool OnJSDialog(CefRefPtr browser, - const CefString &origin_url, - CefJSDialogHandler::JSDialogType dialog_type, - const CefString &message_text, - const CefString &default_prompt_text, - CefRefPtr callback, + virtual bool OnJSDialog(CefRefPtr browser, const CefString &origin_url, + CefJSDialogHandler::JSDialogType dialog_type, const CefString &message_text, + const CefString &default_prompt_text, CefRefPtr callback, bool &suppress_message) override; QCefWidgetInternal *widget = nullptr; diff --git a/panel/browser-panel-internal.hpp b/panel/browser-panel-internal.hpp index b6c53e1f8..1516f4f17 100644 --- a/panel/browser-panel-internal.hpp +++ b/panel/browser-panel-internal.hpp @@ -12,10 +12,7 @@ struct PopupWhitelistInfo { std::string url; QPointer obj; - inline PopupWhitelistInfo(const std::string &url_, QObject *obj_) - : url(url_), obj(obj_) - { - } + inline PopupWhitelistInfo(const std::string &url_, QObject *obj_) : url(url_), obj(obj_) {} }; extern std::mutex popup_whitelist_mutex; @@ -28,8 +25,7 @@ class QCefWidgetInternal : public QCefWidget { Q_OBJECT public: - QCefWidgetInternal(QWidget *parent, const std::string &url, - CefRefPtr rqc); + QCefWidgetInternal(QWidget *parent, const std::string &url, CefRefPtr rqc); ~QCefWidgetInternal(); CefRefPtr cefBrowser; diff --git a/panel/browser-panel.cpp b/panel/browser-panel.cpp index 6df9c2b06..c50ffb79b 100644 --- a/panel/browser-panel.cpp +++ b/panel/browser-panel.cpp @@ -33,8 +33,7 @@ std::mutex popup_whitelist_mutex; std::vector popup_whitelist; std::vector forced_popups; -static int zoomLvls[] = {25, 33, 50, 67, 75, 80, 90, 100, - 110, 125, 150, 175, 200, 250, 300, 400}; +static int zoomLvls[] = {25, 33, 50, 67, 75, 80, 90, 100, 110, 125, 150, 175, 200, 250, 300, 400}; /* ------------------------------------------------------------------------- */ @@ -44,8 +43,7 @@ class CookieCheck : public CefCookieVisitor { std::string target; bool cookie_found = false; - inline CookieCheck(QCefCookieManager::cookie_exists_cb callback_, - const std::string target_) + inline CookieCheck(QCefCookieManager::cookie_exists_cb callback_, const std::string target_) : callback(callback_), target(target_) { } @@ -71,8 +69,7 @@ struct QCefCookieManagerInternal : QCefCookieManager { CefRefPtr cm; CefRefPtr rc; - QCefCookieManagerInternal(const std::string &storage_path, - bool persist_session_cookies) + QCefCookieManagerInternal(const std::string &storage_path, bool persist_session_cookies) { if (os_event_try(cef_started_event) != 0) throw "Browser thread not initialized"; @@ -88,22 +85,19 @@ struct QCefCookieManagerInternal : QCefCookieManager { settings.persist_user_preferences = 1; #endif CefString(&settings.cache_path) = path.Get(); - rc = CefRequestContext::CreateContext( - settings, CefRefPtr()); + rc = CefRequestContext::CreateContext(settings, CefRefPtr()); if (rc) cm = rc->GetCookieManager(nullptr); UNUSED_PARAMETER(persist_session_cookies); } - virtual bool DeleteCookies(const std::string &url, - const std::string &name) override + virtual bool DeleteCookies(const std::string &url, const std::string &name) override { return !!cm ? cm->DeleteCookies(url, name, nullptr) : false; } - virtual bool SetStoragePath(const std::string &storage_path, - bool persist_session_cookies) override + virtual bool SetStoragePath(const std::string &storage_path, bool persist_session_cookies) override { BPtr rpath = obs_module_config_path(storage_path.c_str()); BPtr path = os_get_abs_path_ptr(rpath.Get()); @@ -113,8 +107,7 @@ struct QCefCookieManagerInternal : QCefCookieManager { settings.persist_user_preferences = 1; #endif CefString(&settings.cache_path) = storage_path; - rc = CefRequestContext::CreateContext( - settings, CefRefPtr()); + rc = CefRequestContext::CreateContext(settings, CefRefPtr()); if (rc) cm = rc->GetCookieManager(nullptr); @@ -122,13 +115,9 @@ struct QCefCookieManagerInternal : QCefCookieManager { return true; } - virtual bool FlushStore() override - { - return !!cm ? cm->FlushStore(nullptr) : false; - } + virtual bool FlushStore() override { return !!cm ? cm->FlushStore(nullptr) : false; } - virtual void CheckForCookie(const std::string &site, - const std::string &cookie, + virtual void CheckForCookie(const std::string &site, const std::string &cookie, cookie_exists_cb callback) override { if (!cm) @@ -141,8 +130,7 @@ struct QCefCookieManagerInternal : QCefCookieManager { /* ------------------------------------------------------------------------- */ -QCefWidgetInternal::QCefWidgetInternal(QWidget *parent, const std::string &url_, - CefRefPtr rqc_) +QCefWidgetInternal::QCefWidgetInternal(QWidget *parent, const std::string &url_, CefRefPtr rqc_) : QCefWidget(parent), url(url_), rqc(rqc_) { setAttribute(Qt::WA_PaintOnScreen); @@ -170,11 +158,8 @@ void QCefWidgetInternal::closeBrowser() CefRefPtr browser = cefBrowser; if (!!browser) { auto destroyBrowser = [](CefRefPtr cefBrowser) { - CefRefPtr client = - cefBrowser->GetHost()->GetClient(); - QCefBrowserClient *bc = - reinterpret_cast( - client.get()); + CefRefPtr client = cefBrowser->GetHost()->GetClient(); + QCefBrowserClient *bc = reinterpret_cast(client.get()); if (bc) { bc->widget = nullptr; @@ -215,8 +200,7 @@ void QCefWidgetInternal::closeBrowser() // felt hacky, might delete later void *view = (id)cefBrowser->GetHost()->GetWindowHandle(); if (*((bool *)view)) - ((void (*)(id, SEL))objc_msgSend)( - (id)view, sel_getUid("removeFromSuperview")); + ((void (*)(id, SEL))objc_msgSend)((id)view, sel_getUid("removeFromSuperview")); #endif destroyBrowser(browser); @@ -234,9 +218,8 @@ static bool XWindowHasAtom(Display *display, Window w, Atom a) unsigned long bytesAfter; unsigned char *data = NULL; - if (XGetWindowProperty(display, w, a, 0, LONG_MAX, False, - AnyPropertyType, &type, &format, &nItems, - &bytesAfter, &data) != Success) + if (XGetWindowProperty(display, w, a, 0, LONG_MAX, False, AnyPropertyType, &type, &format, &nItems, &bytesAfter, + &data) != Success) return false; if (data) @@ -257,8 +240,7 @@ void QCefWidgetInternal::unsetToplevelXdndProxy() if (!cefBrowser) return; - CefWindowHandle browserHandle = - cefBrowser->GetHost()->GetWindowHandle(); + CefWindowHandle browserHandle = cefBrowser->GetHost()->GetWindowHandle(); Display *xDisplay = cef_get_xdisplay(); Window toplevel, root, parent, *children; unsigned int nChildren; @@ -269,15 +251,13 @@ void QCefWidgetInternal::unsetToplevelXdndProxy() // Find the toplevel Atom netWmPidAtom = XInternAtom(xDisplay, "_NET_WM_PID", False); do { - if (XQueryTree(xDisplay, toplevel, &root, &parent, &children, - &nChildren) == 0) + if (XQueryTree(xDisplay, toplevel, &root, &parent, &children, &nChildren) == 0) return; if (children) XFree(children); - if (root == parent || - !XWindowHasAtom(xDisplay, parent, netWmPidAtom)) { + if (root == parent || !XWindowHasAtom(xDisplay, parent, netWmPidAtom)) { found = true; break; } @@ -289,8 +269,7 @@ void QCefWidgetInternal::unsetToplevelXdndProxy() // Check if the XdndProxy property is set Atom xDndProxyAtom = XInternAtom(xDisplay, "XdndProxy", False); - if (needsDeleteXdndProxy && - !XWindowHasAtom(xDisplay, toplevel, xDndProxyAtom)) { + if (needsDeleteXdndProxy && !XWindowHasAtom(xDisplay, toplevel, xDndProxyAtom)) { QueueCEFTask([this]() { unsetToplevelXdndProxy(); }); return; } @@ -330,8 +309,7 @@ void QCefWidgetInternal::Init() #if CHROME_VERSION_BUILD < 4430 #ifdef __APPLE__ - windowInfo.SetAsChild((CefWindowHandle)handle, 0, 0, - size.width(), size.height()); + windowInfo.SetAsChild((CefWindowHandle)handle, 0, 0, size.width(), size.height()); #else #ifdef _WIN32 RECT rc = {0, 0, size.width(), size.height()}; @@ -341,20 +319,16 @@ void QCefWidgetInternal::Init() windowInfo.SetAsChild((CefWindowHandle)handle, rc); #endif #else - windowInfo.SetAsChild((CefWindowHandle)handle, - CefRect(0, 0, size.width(), - size.height())); + windowInfo.SetAsChild((CefWindowHandle)handle, CefRect(0, 0, size.width(), size.height())); #endif CefRefPtr browserClient = - new QCefBrowserClient(this, script, - allowAllPopups_); + new QCefBrowserClient(this, script, allowAllPopups_); CefBrowserSettings cefBrowserSettings; - cefBrowser = CefBrowserHost::CreateBrowserSync( - windowInfo, browserClient, url, - cefBrowserSettings, - CefRefPtr(), rqc); + cefBrowser = CefBrowserHost::CreateBrowserSync(windowInfo, browserClient, url, + cefBrowserSettings, + CefRefPtr(), rqc); #ifdef __linux__ QueueCEFTask([this]() { unsetToplevelXdndProxy(); }); @@ -365,8 +339,7 @@ void QCefWidgetInternal::Init() timer.stop(); #ifndef __APPLE__ if (!container) { - container = - QWidget::createWindowContainer(window, this); + container = QWidget::createWindowContainer(window, this); container->show(); } @@ -390,18 +363,15 @@ void QCefWidgetInternal::Resize() if (!cefBrowser) return; - CefWindowHandle handle = - cefBrowser->GetHost()->GetWindowHandle(); + CefWindowHandle handle = cefBrowser->GetHost()->GetWindowHandle(); if (!handle) return; #ifdef _WIN32 - SetWindowPos((HWND)handle, nullptr, 0, 0, size.width(), - size.height(), + SetWindowPos((HWND)handle, nullptr, 0, 0, size.width(), size.height(), SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOZORDER); - SendMessage((HWND)handle, WM_SIZE, 0, - MAKELPARAM(size.width(), size.height())); + SendMessage((HWND)handle, WM_SIZE, 0, MAKELPARAM(size.width(), size.height())); #else Display *xDisplay = cef_get_xdisplay(); @@ -413,8 +383,7 @@ void QCefWidgetInternal::Resize() changes.y = 0; changes.width = size.width(); changes.height = size.height(); - XConfigureWindow(xDisplay, (Window)handle, - CWX | CWY | CWHeight | CWWidth, &changes); + XConfigureWindow(xDisplay, (Window)handle, CWX | CWY | CWHeight | CWWidth, &changes); #if CHROME_VERSION_BUILD >= 4638 XSync(xDisplay, false); #endif @@ -432,8 +401,7 @@ void QCefWidgetInternal::showEvent(QShowEvent *event) if (!cefBrowser) { obs_browser_initialize(); - connect(&timer, &QTimer::timeout, this, - &QCefWidgetInternal::Init); + connect(&timer, &QTimer::timeout, this, &QCefWidgetInternal::Init); timer.start(500); Init(); } @@ -528,21 +496,16 @@ struct QCefInternal : QCef { virtual bool initialized(void) override; virtual bool wait_for_browser_init(void) override; - virtual QCefWidget * - create_widget(QWidget *parent, const std::string &url, - QCefCookieManager *cookie_manager) override; + virtual QCefWidget *create_widget(QWidget *parent, const std::string &url, + QCefCookieManager *cookie_manager) override; - virtual QCefCookieManager * - create_cookie_manager(const std::string &storage_path, - bool persist_session_cookies) override; + virtual QCefCookieManager *create_cookie_manager(const std::string &storage_path, + bool persist_session_cookies) override; - virtual BPtr - get_cookie_path(const std::string &storage_path) override; + virtual BPtr get_cookie_path(const std::string &storage_path) override; - virtual void add_popup_whitelist_url(const std::string &url, - QObject *obj) override; - virtual void add_force_popup_url(const std::string &url, - QObject *obj) override; + virtual void add_popup_whitelist_url(const std::string &url, QObject *obj) override; + virtual void add_force_popup_url(const std::string &url, QObject *obj) override; }; bool QCefInternal::init_browser(void) @@ -564,22 +527,17 @@ bool QCefInternal::wait_for_browser_init(void) return os_event_wait(cef_started_event) == 0; } -QCefWidget *QCefInternal::create_widget(QWidget *parent, const std::string &url, - QCefCookieManager *cm) +QCefWidget *QCefInternal::create_widget(QWidget *parent, const std::string &url, QCefCookieManager *cm) { - QCefCookieManagerInternal *cmi = - reinterpret_cast(cm); + QCefCookieManagerInternal *cmi = reinterpret_cast(cm); return new QCefWidgetInternal(parent, url, cmi ? cmi->rc : nullptr); } -QCefCookieManager * -QCefInternal::create_cookie_manager(const std::string &storage_path, - bool persist_session_cookies) +QCefCookieManager *QCefInternal::create_cookie_manager(const std::string &storage_path, bool persist_session_cookies) { try { - return new QCefCookieManagerInternal(storage_path, - persist_session_cookies); + return new QCefCookieManagerInternal(storage_path, persist_session_cookies); } catch (const char *error) { blog(LOG_ERROR, "Failed to create cookie manager: %s", error); return nullptr; diff --git a/panel/browser-panel.hpp b/panel/browser-panel.hpp index dd61f3874..c75d31ce5 100644 --- a/panel/browser-panel.hpp +++ b/panel/browser-panel.hpp @@ -19,17 +19,13 @@ 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 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; + virtual void CheckForCookie(const std::string &site, const std::string &cookie, cookie_exists_cb callback) = 0; }; /* ------------------------------------------------------------------------- */ @@ -63,20 +59,16 @@ struct QCef { 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 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 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; + 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; }; static inline void *get_browser_lib() @@ -105,8 +97,7 @@ static inline QCef *obs_browser_init_panel(void) if (!lib) return nullptr; - create_qcef = - (decltype(create_qcef))os_dlsym(lib, "obs_browser_create_qcef"); + create_qcef = (decltype(create_qcef))os_dlsym(lib, "obs_browser_create_qcef"); if (!create_qcef) return nullptr; @@ -122,8 +113,7 @@ static inline int obs_browser_qcef_version(void) if (!lib) return 0; - qcef_version = (decltype(qcef_version))os_dlsym( - lib, "obs_browser_qcef_version_export"); + qcef_version = (decltype(qcef_version))os_dlsym(lib, "obs_browser_qcef_version_export"); if (!qcef_version) return 0; From b89a128eea8d27731e62b1b086b43ae4859c9ce5 Mon Sep 17 00:00:00 2001 From: Matt Gajownik Date: Thu, 10 Oct 2024 15:42:50 +1100 Subject: [PATCH 16/38] Fix blank Dev Tools window title Turns out the reason our Dev Tools windows have a blank title when not wrapped in a custom window is due to older code that performed an early return on Title Change. This moves the setting of the window title to the correct location. --- panel/browser-panel-client.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/panel/browser-panel-client.cpp b/panel/browser-panel-client.cpp index 9992ff6a6..d982e979b 100644 --- a/panel/browser-panel-client.cpp +++ b/panel/browser-panel-client.cpp @@ -76,16 +76,20 @@ void QCefBrowserClient::OnTitleChange(CefRefPtr browser, const CefSt QString qt_title = QString::fromUtf8(str_title.c_str()); QMetaObject::invokeMethod(widget, "titleChanged", Q_ARG(QString, qt_title)); } else { /* handle popup title */ - if (title.compare("DevTools") == 0) - return; + CefString newTitle = title; + if (title.compare("DevTools") == 0 && widget) + newTitle = QString(obs_module_text("DevTools")) + .arg(widget->parentWidget()->windowTitle()) + .toUtf8() + .constData(); #if defined(_WIN32) CefWindowHandle handl = browser->GetHost()->GetWindowHandle(); - std::wstring str_title = title; + std::wstring str_title = newTitle; SetWindowTextW((HWND)handl, str_title.c_str()); #elif defined(__linux__) CefWindowHandle handl = browser->GetHost()->GetWindowHandle(); - XStoreName(cef_get_xdisplay(), handl, title.ToString().c_str()); + XStoreName(cef_get_xdisplay(), handl, newTitle.ToString().c_str()); #endif } } @@ -308,12 +312,10 @@ bool QCefBrowserClient::OnContextMenuCommand(CefRefPtr browser, CefR CefRefPtr host = browser->GetHost(); CefWindowInfo windowInfo; QPoint pos; - QString title; switch (command_id) { case MENU_ITEM_DEVTOOLS: #if defined(_WIN32) && CHROME_VERSION_BUILD < 6533 - title = QString(obs_module_text("DevTools")).arg(widget->parentWidget()->windowTitle()); - windowInfo.SetAsPopup(host->GetWindowHandle(), title.toUtf8().constData()); + windowInfo.SetAsPopup(host->GetWindowHandle(), ""); #endif pos = widget->mapToGlobal(QPoint(0, 0)); windowInfo.bounds.x = pos.x(); From 4dafce8fcb4e26537fd4ebdfb8d26afbb8569609 Mon Sep 17 00:00:00 2001 From: Ryan Foster Date: Fri, 11 Oct 2024 21:44:29 -0400 Subject: [PATCH 17/38] cmake: Fix CEF minimum version Apparently, the find_package signature is incorrect. The [version] component must come before the [REQUIRED] component. I mistakenly placed them in the reverse order when originally adding the minimum version. https://cmake.org/cmake/help/v3.28/command/find_package.html#basic-signature --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0c88480c1..e8220a7f6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,7 @@ if(NOT ENABLE_BROWSER) return() endif() -find_package(CEF REQUIRED 95) +find_package(CEF 95 REQUIRED) find_package(nlohmann_json 3.11 REQUIRED) add_library(obs-browser MODULE) From f459def89ddd8b34f090a27fe65fda6264c39283 Mon Sep 17 00:00:00 2001 From: Ryan Foster Date: Fri, 11 Oct 2024 14:18:39 -0400 Subject: [PATCH 18/38] CI: Port check-changes action from obs-studio Co-authored-by: PatTheMav --- .github/actions/check-changes/action.yaml | 82 +++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 .github/actions/check-changes/action.yaml diff --git a/.github/actions/check-changes/action.yaml b/.github/actions/check-changes/action.yaml new file mode 100644 index 000000000..e5690b8a7 --- /dev/null +++ b/.github/actions/check-changes/action.yaml @@ -0,0 +1,82 @@ +name: Check For Changed Files +description: Checks for changed files compared to specific git reference and glob expression +inputs: + baseRef: + description: Git reference to check against + required: false + ref: + description: Git reference to check with + required: false + default: HEAD + checkGlob: + description: Glob expression to limit check to specific files + required: false + useFallback: + description: Use fallback compare against prior commit + required: false + default: 'true' + diffFilter: + description: git diff-filter string to use + required: false + default: '' +outputs: + hasChangedFiles: + value: ${{ steps.checks.outputs.hasChangedFiles }} + description: True if specified files were changed in comparison to specified git reference + changedFiles: + value: ${{ steps.checks.outputs.changedFiles }} + description: List of changed files +runs: + using: composite + steps: + - name: Check For Changed Files ✅ + shell: bash + id: checks + env: + GIT_BASE_REF: ${{ inputs.baseRef }} + GIT_REF: ${{ inputs.ref }} + GITHUB_EVENT_FORCED: ${{ github.event.forced }} + GITHUB_REF_BEFORE: ${{ github.event.before }} + USE_FALLBACK: ${{ inputs.useFallback }} + DIFF_FILTER: ${{ inputs.diffFilter }} + run: | + : Check for Changed Files ✅ + if [[ "${RUNNER_DEBUG}" ]]; then set -x; fi + shopt -s extglob + shopt -s dotglob + + # 4b825dc642cb6eb9a060e54bf8d69288fbee4904 is a "hidden" sha1 hash of + # the "empty tree", retrived via 'git hash-object -t tree /dev/null', + # and used here as a last-resort fallback to always provide a valid + # git ref. + + if [[ "${GIT_BASE_REF}" ]]; then + if ! git cat-file -e "${GIT_BASE_REF}" &> /dev/null; then + echo "::warning::Provided base reference ${GIT_BASE_REF} is invalid" + if [[ "${USE_FALLBACK}" == 'true' ]]; then + GIT_BASE_REF='HEAD~1' + fi + fi + else + if ! git cat-file -e ${GITHUB_REF_BEFORE} &> /dev/null; then + GITHUB_REF_BEFORE='4b825dc642cb6eb9a060e54bf8d69288fbee4904' + fi + + GIT_BASE_REF='HEAD~1' + case "${GITHUB_EVENT_NAME}" in + pull_request) GIT_BASE_REF="origin/${GITHUB_BASE_REF}" ;; + push) if [[ "${GITHUB_EVENT_FORCED}" != 'true' ]]; then GIT_BASE_REF="${GITHUB_REF_BEFORE}"; fi ;; + *) ;; + esac + fi + + changes=($(git diff --name-only --diff-filter="${DIFF_FILTER}" ${GIT_BASE_REF} ${GIT_REF} -- ${{ inputs.checkGlob }})) + + if (( ${#changes[@]} )); then + file_string="${changes[*]}" + echo "hasChangedFiles=true" >> $GITHUB_OUTPUT + echo "changedFiles=[\"${file_string// /\",\"}\"]" >> $GITHUB_OUTPUT + else + echo "hasChangedFiles=false" >> $GITHUB_OUTPUT + echo "changedFiles=[]" >> GITHUB_OUTPUT + fi From 377325758ddbd6c1ed75c8dc1080c6c7b31a70c7 Mon Sep 17 00:00:00 2001 From: Ryan Foster Date: Fri, 11 Oct 2024 14:52:31 -0400 Subject: [PATCH 19/38] build-aux: Add clang-format scripts --- build-aux/.functions/log_debug | 3 + build-aux/.functions/log_error | 3 + build-aux/.functions/log_group | 16 ++ build-aux/.functions/log_info | 7 + build-aux/.functions/log_output | 7 + build-aux/.functions/log_status | 7 + build-aux/.functions/log_warning | 7 + build-aux/.functions/set_loglevel | 17 ++ build-aux/.run-format.zsh | 271 ++++++++++++++++++++++++++++++ build-aux/run-clang-format | 1 + 10 files changed, 339 insertions(+) create mode 100644 build-aux/.functions/log_debug create mode 100644 build-aux/.functions/log_error create mode 100644 build-aux/.functions/log_group create mode 100644 build-aux/.functions/log_info create mode 100644 build-aux/.functions/log_output create mode 100644 build-aux/.functions/log_status create mode 100644 build-aux/.functions/log_warning create mode 100644 build-aux/.functions/set_loglevel create mode 100755 build-aux/.run-format.zsh create mode 120000 build-aux/run-clang-format diff --git a/build-aux/.functions/log_debug b/build-aux/.functions/log_debug new file mode 100644 index 000000000..6a477a181 --- /dev/null +++ b/build-aux/.functions/log_debug @@ -0,0 +1,3 @@ +if (( ! ${+_loglevel} )) typeset -g _loglevel=1 + +if (( _loglevel > 2 )) print -PR -e -- "${CI:+::debug::}%F{220}DEBUG: ${@}%f" diff --git a/build-aux/.functions/log_error b/build-aux/.functions/log_error new file mode 100644 index 000000000..f1c7b4364 --- /dev/null +++ b/build-aux/.functions/log_error @@ -0,0 +1,3 @@ +local icon=' ✖︎ ' + +print -u2 -PR "${CI:+::error::}%F{1} ${icon} %f ${@}" diff --git a/build-aux/.functions/log_group b/build-aux/.functions/log_group new file mode 100644 index 000000000..7b6aca978 --- /dev/null +++ b/build-aux/.functions/log_group @@ -0,0 +1,16 @@ +autoload -Uz log_info + +if (( ! ${+_log_group} )) typeset -g _log_group=0 + +if (( ${+CI} )) { + if (( _log_group )) { + print "::endgroup::" + typeset -g _log_group=0 + } + if (( # )) { + print "::group::${@}" + typeset -g _log_group=1 + } +} else { + if (( # )) log_info ${@} +} diff --git a/build-aux/.functions/log_info b/build-aux/.functions/log_info new file mode 100644 index 000000000..d437c292d --- /dev/null +++ b/build-aux/.functions/log_info @@ -0,0 +1,7 @@ +if (( ! ${+_loglevel} )) typeset -g _loglevel=1 + +if (( _loglevel > 0 )) { + local icon=' =>' + + print -PR "%F{4} ${(r:5:)icon}%f %B${@}%b" +} diff --git a/build-aux/.functions/log_output b/build-aux/.functions/log_output new file mode 100644 index 000000000..4d9b52f39 --- /dev/null +++ b/build-aux/.functions/log_output @@ -0,0 +1,7 @@ +if (( ! ${+_loglevel} )) typeset -g _loglevel=1 + +if (( _loglevel > 0 )) { + local icon='' + + print -PR " ${(r:5:)icon} ${@}" +} diff --git a/build-aux/.functions/log_status b/build-aux/.functions/log_status new file mode 100644 index 000000000..950e68187 --- /dev/null +++ b/build-aux/.functions/log_status @@ -0,0 +1,7 @@ +if (( ! ${+_loglevel} )) typeset -g _loglevel=1 + +if (( _loglevel > 0 )) { + local icon=' >' + + print -PR "%F{2} ${(r:5:)icon}%f ${@}" +} diff --git a/build-aux/.functions/log_warning b/build-aux/.functions/log_warning new file mode 100644 index 000000000..ceff982a9 --- /dev/null +++ b/build-aux/.functions/log_warning @@ -0,0 +1,7 @@ +if (( ! ${+_loglevel} )) typeset -g _loglevel=1 + +if (( _loglevel > 0 )) { + local icon=' =>' + + print -PR "${CI:+::warning::}%F{3} ${(r:5:)icon} ${@}%f" +} diff --git a/build-aux/.functions/set_loglevel b/build-aux/.functions/set_loglevel new file mode 100644 index 000000000..e32f4bb35 --- /dev/null +++ b/build-aux/.functions/set_loglevel @@ -0,0 +1,17 @@ +autoload -Uz log_debug log_error + +local -r _usage="Usage: %B${0}%b + +Set log level, following levels are supported: 0 (quiet), 1 (normal), 2 (verbose), 3 (debug)" + +if (( ! # )); then + log_error 'Called without arguments.' + log_output ${_usage} + return 2 +elif (( ${1} >= 4 )); then + log_error 'Called with loglevel > 3.' + log_output ${_usage} +fi + +typeset -g -i -r _loglevel=${1} +log_debug "Log level set to '${1}'" diff --git a/build-aux/.run-format.zsh b/build-aux/.run-format.zsh new file mode 100755 index 000000000..26c92f8f1 --- /dev/null +++ b/build-aux/.run-format.zsh @@ -0,0 +1,271 @@ +#!/usr/bin/env zsh + +builtin emulate -L zsh +setopt EXTENDED_GLOB +setopt PUSHD_SILENT +setopt ERR_EXIT +setopt ERR_RETURN +setopt NO_UNSET +setopt PIPE_FAIL +setopt NO_AUTO_PUSHD +setopt NO_PUSHD_IGNORE_DUPS +setopt FUNCTION_ARGZERO + +## Enable for script debugging +# setopt WARN_CREATE_GLOBAL +# setopt WARN_NESTED_VAR +# setopt XTRACE + +autoload -Uz is-at-least && if ! is-at-least 5.2; then + print -u2 -PR "%F{1}${funcstack[1]##*/}:%f Running on Zsh version %B${ZSH_VERSION}%b, but Zsh %B5.2%b is the minimum supported version. Upgrade zsh to fix this issue." + exit 1 +fi + +invoke_formatter() { + if (( # < 1 )) { + log_error "Usage invoke_formatter [formatter_name]" + exit 2 + } + + local formatter="${1}" + shift + local -a source_files=(${@}) + + case ${formatter} { + clang) + if (( ${+commands[clang-format-17]} )) { + local formatter=clang-format-17 + } elif (( ${+commands[clang-format]} )) { + local formatter=clang-format + } else { + log_error "No viable clang-format version found (required 17.0.3)" + exit 2 + } + + local -a formatter_version=($(${formatter} --version)) + + if ! is-at-least 17.0.3 ${formatter_version[-1]}; then + log_error "clang-format is not version 17.0.3 or above (found ${formatter_version[-1]}." + exit 2 + fi + + if ! is-at-least ${formatter_version[-1]} 17.0.3; then + log_error "clang-format is more recent than version 17.0.3 (found ${formatter_version[-1]})." + exit 2 + fi + + if (( ! #source_files )) source_files=((libobs|libobs-*|UI|plugins|deps|shared)/**/*.(c|cpp|h|hpp|m|mm)(.N)) + + source_files=(${source_files:#*/(obs-websocket/deps|decklink/*/decklink-sdk|mac-syphon/syphon-framework|libdshowcapture)/*}) + + local -a format_args=(-style=file -fallback-style=none) + if (( _loglevel > 2 )) format_args+=(--verbose) + + check_files() { + local -i num_failures=0 + local -a source_files=($@) + local file + local -a format_args=(-style=file -fallback-style=none) + if (( _loglevel > 2 )) format_args+=(--verbose) + + local -a command=(${formatter} ${format_args}) + + for file (${source_files}) { + if ! ${command} "${file}" | diff -q "${file}" - &> /dev/null; then + log_error "${file} requires formatting changes." + if (( fail_on_error == 2 )) return 2; + num_failures=$(( num_failures + 1 )) + fi + } + if (( num_failures && fail_on_error == 1 )) return 2 + } + + format_files() { + local -a source_files=($@) + + if (( ${#source_files} )) { + local -a format_args=(-style=file -fallback-style=none -i) + if (( _loglevel > 2 )) format_args+=(--verbose) + + "${formatter}" ${format_args} ${source_files} + } + } + ;; + gersemi) + local formatter=gersemi + if (( ${+commands[gersemi]} )) { + local gersemi_version=($(gersemi --version)) + + if ! is-at-least 0.12.0 ${gersemi_version[2]}; then + log_error "gersemi is not version 0.12.0 or above (found ${gersemi_version[2]}." + exit 2 + fi + } + + if (( ! #source_files )) source_files=(CMakeLists.txt (libobs|libobs-*|UI|plugins|deps|shared|cmake|test)/**/(CMakeLists.txt|*.cmake)(.N)) + + source_files=(${source_files:#*/(jansson|decklink/*/decklink-sdk|obs-websocket|obs-browser|libdshowcapture)/*}) + source_files=(${source_files:#(cmake/Modules/*|*/legacy.cmake)}) + + check_files() { + local -i num_failures=0 + local -a source_files=($@) + local file + local -a command=(${formatter} -c --no-cache ${source_files}) + + if (( ${#source_files} )) { + while read -r line; do + local -a line_tokens=(${(z)line}) + file=${line_tokens[1]//*obs-studio\//} + + log_error "${file} requires formatting changes." + + if (( fail_on_error == 2 )) return 2 + num_failures=$(( num_failures + 1 )) + done < <(${command} 2>&1) + + if (( num_failures && fail_on_error == 1 )) return 2 + } + } + + format_files() { + local -a source_files=($@) + + if (( ${#source_files} )) { + "${formatter}" -i ${source_files} + } + } + ;; + swift) + local formatter=swift-format + if (( ${+commands[swift-format]} )) { + local swift_format_version=$(swift-format --version) + + if ! is-at-least 508.0.0 ${swift_format_version}; then + log_error "swift-format is not version 508.0.0 or above (found ${swift_format_version})." + exit 2 + fi + } else { + log_error "No viable swift-format version found (required 508.0.0)" + exit 2 + } + + if (( ! #source_files )) source_files=((libobs|libobs-*|UI|plugins)/**/*.swift(.N)) + + check_files() { + local -i num_failures=0 + local -a source_files=($@) + local file + local -a format_args=() + + local -a command=(${formatter} ${format_args}) + + for file (${source_files}) { + if ! "${command}" "${file}" | diff -q "${file}" - &> /dev/null; then + log_error "${file} requires formatting changes." + if (( fail_on_error == 2 )) return 2; + num_failures=$(( num_failures + 1 )) + fi + } + if (( num_failures && fail_on_error == 1 )) return 2 + } + + format_files() { + local -a source_files=($@) + + if (( ${#source_files} )) { + local -a format_args=(-i) + + "${formatter}" ${format_args} ${source_files} + } + } + ;; + *) log_error "Invalid formatter specified: ${1}. Valid options are clang-format, gersemi, and swift-format."; exit 2 ;; + } + + local file + local -i num_failures=0 + if (( check_only )) { + if (( ${+functions[check_files]} )) { + check_files ${source_files} + } else { + log_error "No format check function defined for formatter '${formatter}'" + exit 2 + } + } else { + if (( ${+functions[format_files]} )) { + format_files ${source_files} + } else { + log_error "No format function defined for formatter '${formatter}'" + exit 2 + } + } +} + +run_format() { + if (( ! ${+SCRIPT_HOME} )) typeset -g SCRIPT_HOME=${ZSH_ARGZERO:A:h} + if (( ! ${+FORMATTER_NAME} )) typeset -g FORMATTER_NAME=${${(s:-:)ZSH_ARGZERO:t:r}[2]} + + typeset -g host_os=${${(L)$(uname -s)}//darwin/macos} + local -i fail_on_error=0 + local -i check_only=0 + local -i verbosity=1 + local -r _version='1.0.0' + + fpath=("${SCRIPT_HOME}/.functions" ${fpath}) + autoload -Uz set_loglevel log_info log_error log_output log_status log_warning + + local -r _usage=" +Usage: %B${functrace[1]%:*}%b