Skip to content

Commit 19d13c9

Browse files
committed
tie access checks to FileSystemHandle
Fixes whatwg#101
1 parent b2644f0 commit 19d13c9

File tree

1 file changed

+92
-85
lines changed

1 file changed

+92
-85
lines changed

index.bs

+92-85
Original file line numberDiff line numberDiff line change
@@ -61,54 +61,6 @@ different storage mechanism with a different API for such files. The entry point
6161

6262
A <dfn export id="entry">file system entry</dfn> is either a [=file entry=] or a [=directory entry=].
6363

64-
Each [=/file system entry=] has an associated
65-
<dfn for="file system entry" id=entry-query-access>query access</dfn>
66-
algorithm, which takes "`read`" or "`readwrite`" <var ignore>mode</var> and
67-
returns a [=/file system access result=].
68-
Unless specified otherwise it returns a [=/file system access result=] with a
69-
[=file system access result/permission state=] of "{{PermissionState/denied}}"
70-
and with an [=file system access result/error name=] of the empty string.
71-
72-
Each [=/file system entry=] has an associated
73-
<dfn for="file system entry" id=entry-request-access>request access</dfn>
74-
algorithm, which takes "`read`" or "`readwrite`" <var ignore>mode</var> and
75-
returns a [=/file system access result=].
76-
Unless specified otherwise it returns a [=/file system access result=] with a
77-
[=file system access result/permission state=] of "{{PermissionState/denied}}"
78-
and with an [=file system access result/error name=] of the empty string.
79-
80-
A <dfn export>file system access result</dfn> is a [=struct=] encapsulating the
81-
result of [=file system entry/query access|querying=] or
82-
[=file system entry/request access|requesting=] access to the file system.
83-
It has the following [=struct/items=]:
84-
85-
: <dfn for="file system access result">permission state</dfn>
86-
:: A {{PermissionState}}
87-
: <dfn for="file system access result">error name</dfn>
88-
:: A [=string=] which must be the empty string if
89-
[=file system access result/permission state=] is
90-
"{{PermissionState/granted}}"; otherwise an
91-
[=DOMException/name=] listed in the [=`DOMException` names table=].
92-
It is expected that in most cases when
93-
[=file system access result/permission state=] is not
94-
"{{PermissionState/granted}}", this should be "{{NotAllowedError}}".
95-
96-
<p class=warning> Dependent specifications may consider this API a
97-
[=powerful feature=]. However, unlike other [=powerful features=] whose
98-
[=permission request algorithm=] may throw, [=/file system entry=]'s
99-
[=file system entry/query access=] and [=file system entry/request access=]
100-
algorithms must run [=in parallel=] on the [=file system queue=] and are
101-
therefore not allowed to throw. Instead, the caller is expected to
102-
[=queue a storage task=] to [=/reject=], as appropriate,
103-
should these algorithms return an [=file system access result/error name=]
104-
other than the empty string.
105-
106-
Note: Implementations that only implement this specification and not dependent
107-
specifications do not need to bother implementing [=/file system entry=]'s
108-
[=file system entry/query access=] and [=file system entry/request access=].
109-
110-
Issue(101): Make access check algorithms associated with a FileSystemHandle.
111-
11264
Each [=/file system entry=] has an associated <dfn for="file system entry" id=entry-name>name</dfn> (a [=string=]).
11365

11466
A <dfn>valid file name</dfn> is a [=string=] that is not an empty string, is not equal to "." or "..",
@@ -355,6 +307,52 @@ All other [=list/item=]s of a [=file system locator/path=] will be a
355307
Issue(109): Consider improving this situation by giving each locator a
356308
[=storage bucket=].
357309

