Skip to content

Commit 345af0a

Browse files
move everything to a filesystem namespace
1 parent a6a04c8 commit 345af0a

File tree

2 files changed

+29
-26
lines changed

2 files changed

+29
-26
lines changed

EXPLAINER.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ this new API might integrate with `<input type=file>`.
9494

9595
```javascript
9696
// Show a file picker to open a file.
97-
const [file_ref] = await self.showOpenFilePicker({
97+
const [file_ref] = await FileSystem.showOpenFilePicker({
9898
multiple: false,
9999
types: [{description: 'Images', accept: {'image/*': ['jpg', 'gif', 'png']}}],
100100
suggestedStartLocation: 'pictures-library'
@@ -152,7 +152,7 @@ request.onerror = function(e) { console.log(e); }
152152
request.onsuccess = function(e) { db = e.target.result; }
153153

154154
// Show file picker UI.
155-
const [file_ref] = await self.showOpenFilePicker();
155+
const [file_ref] = await FileSystem.showOpenFilePicker();
156156

157157
if (file_ref) {
158158
// Save the reference to open the file later.
@@ -215,7 +215,7 @@ navigator.serviceWorker.addEventListener('message', e => {
215215
Also possible to get access to an entire directory.
216216

217217
```javascript
218-
const dir_ref = await self.showDirectoryPicker();
218+
const dir_ref = await FileSystem.showDirectoryPicker();
219219
if (!dir_ref) {
220220
// User cancelled, or otherwise failed to open a directory.
221221
return;
@@ -256,11 +256,11 @@ file or saving to a new file.
256256

257257
```javascript
258258
// Assume we at some point got a valid directory handle.
259-
const dir_ref = await self.showDirectoryPicker();
259+
const dir_ref = await FileSystem.showDirectoryPicker();
260260
if (!dir_ref) return;
261261

262262
// Now get a file reference by showing another file picker:
263-
const file_ref = await self.showOpenFilePicker();
263+
const file_ref = await FileSystem.showOpenFilePicker();
264264
if (!file_ref) {
265265
// User cancelled, or otherwise failed to open a file.
266266
return;

index.bs

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ cases where a website wants to save data to disk before a user has picked a
7676
location to save to, without forcing the website to use a completely different
7777
storage mechanism with a different API for such files. It also makes it easier
7878
to write automated tests for code using this API. The entry point for this is the
79-
{{getOriginPrivateDirectory()}} method. This is similar to the temporary file
79+
{{getPrivateDirectory()}} method. This is similar to the temporary file
8080
system as defined in earlier drafts of [[file-system-api|File API: Directories and System]].
8181

8282
# Files and Directories # {#files-and-directories}
@@ -109,7 +109,7 @@ An [=/entry=]'s [=entry/parent=] is null if no such directory entry exists.
109109
Note: Two different [=/entries=] can represent the same file or directory on disk, in which
110110
case it is possible for both entries to have a different parent, or for one entry to have a
111111
parent while the other entry does not have a parent. Typically an entry does not have a parent
112-
if it was returned by {{getOriginPrivateDirectory()}} or one of the [=native file system handle factories=],
112+
if it was returned by {{getPrivateDirectory()}} or one of the [=native file system handle factories=],
113113
and an entry will have a parent in all other cases.
114114

115115
[=/Entries=] can (but don't have to) be backed by files on the systems native file system,
@@ -809,7 +809,7 @@ const dir_ref = current_project_dir;
809809
if (!dir_ref) return;
810810

811811
// Now get a file reference by showing a file picker:
812-
const file_ref = await self.chooseFileSystemEntries({type: 'openFile'});
812+
const file_ref = await FileSystem.showOpenFilePicker();
813813
if (!file_ref) {
814814
// User cancelled, or otherwise failed to open a file.
815815
return;
@@ -1136,10 +1136,13 @@ dictionary SaveFilePickerOptions : FilePickerOptions {
11361136
dictionary DirectoryPickerOptions {
11371137
};
11381138

1139-
[SecureContext]
1140-
partial interface Window {
1139+
[SecureContext, Exposed=(Window,Worker)]
1140+
namespace FileSystem {
1141+
[Exposed=Window]
11411142
Promise<sequence<FileSystemFileHandle>> showOpenFilePicker(optional OpenFilePickerOptions options = {});
1143+
[Exposed=Window]
11421144
Promise<FileSystemFileHandle> showSaveFilePicker(optional SaveFilePickerOptions options = {});
1145+
[Exposed=Window]
11431146
Promise<FileSystemDirectoryHandle> showDirectoryPicker(optional DirectoryPickerOptions options = {});
11441147
};
11451148
</xmp>
@@ -1183,12 +1186,12 @@ To verify that an |environment| <dfn>is allowed to show a file picker</dfn>, run
11831186
## The {{showOpenFilePicker()}} method ## {#api-showopenfilepicker}
11841187

11851188
<div class="note domintro">
1186-
: [ |handle| ] = await window . {{showOpenFilePicker()}}
1187-
: [ |handle| ] = await window . {{showOpenFilePicker()|showOpenFilePicker}}({ {{OpenFilePickerOptions/multiple}}: false })
1189+
: [ |handle| ] = await {{FileSystem}} . {{showOpenFilePicker()}}
1190+
: [ |handle| ] = await {{FileSystem}} . {{showOpenFilePicker()|showOpenFilePicker}}({ {{OpenFilePickerOptions/multiple}}: false })
11881191
:: Shows a file picker that lets a user select a single existing file, returning a handle for
11891192
the selected file.
11901193

1191-
: handles = await window . {{showOpenFilePicker()|showOpenFilePicker}}({ {{OpenFilePickerOptions/multiple}}: true })
1194+
: handles = await {{FileSystem}} . {{showOpenFilePicker()|showOpenFilePicker}}({ {{OpenFilePickerOptions/multiple}}: true })
11921195
:: Shows a file picker that lets a user select multiple existing files, returning handles for
11931196
the selected files.
11941197

@@ -1197,7 +1200,7 @@ To verify that an |environment| <dfn>is allowed to show a file picker</dfn>, run
11971200
</div>
11981201

11991202
<div algorithm>
1200-
The <dfn method for=Window>showOpenFilePicker(|options|)</dfn> method, when invoked, must run
1203+
The <dfn method for=FileSystem>showOpenFilePicker(|options|)</dfn> method, when invoked, must run
12011204
these steps:
12021205

12031206
1. Let |accepts options| be the result of [=process accept types|processing accept types=] given |options|.
@@ -1246,10 +1249,10 @@ these steps:
12461249

12471250
</div>
12481251

1249-
## The {{Window/showSaveFilePicker()}} method ## {#api-showsavefilepicker}
1252+
## The {{showSaveFilePicker()}} method ## {#api-showsavefilepicker}
12501253

12511254
<div class="note domintro">
1252-
: |handle| = await window . {{showSaveFilePicker()|showSaveFilePicker}}( |options| )
1255+
: |handle| = await {{FileSystem}} . {{showSaveFilePicker()|showSaveFilePicker}}( |options| )
12531256
:: Shows a file picker that lets a user select a single file, returning a handle for
12541257
the selected file. The selected file does not have to exist already. If the selected
12551258
file does not exist a new empty file is created before this method returns, otherwise
@@ -1260,7 +1263,7 @@ these steps:
12601263
</div>
12611264

12621265
<div algorithm>
1263-
The <dfn method for=Window>showSaveFilePicker(|options|)</dfn> method, when invoked, must run
1266+
The <dfn method for=FileSystem>showSaveFilePicker(|options|)</dfn> method, when invoked, must run
12641267
these steps:
12651268

12661269
1. Let |accepts options| be the result of [=process accept types|processing accept types=] given |options|.
@@ -1394,7 +1397,7 @@ run these steps:
13941397
1. If |parsedType|'s [=MIME type/type=] is "*", return `true`.
13951398
1. If |parsedType|'s [=MIME type/type=] is |type|'s [=MIME type/type=], return `true`.
13961399
1. |parsedType|'s [=MIME type/essence=] is |type|'s [=MIME type/essence=], return `true`.
1397-
1. If |extensions| is a string, set |extensions| to a [=list=] with a single
1400+
1. If |extensions| is a string, set |extensions| to a [=/list=] with a single
13981401
element equal to |extensions|.
13991402
1. [=list/For each=] |extension| of |extensions|:
14001403
1. If |filename| ends with "." followed by |extension|, return `true`.
@@ -1417,16 +1420,16 @@ run these steps:
14171420

14181421
</div>
14191422

1420-
## The {{Window/showDirectoryPicker()}} method ## {#api-showdirectorypicker}
1423+
## The {{showDirectoryPicker()}} method ## {#api-showdirectorypicker}
14211424

14221425
<div class="note domintro">
1423-
: |handle| = await window . {{Window/showDirectoryPicker()}}
1426+
: |handle| = await {{FileSystem}} . {{showDirectoryPicker()}}
14241427
:: Shows a directory picker that lets the user select a single directory, returning a handle for
14251428
the selected directory.
14261429
</div>
14271430

14281431
<div algorithm>
1429-
The <dfn method for=Window>showDirectoryPicker(<var ignore>options</var>)</dfn> method, when invoked, must run
1432+
The <dfn method for=FileSystem>showDirectoryPicker(<var ignore>options</var>)</dfn> method, when invoked, must run
14301433
these steps:
14311434

14321435
1. Let |environment| be <b>[=this=]</b>'s [=relevant settings object=].
@@ -1564,22 +1567,22 @@ user accessible. Similarly there is no expectation that files or directories wit
15641567
matching the names of children of the [=origin private file system=] exist.
15651568

15661569
<xmp class=idl>
1567-
[SecureContext]
1568-
partial interface mixin WindowOrWorkerGlobalScope {
1569-
Promise<FileSystemDirectoryHandle> getOriginPrivateDirectory();
1570+
[SecureContext, Exposed=(Window,Worker)]
1571+
partial namespace FileSystem {
1572+
Promise<FileSystemDirectoryHandle> getPrivateDirectory();
15701573
};
15711574
</xmp>
15721575

15731576
Advisement: In Chrome this functionality was previously exposed as `FileSystemDirectoryHandle.getSystemDirectory({type: "sandbox"})`.
15741577
This new method is available as of Chrome 85.
15751578

15761579
<div class="note domintro">
1577-
: |directoryHandle| = await window . {{getOriginPrivateDirectory()}}
1580+
: |directoryHandle| = await {{FileSystem}} . {{getPrivateDirectory()}}
15781581
:: Returns the root directory of the origin private file system.
15791582
</div>
15801583

15811584
<div algorithm>
1582-
The <dfn method for=WindowOrWorkerGlobalScope>getOriginPrivateDirectory()</dfn> method, when
1585+
The <dfn method for=FileSystem>getPrivateDirectory()</dfn> method, when
15831586
invoked, must run these steps:
15841587

15851588
1. Let |environment| be the [=current settings object=].

0 commit comments

Comments
 (0)