From aa8953c166106341ae5bc711d455c67060a60073 Mon Sep 17 00:00:00 2001 From: Matt Gajownik Date: Thu, 10 Oct 2024 15:09:11 +1100 Subject: [PATCH] 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;