summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Meeks <michael.meeks@collabora.com>2019-05-29 13:11:01 +0100
committerMichael Meeks <michael.meeks@collabora.com>2019-05-29 15:10:47 +0100
commit2d956b4c3719699365630f16efec84e22c9a0cd0 (patch)
treecb0e1932738852004d85c2191c3556dfe869813a
parentImprove debugging by showing un-masked websocket content. (diff)
downloadonline-private/mmeeks/copypaste.tar.gz
online-private/mmeeks/copypaste.zip
Add pasteresult: message to allow re-try with a different format. private/mmeeks/copypaste
Change-Id: Ia3d7aacdcf2b819437eb2da68a79dd99ed7dca42
-rw-r--r--kit/ChildSession.cpp16
-rw-r--r--loleaflet/src/layer/tile/TileLayer.js41
2 files changed, 50 insertions, 7 deletions
diff --git a/kit/ChildSession.cpp b/kit/ChildSession.cpp
index 91a3ad296b..f4387d60d1 100644
--- a/kit/ChildSession.cpp
+++ b/kit/ChildSession.cpp
@@ -997,15 +997,19 @@ bool ChildSession::paste(const char* buffer, int length, const std::vector<std::
return false;
}
- if (mimeType.find("") == 0)
+ bool fallback = false;
+ if (mimeType.find("application/x-openoffice-embed-source-xml") == 0)
{
LOG_TRC("Re-writing garbled mime-type " << mimeType);
mimeType = "application/x-openoffice-embed-source-xml;windows_formatname=\"Star Embed Source (XML)\"";
+ fallback = true;
}
const std::string firstLine = getFirstLine(buffer, length);
const char* data = buffer + firstLine.size() + 1;
const int size = length - firstLine.size() - 1;
+ bool success = false;
+ std::string result = "pasteresult: ";
if (size > 0)
{
std::unique_lock<std::mutex> lock(_docManager.getDocumentMutex());
@@ -1013,9 +1017,17 @@ bool ChildSession::paste(const char* buffer, int length, const std::vector<std::
getLOKitDocument()->setView(_viewId);
LOG_TRC("Paste data of size " << size << " bytes and hash " << SpookyHash::Hash64(data, size, 0));
- if (!getLOKitDocument()->paste(mimeType.c_str(), data, size))
+ success = getLOKitDocument()->paste(mimeType.c_str(), data, size);
+ if (!success)
LOG_WRN("Paste failed " << getLOKitLastError());
}
+ if (success)
+ result += "success";
+ else if (fallback)
+ result += "fallback";
+ else
+ result += "fail";
+ sendTextFrame(result);
return true;
}
diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js
index b9a23067ab..71705148aa 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -493,6 +493,9 @@ L.TileLayer = L.GridLayer.extend({
else if (textMsg.startsWith('editor:')) {
this._updateEditor(textMsg);
}
+ else if (textMsg.startsWith('pasteresult:')) {
+ this._pasteResult(textMsg);
+ }
else if (textMsg.startsWith('validitylistbutton:')) {
this._onValidityListButtonMsg(textMsg);
}
@@ -2493,6 +2496,23 @@ L.TileLayer = L.GridLayer.extend({
return '';
},
+ // Sometimes our smart-paste fails & we need to try again.
+ _pasteResult : function(textMsg)
+ {
+ textMsg = textMsg.substring('pasteresult:'.length + 1);
+ console.log('Paste state: ' + textMsg);
+ if (textMsg == 'fallback') {
+ if (this._pasteFallback != null) {
+ console.log('Paste failed- falling back to HTML');
+ this._map._socket.sendMessage(this._pasteFallback);
+ } else {
+ console.log('No paste fallback present.');
+ }
+ }
+
+ this._pasteFallback = null;
+ },
+
_dataTransferToDocument: function (dataTransfer, preferInternal) {
// Look for our HTML meta magic.
@@ -2511,6 +2531,9 @@ L.TileLayer = L.GridLayer.extend({
return;
}
+ console.log('Resetting paste fallback');
+ this._pasteFallback = null;
+
// Suck HTML content out of dataTransfer now while it feels like working.
var content = this._readContentSync(dataTransfer);
@@ -2541,10 +2564,12 @@ L.TileLayer = L.GridLayer.extend({
return;
}
- // Try Fetch the data directly ourselves instead.
- if (meta != '') {
+ if (meta != '') { // in Smart server side paste mode ...
// FIXME: really should short-circuit on the server.
console.log('Doing async paste of data from remote origin\n\t"' + meta + '" is not\n\t"' + id + '"');
+
+ this._pasteFallback = content;
+
var tilelayer = this;
var oReq = new XMLHttpRequest();
oReq.onload = function(e) {
@@ -2556,18 +2581,24 @@ L.TileLayer = L.GridLayer.extend({
} else {
console.log('Error code ' + oReq.status + ' fetching from URL "' + meta + '": ' + e + ' falling back to local.');
tilelayer._map._socket.sendMessage(content);
+ this._pasteFallback = null;
}
}
oReq.onerror = function(e) {
console.log('Error fetching from URL "' + meta + '": ' + e + ' falling back to local.');
tilelayer._map._socket.sendMessage(content);
+ this._pasteFallback = null;
};
oReq.open('GET', meta);
oReq.responseType = 'arraybuffer';
oReq.send();
// user abort - if they do stops paste.
+ } else if (content != null) {
+ console.log('Normal HTML, so smart paste not possible');
+ tilelayer._map._socket.sendMessage(content);
+ this._pasteFallback = null;
} else {
- console.log('Received a paste but nothing on the clipboard');
+ console.log('Nothing we can paste on the clipboard');
}
},
@@ -2575,9 +2606,9 @@ L.TileLayer = L.GridLayer.extend({
// Try various content mime types
var mimeTypes;
if (this._docType === 'spreadsheet') {
- // FIXME apparently we cannot paste the text/html or text/rtf as
- // produced by LibreOffice in Calc from some reason
mimeTypes = [
+ ['text/rtf', 'text/rtf'],
+ ['text/html', 'text/html'],
['text/plain', 'text/plain;charset=utf-8'],
['Text', 'text/plain;charset=utf-8']
];