Skip to content

Commit e75a3c0

Browse files
S1artiemagreenblatt
authored andcommitted
Update to CEF 121.3.9+g1e0a38f+chromium-121.0.6167.184
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.
1 parent 3df5f07 commit e75a3c0

8 files changed

Lines changed: 101 additions & 3 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ set_property(GLOBAL PROPERTY OS_FOLDERS ON)
130130

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

136136
# Determine the platform.

java/org/cef/CefApp.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ public enum CefAppState {
102102
*/
103103
INITIALIZED,
104104

105+
/**
106+
* CEF initialization has failed (for example due to a second process using
107+
* the same root_cache_path).
108+
*/
109+
INITIALIZATION_FAILED,
110+
105111
/**
106112
* CefApp is in its shutdown process. All CefClients and CefBrowser
107113
* instances will be disposed. No new CefClient or CefBrowser is allowed to
@@ -424,7 +430,11 @@ public void run() {
424430
}
425431
}
426432

427-
if (N_Initialize(appHandler_, settings)) setState(CefAppState.INITIALIZED);
433+
if (N_Initialize(appHandler_, settings)) {
434+
setState(CefAppState.INITIALIZED);
435+
} else {
436+
setState(CefAppState.INITIALIZATION_FAILED);
437+
}
428438
}
429439
};
430440
if (SwingUtilities.isEventDispatchThread())

java/org/cef/CefSettings.java

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,39 @@ public ColorType clone() {
102102
* The location where cache data will be stored on disk. If empty an in-memory
103103
* cache will be used for some features and a temporary disk cache for others.
104104
* HTML5 databases such as localStorage will only persist across sessions if a
105-
* cache path is specified.
105+
* cache path is specified. If this is set and root_cache_path is also set, the cache_path
106+
* directory must reside within root_cache_path.
106107
*/
107108
public String cache_path = null;
108109

110+
/**
111+
* The root directory for installation-specific data and the parent directory
112+
* for profile-specific data. All CefSettings.cache_path and
113+
* CefRequestContextSettings.cache_path values must have this parent
114+
* directory in common. If this value is empty and CefSettings.cache_path is
115+
* non-empty then it will default to the CefSettings.cache_path value. Any
116+
* non-empty value must be an absolute path. If both values are empty then
117+
* the default platform-specific directory will be used
118+
* ("~/.config/cef_user_data" directory on Linux, "~/Library/Application
119+
* Support/CEF/User Data" directory on MacOS, "AppData\Local\CEF\User Data"
120+
* directory under the user profile directory on Windows). Use of the default
121+
* directory is not recommended in production applications (see below).
122+
*
123+
* Multiple application instances writing to the same root_cache_path
124+
* directory could result in data corruption. A process singleton lock based
125+
* on the root_cache_path value is therefore used to protect against this.
126+
* This singleton behavior applies to all CEF-based applications using
127+
* version 120 or newer. You should customize root_cache_path for your
128+
* application and implement CefAppHandler::
129+
* onAlreadyRunningAppRelaunch, which will then be called on any app relaunch
130+
* with the same root_cache_path value.
131+
*
132+
* Failure to set the root_cache_path value correctly may result in startup
133+
* crashes or other unexpected behaviors (for example, the sandbox blocking
134+
* read/write access to certain files).
135+
*/
136+
public String root_cache_path = null;
137+
109138
/**
110139
* To persist session cookies (cookies without an expiry date or validity
111140
* interval) by default when using the global cookie manager set this value to
@@ -239,6 +268,7 @@ public CefSettings clone() {
239268
tmp.windowless_rendering_enabled = windowless_rendering_enabled;
240269
tmp.command_line_args_disabled = command_line_args_disabled;
241270
tmp.cache_path = cache_path;
271+
tmp.root_cache_path = root_cache_path;
242272
tmp.persist_session_cookies = persist_session_cookies;
243273
tmp.user_agent = user_agent;
244274
tmp.user_agent_product = user_agent_product;

java/org/cef/handler/CefAppHandler.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,23 @@ public interface CefAppHandler {
7272
* currently pending scheduled call should be cancelled.
7373
*/
7474
public void onScheduleMessagePumpWork(long delay_ms);
75+
76+
/**
77+
* Implement this method to provide app-specific behavior when an already
78+
* running app is relaunched with the same CefSettings.root_cache_path value.
79+
* For example, activate an existing app window or create a new app window.
80+
* |command_line| will be read-only. Do not keep a reference to
81+
* |command_line| outside of this method. Return true if the relaunch is
82+
* handled or false for default relaunch behavior. Default behavior will
83+
* create a new default styled Chrome window.
84+
*
85+
* To avoid cache corruption only a single app instance is allowed to run for
86+
* a given CefSettings.root_cache_path value. On relaunch the app checks a
87+
* process singleton lock and then forwards the new launch arguments to the
88+
* already running app process before exiting early. Client apps should
89+
* therefore check the CefInitialize() return value for early exit before
90+
* proceeding.
91+
*/
92+
public boolean onAlreadyRunningAppRelaunch(
93+
CefCommandLine command_line, String current_directory);
7594
}

