Skip to content

Commit

Permalink
Update to CEF 121.3.9+g1e0a38f+chromium-121.0.6167.184
Browse files Browse the repository at this point in the history
Added root_cache_path setting and onAlreadyRunningAppRelaunch event
to deal with new CEF restrictions regarding parallel use of root_cache_path
dir starting with CEF 120.
  • Loading branch information
S1artie authored and magreenblatt committed Mar 4, 2024
1 parent 3df5f07 commit e75a3c0
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ set_property(GLOBAL PROPERTY OS_FOLDERS ON)

# Specify the CEF distribution version.
if(NOT DEFINED CEF_VERSION)
set(CEF_VERSION "119.4.7+g55e15c8+chromium-119.0.6045.199")
set(CEF_VERSION "121.3.9+g1e0a38f+chromium-121.0.6167.184")
endif()

# Determine the platform.
Expand Down
12 changes: 11 additions & 1 deletion java/org/cef/CefApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ public enum CefAppState {
*/
INITIALIZED,

/**
* CEF initialization has failed (for example due to a second process using
* the same root_cache_path).
*/
INITIALIZATION_FAILED,

/**
* CefApp is in its shutdown process. All CefClients and CefBrowser
* instances will be disposed. No new CefClient or CefBrowser is allowed to
Expand Down Expand Up @@ -424,7 +430,11 @@ public void run() {
}
}

if (N_Initialize(appHandler_, settings)) setState(CefAppState.INITIALIZED);
if (N_Initialize(appHandler_, settings)) {
setState(CefAppState.INITIALIZED);
} else {
setState(CefAppState.INITIALIZATION_FAILED);
}
}
};
if (SwingUtilities.isEventDispatchThread())
Expand Down
32 changes: 31 additions & 1 deletion java/org/cef/CefSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,39 @@ public ColorType clone() {
* The location where cache data will be stored on disk. If empty an in-memory
* cache will be used for some features and a temporary disk cache for others.
* HTML5 databases such as localStorage will only persist across sessions if a
* cache path is specified.
* cache path is specified. If this is set and root_cache_path is also set, the cache_path
* directory must reside within root_cache_path.
*/
public String cache_path = null;

/**
* The root directory for installation-specific data and the parent directory
* for profile-specific data. All CefSettings.cache_path and
* CefRequestContextSettings.cache_path values must have this parent
* directory in common. If this value is empty and CefSettings.cache_path is
* non-empty then it will default to the CefSettings.cache_path value. Any
* non-empty value must be an absolute path. If both values are empty then
* the default platform-specific directory will be used
* ("~/.config/cef_user_data" directory on Linux, "~/Library/Application
* Support/CEF/User Data" directory on MacOS, "AppData\Local\CEF\User Data"
* directory under the user profile directory on Windows). Use of the default
* directory is not recommended in production applications (see below).
*
* Multiple application instances writing to the same root_cache_path
* directory could result in data corruption. A process singleton lock based
* on the root_cache_path value is therefore used to protect against this.
* This singleton behavior applies to all CEF-based applications using
* version 120 or newer. You should customize root_cache_path for your
* application and implement CefAppHandler::
* onAlreadyRunningAppRelaunch, which will then be called on any app relaunch
* with the same root_cache_path value.
*
* Failure to set the root_cache_path value correctly may result in startup
* crashes or other unexpected behaviors (for example, the sandbox blocking
* read/write access to certain files).
*/
public String root_cache_path = null;

/**
* To persist session cookies (cookies without an expiry date or validity
* interval) by default when using the global cookie manager set this value to
Expand Down Expand Up @@ -239,6 +268,7 @@ public CefSettings clone() {
tmp.windowless_rendering_enabled = windowless_rendering_enabled;
tmp.command_line_args_disabled = command_line_args_disabled;
tmp.cache_path = cache_path;
tmp.root_cache_path = root_cache_path;
tmp.persist_session_cookies = persist_session_cookies;
tmp.user_agent = user_agent;
tmp.user_agent_product = user_agent_product;
Expand Down
19 changes: 19 additions & 0 deletions java/org/cef/handler/CefAppHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,23 @@ public interface CefAppHandler {
* currently pending scheduled call should be cancelled.
*/
public void onScheduleMessagePumpWork(long delay_ms);

/**
* Implement this method to provide app-specific behavior when an already
* running app is relaunched with the same CefSettings.root_cache_path value.
* For example, activate an existing app window or create a new app window.
* |command_line| will be read-only. Do not keep a reference to
* |command_line| outside of this method. Return true if the relaunch is
* handled or false for default relaunch behavior. Default behavior will
* create a new default styled Chrome window.
*
* To avoid cache corruption only a single app instance is allowed to run for
* a given CefSettings.root_cache_path value. On relaunch the app checks a
* process singleton lock and then forwards the new launch arguments to the
* already running app process before exiting early. Client apps should
* therefore check the CefInitialize() return value for early exit before
* proceeding.
*/
public boolean onAlreadyRunningAppRelaunch(
CefCommandLine command_line, String current_directory);
}
7 changes: 7 additions & 0 deletions java/org/cef/handler/CefAppHandlerAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,11 @@ public void onContextInitialized() {
public void onScheduleMessagePumpWork(long delay_ms) {
CefApp.getInstance().doMessageLoopWork(delay_ms);
}

@Override
public boolean onAlreadyRunningAppRelaunch(
CefCommandLine command_line, String current_directory) {
// The default implementation does nothing
return false;
}
}
25 changes: 25 additions & 0 deletions native/browser_process_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,31 @@ void BrowserProcessHandler::OnScheduleMessagePumpWork(int64_t delay_ms) {
delay_ms);
}

