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/. */
|
2011-09-29 20:06:35 +04:00
|
|
|
|
|
|
|
#ifndef FileIOObject_h__
|
|
|
|
#define FileIOObject_h__
|
|
|
|
|
2014-04-01 10:13:50 +04:00
|
|
|
#include "mozilla/DOMEventTargetHelper.h"
|
2011-09-29 20:06:35 +04:00
|
|
|
#include "nsIFile.h"
|
|
|
|
#include "nsITimer.h"
|
|
|
|
#include "nsCOMPtr.h"
|
2014-06-10 22:48:36 +04:00
|
|
|
#include "nsIAsyncInputStream.h"
|
2011-09-29 20:06:35 +04:00
|
|
|
|
2012-03-11 12:47:38 +04:00
|
|
|
#include "mozilla/dom/DOMError.h"
|
|
|
|
|
2011-09-29 20:06:35 +04:00
|
|
|
#define NS_PROGRESS_EVENT_INTERVAL 50
|
|
|
|
|
|
|
|
namespace mozilla {
|
2013-04-13 11:06:31 +04:00
|
|
|
|
|
|
|
class ErrorResult;
|
|
|
|
|
2011-09-29 20:06:35 +04:00
|
|
|
namespace dom {
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
extern const uint64_t kUnknownSize;
|
2011-09-29 20:06:35 +04:00
|
|
|
|
|
|
|
// A common base class for FileReader and FileSaver
|
|
|
|
|
2014-04-01 10:13:50 +04:00
|
|
|
class FileIOObject : public DOMEventTargetHelper,
|
2014-06-10 22:48:36 +04:00
|
|
|
public nsIInputStreamCallback,
|
2011-09-29 20:06:35 +04:00
|
|
|
public nsITimerCallback
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
FileIOObject();
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
|
|
|
|
// Common methods
|
2013-04-13 11:06:31 +04:00
|
|
|
void Abort(ErrorResult& aRv);
|
|
|
|
uint16_t ReadyState() const
|
|
|
|
{
|
|
|
|
return mReadyState;
|
|
|
|
}
|
2013-05-18 21:52:06 +04:00
|
|
|
DOMError* GetError() const
|
2013-04-13 11:06:31 +04:00
|
|
|
{
|
|
|
|
return mError;
|
|
|
|
}
|
2011-09-29 20:06:35 +04:00
|
|
|
|
2014-01-09 21:39:36 +04: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 20:06:35 +04:00
|
|
|
|
2013-04-13 11:06:31 +04:00
|
|
|
IMPL_EVENT_HANDLER(abort)
|
|
|
|
IMPL_EVENT_HANDLER(error)
|
|
|
|
IMPL_EVENT_HANDLER(progress)
|
|
|
|
|
2011-09-29 20:06:35 +04:00
|
|
|
NS_DECL_NSITIMERCALLBACK
|
|
|
|
|
2014-06-10 22:48:36 +04:00
|
|
|
NS_DECL_NSIINPUTSTREAMCALLBACK
|
2011-09-29 20:06:35 +04:00
|
|
|
|
2014-04-01 10:13:50 +04:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(FileIOObject, DOMEventTargetHelper)
|
2011-09-29 20:06:35 +04:00
|
|
|
|
|
|
|
protected:
|
2014-07-09 01:23:16 +04:00
|
|
|
virtual ~FileIOObject();
|
|
|
|
|
2011-09-29 20:06:35 +04:00
|
|
|
// Implemented by the derived class to do whatever it needs to do for abort
|
2013-04-13 11:06:31 +04:00
|
|
|
virtual void DoAbort(nsAString& aEvent) = 0;
|
2014-06-10 22:48:36 +04: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 20:06:35 +04: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 22:48:36 +04:00
|
|
|
nsCOMPtr<nsIAsyncInputStream> mAsyncStream;
|
|
|
|
|
2013-05-18 21:52:06 +04:00
|
|
|
nsRefPtr<DOMError> mError;
|
2011-09-29 20:06:35 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint16_t mReadyState;
|
2011-09-29 20:06:35 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint64_t mTotal;
|
|
|
|
uint64_t mTransferred;
|
2011-09-29 20:06:35 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif
|