An open-source, self-hosted system for apps built with web technologies.
Own client documents on iframe load
zohayrslilehc99d61cf38fe
diff --git a/scripts/verify-client-surface.mjs b/scripts/verify-client-surface.mjsindex 41d5932..6c5b147 100644--- a/scripts/verify-client-surface.mjs+++ b/scripts/verify-client-surface.mjs@@ -131,7 +131,10 @@ const localWindow = {const processManager = {processes,front: ClientProcessManager.prototype.front,- scope: ClientProcessManager.prototype.scope+ scope: ClientProcessManager.prototype.scope,+ async ownFrame() {},+ async releaseFrame() {},+ async unsubscribeFrame() {}}const authManager = {processManager,@@ -166,9 +169,8 @@ const boundary = new ClientProcessBoundary({ release(identity) { lifecycle.push(identity) } })-boundary.receive(["boundary", "document", "first-document"])-boundary.receive(["boundary", "document", "first-document"])-boundary.receive(["boundary", "document", "second-document"])+await boundary.own("first-owner")+await boundary.own("second-owner")await boundary.release()assert.deepEqual(lifecycle, ["requester", "requester"])diff --git a/source/client/view/desktop/client-host/client-process-boundary.ts b/source/client/view/desktop/client-host/client-process-boundary.tsindex 9c1981f..041501b 100644--- a/source/client/view/desktop/client-host/client-process-boundary.ts+++ b/source/client/view/desktop/client-host/client-process-boundary.ts@@ -46,7 +46,8 @@ export default class ClientProcessBoundary extends TheLink {// A document can begin executing before its iframe load event gives the// desktop a server-host lease. Keep those endpoint envelopes at the near- // boundary; once the lease exists they follow the same path as later ones.+ // boundary; once the load establishes ownership they follow the same path+ // as later ones.private readonly pending = new Array<unknown[]>()private pointerStop: (() => void) | null = null@@ -57,8 +58,6 @@ export default class ClientProcessBoundary extends TheLink {private leased: string | null = null- private document: string | null = null-public constructor(pane: string, element: HTMLIFrameElement, authManager: AuthManager, desktop: () => DesktopSize, pointer: PointerHost, traffic: ClientTraffic, localWindow: LocalWindowHost) {super()@@ -85,7 +84,29 @@ export default class ClientProcessBoundary extends TheLink {public async own(owner: string) {- await this.authManager.processManager.ownFrame(this.pane, owner)+ // The iframe load event is the document lifecycle boundary. Preserve+ // what the newly loading document already sent, discard everything+ // retained for the previous document, then replay the preserved+ // envelopes only after the new server-host lease exists.+ const pending = this.pending.splice(0)++ if (this.leased) this.localWindow.release(this.pane)++ this.resetEndpoint()++ this.owner = null++ try {++ await this.authManager.processManager.ownFrame(this.pane, owner)+ }++ catch (error) {++ this.pending.unshift(...pending)++ throw error+ }this.owner = owner@@ -96,7 +117,7 @@ export default class ClientProcessBoundary extends TheLink {if (directSubscription(description)) this.authManager.processManager.subscribeFrame(this.pane, owner, subscription, description.kind, description.event).catch(() => undefined)}- const pending = this.pending.splice(0)+ pending.push(...this.pending.splice(0))for (const message of pending) this.receive(message)}@@ -111,8 +132,6 @@ export default class ClientProcessBoundary extends TheLink {this.leased = null- this.document = null-this.resetEndpoint()this.pending.length = 0@@ -305,26 +324,6 @@ export default class ClientProcessBoundary extends TheLink {const [operation, ...args] = values- if (operation === "document") {-- if (typeof args[0] !== "string" || args[0] === this.document) return-- // The first document establishes this already-mounted iframe- // representation. A later document replaces it and therefore- // destroys the previous representation's local Surface.- if (this.document !== null) this.localWindow.release(this.pane)-- this.document = args[0]-- this.resetEndpoint()-- // The new document cannot use the previous document's forwarding- // lease while its own lease is still being established.- this.owner = null-- return- }-if (operation === "log") {if (typeof args[0] !== "string" || typeof args[1] !== "string") return