Skip to content

Commit 0f49768

Browse files
committed
Addendum to b66d52c (Fixes crash)
1 parent 37bc86b commit 0f49768

File tree

2 files changed

+76
-40
lines changed

2 files changed

+76
-40
lines changed

Client/cefweb/CWebApp.cpp

Lines changed: 71 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,69 @@
99
#include "StdInc.h"
1010
#include "CWebApp.h"
1111

12-
#include <cef3/cef/include/wrapper/cef_stream_resource_handler.h>
12+
#include <cef3/cef/include/cef_command_line.h>
1313
#include <cef3/cef/include/cef_parser.h>
14+
#include <cef3/cef/include/cef_resource_handler.h>
15+
#include <cef3/cef/include/cef_response.h>
16+
#include <cef3/cef/include/cef_stream.h>
17+
#include <cef3/cef/include/wrapper/cef_stream_resource_handler.h>
1418
#include "CAjaxResourceHandler.h"
1519

20+
namespace
21+
{
22+
// Centralises command-line switch setup so both pre-launch callbacks stay in sync
23+
void ConfigureCommandLineSwitches(const CefRefPtr<CefCommandLine>& commandLine, const CefString& processType)
24+
{
25+
if (!commandLine)
26+
return;
27+
28+
// CEF occasionally forwards dangling pointers when destroying
29+
if (!IsReadablePointer(commandLine.get(), sizeof(void*)))
30+
return;
31+
32+
// Always provide base installation paths so loader-proxy can validate subprocess origin
33+
const SString gtaPath = GetCommonRegistryValue("", "GTA:SA Path");
34+
if (!gtaPath.empty())
35+
{
36+
commandLine->AppendSwitchWithValue("mta-gta-path", gtaPath);
37+
}
38+
39+
const SString mtaPath = GetMTAProcessBaseDir();
40+
if (!mtaPath.empty())
41+
{
42+
commandLine->AppendSwitchWithValue("mta-base-path", mtaPath);
43+
}
44+
45+
// Prevent Chromium from dropping privileges; required for elevated launches (see chromium/3960)
46+
commandLine->AppendSwitch("do-not-de-elevate");
47+
48+
if (!g_pCore || !IsReadablePointer(g_pCore, sizeof(void*))) [[unlikely]]
49+
return;
50+
51+
const auto webCore = static_cast<CWebCore*>(g_pCore->GetWebCore());
52+
if (!webCore || !IsReadablePointer(webCore, sizeof(void*)))
53+
return;
54+
55+
// Honour the GPU toggle exposed through settings and hard-disable compositor for stability
56+
if (!webCore->GetGPUEnabled())
57+
{
58+
commandLine->AppendSwitch("disable-gpu");
59+
}
60+
61+
commandLine->AppendSwitch("disable-gpu-compositing");
62+
commandLine->AppendSwitch("enable-begin-frame-scheduling");
63+
// Explicitly block account sign-in to avoid crashes when Google API keys are registered on the system
64+
commandLine->AppendSwitchWithValue("allow-browser-signin", "false");
65+
66+
if (processType.empty())
67+
{
68+
// Browser process only: unlock autoplay and legacy Blink features for resource compatibility
69+
commandLine->AppendSwitchWithValue("autoplay-policy", "no-user-gesture-required");
70+
commandLine->AppendSwitchWithValue("enable-blink-features", "ShadowDOMV0,CustomElementsV0,HTMLImports");
71+
}
72+
}
73+
} // namespace
74+
1675
[[nodiscard]] CefRefPtr<CefResourceHandler> CWebApp::HandleError(const SString& strError, unsigned int uiError)
1776
{
1877
auto stream = CefStreamReader::CreateForData(
@@ -25,6 +84,11 @@
2584
}
2685

2786
void CWebApp::OnBeforeCommandLineProcessing(const CefString& process_type, CefRefPtr<CefCommandLine> command_line)
87+
{
88+
ConfigureCommandLineSwitches(command_line, process_type);
89+
}
90+
91+
void CWebApp::OnBeforeChildProcessLaunch(CefRefPtr<CefCommandLine> command_line)
2892
{
2993
if (!command_line)
3094
return;
@@ -42,45 +106,13 @@ void CWebApp::OnBeforeCommandLineProcessing(const CefString& process_type, CefRe
42106
command_line->AppendSwitchWithValue("mta-gta-path", strGTAPath);
43107
// AddReportLog only available in browser process where g_pCore exists
44108
}
109+
const CefString processType = command_line->GetSwitchValue("type");
110+
ConfigureCommandLineSwitches(command_line, processType);
111+
}
45112

46-
// Pass MTA base directory path to subprocess
47-
// MTA DLLs are in Bin/MTA but parent process may be elsewhere
48-
const SString strMTAPath = GetMTAProcessBaseDir();
49-
if (!strMTAPath.empty())
50-
{
51-
command_line->AppendSwitchWithValue("mta-base-path", strMTAPath);
52-
}
53-
54-
// Disable AutoDeElevate to allow CEF to run with elevated privileges
55-
// Must be added before g_pCore check to apply to both browser process and subprocess
56-
// https://github.com/chromiumembedded/cef/issues/3960
57-
// https://chromium-review.googlesource.com/c/chromium/src/+/6515318
58-
command_line->AppendSwitch("do-not-de-elevate");
59-
60-
// Browser-process-only settings
61-
if (!g_pCore) [[unlikely]]
62-
return;
63-
64-
const auto pWebCore = static_cast<CWebCore*>(g_pCore->GetWebCore());
65-
if (!pWebCore)
66-
return;
67-
68-
if (!pWebCore->GetGPUEnabled())
69-
command_line->AppendSwitch("disable-gpu");
70-
71-
command_line->AppendSwitch("disable-gpu-compositing"); // always disable this, causes issues with official builds
72-
73-
// command_line->AppendSwitch("disable-d3d11");
74-
command_line->AppendSwitch("enable-begin-frame-scheduling");
75-
76-
// browser-signin switch(or lack thereof) produces crashes when GOOGLE API keys are present in the OS registry
77-
command_line->AppendSwitchWithValue("allow-browser-signin", "false");
78-
79-
if (process_type.empty())
80-
{
81-
command_line->AppendSwitchWithValue("autoplay-policy", "no-user-gesture-required");
82-
command_line->AppendSwitchWithValue("enable-blink-features", "ShadowDOMV0,CustomElementsV0,HTMLImports");
83-
}
113+
CefRefPtr<CefBrowserProcessHandler> CWebApp::GetBrowserProcessHandler()
114+
{
115+
return this;
84116
}
85117

86118
CefRefPtr<CefResourceHandler> CWebApp::Create(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, const CefString& scheme_name,

Client/cefweb/CWebApp.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,18 @@
99
#pragma once
1010
#include <cef3/cef/include/cef_app.h>
1111
#include <cef3/cef/include/cef_scheme.h>
12+
#include <cef3/cef/include/cef_browser_process_handler.h>
1213

13-
class CWebApp : public CefApp, public CefSchemeHandlerFactory
14+
class CWebApp : public CefApp, public CefSchemeHandlerFactory, public CefBrowserProcessHandler
1415
{
1516
public:
1617
// Error Handler
1718
static CefRefPtr<CefResourceHandler> HandleError(const SString& strError, unsigned int uiError);
1819

1920
virtual void OnBeforeCommandLineProcessing(const CefString& process_type, CefRefPtr<CefCommandLine> command_line) override;
21+
virtual void OnBeforeChildProcessLaunch(CefRefPtr<CefCommandLine> command_line) override;
22+
23+
virtual CefRefPtr<CefBrowserProcessHandler> GetBrowserProcessHandler() override;
2024

2125
// CefSchemeHandlerFactory methods
2226
virtual CefRefPtr<CefResourceHandler> Create(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, const CefString& scheme_name,

0 commit comments

Comments
 (0)