310+
Each {{FileSystemHandle}} has an associated
311+
<dfn for=FileSystemHandle export>query access</dfn>
312+
algorithm, which takes "`read`" or "`readwrite`" <var ignore>mode</var> and
313+
returns a [=/file system access result=].
314+
Unless specified otherwise it returns a [=/file system access result=] with a
315+
[=file system access result/permission state=] of "{{PermissionState/denied}}"
316+
and with an [=file system access result/error name=] of the empty string.
317+
318+
Each {{FileSystemHandle}} has an associated
319+
<dfn for=FileSystemHandle export>request access</dfn>
320+
algorithm, which takes "`read`" or "`readwrite`" <var ignore>mode</var> and
321+
returns a [=/file system access result=].
322+
Unless specified otherwise it returns a [=/file system access result=] with a
323+
[=file system access result/permission state=] of "{{PermissionState/denied}}"
324+
and with an [=file system access result/error name=] of the empty string.
325+
326+
A <dfn export>file system access result</dfn> is a [=struct=] encapsulating the
327+
result of [=FileSystemHandle/query access|querying=] or
328+
[=FileSystemHandle/request access|requesting=] access to the file system.
329+
It has the following [=struct/items=]:
330+
331+
: <dfn for="file system access result">permission state</dfn>
332+
:: A {{PermissionState}}
333+
: <dfn for="file system access result">error name</dfn>
334+
:: A [=string=] which must be the empty string if
335+
[=file system access result/permission state=] is
336+
"{{PermissionState/granted}}"; otherwise an
337+
[=DOMException/name=] listed in the [=`DOMException` names table=].
338+
It is expected that in most cases when
339+
[=file system access result/permission state=] is not
340+
"{{PermissionState/granted}}", this should be "{{NotAllowedError}}".
341+
342+
<p class=warning> Dependent specifications may consider this API a
343+
[=powerful feature=]. However, unlike other [=powerful features=] whose
344+
[=permission request algorithm=] may throw, {{FileSystemHandle}}'s
345+
[=FileSystemHandle/query access=] and [=FileSystemHandle/request access=]
346+
algorithms must run [=in parallel=] on the [=file system queue=] and are
347+
therefore not allowed to throw. Instead, the caller is expected to
348+
[=queue a storage task=] to [=/reject=], as appropriate,
349+
should these algorithms return an [=file system access result/error name=]
350+
other than the empty string.
351+
352+
Note: Implementations that only implement this specification and not dependent
353+
specifications do not need to bother implementing {{FileSystemHandle}}'s
354+
[=FileSystemHandle/query access=] and [=FileSystemHandle/request access=].
355+
358356
<div algorithm="serialization steps">
359357
{{FileSystemHandle}} objects are [=serializable objects=].
360358

@@ -488,9 +486,9 @@ The <dfn method for=FileSystemFileHandle>getFile()</dfn> method steps are:
488486
1. Let |locator| be [=this=]'s [=FileSystemHandle/locator=].
489487
1. Let |global| be [=this=]'s [=relevant global object=].
490488
1. [=Enqueue the following steps=] to the [=file system queue=]:
489+
1. Let |accessResult| be the result of running |global|'s
490+
[=FileSystemHandle/query access=] given "`read`".
491491
1. Let |entry| be the result of [=locating an entry=] given |locator|.
492-
1. Let |accessResult| be the result of running |entry|'s
493-
[=file system entry/query access=] given "`read`".
494492

495493
1. [=Queue a storage task=] with |global| to run these steps:
496494
1. If |accessResult|'s [=file system access result/permission state=]
@@ -560,15 +558,15 @@ The <dfn method for=FileSystemFileHandle>createWritable(|options|)</dfn> method
560558
1. Let |realm| be [=this=]'s [=relevant Realm=].
561559
1. Let |global| be [=this=]'s [=relevant global object=].
562560
1. [=Enqueue the following steps=] to the [=file system queue=]:
563-
1. Let |entry| be the result of [=locating an entry=] given |locator|.
564-
1. Let |accessResult| be the result of running |entry|'s
565-
[=file system entry/request access=] given "`readwrite`".
561+
1. Let |accessResult| be the result of running |global|'s
562+
[=FileSystemHandle/request access=] given "`readwrite`".
566563
1. If |accessResult|'s [=file system access result/permission state=]
567564
is not "{{PermissionState/granted}}", [=queue a storage task=] with
568565
|global| to [=/reject=] |result| with a {{DOMException}} of
569566
|accessResult|'s [=file system access result/error name=] and
570567
abort these steps.
571568

