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 (
2584}
2685
2786void 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
86118CefRefPtr<CefResourceHandler> CWebApp::Create (CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, const CefString& scheme_name,
0 commit comments