cool#9219 clipboard: support URLs in the payload of the setclipboard command

Copying the full clipboard (including ODF) from a remote server into the
JS client failed with:

Refused to connect to '...' because it violates the following Content Security Policy directive: "connect-src ..."

If this happens, still send the original URL to the server, so it can
download the full clipboard, which gives better result for pasting,
compared to going via HTML only.

Not done in this commit: 1) the JS still tries to get the clipboard
itself, we download on the server only on failure and 2) the server does
a blocking HTTP download, which may not be wanted.

Signed-off-by: Miklos Vajna <vmiklos@collabora.com>
Change-Id: I9ed8c8050f9dbe71dc8fcd36c9d8fa6e8bba44f6
This commit is contained in:
Miklos Vajna 2024-06-07 11:22:25 +02:00 committed by Caolán McNamara
parent c3956f3044
commit 213aca81fb
2 changed files with 21 additions and 4 deletions

View file

@ -354,15 +354,15 @@ L.Clipboard = L.Class.extend({
}
var formData = new FormData();
formData.append('data', new Blob([fallbackHtml]), 'clipboard');
formData.append('data', new Blob([src]), 'clipboard');
that._doAsyncDownload(
'POST', dest, formData, false,
function() {
if (that._checkAndDisablePasteSpecial()) {
window.app.console.log('up-load of fallback done, now paste special');
window.app.console.log('up-load of URL done, now paste special');
app.socket.sendMessage('uno .uno:PasteSpecial');
} else {
window.app.console.log('up-load of fallback done, now paste');
window.app.console.log('up-load of URL done, now paste');
app.socket.sendMessage('uno .uno:Paste');
}

View file

@ -318,7 +318,24 @@ void ClientSession::handleClipboardRequest(DocumentBroker::ClipboardRequest
if (data.get())
{
preProcessSetClipboardPayload(*data);
docBroker->forwardToChild(client_from_this(), "setclipboard\n" + *data, true);
if (data->starts_with("http"))
{
// We got a URL, download that and set the result as the clipboard.
std::shared_ptr<http::Session> httpSession = http::Session::create(*data);
std::shared_ptr<const http::Response> httpResponse =
httpSession->syncRequest(http::Request(Poco::URI(*data).getPathAndQuery()));
if (httpResponse->statusLine().statusCode() == http::StatusCode::OK)
{
std::string body = httpResponse->getBody();
docBroker->forwardToChild(client_from_this(), "setclipboard\n" + body, true);
}
}
else
{
// List of mimetype-size-data tuples, pass that over as-is.
docBroker->forwardToChild(client_from_this(), "setclipboard\n" + *data, true);
}
// FIXME: work harder for error detection ?
std::ostringstream oss;