Use Chrome file dialogs on all platforms and runtimes (fixes issue #3314)

All file dialogs irrespective of source, platform and runtime will now be
routed through CefFileDialogManager and trigger CefDialogHandler callbacks
(see issue #3293).

Adds Chrome runtime support for CefBrowserHost::RunFileDialog and
CefDialogHandler callbacks.

Adds Alloy runtime support for internal GTK file and print dialogs on Linux
subject to the following limitations:

1. Internal GTK implementation:
   - Cannot be used with multi-threaded-message-loop because Chromium's
     internal GTK implementation is not thread-safe (does not use GDK threads).
   - Dialogs will not be modal to application windows when used with off-screen
     rendering due to lack of access to the client's top-level GtkWindow.
2. Cefclient CefDialogHandler implementation:
   - Cannot be used with Views because it requires a top-level GtkWindow.

Due to the above limitations no dialog implementation is currently provided for
Views + multi-threaded-message-loop on Linux. In cases where both
implementations are supported the cefclient version is now behind an optional
`--use-client-dialogs` command-line flag.

Expressly forbids multiple simultaneous file dialogs with the internal platform
implementation which uses modal dialogs. CefDialogHandler will still be notified
and can optionally handle each request without a modal dialog (see issue #3154).

Removes some RunFileDialog parameters that are not supported by the Chrome file
dialog implementation (selected_accept_filter parameter, cef_file_dialog_mode_t
overwrite/read-only flags).
This commit is contained in:
Marshall Greenblatt
2022-04-15 15:55:23 -04:00
parent edef01f579
commit 2ea7459a89
75 changed files with 1566 additions and 2231 deletions

View File

@@ -33,7 +33,7 @@
// by hand. See the translator.README.txt file in the tools directory for
// more information.
//
// $hash=b80e84c0039ab45d5c4562d64b67a84766c0dab3$
// $hash=b1c1e44e6d3842064ef6e5b9823173f7ec1fcccc$
//
#ifndef CEF_INCLUDE_CAPI_CEF_BROWSER_CAPI_H_
@@ -205,15 +205,12 @@ typedef struct _cef_run_file_dialog_callback_t {
cef_base_ref_counted_t base;
///
// Called asynchronously after the file dialog is dismissed.
// |selected_accept_filter| is the 0-based index of the value selected from
// the accept filters array passed to cef_browser_host_t::RunFileDialog.
// |file_paths| will be a single value or a list of values depending on the
// dialog mode. If the selection was cancelled |file_paths| will be NULL.
// Called asynchronously after the file dialog is dismissed. |file_paths| will
// be a single value or a list of values depending on the dialog mode. If the
// selection was cancelled |file_paths| will be NULL.
///
void(CEF_CALLBACK* on_file_dialog_dismissed)(
struct _cef_run_file_dialog_callback_t* self,
int selected_accept_filter,
cef_string_list_t file_paths);
} cef_run_file_dialog_callback_t;
@@ -391,11 +388,10 @@ typedef struct _cef_browser_host_t {
// selectable file types and may any combination of (a) valid lower-cased MIME
// types (e.g. "text/*" or "image/*"), (b) individual file extensions (e.g.
// ".txt" or ".png"), or (c) combined description and file extension delimited
// using "|" and ";" (e.g. "Image Types|.png;.gif;.jpg").
// |selected_accept_filter| is the 0-based index of the filter that will be
// selected by default. |callback| will be executed after the dialog is
// dismissed or immediately if another dialog is already pending. The dialog
// will be initiated asynchronously on the UI thread.
// using "|" and ";" (e.g. "Image Types|.png;.gif;.jpg"). |callback| will be
// executed after the dialog is dismissed or immediately if another dialog is
// already pending. The dialog will be initiated asynchronously on the UI
// thread.
///
void(CEF_CALLBACK* run_file_dialog)(
struct _cef_browser_host_t* self,
@@ -403,7 +399,6 @@ typedef struct _cef_browser_host_t {
const cef_string_t* title,
const cef_string_t* default_file_path,
cef_string_list_t accept_filters,
int selected_accept_filter,
struct _cef_run_file_dialog_callback_t* callback);
///

View File

@@ -33,7 +33,7 @@
// by hand. See the translator.README.txt file in the tools directory for
// more information.
//
// $hash=0f56154217707d141912dc8a298279df8df04311$
// $hash=dc579beb1f25f9bbdb72afb4b5b381e129f84e31$
//
#ifndef CEF_INCLUDE_CAPI_CEF_DIALOG_HANDLER_CAPI_H_
@@ -57,14 +57,11 @@ typedef struct _cef_file_dialog_callback_t {
cef_base_ref_counted_t base;
///
// Continue the file selection. |selected_accept_filter| should be the 0-based
// index of the value selected from the accept filters array passed to
// cef_dialog_handler_t::OnFileDialog. |file_paths| should be a single value
// or a list of values depending on the dialog mode. An NULL |file_paths|
// value is treated the same as calling cancel().
// Continue the file selection. |file_paths| should be a single value or a
// list of values depending on the dialog mode. An NULL |file_paths| value is
// treated the same as calling cancel().
///
void(CEF_CALLBACK* cont)(struct _cef_file_dialog_callback_t* self,
int selected_accept_filter,
cef_string_list_t file_paths);
///
@@ -93,10 +90,9 @@ typedef struct _cef_dialog_handler_t {
// (a) valid lower-cased MIME types (e.g. "text/*" or "image/*"), (b)
// individual file extensions (e.g. ".txt" or ".png"), or (c) combined
// description and file extension delimited using "|" and ";" (e.g. "Image
// Types|.png;.gif;.jpg"). |selected_accept_filter| is the 0-based index of
// the filter that should be selected by default. To display a custom dialog
// return true (1) and execute |callback| either inline or at a later time. To
// display the default dialog return false (0).
// Types|.png;.gif;.jpg"). To display a custom dialog return true (1) and
// execute |callback| either inline or at a later time. To display the default
// dialog return false (0).
///
int(CEF_CALLBACK* on_file_dialog)(
struct _cef_dialog_handler_t* self,
@@ -105,7 +101,6 @@ typedef struct _cef_dialog_handler_t {
const cef_string_t* title,
const cef_string_t* default_file_path,
cef_string_list_t accept_filters,
int selected_accept_filter,
struct _cef_file_dialog_callback_t* callback);
} cef_dialog_handler_t;

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 "1d7470ed03e8ddca6998284bef50694f5bad036c"
#define CEF_API_HASH_UNIVERSAL "02da3a1d216f7e3d3dcb54658d939e3d4ebf1aa0"
#if defined(OS_WIN)
#define CEF_API_HASH_PLATFORM "1c2e8c364d8dead07b5601bcac5c51392eb0821d"
#define CEF_API_HASH_PLATFORM "ab8b744ba6e0275c87e5640af47571692957a7b4"
#elif defined(OS_MAC)
#define CEF_API_HASH_PLATFORM "934c730bb8b18a6b987612e5e99b28173f189c72"
#define CEF_API_HASH_PLATFORM "77ae587ff6423e3f26dcc950ef5a894e341ddf1c"
#elif defined(OS_LINUX)
#define CEF_API_HASH_PLATFORM "f45d62cfe6b26112a91404c0ff1332e3ff153b8b"
#define CEF_API_HASH_PLATFORM "1d805fef4907c18098039d89896ab8fec3d5e70a"
#endif
#ifdef __cplusplus

View File

@@ -206,14 +206,11 @@ class CefRunFileDialogCallback : public virtual CefBaseRefCounted {
public:
///
// Called asynchronously after the file dialog is dismissed.
// |selected_accept_filter| is the 0-based index of the value selected from
// the accept filters array passed to CefBrowserHost::RunFileDialog.
// |file_paths| will be a single value or a list of values depending on the
// dialog mode. If the selection was cancelled |file_paths| will be empty.
///
/*--cef(index_param=selected_accept_filter,optional_param=file_paths)--*/
/*--cef(optional_param=file_paths)--*/
virtual void OnFileDialogDismissed(
int selected_accept_filter,
const std::vector<CefString>& file_paths) = 0;
};
@@ -421,19 +418,17 @@ class CefBrowserHost : public virtual CefBaseRefCounted {
// selectable file types and may any combination of (a) valid lower-cased MIME
// types (e.g. "text/*" or "image/*"), (b) individual file extensions (e.g.
// ".txt" or ".png"), or (c) combined description and file extension delimited
// using "|" and ";" (e.g. "Image Types|.png;.gif;.jpg").
// |selected_accept_filter| is the 0-based index of the filter that will be
// selected by default. |callback| will be executed after the dialog is
// dismissed or immediately if another dialog is already pending. The dialog
// will be initiated asynchronously on the UI thread.
// using "|" and ";" (e.g. "Image Types|.png;.gif;.jpg"). |callback| will be
// executed after the dialog is dismissed or immediately if another dialog is
// already pending. The dialog will be initiated asynchronously on the UI
// thread.
///
/*--cef(optional_param=title,optional_param=default_file_path,
optional_param=accept_filters,index_param=selected_accept_filter)--*/
optional_param=accept_filters)--*/
virtual void RunFileDialog(FileDialogMode mode,
const CefString& title,
const CefString& default_file_path,
const std::vector<CefString>& accept_filters,
int selected_accept_filter,
CefRefPtr<CefRunFileDialogCallback> callback) = 0;
///

View File

@@ -48,16 +48,12 @@
class CefFileDialogCallback : public virtual CefBaseRefCounted {
public:
///
// Continue the file selection. |selected_accept_filter| should be the 0-based
// index of the value selected from the accept filters array passed to
// CefDialogHandler::OnFileDialog. |file_paths| should be a single value or a
// Continue the file selection. |file_paths| should be a single value or a
// list of values depending on the dialog mode. An empty |file_paths| value is
// treated the same as calling Cancel().
///
/*--cef(capi_name=cont,index_param=selected_accept_filter,
optional_param=file_paths)--*/
virtual void Continue(int selected_accept_filter,
const std::vector<CefString>& file_paths) = 0;
/*--cef(capi_name=cont,optional_param=file_paths)--*/
virtual void Continue(const std::vector<CefString>& file_paths) = 0;
///
// Cancel the file selection.
@@ -85,19 +81,17 @@ class CefDialogHandler : public virtual CefBaseRefCounted {
// (a) valid lower-cased MIME types (e.g. "text/*" or "image/*"),
// (b) individual file extensions (e.g. ".txt" or ".png"), or (c) combined
// description and file extension delimited using "|" and ";" (e.g.
// "Image Types|.png;.gif;.jpg"). |selected_accept_filter| is the 0-based
// index of the filter that should be selected by default. To display a custom
// dialog return true and execute |callback| either inline or at a later time.
// To display the default dialog return false.
// "Image Types|.png;.gif;.jpg"). To display a custom dialog return true and
// execute |callback| either inline or at a later time. To display the default
// dialog return false.
///
/*--cef(optional_param=title,optional_param=default_file_path,
optional_param=accept_filters,index_param=selected_accept_filter)--*/
optional_param=accept_filters)--*/
virtual bool OnFileDialog(CefRefPtr<CefBrowser> browser,
FileDialogMode mode,
const CefString& title,
const CefString& default_file_path,
const std::vector<CefString>& accept_filters,
int selected_accept_filter,
CefRefPtr<CefFileDialogCallback> callback) {
return false;
}

View File

@@ -2237,26 +2237,6 @@ typedef enum {
// already exists.
///
FILE_DIALOG_SAVE,
///
// General mask defining the bits used for the type values.
///
FILE_DIALOG_TYPE_MASK = 0xFF,
// Qualifiers.
// Any of the type values above can be augmented by one or more qualifiers.
// These qualifiers further define the dialog behavior.
///
// Prompt to overwrite if the user selects an existing file with the Save
// dialog.
///
FILE_DIALOG_OVERWRITEPROMPT_FLAG = 0x01000000,
///
// Do not display read-only files.
///
FILE_DIALOG_HIDEREADONLY_FLAG = 0x02000000,
} cef_file_dialog_mode_t;
///