2011-09-29 09:06:35 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07: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/. */
|
2011-09-29 09:06:35 -07:00
|
|
|
|
|
|
|
#ifndef FileIOObject_h__
|
|
|
|
#define FileIOObject_h__
|
|
|
|
|
2014-03-31 23:13:50 -07:00
|
|
|
#include "mozilla/DOMEventTargetHelper.h"
|
2011-09-29 09:06:35 -07:00
|
|
|
#include "nsIFile.h"
|
|
|
|
#include "nsIDOMFile.h"
|
|
|
|
#include "nsITimer.h"
|
|
|
|
#include "nsCOMPtr.h"
|
2014-06-10 11:48:36 -07:00
|
|
|
#include "nsIAsyncInputStream.h"
|
2011-09-29 09:06:35 -07:00
|
|
|
|
2012-03-11 00:47:38 -08:00
|
|
|
#include "mozilla/dom/DOMError.h"
|
|
|
|
|
2011-09-29 09:06:35 -07:00
|
|
|
#define NS_PROGRESS_EVENT_INTERVAL 50
|
|
|
|
|
|
|
|
namespace mozilla {
|
2013-04-13 00:06:31 -07:00
|
|
|
|
|
|
|
class ErrorResult;
|
|
|
|
|
2011-09-29 09:06:35 -07:00
|
|
|
namespace dom {
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
extern const uint64_t kUnknownSize;
|
2011-09-29 09:06:35 -07:00
|
|
|
|
|
|
|
// A common base class for FileReader and FileSaver
|
|
|
|
|
2014-03-31 23:13:50 -07:00
|
|
|
class FileIOObject : public DOMEventTargetHelper,
|
2014-06-10 11:48:36 -07:00
|
|
|
public nsIInputStreamCallback,
|
2011-09-29 09:06:35 -07:00
|
|
|
public nsITimerCallback
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
FileIOObject();
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
|
|
|
|
// Common methods
|
2013-04-13 00:06:31 -07:00
|
|
|
void Abort(ErrorResult& aRv);
|
|
|
|
uint16_t ReadyState() const
|
|
|
|
{
|
|
|
|
return mReadyState;
|
|
|
|
}
|
2013-05-18 10:52:06 -07:00
|
|
|
DOMError* GetError() const
|
2013-04-13 00:06:31 -07:00
|
|
|
{
|
|
|
|
return mError;
|
|
|
|
}
|
2011-09-29 09:06:35 -07:00
|
|
|
|
2014-01-09 09:39:36 -08:00
|
|
|
NS_METHOD GetOnabort(JSContext* aCx, JS::MutableHandle<JS::Value> aValue);
|
|
|
|
NS_METHOD SetOnabort(JSContext* aCx, JS::Handle<JS::Value> aValue);
|
|
|
|
NS_METHOD GetOnerror(JSContext* aCx, JS::MutableHandle<JS::Value> aValue);
|
|
|
|
NS_METHOD SetOnerror(JSContext* aCx, JS::Handle<JS::Value> aValue);
|
|
|
|
NS_METHOD GetOnprogress(JSContext* aCx, JS::MutableHandle<JS::Value> aValue);
|
|
|
|
NS_METHOD SetOnprogress(JSContext* aCx, JS::Handle<JS::Value> aValue);
|
2011-09-29 09:06:35 -07:00
|
|
|
|
2013-04-13 00:06:31 -07:00
|
|
|
IMPL_EVENT_HANDLER(abort)
|
|
|
|
IMPL_EVENT_HANDLER(error)
|
|
|
|
IMPL_EVENT_HANDLER(progress)
|
|
|
|
|
2011-09-29 09:06:35 -07:00
|
|
|
NS_DECL_NSITIMERCALLBACK
|
|
|
|
|
2014-06-10 11:48:36 -07:00
|
|
|
NS_DECL_NSIINPUTSTREAMCALLBACK
|
2011-09-29 09:06:35 -07:00
|
|
|
|
2014-03-31 23:13:50 -07:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(FileIOObject, DOMEventTargetHelper)
|
2011-09-29 09:06:35 -07:00
|
|
|
|
|
|
|
protected:
|
2014-07-08 14:23:16 -07:00
|
|
|
virtual ~FileIOObject();
|
|
|
|
|
2011-09-29 09:06:35 -07:00
|
|
|
// Implemented by the derived class to do whatever it needs to do for abort
|
2013-04-13 00:06:31 -07:00
|
|
|
virtual void DoAbort(nsAString& aEvent) = 0;
|
2014-06-10 11:48:36 -07:00
|
|
|
|
|
|
|
virtual nsresult DoReadData(nsIAsyncInputStream* aStream, uint64_t aCount) = 0;
|
|
|
|
|
|
|
|
virtual nsresult DoOnLoadEnd(nsresult aStatus, nsAString& aSuccessEvent,
|
|
|
|
nsAString& aTerminationEvent) = 0;
|
|
|
|
|
|
|
|
nsresult OnLoadEnd(nsresult aStatus);
|
|
|
|
nsresult DoAsyncWait(nsIAsyncInputStream* aStream);
|
2011-09-29 09:06:35 -07:00
|
|
|
|
|
|
|
void StartProgressEventTimer();
|
|
|
|
void ClearProgressEventTimer();
|
|
|
|
void DispatchError(nsresult rv, nsAString& finalEvent);
|
|
|
|
nsresult DispatchProgressEvent(const nsAString& aType);
|
|
|
|
|
|
|
|
nsCOMPtr<nsITimer> mProgressNotifier;
|
|
|
|
bool mProgressEventWasDelayed;
|
|
|
|
bool mTimerIsActive;
|
|
|
|
|
2014-06-10 11:48:36 -07:00
|
|
|
nsCOMPtr<nsIAsyncInputStream> mAsyncStream;
|
|
|
|
|
2013-05-18 10:52:06 -07:00
|
|
|
nsRefPtr<DOMError> mError;
|
2011-09-29 09:06:35 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint16_t mReadyState;
|
2011-09-29 09:06:35 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint64_t mTotal;
|
|
|
|
uint64_t mTransferred;
|
2011-09-29 09:06:35 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif
|