569+
1. Let |entry| be the result of [=locating an entry=] given |locator|.
572570
1. If |entry| is `null`, [=queue a storage task=] with |global| to [=/reject=]
573571
|result| with a "{{NotFoundError}}" {{DOMException}} and abort these steps.
574572
1. [=Assert=]: |entry| is a [=file entry=].
@@ -581,7 +579,7 @@ The <dfn method for=FileSystemFileHandle>createWritable(|options|)</dfn> method
581579
"{{NoModificationAllowedError}}" {{DOMException}} and abort these steps.
582580

583581
1. Let |stream| be the result of <a>creating a new `FileSystemWritableFileStream`</a>
584-
for |entry| in |realm|.
582+
given |global| and |entry| in |realm|.
585583
1. If |options|'s {{FileSystemCreateWritableOptions/keepExistingData}} is true:
586584
1. Set |stream|'s [=[[buffer]]=] to a copy of |entry|'s [=file entry/binary data=].
587585
1. [=/Resolve=] |result| with |stream|.
@@ -623,9 +621,8 @@ The <dfn method for=FileSystemFileHandle>createSyncAccessHandle()</dfn> method s
623621
[=this=] [=FileSystemHandle/is in an origin private file system=];
624622
otherwise false.
625623
1. [=Enqueue the following steps=] to the [=file system queue=]:
626-
1. Let |entry| be the result of [=locating an entry=] given |locator|.
627-
1. Let |accessResult| be the result of running |entry|'s
628-
[=file system entry/request access=] given "`readwrite`".
624+
1. Let |accessResult| be the result of running |global|'s
625+
[=FileSystemHandle/request access=] given "`readwrite`".
629626
1. If |accessResult|'s [=file system access result/permission state=]
630627
is not "{{PermissionState/granted}}", [=queue a storage task=] with
631628
|global| to [=/reject=] |result| with a {{DOMException}} of
@@ -637,6 +634,7 @@ The <dfn method for=FileSystemFileHandle>createSyncAccessHandle()</dfn> method s
637634
[=/reject=] |result| with an "{{InvalidStateError}}" {{DOMException}} and
638635
abort these steps.
639636

637+
1. Let |entry| be the result of [=locating an entry=] given |locator|.
640638
1. If |entry| is `null`, [=queue a storage task=] with |global| to [=/reject=]
641639
|result| with a "{{NotFoundError}}" {{DOMException}} and abort these steps.
642640
1. [=Assert=]: |entry| is a [=file entry=].
@@ -754,17 +752,17 @@ and its async iterator |iterator|:
754752

755753
1. Let |promise| be [=a new promise=].
756754
1. [=Enqueue the following steps=] to the [=file system queue=]:
755+
1. Let |accessResult| be the result of running |handle|'s
756+
[=FileSystemHandle/query access=] given "`read`".
757757
1. Let |directory| be the result of [=locating an entry=]
758758
given |handle|'s [=FileSystemHandle/locator=].
759-
1. Let |accessResult| be the result of running |directory|'s
760-
[=file system entry/query access=] given "`read`".
761759

762760
1. [=Queue a storage task=] with |handle|'s [=relevant global object=] to
763761
run these steps:
764762
1. If |accessResult|'s [=file system access result/permission state=]
765763
is not "{{PermissionState/granted}}", [=/reject=] |promise| with a
766764
{{DOMException}} of |accessResult|'s
767-
[=file system access result/error name=] and abort these steps.:
765+
[=file system access result/error name=] and abort these steps.
768766

