Set default-dir, suggested-name in EXTRAS_INITIAL_URI, EXTRAS_TITLE
File System Access allows file choosers to set the default_directory
to one of the chosen directory file handles. Android supports this
via EXTRAS_INITIAL_URI.
JS API showSaveFilePicker() takes an optional suggestedName for the new
file which should be added into EXTRAS_TITLE in CREATE_DOCUMENT intent
to auto-fill a suggested name in save-as.
FileSystemChooser::Options::default_path() is created as
default_directory.Append(suggested_name) where both can be empty.
It is updated to always end with a path separator when suggested_name
is empty so that it can be reliably parsed back into default_directory
and suggested_name after default_path is passed as a param to
SelectFileDialgo::SelectFile(). The alternative of modifying the
existing SelectFile() default_path into 2 fields would not work since
many callsites have only the default_path which is ambiguous as to
whether it is a directory, or suggested-name or combination.
Bug: 379140421
Change-Id: Ife6ce61471c95acd4ef763ed6e570e063afc114c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6024565
Reviewed-by: Xiyuan Xia <[email protected]>
Code-Coverage: [email protected] <[email protected]>
Commit-Queue: Joel Hockey <[email protected]>
Reviewed-by: Ted Choc <[email protected]>
Reviewed-by: Nathan Memmott <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1384627}
diff --git a/ui/shell_dialogs/select_file_dialog_android.cc b/ui/shell_dialogs/select_file_dialog_android.cc
index eb9bd0b..adf17187 100644
--- a/ui/shell_dialogs/select_file_dialog_android.cc
+++ b/ui/shell_dialogs/select_file_dialog_android.cc
@@ -156,9 +156,23 @@
bool accept_multiple_files = SelectFileDialog::SELECT_OPEN_MULTI_FILE == type;
+ base::FilePath default_directory;
+ base::FilePath suggested_name;
+ // If default_path ends with a separator, then suggested_name was empty.
+ if (default_path.EndsWithSeparator()) {
+ default_directory = default_path;
+ } else {
+ default_directory = default_path.DirName();
+ suggested_name = default_path.BaseName();
+ }
+ if (!default_directory.IsContentUri()) {
+ default_directory = base::FilePath();
+ }
+
Java_SelectFileDialog_selectFile(
env, java_object_, intent_action, accept_types_java, use_media_capture_,
- accept_multiple_files, owning_window->GetJavaObject());
+ accept_multiple_files, default_directory.value(), suggested_name.value(),
+ owning_window->GetJavaObject());
}
SelectFileDialogImpl::~SelectFileDialogImpl() {