From 43a97878ce14b72f0981164f87f2e35e14151312 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 11:22:09 +0200 Subject: Adding upstream version 110.0.1. Signed-off-by: Daniel Baumann --- .../tests/resources/chromium/webusb-child-test.js | 40 ++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 testing/web-platform/tests/resources/chromium/webusb-child-test.js (limited to 'testing/web-platform/tests/resources/chromium/webusb-child-test.js') diff --git a/testing/web-platform/tests/resources/chromium/webusb-child-test.js b/testing/web-platform/tests/resources/chromium/webusb-child-test.js new file mode 100644 index 0000000000..add04fa582 --- /dev/null +++ b/testing/web-platform/tests/resources/chromium/webusb-child-test.js @@ -0,0 +1,40 @@ +'use strict'; + +// This polyfill prepares a child context to be attached to a parent context. +// The parent must call navigator.usb.test.attachToContext() to attach to the +// child context. +(() => { + if (this.constructor.name === 'DedicatedWorkerGlobalScope' || + this !== window.top) { + + // Run Chromium specific set up code. + if (typeof MojoInterfaceInterceptor !== 'undefined') { + let messageChannel = new MessageChannel(); + messageChannel.port1.onmessage = async (messageEvent) => { + if (messageEvent.data.type === 'Attach') { + messageEvent.data.interfaces.forEach(interfaceName => { + let interfaceInterceptor = + new MojoInterfaceInterceptor(interfaceName); + interfaceInterceptor.oninterfacerequest = + e => messageChannel.port1.postMessage({ + type: interfaceName, + handle: e.handle + }, [e.handle]); + interfaceInterceptor.start(); + }); + + // Wait for a call to GetDevices() to ensure that the interface + // handles are forwarded to the parent context. + await navigator.usb.getDevices(); + messageChannel.port1.postMessage({ type: 'Complete' }); + } + }; + + let message = { type: 'ReadyForAttachment', port: messageChannel.port2 }; + if (typeof Window !== 'undefined') + parent.postMessage(message, '*', [messageChannel.port2]); + else + postMessage(message, [messageChannel.port2]); + } + } +})(); -- cgit v1.2.3