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