select_file.mojom 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. // Copyright 2020 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. module crosapi.mojom;
  5. import "mojo/public/mojom/base/file_path.mojom";
  6. import "mojo/public/mojom/base/string16.mojom";
  7. import "url/mojom/url.mojom";
  8. // The type of dialog to open. The integer values intentionally do not match
  9. // ui::SelectFileDialog::Type because there is no "none" value and kOpenFile
  10. // is the common case.
  11. [Stable, Extensible]
  12. enum SelectFileDialogType {
  13. // For opening a file.
  14. kOpenFile = 0,
  15. // Like kOpenFile, but allowing multiple files to open.
  16. kOpenMultiFile = 1,
  17. // For opening a folder.
  18. kFolder = 2,
  19. // Like kFolder, but the dialog UI shows it's specifically for "upload".
  20. kUploadFolder = 3,
  21. // Like kFolder, but folder creation is disabled.
  22. kExistingFolder = 4,
  23. // For saving into a file, allowing a nonexistent file to be selected.
  24. kSaveAsFile = 5,
  25. };
  26. // Specifies which type of paths the caller can handle.
  27. [Stable, Extensible]
  28. enum AllowedPaths {
  29. // Any type of path, whether local/native or remote/virtual.
  30. kAnyPath,
  31. // Set when the caller cannot handle virtual volumes (e.g. File System
  32. // Provider [FSP] volumes like "File System for Dropbox"). When opening files,
  33. // the dialog will create a native replica of the file and return its path.
  34. // When saving files, the dialog will hide virtual volumes.
  35. kNativePath,
  36. // Set when the caller can open files via URL. For example, when opening a
  37. // .gdoc file from Google Drive the file is "opened" by navigating to
  38. // docs.google.com.
  39. kAnyPathOrUrl,
  40. };
  41. // Information about the types of files used by the dialog.
  42. [Stable]
  43. struct SelectFileTypeInfo {
  44. // The list of allowed file extensions. For example:
  45. // { { "htm", "html" }, { "txt" } }
  46. // Only pass more than one extension in the inner vector if the extensions
  47. // are equivalent.
  48. array<array<string>> extensions@0;
  49. // Overrides the system descriptions of specified extensions. For example,
  50. // when saving a web page, "Webpage, HTML only" is used for {"htm", "html"}
  51. // and "Webpage, Single File" is used for {"mhtml"}. Length must match the
  52. // length of |extensions|. If empty or if the length doesn't match then
  53. // the system descriptions will be used.
  54. array<mojo_base.mojom.String16> extension_description_overrides@1;
  55. // One-based index of the file type (in the extensions list) to select by
  56. // default. Zero means no selection. (The index is one-based for consistency
  57. // with the C++ code and because mojo doesn't allow nullable primitive types.)
  58. // For example, when saving a web page, we use the index of {"mhtml"} so the
  59. // user sees "Webpage, Single File" as the default choice.
  60. int32 default_file_type_index@2;
  61. // Whether or not there will be a filter added for all files (*.*).
  62. bool include_all_files@3;
  63. // Types of paths/volumes allowed. Unrelated to file extensions.
  64. AllowedPaths allowed_paths@4;
  65. };
  66. // Options for the select file dialog.
  67. [Stable]
  68. struct SelectFileOptions {
  69. // Dialog type.
  70. SelectFileDialogType type@0;
  71. // Window title.
  72. mojo_base.mojom.String16 title@1;
  73. // Default path to open.
  74. mojo_base.mojom.FilePath default_path@2;
  75. // Optional file type configuration. In the common case for file open (Ctrl-O)
  76. // this is null.
  77. SelectFileTypeInfo? file_types@3;
  78. // Internal window ID for the top-level shell window that owns the dialog.
  79. // If provided, the dialog will be window-modal to that shell window.
  80. // If empty, a modeless dialog will be opened on the default display.
  81. string owning_shell_window_id@4;
  82. };
  83. // Result of the select file dialog.
  84. [Stable, Extensible]
  85. enum SelectFileResult {
  86. // Everything worked.
  87. kSuccess = 0,
  88. // Failed because the dialog couldn't find the owning top-level window.
  89. kInvalidShellWindow = 1,
  90. };
  91. // Information about the selected file or files.
  92. [Stable]
  93. struct SelectedFileInfo {
  94. // Path to the file, as seen in the UI.
  95. mojo_base.mojom.FilePath file_path@0;
  96. // The actual local path to the selected file. This can be a snapshot file
  97. // with a human unreadable name like /blah/.d41d8cd98f00b204e9800998ecf8427e.
  98. // |local_path| can differ from |file_path| for drive files (e.g.
  99. // /drive_cache/temporary/d41d8cd98f00b204e9800998ecf8427e vs.
  100. // /special/drive/foo.txt).
  101. mojo_base.mojom.FilePath local_path@1;
  102. // Optional display name of the file. UTF-8 encoded. If empty, the UI should
  103. // display the base name portion of |file_path|.
  104. string display_name@2;
  105. // Optional URL to access the file. If the caller can use a URL to access a
  106. // file, |url| should be used instead of |local_path|. For example, when
  107. // opening a .gdoc file from Google Drive the |local_path| is a placeholder
  108. // file that should be "opened" by navigating to docs.google.com.
  109. url.mojom.Url? url@3;
  110. };
  111. // Select file dialog interface. Wrapper around the C++ SelectFileDialog
  112. // class. Called from lacros-chrome. Implemented in ash-chrome using the
  113. // file manager dialog.
  114. [Stable, Uuid="8c0eb5f3-4c90-4bfd-8a0f-377c99f09125"]
  115. interface SelectFile {
  116. // Selects one or more files. If the dialog is closed or canceled without
  117. // selecting a file, or if there is an error, |files| will be empty.
  118. // When saving a file or opening a single file, |file_type_index| is the
  119. // one-based index of the selected file type from the SelectFileTypeInfo
  120. // extension list, otherwise it is zero.
  121. Select@0(SelectFileOptions options) =>
  122. (SelectFileResult result,
  123. array<SelectedFileInfo> files,
  124. int32 file_type_index);
  125. };