@@ -2293,7 +2293,8 @@ BrowserCommand = (
2293
2293
browser.GetClientWindows //
2294
2294
browser.GetUserContexts //
2295
2295
browser.RemoveUserContext //
2296
- browser.SetClientWindowState
2296
+ browser.SetClientWindowState //
2297
+ browser.SetDownloadBehavior
2297
2298
)
2298
2299
</pre>
2299
2300
@@ -2949,6 +2950,116 @@ those after the window has reached its new state.
2949
2950
2950
2951
</div>
2951
2952
2953
+ #### The browser.setDownloadBehavior Command #### {#command-browser-setDownloadBehavior}
2954
+
2955
+ A <dfn>download behavior struct</dfn> is a [=struct=] with:
2956
+ * [=struct/item=] named <dfn id="download-behavior-struct-allowed" for="download-behavior-struct">allowed</dfn> which is a boolean;
2957
+ * [=struct/item=] named <dfn id="download-behavior-struct-destination-folder" for="download-behavior-struct">destinationFolder</dfn> which is a string or null.
2958
+
2959
+ A [=remote end=] has a <dfn>download behavior</dfn> which is a [=struct=] with an [=struct/item=]
2960
+ named <dfn for="download behavior">default download behavior</dfn> , which is a
2961
+ [=download behavior struct=] or null, and an [=struct/item=] named <dfn
2962
+ for="download behavior"> user context download behavior</dfn> , which is a weak map between
2963
+ [=user contexts=] and [=download behavior struct=] .
2964
+
2965
+ <dl>
2966
+ <dt> Command Type</dt>
2967
+ <dd>
2968
+ <pre class="cddl" data-cddl-module="remote-cddl">
2969
+ browser.SetDownloadBehavior = (
2970
+ method: "browser.setDownloadBehavior",
2971
+ params: browser.SetDownloadBehaviorParameters
2972
+ )
2973
+
2974
+ browser.SetDownloadBehaviorParameters = {
2975
+ downloadBehavior: browser.DownloadBehavior / null,
2976
+ ? userContexts: [+browser.UserContext]
2977
+ }
2978
+
2979
+ browser.DownloadBehavior = {
2980
+ (
2981
+ browser.DownloadBehaviorAllowed //
2982
+ browser.DownloadBehaviorDenied
2983
+ )
2984
+ }
2985
+
2986
+ browser.DownloadBehaviorAllowed = (
2987
+ type: "allowed",
2988
+ ? destinationFolder: text
2989
+ )
2990
+
2991
+ browser.DownloadBehaviorDenied = (
2992
+ type: "denied"
2993
+ )
2994
+ </pre>
2995
+ </dd>
2996
+ <dt> Return Type</dt>
2997
+ <dd>
2998
+ <code>
2999
+ EmptyResult
3000
+ </code>
3001
+ </dd>
3002
+ </dl>
3003
+
3004
+ <div algorithm>
3005
+ To <dfn export>get download behavior</dfn> given |navigable|:
3006
+
3007
+ 1. Let |user context| be |navigable|'s [=associated user context=] .
3008
+
3009
+ 1. If [=download behavior=] 's [=download behavior/user context download behavior=] [=map/contains=]
3010
+ |user context|, return [=download behavior=] 's
3011
+ [=download behavior/user context download behavior=] [|user context|] .
3012
+
3013
+ 1. Return [=download behavior=] 's [=download behavior/default download behavior=] .
3014
+
3015
+ </div>
3016
+
3017
+ <div algorithm="remote end steps for browser.setDownloadBehavior">
3018
+
3019
+ The [=remote end steps=] with <var ignore> session</var> and |command parameters| are:
3020
+
3021
+ 1. If |command parameters|["<code>downloadBehavior</code>"] is null, let
3022
+ |download behavior| be null.
3023
+
3024
+ 1. Otherwise:
3025
+
3026
+ 1. If |command parameters|["<code>downloadBehavior</code>"]["<code>type</code>"]
3027
+ is "<code> allowed</code> ", let |allowed| be true, otherwise let |allowed| be
3028
+ false.
3029
+
3030
+ 1. If |command parameters|["<code>downloadBehavior</code>"] [=map/contains=]
3031
+ "<code> destinationFolder</code> ", let |destinationFolder| be
3032
+ |command parameters|["<code>downloadBehavior</code>"]["<code>destinationFolder</code>"] ,
3033
+ otherwise let |destinationFolder| be null.
3034
+
3035
+ 1. Let |download behavior| be a [=download behavior struct=] with
3036
+ [=download-behavior-struct/allowed=] set to |allowed| and
3037
+ [=download-behavior-struct/destinationFolder=] set to |destinationFolder|.
3038
+
3039
+ 1. If the implementation does not support required |download behavior|, then return
3040
+ [=error=] with [=error code=] [=unsupported operation=] .
3041
+
3042
+ 1. If the <code> userContexts</code> field of |command parameters| is present:
3043
+
3044
+ 1. Let |user contexts| be the result of [=trying=] to [=get valid user contexts=]
3045
+ with |command parameters|["<code>userContexts</code>"] .
3046
+
3047
+ 1. For each |user context| of |user contexts|:
3048
+
3049
+ 1. If |download behavior| is null, [=map/remove=] |user context| from [=download behavior=] 's
3050
+ [=download behavior/user context download behavior=] .
3051
+
3052
+ 1. Otherwise, [=map/set=] [=download behavior=] 's
3053
+ [=download behavior/user context download behavior=] [|user context|] to
3054
+ |download behavior|.
3055
+
3056
+ 1. Otherwise, set [=download behavior=] 's [=download behavior/default download behavior=] to
3057
+ |download behavior|.
3058
+
3059
+ 1. Return [=success=] with data null.
3060
+
3061
+ </div>
3062
+
2952
3063
## The browsingContext Module ## {#module-browsingContext}
2953
3064
2954
3065
The <dfn export for=modules>browsingContext</dfn> module contains commands and
@@ -5384,11 +5495,53 @@ complete</dfn> steps given |navigable| and |navigation status|:
5384
5495
</dd>
5385
5496
</dl>
5386
5497
5498
+ <div algorithm>
5499
+ The [=remote end event trigger=] is the
5500
+ <dfn export>WebDriver BiDi download will begin</dfn> steps given |navigable| and
5501
+ |navigation status|:
5502
+
5503
+ 1. Let |navigation info| be the result of [=get the navigation info=] given
5504
+ |navigable| and |navigation status|.
5505
+
5506
+ 1. Let |params| be a [=/map=] matching the
5507
+ <code> browsingContext.DownloadWillBeginParams</code> production, with the
5508
+ <code> context</code> field set to |navigation info|["<code>context</code>"] , the
5509
+ <code> navigation</code> field set to |navigation info|["<code>navigation</code>"] ,
5510
+ the <code> timestamp</code> field set to
5511
+ |navigation info|["<code>timestamp</code>"] , the <code> url</code> field set to
5512
+ |navigation info|["<code>url</code>"] and <code> suggestedFilename</code> field set
5513
+ to |navigation status|'s <code> suggestedFilename</code> .
5514
+
5515
+ 1. Let |body| be a [=/map=] matching the
5516
+ <code> browsingContext.DownloadWillBegin</code> production, with the
5517
+ <code> params</code> field set to |params|.
5518
+
5519
+ 1. Let |navigation id| be |navigation status|'s id.
5520
+
5521
+ 1. Let |related navigables| be a [=/set=] containing |navigable|.
5522
+
5523
+ 1. [=Resume=] with "<code> download started</code> ", |navigation id|, and
5524
+ |navigation status|.
5525
+
5526
+ 1. For each |session| in the [=set of sessions for which an event is enabled=]
5527
+ given "<code> browsingContext.downloadWillBegin</code> " and |related navigables|:
5528
+
5529
+ 1. [=Emit an event=] with |session| and |body|.
5530
+
5531
+ 1. Let |download behavior| be [=get download behavior=] with |navigable|.
5532
+
5533
+ 1. Return |download behavior|.
5534
+
5535
+ </div>
5536
+
5387
5537
<div algorithm>
5388
5538
The [=remote end event trigger=] is the <dfn export>WebDriver BiDi download
5389
5539
started</dfn> steps given |navigable| and |navigation status|:
5390
5540
5391
- 1. Let |navigation info| be the result of [=get the navigation info=] given |navigable| and
5541
+ Issue: Remove after HTML spec switched to [=WebDriver BiDi download will begin=]
5542
+ (https://github.com/whatwg/html/pull/11474).
5543
+
5544
+ 1. Let |navigation info| be the result of [=get the navigation info=] given |navigable| and
5392
5545
|navigation status|.
5393
5546
5394
5547
1. Let |params| be a [=/map=] matching the <code> browsingContext.DownloadWillBeginParams</code>
@@ -5399,20 +5552,20 @@ started</dfn> steps given |navigable| and |navigation status|:
5399
5552
<code> suggestedFilename</code> field set to |navigation status|'s
5400
5553
<code> suggestedFilename</code> .
5401
5554
5402
- 1. Let |body| be a [=/map=] matching the
5403
- <code> browsingContext.DownloadWillBegin</code> production, with the
5404
- <code> params</code> field set to |params|.
5555
+ 1. Let |body| be a [=/map=] matching the
5556
+ <code> browsingContext.DownloadWillBegin</code> production, with the
5557
+ <code> params</code> field set to |params|.
5405
5558
5406
- 1. Let |navigation id| be |navigation status|'s id.
5559
+ 1. Let |navigation id| be |navigation status|'s id.
5407
5560
5408
- 1. Let |related navigables| be a [=/set=] containing |navigable|.
5561
+ 1. Let |related navigables| be a [=/set=] containing |navigable|.
5409
5562
5410
- 1. [=Resume=] with "<code> download started</code> ", |navigation id|, and |navigation status|.
5563
+ 1. [=Resume=] with "<code> download started</code> ", |navigation id|, and |navigation status|.
5411
5564
5412
- 1. For each |session| in the [=set of sessions for which an event is enabled=]
5413
- given "<code> browsingContext.downloadWillBegin</code> " and |related navigables|:
5565
+ 1. For each |session| in the [=set of sessions for which an event is enabled=]
5566
+ given "<code> browsingContext.downloadWillBegin</code> " and |related navigables|:
5414
5567
5415
- 1. [=Emit an event=] with |session| and |body|.
5568
+ 1. [=Emit an event=] with |session| and |body|.
5416
5569
5417
5570
</div>
5418
5571
0 commit comments