dom/file/ArchiveReader.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/file/ArchiveReader.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,112 @@
     1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* vim: set ts=2 et sw=2 tw=80: */
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this file,
     1.8 + * You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#ifndef mozilla_dom_file_domarchivereader_h__
    1.11 +#define mozilla_dom_file_domarchivereader_h__
    1.12 +
    1.13 +#include "nsWrapperCache.h"
    1.14 +
    1.15 +#include "FileCommon.h"
    1.16 +
    1.17 +#include "nsCOMArray.h"
    1.18 +#include "nsIChannel.h"
    1.19 +#include "nsIDOMFile.h"
    1.20 +#include "mozilla/Attributes.h"
    1.21 +
    1.22 +namespace mozilla {
    1.23 +namespace dom {
    1.24 +class ArchiveReaderOptions;
    1.25 +class GlobalObject;
    1.26 +} // namespace dom
    1.27 +} // namespace mozilla
    1.28 +
    1.29 +BEGIN_FILE_NAMESPACE
    1.30 +
    1.31 +class ArchiveRequest;
    1.32 +
    1.33 +/**
    1.34 + * This is the ArchiveReader object
    1.35 + */
    1.36 +class ArchiveReader MOZ_FINAL : public nsISupports,
    1.37 +                                public nsWrapperCache
    1.38 +{
    1.39 +public:
    1.40 +  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
    1.41 +  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(ArchiveReader)
    1.42 +
    1.43 +  static already_AddRefed<ArchiveReader>
    1.44 +  Constructor(const GlobalObject& aGlobal, nsIDOMBlob* aBlob,
    1.45 +              const ArchiveReaderOptions& aOptions, ErrorResult& aError);
    1.46 +
    1.47 +  ArchiveReader(nsIDOMBlob* aBlob, nsPIDOMWindow* aWindow,
    1.48 +                const nsACString& aEncoding);
    1.49 +
    1.50 +  nsIDOMWindow* GetParentObject() const
    1.51 +  {
    1.52 +    return mWindow;
    1.53 +  }
    1.54 +  virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
    1.55 +
    1.56 +  already_AddRefed<ArchiveRequest> GetFilenames();
    1.57 +  already_AddRefed<ArchiveRequest> GetFile(const nsAString& filename);
    1.58 +  already_AddRefed<ArchiveRequest> GetFiles();
    1.59 +
    1.60 +  nsresult GetInputStream(nsIInputStream** aInputStream);
    1.61 +  nsresult GetSize(uint64_t* aSize);
    1.62 +
    1.63 +public: // for the ArchiveRequest:
    1.64 +  nsresult RegisterRequest(ArchiveRequest* aRequest);
    1.65 +
    1.66 +public: // For events:
    1.67 +  void Ready(nsTArray<nsCOMPtr<nsIDOMFile> >& aFileList,
    1.68 +             nsresult aStatus);
    1.69 +
    1.70 +private:
    1.71 +  ~ArchiveReader();
    1.72 +
    1.73 +  already_AddRefed<ArchiveRequest> GenerateArchiveRequest();
    1.74 +
    1.75 +  nsresult OpenArchive();
    1.76 +
    1.77 +  void RequestReady(ArchiveRequest* aRequest);
    1.78 +
    1.79 +protected:
    1.80 +  // The archive blob/file
    1.81 +  nsCOMPtr<nsIDOMBlob> mBlob;
    1.82 +
    1.83 +  // The window is needed by the requests
    1.84 +  nsCOMPtr<nsPIDOMWindow> mWindow;
    1.85 +
    1.86 +  // Are we ready to return data?
    1.87 +  enum {
    1.88 +    NOT_STARTED = 0,
    1.89 +    WORKING,
    1.90 +    READY
    1.91 +  } mStatus;
    1.92 +
    1.93 +  // State of the read:
    1.94 +  enum {
    1.95 +    Header, // We are collecting the header: 30bytes
    1.96 +    Name,   // The name length is contained in the header
    1.97 +    Data,   // The length of the data segment COULD be written in the header
    1.98 +    Search  // ... if the data length is unknown (== 0) we wait until we read a new header 
    1.99 +  } mReadStatus;
   1.100 +
   1.101 +  // List of requests to be processed
   1.102 +  nsTArray<nsRefPtr<ArchiveRequest> > mRequests;
   1.103 +
   1.104 +  // Everything related to the blobs and the status:
   1.105 +  struct {
   1.106 +    nsTArray<nsCOMPtr<nsIDOMFile> > fileList;
   1.107 +    nsresult status;
   1.108 +  } mData;
   1.109 +
   1.110 +  nsCString mEncoding;
   1.111 +};
   1.112 +
   1.113 +END_FILE_NAMESPACE
   1.114 +
   1.115 +#endif // mozilla_dom_file_domarchivereader_h__

mercurial