michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef FileIOObject_h__ michael@0: #define FileIOObject_h__ michael@0: michael@0: #include "mozilla/DOMEventTargetHelper.h" michael@0: #include "nsIChannel.h" michael@0: #include "nsIFile.h" michael@0: #include "nsIDOMFile.h" michael@0: #include "nsIStreamListener.h" michael@0: #include "nsITimer.h" michael@0: #include "nsCOMPtr.h" michael@0: michael@0: #include "mozilla/dom/DOMError.h" michael@0: michael@0: #define NS_PROGRESS_EVENT_INTERVAL 50 michael@0: michael@0: namespace mozilla { michael@0: michael@0: class ErrorResult; michael@0: michael@0: namespace dom { michael@0: michael@0: extern const uint64_t kUnknownSize; michael@0: michael@0: // A common base class for FileReader and FileSaver michael@0: michael@0: class FileIOObject : public DOMEventTargetHelper, michael@0: public nsIStreamListener, michael@0: public nsITimerCallback michael@0: { michael@0: public: michael@0: FileIOObject(); michael@0: michael@0: NS_DECL_ISUPPORTS_INHERITED michael@0: michael@0: // Common methods michael@0: void Abort(ErrorResult& aRv); michael@0: uint16_t ReadyState() const michael@0: { michael@0: return mReadyState; michael@0: } michael@0: DOMError* GetError() const michael@0: { michael@0: return mError; michael@0: } michael@0: michael@0: NS_METHOD GetOnabort(JSContext* aCx, JS::MutableHandle aValue); michael@0: NS_METHOD SetOnabort(JSContext* aCx, JS::Handle aValue); michael@0: NS_METHOD GetOnerror(JSContext* aCx, JS::MutableHandle aValue); michael@0: NS_METHOD SetOnerror(JSContext* aCx, JS::Handle aValue); michael@0: NS_METHOD GetOnprogress(JSContext* aCx, JS::MutableHandle aValue); michael@0: NS_METHOD SetOnprogress(JSContext* aCx, JS::Handle aValue); michael@0: michael@0: IMPL_EVENT_HANDLER(abort) michael@0: IMPL_EVENT_HANDLER(error) michael@0: IMPL_EVENT_HANDLER(progress) michael@0: michael@0: NS_DECL_NSITIMERCALLBACK michael@0: michael@0: NS_DECL_NSISTREAMLISTENER michael@0: michael@0: NS_DECL_NSIREQUESTOBSERVER michael@0: michael@0: NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(FileIOObject, DOMEventTargetHelper) michael@0: michael@0: protected: michael@0: // Implemented by the derived class to do whatever it needs to do for abort michael@0: virtual void DoAbort(nsAString& aEvent) = 0; michael@0: // for onStartRequest (this has a default impl since FileReader doesn't need michael@0: // special handling michael@0: NS_IMETHOD DoOnStartRequest(nsIRequest *aRequest, nsISupports *aContext); michael@0: // for onStopRequest michael@0: NS_IMETHOD DoOnStopRequest(nsIRequest *aRequest, nsISupports *aContext, michael@0: nsresult aStatus, nsAString& aSuccessEvent, michael@0: nsAString& aTerminationEvent) = 0; michael@0: // and for onDataAvailable michael@0: NS_IMETHOD DoOnDataAvailable(nsIRequest *aRequest, nsISupports *aContext, michael@0: nsIInputStream *aInputStream, uint64_t aOffset, michael@0: uint32_t aCount) = 0; michael@0: michael@0: void StartProgressEventTimer(); michael@0: void ClearProgressEventTimer(); michael@0: void DispatchError(nsresult rv, nsAString& finalEvent); michael@0: nsresult DispatchProgressEvent(const nsAString& aType); michael@0: michael@0: nsCOMPtr mProgressNotifier; michael@0: bool mProgressEventWasDelayed; michael@0: bool mTimerIsActive; michael@0: michael@0: nsRefPtr mError; michael@0: nsCOMPtr mChannel; michael@0: michael@0: uint16_t mReadyState; michael@0: michael@0: uint64_t mTotal; michael@0: uint64_t mTransferred; michael@0: }; michael@0: michael@0: } // namespace dom michael@0: } // namespace mozilla michael@0: michael@0: #endif