24 lines
1.1 KiB
JavaScript
24 lines
1.1 KiB
JavaScript
// Keep the original document boundary as well as its ticket across fallbacks.
|
|
export function captureSharingOwner() {
|
|
var boundary = window.AccountBoundary;
|
|
var owner = boundary && typeof boundary.capture === 'function' && typeof boundary.signal === 'function'
|
|
? { boundary: boundary, ticket: boundary.capture(), signal: boundary.signal() } : null;
|
|
assertSharingOwner(owner);
|
|
return owner;
|
|
}
|
|
|
|
export function validSharingOwner(owner) {
|
|
return !!(owner && owner.ticket && owner.boundary === window.AccountBoundary &&
|
|
owner.signal && !owner.signal.aborted && typeof owner.boundary.valid === 'function' && owner.boundary.valid(owner.ticket));
|
|
}
|
|
|
|
export function assertSharingOwner(owner) {
|
|
if (!validSharingOwner(owner)) {
|
|
throw owner && typeof owner.boundary.error === 'function' ? owner.boundary.error() : new DOMException('Account unavailable', 'AbortError');
|
|
}
|
|
}
|
|
|
|
export function sharingFilename(prefix, extension) {
|
|
// An already-admitted OS write can finish after freeze; never reuse B's path.
|
|
return prefix + '-' + window.crypto.randomUUID() + '.' + extension;
|
|
}
|