Skip to content

Commit

Permalink
REALLY don't allow browser docks to arbitrarily close OBS
Browse files Browse the repository at this point in the history
The previous solution only worked for code that ran *after* the page had
*finished* loading.
  • Loading branch information
WizardCM authored and RytoEX committed Jan 22, 2024
1 parent e873fb0 commit 7fa3822
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
19 changes: 13 additions & 6 deletions panel/browser-panel-client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 395,19 @@ bool QCefBrowserClient::OnContextMenuCommand(
return false;
}

void QCefBrowserClient::OnLoadStart(CefRefPtr<CefBrowser>,
CefRefPtr<CefFrame> 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<CefBrowser>,
CefRefPtr<CefFrame> frame, int)
{
Expand All @@ -405,12 418,6 @@ void QCefBrowserClient::OnLoadEnd(CefRefPtr<CefBrowser>,
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<CefBrowser>, const CefString &,
Expand Down
4 changes: 4 additions & 0 deletions panel/browser-panel-client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 95,10 @@ class QCefBrowserClient : public CefClient,
CefContextMenuHandler::EventFlags event_flags) override;

/* CefLoadHandler */
virtual void OnLoadStart(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
TransitionType transition_type) override;

virtual void OnLoadEnd(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
int httpStatusCode) override;
Expand Down

0 comments on commit 7fa3822

Please sign in to comment.