1 // Copyright 2018 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef UI_SHELL_DIALOGS_EXECUTE_SELECT_FILE_WIN_H_
6 #define UI_SHELL_DIALOGS_EXECUTE_SELECT_FILE_WIN_H_
7 
8 #include <utility>
9 #include <vector>
10 
11 #include "base/callback_forward.h"
12 #include "base/strings/string16.h"
13 #include "base/win/windows_types.h"
14 #include "ui/shell_dialogs/select_file_dialog.h"
15 #include "ui/shell_dialogs/shell_dialogs_export.h"
16 
17 namespace base {
18 class FilePath;
19 }
20 
21 namespace ui {
22 
23 // Implementation detail exported for unit tests.
24 SHELL_DIALOGS_EXPORT base::string16 AppendExtensionIfNeeded(
25     const base::string16& filename,
26     const base::string16& filter_selected,
27     const base::string16& suggested_ext);
28 
29 // Describes a filter for a file dialog.
30 struct FileFilterSpec {
31   // A human readable description of this filter. E.g. "HTML Files."
32   base::string16 description;
33   // The different extensions that map to this spec. This is a semicolon-
34   // separated list of extensions that contains a wildcard and the separator.
35   // E.g. "*.html;*.htm"
36   base::string16 extension_spec;
37 };
38 
39 using OnSelectFileExecutedCallback =
40     base::OnceCallback<void(const std::vector<base::FilePath>&, int)>;
41 
42 // Shows the file selection dialog modal to |owner| returns the selected file(s)
43 // and file type index using the |on_select_file_executed_callback|. The file
44 // path vector will be empty on failure.
45 SHELL_DIALOGS_EXPORT
46 void ExecuteSelectFile(
47     SelectFileDialog::Type type,
48     const base::string16& title,
49     const base::FilePath& default_path,
50     const std::vector<FileFilterSpec>& filter,
51     int file_type_index,
52     const base::string16& default_extension,
53     HWND owner,
54     OnSelectFileExecutedCallback on_select_file_executed_callback);
55 
56 }  // namespace ui
57 
58 #endif  // UI_SHELL_DIALOGS_EXECUTE_SELECT_FILE_WIN_H_
59