Loading
Bug 2057113 - Part 2: Don't force a synchronous clipboard flush for file...
Bug 2057113 - Part 2: Don't force a synchronous clipboard flush for file promises. a=diannaS DONTBUILD SetNativeClipboardData flushes clipboard writes when text/plain is on the transferable on Windows 11 22H2+. Flushing was added to clipboard write in bug 1774285, because delayed rendering makes Windows Suggested Actions walk the a11y tree, and immediate rendering of data to the clipboard was the lesser evil. Rendering a file promise maps to CF_HDROP, whose renderer is nsDataObj::DropTempFile (which is unintuitively _not_ used for drag and drop, only clipboard). It opens a channel to the promised URL and runs a nested event loop in CStream::WaitForCompletion until it completes, so forcing the flush runs a network fetch in a nested event loop inside the clipboard commit. The duration of the nest is unpredictable but can be as long as the device maintains the connection (modulo any timeout limits). This patch skips the flush if there is a file (or no text) in the payload, avoiding the nested loop altogether when this happens. Without a pref flip (clipboard.imageAsFile.enabled = true), writing both a file and text to clipboard should not be possible, so this case does not occur. This is because only images can be written to the clipboard as files. See [the MDN page for mandatory types](https://www.w3.org/TR/clipboard-apis/#mandatory-data-types) and the comment in ClipboardItem::Supports. Original Revision: https://phabricator.services.mozilla.com/D326256 Differential Revision: https://phabricator.services.mozilla.com/D328682