Bug 377621 [Linux] Don't advertise _NETSCAPE_URL MIME type for internal data r=emilio

_NETSCAPE_URL hints target application it should store URL link instead of copy the pointed data.
Don't use that for internal URL (mailbox:/// and similar).

Differential Revision: https://phabricator.services.mozilla.com/D161442
This commit is contained in:
stransky 2022-11-08 19:23:01 +00:00
Родитель 0092bf74f2
Коммит 908442a9d5
1 изменённых файлов: 44 добавлений и 2 удалений

Просмотреть файл

@ -102,8 +102,20 @@ static void SetMotionEvent(GUniquePtr<GdkEvent> aEvent) {
static GtkWidget* sGrabWidget;
static const char gMimeListType[] = "application/x-moz-internal-item-list";
static constexpr nsLiteralString kDisallowedExportedSchemes[] = {
u"about"_ns, u"blob"_ns, u"chrome"_ns, u"imap"_ns,
u"javascript"_ns, u"mailbox"_ns, u"moz-anno"_ns, u"news"_ns,
u"page-icon"_ns, u"resource"_ns, u"view-source"_ns, u"moz-extension"_ns,
};
// _NETSCAPE_URL is similar to text/uri-list type.
// Format is UTF8: URL + "\n" + title.
// While text/uri-list tells target application to fetch, copy and store data
// from URL, _NETSCAPE_URL suggest to create a link to the target.
// Also _NETSCAPE_URL points to only one item while text/uri-list can point to
// multiple ones.
static const char gMozUrlType[] = "_NETSCAPE_URL";
static const char gMimeListType[] = "application/x-moz-internal-item-list";
static const char gTextUriListType[] = "text/uri-list";
static const char gTextPlainUTF8Type[] = "text/plain;charset=utf-8";
static const char gXdndDirectSaveType[] = "XdndDirectSave0";
@ -1273,6 +1285,21 @@ static void TargetArrayAddTarget(nsTArray<GtkTargetEntry*>& aTargetArray,
LOGDRAGSERVICESTATIC("adding target %s\n", aTarget);
}
static bool CanExportAsURLTarget(char16_t* aURLData, uint32_t aURLLen) {
for (const nsLiteralString& disallowed : kDisallowedExportedSchemes) {
auto len = disallowed.AsString().Length();
if (len < aURLLen) {
if (!memcmp(disallowed.get(), aURLData,
/* len is char16_t char count */ len * 2)) {
LOGDRAGSERVICESTATIC("rejected URL scheme %s\n",
NS_ConvertUTF16toUTF8(disallowed).get());
return false;
}
}
}
return true;
}
GtkTargetList* nsDragService::GetSourceList(void) {
if (!mSourceDataItems) {
return nullptr;
@ -1339,7 +1366,22 @@ GtkTargetList* nsDragService::GetSourceList(void) {
// If it is, add _NETSCAPE_URL
// this is a type used by everybody.
else if (flavorStr.EqualsLiteral(kURLMime)) {
TargetArrayAddTarget(targetArray, gMozUrlType);
nsCOMPtr<nsISupports> data;
if (NS_SUCCEEDED(currItem->GetTransferData(flavorStr.get(),
getter_AddRefs(data)))) {
void* tmpData = nullptr;
uint32_t tmpDataLen = 0;
nsPrimitiveHelpers::CreateDataFromPrimitive(
nsDependentCString(flavorStr.get()), data, &tmpData,
&tmpDataLen);
if (tmpData) {
if (CanExportAsURLTarget(reinterpret_cast<char16_t*>(tmpData),
tmpDataLen / 2)) {
TargetArrayAddTarget(targetArray, gMozUrlType);
}
free(tmpData);
}
}
}
// check if application/x-moz-file-promise url is supported.
// If so, advertise text/uri-list.