1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 23:37:36 +00:00

Clipboard: Move the system clipboard to a dedicated service process :^)

This commit moves the clipboard from WindowServer into a new Clipboard
service program. Clipboard runs as the unprivileged "clipboard" user
and with a much tighter pledge than WindowServer.

To keep things working as before, all GUI::Application users now make
a connection to Clipboard after making the connection to WindowServer.
It could be interesting to connect to Clipboard on demand, but right
now that would necessitate expanding every GUI app's pledge to include
"unix" and also unveiling the clipboard portal, which I prefer not to.
This commit is contained in:
Andreas Kling 2020-05-14 22:51:15 +02:00
parent f4c60740bd
commit 244efe050a
25 changed files with 447 additions and 146 deletions

View file

@ -0,0 +1,44 @@
#pragma once
#include <AK/Function.h>
#include <AK/SharedBuffer.h>
#include <AK/String.h>
namespace Clipboard {
class Storage {
public:
static Storage& the();
~Storage();
bool has_data() const { return m_shared_buffer; }
const String& mime_type() const { return m_mime_type; }
const u8* data() const
{
if (!has_data())
return nullptr;
return static_cast<const u8*>(m_shared_buffer->data());
}
size_t data_size() const
{
if (has_data())
return m_data_size;
return 0;
}
void set_data(NonnullRefPtr<SharedBuffer>, size_t data_size, const String& mime_type);
Function<void()> on_content_change;
private:
Storage();
String m_mime_type;
RefPtr<SharedBuffer> m_shared_buffer;
size_t m_data_size { 0 };
};
}