2015-12-12 13:23:44 -06:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
|
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*/
|
|
|
|
|
2017-12-20 07:06:26 -06:00
|
|
|
#include <config.h>
|
2016-04-15 09:13:04 -05:00
|
|
|
|
2017-03-08 10:38:22 -06:00
|
|
|
#include "ChildSession.hpp"
|
|
|
|
|
2016-08-30 00:19:49 -05:00
|
|
|
#include <sstream>
|
|
|
|
|
2017-12-04 13:11:02 -06:00
|
|
|
#define LOK_USE_UNSTABLE_API
|
|
|
|
#include <LibreOfficeKit/LibreOfficeKitEnums.h>
|
|
|
|
|
2015-12-12 13:23:44 -06:00
|
|
|
#include <Poco/JSON/Object.h>
|
|
|
|
#include <Poco/JSON/Parser.h>
|
|
|
|
#include <Poco/Net/WebSocket.h>
|
|
|
|
#include <Poco/StringTokenizer.h>
|
|
|
|
#include <Poco/URI.h>
|
|
|
|
|
2017-12-20 07:06:26 -06:00
|
|
|
#include <common/FileUtil.hpp>
|
2016-11-24 08:56:06 -06:00
|
|
|
#include "KitHelper.hpp"
|
2017-12-20 07:06:26 -06:00
|
|
|
#include <Log.hpp>
|
|
|
|
#include <Png.hpp>
|
|
|
|
#include <Util.hpp>
|
2015-12-12 13:23:44 -06:00
|
|
|
|
|
|
|
using Poco::JSON::Object;
|
|
|
|
using Poco::JSON::Parser;
|
|
|
|
using Poco::StringTokenizer;
|
2016-04-04 05:29:02 -05:00
|
|
|
using Poco::Timestamp;
|
2015-12-12 13:23:44 -06:00
|
|
|
using Poco::URI;
|
|
|
|
|
2016-08-13 18:17:03 -05:00
|
|
|
using namespace LOOLProtocol;
|
|
|
|
|
2016-05-17 06:35:07 -05:00
|
|
|
std::recursive_mutex ChildSession::Mutex;
|
2015-12-19 14:55:19 -06:00
|
|
|
|
2016-05-17 06:35:07 -05:00
|
|
|
ChildSession::ChildSession(const std::string& id,
|
2016-05-17 17:28:59 -05:00
|
|
|
const std::string& jailId,
|
2018-09-12 11:05:01 -05:00
|
|
|
DocumentManagerInterface& docManager) :
|
2017-03-30 09:59:59 -05:00
|
|
|
Session("ToMaster-" + id, id, false),
|
2016-01-06 21:47:01 -06:00
|
|
|
_jailId(jailId),
|
2016-08-21 11:56:58 -05:00
|
|
|
_docManager(docManager),
|
2016-08-17 18:51:34 -05:00
|
|
|
_viewId(-1),
|
2018-02-25 13:18:04 -06:00
|
|
|
_isDocLoaded(false),
|
|
|
|
_copyToClipboard(false)
|
2015-12-12 13:23:44 -06:00
|
|
|
{
|
2016-11-05 16:29:38 -05:00
|
|
|
LOG_INF("ChildSession ctor [" << getName() << "].");
|
2015-12-12 13:23:44 -06:00
|
|
|
}
|
|
|
|
|
2016-05-17 06:35:07 -05:00
|
|
|
ChildSession::~ChildSession()
|
2015-12-12 13:23:44 -06:00
|
|
|
{
|
2016-11-05 16:29:38 -05:00
|
|
|
LOG_INF("~ChildSession dtor [" << getName() << "].");
|
2015-12-26 10:12:52 -06:00
|
|
|
|
2016-01-21 08:26:34 -06:00
|
|
|
disconnect();
|
|
|
|
}
|
|
|
|
|
2016-05-17 06:35:07 -05:00
|
|
|
void ChildSession::disconnect()
|
2016-01-21 08:26:34 -06:00
|
|
|
{
|
|
|
|
if (!isDisconnected())
|
|
|
|
{
|
2016-01-23 16:32:09 -06:00
|
|
|
std::unique_lock<std::recursive_mutex> lock(Mutex);
|
2016-01-08 11:59:57 -06:00
|
|
|
|
2016-08-17 18:51:34 -05:00
|
|
|
if (_viewId >= 0)
|
|
|
|
{
|
2016-08-21 10:12:12 -05:00
|
|
|
_docManager.onUnload(*this);
|
2016-08-17 18:51:34 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-11-05 16:29:38 -05:00
|
|
|
LOG_WRN("Skipping unload on incomplete view.");
|
2016-08-17 18:51:34 -05:00
|
|
|
}
|
2016-01-10 09:33:58 -06:00
|
|
|
|
2016-12-12 18:53:58 -06:00
|
|
|
Session::disconnect();
|
2016-01-21 08:26:34 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-17 06:35:07 -05:00
|
|
|
bool ChildSession::_handleInput(const char *buffer, int length)
|
2015-12-12 13:23:44 -06:00
|
|
|
{
|
2017-05-20 12:28:09 -05:00
|
|
|
LOG_TRC(getName() << ": handling [" << getAbbreviatedMessage(buffer, length) << "].");
|
2016-04-23 13:05:21 -05:00
|
|
|
const std::string firstLine = getFirstLine(buffer, length);
|
2018-02-07 03:17:28 -06:00
|
|
|
const std::vector<std::string> tokens = LOOLProtocol::tokenize(firstLine.data(), firstLine.size());
|
2016-04-23 13:05:21 -05:00
|
|
|
|
2016-08-15 18:06:42 -05:00
|
|
|
if (LOOLProtocol::tokenIndicatesUserInteraction(tokens[0]))
|
|
|
|
{
|
|
|
|
// Keep track of timestamps of incoming client messages that indicate user activity.
|
|
|
|
updateLastActivityTime();
|
|
|
|
}
|
|
|
|
|
2017-01-19 19:44:39 -06:00
|
|
|
if (tokens.size() > 0 && tokens[0] == "useractive" && getLOKitDocument() != nullptr)
|
2016-01-24 14:24:11 -06:00
|
|
|
{
|
2016-11-05 16:29:38 -05:00
|
|
|
LOG_DBG("Handling message after inactivity of " << getInactivityMS() << "ms.");
|
2016-08-15 18:06:42 -05:00
|
|
|
setIsActive(true);
|
2016-01-24 14:24:11 -06:00
|
|
|
|
|
|
|
// Client is getting active again.
|
|
|
|
// Send invalidation and other sync-up messages.
|
2016-08-17 18:51:34 -05:00
|
|
|
std::unique_lock<std::recursive_mutex> lock(Mutex); //TODO: Move to top of function?
|
2016-11-15 04:37:47 -06:00
|
|
|
std::unique_lock<std::mutex> lockLokDoc(_docManager.getDocumentMutex());
|
2016-01-24 14:24:11 -06:00
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
getLOKitDocument()->setView(_viewId);
|
2016-01-24 14:24:11 -06:00
|
|
|
|
2016-11-15 05:50:58 -06:00
|
|
|
int curPart = 0;
|
|
|
|
if (getLOKitDocument()->getDocumentType() != LOK_DOCTYPE_TEXT)
|
|
|
|
curPart = getLOKitDocument()->getPart();
|
2016-10-05 21:06:02 -05:00
|
|
|
|
|
|
|
// Notify all views about updated view info
|
2017-05-28 22:59:12 -05:00
|
|
|
_docManager.notifyViewInfo();
|
|
|
|
|
|
|
|
lockLokDoc.unlock();
|
2016-10-05 21:06:02 -05:00
|
|
|
|
2016-12-01 05:25:16 -06:00
|
|
|
if (getLOKitDocument()->getDocumentType() != LOK_DOCTYPE_TEXT)
|
|
|
|
{
|
|
|
|
sendTextFrame("curpart: part=" + std::to_string(curPart));
|
|
|
|
sendTextFrame("setpart: part=" + std::to_string(curPart));
|
|
|
|
}
|
2016-01-24 14:24:11 -06:00
|
|
|
|
2017-04-24 12:19:18 -05:00
|
|
|
// Invalidate if we have to
|
|
|
|
// TODO instead just a "_invalidate" flag, we should remember / grow
|
|
|
|
// the rectangle to invalidate; invalidating everything is sub-optimal
|
|
|
|
if (_stateRecorder._invalidate)
|
|
|
|
{
|
|
|
|
std::string payload = "0, 0, " + std::to_string(INT_MAX) + ", " + std::to_string(INT_MAX) + ", " + std::to_string(curPart);
|
|
|
|
loKitCallback(LOK_CALLBACK_INVALIDATE_TILES, payload);
|
|
|
|
}
|
|
|
|
|
2017-01-02 07:21:49 -06:00
|
|
|
for (const auto& viewPair : _stateRecorder._recordedViewEvents)
|
2016-04-21 23:28:52 -05:00
|
|
|
{
|
2017-04-24 12:19:18 -05:00
|
|
|
for (const auto& eventPair : viewPair.second)
|
|
|
|
{
|
|
|
|
const RecordedEvent& event = eventPair.second;
|
|
|
|
LOG_TRC("Replaying missed view event: " << viewPair.first << " " << LOKitHelper::kitCallbackTypeToString(event._type)
|
|
|
|
<< ": " << event._payload);
|
|
|
|
loKitCallback(event._type, event._payload);
|
|
|
|
}
|
2016-04-21 23:28:52 -05:00
|
|
|
}
|
2016-01-24 14:24:11 -06:00
|
|
|
|
2017-01-02 07:21:49 -06:00
|
|
|
for (const auto& eventPair : _stateRecorder._recordedEvents)
|
2016-11-01 08:24:14 -05:00
|
|
|
{
|
2017-01-02 07:21:49 -06:00
|
|
|
const RecordedEvent& event = eventPair.second;
|
|
|
|
LOG_TRC("Replaying missed event: " << LOKitHelper::kitCallbackTypeToString(event._type) << ": " << event._payload);
|
|
|
|
loKitCallback(event._type, event._payload);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const auto& pair : _stateRecorder._recordedStates)
|
|
|
|
{
|
|
|
|
LOG_TRC("Replaying missed state-change: " << pair.second);
|
2016-11-01 08:24:14 -05:00
|
|
|
loKitCallback(LOK_CALLBACK_STATE_CHANGED, pair.second);
|
|
|
|
}
|
|
|
|
|
2017-04-25 11:17:50 -05:00
|
|
|
for (const auto& event : _stateRecorder._recordedEventsVector)
|
|
|
|
{
|
|
|
|
LOG_TRC("Replaying missed event (part of sequence): " << LOKitHelper::kitCallbackTypeToString(event._type) << ": " << event._payload);
|
|
|
|
loKitCallback(event._type, event._payload);
|
|
|
|
}
|
|
|
|
|
2017-01-02 07:21:49 -06:00
|
|
|
_stateRecorder.clear();
|
|
|
|
|
2016-11-05 16:29:38 -05:00
|
|
|
LOG_TRC("Finished replaying messages.");
|
2016-04-09 22:16:09 -05:00
|
|
|
}
|
|
|
|
|
2016-03-23 11:55:28 -05:00
|
|
|
if (tokens[0] == "dummymsg")
|
|
|
|
{
|
2016-05-21 10:47:13 -05:00
|
|
|
// Just to update the activity of a view-only client.
|
2016-03-23 11:55:28 -05:00
|
|
|
return true;
|
|
|
|
}
|
2015-12-12 13:23:44 -06:00
|
|
|
else if (tokens[0] == "commandvalues")
|
|
|
|
{
|
|
|
|
return getCommandValues(buffer, length, tokens);
|
|
|
|
}
|
|
|
|
else if (tokens[0] == "load")
|
|
|
|
{
|
2016-02-04 11:35:26 -06:00
|
|
|
if (_isDocLoaded)
|
2015-12-12 13:23:44 -06:00
|
|
|
{
|
|
|
|
sendTextFrame("error: cmd=load kind=docalreadyloaded");
|
|
|
|
return false;
|
|
|
|
}
|
2016-01-08 11:59:57 -06:00
|
|
|
|
2016-02-04 11:35:26 -06:00
|
|
|
_isDocLoaded = loadDocument(buffer, length, tokens);
|
2016-05-11 20:16:10 -05:00
|
|
|
if (!_isDocLoaded)
|
|
|
|
{
|
|
|
|
sendTextFrame("error: cmd=load kind=faileddocloading");
|
|
|
|
}
|
|
|
|
|
2016-02-04 11:35:26 -06:00
|
|
|
return _isDocLoaded;
|
2015-12-12 13:23:44 -06:00
|
|
|
}
|
2016-02-04 11:35:26 -06:00
|
|
|
else if (!_isDocLoaded)
|
2015-12-12 13:23:44 -06:00
|
|
|
{
|
|
|
|
sendTextFrame("error: cmd=" + tokens[0] + " kind=nodocloaded");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if (tokens[0] == "renderfont")
|
|
|
|
{
|
|
|
|
sendFontRendering(buffer, length, tokens);
|
|
|
|
}
|
|
|
|
else if (tokens[0] == "setclientpart")
|
|
|
|
{
|
|
|
|
return setClientPart(buffer, length, tokens);
|
|
|
|
}
|
|
|
|
else if (tokens[0] == "setpage")
|
|
|
|
{
|
|
|
|
return setPage(buffer, length, tokens);
|
|
|
|
}
|
|
|
|
else if (tokens[0] == "status")
|
|
|
|
{
|
|
|
|
return getStatus(buffer, length);
|
|
|
|
}
|
2017-12-04 10:43:50 -06:00
|
|
|
else if (tokens[0] == "paintwindow")
|
2017-11-24 14:31:14 -06:00
|
|
|
{
|
2017-12-04 10:43:50 -06:00
|
|
|
return renderWindow(buffer, length, tokens);
|
2017-11-24 14:31:14 -06:00
|
|
|
}
|
2016-05-03 06:47:58 -05:00
|
|
|
else if (tokens[0] == "tile" || tokens[0] == "tilecombine")
|
2015-12-12 13:23:44 -06:00
|
|
|
{
|
2016-07-13 02:22:35 -05:00
|
|
|
assert(false && "Tile traffic should go through the DocumentBroker-LoKit WS.");
|
2015-12-12 13:23:44 -06:00
|
|
|
}
|
2018-09-11 01:30:55 -05:00
|
|
|
else if (tokens[0] == "requestloksession" ||
|
|
|
|
tokens[0] == "canceltiles")
|
|
|
|
{
|
|
|
|
// Just ignore these.
|
|
|
|
// FIXME: We probably should do something for "canceltiles" at least?
|
|
|
|
}
|
2015-12-12 13:23:44 -06:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// All other commands are such that they always require a LibreOfficeKitDocument session,
|
|
|
|
// i.e. need to be handled in a child process.
|
|
|
|
|
|
|
|
assert(tokens[0] == "clientzoom" ||
|
2016-02-02 04:48:41 -06:00
|
|
|
tokens[0] == "clientvisiblearea" ||
|
2017-11-28 16:38:35 -06:00
|
|
|
tokens[0] == "outlinestate" ||
|
2015-12-12 13:23:44 -06:00
|
|
|
tokens[0] == "downloadas" ||
|
|
|
|
tokens[0] == "getchildid" ||
|
|
|
|
tokens[0] == "gettextselection" ||
|
|
|
|
tokens[0] == "paste" ||
|
|
|
|
tokens[0] == "insertfile" ||
|
|
|
|
tokens[0] == "key" ||
|
2018-02-07 12:30:45 -06:00
|
|
|
tokens[0] == "textinput" ||
|
2017-12-04 10:43:50 -06:00
|
|
|
tokens[0] == "windowkey" ||
|
2015-12-12 13:23:44 -06:00
|
|
|
tokens[0] == "mouse" ||
|
2017-12-04 10:43:50 -06:00
|
|
|
tokens[0] == "windowmouse" ||
|
2015-12-12 13:23:44 -06:00
|
|
|
tokens[0] == "uno" ||
|
|
|
|
tokens[0] == "selecttext" ||
|
|
|
|
tokens[0] == "selectgraphic" ||
|
|
|
|
tokens[0] == "resetselection" ||
|
2016-04-21 00:14:27 -05:00
|
|
|
tokens[0] == "saveas" ||
|
|
|
|
tokens[0] == "useractive" ||
|
2017-12-04 13:11:02 -06:00
|
|
|
tokens[0] == "userinactive" ||
|
|
|
|
tokens[0] == "windowcommand");
|
2015-12-12 13:23:44 -06:00
|
|
|
|
|
|
|
if (tokens[0] == "clientzoom")
|
|
|
|
{
|
|
|
|
return clientZoom(buffer, length, tokens);
|
|
|
|
}
|
2016-02-02 04:48:41 -06:00
|
|
|
else if (tokens[0] == "clientvisiblearea")
|
|
|
|
{
|
|
|
|
return clientVisibleArea(buffer, length, tokens);
|
|
|
|
}
|
2017-11-28 16:38:35 -06:00
|
|
|
else if (tokens[0] == "outlinestate")
|
|
|
|
{
|
|
|
|
return outlineState(buffer, length, tokens);
|
|
|
|
}
|
2015-12-12 13:23:44 -06:00
|
|
|
else if (tokens[0] == "downloadas")
|
|
|
|
{
|
|
|
|
return downloadAs(buffer, length, tokens);
|
|
|
|
}
|
|
|
|
else if (tokens[0] == "getchildid")
|
|
|
|
{
|
|
|
|
return getChildId();
|
|
|
|
}
|
|
|
|
else if (tokens[0] == "gettextselection")
|
|
|
|
{
|
|
|
|
return getTextSelection(buffer, length, tokens);
|
|
|
|
}
|
|
|
|
else if (tokens[0] == "paste")
|
|
|
|
{
|
|
|
|
return paste(buffer, length, tokens);
|
|
|
|
}
|
|
|
|
else if (tokens[0] == "insertfile")
|
|
|
|
{
|
|
|
|
return insertFile(buffer, length, tokens);
|
|
|
|
}
|
|
|
|
else if (tokens[0] == "key")
|
|
|
|
{
|
2017-08-24 06:47:40 -05:00
|
|
|
return keyEvent(buffer, length, tokens, LokEventTargetEnum::Document);
|
|
|
|
}
|
2018-02-07 12:30:45 -06:00
|
|
|
else if (tokens[0] == "textinput")
|
|
|
|
{
|
|
|
|
return extTextInputEvent(buffer, length, tokens);
|
|
|
|
}
|
2017-12-04 10:43:50 -06:00
|
|
|
else if (tokens[0] == "windowkey")
|
2017-08-24 06:47:40 -05:00
|
|
|
{
|
2017-12-04 10:43:50 -06:00
|
|
|
return keyEvent(buffer, length, tokens, LokEventTargetEnum::Window);
|
2015-12-12 13:23:44 -06:00
|
|
|
}
|
|
|
|
else if (tokens[0] == "mouse")
|
|
|
|
{
|
2017-08-24 06:47:40 -05:00
|
|
|
return mouseEvent(buffer, length, tokens, LokEventTargetEnum::Document);
|
|
|
|
}
|
2017-12-04 10:43:50 -06:00
|
|
|
else if (tokens[0] == "windowmouse")
|
2017-08-24 06:47:40 -05:00
|
|
|
{
|
2017-12-04 10:43:50 -06:00
|
|
|
return mouseEvent(buffer, length, tokens, LokEventTargetEnum::Window);
|
2015-12-12 13:23:44 -06:00
|
|
|
}
|
|
|
|
else if (tokens[0] == "uno")
|
|
|
|
{
|
|
|
|
return unoCommand(buffer, length, tokens);
|
|
|
|
}
|
|
|
|
else if (tokens[0] == "selecttext")
|
|
|
|
{
|
|
|
|
return selectText(buffer, length, tokens);
|
|
|
|
}
|
|
|
|
else if (tokens[0] == "selectgraphic")
|
|
|
|
{
|
|
|
|
return selectGraphic(buffer, length, tokens);
|
|
|
|
}
|
|
|
|
else if (tokens[0] == "resetselection")
|
|
|
|
{
|
|
|
|
return resetSelection(buffer, length, tokens);
|
|
|
|
}
|
|
|
|
else if (tokens[0] == "saveas")
|
|
|
|
{
|
|
|
|
return saveAs(buffer, length, tokens);
|
|
|
|
}
|
2016-04-21 00:14:27 -05:00
|
|
|
else if (tokens[0] == "useractive")
|
|
|
|
{
|
|
|
|
setIsActive(true);
|
|
|
|
}
|
|
|
|
else if (tokens[0] == "userinactive")
|
|
|
|
{
|
|
|
|
setIsActive(false);
|
|
|
|
}
|
2017-12-04 13:11:02 -06:00
|
|
|
else if (tokens[0] == "windowcommand")
|
|
|
|
{
|
|
|
|
sendWindowCommand(buffer, length, tokens);
|
|
|
|
}
|
2015-12-12 13:23:44 -06:00
|
|
|
else
|
|
|
|
{
|
2016-07-13 02:22:35 -05:00
|
|
|
assert(false && "Unknown command token.");
|
2015-12-12 13:23:44 -06:00
|
|
|
}
|
|
|
|
}
|
2016-05-21 10:47:13 -05:00
|
|
|
|
2015-12-12 13:23:44 -06:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-01-19 19:44:39 -06:00
|
|
|
bool ChildSession::loadDocument(const char * /*buffer*/, int /*length*/, const std::vector<std::string>& tokens)
|
2015-12-12 13:23:44 -06:00
|
|
|
{
|
|
|
|
int part = -1;
|
2017-01-19 19:44:39 -06:00
|
|
|
if (tokens.size() < 2)
|
2015-12-12 13:23:44 -06:00
|
|
|
{
|
|
|
|
sendTextFrame("error: cmd=load kind=syntax");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string timestamp;
|
|
|
|
parseDocOptions(tokens, part, timestamp);
|
|
|
|
|
2016-04-27 19:51:54 -05:00
|
|
|
std::string renderOpts;
|
2016-04-27 19:42:45 -05:00
|
|
|
if (!_docOptions.empty())
|
|
|
|
{
|
|
|
|
Parser parser;
|
|
|
|
Poco::Dynamic::Var var = parser.parse(_docOptions);
|
|
|
|
Object::Ptr object = var.extract<Object::Ptr>();
|
2016-08-29 09:21:47 -05:00
|
|
|
Poco::Dynamic::Var rendering = object->get("rendering");
|
|
|
|
if (!rendering.isEmpty())
|
|
|
|
renderOpts = rendering.toString();
|
2016-04-27 19:42:45 -05:00
|
|
|
}
|
|
|
|
|
2016-01-06 23:33:54 -06:00
|
|
|
assert(!_docURL.empty());
|
|
|
|
assert(!_jailedFilePath.empty());
|
2015-12-12 13:23:44 -06:00
|
|
|
|
2016-04-30 09:27:49 -05:00
|
|
|
std::unique_lock<std::recursive_mutex> lock(Mutex);
|
|
|
|
|
2017-09-04 08:40:04 -05:00
|
|
|
bool loaded = _docManager.onLoad(getId(), _jailedFilePath, _userName,
|
|
|
|
_docPassword, renderOpts, _haveDocPassword, _lang, _watermarkText);
|
2016-11-15 04:37:47 -06:00
|
|
|
if (!loaded || _viewId < 0)
|
2016-04-27 19:42:45 -05:00
|
|
|
{
|
2016-11-05 16:29:38 -05:00
|
|
|
LOG_ERR("Failed to get LoKitDocument instance.");
|
2016-02-04 11:35:26 -06:00
|
|
|
return false;
|
2016-04-27 19:42:45 -05:00
|
|
|
}
|
2016-02-04 11:35:26 -06:00
|
|
|
|
2017-05-20 12:28:09 -05:00
|
|
|
LOG_INF("Created new view with viewid: [" << _viewId << "] for username: [" <<
|
2016-11-05 16:29:38 -05:00
|
|
|
_userName << "] in session: [" << getId() << "].");
|
2016-10-05 21:06:02 -05:00
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
std::unique_lock<std::mutex> lockLokDoc(_docManager.getDocumentMutex());
|
2016-10-05 21:06:02 -05:00
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
getLOKitDocument()->setView(_viewId);
|
2016-10-05 21:06:02 -05:00
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
_docType = LOKitHelper::getDocumentTypeAsString(getLOKitDocument()->get());
|
2015-12-25 18:37:44 -06:00
|
|
|
if (_docType != "text" && part != -1)
|
2015-12-12 13:23:44 -06:00
|
|
|
{
|
2016-11-15 04:37:47 -06:00
|
|
|
getLOKitDocument()->setPart(part);
|
2015-12-12 13:23:44 -06:00
|
|
|
}
|
|
|
|
|
2016-08-15 02:10:45 -05:00
|
|
|
// Respond by the document status
|
2016-11-05 16:29:38 -05:00
|
|
|
LOG_DBG("Sending status after loading view " << _viewId << ".");
|
2018-02-07 03:17:28 -06:00
|
|
|
const std::string status = LOKitHelper::documentStatus(getLOKitDocument()->get());
|
2016-08-12 08:42:31 -05:00
|
|
|
if (status.empty() || !sendTextFrame("status: " + status))
|
|
|
|
{
|
2016-11-05 16:29:38 -05:00
|
|
|
LOG_ERR("Failed to get/forward document status [" << status << "].");
|
2015-12-12 13:23:44 -06:00
|
|
|
return false;
|
2016-08-12 08:42:31 -05:00
|
|
|
}
|
2015-12-12 13:23:44 -06:00
|
|
|
|
2016-09-20 05:29:53 -05:00
|
|
|
// Inform everyone (including this one) about updated view info
|
2017-05-28 22:59:12 -05:00
|
|
|
_docManager.notifyViewInfo();
|
2017-06-27 06:44:50 -05:00
|
|
|
sendTextFrame("editor: " + std::to_string(_docManager.getEditorId()));
|
|
|
|
|
2016-08-29 06:33:49 -05:00
|
|
|
|
2016-11-05 16:29:38 -05:00
|
|
|
LOG_INF("Loaded session " << getId());
|
2015-12-12 13:23:44 -06:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-01-19 19:44:39 -06:00
|
|
|
bool ChildSession::sendFontRendering(const char* /*buffer*/, int /*length*/, const std::vector<std::string>& tokens)
|
2015-12-12 13:23:44 -06:00
|
|
|
{
|
2016-11-27 17:49:17 -06:00
|
|
|
std::string font, text, decodedFont, decodedChar;
|
2016-11-29 18:22:23 -06:00
|
|
|
bool bSuccess;
|
2015-12-12 13:23:44 -06:00
|
|
|
|
2017-01-19 19:44:39 -06:00
|
|
|
if (tokens.size() < 3 ||
|
2015-12-12 13:23:44 -06:00
|
|
|
!getTokenString(tokens[1], "font", font))
|
|
|
|
{
|
|
|
|
sendTextFrame("error: cmd=renderfont kind=syntax");
|
2016-05-21 10:47:13 -05:00
|
|
|
return false;
|
2015-12-12 13:23:44 -06:00
|
|
|
}
|
|
|
|
|
2016-11-11 11:24:13 -06:00
|
|
|
getTokenString(tokens[2], "char", text);
|
|
|
|
|
2016-11-27 17:49:17 -06:00
|
|
|
try
|
|
|
|
{
|
|
|
|
URI::decode(font, decodedFont);
|
|
|
|
URI::decode(text, decodedChar);
|
|
|
|
}
|
|
|
|
catch (Poco::SyntaxException& exc)
|
|
|
|
{
|
|
|
|
LOG_DBG(exc.message());
|
|
|
|
sendTextFrame("error: cmd=renderfont kind=syntax");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-01-04 05:57:39 -06:00
|
|
|
const std::string response = "renderfont: " + Poco::cat(std::string(" "), tokens.begin() + 1, tokens.end()) + "\n";
|
2015-12-12 13:23:44 -06:00
|
|
|
|
|
|
|
std::vector<char> output;
|
|
|
|
output.resize(response.size());
|
|
|
|
std::memcpy(output.data(), response.data(), response.size());
|
|
|
|
|
2016-04-04 05:29:02 -05:00
|
|
|
Timestamp timestamp;
|
2017-09-04 08:40:04 -05:00
|
|
|
// renderFont use a default font size (25) when width and height are 0
|
|
|
|
int width = 0, height = 0;
|
2016-09-27 21:05:02 -05:00
|
|
|
unsigned char* ptrFont = nullptr;
|
|
|
|
|
|
|
|
{
|
2016-11-15 04:37:47 -06:00
|
|
|
std::unique_lock<std::mutex> lock(_docManager.getDocumentMutex());
|
2016-09-27 21:05:02 -05:00
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
getLOKitDocument()->setView(_viewId);
|
2016-09-27 21:05:02 -05:00
|
|
|
|
2016-11-27 17:49:17 -06:00
|
|
|
ptrFont = getLOKitDocument()->renderFont(decodedFont.c_str(), decodedChar.c_str(), &width, &height);
|
2016-09-27 21:05:02 -05:00
|
|
|
}
|
|
|
|
|
2016-11-05 16:29:38 -05:00
|
|
|
LOG_TRC("renderFont [" << font << "] rendered in " << (timestamp.elapsed()/1000.) << "ms");
|
2015-12-12 13:23:44 -06:00
|
|
|
|
2016-11-29 18:22:23 -06:00
|
|
|
if (!ptrFont)
|
2015-12-23 20:20:49 -06:00
|
|
|
{
|
2016-11-29 18:22:23 -06:00
|
|
|
return sendTextFrame(output.data(), output.size());
|
|
|
|
}
|
|
|
|
|
2017-12-15 10:08:00 -06:00
|
|
|
const auto mode = static_cast<LibreOfficeKitTileMode>(getLOKitDocument()->getTileMode());
|
|
|
|
|
|
|
|
if (Png::encodeBufferToPNG(ptrFont, width, height, output, mode))
|
2016-11-29 18:22:23 -06:00
|
|
|
{
|
|
|
|
bSuccess = sendTextFrame(output.data(), output.size());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bSuccess = sendTextFrame("error: cmd=renderfont kind=failure");
|
2015-12-12 13:23:44 -06:00
|
|
|
}
|
|
|
|
|
2016-05-31 09:12:03 -05:00
|
|
|
std::free(ptrFont);
|
2016-11-29 18:22:23 -06:00
|
|
|
return bSuccess;
|
2015-12-12 13:23:44 -06:00
|
|
|
}
|
|
|
|
|
2016-05-17 06:35:07 -05:00
|
|
|
bool ChildSession::getStatus(const char* /*buffer*/, int /*length*/)
|
2015-12-12 13:23:44 -06:00
|
|
|
{
|
2016-09-27 21:05:02 -05:00
|
|
|
std::string status;
|
|
|
|
{
|
2016-11-15 04:37:47 -06:00
|
|
|
std::unique_lock<std::mutex> lock(_docManager.getDocumentMutex());
|
2015-12-25 18:37:44 -06:00
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
getLOKitDocument()->setView(_viewId);
|
2016-09-27 21:05:02 -05:00
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
status = LOKitHelper::documentStatus(getLOKitDocument()->get());
|
2016-09-27 21:05:02 -05:00
|
|
|
}
|
2016-01-08 18:58:50 -06:00
|
|
|
|
2016-05-07 22:27:15 -05:00
|
|
|
if (status.empty())
|
2015-12-12 13:23:44 -06:00
|
|
|
{
|
2016-11-05 16:29:38 -05:00
|
|
|
LOG_ERR("Failed to get document status.");
|
2016-01-10 21:52:00 -06:00
|
|
|
return false;
|
2015-12-12 13:23:44 -06:00
|
|
|
}
|
2016-01-08 18:58:50 -06:00
|
|
|
|
2016-05-21 10:47:13 -05:00
|
|
|
return sendTextFrame("status: " + status);
|
2015-12-12 13:23:44 -06:00
|
|
|
}
|
|
|
|
|
2016-09-30 07:21:14 -05:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
|
|
|
/// Given a view ID <-> user name map and a .uno:DocumentRepair result, annotate with user names.
|
2016-10-26 10:08:25 -05:00
|
|
|
void insertUserNames(const std::map<int, UserInfo>& viewInfo, std::string& json)
|
2016-09-30 07:21:14 -05:00
|
|
|
{
|
|
|
|
Poco::JSON::Parser parser;
|
2018-02-07 03:17:28 -06:00
|
|
|
const Poco::JSON::Object::Ptr root = parser.parse(json).extract<Poco::JSON::Object::Ptr>();
|
2016-09-30 07:21:14 -05:00
|
|
|
std::vector<std::string> directions { "Undo", "Redo" };
|
|
|
|
for (auto& directionName : directions)
|
|
|
|
{
|
2018-02-07 03:17:28 -06:00
|
|
|
Poco::JSON::Object::Ptr direction = root->get(directionName).extract<Poco::JSON::Object::Ptr>();
|
2016-09-30 07:21:14 -05:00
|
|
|
if (direction->get("actions").type() == typeid(Poco::JSON::Array::Ptr))
|
|
|
|
{
|
2018-02-07 03:17:28 -06:00
|
|
|
Poco::JSON::Array::Ptr actions = direction->get("actions").extract<Poco::JSON::Array::Ptr>();
|
2016-09-30 07:21:14 -05:00
|
|
|
for (auto& actionVar : *actions)
|
|
|
|
{
|
2018-02-07 03:17:28 -06:00
|
|
|
Poco::JSON::Object::Ptr action = actionVar.extract<Poco::JSON::Object::Ptr>();
|
2016-09-30 07:21:14 -05:00
|
|
|
int viewId = action->getValue<int>("viewId");
|
|
|
|
auto it = viewInfo.find(viewId);
|
|
|
|
if (it != viewInfo.end())
|
2017-05-28 11:20:49 -05:00
|
|
|
action->set("userName", Poco::Dynamic::Var(it->second.Username));
|
2016-09-30 07:21:14 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
std::stringstream ss;
|
|
|
|
root->stringify(ss);
|
|
|
|
json = ss.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-01-19 19:44:39 -06:00
|
|
|
bool ChildSession::getCommandValues(const char* /*buffer*/, int /*length*/, const std::vector<std::string>& tokens)
|
2015-12-12 13:23:44 -06:00
|
|
|
{
|
2016-08-28 07:46:38 -05:00
|
|
|
bool success;
|
2017-01-13 06:52:08 -06:00
|
|
|
char* values;
|
2015-12-12 13:23:44 -06:00
|
|
|
std::string command;
|
2017-01-19 19:44:39 -06:00
|
|
|
if (tokens.size() != 2 || !getTokenString(tokens[1], "command", command))
|
2015-12-12 13:23:44 -06:00
|
|
|
{
|
|
|
|
sendTextFrame("error: cmd=commandvalues kind=syntax");
|
|
|
|
return false;
|
|
|
|
}
|
2016-01-07 08:40:41 -06:00
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
std::unique_lock<std::mutex> lock(_docManager.getDocumentMutex());
|
2016-01-07 08:40:41 -06:00
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
getLOKitDocument()->setView(_viewId);
|
2016-01-08 18:58:50 -06:00
|
|
|
|
2016-08-28 07:46:38 -05:00
|
|
|
if (command == ".uno:DocumentRepair")
|
|
|
|
{
|
2017-01-13 06:52:08 -06:00
|
|
|
char* undo;
|
2016-09-30 07:21:14 -05:00
|
|
|
const std::string jsonTemplate("{\"commandName\":\".uno:DocumentRepair\",\"Redo\":%s,\"Undo\":%s}");
|
2017-01-13 06:52:08 -06:00
|
|
|
values = getLOKitDocument()->getCommandValues(".uno:Redo");
|
|
|
|
undo = getLOKitDocument()->getCommandValues(".uno:Undo");
|
2016-09-30 07:21:14 -05:00
|
|
|
std::string json = Poco::format(jsonTemplate,
|
2017-01-13 06:52:08 -06:00
|
|
|
std::string(values == nullptr ? "" : values),
|
|
|
|
std::string(undo == nullptr ? "" : undo));
|
2016-09-30 07:21:14 -05:00
|
|
|
// json only contains view IDs, insert matching user names.
|
2016-10-26 10:08:25 -05:00
|
|
|
std::map<int, UserInfo> viewInfo = _docManager.getViewInfo();
|
2016-09-30 07:21:14 -05:00
|
|
|
insertUserNames(viewInfo, json);
|
|
|
|
success = sendTextFrame("commandvalues: " + json);
|
2017-01-13 06:52:08 -06:00
|
|
|
std::free(values);
|
|
|
|
std::free(undo);
|
2016-08-28 07:46:38 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-01-13 06:52:08 -06:00
|
|
|
values = getLOKitDocument()->getCommandValues(command.c_str());
|
2018-02-21 19:44:09 -06:00
|
|
|
success = sendTextFrame("commandvalues: " + std::string(values == nullptr ? "{}" : values));
|
2017-01-13 06:52:08 -06:00
|
|
|
std::free(values);
|
2016-08-28 07:46:38 -05:00
|
|
|
}
|
|
|
|
|
2016-05-24 23:32:00 -05:00
|
|
|
return success;
|
2015-12-12 13:23:44 -06:00
|
|
|
}
|
|
|
|
|
2017-01-19 19:44:39 -06:00
|
|
|
bool ChildSession::clientZoom(const char* /*buffer*/, int /*length*/, const std::vector<std::string>& tokens)
|
2015-12-12 13:23:44 -06:00
|
|
|
{
|
2016-02-19 01:37:29 -06:00
|
|
|
int tilePixelWidth, tilePixelHeight, tileTwipWidth, tileTwipHeight;
|
2015-12-12 13:23:44 -06:00
|
|
|
|
2017-01-19 19:44:39 -06:00
|
|
|
if (tokens.size() != 5 ||
|
2015-12-12 13:23:44 -06:00
|
|
|
!getTokenInteger(tokens[1], "tilepixelwidth", tilePixelWidth) ||
|
|
|
|
!getTokenInteger(tokens[2], "tilepixelheight", tilePixelHeight) ||
|
|
|
|
!getTokenInteger(tokens[3], "tiletwipwidth", tileTwipWidth) ||
|
|
|
|
!getTokenInteger(tokens[4], "tiletwipheight", tileTwipHeight))
|
|
|
|
{
|
|
|
|
sendTextFrame("error: cmd=clientzoom kind=syntax");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
std::unique_lock<std::mutex> lock(_docManager.getDocumentMutex());
|
2016-01-07 08:40:41 -06:00
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
getLOKitDocument()->setView(_viewId);
|
2016-01-08 18:58:50 -06:00
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
getLOKitDocument()->setClientZoom(tilePixelWidth, tilePixelHeight, tileTwipWidth, tileTwipHeight);
|
2015-12-12 13:23:44 -06:00
|
|
|
return true;
|
|
|
|
}
|
2015-12-19 14:55:19 -06:00
|
|
|
|
2017-01-19 19:44:39 -06:00
|
|
|
bool ChildSession::clientVisibleArea(const char* /*buffer*/, int /*length*/, const std::vector<std::string>& tokens)
|
2016-02-02 04:48:41 -06:00
|
|
|
{
|
|
|
|
int x;
|
|
|
|
int y;
|
|
|
|
int width;
|
|
|
|
int height;
|
|
|
|
|
2017-01-19 19:44:39 -06:00
|
|
|
if (tokens.size() != 5 ||
|
2016-02-02 04:48:41 -06:00
|
|
|
!getTokenInteger(tokens[1], "x", x) ||
|
|
|
|
!getTokenInteger(tokens[2], "y", y) ||
|
|
|
|
!getTokenInteger(tokens[3], "width", width) ||
|
|
|
|
!getTokenInteger(tokens[4], "height", height))
|
|
|
|
{
|
|
|
|
sendTextFrame("error: cmd=clientvisiblearea kind=syntax");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
std::unique_lock<std::mutex> lock(_docManager.getDocumentMutex());
|
2016-02-02 04:48:41 -06:00
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
getLOKitDocument()->setView(_viewId);
|
2016-02-02 04:48:41 -06:00
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
getLOKitDocument()->setClientVisibleArea(x, y, width, height);
|
2016-02-02 04:48:41 -06:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-11-28 16:38:35 -06:00
|
|
|
bool ChildSession::outlineState(const char* /*buffer*/, int /*length*/, const std::vector<std::string>& tokens)
|
|
|
|
{
|
|
|
|
std::string type, state;
|
|
|
|
int level, index;
|
|
|
|
|
|
|
|
if (tokens.size() != 5 ||
|
|
|
|
!getTokenString(tokens[1], "type", type) ||
|
|
|
|
(type != "column" && type != "row") ||
|
|
|
|
!getTokenInteger(tokens[2], "level", level) ||
|
|
|
|
!getTokenInteger(tokens[3], "index", index) ||
|
|
|
|
!getTokenString(tokens[4], "state", state) ||
|
|
|
|
(state != "visible" && state != "hidden"))
|
|
|
|
{
|
|
|
|
sendTextFrame("error: cmd=outlinestate kind=syntax");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool column = type == "column";
|
|
|
|
bool hidden = state == "hidden";
|
|
|
|
|
|
|
|
std::unique_lock<std::mutex> lock(_docManager.getDocumentMutex());
|
|
|
|
|
|
|
|
getLOKitDocument()->setView(_viewId);
|
|
|
|
|
|
|
|
getLOKitDocument()->setOutlineState(column, level, index, hidden);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-01-19 19:44:39 -06:00
|
|
|
bool ChildSession::downloadAs(const char* /*buffer*/, int /*length*/, const std::vector<std::string>& tokens)
|
2015-12-12 13:23:44 -06:00
|
|
|
{
|
|
|
|
std::string name, id, format, filterOptions;
|
|
|
|
|
2017-01-19 19:44:39 -06:00
|
|
|
if (tokens.size() < 5 ||
|
2015-12-12 13:23:44 -06:00
|
|
|
!getTokenString(tokens[1], "name", name) ||
|
|
|
|
!getTokenString(tokens[2], "id", id))
|
|
|
|
{
|
|
|
|
sendTextFrame("error: cmd=downloadas kind=syntax");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
getTokenString(tokens[3], "format", format);
|
|
|
|
|
|
|
|
if (getTokenString(tokens[4], "options", filterOptions))
|
|
|
|
{
|
2017-01-19 19:44:39 -06:00
|
|
|
if (tokens.size() > 5)
|
2015-12-12 13:23:44 -06:00
|
|
|
{
|
|
|
|
filterOptions += Poco::cat(std::string(" "), tokens.begin() + 5, tokens.end());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-30 19:42:44 -05:00
|
|
|
// The file is removed upon downloading.
|
2018-02-07 03:17:28 -06:00
|
|
|
const std::string tmpDir = FileUtil::createRandomDir(JAILED_DOCUMENT_ROOT);
|
2016-07-21 05:31:35 -05:00
|
|
|
// Prevent user inputting anything funny here.
|
|
|
|
// A "name" should always be a name, not a path
|
|
|
|
const Poco::Path filenameParam(name);
|
|
|
|
const auto url = JAILED_DOCUMENT_ROOT + tmpDir + "/" + filenameParam.getFileName();
|
2015-12-12 13:23:44 -06:00
|
|
|
|
2016-09-27 21:05:02 -05:00
|
|
|
{
|
2016-11-15 04:37:47 -06:00
|
|
|
std::unique_lock<std::mutex> lock(_docManager.getDocumentMutex());
|
2016-01-07 08:40:41 -06:00
|
|
|
|
2017-11-06 05:44:37 -06:00
|
|
|
LOG_DBG("Calling LOK's downloadAs with: '" << url.c_str() << "', '" <<
|
|
|
|
(format.size() == 0 ? "(nullptr)" : format.c_str()) << "', '" <<
|
|
|
|
(filterOptions.size() == 0 ? "(nullptr)" : filterOptions.c_str()) << "'.");
|
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
getLOKitDocument()->saveAs(url.c_str(),
|
2016-09-27 21:05:02 -05:00
|
|
|
format.size() == 0 ? nullptr :format.c_str(),
|
|
|
|
filterOptions.size() == 0 ? nullptr : filterOptions.c_str());
|
|
|
|
}
|
2015-12-12 13:23:44 -06:00
|
|
|
|
2016-01-06 21:47:01 -06:00
|
|
|
sendTextFrame("downloadas: jail=" + _jailId + " dir=" + tmpDir + " name=" + name +
|
2016-01-07 08:40:41 -06:00
|
|
|
" port=" + std::to_string(ClientPortNumber) + " id=" + id);
|
2015-12-12 13:23:44 -06:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-05-17 06:35:07 -05:00
|
|
|
bool ChildSession::getChildId()
|
2015-12-12 13:23:44 -06:00
|
|
|
{
|
2016-01-06 21:47:01 -06:00
|
|
|
sendTextFrame("getchildid: id=" + _jailId);
|
2015-12-12 13:23:44 -06:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-02-25 13:18:04 -06:00
|
|
|
std::string ChildSession::getTextSelectionInternal(const std::string& mimeType)
|
2015-12-12 13:23:44 -06:00
|
|
|
{
|
2016-09-27 21:05:02 -05:00
|
|
|
char* textSelection = nullptr;
|
|
|
|
{
|
2016-11-15 04:37:47 -06:00
|
|
|
std::unique_lock<std::mutex> lock(_docManager.getDocumentMutex());
|
2016-01-07 08:40:41 -06:00
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
getLOKitDocument()->setView(_viewId);
|
2016-01-08 18:58:50 -06:00
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
textSelection = getLOKitDocument()->getTextSelection(mimeType.c_str(), nullptr);
|
2016-09-27 21:05:02 -05:00
|
|
|
}
|
2015-12-12 13:23:44 -06:00
|
|
|
|
2018-02-25 13:18:04 -06:00
|
|
|
std::string str(textSelection ? textSelection : "");
|
2016-03-12 11:17:34 -06:00
|
|
|
free(textSelection);
|
2018-02-25 13:18:04 -06:00
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ChildSession::getTextSelection(const char* /*buffer*/, int /*length*/, const std::vector<std::string>& tokens)
|
|
|
|
{
|
|
|
|
std::string mimeType;
|
|
|
|
|
|
|
|
if (tokens.size() != 2 ||
|
|
|
|
!getTokenString(tokens[1], "mimetype", mimeType))
|
|
|
|
{
|
|
|
|
sendTextFrame("error: cmd=gettextselection kind=syntax");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
sendTextFrame("textselectioncontent: " + getTextSelectionInternal(mimeType));
|
2015-12-12 13:23:44 -06:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-01-19 19:44:39 -06:00
|
|
|
bool ChildSession::paste(const char* buffer, int length, const std::vector<std::string>& tokens)
|
2015-12-12 13:23:44 -06:00
|
|
|
{
|
|
|
|
std::string mimeType;
|
2017-02-09 20:15:25 -06:00
|
|
|
if (tokens.size() < 2 || !getTokenString(tokens[1], "mimetype", mimeType) ||
|
|
|
|
mimeType.empty())
|
2015-12-12 13:23:44 -06:00
|
|
|
{
|
|
|
|
sendTextFrame("error: cmd=paste kind=syntax");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-01-15 07:42:02 -06:00
|
|
|
const std::string firstLine = getFirstLine(buffer, length);
|
|
|
|
const char* data = buffer + firstLine.size() + 1;
|
2017-02-09 20:15:25 -06:00
|
|
|
const int size = length - firstLine.size() - 1;
|
|
|
|
if (size > 0)
|
|
|
|
{
|
|
|
|
std::unique_lock<std::mutex> lock(_docManager.getDocumentMutex());
|
2015-12-25 18:37:44 -06:00
|
|
|
|
2017-02-09 20:15:25 -06:00
|
|
|
getLOKitDocument()->setView(_viewId);
|
2016-01-08 18:58:50 -06:00
|
|
|
|
2017-02-09 20:15:25 -06:00
|
|
|
getLOKitDocument()->paste(mimeType.c_str(), data, size);
|
|
|
|
}
|
2015-12-12 13:23:44 -06:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-01-19 19:44:39 -06:00
|
|
|
bool ChildSession::insertFile(const char* /*buffer*/, int /*length*/, const std::vector<std::string>& tokens)
|
2015-12-12 13:23:44 -06:00
|
|
|
{
|
|
|
|
std::string name, type;
|
2017-01-19 19:44:39 -06:00
|
|
|
if (tokens.size() != 3 ||
|
2015-12-12 13:23:44 -06:00
|
|
|
!getTokenString(tokens[1], "name", name) ||
|
|
|
|
!getTokenString(tokens[2], "type", type))
|
|
|
|
{
|
|
|
|
sendTextFrame("error: cmd=insertfile kind=syntax");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type == "graphic")
|
|
|
|
{
|
2016-03-28 06:01:19 -05:00
|
|
|
std::string fileName = "file://" + std::string(JAILED_DOCUMENT_ROOT) + "insertfile/" + name;
|
2015-12-12 13:23:44 -06:00
|
|
|
std::string command = ".uno:InsertGraphic";
|
|
|
|
std::string arguments = "{"
|
|
|
|
"\"FileName\":{"
|
|
|
|
"\"type\":\"string\","
|
|
|
|
"\"value\":\"" + fileName + "\""
|
|
|
|
"}}";
|
2016-09-19 02:03:31 -05:00
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
std::unique_lock<std::mutex> lock(_docManager.getDocumentMutex());
|
2016-09-27 21:05:02 -05:00
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
getLOKitDocument()->setView(_viewId);
|
2016-01-08 18:58:50 -06:00
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
getLOKitDocument()->postUnoCommand(command.c_str(), arguments.c_str(), false);
|
2015-12-12 13:23:44 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-02-07 12:30:45 -06:00
|
|
|
bool ChildSession::extTextInputEvent(const char* /*buffer*/, int /*length*/,
|
|
|
|
const std::vector<std::string>& tokens)
|
|
|
|
{
|
2018-02-13 11:35:54 -06:00
|
|
|
int id, type;
|
2018-02-07 12:30:45 -06:00
|
|
|
std::string text;
|
2018-02-13 11:35:54 -06:00
|
|
|
if (tokens.size() < 4 ||
|
|
|
|
!getTokenInteger(tokens[1], "id", id) || id < 0 ||
|
|
|
|
!getTokenKeyword(tokens[2], "type",
|
2018-02-07 12:30:45 -06:00
|
|
|
{{"input", LOK_EXT_TEXTINPUT}, {"end", LOK_EXT_TEXTINPUT_END}},
|
|
|
|
type) ||
|
2018-02-13 11:35:54 -06:00
|
|
|
!getTokenString(tokens[3], "text", text))
|
|
|
|
|
2018-02-07 12:30:45 -06:00
|
|
|
{
|
|
|
|
sendTextFrame("error: cmd=" + std::string(tokens[0]) + " kind=syntax");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-02-21 09:59:50 -06:00
|
|
|
std::string decodedText;
|
|
|
|
URI::decode(text, decodedText);
|
|
|
|
|
2018-02-07 12:30:45 -06:00
|
|
|
std::unique_lock<std::mutex> lock(_docManager.getDocumentMutex());
|
|
|
|
getLOKitDocument()->setView(_viewId);
|
2018-02-21 10:35:18 -06:00
|
|
|
getLOKitDocument()->postWindowExtTextInputEvent(id, type, decodedText.c_str());
|
2018-02-07 12:30:45 -06:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-08-24 06:47:40 -05:00
|
|
|
bool ChildSession::keyEvent(const char* /*buffer*/, int /*length*/,
|
|
|
|
const std::vector<std::string>& tokens,
|
|
|
|
const LokEventTargetEnum target)
|
2015-12-12 13:23:44 -06:00
|
|
|
{
|
|
|
|
int type, charcode, keycode;
|
2017-12-04 10:43:50 -06:00
|
|
|
unsigned winId = 0;
|
2017-08-24 06:47:40 -05:00
|
|
|
unsigned counter = 1;
|
2017-11-24 14:31:14 -06:00
|
|
|
unsigned expectedTokens = 4; // cmdname(key), type, char, key are strictly required
|
2017-12-04 10:43:50 -06:00
|
|
|
if (target == LokEventTargetEnum::Window)
|
2017-08-24 06:47:40 -05:00
|
|
|
{
|
2017-11-24 14:31:14 -06:00
|
|
|
if (tokens.size() <= counter ||
|
2017-12-04 10:43:50 -06:00
|
|
|
!getTokenUInt32(tokens[counter++], "id", winId))
|
2017-11-24 14:31:14 -06:00
|
|
|
{
|
2017-12-04 10:43:50 -06:00
|
|
|
LOG_ERR("Window key event expects a valid id= attribute");
|
2017-11-24 14:31:14 -06:00
|
|
|
sendTextFrame("error: cmd=" + std::string(tokens[0]) + " kind=syntax");
|
|
|
|
return false;
|
|
|
|
}
|
2017-12-04 10:43:50 -06:00
|
|
|
else // id= attribute is found
|
2017-11-24 14:31:14 -06:00
|
|
|
expectedTokens++;
|
2017-08-24 06:47:40 -05:00
|
|
|
}
|
|
|
|
|
2017-11-24 14:31:14 -06:00
|
|
|
if (tokens.size() != expectedTokens ||
|
2017-08-24 06:47:40 -05:00
|
|
|
!getTokenKeyword(tokens[counter++], "type",
|
2015-12-12 13:23:44 -06:00
|
|
|
{{"input", LOK_KEYEVENT_KEYINPUT}, {"up", LOK_KEYEVENT_KEYUP}},
|
|
|
|
type) ||
|
2017-08-24 06:47:40 -05:00
|
|
|
!getTokenInteger(tokens[counter++], "char", charcode) ||
|
|
|
|
!getTokenInteger(tokens[counter++], "key", keycode))
|
2015-12-12 13:23:44 -06:00
|
|
|
{
|
2017-08-24 06:47:40 -05:00
|
|
|
sendTextFrame("error: cmd=" + std::string(tokens[0]) + " kind=syntax");
|
2015-12-12 13:23:44 -06:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-01-10 21:04:55 -06:00
|
|
|
// Don't close LO window!
|
2018-02-07 03:17:28 -06:00
|
|
|
constexpr int KEY_CTRL = 0x2000;
|
|
|
|
constexpr int KEY_W = 0x0216;
|
2016-01-10 21:04:55 -06:00
|
|
|
if (keycode == (KEY_CTRL | KEY_W))
|
2016-04-09 23:14:20 -05:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ctrl+Tab switching browser tabs,
|
|
|
|
// Doesn't insert tabs.
|
2018-02-07 03:17:28 -06:00
|
|
|
constexpr int KEY_TAB = 0x0502;
|
2016-04-09 23:14:20 -05:00
|
|
|
if (keycode == (KEY_CTRL | KEY_TAB))
|
|
|
|
{
|
2016-01-10 21:04:55 -06:00
|
|
|
return true;
|
2016-04-09 23:14:20 -05:00
|
|
|
}
|
2016-01-10 21:04:55 -06:00
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
std::unique_lock<std::mutex> lock(_docManager.getDocumentMutex());
|
2017-12-04 15:09:26 -06:00
|
|
|
getLOKitDocument()->setView(_viewId);
|
2017-08-24 06:47:40 -05:00
|
|
|
if (target == LokEventTargetEnum::Document)
|
|
|
|
getLOKitDocument()->postKeyEvent(type, charcode, keycode);
|
2017-12-04 10:43:50 -06:00
|
|
|
else if (winId != 0)
|
|
|
|
getLOKitDocument()->postWindowKeyEvent(winId, type, charcode, keycode);
|
2015-12-12 13:23:44 -06:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-08-24 06:47:40 -05:00
|
|
|
bool ChildSession::mouseEvent(const char* /*buffer*/, int /*length*/,
|
|
|
|
const std::vector<std::string>& tokens,
|
|
|
|
const LokEventTargetEnum target)
|
2015-12-12 13:23:44 -06:00
|
|
|
{
|
2016-02-08 08:44:13 -06:00
|
|
|
int type, x, y, count;
|
|
|
|
bool success = true;
|
2015-12-12 13:23:44 -06:00
|
|
|
|
2016-02-08 08:44:13 -06:00
|
|
|
// default values for compatibility reasons with older loleaflets
|
2016-02-09 02:14:16 -06:00
|
|
|
int buttons = 1; // left button
|
2016-02-08 08:44:13 -06:00
|
|
|
int modifier = 0;
|
|
|
|
|
2017-12-04 10:43:50 -06:00
|
|
|
unsigned winId = 0;
|
2017-08-24 06:47:40 -05:00
|
|
|
unsigned counter = 1;
|
2017-11-24 14:31:14 -06:00
|
|
|
unsigned minTokens = 5; // cmdname(mouse), type, x, y, count are strictly required
|
2017-12-04 10:43:50 -06:00
|
|
|
if (target == LokEventTargetEnum::Window)
|
2017-08-24 06:47:40 -05:00
|
|
|
{
|
2017-11-24 14:31:14 -06:00
|
|
|
if (tokens.size() <= counter ||
|
2017-12-04 10:43:50 -06:00
|
|
|
!getTokenUInt32(tokens[counter++], "id", winId))
|
2017-11-24 14:31:14 -06:00
|
|
|
{
|
2017-12-04 10:43:50 -06:00
|
|
|
LOG_ERR("Window mouse event expects a valid id= attribute");
|
2017-11-24 14:31:14 -06:00
|
|
|
success = false;
|
|
|
|
}
|
2017-12-04 10:43:50 -06:00
|
|
|
else // id= attribute is found
|
2017-11-24 14:31:14 -06:00
|
|
|
minTokens++;
|
2017-08-24 06:47:40 -05:00
|
|
|
}
|
|
|
|
|
2017-11-24 14:31:14 -06:00
|
|
|
if (tokens.size() < minTokens ||
|
2017-08-24 06:47:40 -05:00
|
|
|
!getTokenKeyword(tokens[counter++], "type",
|
2015-12-12 13:23:44 -06:00
|
|
|
{{"buttondown", LOK_MOUSEEVENT_MOUSEBUTTONDOWN},
|
|
|
|
{"buttonup", LOK_MOUSEEVENT_MOUSEBUTTONUP},
|
|
|
|
{"move", LOK_MOUSEEVENT_MOUSEMOVE}},
|
|
|
|
type) ||
|
2017-08-24 06:47:40 -05:00
|
|
|
!getTokenInteger(tokens[counter++], "x", x) ||
|
|
|
|
!getTokenInteger(tokens[counter++], "y", y) ||
|
|
|
|
!getTokenInteger(tokens[counter++], "count", count))
|
2016-02-08 08:44:13 -06:00
|
|
|
{
|
|
|
|
success = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// compatibility with older loleaflets
|
2017-08-24 06:47:40 -05:00
|
|
|
if (success && tokens.size() > counter && !getTokenInteger(tokens[counter++], "buttons", buttons))
|
2016-02-08 08:44:13 -06:00
|
|
|
success = false;
|
|
|
|
|
|
|
|
// compatibility with older loleaflets
|
2017-08-24 06:47:40 -05:00
|
|
|
if (success && tokens.size() > counter && !getTokenInteger(tokens[counter++], "modifier", modifier))
|
2016-02-08 08:44:13 -06:00
|
|
|
success = false;
|
|
|
|
|
|
|
|
if (!success)
|
2015-12-12 13:23:44 -06:00
|
|
|
{
|
2017-08-24 06:47:40 -05:00
|
|
|
sendTextFrame("error: cmd=" + std::string(tokens[0]) + " kind=syntax");
|
2015-12-12 13:23:44 -06:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
std::unique_lock<std::mutex> lock(_docManager.getDocumentMutex());
|
2016-01-07 08:40:41 -06:00
|
|
|
|
2017-12-04 15:09:26 -06:00
|
|
|
getLOKitDocument()->setView(_viewId);
|
2017-08-24 06:47:40 -05:00
|
|
|
switch (target)
|
|
|
|
{
|
|
|
|
case LokEventTargetEnum::Document:
|
|
|
|
getLOKitDocument()->postMouseEvent(type, x, y, count, buttons, modifier);
|
|
|
|
break;
|
2017-12-04 10:43:50 -06:00
|
|
|
case LokEventTargetEnum::Window:
|
|
|
|
getLOKitDocument()->postWindowMouseEvent(winId, type, x, y, count, buttons, modifier);
|
2017-08-24 06:47:40 -05:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(false && "Unsupported mouse target type");
|
|
|
|
}
|
2015-12-12 13:23:44 -06:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-01-19 19:44:39 -06:00
|
|
|
bool ChildSession::unoCommand(const char* /*buffer*/, int /*length*/, const std::vector<std::string>& tokens)
|
2015-12-12 13:23:44 -06:00
|
|
|
{
|
2017-01-19 19:44:39 -06:00
|
|
|
if (tokens.size() <= 1)
|
2015-12-12 13:23:44 -06:00
|
|
|
{
|
|
|
|
sendTextFrame("error: cmd=uno kind=syntax");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// we need to get LOK_CALLBACK_UNO_COMMAND_RESULT callback when saving
|
2018-01-15 05:46:31 -06:00
|
|
|
const bool bNotify = (tokens[1] == ".uno:Save" ||
|
|
|
|
tokens[1] == ".uno:Undo" ||
|
|
|
|
tokens[1] == ".uno:Redo" ||
|
|
|
|
Util::startsWith(tokens[1], "vnd.sun.star.script:"));
|
2015-12-12 13:23:44 -06:00
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
std::unique_lock<std::mutex> lock(_docManager.getDocumentMutex());
|
2016-09-27 21:05:02 -05:00
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
getLOKitDocument()->setView(_viewId);
|
2016-09-27 21:05:02 -05:00
|
|
|
|
2018-02-25 13:18:04 -06:00
|
|
|
if (tokens.size() == 2)
|
2016-09-28 14:07:07 -05:00
|
|
|
{
|
2018-02-25 13:18:04 -06:00
|
|
|
if (tokens[1] == ".uno:fakeDiskFull")
|
|
|
|
{
|
|
|
|
Util::alertAllUsers("internal", "diskfull");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (tokens[1] == ".uno:Copy")
|
|
|
|
_copyToClipboard = true;
|
|
|
|
|
|
|
|
getLOKitDocument()->postUnoCommand(tokens[1].c_str(), nullptr, bNotify);
|
|
|
|
}
|
2015-12-12 13:23:44 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-11-15 04:37:47 -06:00
|
|
|
getLOKitDocument()->postUnoCommand(tokens[1].c_str(),
|
2018-02-25 13:18:04 -06:00
|
|
|
Poco::cat(std::string(" "), tokens.begin() + 2, tokens.end()).c_str(),
|
|
|
|
bNotify);
|
2015-12-12 13:23:44 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-01-19 19:44:39 -06:00
|
|
|
bool ChildSession::selectText(const char* /*buffer*/, int /*length*/, const std::vector<std::string>& tokens)
|
2015-12-12 13:23:44 -06:00
|
|
|
{
|
|
|
|
int type, x, y;
|
2017-01-19 19:44:39 -06:00
|
|
|
if (tokens.size() != 4 ||
|
2015-12-12 13:23:44 -06:00
|
|
|
!getTokenKeyword(tokens[1], "type",
|
|
|
|
{{"start", LOK_SETTEXTSELECTION_START},
|
|
|
|
{"end", LOK_SETTEXTSELECTION_END},
|
|
|
|
{"reset", LOK_SETTEXTSELECTION_RESET}},
|
|
|
|
type) ||
|
|
|
|
!getTokenInteger(tokens[2], "x", x) ||
|
|
|
|
!getTokenInteger(tokens[3], "y", y))
|
|
|
|
{
|
|
|
|
sendTextFrame("error: cmd=selecttext kind=syntax");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
std::unique_lock<std::mutex> lock(_docManager.getDocumentMutex());
|
2016-01-07 08:40:41 -06:00
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
getLOKitDocument()->setView(_viewId);
|
2016-01-08 18:58:50 -06:00
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
getLOKitDocument()->setTextSelection(type, x, y);
|
2015-12-12 13:23:44 -06:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-12-04 10:43:50 -06:00
|
|
|
bool ChildSession::renderWindow(const char* /*buffer*/, int /*length*/, const std::vector<std::string>& tokens)
|
2017-11-24 14:31:14 -06:00
|
|
|
{
|
|
|
|
std::unique_lock<std::mutex> lock(_docManager.getDocumentMutex());
|
|
|
|
getLOKitDocument()->setView(_viewId);
|
|
|
|
|
2017-12-04 10:43:50 -06:00
|
|
|
unsigned winId = 0;
|
2017-11-24 14:31:14 -06:00
|
|
|
if (tokens.size() > 1)
|
|
|
|
{
|
|
|
|
std::istringstream reader(tokens[1]);
|
2017-12-04 10:43:50 -06:00
|
|
|
reader >> winId;
|
2017-11-24 14:31:14 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
int startX = 0, startY = 0;
|
|
|
|
int bufferWidth = 800, bufferHeight = 600;
|
|
|
|
std::string paintRectangle;
|
|
|
|
if (tokens.size() > 2 && getTokenString(tokens[2], "rectangle", paintRectangle))
|
|
|
|
{
|
|
|
|
const std::vector<std::string> rectParts = LOOLProtocol::tokenize(paintRectangle.c_str(), paintRectangle.length(), ',');
|
|
|
|
startX = std::atoi(rectParts[0].c_str());
|
|
|
|
startY = std::atoi(rectParts[1].c_str());
|
|
|
|
bufferWidth = std::atoi(rectParts[2].c_str());
|
|
|
|
bufferHeight = std::atoi(rectParts[3].c_str());
|
|
|
|
}
|
|
|
|
else
|
2017-12-04 10:43:50 -06:00
|
|
|
LOG_WRN("windowpaint command doesn't specify a rectangle= attribute.");
|
2017-11-24 14:31:14 -06:00
|
|
|
|
|
|
|
size_t pixmapDataSize = 4 * bufferWidth * bufferHeight;
|
|
|
|
std::vector<unsigned char> pixmap(pixmapDataSize);
|
|
|
|
int width = bufferWidth, height = bufferHeight;
|
|
|
|
std::string response;
|
2017-12-04 10:43:50 -06:00
|
|
|
Timestamp timestamp;
|
|
|
|
getLOKitDocument()->paintWindow(winId, pixmap.data(), startX, startY, width, height);
|
|
|
|
const double area = width * height;
|
|
|
|
LOG_TRC("paintWindow for " << winId << " returned " << width << "X" << height
|
|
|
|
<< "@(" << startX << "," << startY << ")"
|
|
|
|
<< "and rendered in " << (timestamp.elapsed()/1000.)
|
|
|
|
<< "ms (" << area / (timestamp.elapsed()) << " MP/s).");
|
2017-11-24 14:31:14 -06:00
|
|
|
|
2017-12-04 10:43:50 -06:00
|
|
|
response = "windowpaint: id=" + tokens[1] +
|
|
|
|
" width=" + std::to_string(width) + " height=" + std::to_string(height);
|
2017-11-24 14:31:14 -06:00
|
|
|
|
2017-12-04 10:43:50 -06:00
|
|
|
if (!paintRectangle.empty())
|
|
|
|
response += " rectangle=" + paintRectangle;
|
2017-11-24 14:31:14 -06:00
|
|
|
|
2017-12-04 10:43:50 -06:00
|
|
|
response += "\n";
|
2017-11-24 14:31:14 -06:00
|
|
|
|
|
|
|
std::vector<char> output;
|
|
|
|
output.reserve(response.size() + pixmapDataSize);
|
|
|
|
output.resize(response.size());
|
|
|
|
std::memcpy(output.data(), response.data(), response.size());
|
|
|
|
|
2017-12-15 10:08:00 -06:00
|
|
|
const auto mode = static_cast<LibreOfficeKitTileMode>(getLOKitDocument()->getTileMode());
|
|
|
|
|
2017-11-24 14:31:14 -06:00
|
|
|
// TODO: use png cache for dialogs too
|
2017-12-15 10:08:00 -06:00
|
|
|
if (!Png::encodeSubBufferToPNG(pixmap.data(), 0, 0, width, height, bufferWidth, bufferHeight, output, mode))
|
2017-11-24 14:31:14 -06:00
|
|
|
{
|
|
|
|
LOG_ERR("Failed to encode into PNG.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
LOG_TRC("Sending response (" << output.size() << " bytes) for: " << response);
|
|
|
|
sendBinaryFrame(output.data(), output.size());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-12-04 13:11:02 -06:00
|
|
|
|
|
|
|
bool ChildSession::sendWindowCommand(const char* /*buffer*/, int /*length*/, const std::vector<std::string>& tokens)
|
|
|
|
{
|
|
|
|
std::unique_lock<std::mutex> lock(_docManager.getDocumentMutex());
|
|
|
|
getLOKitDocument()->setView(_viewId);
|
|
|
|
|
|
|
|
unsigned winId = 0;
|
|
|
|
if (tokens.size() > 1)
|
|
|
|
{
|
|
|
|
std::istringstream reader(tokens[1]);
|
|
|
|
reader >> winId;
|
|
|
|
}
|
|
|
|
|
2017-12-04 15:09:26 -06:00
|
|
|
getLOKitDocument()->setView(_viewId);
|
|
|
|
|
2017-12-04 13:11:02 -06:00
|
|
|
if (tokens.size() > 2 && tokens[2] == "close")
|
|
|
|
getLOKitDocument()->postWindow(winId, LOK_WINDOW_CLOSE);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-01-19 19:44:39 -06:00
|
|
|
bool ChildSession::selectGraphic(const char* /*buffer*/, int /*length*/, const std::vector<std::string>& tokens)
|
2015-12-12 13:23:44 -06:00
|
|
|
{
|
|
|
|
int type, x, y;
|
2017-01-19 19:44:39 -06:00
|
|
|
if (tokens.size() != 4 ||
|
2015-12-12 13:23:44 -06:00
|
|
|
!getTokenKeyword(tokens[1], "type",
|
|
|
|
{{"start", LOK_SETGRAPHICSELECTION_START},
|
|
|
|
{"end", LOK_SETGRAPHICSELECTION_END}},
|
|
|
|
type) ||
|
|
|
|
!getTokenInteger(tokens[2], "x", x) ||
|
|
|
|
!getTokenInteger(tokens[3], "y", y))
|
|
|
|
{
|
|
|
|
sendTextFrame("error: cmd=selectgraphic kind=syntax");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
std::unique_lock<std::mutex> lock(_docManager.getDocumentMutex());
|
2016-01-07 08:40:41 -06:00
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
getLOKitDocument()->setView(_viewId);
|
2016-01-08 18:58:50 -06:00
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
getLOKitDocument()->setGraphicSelection(type, x, y);
|
2015-12-12 13:23:44 -06:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-01-19 19:44:39 -06:00
|
|
|
bool ChildSession::resetSelection(const char* /*buffer*/, int /*length*/, const std::vector<std::string>& tokens)
|
2015-12-12 13:23:44 -06:00
|
|
|
{
|
2017-01-19 19:44:39 -06:00
|
|
|
if (tokens.size() != 1)
|
2015-12-12 13:23:44 -06:00
|
|
|
{
|
|
|
|
sendTextFrame("error: cmd=resetselection kind=syntax");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
std::unique_lock<std::mutex> lock(_docManager.getDocumentMutex());
|
2016-01-07 08:40:41 -06:00
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
getLOKitDocument()->setView(_viewId);
|
2016-01-08 18:58:50 -06:00
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
getLOKitDocument()->resetSelection();
|
2015-12-12 13:23:44 -06:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-01-19 19:44:39 -06:00
|
|
|
bool ChildSession::saveAs(const char* /*buffer*/, int /*length*/, const std::vector<std::string>& tokens)
|
2015-12-12 13:23:44 -06:00
|
|
|
{
|
2017-10-20 11:12:05 -05:00
|
|
|
std::string wopiFilename, url, format, filterOptions;
|
2015-12-12 13:23:44 -06:00
|
|
|
|
2017-10-20 11:12:05 -05:00
|
|
|
if (tokens.size() <= 1 ||
|
2015-12-12 13:23:44 -06:00
|
|
|
!getTokenString(tokens[1], "url", url))
|
|
|
|
{
|
|
|
|
sendTextFrame("error: cmd=saveas kind=syntax");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-10-20 11:12:05 -05:00
|
|
|
// if the url is a 'wopi:///something/blah.odt', then save to a temporary
|
|
|
|
Poco::URI wopiURL(url);
|
|
|
|
if (wopiURL.getScheme() == "wopi")
|
|
|
|
{
|
|
|
|
std::vector<std::string> pathSegments;
|
|
|
|
wopiURL.getPathSegments(pathSegments);
|
|
|
|
|
|
|
|
if (pathSegments.size() == 0)
|
|
|
|
{
|
|
|
|
sendTextFrame("error: cmd=saveas kind=syntax");
|
|
|
|
return false;
|
|
|
|
}
|
2015-12-12 13:23:44 -06:00
|
|
|
|
2017-10-20 11:12:05 -05:00
|
|
|
// TODO do we need a tempdir here?
|
|
|
|
url = std::string("file://") + JAILED_DOCUMENT_ROOT + pathSegments[pathSegments.size() - 1];
|
|
|
|
wopiFilename = wopiURL.getPath();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tokens.size() > 2)
|
|
|
|
getTokenString(tokens[2], "format", format);
|
|
|
|
|
|
|
|
if (tokens.size() > 3 && getTokenString(tokens[3], "options", filterOptions))
|
2015-12-12 13:23:44 -06:00
|
|
|
{
|
2017-01-19 19:44:39 -06:00
|
|
|
if (tokens.size() > 4)
|
2015-12-12 13:23:44 -06:00
|
|
|
{
|
|
|
|
filterOptions += Poco::cat(std::string(" "), tokens.begin() + 4, tokens.end());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-27 21:05:02 -05:00
|
|
|
bool success = false;
|
|
|
|
{
|
2016-11-15 04:37:47 -06:00
|
|
|
std::unique_lock<std::mutex> lock(_docManager.getDocumentMutex());
|
2016-01-07 08:40:41 -06:00
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
getLOKitDocument()->setView(_viewId);
|
2015-12-25 18:37:44 -06:00
|
|
|
|
2018-05-10 02:39:50 -05:00
|
|
|
if (filterOptions.empty() && format == "html")
|
2018-04-27 07:32:25 -05:00
|
|
|
{
|
2018-05-10 02:39:50 -05:00
|
|
|
// Opt-in to avoid linked images, those would not leave the chroot.
|
|
|
|
filterOptions = "EmbedImages";
|
2018-04-27 07:32:25 -05:00
|
|
|
}
|
2018-03-26 10:36:15 -05:00
|
|
|
|
2017-11-06 05:44:37 -06:00
|
|
|
LOG_DBG("Calling LOK's saveAs with: '" << url.c_str() << "', '" <<
|
|
|
|
(format.size() == 0 ? "(nullptr)" : format.c_str()) << "', '" <<
|
|
|
|
(filterOptions.size() == 0 ? "(nullptr)" : filterOptions.c_str()) << "'.");
|
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
success = getLOKitDocument()->saveAs(url.c_str(),
|
2016-09-27 21:05:02 -05:00
|
|
|
format.size() == 0 ? nullptr :format.c_str(),
|
|
|
|
filterOptions.size() == 0 ? nullptr : filterOptions.c_str());
|
2017-11-07 07:30:52 -06:00
|
|
|
|
|
|
|
if (!success)
|
|
|
|
{
|
|
|
|
// a desperate try - add an extension hoping that it'll help
|
|
|
|
bool retry = true;
|
|
|
|
switch (getLOKitDocument()->getDocumentType())
|
|
|
|
{
|
|
|
|
case LOK_DOCTYPE_TEXT: url += ".odt"; wopiFilename += ".odt"; break;
|
|
|
|
case LOK_DOCTYPE_SPREADSHEET: url += ".ods"; wopiFilename += ".ods"; break;
|
|
|
|
case LOK_DOCTYPE_PRESENTATION: url += ".odp"; wopiFilename += ".odp"; break;
|
|
|
|
case LOK_DOCTYPE_DRAWING: url += ".odg"; wopiFilename += ".odg"; break;
|
|
|
|
default: retry = false; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (retry)
|
|
|
|
{
|
2018-07-11 04:08:53 -05:00
|
|
|
LOG_DBG("Retry: calling LOK's saveAs with: '" << url.c_str() << "', '" <<
|
|
|
|
(format.size() == 0 ? "(nullptr)" : format.c_str()) << "', '" <<
|
|
|
|
(filterOptions.size() == 0 ? "(nullptr)" : filterOptions.c_str()) << "'.");
|
|
|
|
|
2017-11-07 07:30:52 -06:00
|
|
|
success = getLOKitDocument()->saveAs(url.c_str(),
|
|
|
|
format.size() == 0 ? nullptr :format.c_str(),
|
|
|
|
filterOptions.size() == 0 ? nullptr : filterOptions.c_str());
|
|
|
|
}
|
|
|
|
}
|
2016-09-27 21:05:02 -05:00
|
|
|
}
|
2015-12-12 13:23:44 -06:00
|
|
|
|
2017-10-20 11:12:05 -05:00
|
|
|
std::string encodedURL, encodedWopiFilename;
|
|
|
|
Poco::URI::encode(url, "", encodedURL);
|
|
|
|
Poco::URI::encode(wopiFilename, "", encodedWopiFilename);
|
|
|
|
|
2017-10-25 07:09:27 -05:00
|
|
|
if (success)
|
|
|
|
sendTextFrame("saveas: url=" + encodedURL + " filename=" + encodedWopiFilename);
|
|
|
|
else
|
|
|
|
sendTextFrame("error: cmd=storage kind=savefailed");
|
2015-12-12 13:23:44 -06:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-01-19 19:44:39 -06:00
|
|
|
bool ChildSession::setClientPart(const char* /*buffer*/, int /*length*/, const std::vector<std::string>& tokens)
|
2015-12-12 13:23:44 -06:00
|
|
|
{
|
2016-04-27 12:47:58 -05:00
|
|
|
int part;
|
2017-01-19 19:44:39 -06:00
|
|
|
if (tokens.size() < 2 ||
|
2016-04-27 12:47:58 -05:00
|
|
|
!getTokenInteger(tokens[1], "part", part))
|
2015-12-12 13:23:44 -06:00
|
|
|
{
|
2016-04-27 12:47:58 -05:00
|
|
|
sendTextFrame("error: cmd=setclientpart kind=invalid");
|
2015-12-12 13:23:44 -06:00
|
|
|
return false;
|
|
|
|
}
|
2016-04-27 12:47:58 -05:00
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
std::unique_lock<std::mutex> lock(_docManager.getDocumentMutex());
|
2016-04-27 12:47:58 -05:00
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
getLOKitDocument()->setView(_viewId);
|
2016-10-01 13:07:39 -05:00
|
|
|
|
2016-11-15 05:50:58 -06:00
|
|
|
if (getLOKitDocument()->getDocumentType() != LOK_DOCTYPE_TEXT && part != getLOKitDocument()->getPart())
|
2016-04-29 20:52:00 -05:00
|
|
|
{
|
2016-11-15 04:37:47 -06:00
|
|
|
getLOKitDocument()->setPart(part);
|
2016-04-29 20:52:00 -05:00
|
|
|
}
|
2016-04-27 12:47:58 -05:00
|
|
|
|
2015-12-12 13:23:44 -06:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-01-19 19:44:39 -06:00
|
|
|
bool ChildSession::setPage(const char* /*buffer*/, int /*length*/, const std::vector<std::string>& tokens)
|
2015-12-12 13:23:44 -06:00
|
|
|
{
|
|
|
|
int page;
|
2017-01-19 19:44:39 -06:00
|
|
|
if (tokens.size() < 2 ||
|
2015-12-12 13:23:44 -06:00
|
|
|
!getTokenInteger(tokens[1], "page", page))
|
|
|
|
{
|
|
|
|
sendTextFrame("error: cmd=setpage kind=invalid");
|
|
|
|
return false;
|
|
|
|
}
|
2015-12-25 18:37:44 -06:00
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
std::unique_lock<std::mutex> lock(_docManager.getDocumentMutex());
|
2016-01-07 08:40:41 -06:00
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
getLOKitDocument()->setView(_viewId);
|
2016-01-08 18:58:50 -06:00
|
|
|
|
2016-11-15 04:37:47 -06:00
|
|
|
getLOKitDocument()->setPart(page);
|
2015-12-12 13:23:44 -06:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-01-02 07:21:49 -06:00
|
|
|
/* If the user is inactive we have to remember important events so that when
|
|
|
|
* the user becomes active again, we can replay the events.
|
|
|
|
*/
|
2017-01-13 06:52:08 -06:00
|
|
|
void ChildSession::rememberEventsForInactiveUser(const int type, const std::string& payload)
|
2017-01-02 07:21:49 -06:00
|
|
|
{
|
2017-04-24 12:19:18 -05:00
|
|
|
if (type == LOK_CALLBACK_INVALIDATE_TILES)
|
|
|
|
{
|
2018-02-07 03:17:28 -06:00
|
|
|
std::unique_lock<std::mutex> lock(getLock());
|
2017-04-24 12:19:18 -05:00
|
|
|
_stateRecorder.recordInvalidate(); // TODO remember the area, not just a bool ('true' invalidates everything)
|
|
|
|
}
|
|
|
|
else if (type == LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR ||
|
|
|
|
type == LOK_CALLBACK_CURSOR_VISIBLE ||
|
|
|
|
type == LOK_CALLBACK_TEXT_SELECTION ||
|
|
|
|
type == LOK_CALLBACK_TEXT_SELECTION_START ||
|
|
|
|
type == LOK_CALLBACK_TEXT_SELECTION_END ||
|
|
|
|
type == LOK_CALLBACK_CELL_FORMULA ||
|
|
|
|
type == LOK_CALLBACK_CELL_CURSOR ||
|
|
|
|
type == LOK_CALLBACK_GRAPHIC_SELECTION ||
|
|
|
|
type == LOK_CALLBACK_DOCUMENT_SIZE_CHANGED ||
|
2017-05-07 17:38:13 -05:00
|
|
|
type == LOK_CALLBACK_INVALIDATE_HEADER ||
|
|
|
|
type == LOK_CALLBACK_CELL_ADDRESS)
|
2017-01-02 07:21:49 -06:00
|
|
|
{
|
2018-02-07 03:17:28 -06:00
|
|
|
std::unique_lock<std::mutex> lock(getLock());
|
2017-01-13 06:52:08 -06:00
|
|
|
_stateRecorder.recordEvent(type, payload);
|
2017-01-02 07:21:49 -06:00
|
|
|
}
|
2017-01-13 06:52:08 -06:00
|
|
|
else if (type == LOK_CALLBACK_INVALIDATE_VIEW_CURSOR ||
|
|
|
|
type == LOK_CALLBACK_TEXT_VIEW_SELECTION ||
|
|
|
|
type == LOK_CALLBACK_CELL_VIEW_CURSOR ||
|
|
|
|
type == LOK_CALLBACK_GRAPHIC_VIEW_SELECTION ||
|
|
|
|
type == LOK_CALLBACK_VIEW_CURSOR_VISIBLE ||
|
|
|
|
type == LOK_CALLBACK_VIEW_LOCK)
|
2017-01-02 07:21:49 -06:00
|
|
|
{
|
2018-02-07 03:17:28 -06:00
|
|
|
std::unique_lock<std::mutex> lock(getLock());
|
2017-01-02 07:21:49 -06:00
|
|
|
Poco::JSON::Parser parser;
|
|
|
|
|
2018-02-07 03:17:28 -06:00
|
|
|
Poco::JSON::Object::Ptr root = parser.parse(payload).extract<Poco::JSON::Object::Ptr>();
|
2017-01-02 07:21:49 -06:00
|
|
|
int viewId = root->getValue<int>("viewId");
|
2017-01-13 06:52:08 -06:00
|
|
|
_stateRecorder.recordViewEvent(viewId, type, payload);
|
2017-01-02 07:21:49 -06:00
|
|
|
}
|
2017-01-13 06:52:08 -06:00
|
|
|
else if (type == LOK_CALLBACK_STATE_CHANGED)
|
2017-01-02 07:21:49 -06:00
|
|
|
{
|
|
|
|
std::string name;
|
|
|
|
std::string value;
|
2017-01-13 06:52:08 -06:00
|
|
|
if (LOOLProtocol::parseNameValuePair(payload, name, value, '='))
|
2017-01-02 07:21:49 -06:00
|
|
|
{
|
2018-02-07 03:17:28 -06:00
|
|
|
std::unique_lock<std::mutex> lock(getLock());
|
2017-04-24 11:37:03 -05:00
|
|
|
_stateRecorder.recordState(name, payload);
|
2017-01-02 07:21:49 -06:00
|
|
|
}
|
|
|
|
}
|
2017-04-25 11:17:50 -05:00
|
|
|
else if (type == LOK_CALLBACK_REDLINE_TABLE_SIZE_CHANGED ||
|
|
|
|
type == LOK_CALLBACK_REDLINE_TABLE_ENTRY_MODIFIED ||
|
|
|
|
type == LOK_CALLBACK_COMMENT)
|
|
|
|
{
|
2018-02-07 03:17:28 -06:00
|
|
|
std::unique_lock<std::mutex> lock(getLock());
|
2017-04-25 11:17:50 -05:00
|
|
|
_stateRecorder.recordEventSequence(type, payload);
|
|
|
|
}
|
2017-01-02 07:21:49 -06:00
|
|
|
}
|
|
|
|
|
2018-02-11 12:16:42 -06:00
|
|
|
void ChildSession::updateSpeed()
|
|
|
|
{
|
2017-06-27 06:44:50 -05:00
|
|
|
std::chrono::steady_clock::time_point now(std::chrono::steady_clock::now());
|
|
|
|
|
2018-02-11 12:16:42 -06:00
|
|
|
while (_cursorInvalidatedEvent.size() != 0 &&
|
|
|
|
std::chrono::duration_cast<std::chrono::milliseconds>(now - _cursorInvalidatedEvent.front()).count() > _eventStorageIntervalMs)
|
2017-06-27 06:44:50 -05:00
|
|
|
{
|
|
|
|
_cursorInvalidatedEvent.pop();
|
|
|
|
}
|
2018-02-11 12:16:42 -06:00
|
|
|
|
2017-06-27 06:44:50 -05:00
|
|
|
_cursorInvalidatedEvent.push(now);
|
|
|
|
_docManager.updateEditorSpeeds(_viewId, _cursorInvalidatedEvent.size());
|
|
|
|
}
|
|
|
|
|
2018-02-11 12:16:42 -06:00
|
|
|
int ChildSession::getSpeed()
|
|
|
|
{
|
2017-06-27 06:44:50 -05:00
|
|
|
std::chrono::steady_clock::time_point now(std::chrono::steady_clock::now());
|
|
|
|
|
2018-02-11 12:16:42 -06:00
|
|
|
while (_cursorInvalidatedEvent.size() > 0 &&
|
|
|
|
std::chrono::duration_cast<std::chrono::milliseconds>(now - _cursorInvalidatedEvent.front()).count() > _eventStorageIntervalMs)
|
2017-06-27 06:44:50 -05:00
|
|
|
{
|
|
|
|
_cursorInvalidatedEvent.pop();
|
|
|
|
}
|
2018-02-11 12:16:42 -06:00
|
|
|
|
2017-06-27 06:44:50 -05:00
|
|
|
return _cursorInvalidatedEvent.size();
|
|
|
|
}
|
|
|
|
|
2017-01-13 06:52:08 -06:00
|
|
|
void ChildSession::loKitCallback(const int type, const std::string& payload)
|
2016-01-24 17:25:02 -06:00
|
|
|
{
|
2018-02-07 03:17:28 -06:00
|
|
|
const std::string typeName = LOKitHelper::kitCallbackTypeToString(type);
|
2018-01-17 04:35:07 -06:00
|
|
|
LOG_TRC("ChildSession::loKitCallback [" << getName() << "]: " <<
|
2017-01-13 06:52:08 -06:00
|
|
|
typeName << " [" << payload << "].");
|
2016-09-27 21:05:02 -05:00
|
|
|
|
2016-08-13 17:25:06 -05:00
|
|
|
if (isCloseFrame())
|
|
|
|
{
|
2016-11-05 16:29:38 -05:00
|
|
|
LOG_TRC("Skipping callback [" << typeName << "] on closing session " << getName());
|
2016-08-13 17:25:06 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (isDisconnected())
|
|
|
|
{
|
2016-11-05 16:29:38 -05:00
|
|
|
LOG_TRC("Skipping callback [" << typeName << "] on disconnected session " << getName());
|
2016-08-13 17:25:06 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (!isActive())
|
|
|
|
{
|
2017-01-13 06:52:08 -06:00
|
|
|
rememberEventsForInactiveUser(type, payload);
|
2016-11-01 08:24:14 -05:00
|
|
|
|
2016-08-13 17:25:06 -05:00
|
|
|
// Pass save notifications through.
|
2017-01-13 06:52:08 -06:00
|
|
|
if (type != LOK_CALLBACK_UNO_COMMAND_RESULT || payload.find(".uno:Save") == std::string::npos)
|
2016-08-13 17:25:06 -05:00
|
|
|
{
|
2016-11-05 16:29:38 -05:00
|
|
|
LOG_TRC("Skipping callback [" << typeName << "] on inactive session " << getName());
|
2016-08-13 17:25:06 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-13 06:52:08 -06:00
|
|
|
switch (type)
|
2016-08-13 17:25:06 -05:00
|
|
|
{
|
|
|
|
case LOK_CALLBACK_INVALIDATE_TILES:
|
|
|
|
{
|
2017-01-13 06:52:08 -06:00
|
|
|
StringTokenizer tokens(payload, ",", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM);
|
2016-10-02 15:44:11 -05:00
|
|
|
if (tokens.count() == 5)
|
2016-08-13 17:25:06 -05:00
|
|
|
{
|
2016-10-02 15:44:11 -05:00
|
|
|
int part, x, y, width, height;
|
2016-08-13 17:25:06 -05:00
|
|
|
try
|
|
|
|
{
|
|
|
|
x = std::stoi(tokens[0]);
|
|
|
|
y = std::stoi(tokens[1]);
|
|
|
|
width = std::stoi(tokens[2]);
|
|
|
|
height = std::stoi(tokens[3]);
|
2016-10-07 17:19:56 -05:00
|
|
|
part = (_docType != "text" ? std::stoi(tokens[4]) : 0); // Writer renders everything as part 0.
|
2016-08-13 17:25:06 -05:00
|
|
|
}
|
|
|
|
catch (const std::out_of_range&)
|
|
|
|
{
|
2016-10-21 21:00:10 -05:00
|
|
|
// We might get INT_MAX +/- some delta that
|
|
|
|
// can overflow signed int and we end up here.
|
2016-08-13 17:25:06 -05:00
|
|
|
x = 0;
|
|
|
|
y = 0;
|
|
|
|
width = INT_MAX;
|
|
|
|
height = INT_MAX;
|
2016-10-02 15:44:11 -05:00
|
|
|
part = 0;
|
2016-08-13 17:25:06 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
sendTextFrame("invalidatetiles:"
|
2016-10-02 15:44:11 -05:00
|
|
|
" part=" + std::to_string(part) +
|
2016-09-27 21:05:02 -05:00
|
|
|
" x=" + std::to_string(x) +
|
|
|
|
" y=" + std::to_string(y) +
|
|
|
|
" width=" + std::to_string(width) +
|
|
|
|
" height=" + std::to_string(height));
|
2016-08-13 17:25:06 -05:00
|
|
|
}
|
2016-11-29 21:59:47 -06:00
|
|
|
else if (tokens.count() == 2 && tokens[0] == "EMPTY")
|
|
|
|
{
|
|
|
|
const std::string part = (_docType != "text" ? tokens[1].c_str() : "0"); // Writer renders everything as part 0.
|
|
|
|
sendTextFrame("invalidatetiles: EMPTY, " + part);
|
|
|
|
}
|
2016-08-13 17:25:06 -05:00
|
|
|
else
|
|
|
|
{
|
2017-01-13 06:52:08 -06:00
|
|
|
sendTextFrame("invalidatetiles: " + payload);
|
2016-08-13 17:25:06 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR:
|
2017-06-27 06:44:50 -05:00
|
|
|
updateSpeed();
|
2017-01-13 06:52:08 -06:00
|
|
|
sendTextFrame("invalidatecursor: " + payload);
|
2016-08-13 17:25:06 -05:00
|
|
|
break;
|
|
|
|
case LOK_CALLBACK_TEXT_SELECTION:
|
2017-01-13 06:52:08 -06:00
|
|
|
sendTextFrame("textselection: " + payload);
|
2016-08-13 17:25:06 -05:00
|
|
|
break;
|
|
|
|
case LOK_CALLBACK_TEXT_SELECTION_START:
|
2017-01-13 06:52:08 -06:00
|
|
|
sendTextFrame("textselectionstart: " + payload);
|
2016-08-13 17:25:06 -05:00
|
|
|
break;
|
|
|
|
case LOK_CALLBACK_TEXT_SELECTION_END:
|
2017-01-13 06:52:08 -06:00
|
|
|
sendTextFrame("textselectionend: " + payload);
|
2016-08-13 17:25:06 -05:00
|
|
|
break;
|
|
|
|
case LOK_CALLBACK_CURSOR_VISIBLE:
|
2017-01-13 06:52:08 -06:00
|
|
|
sendTextFrame("cursorvisible: " + payload);
|
2016-08-13 17:25:06 -05:00
|
|
|
break;
|
|
|
|
case LOK_CALLBACK_GRAPHIC_SELECTION:
|
2017-01-13 06:52:08 -06:00
|
|
|
sendTextFrame("graphicselection: " + payload);
|
2016-08-13 17:25:06 -05:00
|
|
|
break;
|
|
|
|
case LOK_CALLBACK_CELL_CURSOR:
|
2017-01-13 06:52:08 -06:00
|
|
|
sendTextFrame("cellcursor: " + payload);
|
2016-08-13 17:25:06 -05:00
|
|
|
break;
|
|
|
|
case LOK_CALLBACK_CELL_FORMULA:
|
2017-01-13 06:52:08 -06:00
|
|
|
sendTextFrame("cellformula: " + payload);
|
2016-08-13 17:25:06 -05:00
|
|
|
break;
|
|
|
|
case LOK_CALLBACK_MOUSE_POINTER:
|
2017-01-13 06:52:08 -06:00
|
|
|
sendTextFrame("mousepointer: " + payload);
|
2016-08-13 17:25:06 -05:00
|
|
|
break;
|
|
|
|
case LOK_CALLBACK_HYPERLINK_CLICKED:
|
2017-01-13 06:52:08 -06:00
|
|
|
sendTextFrame("hyperlinkclicked: " + payload);
|
2016-08-13 17:25:06 -05:00
|
|
|
break;
|
|
|
|
case LOK_CALLBACK_STATE_CHANGED:
|
2017-01-13 06:52:08 -06:00
|
|
|
sendTextFrame("statechanged: " + payload);
|
2016-08-13 17:25:06 -05:00
|
|
|
break;
|
|
|
|
case LOK_CALLBACK_SEARCH_NOT_FOUND:
|
2017-01-13 06:52:08 -06:00
|
|
|
sendTextFrame("searchnotfound: " + payload);
|
2016-08-13 17:25:06 -05:00
|
|
|
break;
|
|
|
|
case LOK_CALLBACK_SEARCH_RESULT_SELECTION:
|
2017-01-13 06:52:08 -06:00
|
|
|
sendTextFrame("searchresultselection: " + payload);
|
2016-08-13 17:25:06 -05:00
|
|
|
break;
|
|
|
|
case LOK_CALLBACK_DOCUMENT_SIZE_CHANGED:
|
2016-12-04 22:45:26 -06:00
|
|
|
{
|
|
|
|
//TODO: clenaup and merge.
|
|
|
|
|
|
|
|
std::unique_lock<std::mutex> lock(_docManager.getDocumentMutex());
|
|
|
|
const int parts = getLOKitDocument()->getParts();
|
|
|
|
for (int i = 0; i < parts; ++i)
|
|
|
|
{
|
|
|
|
sendTextFrame("invalidatetiles:"
|
|
|
|
" part=" + std::to_string(i) +
|
|
|
|
" x=0" +
|
|
|
|
" y=0" +
|
|
|
|
" width=" + std::to_string(INT_MAX) +
|
|
|
|
" height=" + std::to_string(INT_MAX));
|
|
|
|
}
|
|
|
|
|
|
|
|
lock.unlock();
|
|
|
|
|
|
|
|
getStatus("", 0);
|
|
|
|
}
|
2016-08-13 17:25:06 -05:00
|
|
|
break;
|
|
|
|
case LOK_CALLBACK_SET_PART:
|
2017-01-13 06:52:08 -06:00
|
|
|
sendTextFrame("setpart: " + payload);
|
2016-08-13 17:25:06 -05:00
|
|
|
break;
|
|
|
|
case LOK_CALLBACK_UNO_COMMAND_RESULT:
|
2017-01-13 06:52:08 -06:00
|
|
|
sendTextFrame("unocommandresult: " + payload);
|
2016-08-13 17:25:06 -05:00
|
|
|
break;
|
|
|
|
case LOK_CALLBACK_ERROR:
|
|
|
|
{
|
2017-01-13 06:52:08 -06:00
|
|
|
LOG_ERR("CALLBACK_ERROR: " << payload);
|
2016-08-13 17:25:06 -05:00
|
|
|
Parser parser;
|
2017-01-13 06:52:08 -06:00
|
|
|
Poco::Dynamic::Var var = parser.parse(payload);
|
2016-08-13 17:25:06 -05:00
|
|
|
Object::Ptr object = var.extract<Object::Ptr>();
|
|
|
|
|
|
|
|
sendTextFrame("error: cmd=" + object->get("cmd").toString() +
|
|
|
|
" kind=" + object->get("kind").toString() + " code=" + object->get("code").toString());
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case LOK_CALLBACK_CONTEXT_MENU:
|
2017-01-13 06:52:08 -06:00
|
|
|
sendTextFrame("contextmenu: " + payload);
|
2016-08-13 17:25:06 -05:00
|
|
|
break;
|
|
|
|
case LOK_CALLBACK_STATUS_INDICATOR_START:
|
|
|
|
sendTextFrame("statusindicatorstart:");
|
|
|
|
break;
|
|
|
|
case LOK_CALLBACK_STATUS_INDICATOR_SET_VALUE:
|
2017-01-13 06:52:08 -06:00
|
|
|
sendTextFrame("statusindicatorsetvalue: " + payload);
|
2016-08-13 17:25:06 -05:00
|
|
|
break;
|
|
|
|
case LOK_CALLBACK_STATUS_INDICATOR_FINISH:
|
|
|
|
sendTextFrame("statusindicatorfinish:");
|
|
|
|
break;
|
|
|
|
case LOK_CALLBACK_INVALIDATE_VIEW_CURSOR:
|
2017-01-13 06:52:08 -06:00
|
|
|
sendTextFrame("invalidateviewcursor: " + payload);
|
2016-08-13 17:25:06 -05:00
|
|
|
break;
|
|
|
|
case LOK_CALLBACK_TEXT_VIEW_SELECTION:
|
2017-01-13 06:52:08 -06:00
|
|
|
sendTextFrame("textviewselection: " + payload);
|
2016-08-13 17:25:06 -05:00
|
|
|
break;
|
|
|
|
case LOK_CALLBACK_CELL_VIEW_CURSOR:
|
2017-01-13 06:52:08 -06:00
|
|
|
sendTextFrame("cellviewcursor: " + payload);
|
2016-08-13 17:25:06 -05:00
|
|
|
break;
|
|
|
|
case LOK_CALLBACK_GRAPHIC_VIEW_SELECTION:
|
2017-01-13 06:52:08 -06:00
|
|
|
sendTextFrame("graphicviewselection: " + payload);
|
2016-08-13 17:25:06 -05:00
|
|
|
break;
|
|
|
|
case LOK_CALLBACK_VIEW_CURSOR_VISIBLE:
|
2017-01-13 06:52:08 -06:00
|
|
|
sendTextFrame("viewcursorvisible: " + payload);
|
2016-08-13 17:25:06 -05:00
|
|
|
break;
|
|
|
|
case LOK_CALLBACK_VIEW_LOCK:
|
2017-01-13 06:52:08 -06:00
|
|
|
sendTextFrame("viewlock: " + payload);
|
2016-08-13 17:25:06 -05:00
|
|
|
break;
|
2016-08-21 10:15:50 -05:00
|
|
|
case LOK_CALLBACK_REDLINE_TABLE_SIZE_CHANGED:
|
2017-01-13 06:52:08 -06:00
|
|
|
sendTextFrame("redlinetablechanged: " + payload);
|
2016-08-21 10:15:50 -05:00
|
|
|
break;
|
2016-09-19 04:15:15 -05:00
|
|
|
case LOK_CALLBACK_REDLINE_TABLE_ENTRY_MODIFIED:
|
2017-01-13 06:52:08 -06:00
|
|
|
sendTextFrame("redlinetablemodified: " + payload);
|
2016-09-19 04:15:15 -05:00
|
|
|
break;
|
2017-01-23 11:01:57 -06:00
|
|
|
case LOK_CALLBACK_COMMENT:
|
|
|
|
sendTextFrame("comment: " + payload);
|
|
|
|
break;
|
2017-04-19 16:09:19 -05:00
|
|
|
case LOK_CALLBACK_INVALIDATE_HEADER:
|
|
|
|
sendTextFrame("invalidateheader: " + payload);
|
|
|
|
break;
|
2017-05-07 17:38:13 -05:00
|
|
|
case LOK_CALLBACK_CELL_ADDRESS:
|
|
|
|
sendTextFrame("celladdress: " + payload);
|
|
|
|
break;
|
2017-07-26 14:14:30 -05:00
|
|
|
case LOK_CALLBACK_RULER_UPDATE:
|
|
|
|
sendTextFrame("rulerupdate: " + payload);
|
|
|
|
break;
|
2017-12-04 10:43:50 -06:00
|
|
|
case LOK_CALLBACK_WINDOW:
|
|
|
|
sendTextFrame("window: " + payload);
|
2017-08-16 06:20:58 -05:00
|
|
|
break;
|
2018-03-19 08:08:10 -05:00
|
|
|
case LOK_CALLBACK_VALIDITY_LIST_BUTTON:
|
|
|
|
sendTextFrame("validitylistbutton: " + payload);
|
|
|
|
break;
|
2018-02-25 13:18:04 -06:00
|
|
|
case LOK_CALLBACK_CLIPBOARD_CHANGED:
|
|
|
|
{
|
|
|
|
std::string selection;
|
|
|
|
if (_copyToClipboard)
|
|
|
|
{
|
|
|
|
_copyToClipboard = false;
|
|
|
|
selection = getTextSelectionInternal("");
|
|
|
|
}
|
|
|
|
|
|
|
|
sendTextFrame("clipboardchanged: " + selection);
|
|
|
|
break;
|
|
|
|
}
|
2016-08-13 17:25:06 -05:00
|
|
|
default:
|
2017-01-13 06:52:08 -06:00
|
|
|
LOG_ERR("Unknown callback event (" << type << "): " << payload);
|
2016-08-13 17:25:06 -05:00
|
|
|
}
|
2016-01-24 17:25:02 -06:00
|
|
|
}
|
|
|
|
|
2015-12-13 11:47:14 -06:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|