Skip to content

Commit 55adba6

Browse files
OrKoNmathiasbynensjugglinmikesadym-chromiumjrandolf-2
authored
Support user contexts (#570)
* WIP partitions * Update index.bs Co-authored-by: Mathias Bynens <[email protected]> * Rename to UserContext; add a note about User Agents * define getUserContexts * Add jgraham's suggestions * draft browser.closeUserContext * draft create user context * add types and commands * trying to improve the definitions * fix the outline * Update index.bs Co-authored-by: jugglinmike <[email protected]> * update steps * Update index.bs * Update index.bs * Update index.bs * clarify how default contexts work * fix types # Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. # # Date: Mon Nov 27 17:15:45 2023 +0100 # # On branch orkon/partitions # Your branch is up to date with 'origin/orkon/partitions'. # # Changes to be committed: # modified: index.bs # * remove null from userContext Co-authored-by: Maksim Sadym <[email protected]> * update undefined to null Co-authored-by: Maksim Sadym <[email protected]> * update undefined to null Co-authored-by: Maksim Sadym <[email protected]> * Update index.bs * Use `removeUserContext` * Address comments * Update index.bs * Update wording. * review comments * replace user agent with remote end * fix cddl * fix phrasing * Remove GetUserContexts * no such context error * Use reference context's user context * Prevent removal of the default context * no such context error * remove duplicate error * fix formatting * Update the definition of user contexts This gives us an explicit set of top-level user contexts to work with, and makes the association between nagigables and user contexts clearer. * Add a browser.getUserContext command This returns a list of all user contexts. At the moment it doesn't contain any information about the browsing contexts in each user context (so you'd have to cross-reference with browsingContext.getTree). * Fix UserContextInfo * Apply suggestions to browsingContext creation * Reuse UserContextInfo * Extract the get user context algorithm * Fix userContextId * Add missing +BrowserResult --------- Co-authored-by: Mathias Bynens <[email protected]> Co-authored-by: jugglinmike <[email protected]> Co-authored-by: Maksim Sadym <[email protected]> Co-authored-by: Randolf Jung <[email protected]> Co-authored-by: James Graham <[email protected]>
1 parent 6462133 commit 55adba6

File tree

1 file changed

+273
-13
lines changed

1 file changed

+273
-13
lines changed

index.bs

Lines changed: 273 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,9 @@ with the following additional codes:
598598
<dt><dfn>no such storage partition</dfn>
599599
<dd>Tried to access data in a non-existent storage partition.
600600

601+
<dt><dfn>no such user context</dfn>
602+
<dd>Tried to reference an unknown [=user context=].
603+
601604
<dt><dfn>unable to close browser</dfn>
602605
<dd>Tried to close the browser, but failed to do so.
603606

@@ -625,6 +628,7 @@ ErrorCode = "invalid argument" /
625628
"no such request" /
626629
"no such script" /
627630
"no such storage partition" /
631+
"no such user context" /
628632
"session not created" /
629633
"unable to capture screen" /
630634
"unable to close browser" /
@@ -1291,6 +1295,77 @@ access to that data in a {{Window}} global.
12911295

12921296
Issue: Define how this works.
12931297

