2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-07-25 08:29:47 +04:00
|
|
|
|
2014-10-08 20:15:23 +04:00
|
|
|
#ifndef mozilla_dom_File_h
|
|
|
|
#define mozilla_dom_File_h
|
2007-07-25 08:29:47 +04:00
|
|
|
|
2017-02-16 20:26:38 +03:00
|
|
|
#include "mozilla/dom/Blob.h"
|
2011-07-12 06:41:29 +04:00
|
|
|
|
2007-07-25 08:29:47 +04:00
|
|
|
class nsIFile;
|
2014-06-27 07:46:34 +04:00
|
|
|
|
2014-06-26 20:47:44 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2014-04-30 00:02:41 +04:00
|
|
|
|
2014-10-08 20:15:23 +04:00
|
|
|
struct ChromeFilePropertyBag;
|
2014-10-08 20:15:22 +04:00
|
|
|
struct FilePropertyBag;
|
2017-02-08 12:18:32 +03:00
|
|
|
class Promise;
|
2012-06-03 20:33:52 +04:00
|
|
|
|
2015-05-12 15:09:51 +03:00
|
|
|
class File final : public Blob {
|
|
|
|
friend class Blob;
|
|
|
|
|
|
|
|
public:
|
2015-05-12 15:11:03 +03:00
|
|
|
// Note: BlobImpl must be a File in order to use this method.
|
2015-05-12 15:09:51 +03:00
|
|
|
// Check impl->IsFile().
|
2019-10-21 08:33:33 +03:00
|
|
|
static File* Create(nsIGlobalObject* aGlobal, BlobImpl* aImpl);
|
2015-05-12 15:09:51 +03:00
|
|
|
|
2015-05-12 00:54:02 +03:00
|
|
|
// The returned File takes ownership of aMemoryBuffer. aMemoryBuffer will be
|
|
|
|
// freed by free so it must be allocated by malloc or something
|
|
|
|
// compatible with it.
|
2020-03-05 02:10:22 +03:00
|
|
|
static already_AddRefed<File> CreateMemoryFileWithLastModifiedNow(
|
|
|
|
nsIGlobalObject* aGlobal, void* aMemoryBuffer, uint64_t aLength,
|
|
|
|
const nsAString& aName, const nsAString& aContentType);
|
|
|
|
|
|
|
|
// You should not use this method! Please consider to use the
|
|
|
|
// CreateMemoryFileWithLastModifiedNow.
|
|
|
|
static already_AddRefed<File> CreateMemoryFileWithCustomLastModified(
|
|
|
|
nsIGlobalObject* aGlobal, void* aMemoryBuffer, uint64_t aLength,
|
|
|
|
const nsAString& aName, const nsAString& aContentType,
|
|
|
|
int64_t aLastModifiedDate);
|
2015-05-12 00:54:02 +03:00
|
|
|
|
2016-03-31 10:32:58 +03:00
|
|
|
// This method creates a BlobFileImpl for the new File object. This is
|
|
|
|
// thread-safe, cross-process, cross-thread as any other BlobImpl, but, when
|
|
|
|
// GetType() is called, it must dispatch a runnable to the main-thread in
|
|
|
|
// order to use nsIMIMEService.
|
|
|
|
// Would be nice if we try to avoid to use this method outside the
|
|
|
|
// main-thread to avoid extra runnables.
|
2019-10-21 08:33:33 +03:00
|
|
|
static already_AddRefed<File> CreateFromFile(nsIGlobalObject* aGlobal,
|
2017-01-24 14:11:07 +03:00
|
|
|
nsIFile* aFile);
|
2014-06-26 20:47:44 +04:00
|
|
|
|
2019-10-21 08:33:33 +03:00
|
|
|
static already_AddRefed<File> CreateFromFile(nsIGlobalObject* aGlobal,
|
2014-10-08 20:15:22 +04:00
|
|
|
nsIFile* aFile,
|
|
|
|
const nsAString& aName,
|
2014-06-26 20:47:44 +04:00
|
|
|
const nsAString& aContentType);
|
|
|
|
|
2014-10-08 20:15:22 +04:00
|
|
|
// WebIDL methods
|
|
|
|
|
2015-05-12 15:09:51 +03:00
|
|
|
virtual JSObject* WrapObject(JSContext* cx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) override;
|
2014-10-08 20:15:22 +04:00
|
|
|
|
|
|
|
// File constructor
|
|
|
|
static already_AddRefed<File> Constructor(const GlobalObject& aGlobal,
|
2016-06-01 13:33:09 +03:00
|
|
|
const Sequence<BlobPart>& aData,
|
2014-10-08 20:15:22 +04:00
|
|
|
const nsAString& aName,
|
|
|
|
const FilePropertyBag& aBag,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
|
2016-11-11 20:56:44 +03:00
|
|
|
// ChromeOnly
|
2017-02-08 12:18:32 +03:00
|
|
|
static already_AddRefed<Promise> CreateFromFileName(
|
2016-11-11 20:56:44 +03:00
|
|
|
const GlobalObject& aGlobal, const nsAString& aFilePath,
|
|
|
|
const ChromeFilePropertyBag& aBag, SystemCallerGuarantee aGuarantee,
|
|
|
|
ErrorResult& aRv);
|
2014-10-08 20:15:22 +04:00
|
|
|
|
2016-11-11 20:56:44 +03:00
|
|
|
// ChromeOnly
|
2017-02-08 12:18:32 +03:00
|
|
|
static already_AddRefed<Promise> CreateFromNsIFile(
|
2016-11-11 20:56:44 +03:00
|
|
|
const GlobalObject& aGlobal, nsIFile* aFile,
|
|
|
|
const ChromeFilePropertyBag& aBag, SystemCallerGuarantee aGuarantee,
|
|
|
|
ErrorResult& aRv);
|
2014-10-08 20:15:22 +04:00
|
|
|
|
2016-04-01 13:50:16 +03:00
|
|
|
void GetName(nsAString& aName) const;
|
2014-10-08 20:15:22 +04:00
|
|
|
|
|
|
|
int64_t GetLastModified(ErrorResult& aRv);
|
|
|
|
|
2017-02-06 13:07:54 +03:00
|
|
|
void GetRelativePath(nsAString& aPath) const;
|
2015-05-12 15:09:51 +03:00
|
|
|
|
2017-02-01 23:43:37 +03:00
|
|
|
void GetMozFullPath(nsAString& aFilename, SystemCallerGuarantee aGuarantee,
|
2019-04-26 20:53:07 +03:00
|
|
|
ErrorResult& aRv);
|
2014-10-08 20:15:22 +04:00
|
|
|
|
2019-04-26 20:53:07 +03:00
|
|
|
void GetMozFullPathInternal(nsAString& aName, ErrorResult& aRv);
|
2015-05-18 16:51:54 +03:00
|
|
|
|
2015-05-12 15:09:51 +03:00
|
|
|
protected:
|
|
|
|
virtual bool HasFileInterface() const override { return true; }
|
2014-06-27 07:46:34 +04:00
|
|
|
|
|
|
|
private:
|
2015-05-12 15:09:51 +03:00
|
|
|
// File constructor should never be used directly. Use Blob::Create or
|
|
|
|
// File::Create.
|
2019-10-21 08:33:33 +03:00
|
|
|
File(nsIGlobalObject* aGlobal, BlobImpl* aImpl);
|
2017-02-16 20:26:38 +03:00
|
|
|
~File();
|
2016-09-21 13:27:26 +03:00
|
|
|
};
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2014-10-08 20:15:22 +04:00
|
|
|
|
2014-10-08 20:15:23 +04:00
|
|
|
#endif // mozilla_dom_File_h
|