From bca96d645de00a25a66e98a8a5d51fa9fc291f6d Mon Sep 17 00:00:00 2001 From: Matt Gajownik Date: Tue, 26 Dec 2023 18:34:55 +1100 Subject: [PATCH] REALLY don't allow browser docks to arbitrarily close OBS The previous solution only worked for code that ran *after* the page had *finished* loading. --- panel/browser-panel-client.cpp | 19 +++++++++++++------ panel/browser-panel-client.hpp | 4 ++++ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/panel/browser-panel-client.cpp b/panel/browser-panel-client.cpp index f5d5a3040..202e15f52 100644 --- a/panel/browser-panel-client.cpp +++ b/panel/browser-panel-client.cpp @@ -395,6 +395,19 @@ bool QCefBrowserClient::OnContextMenuCommand( return false; } +void QCefBrowserClient::OnLoadStart(CefRefPtr, + CefRefPtr frame, TransitionType) +{ + if (!frame->IsMain()) + return; + + std::string script = "window.close = () => "; + script += "console.log("; + script += "'OBS browser docks cannot be closed using JavaScript.'"; + script += ");"; + frame->ExecuteJavaScript(script, "", 0); +} + void QCefBrowserClient::OnLoadEnd(CefRefPtr, CefRefPtr frame, int) { @@ -405,12 +418,6 @@ void QCefBrowserClient::OnLoadEnd(CefRefPtr, frame->ExecuteJavaScript(widget->script, CefString(), 0); else if (!script.empty()) frame->ExecuteJavaScript(script, CefString(), 0); - - std::string script2 = "window.close = () => "; - script2 += "console.log("; - script2 += "'OBS browser docks cannot be closed using JavaScript.'"; - script2 += ");"; - frame->ExecuteJavaScript(script2, "", 0); } bool QCefBrowserClient::OnJSDialog(CefRefPtr, const CefString &, diff --git a/panel/browser-panel-client.hpp b/panel/browser-panel-client.hpp index 941b9e632..c099fd6d1 100644 --- a/panel/browser-panel-client.hpp +++ b/panel/browser-panel-client.hpp @@ -95,6 +95,10 @@ class QCefBrowserClient : public CefClient, CefContextMenuHandler::EventFlags event_flags) override; /* CefLoadHandler */ + virtual void OnLoadStart(CefRefPtr browser, + CefRefPtr frame, + TransitionType transition_type) override; + virtual void OnLoadEnd(CefRefPtr browser, CefRefPtr frame, int httpStatusCode) override;