content/base/src/FileIOObject.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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

mercurial