Skip to content

Commit

Permalink
- Update to CEF 124.3.0+g77c1e82+chromium-124.0.6367.60
Browse files Browse the repository at this point in the history
- Implement OnAlreadyRunningAppRelaunch and Fix -multirun support
- Fix rotate log errors
  • Loading branch information
WinterPhoenix committed Apr 30, 2024
1 parent de980b8 commit 92ebc22
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 57 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ project(gmod_html)

set_property(GLOBAL PROPERTY OS_FOLDERS ON)

set(CEF_VERSION "120.2.7+g4bc6a59+chromium-120.0.6099.234")
set(CEF_VERSION "124.3.0+g77c1e82+chromium-124.0.6367.60")

if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
if("${PROJECT_ARCH}" STREQUAL "arm64")
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Everything you need is in the **Standard Distribution**. If you need to debug th
## Currently supported CEF version
The current version of CEF that's supported by this library is:

- **120.2.7+g4bc6a59+chromium-120.0.6099.234**
- **124.3.0+g77c1e82+chromium-124.0.6367.60**

This is not the only version that could be supported, but it's the version that's currently configured and tested to work.

Expand Down
20 changes: 15 additions & 5 deletions chromium_process/ChromiumApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ void ChromiumApp::OnBeforeCommandLineProcessing( const CefString& process_type,
command_line->AppendSwitch( "disable-smooth-scrolling" );
#ifdef _WIN32
command_line->AppendSwitch( "enable-begin-frame-scheduling" );
// TODO: WINE/Proton support?

// TODO: WINE/Proton/Flatpak support?
//command_line->AppendSwitch( "no-sandbox" );
#endif
command_line->AppendSwitch( "enable-system-flash" );
Expand Down Expand Up @@ -214,6 +215,15 @@ CefRefPtr<CefRenderProcessHandler> ChromiumApp::GetRenderProcessHandler()
return this;
}

//
// CefBrowserProcessHandler interface
//
bool ChromiumApp::OnAlreadyRunningAppRelaunch( CefRefPtr<CefCommandLine> command_line, const CefString &current_directory )
{
// See ChromiumSystem::Init, we detect lockfile and handle things there
return true;
}

