LibWeb/EntriesAPI: Implement FileSystemEntry

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

View file

@ -4186,6 +4186,7 @@ static void generate_using_namespace_definitions(SourceGenerator& generator)
using namespace Web::DOMParsing;
using namespace Web::DOMURL;
using namespace Web::Encoding;
using namespace Web::EntriesAPI;
using namespace Web::Fetch;
using namespace Web::FileAPI;
using namespace Web::Geometry;

View file

@ -0,0 +1,5 @@
source_set("EntriesAPI") {
configs += [ "//Userland/Libraries/LibWeb:configs" ]
deps = [ "//Userland/Libraries/LibWeb:all_generated" ]
sources = [ "FileSystemEntry.cpp" ]
}

View file

@ -93,6 +93,7 @@ standard_idl_files = [
"//Userland/Libraries/LibWeb/DOMURL/DOMURL.idl",
"//Userland/Libraries/LibWeb/Encoding/TextDecoder.idl",
"//Userland/Libraries/LibWeb/Encoding/TextEncoder.idl",
"//Userland/Libraries/LibWeb/EntriesAPI/FileSystemEntry.idl",
"//Userland/Libraries/LibWeb/Fetch/Request.idl",
"//Userland/Libraries/LibWeb/Fetch/Response.idl",
"//Userland/Libraries/LibWeb/FileAPI/Blob.idl",

View file

@ -97,6 +97,7 @@ EventTarget
File
FileList
FileReader
FileSystemEntry
FinalizationRegistry
Float32Array
Float64Array

View file

@ -211,6 +211,7 @@ set(SOURCES
Dump.cpp
Encoding/TextDecoder.cpp
Encoding/TextEncoder.cpp
EntriesAPI/FileSystemEntry.cpp
Fetch/Body.cpp
Fetch/BodyInit.cpp
Fetch/Enums.cpp

View file

@ -0,0 +1,55 @@
/*
* Copyright (c) 2024, Jamie Mansfield <jmansfield@cadixdev.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Bindings/FileSystemEntryPrototype.h>
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/EntriesAPI/FileSystemEntry.h>
#include <LibWeb/HTML/Window.h>
namespace Web::EntriesAPI {
JS_DEFINE_ALLOCATOR(FileSystemEntry);
JS::NonnullGCPtr<FileSystemEntry> FileSystemEntry::create(JS::Realm& realm, EntryType entry_type, ByteString name)
{
return realm.heap().allocate<FileSystemEntry>(realm, realm, entry_type, name);
}
FileSystemEntry::FileSystemEntry(JS::Realm& realm, EntryType entry_type, ByteString name)
: PlatformObject(realm)
, m_entry_type(entry_type)
, m_name(name)
{
}
void FileSystemEntry::initialize(JS::Realm& realm)
{
Base::initialize(realm);
WEB_SET_PROTOTYPE_FOR_INTERFACE(FileSystemEntry);
}
// https://wicg.github.io/entries-api/#dom-filesystementry-isfile
bool FileSystemEntry::is_file() const
{
// The isFile getter steps are to return true if this is a file entry and false otherwise.
return m_entry_type == EntryType::File;
}
// https://wicg.github.io/entries-api/#dom-filesystementry-isdirectory
bool FileSystemEntry::is_directory() const
{
// The isDirectory getter steps are to return true if this is a directory entry and false otherwise.
return m_entry_type == EntryType::Directory;
}
// https://wicg.github.io/entries-api/#dom-filesystementry-name
ByteString FileSystemEntry::name() const
{
// The name getter steps are to return this's name.
return m_name;
}
}

View file

@ -0,0 +1,39 @@
/*
* Copyright (c) 2024, Jamie Mansfield <jmansfield@cadixdev.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibWeb/Bindings/PlatformObject.h>
namespace Web::EntriesAPI {
enum class EntryType {
File,
Directory,
};
class FileSystemEntry final : public Bindings::PlatformObject {
WEB_PLATFORM_OBJECT(FileSystemEntry, Bindings::PlatformObject);
JS_DECLARE_ALLOCATOR(FileSystemEntry);
public:
static JS::NonnullGCPtr<FileSystemEntry> create(JS::Realm&, EntryType entry_type, ByteString name);
virtual ~FileSystemEntry() override = default;
bool is_file() const;
bool is_directory() const;
ByteString name() const;
private:
FileSystemEntry(JS::Realm&, EntryType entry_type, ByteString name);
virtual void initialize(JS::Realm&) override;
EntryType m_entry_type;
ByteString m_name;
};
}

View file

@ -0,0 +1,10 @@
[Exposed=Window]
interface FileSystemEntry {
readonly attribute boolean isFile;
readonly attribute boolean isDirectory;
readonly attribute USVString name;
[FIXME] readonly attribute USVString fullPath;
[FIXME] readonly attribute FileSystem filesystem;
[FIXME] undefined getParent(optional FileSystemEntryCallback successCallback, optional ErrorCallback errorCallback);
};

View file

@ -297,6 +297,10 @@ class TextEncoder;
struct TextEncoderEncodeIntoResult;
}
namespace Web::EntriesAPI {
class FileSystemEntry;
}
namespace Web::Fetch {
class BodyMixin;
class Headers;

View file

@ -78,6 +78,7 @@ libweb_js_bindings(DOMURL/DOMURL)
libweb_js_bindings(DOMURL/URLSearchParams ITERABLE)
libweb_js_bindings(Encoding/TextDecoder)
libweb_js_bindings(Encoding/TextEncoder)
libweb_js_bindings(EntriesAPI/FileSystemEntry)
libweb_js_bindings(Fetch/Headers ITERABLE)
libweb_js_bindings(Fetch/Request)
libweb_js_bindings(Fetch/Response)