1298+
# User Contexts # {#user-contexts}
1299+
1300+
A <dfn>user context</dfn> represents a collection of zero or more
1301+
[=/top-level traversables=] within a [=remote end=]. Each [=user context=] has
1302+
an associated [=storage partition=], so that [=remote end=] data is not shared
1303+
between different [=user contexts=].
1304+
1305+
Issue: Unclear that this is the best way to formally define the concept of a
1306+
user context or the interaction with storage.
1307+
1308+
Note: The infra spec uses the term "user agent" to refer to the same concept as
1309+
[=user context|user contexts=]. However, this is not compatible with usage of
1310+
the term "user agent" to mean the entire web client with multiple [=user
1311+
context|user contexts=]. Although this difference is not visible to web content,
1312+
it is observed via WebDriver, so we avoid using this terminology.
1313+
1314+
A [=user context=] has a <dfn>user context id</dfn>, which is a unique string
1315+
set upon the user context creation.
1316+
1317+
A [=navigable=] has an <dfn>associated user context</dfn>, which is a
1318+
[=user context=].
1319+
1320+
When a new [=/top-level traversable=] is created its [=associated user context=]
1321+
is set to a user context in the [=set of user contexts=].
1322+
1323+
Note: In some cases the user context is set by specification when the
1324+
[=/top-level traversable=] is created, however in cases where no such
1325+
requirements are present, the [=associated user context=] for a [=/top-level
1326+
traversable=] is implemenation-defined.
1327+
1328+
Issue: Should we specify that [=/top-level traversables=] with a non-null
1329+
opener have the same [=associated user context=] as their opener?
1330+
Need to check if this is something existing implementations enforce.
1331+
1332+
A [=child navigable=]'s [=associated user context=] is it's
1333+
[=navigable/parent=]'s [=associated user context=].
1334+
1335+
A [=user context=] which isn't the [=associated user context=] for any
1336+
[=/top-level traversable=] is an <dfn>empty user context</dfn>.
1337+
1338+
The <dfn>default user context</dfn> is a [=user context=] with [=user context
1339+
id=] <code>"default"</code>.
1340+
1341+
An implementation has a <dfn>set of user contexts</dfn>, which is a [=/set=] of
1342+
[=user contexts=]. Initially this contains the [=default user context=].
1343+
1344+
Implementations may [=set/append=] new [=user contexts=] to the [=set of user
1345+
contexts=] at any time, for example in response to user actions.
1346+
1347+
Note: "At any time" here includes during implementation startup, so a given
1348+
implementation might always have multiple entries in the [=set of user contexts=].
1349+
1350+
Implementations may [=set/remove=] any [=empty user context=], with exception of
1351+
the [=default user context=], from the [=set of user contexts=] at any
1352+
time. However they are not required to remove such [=user contexts=]. [=User
1353+
contexts=] that are not [=empty user contexts=] must not be removed from the
1354+
[=set of user contexts=].
1355+
1356+
<div algorithm>
1357+
To <dfn>get user context</dfn> given |user context id|:
1358+
1359+
1. For each |user context| in the [=set of user contexts=]:
1360+
1361+
1. If |user context|'s [=user context id=] equals |user context id|:
1362+
1363+
1. Return |user context|.
1364+
1365+
1. Return null.
1366+
1367+
</div>
1368+
12941369
# Modules # {#modules}
12951370

12961371
## The session Module ## {#module-session}
@@ -1865,16 +1940,44 @@ managing the remote end browser process.
18651940

18661941
<pre class="cddl remote-cddl">
18671942
BrowserCommand = (
1868-
browser.Close
1943+
browser.Close //
1944+
browser.CreateUserContext //
1945+
browser.GetUserContexts //
1946+
browser.RemoveUserContext
18691947
)
18701948
</pre>
18711949

18721950
[=local end definition=]
18731951

18741952
<!-- Nothing yet -->
18751953
<pre class="cddl local-cddl">
1954+
BrowserResult = (
1955+
browser.CreateUserContextResult /
1956+
browser.GetUserContextsResult
1957+
)
1958+
</pre>
1959+
1960+
1961+
### Types ### {#module-browser-types}
1962+
1963+
#### The browser.UserContext Type #### {#type-browser-UserContext}
1964+
1965+
<pre class="cddl remote-cddl local-cddl">
1966+
browser.UserContext = text;
1967+
</pre>
1968+
1969+
The <code>browser.UserContext</code> unique identifies a [=user context=].
1970+
1971+
#### The browser.UserContextInfo Type #### {#type-browser-UserContextInfo}
1972+
1973+
<pre class="cddl remote-cddl local-cddl">
1974+
browser.UserContextInfo = {
1975+
userContext: browser.UserContext
1976+
}
18761977
</pre>
18771978

1979+
The <code>browser.UserContextInfo</code> type represents properties of a [=user
1980+
context=].
18781981

18791982
### Commands ### {#module-browser-commands}
18801983

@@ -1936,9 +2039,6 @@ The [=remote end steps=] with |session| and <var ignore>command parameters</var>
19362039

19372040
1. [=Close=] any [=top-level browsing contexts=] without [=prompting to unload=].
19382041

1939-
Note: This implicitly only affects browsing contexts that were under
1940-
automation in the first place.
1941-
19422042
1. Perform implementation defined steps to clean up resources associated with
19432043
the [=remote end=] under automation.
19442044

@@ -1951,6 +2051,145 @@ The [=remote end steps=] with |session| and <var ignore>command parameters</var>
19512051

19522052
</div>
19532053

