chrome: Add callback for already running app relaunch (fixes #3609)

Adds a new CefBrowserProcessHandler::OnAlreadyRunningAppRelaunch
callback for when an already running app is relaunched with the
same CefSettings.root_cache_path.

Client apps should check the CefInitialize() return value for early
exit of the relaunch source process.
This commit is contained in:
Marshall Greenblatt
2023-11-28 20:33:44 -05:00
parent d6af79e7a6
commit a25f89f9e4
45 changed files with 553 additions and 178 deletions

View File

@@ -33,7 +33,7 @@
// by hand. See the translator.README.txt file in the tools directory for
// more information.
//
// $hash=9b523fbf312a8a0cb1c743a3c8aca7bc9cc22bbc$
// $hash=692f2719fc029131ce17a7c90abca178daadb63e$
//
#ifndef CEF_INCLUDE_CAPI_CEF_APP_CAPI_H_
@@ -133,10 +133,13 @@ CEF_EXPORT int cef_execute_process(const cef_main_args_t* args,
///
/// This function should be called on the main application thread to initialize
/// the CEF browser process. The |application| parameter may be NULL. A return
/// value of true (1) indicates that it succeeded and false (0) indicates that
/// it failed. The |windows_sandbox_info| parameter is only used on Windows and
/// may be NULL (see cef_sandbox_win.h for details).
/// the CEF browser process. The |application| parameter may be NULL. Returns
/// true (1) if initialization succeeds. Returns false (0) if initialization
/// fails or if early exit is desired (for example, due to process singleton
/// relaunch behavior). If this function returns false (0) then the application
/// should exit immediately without calling any other CEF functions. The
/// |windows_sandbox_info| parameter is only used on Windows and may be NULL
/// (see cef_sandbox_win.h for details).
///
CEF_EXPORT int cef_initialize(const cef_main_args_t* args,
const struct _cef_settings_t* settings,
@@ -145,7 +148,8 @@ CEF_EXPORT int cef_initialize(const cef_main_args_t* args,
///
/// This function should be called on the main application thread to shut down
/// the CEF browser process before the application exits.
/// the CEF browser process before the application exits. Do not call any other
/// CEF functions after calling this function.
///
CEF_EXPORT void cef_shutdown(void);

View File

@@ -33,7 +33,7 @@
// by hand. See the translator.README.txt file in the tools directory for
// more information.
//
// $hash=a146316e075450f0a6f37cb45d14e15e0ac7be08$
// $hash=9e91adb231d67a65ce02294a0806d7effd40d280$
//
#ifndef CEF_INCLUDE_CAPI_CEF_BROWSER_PROCESS_HANDLER_CAPI_H_
@@ -106,6 +106,30 @@ typedef struct _cef_browser_process_handler_t {
struct _cef_browser_process_handler_t* self,
struct _cef_command_line_t* command_line);
///
/// Implement this function 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 function. Return true (1) if the relaunch
/// is handled or false (0) 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 cef_initialize() return value for early exit before
/// proceeding.
///
/// This function will be called on the browser process UI thread. Currently
/// only used with the chrome runtime.
///
int(CEF_CALLBACK* on_already_running_app_relaunch)(
struct _cef_browser_process_handler_t* self,
struct _cef_command_line_t* command_line,
const cef_string_t* current_directory);
///
/// Called from any thread when work has been scheduled for the browser
/// process main (UI) thread. This callback is used in combination with

View File

@@ -42,13 +42,13 @@
// way that may cause binary incompatibility with other builds. The universal
// hash value will change if any platform is affected whereas the platform hash
// values will change only if that particular platform is affected.
#define CEF_API_HASH_UNIVERSAL "09b1cc5ff57703ab04bd555c4b24e8bc7c660cb6"
#define CEF_API_HASH_UNIVERSAL "bbdc07e7c5ed2ae5398efdebdd1ed08801bc91ab"
#if defined(OS_WIN)
#define CEF_API_HASH_PLATFORM "64478d96e4841bd34db245d65d390f2d25759e5e"
#define CEF_API_HASH_PLATFORM "002e3391fd68b0a444dbb6cd1b2a19a4c181d935"
#elif defined(OS_MAC)
#define CEF_API_HASH_PLATFORM "8596f11f53a9100d69757d82208bb3d89d5bf524"
#define CEF_API_HASH_PLATFORM "3e4f2433692dc8bb779314dce84b81d81d39d2c2"
#elif defined(OS_LINUX)
#define CEF_API_HASH_PLATFORM "2f53b2bbce606c42c0c462be1b1e16199962d6b7"
#define CEF_API_HASH_PLATFORM "4e707370d08d4639c41e7c8aa8027c4a6090eace"
#endif
#ifdef __cplusplus

View File

@@ -67,10 +67,13 @@ int CefExecuteProcess(const CefMainArgs& args,
///
/// This function should be called on the main application thread to initialize
/// the CEF browser process. The |application| parameter may be empty. A return
/// value of true indicates that it succeeded and false indicates that it
/// failed. The |windows_sandbox_info| parameter is only used on Windows and may
/// be NULL (see cef_sandbox_win.h for details).
/// the CEF browser process. The |application| parameter may be empty. Returns
/// true if initialization succeeds. Returns false if initialization fails or if
/// early exit is desired (for example, due to process singleton relaunch
/// behavior). If this function returns false then the application should exit
/// immediately without calling any other CEF functions. The
/// |windows_sandbox_info| parameter is only used on Windows and may be NULL
/// (see cef_sandbox_win.h for details).
///
/*--cef(api_hash_check,optional_param=application,
optional_param=windows_sandbox_info)--*/
@@ -81,7 +84,8 @@ bool CefInitialize(const CefMainArgs& args,
///
/// This function should be called on the main application thread to shut down
/// the CEF browser process before the application exits.
/// the CEF browser process before the application exits. Do not call any
/// other CEF functions after calling this function.
///
/*--cef()--*/
void CefShutdown();

View File

@@ -97,6 +97,32 @@ class CefBrowserProcessHandler : public virtual CefBaseRefCounted {
virtual void OnBeforeChildProcessLaunch(
CefRefPtr<CefCommandLine> command_line) {}
///
/// 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.
///
/// This method will be called on the browser process UI thread. Currently
/// only used with the chrome runtime.
///
/*--cef(optional_param=current_directory)--*/
virtual bool OnAlreadyRunningAppRelaunch(
CefRefPtr<CefCommandLine> command_line,
const CefString& current_directory) {
return false;
}
///
/// Called from any thread when work has been scheduled for the browser
/// process main (UI) thread. This callback is used in combination with