//
// CefRenderProcessHandler interface
//
Expand All @@ -226,7 +236,7 @@ void ChromiumApp::OnContextCreated( CefRefPtr<CefBrowser> browser, CefRefPtr<Cef
{
context->GetGlobal()->DeleteValue( "print" );

// Removing WebSQL for now - we can add it back after CEF3 has been updated
// TODO: Removing WebSQL for now - we can add it back after CEF3 has been updated
context->GetGlobal()->DeleteValue( "openDatabase" );

}
Expand All @@ -244,7 +254,7 @@ void ChromiumApp::OnContextCreated( CefRefPtr<CefBrowser> browser, CefRefPtr<Cef

void ChromiumApp::OnContextReleased( CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefV8Context> context )
{

// Do nothing
}

bool ChromiumApp::OnProcessMessageReceived( CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefProcessId source_process, CefRefPtr<CefProcessMessage> message )
Expand Down Expand Up @@ -445,12 +455,12 @@ void ChromiumApp::RegisterFunction( CefRefPtr<CefBrowser> browser, CefRefPtr<Cef

// Register this function in any frames that already exist
{
std::vector<int64_t> frames;
std::vector<CefString> frames;
browser->GetFrameIdentifiers( frames );

for ( auto frameId : frames )
{
RegisterFunctionInFrame( browser->GetFrame( frameId ), objName, funcName );
RegisterFunctionInFrame( browser->GetFrameByIdentifier( frameId ), objName, funcName );
}
}

Expand Down
74 changes: 40 additions & 34 deletions chromium_process/ChromiumApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,53 +4,59 @@
#include <unordered_map>

class ChromiumApp
: public CefApp
, public CefRenderProcessHandler
, public CefV8Handler
: public CefApp
, public CefBrowserProcessHandler
, public CefRenderProcessHandler
, public CefV8Handler
{
public:
//
// CefApp interface
//
void OnBeforeCommandLineProcessing( const CefString& process_type, CefRefPtr<CefCommandLine> command_line ) override;
void OnRegisterCustomSchemes( CefRawPtr<CefSchemeRegistrar> registrar ) override;
CefRefPtr<CefRenderProcessHandler> GetRenderProcessHandler() override;

//
// CefRenderProcessHandler interface
//
void OnContextCreated( CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefV8Context> context ) override;
void OnContextReleased( CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefV8Context> context ) override;
//
// CefApp interface
//
void OnBeforeCommandLineProcessing( const CefString& process_type, CefRefPtr<CefCommandLine> command_line ) override;
void OnRegisterCustomSchemes( CefRawPtr<CefSchemeRegistrar> registrar ) override;
CefRefPtr<CefRenderProcessHandler> GetRenderProcessHandler() override;

//
// CefBrowserProcessHandler interface
//
bool OnAlreadyRunningAppRelaunch( CefRefPtr<CefCommandLine> command_line, const CefString &current_directory ) override;

//
// CefRenderProcessHandler interface
//
void OnContextCreated( CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefV8Context> context ) override;
void OnContextReleased( CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefV8Context> context ) override;
bool OnProcessMessageReceived( CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefProcessId source_process, CefRefPtr<CefProcessMessage> message ) override;

//
// CefV8Handler interface
//
bool Execute( const CefString& name, CefRefPtr<CefV8Value> object, const CefV8ValueList& arguments, CefRefPtr<CefV8Value>& retval, CefString& exception ) override;
//
// CefV8Handler interface
//
bool Execute( const CefString& name, CefRefPtr<CefV8Value> object, const CefV8ValueList& arguments, CefRefPtr<CefV8Value>& retval, CefString& exception ) override;

private:
int CreateCallback( CefRefPtr<CefV8Context> context, CefRefPtr<CefV8Value> func );
void RegisterFunctionInFrame( CefRefPtr<CefFrame> frame, const CefString& objName, const CefString& funcName );
int CreateCallback( CefRefPtr<CefV8Context> context, CefRefPtr<CefV8Value> func );
void RegisterFunctionInFrame( CefRefPtr<CefFrame> frame, const CefString& objName, const CefString& funcName );

// Messages from the game process
// Messages from the game process
void ExecuteJavaScript( CefRefPtr<CefBrowser> browser, CefRefPtr<CefListValue> args );
void RegisterFunction( CefRefPtr<CefBrowser> browser, CefRefPtr<CefListValue> args );
void ExecuteCallback( CefRefPtr<CefBrowser> browser, CefRefPtr<CefListValue> args );
void ForgetCallback( CefRefPtr<CefBrowser> browser, CefRefPtr<CefListValue> args );
void RegisterFunction( CefRefPtr<CefBrowser> browser, CefRefPtr<CefListValue> args );
void ExecuteCallback( CefRefPtr<CefBrowser> browser, CefRefPtr<CefListValue> args );
void ForgetCallback( CefRefPtr<CefBrowser> browser, CefRefPtr<CefListValue> args );

private:
std::vector<std::pair<CefString, CefString>> m_RegisteredFunctions;
std::vector<std::pair<CefString, CefString>> m_RegisteredFunctions;

struct Callback
{
CefRefPtr<CefV8Context> Context;
CefRefPtr<CefV8Value> Function;
};
struct Callback
{
CefRefPtr<CefV8Context> Context;
CefRefPtr<CefV8Value> Function;
};

std::unordered_map<int, Callback> m_Callbacks;
int m_NextCallbackId = 0;
std::unordered_map<int, Callback> m_Callbacks;
int m_NextCallbackId = 0;

private:
IMPLEMENT_REFCOUNTING( ChromiumApp );
IMPLEMENT_REFCOUNTING( ChromiumApp );

};
2 changes: 1 addition & 1 deletion html_chromium/ChromiumBrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,7 @@ void ChromiumBrowser::OnPaint( CefRefPtr<CefBrowser>, CefRenderHandler::PaintEle
}
}

void ChromiumBrowser::OnAcceleratedPaint(CefRefPtr<CefBrowser> browser, CefRenderHandler::PaintElementType type, const CefRenderHandler::RectList& dirtyRects, void* shared_handle)
void ChromiumBrowser::OnAcceleratedPaint(CefRefPtr<CefBrowser> browser, CefRenderHandler::PaintElementType type, const CefRenderHandler::RectList& dirtyRects, const CefAcceleratedPaintInfo& info)
{
// TODO: Implement once fixed for OSR on Viz
// TODO: See ChromiumSystem::CreateClient
Expand Down
2 changes: 1 addition & 1 deletion html_chromium/ChromiumBrowser.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class ChromiumBrowser
void OnPopupShow( CefRefPtr<CefBrowser>, bool show ) override;
void OnPopupSize( CefRefPtr<CefBrowser>, const CefRect& rect ) override;
void OnPaint( CefRefPtr<CefBrowser>, CefRenderHandler::PaintElementType type, const CefRenderHandler::RectList& dirtyRects, const void* buffer, int width, int height ) override;
void OnAcceleratedPaint( CefRefPtr<CefBrowser> browser, CefRenderHandler::PaintElementType type, const CefRenderHandler::RectList& dirtyRects, void* shared_handle ) override;
void OnAcceleratedPaint( CefRefPtr<CefBrowser> browser, CefRenderHandler::PaintElementType type, const CefRenderHandler::RectList& dirtyRects, const CefAcceleratedPaintInfo& info) override;

//
// CefRequestHandler interface
Expand Down
70 changes: 56 additions & 14 deletions html_chromium/ChromiumSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ChromiumApp
command_line->AppendSwitch( "disable-smooth-scrolling" );
#ifdef _WIN32
command_line->AppendSwitch( "enable-begin-frame-scheduling" );
// TODO: WINE/Proton support?
// TODO: WINE/Proton/Flatpak support?
//command_line->AppendSwitch( "no-sandbox" );
#endif
command_line->AppendSwitch( "enable-system-flash" );
Expand Down Expand Up @@ -77,7 +77,7 @@ class ChromiumApp
typedef void* ( *CreateCefSandboxInfoFn )( );
typedef void ( *DestroyCefSandboxInfoFn )( void* );

// Needs cleaning up. There's too much Windows shit.
// TODO: Needs cleaning up. There's too much Windows shit.
bool ChromiumSystem::Init( const char* pBaseDir, IHtmlResourceHandler* pResourceHandler )
{
g_pHtmlResourceHandler = pResourceHandler;
Expand Down Expand Up @@ -205,26 +205,50 @@ bool ChromiumSystem::Init( const char* pBaseDir, IHtmlResourceHandler* pResource
std::string curLogPath = strBaseDir + "/chromium.log";
std::string lastLogPath = strBaseDir + "/chromium.log.1";

fs::copy_file(curLogPath, lastLogPath, fs::copy_options::overwrite_existing, rotateError);
std::string cefCachePath = strBaseDir + "/ChromiumCache";
std::string cefLockFilePath = cefCachePath + "/lockfile";

if (rotateError) {
pResourceHandler->Message("Couldn't rotate chromium.log (copy): " + rotateError.message() + "\n");
rotateError.clear();
}
// TODO(winter): What if GMod/CEF crashes? Will the lockfile still be there?
if (fs::exists(cefLockFilePath)) {
pResourceHandler->Message("Skipping Chromium log rotation (lockfile exists)...\n");

// TODO(winter): See also ChromiumSystem::Shutdown; we should be clearing these multirun caches instead of keeping them around/reusing them (they can be >500MB EACH)
unsigned int multirunInstanceID = 0;
//while (fs::exists(cefCachePath)) {
while (fs::exists(cefCachePath) && fs::exists(cefLockFilePath)) {
multirunInstanceID++;
cefCachePath = strBaseDir + "/ChromiumCacheMultirun/" + std::to_string(multirunInstanceID);
cefLockFilePath = cefCachePath + "/lockfile";
}

m_MultirunCacheDir = cefCachePath;

std::string tmpCacheMsg = "Using temporary Chromium cache to support multirun: " + m_MultirunCacheDir + "\n";
pResourceHandler->Message(tmpCacheMsg.c_str());
} else {
fs::copy_file(curLogPath, lastLogPath, fs::copy_options::overwrite_existing, rotateError);

if (rotateError) {
const std::string rotateErrorMsg = "Couldn't rotate chromium.log (copy): " + rotateError.message() + "\n";
pResourceHandler->Message(rotateErrorMsg.c_str());
rotateError.clear();
}

// TODO(winter): Truncate instead?
fs::remove(curLogPath, rotateError);
// TODO(winter): Truncate instead?
fs::remove(curLogPath, rotateError);

if (rotateError) {
pResourceHandler->Message("Couldn't rotate chromium.log (remove): " + rotateError.message() + "\n");
rotateError.clear();
if (rotateError) {
const std::string rotateErrorMsg = "Couldn't rotate chromium.log (remove): " + rotateError.message() + "\n";
pResourceHandler->Message(rotateErrorMsg.c_str());
rotateError.clear();
}
}

CefString( &settings.log_file ).FromString( curLogPath );

// CEF 120+ requires this otherwise CEF applications will trample each other
CefString( &settings.root_cache_path ).FromString( strBaseDir + "/ChromiumCache" );
CefString( &settings.cache_path ).FromString( strBaseDir + "/ChromiumCache" );
CefString( &settings.root_cache_path ).FromString( cefCachePath );
CefString( &settings.cache_path ).FromString( cefCachePath );

// Grab our Sandbox info from the "game" exe
#if defined(_WIN32) && defined(CEF_USE_SANDBOX)
Expand Down Expand Up @@ -297,6 +321,24 @@ bool ChromiumSystem::Init( const char* pBaseDir, IHtmlResourceHandler* pResource
void ChromiumSystem::Shutdown()
{
CefShutdown();

// Delete temporary ChromiumCacheMultirun if it exists
// TODO(winter): For some reason CEF still hasn't released the handles it has for these files even though CefShutdown has finished and the lockfile is gone...
/*
if (!m_MultirunCacheDir.empty()) {
while (fs::exists(m_MultirunCacheDir + "/lockfile")) {
// Spin until the lockfile is released by CEF
}
std::error_code removeTempError;
fs::remove_all(m_MultirunCacheDir, removeTempError);
if (removeTempError) {
const std::string removeTempErrorMsg = "Couldn't remove temporary Chromium cache: " + removeTempError.message() + "\n";
g_pHtmlResourceHandler->Message(removeTempErrorMsg.c_str());
}
}
*/
}

IHtmlClient* ChromiumSystem::CreateClient( IHtmlClientListener* listener )
Expand Down
2 changes: 2 additions & 0 deletions html_chromium/ChromiumSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class ChromiumSystem : public IHtmlSystem

base::Lock m_RequestsLock;
std::vector<CefRefPtr<ResourceHandler>> m_Requests;

std::string m_MultirunCacheDir;
};

// We've got a few bits of code that need to access this directly
Expand Down

0 comments on commit 92ebc22

Please sign in to comment.