summaryrefslogtreecommitdiff
path: root/src/protocols/core/DataDevice.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/protocols/core/DataDevice.cpp')
-rw-r--r--src/protocols/core/DataDevice.cpp83
1 files changed, 82 insertions, 1 deletions
diff --git a/src/protocols/core/DataDevice.cpp b/src/protocols/core/DataDevice.cpp
index 41f07273..1318910a 100644
--- a/src/protocols/core/DataDevice.cpp
+++ b/src/protocols/core/DataDevice.cpp
@@ -1,5 +1,6 @@
#include "DataDevice.hpp"
#include <algorithm>
+#include <hyprutils/os/FileDescriptor.hpp>
#include "../../managers/SeatManager.hpp"
#include "../../managers/PointerManager.hpp"
#include "../../managers/eventLoop/EventLoopManager.hpp"
@@ -15,6 +16,7 @@
#include "../../helpers/Monitor.hpp"
#include "../../render/Renderer.hpp"
#include "../../xwayland/Dnd.hpp"
+#include "../../managers/permissions/DynamicPermissionManager.hpp"
using namespace Hyprutils::OS;
CWLDataOfferResource::CWLDataOfferResource(SP<CWlDataOffer> resource_, SP<IDataSource> source_) : m_source(source_), m_resource(resource_) {
@@ -53,7 +55,49 @@ CWLDataOfferResource::CWLDataOfferResource(SP<CWlDataOffer> resource_, SP<IDataS
return;
}
- LOGM(Log::DEBUG, "Offer {:x} asks to send data from source {:x}", (uintptr_t)this, (uintptr_t)m_source.get());
+ const auto CLIENT = r->client();
+ const auto PERM = g_pDynamicPermissionManager->clientPermissionMode(CLIENT, PERMISSION_TYPE_CLIPBOARD_READ);
+ if (PERM == PERMISSION_RULE_ALLOW_MODE_DENY) {
+ LOGM(Log::LOG, "Clipboard read denied by permission manager for client {:x}", (uintptr_t)CLIENT);
+ return;
+ } else if (PERM == PERMISSION_RULE_ALLOW_MODE_PENDING) {
+ LOGM(Log::LOG, "Clipboard read permission pending for client {:x}", (uintptr_t)CLIENT);
+ const auto PROMISE = g_pDynamicPermissionManager->promiseFor(CLIENT, PERMISSION_TYPE_CLIPBOARD_READ);
+ if (!PROMISE) {
+ LOGM(Log::ERR, "BUG THIS: No promise for client permission for clipboard read");
+ return;
+ }
+ auto sharedFd = std::make_shared<CFileDescriptor>(std::move(sendFd));
+ PROMISE->then([this, mime = std::string(mime ? mime : ""), sharedFd](SP<CPromiseResult<eDynamicPermissionAllowMode>> r) {
+ if (r->hasError()) {
+ LOGM(Log::ERR, "BUG THIS: No permission returned for clipboard read");
+ return;
+ }
+
+ if (r->result() != PERMISSION_RULE_ALLOW_MODE_ALLOW) {
+ LOGM(Log::LOG, "Clipboard read denied by user");
+ return;
+ }
+
+ if (!m_source) {
+ LOGM(Log::WARN, "Source disappeared while waiting for permission");
+ return;
+ }
+
+ LOGM(Log::LOG, "Offer {:x} asks to send data from source {:x} (permission granted)", (uintptr_t)this, (uintptr_t)m_source.get());
+
+ if (!m_accepted) {
+ LOGM(Log::WARN, "Offer was never accepted, sending accept first");
+ m_source->accepted(mime.c_str());
+ }
+
+ m_source->send(mime.c_str(), std::move(*sharedFd));
+ m_recvd = true;
+ });
+ return;
+ }
+
+ LOGM(Log::LOG, "Offer {:x} asks to send data from source {:x}", (uintptr_t)this, (uintptr_t)m_source.get());
if (!m_accepted) {
LOGM(Log::WARN, "Offer was never accepted, sending accept first");
@@ -253,6 +297,43 @@ CWLDataDeviceResource::CWLDataDeviceResource(SP<CWlDataDevice> resource_) : m_re
return;
}
+ const auto CLIENT = r->client();
+ const auto PERM = g_pDynamicPermissionManager->clientPermissionMode(CLIENT, PERMISSION_TYPE_CLIPBOARD_WRITE);
+ if (PERM == PERMISSION_RULE_ALLOW_MODE_DENY) {
+ LOGM(Log::LOG, "Clipboard write denied by permission manager for client {:x}", (uintptr_t)CLIENT);
+ return;
+ } else if (PERM == PERMISSION_RULE_ALLOW_MODE_PENDING) {
+ LOGM(Log::LOG, "Clipboard write permission pending for client {:x}", (uintptr_t)CLIENT);
+ const auto PROMISE = g_pDynamicPermissionManager->promiseFor(CLIENT, PERMISSION_TYPE_CLIPBOARD_WRITE);
+ if (!PROMISE) {
+ LOGM(Log::ERR, "BUG THIS: No promise for client permission for clipboard write");
+ return;
+ }
+ PROMISE->then([source](SP<CPromiseResult<eDynamicPermissionAllowMode>> r) mutable {
+ if (r->hasError()) {
+ LOGM(Log::ERR, "BUG THIS: No permission returned for clipboard write");
+ return;
+ }
+
+ if (r->result() != PERMISSION_RULE_ALLOW_MODE_ALLOW) {
+ LOGM(Log::LOG, "Clipboard write denied by user");
+ return;
+ }
+
+ if (!source) {
+ LOGM(Log::WARN, "Source disappeared while waiting for permission");
+ return;
+ }
+
+ if (source && source->m_used)
+ LOGM(Log::WARN, "setSelection on a used resource. By protocol, this is a violation, but firefox et al insist on doing this.");
+
+ source->markUsed();
+ g_pSeatManager->setCurrentSelection(source);
+ });
+ return;
+ }
+
if (source && source->m_used)
LOGM(Log::WARN, "setSelection on a used resource. By protocol, this is a violation, but firefox et al insist on doing this.");