LibWeb/HTML: Implement DataTransferItem.webkitGetAsEntry()

This commit is contained in:
Jamie Mansfield 2024-08-23 19:41:56 +01:00 committed by Andreas Kling
parent 169163b002
commit 2e9aec984c
Notes: github-actions[bot] 2024-08-24 12:54:04 +00:00
5 changed files with 34 additions and 0 deletions

View file

@ -1,5 +1,6 @@
/*
* Copyright (c) 2024, Tim Flynn <trflynn89@serenityos.org>
* Copyright (c) 2024, Jamie Mansfield <jmansfield@cadixdev.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -148,4 +149,26 @@ JS::GCPtr<FileAPI::File> DataTransferItem::get_as_file() const
return MUST(FileAPI::File::create(realm, { JS::make_handle(blob) }, file_name, move(options)));
}
// https://wicg.github.io/entries-api/#dom-datatransferitem-webkitgetasentry
JS::GCPtr<EntriesAPI::FileSystemEntry> DataTransferItem::webkit_get_as_entry() const
{
auto& realm = this->realm();
// 1. Let store be this's DataTransfer objects drag data store.
// 2. If stores drag data store mode is not read/write mode or read-only mode, return null and abort these steps
if (mode() != DragDataStore::Mode::ReadWrite && mode() != DragDataStore::Mode::ReadOnly)
return nullptr;
// 3. Let item be the item in stores drag data store item list that this represents.
auto const& item = m_data_transfer->drag_data(*m_item_index);
// 4. If items kind is not File, then return null and abort these steps.
if (item.kind != DragDataStoreItem::Kind::File)
return nullptr;
// 5. Return a new FileSystemEntry object representing the entry.
return EntriesAPI::FileSystemEntry::create(realm, EntriesAPI::EntryType::File, item.file_name);
}
}