java/org/cef/handler/CefAppHandlerAdapter.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,11 @@ public void onContextInitialized() {
8989
public void onScheduleMessagePumpWork(long delay_ms) {
9090
CefApp.getInstance().doMessageLoopWork(delay_ms);
9191
}
92+
93+
@Override
94+
public boolean onAlreadyRunningAppRelaunch(
95+
CefCommandLine command_line, String current_directory) {
96+
// The default implementation does nothing
97+
return false;
98+
}
9299
}

native/browser_process_handler.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,31 @@ void BrowserProcessHandler::OnScheduleMessagePumpWork(int64_t delay_ms) {
5050
delay_ms);
5151
}
5252

53+
bool BrowserProcessHandler::OnAlreadyRunningAppRelaunch(
54+
CefRefPtr<CefCommandLine> command_line,
55+
const CefString& current_directory) {
56+
if (!handle_)
57+
return false;
58+
59+
ScopedJNIEnv env;
60+
if (!env)
61+
return false;
62+
63+
ScopedJNIObject<CefCommandLine> jcommandLine(
64+
env, command_line, "org/cef/callback/CefCommandLine_N", "CefCommandLine");
65+
jcommandLine.SetTemporary();
66+
ScopedJNIString jcurrentDirectory(env, current_directory);
67+
68+
jboolean jresult = 0;
69+
70+
JNI_CALL_BOOLEAN_METHOD(
71+
jresult, env, handle_, "onAlreadyRunningAppRelaunch",
72+
"(Lorg/cef/callback/CefCommandLine;Ljava/lang/String;)Z",
73+
jcommandLine.get(), jcurrentDirectory.get());
74+
75+
return jresult;
76+
}
77+
5378
// static
5479
CefRefPtr<CefListValue> BrowserProcessHandler::GetMessageRouterConfigs() {
5580
int idx = 0;

native/browser_process_handler.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ class BrowserProcessHandler : public CefBrowserProcessHandler {
3434

3535
void OnContextInitialized() override;
3636
void OnScheduleMessagePumpWork(int64_t delay_ms) override;
37+
bool OnAlreadyRunningAppRelaunch(CefRefPtr<CefCommandLine> command_line,
38+
const CefString& current_directory) override;
3739

3840
static CefRefPtr<CefListValue> GetMessageRouterConfigs();
3941
static void AddMessageRouterConfig(const CefMessageRouterConfig& cfg);

native/context.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ CefSettings GetJNISettings(JNIEnv* env, jobject obj) {
4444
CefString(&settings.cache_path) = tmp;
4545
tmp.clear();
4646
}
47+
if (GetJNIFieldString(env, cls, obj, "root_cache_path", &tmp) &&
48+
!tmp.empty()) {
49+
CefString(&settings.root_cache_path) = tmp;
50+
tmp.clear();
51+
}
4752
GetJNIFieldBoolean(env, cls, obj, "persist_session_cookies",
4853
&settings.persist_session_cookies);
4954
if (GetJNIFieldString(env, cls, obj, "user_agent", &tmp) && !tmp.empty()) {

0 commit comments

Comments
 (0)