2054+
#### The browser.createUserContext Command #### {#command-browser-createUserContext}
2055+
2056+
The <dfn export for=commands>browser.createUserContext</dfn> command creates a
2057+
[=user context=].
2058+
2059+
<dl>
2060+
<dt>Command Type</dt>
2061+
<dd>
2062+
<pre class="cddl remote-cddl">
2063+
browser.CreateUserContext = (
2064+
method: "browser.createUserContext",
2065+
params: EmptyParams,
2066+
)
2067+
</pre>
2068+
</dd>
2069+
<dt>Return Type</dt>
2070+
<dd>
2071+
<pre class="cddl local-cddl">
2072+
browser.CreateUserContextResult = browser.UserContextInfo
2073+
</pre>
2074+
</dd>
2075+
</dl>
2076+
2077+
<div algorithm="remote end steps for browser.createUserContext">
2078+
2079+
The [=remote end steps=] are:
2080+
2081+
1. Let |user context| be a new [=user context=].
2082+
2083+
1. [=set/Append=] |user context| to the [=set of user contexts=].
2084+
2085+
1. Let |user context info| be a [=/map=] matching the
2086+
<code>browser.UserContextInfo</code> production with the
2087+
<code>userContext</code> field set to |user context|'s [=user context id=].
2088+
2089+
1. Return [=success=] with data |user context info|.
2090+
2091+
</div>
2092+
2093+
2094+
#### The browser.getUserContexts Command #### {#command-browser-getUserContexts}
2095+
2096+
The <dfn export for=commands>browser.getUserContexts</dfn> command returns a
2097+
list of [=user context=]s.
2098+
2099+
<dl>
2100+
<dt>Command Type</dt>
2101+
<dd>
2102+
<pre class="cddl remote-cddl">
2103+
browser.GetUserContexts = (
2104+
method: "browser.getUserContexts",
2105+
params: EmptyParams,
2106+
)
2107+
</pre>
2108+
</dd>
2109+
<dt>Return Type</dt>
2110+
<dd>
2111+
<pre class="cddl local-cddl">
2112+
browser.GetUserContextsResult = {
2113+
userContexts: [ + browser.UserContextInfo]
2114+
}
2115+
</pre>
2116+
</dd>
2117+
</dl>
2118+
2119+
<div algorithm="remote end steps for browser.getUserContexts">
2120+
2121+
The [=remote end steps=] are:
2122+
2123+
1. Let |user contexts| be an empty [=/list=].
2124+
2125+
1. For each |user context| in the [=set of user contexts=]:
2126+
2127+
1. Let |user context info| be a [=/map=] matching the
2128+
<code>browser.UserContextInfo</code> production with the
2129+
<code>userContext</code> field set to |user context|'s [=user context id=].
2130+
2131+
1. [=list/Append=] |user context info| to |user contexts|.
2132+
2133+
1. Let |result| be a [=/map=] matching the
2134+
<code>browser.GetUserContextsResult</code> production with the
2135+
<code>userContexts</code> field set to |user contexts|.
2136+
2137+
1. Return [=success=] with data |result|.
2138+
2139+
</div>
2140+
2141+
2142+
#### The browser.removeUserContext Command #### {#command-browser-removeUserContext}
2143+
2144+
The <dfn export for=commands>browser.removeUserContext</dfn> command closes a
2145+
user context and all browsing contexts in it without running
2146+
<code>beforeunload</code> handlers.
2147+
2148+
<dl>
2149+
<dt>Command Type</dt>
2150+
<dd>
2151+
<pre class="cddl remote-cddl">
2152+
browser.RemoveUserContext = (
2153+
method: "browser.removeUserContext",
2154+
params: {
2155+
userContext: browser.UserContext
2156+
},
2157+
)
2158+
</pre>
2159+
</dd>
2160+
<dt>Return Type</dt>
2161+
<dd>
2162+
<pre class="cddl">
2163+
EmptyResult
2164+
</pre>
2165+
</dd>
2166+
</dl>
2167+
2168+
<div algorithm="remote end steps for browser.removeUserContext">
2169+
2170+
The [=remote end steps=] with |command parameters| are:
2171+
2172+
1. Let |user context id| be |command parameters|["<code>userContext</code>"].
2173+
2174+
1. If |user context id| is <code>"default"</code>, return [=error=] with [=error
2175+
code=] [=invalid argument=].
2176+
2177+
1. Set |user context| to [=get user context=] with |user context id|.
2178+
2179+
1. If |user context| is null, return [=error=] with [=error code=] [=no such user context=].
2180+
2181+
1. For each [=/top-level traversable=] |navigable|:
2182+
2183+
1. If |navigable|'s [=associated user context=] is |user context|:
2184+
2185+
1. [=Close=] |navigable| without [=prompting to unload=].
2186+
2187+
1. [=set/Remove=] |user context| for the [=set of user contexts=].
2188+
2189+
1. Return [=success=] with data null.
2190+
2191+
</div>
2192+
19542193
## The browsingContext Module ## {#module-browsingContext}
19552194

