wasm: extend qstdweb to support objectUrls in File
Change-Id: If346f8afcf4578dedccce6f768e85c7750a9de3e Done-with: Mikolaj.Boc@qt.io Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
This commit is contained in:
parent
e853c83491
commit
a7bf26642b
@ -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
|
Blob File::slice(uint64_t begin, uint64_t end) const
|
||||||
{
|
{
|
||||||
return Blob(m_file.call<emscripten::val>("slice", uint53_t(begin), uint53_t(end)));
|
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;
|
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)
|
FileList::FileList(const emscripten::val &fileList)
|
||||||
:m_fileList(fileList)
|
:m_fileList(fileList)
|
||||||
{
|
{
|
||||||
@ -902,7 +929,7 @@ namespace Promise {
|
|||||||
//
|
//
|
||||||
// haveJspi(): returns true if asyncify 2 (JSPI) is available.
|
// 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.
|
// QEventLoop::exec(), using either asyncify or as a seconarday thread.
|
||||||
bool haveJspi()
|
bool haveJspi()
|
||||||
{
|
{
|
||||||
|
@ -88,6 +88,12 @@ namespace qstdweb {
|
|||||||
public:
|
public:
|
||||||
File() = default;
|
File() = default;
|
||||||
explicit File(const emscripten::val &file);
|
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;
|
Blob slice(uint64_t begin, uint64_t end) const;
|
||||||
std::string name() const;
|
std::string name() const;
|
||||||
@ -97,11 +103,34 @@ namespace qstdweb {
|
|||||||
std::function<void()> completed) const;
|
std::function<void()> completed) const;
|
||||||
void stream(char *buffer, std::function<void()> completed) const;
|
void stream(char *buffer, std::function<void()> completed) const;
|
||||||
emscripten::val val() const;
|
emscripten::val val() const;
|
||||||
|
void fileUrlRegistration() const;
|
||||||
|
const QString &fileUrlPath() const { return m_urlPath; }
|
||||||
|
emscripten::val file() const { return m_file; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
emscripten::val m_file = emscripten::val::undefined();
|
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 {
|
class Q_CORE_EXPORT FileList {
|
||||||
public:
|
public:
|
||||||
FileList() = default;
|
FileList() = default;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user