bool BrowserProcessHandler::OnAlreadyRunningAppRelaunch(
CefRefPtr<CefCommandLine> command_line,
const CefString& current_directory) {
if (!handle_)
return false;

ScopedJNIEnv env;
if (!env)
return false;

ScopedJNIObject<CefCommandLine> jcommandLine(
env, command_line, "org/cef/callback/CefCommandLine_N", "CefCommandLine");
jcommandLine.SetTemporary();
ScopedJNIString jcurrentDirectory(env, current_directory);

jboolean jresult = 0;

JNI_CALL_BOOLEAN_METHOD(
jresult, env, handle_, "onAlreadyRunningAppRelaunch",
"(Lorg/cef/callback/CefCommandLine;Ljava/lang/String;)Z",
jcommandLine.get(), jcurrentDirectory.get());

return jresult;
}

// static
CefRefPtr<CefListValue> BrowserProcessHandler::GetMessageRouterConfigs() {
int idx = 0;
Expand Down
2 changes: 2 additions & 0 deletions native/browser_process_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class BrowserProcessHandler : public CefBrowserProcessHandler {

void OnContextInitialized() override;
void OnScheduleMessagePumpWork(int64_t delay_ms) override;
bool OnAlreadyRunningAppRelaunch(CefRefPtr<CefCommandLine> command_line,
const CefString& current_directory) override;

static CefRefPtr<CefListValue> GetMessageRouterConfigs();
static void AddMessageRouterConfig(const CefMessageRouterConfig& cfg);
Expand Down
5 changes: 5 additions & 0 deletions native/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ CefSettings GetJNISettings(JNIEnv* env, jobject obj) {
CefString(&settings.cache_path) = tmp;
tmp.clear();
}
if (GetJNIFieldString(env, cls, obj, "root_cache_path", &tmp) &&
!tmp.empty()) {
CefString(&settings.root_cache_path) = tmp;
tmp.clear();
}
GetJNIFieldBoolean(env, cls, obj, "persist_session_cookies",
&settings.persist_session_cookies);
if (GetJNIFieldString(env, cls, obj, "user_agent", &tmp) && !tmp.empty()) {
Expand Down

0 comments on commit e75a3c0

Please sign in to comment.