769767
1. If |directory| is `null`, [=/reject=] |result| with a
770768
"{{NotFoundError}}" {{DOMException}} and abort these steps.
@@ -838,13 +836,14 @@ The <dfn method for=FileSystemDirectoryHandle>getFileHandle(|name|, |options|)</
838836
|global| to [=/reject=] |result| with a {{TypeError}} and
839837
abort these steps.
840838

841-
1. Let |entry| be the result of [=locating an entry=] given |locator|.
842839
1. If |options|.{{FileSystemGetFileOptions/create}} is true:
843-
1. Let |accessResult| be the result of running |entry|'s
844-
[=file system entry/request access=] given "`readwrite`".
840+
1. Let |accessResult| be the result of running |global|'s
841+
[=FileSystemHandle/request access=] given "`readwrite`".
845842
1. Otherwise:
846-
1. Let |accessResult| be the result of running |entry|'s
847-
[=file system entry/query access=] given "`read`".
843+
1. Let |accessResult| be the result of running |global|'s
844+
[=FileSystemHandle/query access=] given "`read`".
845+
846+
1. Let |entry| be the result of [=locating an entry=] given |locator|.
848847

849848
1. [=Queue a storage task=] with |global| to run these steps:
850849
1. If |accessResult|'s [=file system access result/permission state=]
@@ -920,13 +919,14 @@ The <dfn method for=FileSystemDirectoryHandle>getDirectoryHandle(|name|, |option
920919
|global| to [=/reject=] |result| with a {{TypeError}} and
921920
abort these steps.
922921

923-
1. Let |entry| be the result of [=locating an entry=] given |locator|.
924922
1. If |options|.{{FileSystemGetDirectoryOptions/create}} is true:
925-
1. Let |accessResult| be the result of running |entry|'s
926-
[=file system entry/request access=] given "`readwrite`".
923+
1. Let |accessResult| be the result of running |global|'s
924+
[=FileSystemHandle/request access=] given "`readwrite`".
927925
1. Otherwise:
928-
1. Let |accessResult| be the result of running |entry|'s
929-
[=file system entry/query access=] given "`read`".
926+
1. Let |accessResult| be the result of running |global|'s
927+
[=FileSystemHandle/query access=] given "`read`".
928+
929+
1. Let |entry| be the result of [=locating an entry=] given |locator|.
930930

931931
1. [=Queue a storage task=] with |global| to run these steps:
932932
1. If |accessResult|'s [=file system access result/permission state=]
@@ -997,9 +997,9 @@ The <dfn method for=FileSystemDirectoryHandle>removeEntry(|name|, |options|)</df
997997
|global| to [=/reject=] |result| with a {{TypeError}} and
998998
abort these steps.
999999

1000+
1. Let |accessResult| be the result of running |global|'s
1001+
[=FileSystemHandle/request access=] given "`readwrite`".
10001002
1. Let |entry| be the result of [=locating an entry=] given |locator|.
1001-
1. Let |accessResult| be the result of running |entry|'s
1002-
[=file system entry/request access=] given "`readwrite`".
10031003

10041004
1. [=Queue a storage task=] with |global| to run these steps:
10051005
1. If |accessResult|'s [=file system access result/permission state=]
@@ -1147,19 +1147,24 @@ Similarly, when piping a {{ReadableStream}} into a {{FileSystemWritableFileStrea
11471147
<div algorithm>
11481148
To
11491149
<dfn local-lt="creating a new FileSystemWritableFileStream">create a new `FileSystemWritableFileStream`</dfn>
1150-
given a [=file entry=] |file| in a [=/Realm=] |realm|:
1150+
given a {{FileSystemFileHandle}} |fileHandle| and a [=file entry=] |fileEntry|
1151+
in a [=/Realm=] |realm|:
11511152

11521153
1. Let |stream| be a [=new=] {{FileSystemWritableFileStream}} in |realm|.
1153-
1. Set |stream|'s [=FileSystemWritableFileStream/[[file]]=] to |file|.
1154+
1. Set |stream|'s [=FileSystemWritableFileStream/[[file]]=] to |fileEntry|.
11541155
1. Let |writeAlgorithm| be an algorithm which takes a |chunk| argument
1155-
and returns the result of running the [=write a chunk=] algorithm with |stream| and |chunk|.
1156+
and returns the result of running the [=write a chunk=] algorithm with
1157+
|fileHandle|, |stream|, and |chunk|.
11561158
1. Let |closeAlgorithm| be these steps:
11571159
1. Let |closeResult| be [=a new promise=].
11581160
1. [=Enqueue the following steps=] to the [=file system queue=]:
1159-
1. Let |accessResult| be the result of running |file|'s
1160-
[=file system entry/query access=] given "`readwrite`".
1161+
1. [=Assert=]: [=locating an entry=] given |fileHandle|'s
1162+
[=FileSystemHandle/locator=] returns a [=file entry=] that is
1163+
[=the same entry as=] |fileEntry|.
1164+
1. Let |accessResult| be the result of running |fileHandle|'s
1165+
[=FileSystemHandle/query access=] given "`readwrite`".
11611166

1162-
1. [=Queue a storage task=] with |file|'s [=relevant global object=]
1167+
1. [=Queue a storage task=] with |fileEntry|'s [=relevant global object=]
11631168
to run these steps:
11641169
1. If |accessResult|'s [=file system access result/permission state=]
11651170
is not "{{PermissionState/granted}}", [=/reject=] |closeResult|
@@ -1179,8 +1184,9 @@ given a [=file entry=] |file| in a [=/Realm=] |realm|:
11791184
1. [=Enqueue the following steps=] to the [=file system queue=]:
11801185
1. [=file entry/lock/release|Release the lock=] on
11811186
|stream|'s [=FileSystemWritableFileStream/[[file]]=].
1182-
1. [=Queue a storage task=] with |file|'s [=relevant global object=]
1183-
to [=/resolve=] |closeResult| with `undefined`.
1187+
1. [=Queue a storage task=] with
1188+
|fileEntry|'s [=relevant global object=] to
1189+
[=/resolve=] |closeResult| with `undefined`.
11841190

11851191
1. Return |closeResult|.
11861192
1. Let |abortAlgorithm| be these steps:
@@ -1200,17 +1206,18 @@ given a [=file entry=] |file| in a [=/Realm=] |realm|:
12001206
</div>
12011207

12021208
<div algorithm>
1203-
The <dfn>write a chunk</dfn> algorithm,
1204-
given a {{FileSystemWritableFileStream}} |stream| and |chunk|,
1209+
The <dfn>write a chunk</dfn> algorithm, given
1210+
a {{FileSystemFileHandle}} |fileHandle|,
1211+
a {{FileSystemWritableFileStream}} |stream|,
1212+
and a |chunk|,
12051213
runs these steps:
12061214

12071215
1. Let |input| be the result of [=converted to an IDL value|converting=] |chunk| to a {{FileSystemWriteChunkType}}.
12081216
If this throws an exception, then return [=a promise rejected with=] that exception.
12091217
1. Let |p| be [=a new promise=].
12101218
1. [=Enqueue the following steps=] to the [=file system queue=]:
1211-
1. Let |accessResult| be the result of running
1212-
|stream|'s [=FileSystemWritableFileStream/[[file]]=]'s
1213-
[=file system entry/query access=] given "`readwrite`".
1219+
1. Let |accessResult| be the result of running |fileHandle|'s
1220+
[=FileSystemHandle/query access=] given "`readwrite`".
12141221

12151222
1. [=Queue a storage task=] with |stream|'s [=relevant global object=] to
12161223
run these steps:

0 commit comments

Comments
 (0)