summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/public/mojom/file_system_access/file_system_access_manager.mojom
blob: d4315ee1b2e071ef49c497c475a7b58b7cad4c22 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

module blink.mojom;

import "mojo/public/mojom/base/string16.mojom";
import "third_party/blink/public/mojom/file_system_access/file_system_access_directory_handle.mojom";
import "third_party/blink/public/mojom/file_system_access/file_system_access_file_handle.mojom";
import "third_party/blink/public/mojom/file_system_access/file_system_access_error.mojom";
import "third_party/blink/public/mojom/file_system_access/file_system_access_transfer_token.mojom";
import "third_party/blink/public/mojom/file_system_access/file_system_access_data_transfer_token.mojom";

enum WellKnownDirectory {
  kDefault,
  kDirDesktop,
  kDirDocuments,
  kDirDownloads,
  kDirMusic,
  kDirPictures,
  kDirVideos,
};

// Struct to represent individual options for types of files that are accepted
// by calls to ChooseEntry. Each type has an optional description, and any
// number of mime types and/or extensions.
// Options with no extensions and no known mime types will be ignored.
struct ChooseFileSystemEntryAcceptsOption {
  mojo_base.mojom.String16 description;
  array<string> mime_types;
  array<string> extensions;
};

// If |include_accepts_all| is true, an "all files" option is included in the
// dialog displayed to the user. If no valid options are present in |accepts|
// |include_accepts_all| is treated as if it was true.
struct AcceptsTypesInfo {
  array<ChooseFileSystemEntryAcceptsOption> accepts;
  bool include_accepts_all;
};

struct OpenFilePickerOptions {
  AcceptsTypesInfo accepts_types_info;
  bool can_select_multiple_files;
};

struct SaveFilePickerOptions {
  AcceptsTypesInfo accepts_types_info;
  string suggested_name;
};

struct DirectoryPickerOptions {};

// Encapsulation of data from the FilePickerOptions idl spec:
// https://wicg.github.io/file-system-access/#dictdef-filepickeroptions.
union FilePickerOptions {
  OpenFilePickerOptions open_file_picker_options;
  SaveFilePickerOptions save_file_picker_options;
  DirectoryPickerOptions directory_picker_options;
};

// See the documentation for how the `starting_directory` fields interact:
// https://github.com/WICG/file-system-access/blob/main/SuggestedNameAndDir.md
// |starting_directory_id| allows for specification of the "purpose" of a file
// picker invocation. When an ID is specified, the picker will remember the
// picked directory. The next time the matching ID is specified, the picker
// will default to this directory. The ID cannot exceed 32 characters in
// length and may only contain alphanumeric characters, '-', and '_'.
// A maximum of 32 custom IDs is allowed per origin (LRU eviction).
// |well_known_starting_directory| opens the file picker at a well-known
// directory.
// |starting_directory_token| is resolved into a file or directory by the
// FileSystemAccessManager to be used as the starting directory for the file
// picker. If the token is a file, its parent directory is used.
// See the FileSystemAccessManager's ResolveDefaultDirectory() method for
// how these fields are prioritized.
struct CommonFilePickerOptions {
  string starting_directory_id;
  WellKnownDirectory well_known_starting_directory;
  pending_remote<FileSystemAccessTransferToken>? starting_directory_token;
};

// Interface provided by the browser to the renderer as main entry point to the
// File System Access API. The renderer can request this interface for a
// specific worker or document, so the browser process will always be able to
// tell what operations are being done by which document or worker.
interface FileSystemAccessManager {
  // Opens the sandboxed filesystem for the origin of the current document or worker.
  GetSandboxedFileSystem() =>
      (FileSystemAccessError result,
       pending_remote<FileSystemAccessDirectoryHandle>? directory);

  // Prompts the user to select a file from the local filesystem. Returns an
  // error code if something failed, or a list of the selected entries on
  // success.
  ChooseEntries(FilePickerOptions options,
                CommonFilePickerOptions common_options) =>
      (FileSystemAccessError result,
       array<FileSystemAccessEntry> entries);

  // Used to redeem tokens received by a postMessage() target. Clones
  // FileSystemFileHandles. Token redemption should never fail. The
  // postMessage() target should perform an origin check before
  // redeeming tokens. Origin check failures must dispatch a messageerror
  // event instead of cloning the objects. FileSystemAccessManager will also
  // validate the redeemed token, including the token's origin, before binding the
  // FileSystemHandle.
  GetFileHandleFromToken(
    pending_remote<FileSystemAccessTransferToken> token,
    pending_receiver<FileSystemAccessFileHandle> file_handle);

  // Same as GetFileHandleFromToken(), but for FileSystemDirectoryHandles.
  // See GetFileHandleFromToken() comment above for details.
  GetDirectoryHandleFromToken(
    pending_remote<FileSystemAccessTransferToken> token,
    pending_receiver<FileSystemAccessDirectoryHandle> directory_handle);

  // Used to redeem FileSystemAccessDataTransferToken that are passed to the
  // renderer from the browser during a drag-and-drop or clipboard operation.
  // Token redemption can fail if the id of the process trying to redeem the
  // token does not match the id assigned to the token at creation or if the
  // FileSystemAccessManager does not have record of the token.
  GetEntryFromDataTransferToken(
    pending_remote<FileSystemAccessDataTransferToken> token
  )  => (FileSystemAccessEntry entry);
};