commit b2e55c74851da38ae7125c579d92cf53ea6d1f95
parent bc3b51afc6bd17fd9f7fc21491ed64be021ef865
Author: Jan Horak <jhorak@redhat.com>
Date: Thu, 9 Oct 2025 07:24:44 +0000
Bug 1950034 Prefer portals over text/uri-list in drag and drop; r=stransky
Currently we don't have test for these.
Differential Revision: https://phabricator.services.mozilla.com/D263675
Diffstat:
1 file changed, 20 insertions(+), 20 deletions(-)
diff --git a/widget/gtk/nsDragService.cpp b/widget/gtk/nsDragService.cpp
@@ -1168,9 +1168,19 @@ nsDragSession::GetData(nsITransferable* aTransferable, uint32_t aItemIndex) {
dragData = GetDragData(sTextPlainUTF8TypeAtom);
}
+ // Try portals first since text/uri-list URIs in sandboxed environments
+ // (Flatpak/Snap) may point to inaccessible file paths.
+ if (requestedFlavor == sURLMimeAtom || requestedFlavor == sFileMimeAtom) {
+ LOGDRAGSERVICE(" try portals first\n");
+ dragData = GetDragData(sPortalFileAtom);
+ if (!dragData) {
+ dragData = GetDragData(sPortalFileTransferAtom);
+ }
+ }
+
// We are looking for text/x-moz-url. That format may be poorly supported,
// try first with text/uri-list, and then _NETSCAPE_URL
- if (requestedFlavor == sURLMimeAtom) {
+ if (!dragData && requestedFlavor == sURLMimeAtom) {
LOGDRAGSERVICE(" conversion %s => %s", gTextUriListType, kURLMime);
dragData = GetDragData(sTextUriListTypeAtom);
if (dragData) {
@@ -1195,27 +1205,17 @@ nsDragSession::GetData(nsITransferable* aTransferable, uint32_t aItemIndex) {
}
// We're asked to get file mime type but we failed.
- // Try portal variants and text/uri-list conversion.
+ // Try text/uri-list conversion.
if (!dragData && requestedFlavor == sFileMimeAtom) {
- // application/vnd.portal.files
- dragData = GetDragData(sPortalFileAtom);
-
- // application/vnd.portal.filetransfer
- if (!dragData) {
- dragData = GetDragData(sPortalFileTransferAtom);
- }
-
- if (!dragData) {
- LOGDRAGSERVICE(
- " file not found, proceed with conversion %s => %s flavor\n",
- gTextUriListType, kFileMime);
- // Conversion text/uri-list => application/x-moz-file
- dragData = GetDragData(sTextUriListTypeAtom);
+ LOGDRAGSERVICE(
+ " file not found, proceed with conversion %s => %s flavor\n",
+ gTextUriListType, kFileMime);
+ // Conversion text/uri-list => application/x-moz-file
+ dragData = GetDragData(sTextUriListTypeAtom);
+ if (dragData) {
+ dragData = dragData->ConvertToFile();
if (dragData) {
- dragData = dragData->ConvertToFile();
- if (dragData) {
- mCachedDragData.InsertOrUpdate(dragData->GetFlavor(), dragData);
- }
+ mCachedDragData.InsertOrUpdate(dragData->GetFlavor(), dragData);
}
}
}