|
9 | 9 | #include "StdInc.h" |
10 | 10 | #include "CWebApp.h" |
11 | 11 |
|
12 | | -#include <cef3/cef/include/wrapper/cef_stream_resource_handler.h> |
| 12 | +#include <cef3/cef/include/cef_command_line.h> |
13 | 13 | #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> |
14 | 18 | #include "CAjaxResourceHandler.h" |
15 | 19 |
|
| 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 | + |
16 | 75 | [[nodiscard]] CefRefPtr<CefResourceHandler> CWebApp::HandleError(const SString& strError, unsigned int uiError) |
17 | 76 | { |
18 | 77 | auto stream = CefStreamReader::CreateForData( |
|
26 | 85 |
|
27 | 86 | void CWebApp::OnBeforeCommandLineProcessing(const CefString& process_type, CefRefPtr<CefCommandLine> command_line) |
28 | 87 | { |
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 | +} |
62 | 90 |
|
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) |
65 | 94 | return; |
66 | 95 |
|
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 | +} |
77 | 99 |
|
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; |
83 | 103 | } |
84 | 104 |
|
85 | 105 | CefRefPtr<CefResourceHandler> CWebApp::Create(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, const CefString& scheme_name, |
|
0 commit comments