[Libreoffice-commits] online.git: 2 commits - loleaflet/dist test/TileCacheTests.cpp wsd/DocumentBroker.cpp wsd/TileCache.cpp wsd/TileCache.hpp
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Fri Oct 12 15:47:21 UTC 2018
loleaflet/dist/framed.doc.html | 85 +++++++++++++++++++++++++++++++++++++++++
test/TileCacheTests.cpp | 2
wsd/DocumentBroker.cpp | 2
wsd/TileCache.cpp | 13 ++++--
wsd/TileCache.hpp | 4 +
5 files changed, 99 insertions(+), 7 deletions(-)
New commits:
commit 7563490fd43ceb32a3083ff5a4eb177156a96d53
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
AuthorDate: Fri Jul 27 00:16:50 2018 -0400
Commit: Jan Holesovsky <kendy at collabora.com>
CommitDate: Fri Oct 12 17:43:40 2018 +0200
leaflet: new sample iframe html
This loads a writer doc and demonstrates the
use of Capitalise.py and InsertText.py.
Change-Id: I4a200eff54b697b1179627b49c27961edf188e59
diff --git a/loleaflet/dist/framed.doc.html b/loleaflet/dist/framed.doc.html
new file mode 100644
index 000000000..8fa875db4
--- /dev/null
+++ b/loleaflet/dist/framed.doc.html
@@ -0,0 +1,85 @@
+<!DOCTYPE html>
+
+<!-- Proof of concept of running loleaflet.html in an iframe. Also
+ shows how to, from outside the iframe, invoke Python scripting in
+ the underlying LibreOffice instance that manipulates the document
+ being edited.
+
+ This demonstrates using the Python InsertText.py and Capitalise.py
+ scripts from javascript across iframes.
+
+ To test this, do 'make run', and then in your browser open the
+ equivalent of
+ http://snorken.local:9980/loleaflet/3304e9093/framed.html if the
+ browser is running on a different machine, or
+ http://localhost:9980/loleaflet/3304e9093/framed.html if running
+ on the same machine.
+
+-->
+
+<html>
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+ <title>Online Editor</title>
+
+ <script>
+
+ function insertText(text) {
+ window.frames[0].postMessage(JSON.stringify({'MessageId': 'Host_PostmessageReady'}), '*');
+ window.frames[0].postMessage(JSON.stringify({'MessageId': 'CallPythonScript',
+ 'SendTime': Date.now(),
+ 'ScriptFile': 'InsertText.py',
+ 'Function': 'InsertText',
+ 'Values': { 'text': {'type': 'string', 'value': text}}
+ }),
+ '*');
+ }
+
+ function capitalize() {
+ window.frames[0].postMessage(JSON.stringify({'MessageId': 'Host_PostmessageReady'}), '*');
+ window.frames[0].postMessage(JSON.stringify({'MessageId': 'CallPythonScript',
+ 'SendTime': Date.now(),
+ 'ScriptFile': 'Capitalise.py',
+ 'Function': 'capitalisePython',
+ 'Values': null
+ }),
+ '*');
+ }
+
+ // This function is invoked when the iframe posts a message back.
+
+ function receiveMessage(event) {
+ var msg = JSON.parse(event.data);
+ console.log('==== framed.html receiveMessage: ' + event.data);
+ console.log(' ' + msg);
+ }
+
+ // 'main' code of this <script> block, run when page is being
+ // rendered. Install the message listener.
+ 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;">
+
+ <form id="insert-text-form">
+ Click <button onclick="insertText(document.forms['insert-text-form'].elements['source'].value); return false;">here</button> to insert the following text into the document:
+ <textarea name="source" value="" rows="10" cols="80"></textarea>
+ </form>
+
+ <form id="insert-text-form">
+ Click <button onclick="capitalize(); return false;">here</button> to capitalize selected text in the document:
+ </form>
+
+ <!-- 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
+ shown by 'make run'. -->
+
+ <iframe src="http://localhost:9980/loleaflet/ef3c798/loleaflet.html?file_path=file:///home/ash/prj/lo/online/test/data/empty.odt&NotWOPIButIframe=true" height="1000" width="1000"></iframe>
+ </body>
+</html>
commit 03f58b9a9a9b2548ba48007035ff20bafcf7039a
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
AuthorDate: Thu Jul 5 00:07:43 2018 -0400
Commit: Jan Holesovsky <kendy at collabora.com>
CommitDate: Fri Oct 12 17:43:31 2018 +0200
wsd: disable tile caching when TileCachePersistent is false
Change-Id: I660438d478ab6d1ef60575b5f63b71c8b86bab4f
diff --git a/test/TileCacheTests.cpp b/test/TileCacheTests.cpp
index f4269c3bc..3f0be4016 100644
--- a/test/TileCacheTests.cpp
+++ b/test/TileCacheTests.cpp
@@ -183,7 +183,7 @@ void TileCacheTests::testSimple()
// Create TileCache and pretend the file was modified as recently as
// now, so it discards the cached data.
- TileCache tc("doc.ods", Poco::Timestamp(), "/tmp/tile_cache_tests");
+ TileCache tc("doc.ods", Poco::Timestamp(), "/tmp/tile_cache_tests", true);
int part = 0;
int width = 256;
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 504912678..58c305ca5 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -686,7 +686,7 @@ bool DocumentBroker::load(const std::shared_ptr<ClientSession>& session, const s
// Use the local temp file's timestamp.
_lastFileModifiedTime = Poco::File(_storage->getRootFilePath()).getLastModified();
- _tileCache.reset(new TileCache(_storage->getUri(), _lastFileModifiedTime, _cacheRoot));
+ _tileCache.reset(new TileCache(_storage->getUri(), _lastFileModifiedTime, _cacheRoot, LOOLWSD::TileCachePersistent));
_tileCache->setThreadOwner(std::this_thread::get_id());
}
diff --git a/wsd/TileCache.cpp b/wsd/TileCache.cpp
index 3ee3647ea..424e30bae 100644
--- a/wsd/TileCache.cpp
+++ b/wsd/TileCache.cpp
@@ -47,9 +47,11 @@ using Poco::Timestamp;
TileCache::TileCache(const std::string& docURL,
const Timestamp& modifiedTime,
- const std::string& cacheDir) :
+ const std::string& cacheDir,
+ const bool tileCachePersistent) :
_docURL(docURL),
- _cacheDir(cacheDir)
+ _cacheDir(cacheDir),
+ _tileCachePersistent(tileCachePersistent)
{
LOG_INF("TileCache ctor for uri [" << _docURL <<
"], cacheDir: [" << _cacheDir <<
@@ -161,6 +163,9 @@ int TileCache::getTileBeingRenderedVersion(const TileDesc& tile)
std::unique_ptr<std::fstream> TileCache::lookupTile(const TileDesc& tile)
{
+ if (!_tileCachePersistent)
+ return nullptr;
+
const std::string fileName = _cacheDir + "/" + cacheFileName(tile);
std::unique_ptr<std::fstream> result(new std::fstream(fileName, std::ios::in));
@@ -190,7 +195,7 @@ void TileCache::saveTileAndNotify(const TileDesc& tile, const char *data, const
// Ignore if we can't save the tile, things will work anyway, but slower.
// An error indication is supposed to be sent to all users in that case.
const auto fileName = _cacheDir + "/" + cachedName;
- if (FileUtil::saveDataToFileSafely(fileName, data, size))
+ if (_tileCachePersistent && FileUtil::saveDataToFileSafely(fileName, data, size))
{
LOG_TRC("Saved cache tile: " << fileName);
}
@@ -317,7 +322,7 @@ void TileCache::setUnsavedChanges(bool state)
removeFile("unsaved.txt");
}
-void TileCache::saveRendering(const std::string& name, const std::string& dir, const char *data, size_t size)
+void TileCache::saveRendering(const std::string& name, const std::string& dir, const char *data, std::size_t size)
{
// can fonts be invalidated?
const std::string dirName = _cacheDir + "/" + dir;
diff --git a/wsd/TileCache.hpp b/wsd/TileCache.hpp
index 52fb104ff..db922691d 100644
--- a/wsd/TileCache.hpp
+++ b/wsd/TileCache.hpp
@@ -34,7 +34,7 @@ public:
/// When the docURL is a non-file:// url, the timestamp has to be provided by the caller.
/// For file:// url's, it's ignored.
/// When it is missing for non-file:// url, it is assumed the document must be read, and no cached value used.
- TileCache(const std::string& docURL, const Poco::Timestamp& modifiedTime, const std::string& cacheDir);
+ TileCache(const std::string& docURL, const Poco::Timestamp& modifiedTime, const std::string& cacheDir, bool tileCachePersistent);
~TileCache();
/// Remove the entire cache directory.
@@ -114,6 +114,8 @@ private:
const std::string _cacheDir;
+ const bool _tileCachePersistent;
+
std::thread::id _owner;
std::map<std::string, std::shared_ptr<TileBeingRendered> > _tilesBeingRendered;
More information about the Libreoffice-commits
mailing list