content/base/src/FileIOObject.h

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #ifndef FileIOObject_h__
michael@0 7 #define FileIOObject_h__
michael@0 8
michael@0 9 #include "mozilla/DOMEventTargetHelper.h"
michael@0 10 #include "nsIChannel.h"
michael@0 11 #include "nsIFile.h"
michael@0 12 #include "nsIDOMFile.h"
michael@0 13 #include "nsIStreamListener.h"
michael@0 14 #include "nsITimer.h"
michael@0 15 #include "nsCOMPtr.h"
michael@0 16
michael@0 17 #include "mozilla/dom/DOMError.h"
michael@0 18
michael@0 19 #define NS_PROGRESS_EVENT_INTERVAL 50
michael@0 20
michael@0 21 namespace mozilla {
michael@0 22
michael@0 23 class ErrorResult;
michael@0 24
michael@0 25 namespace dom {
michael@0 26
michael@0 27 extern const uint64_t kUnknownSize;
michael@0 28
michael@0 29 // A common base class for FileReader and FileSaver
michael@0 30
michael@0 31 class FileIOObject : public DOMEventTargetHelper,
michael@0 32 public nsIStreamListener,
michael@0 33 public nsITimerCallback
michael@0 34 {
michael@0 35 public:
michael@0 36 FileIOObject();
michael@0 37
michael@0 38 NS_DECL_ISUPPORTS_INHERITED
michael@0 39
michael@0 40 // Common methods
michael@0 41 void Abort(ErrorResult& aRv);
michael@0 42 uint16_t ReadyState() const
michael@0 43 {
michael@0 44 return mReadyState;
michael@0 45 }
michael@0 46 DOMError* GetError() const
michael@0 47 {
michael@0 48 return mError;
michael@0 49 }
michael@0 50
michael@0 51 NS_METHOD GetOnabort(JSContext* aCx, JS::MutableHandle<JS::Value> aValue);
michael@0 52 NS_METHOD SetOnabort(JSContext* aCx, JS::Handle<JS::Value> aValue);
michael@0 53 NS_METHOD GetOnerror(JSContext* aCx, JS::MutableHandle<JS::Value> aValue);
michael@0 54 NS_METHOD SetOnerror(JSContext* aCx, JS::Handle<JS::Value> aValue);
michael@0 55 NS_METHOD GetOnprogress(JSContext* aCx, JS::MutableHandle<JS::Value> aValue);
michael@0 56 NS_METHOD SetOnprogress(JSContext* aCx, JS::Handle<JS::Value> aValue);
michael@0 57
michael@0 58 IMPL_EVENT_HANDLER(abort)
michael@0 59 IMPL_EVENT_HANDLER(error)
michael@0 60 IMPL_EVENT_HANDLER(progress)
michael@0 61
michael@0 62 NS_DECL_NSITIMERCALLBACK
michael@0 63
michael@0 64 NS_DECL_NSISTREAMLISTENER
michael@0 65
michael@0 66 NS_DECL_NSIREQUESTOBSERVER
michael@0 67
michael@0 68 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(FileIOObject, DOMEventTargetHelper)
michael@0 69
michael@0 70 protected:
michael@0 71 // Implemented by the derived class to do whatever it needs to do for abort
michael@0 72 virtual void DoAbort(nsAString& aEvent) = 0;
michael@0 73 // for onStartRequest (this has a default impl since FileReader doesn't need
michael@0 74 // special handling
michael@0 75 NS_IMETHOD DoOnStartRequest(nsIRequest *aRequest, nsISupports *aContext);
michael@0 76 // for onStopRequest
michael@0 77 NS_IMETHOD DoOnStopRequest(nsIRequest *aRequest, nsISupports *aContext,
michael@0 78 nsresult aStatus, nsAString& aSuccessEvent,
michael@0 79 nsAString& aTerminationEvent) = 0;
michael@0 80 // and for onDataAvailable
michael@0 81 NS_IMETHOD DoOnDataAvailable(nsIRequest *aRequest, nsISupports *aContext,
michael@0 82 nsIInputStream *aInputStream, uint64_t aOffset,
michael@0 83 uint32_t aCount) = 0;
michael@0 84
michael@0 85 void StartProgressEventTimer();
michael@0 86 void ClearProgressEventTimer();
michael@0 87 void DispatchError(nsresult rv, nsAString& finalEvent);
michael@0 88 nsresult DispatchProgressEvent(const nsAString& aType);
michael@0 89
michael@0 90 nsCOMPtr<nsITimer> mProgressNotifier;
michael@0 91 bool mProgressEventWasDelayed;
michael@0 92 bool mTimerIsActive;
michael@0 93
michael@0 94 nsRefPtr<DOMError> mError;
michael@0 95 nsCOMPtr<nsIChannel> mChannel;
michael@0 96
michael@0 97 uint16_t mReadyState;
michael@0 98
michael@0 99 uint64_t mTotal;
michael@0 100 uint64_t mTransferred;
michael@0 101 };
michael@0 102
michael@0 103 } // namespace dom
michael@0 104 } // namespace mozilla
michael@0 105
michael@0 106 #endif

mercurial