2012-06-03 09:33:52 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=2 et sw=2 tw=80: */
|
|
|
|
/* 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/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_dom_file_filehandle_h__
|
|
|
|
#define mozilla_dom_file_filehandle_h__
|
|
|
|
|
|
|
|
#include "FileCommon.h"
|
|
|
|
|
|
|
|
#include "nsIFile.h"
|
2012-06-19 18:50:39 -07:00
|
|
|
#include "nsIFileStorage.h"
|
2012-06-03 09:33:52 -07:00
|
|
|
|
2012-12-02 00:58:57 -08:00
|
|
|
#include "mozilla/Attributes.h"
|
2014-03-31 23:13:50 -07:00
|
|
|
#include "mozilla/DOMEventTargetHelper.h"
|
2013-06-12 00:00:06 -07:00
|
|
|
#include "mozilla/dom/FileModeBinding.h"
|
2012-12-02 00:58:57 -08:00
|
|
|
|
2012-06-03 09:33:52 -07:00
|
|
|
class nsIDOMFile;
|
|
|
|
class nsIFileStorage;
|
2014-01-06 18:53:23 -08:00
|
|
|
class nsPIDOMWindow;
|
2012-06-03 09:33:52 -07:00
|
|
|
|
2013-03-17 01:51:36 -07:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
class DOMRequest;
|
2014-02-24 12:56:13 -08:00
|
|
|
namespace indexedDB {
|
|
|
|
class FileInfo;
|
|
|
|
} // namespace indexedDB
|
2013-03-17 01:51:36 -07:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2012-06-03 09:33:52 -07:00
|
|
|
BEGIN_FILE_NAMESPACE
|
|
|
|
|
|
|
|
class FileService;
|
|
|
|
class LockedFile;
|
|
|
|
class FinishHelper;
|
|
|
|
class FileHelper;
|
|
|
|
|
|
|
|
/**
|
2014-02-24 12:56:13 -08:00
|
|
|
* This class provides a default FileHandle implementation, but it can be also
|
|
|
|
* subclassed. The subclass can override implementation of GetFileId,
|
|
|
|
* GetFileInfo, CreateStream and CreateFileObject.
|
|
|
|
* (for example IDBFileHandle provides IndexedDB specific implementation).
|
2012-06-03 09:33:52 -07:00
|
|
|
*/
|
2014-03-31 23:13:50 -07:00
|
|
|
class FileHandle : public DOMEventTargetHelper
|
2012-06-03 09:33:52 -07:00
|
|
|
{
|
|
|
|
friend class FileService;
|
|
|
|
friend class LockedFile;
|
|
|
|
friend class FinishHelper;
|
|
|
|
friend class FileHelper;
|
|
|
|
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
2014-03-31 23:13:50 -07:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(FileHandle, DOMEventTargetHelper)
|
2012-06-03 09:33:52 -07:00
|
|
|
|
2014-02-24 12:56:13 -08:00
|
|
|
static already_AddRefed<FileHandle>
|
|
|
|
Create(nsPIDOMWindow* aWindow,
|
|
|
|
nsIFileStorage* aFileStorage,
|
|
|
|
nsIFile* aFile);
|
|
|
|
|
2012-06-03 09:33:52 -07:00
|
|
|
const nsAString&
|
|
|
|
Name() const
|
|
|
|
{
|
|
|
|
return mName;
|
|
|
|
}
|
|
|
|
|
|
|
|
const nsAString&
|
|
|
|
Type() const
|
|
|
|
{
|
|
|
|
return mType;
|
|
|
|
}
|
|
|
|
|
2014-02-24 12:56:13 -08:00
|
|
|
virtual int64_t
|
|
|
|
GetFileId()
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual mozilla::dom::indexedDB::FileInfo*
|
|
|
|
GetFileInfo()
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2012-06-03 09:33:52 -07:00
|
|
|
virtual already_AddRefed<nsISupports>
|
2014-02-24 12:56:13 -08:00
|
|
|
CreateStream(nsIFile* aFile, bool aReadOnly);
|
2012-06-03 09:33:52 -07:00
|
|
|
|
|
|
|
virtual already_AddRefed<nsIDOMFile>
|
2014-02-24 12:56:13 -08:00
|
|
|
CreateFileObject(LockedFile* aLockedFile, uint32_t aFileSize);
|
|
|
|
|
|
|
|
// nsWrapperCache
|
|
|
|
virtual JSObject*
|
|
|
|
WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
|
|
|
|
|
|
|
|
// WebIDL
|
|
|
|
nsPIDOMWindow*
|
|
|
|
GetParentObject() const
|
|
|
|
{
|
|
|
|
return GetOwner();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GetName(nsString& aName) const
|
|
|
|
{
|
|
|
|
aName = mName;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GetType(nsString& aType) const
|
|
|
|
{
|
|
|
|
aType = mType;
|
|
|
|
}
|
|
|
|
|
2014-03-24 08:10:27 -07:00
|
|
|
already_AddRefed<LockedFile>
|
2014-02-24 12:56:13 -08:00
|
|
|
Open(FileMode aMode, ErrorResult& aError);
|
|
|
|
|
|
|
|
already_AddRefed<DOMRequest>
|
|
|
|
GetFile(ErrorResult& aError);
|
|
|
|
|
|
|
|
IMPL_EVENT_HANDLER(abort)
|
|
|
|
IMPL_EVENT_HANDLER(error)
|
2012-06-03 09:33:52 -07:00
|
|
|
|
|
|
|
protected:
|
2014-01-06 18:53:23 -08:00
|
|
|
FileHandle(nsPIDOMWindow* aWindow)
|
2014-03-31 23:13:50 -07:00
|
|
|
: DOMEventTargetHelper(aWindow)
|
2014-01-06 18:53:23 -08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-03-31 23:13:50 -07:00
|
|
|
FileHandle(DOMEventTargetHelper* aOwner)
|
|
|
|
: DOMEventTargetHelper(aOwner)
|
2012-12-02 00:58:57 -08:00
|
|
|
{
|
|
|
|
}
|
2012-06-03 09:33:52 -07:00
|
|
|
|
|
|
|
~FileHandle()
|
2014-02-24 12:56:13 -08:00
|
|
|
{
|
|
|
|
}
|
2012-06-03 09:33:52 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIFileStorage> mFileStorage;
|
|
|
|
|
|
|
|
nsString mName;
|
|
|
|
nsString mType;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIFile> mFile;
|
|
|
|
nsString mFileName;
|
|
|
|
};
|
|
|
|
|
|
|
|
END_FILE_NAMESPACE
|
|
|
|
|
|
|
|
#endif // mozilla_dom_file_filehandle_h__
|