19562195
The <dfn export for=modules>browsingContext</dfn> module contains commands and
@@ -2065,9 +2304,10 @@ To <dfn export>get a browsing context</dfn> given |context id|:
20652304
browsingContext.InfoList = [*browsingContext.Info]
20662305

20672306
browsingContext.Info = {
2307+
children: browsingContext.InfoList / null,
20682308
context: browsingContext.BrowsingContext,
20692309
url: text,
2070-
children: browsingContext.InfoList / null
2310+
userContext: browser.UserContext
20712311
? parent: browsingContext.BrowsingContext / null,
20722312
}
20732313
</pre>
@@ -2142,18 +2382,22 @@ To <dfn>get the browsing context info</dfn> given |context|,
21422382

21432383
1. Set |child infos| to an empty [=/list=].
21442384

2145-
1. For each |context| of |child contexts|:
2385+
1. For each |child context| of |child contexts|:
21462386

21472387
1. Let |info| be the result of [=get the browsing context info=] given
2148-
|context|, |child depth|, and false.
2388+
|child context|, |child depth|, and false.
21492389

21502390
1. Append |info| to |child infos|
21512391

2392+
1. Let |user context| be |context|'s [=associated user context=].
2393+
21522394
1. Let |context info| be a [=/map=] matching the
21532395
<code>browsingContext.Info</code> production with the <code>context</code>
21542396
field set to |context id|, the <code>parent</code> field set to |parent id|
21552397
if |is root| is <code>true</code>, or unset otherwise, the <code>url</code>
2156-
field set to |url|, and the <code>children</code> field set to |child infos|.
2398+
field set to |url|, the <code>userContext</code> field set to
2399+
|user context|'s [=user context id=], and the <code>children</code> field
2400+
set to |child infos|.
21572401

21582402
1. Return |context info|.
21592403

@@ -2769,7 +3013,8 @@ The <dfn export for=commands>browsingContext.create</dfn> command creates a new
27693013
browsingContext.CreateParameters = {
27703014
type: browsingContext.CreateType,
27713015
? referenceContext: browsingContext.BrowsingContext,
2772-
? background: bool .default false
3016+
? background: bool .default false,
3017+
? userContext: browser.UserContext / null
27733018
}
27743019
</pre>
27753020
</dd>
@@ -2802,13 +3047,28 @@ The [=remote end steps=] with |command parameters| are:
28023047
1. If the implementation is unable to create a new browsing context for any
28033048
reason then return [=error=] with [=error code=] [=unsupported operation=].
28043049

3050+
1. Let |user context| be the [=default user context=] if |reference context|
3051+
is null, and |reference context|' [=associated user context=] otherwise.
3052+
3053+
1. If |command parameters|[<code>userContext</code>] is present and is not null:
3054+
3055+
1. Set |user context| to [=get user context=] with |command parameters|["<code>userContext</code>"].
3056+
3057+
1. If |user context| is null, return [=error=] with [=error code=] [=no such user context=].
3058+
3059+
1. If the implementation is unable to create a new [=/top-level traversable=]
3060+
with [=associated user context=] |user context| for any reason, return
3061+
[=error=] with [=error code=] [=unsupported operation=].
3062+
28053063
<!-- This is based on step 5 of https://w3c.github.io/webdriver/#new-window,
28063064
but without using the "current browsing context" concept. -->
28073065
1. Create a new [=top-level browsing context=] by running the [=window open
2808-
steps=] with <var ignore>url</var> set to "<code>about:blank</code>",
2809-
<var ignore>target</var> set to the empty string, and
2810-
<var ignore>features</var> set to "<code>noopener</code>". Which OS window the new [=/browsing context=]
2811-
is created in depends on |type| and |reference context|:
3066+
steps=] with <var ignore>url</var> set to "<code>about:blank</code>", <var
3067+
ignore>target</var> set to the empty string, and <var ignore>features</var>
3068+
set to "<code>noopener</code>", and setting the [=associated user context=]
3069+
for the newly created [=/top-level traversable=] to |user context|. Which OS
3070+
window the new [=/browsing context=] is created in depends on |type| and
3071+
|reference context|:
28123072

28133073
* If |type| is "<code>tab</code>" and the implementation supports
28143074
multiple browsing contexts in the same OS window:

0 commit comments

Comments
 (0)