diff options
author | Lorn Potter <[email protected]> | 2023-10-05 13:47:36 +1000 |
---|---|---|
committer | Lorn Potter <[email protected]> | 2023-12-21 11:04:12 +1000 |
commit | 66c2dfbebab4ec632b723779a9a41896d35e84d0 (patch) | |
tree | 7a6b19c5d7d22c1990e1d850ff88403ad07e753a | |
parent | 4f95e66f940c3a6c72f51c2428620c09e30bbd0b (diff) |
wasm: extend qstdweb to support objectUrls in File
Change-Id: If346f8afcf4578dedccce6f768e85c7750a9de3e
Done-with: [email protected]
Reviewed-by: Morten Johan Sørvig <[email protected]>
-rw-r--r-- | src/corelib/platform/wasm/qstdweb.cpp | 29 | ||||
-rw-r--r-- | src/corelib/platform/wasm/qstdweb_p.h | 29 |
2 files changed, 57 insertions, 1 deletions
diff --git a/src/corelib/platform/wasm/qstdweb.cpp b/src/corelib/platform/wasm/qstdweb.cpp index e0c6d432c1d..38ade571bda 100644 --- a/src/corelib/platform/wasm/qstdweb.cpp +++ b/src/corelib/platform/wasm/qstdweb.cpp @@ -578,6 +578,17 @@ File::File(const emscripten::val &file) } +File::~File() = default; + +File::File(const File &other) = default; + +File::File(File &&other) = default; + +File &File::operator=(const File &other) = default; + +File &File::operator=(File &&other) = default; + + Blob File::slice(uint64_t begin, uint64_t end) const { return Blob(m_file.call<emscripten::val>("slice", uint53_t(begin), uint53_t(end))); @@ -623,6 +634,22 @@ emscripten::val File::val() const return m_file; } +FileUrlRegistration::FileUrlRegistration(File file) +{ + m_path = QString::fromStdString(emscripten::val::global("window")["URL"].call<std::string>( + "createObjectURL", file.file())); +} + +FileUrlRegistration::~FileUrlRegistration() +{ + emscripten::val::global("window")["URL"].call<void>("revokeObjectURL", + emscripten::val(m_path.toStdString())); +} + +FileUrlRegistration::FileUrlRegistration(FileUrlRegistration &&other) = default; + +FileUrlRegistration &FileUrlRegistration::operator=(FileUrlRegistration &&other) = default; + FileList::FileList(const emscripten::val &fileList) :m_fileList(fileList) { @@ -902,7 +929,7 @@ namespace Promise { // // haveJspi(): returns true if asyncify 2 (JSPI) is available. // -// canBlockCallingThread(): returns true if the calling thread can block on +// canBlockCallingThread(): returns true if the calling thread can block on // QEventLoop::exec(), using either asyncify or as a seconarday thread. bool haveJspi() { diff --git a/src/corelib/platform/wasm/qstdweb_p.h b/src/corelib/platform/wasm/qstdweb_p.h index 8ec32416d31..110e2c10ac4 100644 --- a/src/corelib/platform/wasm/qstdweb_p.h +++ b/src/corelib/platform/wasm/qstdweb_p.h @@ -88,6 +88,12 @@ namespace qstdweb { public: File() = default; explicit File(const emscripten::val &file); + ~File(); + + File(const File &other); + File(File &&other); + File &operator=(const File &other); + File &operator=(File &&other); Blob slice(uint64_t begin, uint64_t end) const; std::string name() const; @@ -97,11 +103,34 @@ namespace qstdweb { std::function<void()> completed) const; void stream(char *buffer, std::function<void()> completed) const; emscripten::val val() const; + void fileUrlRegistration() const; + const QString &fileUrlPath() const { return m_urlPath; } + emscripten::val file() const { return m_file; } private: emscripten::val m_file = emscripten::val::undefined(); + QString m_urlPath; + }; + + class Q_CORE_EXPORT FileUrlRegistration + { + public: + explicit FileUrlRegistration(File file); + ~FileUrlRegistration(); + + FileUrlRegistration(const FileUrlRegistration &other) = delete; + FileUrlRegistration(FileUrlRegistration &&other); + FileUrlRegistration &operator=(const FileUrlRegistration &other) = delete; + FileUrlRegistration &operator=(FileUrlRegistration &&other); + + const QString &path() const { return m_path; } + + private: + QString m_path; }; + using FileUrlRegistrations = std::vector<std::unique_ptr<FileUrlRegistration>>; + class Q_CORE_EXPORT FileList { public: FileList() = default; |