Description
This is a follow-up to #4198. The browsing context group concept is added by #4350, but to properly clarify the lifetime of objects, we'll need to imperatively allocate them. In particular, objects might lose their direct connection to a browsing context (e.g., when you remove an <iframe>
), but that doesn't mean they're outside the scope of the agent they were created in (e.g., when you keep a reference to a WindowProxy
object while you remove that <iframe>
).
(Alternatively we could perhaps give everything a pointer to the browsing context group, but that doesn't seem like a good architecture, in particular because nothing in ECMAScript really supports that kind of notion.)
This is the setup I have for this thus far:
A browsing context group has associated agent clusters (a map of agent cluster key/agent cluster).
An agent cluster key is an origin or a scheme-and-site. A scheme-and-site is a tuple of a scheme and a domain.
To obtain an agent cluster key, given an origin origin, run these steps:
-
If origin is an opaque origin, then return origin.
-
If origin's host's registrable domain is null, then return origin.
-
Return (origin's host's scheme, origin's host's registrable domain).
To obtain a similar-origin window agent, given a browsing context group group and agent cluster key key, run these steps:
-
Let agentCluster be the result of obtaining a browsing context agent cluster with group and key.
-
If agentCluster does not contain an agent, then add a new similar-origin window agent to it. (ECMAScript does not define the layout of agent clusters unfortunately.)
-
Return agentCluster's similar-origin window agent.
To obtain a browsing context agent cluster, given a browsing context group group and agent cluster key key, run these steps:
-
If group's agent clusters[key] does not exist, then set group's agent clusters[key] to a new agent cluster. (ECMAScript does not define allocating agent clusters unfortunately.)
-
Return group's agent clusters[key].
Feedback appreciated.
cc @mystor @farre @rniwa @creis @domenic
(This intentionally does not cover workers. They can use a simpler allocation setup that can be sorted as part of #4339.)