2018-01-18 10:59:35 -06:00
|
|
|
<!DOCTYPE html>
|
|
|
|
|
|
|
|
<!-- Proof of concept of running loleaflet.html in an iframe.
|
|
|
|
|
|
|
|
The top part of this page has a form with three input fields:
|
|
|
|
"x", "y", and "color", a submit button, and a "result" field used
|
|
|
|
for output only.
|
|
|
|
|
|
|
|
When the submit button is pressed, the input fields are passed as
|
2018-01-19 04:16:55 -06:00
|
|
|
a postMessage to the iframe. The message also specifies what
|
|
|
|
Python script to call. (In this demo case, the 'SetCellColor'
|
|
|
|
script in scripting/examples/python/SetCellColor.py in
|
|
|
|
LibreOffice core.) The parameters are then in our JavaScript
|
|
|
|
passed on to the Python script that acts on the document open in
|
|
|
|
the iframe. The Python script returns a value, which gets passed
|
|
|
|
to loleaflet in a unocommandresult: message, and passed on to the
|
|
|
|
event listener on this page, which writes it to the output field.
|
2018-01-18 10:59:35 -06:00
|
|
|
|
2018-01-19 04:16:55 -06:00
|
|
|
For this to work, in the trivial proof of concept case of 'make
|
|
|
|
run', the below patch is needed to the C++ code. It is probably
|
|
|
|
not necessary in a "real" WOPI-based setup where iframes are
|
|
|
|
already used and things work fine.
|
2018-01-18 10:59:35 -06:00
|
|
|
|
|
|
|
--- a/wsd/FileServer.cpp
|
|
|
|
+++ b/wsd/FileServer.cpp
|
|
|
|
@@ -172,7 +172,7 @@ void FileServerRequestHandler::handleRequest(const HTTPRequest& request, Poco::M
|
|
|
|
const auto& config = Application::instance().config();
|
|
|
|
const std::string loleafletHtml = config.getString("loleaflet_html", "loleaflet.html");
|
|
|
|
const std::string endPoint = requestSegments[requestSegments.size() - 1];
|
|
|
|
- if (endPoint == loleafletHtml)
|
|
|
|
+ if (endPoint == loleafletHtml || endPoint == "framed.html")
|
|
|
|
{
|
|
|
|
preprocessFile(request, message, socket);
|
|
|
|
return;
|
|
|
|
@@ -548,7 +548,7 @@ void FileServerRequestHandler::preprocessFile(const HTTPRequest& request, Poco::
|
|
|
|
LOG_TRC("Denied frame ancestor: " << frameAncestor);
|
|
|
|
|
|
|
|
cspOss << "img-src 'self' data: ;";
|
|
|
|
- oss << "X-Frame-Options: deny\r\n";
|
|
|
|
+ oss << "X-Frame-Options: sameorigin\r\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
cspOss << "\r\n";
|
|
|
|
|
|
|
|
-->
|
|
|
|
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
|
|
|
<title>Online Editor</title>
|
|
|
|
|
|
|
|
<script>
|
2018-01-19 10:02:13 -06:00
|
|
|
function callSetCellColor() {
|
2018-01-18 10:59:35 -06:00
|
|
|
window.frames[0].postMessage(JSON.stringify({'MessageId': 'Host_PostmessageReady'}), '*');
|
|
|
|
var x = document.forms[0].elements['x'].value;
|
|
|
|
var y = document.forms[0].elements['y'].value;
|
|
|
|
var color = document.forms[0].elements['color'].value;
|
|
|
|
console.log('x=' + x + ' y=' + y + ' color=' + color);
|
|
|
|
color = parseInt('0x' + color.substring(1));
|
|
|
|
console.log('x=' + x + ' y=' + y + ' color=' + color);
|
2018-01-19 04:16:55 -06:00
|
|
|
window.frames[0].postMessage(JSON.stringify({'MessageId': 'CallPythonScript',
|
2018-01-18 10:59:35 -06:00
|
|
|
'SendTime': Date.now(),
|
2018-01-19 04:16:55 -06:00
|
|
|
'ScriptFile': 'SetCellColor.py',
|
|
|
|
'Function': 'SetCellColor',
|
|
|
|
'Values': {'x': {'type': 'long', 'value': x},
|
|
|
|
'y': {'type': 'long', 'value': y},
|
|
|
|
'color': {'type': 'long', 'value': color}
|
2018-01-18 10:59:35 -06:00
|
|
|
}
|
|
|
|
}),
|
|
|
|
'*');
|
|
|
|
}
|
|
|
|
|
2018-01-19 10:02:13 -06:00
|
|
|
function callGetNamedRanges() {
|
|
|
|
window.frames[0].postMessage(JSON.stringify({'MessageId': 'Host_PostmessageReady'}), '*');
|
|
|
|
window.frames[0].postMessage(JSON.stringify({'MessageId': 'CallPythonScript',
|
|
|
|
'SendTime': Date.now(),
|
|
|
|
'ScriptFile': 'NamedRanges.py',
|
|
|
|
'Function': 'GetNamedRanges',
|
|
|
|
'Values': null
|
|
|
|
}),
|
|
|
|
'*');
|
|
|
|
}
|
|
|
|
|
2018-01-19 13:17:15 -06:00
|
|
|
function callAddNamedRange() {
|
|
|
|
window.frames[0].postMessage(JSON.stringify({'MessageId': 'Host_PostmessageReady'}), '*');
|
|
|
|
// FIXME: Add parameters for the position, size, and name of the range
|
|
|
|
window.frames[0].postMessage(JSON.stringify({'MessageId': 'CallPythonScript',
|
|
|
|
'SendTime': Date.now(),
|
|
|
|
'ScriptFile': 'NamedRanges.py',
|
|
|
|
'Function': 'DefineNamedRange',
|
|
|
|
'Values': {'sheet': {'type': 'string', 'value': 'Sheet1'},
|
|
|
|
'x0': {'type': 'long', 'value': '2'},
|
|
|
|
'y0': {'type': 'long', 'value': '3'},
|
|
|
|
'width': {'type': 'long', 'value': '2'},
|
|
|
|
'height': {'type': 'long', 'value': '2'},
|
|
|
|
'name': {'type': 'string', 'value': 'N' + Date.now().toString()}
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
'*');
|
|
|
|
}
|
|
|
|
|
2018-01-18 10:59:35 -06:00
|
|
|
function receiveMessage(event) {
|
|
|
|
var msg = JSON.parse(event.data);
|
|
|
|
console.log('==== framed.html receiveMessage: ' + event.data);
|
|
|
|
console.log(' ' + msg);
|
|
|
|
if (msg.hasOwnProperty('MessageId') &&
|
2018-01-19 04:16:55 -06:00
|
|
|
msg.MessageId === 'CallPythonScript-Result' &&
|
2018-01-18 10:59:35 -06:00
|
|
|
msg.hasOwnProperty('Values') &&
|
|
|
|
msg.Values.hasOwnProperty('commandName') &&
|
|
|
|
msg.Values.hasOwnProperty('success') &&
|
|
|
|
msg.Values.success == 'true' &&
|
|
|
|
msg.Values.hasOwnProperty('result') &&
|
|
|
|
msg.Values.result.hasOwnProperty('value')) {
|
2018-01-19 10:02:13 -06:00
|
|
|
if (msg.Values.commandName === 'vnd.sun.star.script:SetCellColor.py$SetCellColor?language=Python&location=share') {
|
|
|
|
document.forms['cell-colour-form'].elements['result'].readOnly = false;
|
|
|
|
document.forms['cell-colour-form'].elements['result'].value = msg.Values.result.value;
|
|
|
|
document.forms['cell-colour-form'].elements['result'].readOnly = true;
|
|
|
|
}
|
|
|
|
else if (msg.Values.commandName === 'vnd.sun.star.script:NamedRanges.py$GetNamedRanges?language=Python&location=share') {
|
|
|
|
document.forms['get-named-ranges-form'].elements['result'].readOnly = false;
|
|
|
|
var index = 0;
|
|
|
|
var result = '';
|
|
|
|
while (msg.Values.result.value.hasOwnProperty(index.toString())) {
|
|
|
|
result += msg.Values.result.value[index.toString()].value + "\n";
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
document.forms['get-named-ranges-form'].elements['result'].value = result;
|
|
|
|
document.forms['get-named-ranges-form'].elements['result'].readOnly = true;
|
|
|
|
}
|
2018-01-18 10:59:35 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
window.addEventListener("message", receiveMessage, false);
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<meta charset="utf-8">
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
|
</head>
|
|
|
|
|
|
|
|
<body style="user-select: none;">
|
|
|
|
|
|
|
|
<p>
|
2018-01-19 10:02:13 -06:00
|
|
|
<form id="cell-colour-form">
|
2018-01-18 10:59:35 -06:00
|
|
|
Cell: (<input type="number" name="x" min="0" max="20" value="0">, <input type="number" name="y" min="0" max="20" value="0">),
|
|
|
|
colour: <input type="text" name="color" value="#008000">
|
|
|
|
<br>
|
2018-01-19 10:02:13 -06:00
|
|
|
Click <button onclick="callSetCellColor(); return false;">here</button>
|
2018-01-18 10:59:35 -06:00
|
|
|
to send message to iframe below. It returned <input type="text" name="result" value="" readonly>.
|
|
|
|
</form>
|
|
|
|
</p>
|
|
|
|
|
2018-01-19 10:02:13 -06:00
|
|
|
<form id="get-named-ranges-form">
|
|
|
|
Click <button onclick="callGetNamedRanges(); return false;">here</button> to get a list of named ranges in the document:
|
2018-01-22 03:22:58 -06:00
|
|
|
<textarea name="result" value="" rows="10" cols="80"></textarea>
|
2018-01-19 10:02:13 -06:00
|
|
|
</form>
|
|
|
|
|
2018-01-19 13:17:15 -06:00
|
|
|
<form id="get-named-ranges-form">
|
|
|
|
<!-- FIXME: Add input fields for the position, size, and name of the range -->
|
|
|
|
Click <button onclick="callAddNamedRange(); return false;">here</button> to add a new named range.
|
|
|
|
</form>
|
|
|
|
|
2018-01-19 04:31:38 -06:00
|
|
|
<!-- The hostname and pathnames below are obviously specific to my
|
|
|
|
personal environment and need to be changed appropriately. Also
|
|
|
|
the hex string needs to be changed of course, to the right one as
|
2018-01-18 11:06:08 -06:00
|
|
|
shown by 'make run'. -->
|
|
|
|
|
2018-01-18 10:59:35 -06:00
|
|
|
<iframe src="http://snorken.local:9980/loleaflet/94781ec6/loleaflet.html?file_path=file:///home/tml/lo/internal-online/test/data/empty.ods&NotWOPIButIframe=true" height="1000" width="1000"></iframe>
|
|
|
|
</body>
|
|
|
|
</html>
|