Skip to content

Commit 1e35a6a

Browse files
committed
1.6: Addendum to 05ae2ac (Fixes crash)
1 parent db68577 commit 1e35a6a

File tree

2 files changed

+76
-52
lines changed

2 files changed

+76
-52
lines changed

Client/cefweb/CWebApp.cpp

Lines changed: 71 additions & 51 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(
@@ -26,60 +85,21 @@
2685

2786
void CWebApp::OnBeforeCommandLineProcessing(const CefString& process_type, CefRefPtr<CefCommandLine> command_line)
2887
{
29-
if (!command_line)
30-
return;
31-
32-
// Add GTA path and MTA base path switches before g_pCore check
33-
// This callback runs in both browser process and subprocess
34-
// In subprocess, g_pCore is NULL, so switches must be added before that check
35-
// Read GTA path from registry
36-
const SString strGTAPath = GetCommonRegistryValue("", "GTA:SA Path");
37-
if (!strGTAPath.empty())
38-
{
39-
// Pass GTA directory path to CEFLauncher subprocess via command-line switch
40-
// CEF's AppendSwitchWithValue handles quoting automatically
41-
command_line->AppendSwitchWithValue("mta-gta-path", strGTAPath);
42-
// AddReportLog only available in browser process where g_pCore exists
43-
}
44-
45-
// Pass MTA base directory path to subprocess
46-
// MTA DLLs are in Bin/MTA but parent process may be elsewhere
47-
const SString strMTAPath = GetMTAProcessBaseDir();
48-
if (!strMTAPath.empty())
49-
{
50-
command_line->AppendSwitchWithValue("mta-base-path", strMTAPath);
51-
}
52-
53-
// Disable AutoDeElevate to allow CEF to run with elevated privileges
54-
// Must be added before g_pCore check to apply to both browser process and subprocess
55-
// https://github.com/chromiumembedded/cef/issues/3960
56-
// https://chromium-review.googlesource.com/c/chromium/src/+/6515318
57-
command_line->AppendSwitch("do-not-de-elevate");
58-
59-
// Browser-process-only settings
60-
if (!g_pCore) [[unlikely]]
61-
return;
88+
ConfigureCommandLineSwitches(command_line, process_type);
89+
}
6290

63-
const auto pWebCore = static_cast<CWebCore*>(g_pCore->GetWebCore());
64-
if (!pWebCore)
91+
void CWebApp::OnBeforeChildProcessLaunch(CefRefPtr<CefCommandLine> command_line)
92+
{
93+
if (!command_line)
6594
return;
6695

67-
if (!pWebCore->GetGPUEnabled())
68-
command_line->AppendSwitch("disable-gpu");
69-
70-
command_line->AppendSwitch("disable-gpu-compositing"); // always disable this, causes issues with official builds
71-
72-
// command_line->AppendSwitch("disable-d3d11");
73-
command_line->AppendSwitch("enable-begin-frame-scheduling");
74-
75-
// browser-signin switch(or lack thereof) produces crashes when GOOGLE API keys are present in the OS registry
76-
command_line->AppendSwitchWithValue("allow-browser-signin", "false");
96+
const CefString processType = command_line->GetSwitchValue("type");
97+
ConfigureCommandLineSwitches(command_line, processType);
98+
}
7799

78-
if (process_type.empty())
79-
{
80-
command_line->AppendSwitchWithValue("autoplay-policy", "no-user-gesture-required");
81-
command_line->AppendSwitchWithValue("enable-blink-features", "ShadowDOMV0,CustomElementsV0,HTMLImports");
82-
}
100+
CefRefPtr<CefBrowserProcessHandler> CWebApp::GetBrowserProcessHandler()
101+
{
102+
return this;
83103
}
84104

85105
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)