2015-12-12 20:23:44 +01:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
|
|
|
|
/*
|
2023-11-09 19:23:00 +01:00
|
|
|
* Copyright the Collabora Online contributors.
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
*
|
2015-12-12 20:23:44 +01:00
|
|
|
* 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/.
|
|
|
|
*/
|
|
|
|
|
2020-04-18 10:39:50 +02:00
|
|
|
#pragma once
|
2015-12-13 18:47:14 +01:00
|
|
|
|
2017-01-02 14:21:49 +01:00
|
|
|
#include <unordered_map>
|
2017-06-27 13:44:50 +02:00
|
|
|
#include <queue>
|
2016-01-11 04:52:00 +01:00
|
|
|
|
2021-07-09 17:57:09 +02:00
|
|
|
#include <atomic>
|
|
|
|
|
2016-11-15 11:37:47 +01:00
|
|
|
#define LOK_USE_UNSTABLE_API
|
|
|
|
#include <LibreOfficeKit/LibreOfficeKit.hxx>
|
|
|
|
|
2016-02-26 07:25:13 +01:00
|
|
|
#include "Common.hpp"
|
2016-11-24 15:56:06 +01:00
|
|
|
#include "Kit.hpp"
|
|
|
|
#include "Session.hpp"
|
2020-11-11 01:56:59 +01:00
|
|
|
#include "Watermark.hpp"
|
2024-03-06 13:43:53 +01:00
|
|
|
#include "StateRecorder.hpp"
|
2015-12-12 20:23:44 +01:00
|
|
|
|
2024-04-25 14:08:42 +02:00
|
|
|
class Document;
|
2016-08-21 17:12:12 +02:00
|
|
|
class ChildSession;
|
|
|
|
|
2017-08-24 13:47:40 +02:00
|
|
|
enum class LokEventTargetEnum
|
|
|
|
{
|
|
|
|
Document,
|
2017-12-04 17:43:50 +01:00
|
|
|
Window
|
2017-08-24 13:47:40 +02:00
|
|
|
};
|
|
|
|
|
2016-09-28 19:15:51 +02:00
|
|
|
/// Represents a session to the WSD process, in a Kit process. Note that this is not a singleton.
|
2016-12-13 01:53:58 +01:00
|
|
|
class ChildSession final : public Session
|
2015-12-12 20:23:44 +01:00
|
|
|
{
|
|
|
|
public:
|
2020-03-11 16:55:49 +01:00
|
|
|
static bool NoCapsForKit;
|
|
|
|
|
2016-05-17 13:35:07 +02:00
|
|
|
/// Create a new ChildSession
|
2016-01-07 04:47:01 +01:00
|
|
|
/// jailId The JailID of the jail root directory,
|
|
|
|
// used by downloadas to construct jailed path.
|
2020-03-06 18:43:46 +01:00
|
|
|
ChildSession(
|
|
|
|
const std::shared_ptr<ProtocolHandlerInterface> &protocol,
|
|
|
|
const std::string& id,
|
|
|
|
const std::string& jailId,
|
2020-10-23 04:24:04 +02:00
|
|
|
const std::string& jailRoot,
|
2024-04-25 14:08:42 +02:00
|
|
|
Document& document);
|
2016-05-17 13:35:07 +02:00
|
|
|
virtual ~ChildSession();
|
2015-12-12 20:23:44 +01:00
|
|
|
|
2022-02-24 04:39:20 +01:00
|
|
|
bool getStatus();
|
2016-08-29 13:52:06 +02:00
|
|
|
int getViewId() const { return _viewId; }
|
2016-09-17 23:52:54 +02:00
|
|
|
void setViewId(const int viewId) { _viewId = viewId; }
|
2018-11-13 09:04:19 +01:00
|
|
|
const std::string& getViewUserId() const { return getUserId(); }
|
|
|
|
const std::string& getViewUserName() const { return getUserName(); }
|
|
|
|
const std::string& getViewUserExtraInfo() const { return getUserExtraInfo(); }
|
2023-01-04 10:09:21 +01:00
|
|
|
const std::string& getViewUserPrivateInfo() const { return getUserPrivateInfo(); }
|
2017-06-27 13:44:50 +02:00
|
|
|
void updateSpeed();
|
|
|
|
int getSpeed();
|
2016-01-03 16:56:41 +01:00
|
|
|
|
2017-01-13 13:52:08 +01:00
|
|
|
void loKitCallback(const int type, const std::string& payload);
|
2016-01-25 00:25:02 +01:00
|
|
|
|
2020-11-11 01:56:59 +01:00
|
|
|
/// Initializes the watermark support, if enabled and required.
|
|
|
|
/// Returns true if watermark is enabled and initialized.
|
|
|
|
bool initWatermark()
|
|
|
|
{
|
|
|
|
if (hasWatermark())
|
|
|
|
{
|
2023-07-30 16:40:21 +02:00
|
|
|
_docWatermark = std::make_shared<Watermark>(getLOKitDocument(), getWatermarkText(),
|
|
|
|
getWatermarkOpacity());
|
2020-11-11 01:56:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return _docWatermark != nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::shared_ptr<Watermark>& watermark() const { return _docWatermark; };
|
2019-10-15 14:35:35 +02:00
|
|
|
|
2017-11-24 21:29:48 +01:00
|
|
|
bool sendTextFrame(const char* buffer, int length) override
|
2016-10-09 17:28:22 +02:00
|
|
|
{
|
2020-03-06 18:43:46 +01:00
|
|
|
if (!_docManager)
|
|
|
|
{
|
|
|
|
LOG_TRC("ERR dropping - client-" + getId() + ' ' + std::string(buffer, length));
|
|
|
|
return false;
|
|
|
|
}
|
2016-10-09 17:28:22 +02:00
|
|
|
const auto msg = "client-" + getId() + ' ' + std::string(buffer, length);
|
2019-08-16 09:05:54 +02:00
|
|
|
return _docManager->sendFrame(msg.data(), msg.size(), WSOpCode::Text);
|
2017-11-24 21:29:48 +01:00
|
|
|
}
|
2016-10-09 17:28:22 +02:00
|
|
|
|
2017-11-24 21:29:48 +01:00
|
|
|
bool sendBinaryFrame(const char* buffer, int length) override
|
|
|
|
{
|
2020-03-06 18:43:46 +01:00
|
|
|
if (!_docManager)
|
|
|
|
{
|
|
|
|
LOG_TRC("ERR dropping binary - client-" + getId());
|
|
|
|
return false;
|
|
|
|
}
|
2017-11-24 21:29:48 +01:00
|
|
|
const auto msg = "client-" + getId() + ' ' + std::string(buffer, length);
|
2019-08-16 09:05:54 +02:00
|
|
|
return _docManager->sendFrame(msg.data(), msg.size(), WSOpCode::Binary);
|
2016-10-09 17:28:22 +02:00
|
|
|
}
|
|
|
|
|
2024-05-01 14:23:40 +02:00
|
|
|
bool sendProgressFrame(const char* id, const std::string &jsonProps);
|
|
|
|
|
2016-12-13 02:18:25 +01:00
|
|
|
using Session::sendTextFrame;
|
2016-10-09 17:28:22 +02:00
|
|
|
|
2022-02-24 04:39:20 +01:00
|
|
|
bool getClipboard(const StringVector& tokens);
|
2019-07-04 11:50:33 +02:00
|
|
|
|
2019-08-16 09:05:54 +02:00
|
|
|
void resetDocManager()
|
|
|
|
{
|
android: Fix crash on the 2nd editing start.
The failing scenario was reproducible on my old phone:
* start editing the document from the shell
* add a word
* leave the editing using the '<' in the top left
* start editing the document again => boom!
In the normali, non-crashing case, the order of destruction is that
~ChildSession is called first (and calls ChildSession::disconnect() that
consequently calls Document::onUnload() via _docManager->onUnLoad(...).
The Document::onUnload() then deregisters callbacks and all is fine.
The in the above described crashing case, the Document is destroyed
before ChildSession and calls resetDocManager() for all sessions.
Before this patch, this meant that the _docManager was set to nullptr,
leading to situation that later, in the ~ChildSession, the call of
onUnload() was avoided, the callbacks were not unregistered, and later,
on the next document load, the app crashed because it called stale
callbacks.
I suspect the change might be useful even for the non-mobile case, but
not 100% sure, so rather do it MOBILEAPP-only.
Change-Id: I279a160ccaab3080e84fe0437ed72684331b6e13
Reviewed-on: https://gerrit.libreoffice.org/84588
Reviewed-by: Jan Holesovsky <kendy@collabora.com>
Tested-by: Jan Holesovsky <kendy@collabora.com>
2019-12-05 22:09:22 +01:00
|
|
|
disconnect();
|
2019-08-16 09:05:54 +02:00
|
|
|
_docManager = nullptr;
|
|
|
|
}
|
|
|
|
|
2023-02-23 23:41:06 +01:00
|
|
|
// Only called by kit.
|
|
|
|
void setCanonicalViewId(int viewId) { _canonicalViewId = viewId; }
|
|
|
|
|
|
|
|
int getCanonicalViewId() { return _canonicalViewId; }
|
|
|
|
|
2023-03-01 03:20:08 +01:00
|
|
|
void setViewRenderState(const std::string& state) { _viewRenderState = state; }
|
|
|
|
|
2023-05-28 14:50:06 +02:00
|
|
|
bool getDumpTiles() { return _isDumpingTiles; }
|
|
|
|
|
|
|
|
void setDumpTiles(bool dumpTiles) { _isDumpingTiles = dumpTiles; }
|
|
|
|
|
2023-03-01 03:20:08 +01:00
|
|
|
std::string getViewRenderState() { return _viewRenderState; }
|
2023-08-15 16:34:09 +02:00
|
|
|
|
|
|
|
bool isTileInsideVisibleArea(const TileDesc& tile) const;
|
|
|
|
|
2016-08-13 18:14:44 +02:00
|
|
|
private:
|
2022-02-24 04:39:20 +01:00
|
|
|
bool loadDocument(const StringVector& tokens);
|
2024-03-29 11:53:46 +01:00
|
|
|
bool saveDocumentBackground(const StringVector &tokens);
|
2015-12-12 20:23:44 +01:00
|
|
|
|
2022-02-24 04:39:20 +01:00
|
|
|
bool sendFontRendering(const StringVector& tokens);
|
|
|
|
bool getCommandValues(const StringVector& tokens);
|
2015-12-12 20:23:44 +01:00
|
|
|
|
2022-02-24 04:39:20 +01:00
|
|
|
bool clientZoom(const StringVector& tokens);
|
|
|
|
bool clientVisibleArea(const StringVector& tokens);
|
|
|
|
bool outlineState(const StringVector& tokens);
|
|
|
|
bool downloadAs(const StringVector& tokens);
|
2015-12-12 20:23:44 +01:00
|
|
|
bool getChildId();
|
2022-02-24 04:39:20 +01:00
|
|
|
bool getTextSelection(const StringVector& tokens);
|
2020-02-28 10:50:58 +01:00
|
|
|
bool setClipboard(const char* buffer, int length, const StringVector& tokens);
|
2018-02-25 20:18:04 +01:00
|
|
|
std::string getTextSelectionInternal(const std::string& mimeType);
|
2020-02-28 10:50:58 +01:00
|
|
|
bool paste(const char* buffer, int length, const StringVector& tokens);
|
2022-02-24 04:39:20 +01:00
|
|
|
bool insertFile(const StringVector& tokens);
|
|
|
|
bool keyEvent(const StringVector& tokens, const LokEventTargetEnum target);
|
|
|
|
bool extTextInputEvent(const StringVector& tokens);
|
2017-08-24 13:47:40 +02:00
|
|
|
bool dialogKeyEvent(const char* buffer, int length, const std::vector<std::string>& tokens);
|
2022-02-24 04:39:20 +01:00
|
|
|
bool mouseEvent(const StringVector& tokens, const LokEventTargetEnum target);
|
|
|
|
bool gestureEvent(const StringVector& tokens);
|
|
|
|
bool dialogEvent(const StringVector& tokens);
|
|
|
|
bool completeFunction(const StringVector& tokens);
|
|
|
|
bool unoCommand(const StringVector& tokens);
|
|
|
|
bool selectText(const StringVector& tokens, const LokEventTargetEnum target);
|
|
|
|
bool selectGraphic(const StringVector& tokens);
|
|
|
|
bool renderWindow(const StringVector& tokens);
|
|
|
|
bool resizeWindow(const StringVector& tokens);
|
|
|
|
bool resetSelection(const StringVector& tokens);
|
|
|
|
bool saveAs(const StringVector& tokens);
|
2023-01-19 16:19:53 +01:00
|
|
|
bool exportAs(const StringVector& tokens);
|
2022-02-24 04:39:20 +01:00
|
|
|
bool setClientPart(const StringVector& tokens);
|
|
|
|
bool selectClientPart(const StringVector& tokens);
|
|
|
|
bool moveSelectedClientParts(const StringVector& tokens);
|
|
|
|
bool setPage(const StringVector& tokens);
|
|
|
|
bool sendWindowCommand(const StringVector& tokens);
|
2020-02-28 10:50:58 +01:00
|
|
|
bool askSignatureStatus(const char* buffer, int length, const StringVector& tokens);
|
2022-02-24 04:39:20 +01:00
|
|
|
bool renderShapeSelection(const StringVector& tokens);
|
|
|
|
bool removeTextContext(const StringVector& tokens);
|
2022-08-03 04:04:49 +02:00
|
|
|
#if ENABLE_FEATURE_LOCK || ENABLE_FEATURE_RESTRICTION
|
2022-02-24 04:39:20 +01:00
|
|
|
bool updateBlockingCommandStatus(const StringVector& tokens);
|
2021-09-17 15:49:06 +02:00
|
|
|
std::string getBlockedCommandType(std::string command);
|
2021-07-05 16:49:58 +02:00
|
|
|
#endif
|
2022-11-16 09:56:21 +01:00
|
|
|
bool handleZoteroMessage(const StringVector& tokens);
|
2021-08-09 07:48:27 +02:00
|
|
|
bool formFieldEvent(const char* buffer, int length, const StringVector& tokens);
|
2022-07-01 06:25:59 +02:00
|
|
|
bool contentControlEvent(const StringVector& tokens);
|
2021-08-09 07:48:27 +02:00
|
|
|
bool renderSearchResult(const char* buffer, int length, const StringVector& tokens);
|
2023-06-19 18:02:16 +02:00
|
|
|
bool setAccessibilityState(bool enable);
|
2023-04-07 10:58:09 +02:00
|
|
|
bool getA11yFocusedParagraph();
|
|
|
|
bool getA11yCaretPosition();
|
2015-12-12 20:23:44 +01:00
|
|
|
|
2017-01-13 13:52:08 +01:00
|
|
|
void rememberEventsForInactiveUser(const int type, const std::string& payload);
|
2017-01-02 14:21:49 +01:00
|
|
|
|
2016-08-13 18:14:44 +02:00
|
|
|
virtual void disconnect() override;
|
2016-10-30 02:15:00 +01:00
|
|
|
virtual bool _handleInput(const char* buffer, int length) override;
|
2015-12-25 19:51:32 +01:00
|
|
|
|
2021-07-09 17:57:09 +02:00
|
|
|
static void dumpRecordedUnoCommands();
|
|
|
|
|
2020-11-11 01:56:59 +01:00
|
|
|
std::shared_ptr<lok::Document> getLOKitDocument() const
|
2016-11-15 11:37:47 +01:00
|
|
|
{
|
2019-08-16 09:05:54 +02:00
|
|
|
return _docManager->getLOKitDocument();
|
2016-11-15 11:37:47 +01:00
|
|
|
}
|
|
|
|
|
2020-12-28 16:30:38 +01:00
|
|
|
std::shared_ptr<lok::Office> getLOKit() const
|
|
|
|
{
|
|
|
|
return _docManager->getLOKit();
|
|
|
|
}
|
|
|
|
|
2020-11-11 01:56:59 +01:00
|
|
|
std::string getLOKitLastError() const
|
2019-05-29 17:26:16 +02:00
|
|
|
{
|
2019-08-16 09:05:54 +02:00
|
|
|
char *lastErr = _docManager->getLOKit()->getError();
|
2019-05-29 17:26:16 +02:00
|
|
|
std::string ret;
|
|
|
|
if (lastErr)
|
|
|
|
{
|
|
|
|
ret = std::string(lastErr, strlen(lastErr));
|
|
|
|
free (lastErr);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-07-14 16:20:05 +02:00
|
|
|
public:
|
2024-02-06 12:28:52 +01:00
|
|
|
// simple one line for priming
|
|
|
|
std::string getActivityState()
|
|
|
|
{
|
|
|
|
std::stringstream ss;
|
|
|
|
ss << "view: " << _viewId
|
|
|
|
<< ", session " << getId()
|
|
|
|
<< (isReadOnly() ? ", ro": ", rw")
|
|
|
|
<< ", user: '" << getUserNameAnonym() << "'"
|
|
|
|
<< ", load" << (_isDocLoaded ? "ed" : "ing")
|
|
|
|
<< ", type: " << _docType
|
|
|
|
<< ", lang: " << getLang();
|
|
|
|
return ss.str();
|
|
|
|
}
|
|
|
|
|
2020-07-14 16:20:05 +02:00
|
|
|
void dumpState(std::ostream& oss) override
|
|
|
|
{
|
|
|
|
Session::dumpState(oss);
|
2024-01-18 15:09:32 +01:00
|
|
|
|
|
|
|
oss << "\n\tviewId: " << _viewId
|
|
|
|
<< "\n\tcanonicalViewId: " << _canonicalViewId
|
|
|
|
<< "\n\tisDocLoaded: " << _isDocLoaded
|
|
|
|
<< "\n\tdocType: " << _docType
|
|
|
|
<< "\n\tcopyingToClipboard: " << _copyToClipboard
|
|
|
|
<< "\n\tdocType: " << _docType
|
|
|
|
// FIXME: _pixmapCache
|
|
|
|
<< "\n\texportAsWopiUrl: " << _exportAsWopiUrl
|
|
|
|
<< "\n\tviewRenderedState: " << _viewRenderState
|
|
|
|
<< "\n\tisDumpingTiles: " << _isDocLoaded
|
|
|
|
<< "\n\tclientVisibleArea: " << _clientVisibleArea.toString()
|
|
|
|
<< "\n\thasURP: " << _hasURP
|
|
|
|
<< "\n\tURPContext?: " << (_URPContext == nullptr)
|
|
|
|
<< '\n';
|
|
|
|
|
|
|
|
_stateRecorder.dumpState(oss);
|
2020-07-14 16:20:05 +02:00
|
|
|
}
|
|
|
|
|
2015-12-25 19:51:32 +01:00
|
|
|
private:
|
2016-01-09 01:58:50 +01:00
|
|
|
const std::string _jailId;
|
2020-10-23 04:24:04 +02:00
|
|
|
const std::string _jailRoot;
|
2024-04-25 14:08:42 +02:00
|
|
|
Document* _docManager;
|
2016-08-21 18:56:58 +02:00
|
|
|
|
2020-11-11 01:56:59 +01:00
|
|
|
std::shared_ptr<Watermark> _docWatermark;
|
|
|
|
|
2017-06-27 13:44:50 +02:00
|
|
|
std::queue<std::chrono::steady_clock::time_point> _cursorInvalidatedEvent;
|
|
|
|
const unsigned _eventStorageIntervalMs = 15*1000;
|
|
|
|
|
2016-01-03 16:56:41 +01:00
|
|
|
/// View ID, returned by createView() or 0 by default.
|
|
|
|
int _viewId;
|
2016-08-21 18:56:58 +02:00
|
|
|
|
2020-04-26 22:55:16 +02:00
|
|
|
/// Whether document has been opened successfully
|
2016-08-21 18:56:58 +02:00
|
|
|
bool _isDocLoaded;
|
|
|
|
|
|
|
|
std::string _docType;
|
2017-01-02 14:21:49 +01:00
|
|
|
|
|
|
|
StateRecorder _stateRecorder;
|
2016-01-11 04:52:00 +01:00
|
|
|
|
2018-02-25 20:18:04 +01:00
|
|
|
/// If we are copying to clipboard.
|
|
|
|
bool _copyToClipboard;
|
2021-01-21 13:39:10 +01:00
|
|
|
|
|
|
|
std::vector<uint64_t> _pixmapCache;
|
2022-06-15 19:34:11 +02:00
|
|
|
|
|
|
|
/// How many sessions / clients we have
|
|
|
|
static size_t NumSessions;
|
2023-01-19 16:19:53 +01:00
|
|
|
|
|
|
|
/// stores wopi url for export as operation
|
|
|
|
std::string _exportAsWopiUrl;
|
2023-02-23 23:41:06 +01:00
|
|
|
|
2023-03-01 03:20:08 +01:00
|
|
|
/// stores info about the view
|
|
|
|
std::string _viewRenderState;
|
|
|
|
|
2023-02-23 23:41:06 +01:00
|
|
|
/// the canonical id unique to the set of rendering properties of this session
|
|
|
|
int _canonicalViewId;
|
2023-05-28 14:50:06 +02:00
|
|
|
|
|
|
|
/// whether we are dumping tiles as they are being drawn
|
|
|
|
bool _isDumpingTiles;
|
2023-08-15 16:34:09 +02:00
|
|
|
|
|
|
|
Util::Rectangle _clientVisibleArea;
|
2023-07-31 16:28:27 +02:00
|
|
|
|
2023-10-03 21:57:30 +02:00
|
|
|
void* _URPContext;
|
2023-07-31 16:28:27 +02:00
|
|
|
|
|
|
|
/// whether there is a URP session created for this ChildSession
|
2023-10-03 21:57:30 +02:00
|
|
|
bool _hasURP;
|
2024-01-18 15:09:32 +01:00
|
|
|
|
|
|
|
// When state is added - please update dumpState above.
|
2015-12-12 20:23:44 +01:00
|
|
|
};
|
|
|
|
|
2015-12-13 18:47:14 +01:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|