michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set ts=2 et sw=2 tw=80: */ 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 file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef mozilla_dom_file_domarchivereader_h__ michael@0: #define mozilla_dom_file_domarchivereader_h__ michael@0: michael@0: #include "nsWrapperCache.h" michael@0: michael@0: #include "FileCommon.h" michael@0: michael@0: #include "nsCOMArray.h" michael@0: #include "nsIChannel.h" michael@0: #include "nsIDOMFile.h" michael@0: #include "mozilla/Attributes.h" michael@0: michael@0: namespace mozilla { michael@0: namespace dom { michael@0: class ArchiveReaderOptions; michael@0: class GlobalObject; michael@0: } // namespace dom michael@0: } // namespace mozilla michael@0: michael@0: BEGIN_FILE_NAMESPACE michael@0: michael@0: class ArchiveRequest; michael@0: michael@0: /** michael@0: * This is the ArchiveReader object michael@0: */ michael@0: class ArchiveReader MOZ_FINAL : public nsISupports, michael@0: public nsWrapperCache michael@0: { michael@0: public: michael@0: NS_DECL_CYCLE_COLLECTING_ISUPPORTS michael@0: NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(ArchiveReader) michael@0: michael@0: static already_AddRefed michael@0: Constructor(const GlobalObject& aGlobal, nsIDOMBlob* aBlob, michael@0: const ArchiveReaderOptions& aOptions, ErrorResult& aError); michael@0: michael@0: ArchiveReader(nsIDOMBlob* aBlob, nsPIDOMWindow* aWindow, michael@0: const nsACString& aEncoding); michael@0: michael@0: nsIDOMWindow* GetParentObject() const michael@0: { michael@0: return mWindow; michael@0: } michael@0: virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE; michael@0: michael@0: already_AddRefed GetFilenames(); michael@0: already_AddRefed GetFile(const nsAString& filename); michael@0: already_AddRefed GetFiles(); michael@0: michael@0: nsresult GetInputStream(nsIInputStream** aInputStream); michael@0: nsresult GetSize(uint64_t* aSize); michael@0: michael@0: public: // for the ArchiveRequest: michael@0: nsresult RegisterRequest(ArchiveRequest* aRequest); michael@0: michael@0: public: // For events: michael@0: void Ready(nsTArray >& aFileList, michael@0: nsresult aStatus); michael@0: michael@0: private: michael@0: ~ArchiveReader(); michael@0: michael@0: already_AddRefed GenerateArchiveRequest(); michael@0: michael@0: nsresult OpenArchive(); michael@0: michael@0: void RequestReady(ArchiveRequest* aRequest); michael@0: michael@0: protected: michael@0: // The archive blob/file michael@0: nsCOMPtr mBlob; michael@0: michael@0: // The window is needed by the requests michael@0: nsCOMPtr mWindow; michael@0: michael@0: // Are we ready to return data? michael@0: enum { michael@0: NOT_STARTED = 0, michael@0: WORKING, michael@0: READY michael@0: } mStatus; michael@0: michael@0: // State of the read: michael@0: enum { michael@0: Header, // We are collecting the header: 30bytes michael@0: Name, // The name length is contained in the header michael@0: Data, // The length of the data segment COULD be written in the header michael@0: Search // ... if the data length is unknown (== 0) we wait until we read a new header michael@0: } mReadStatus; michael@0: michael@0: // List of requests to be processed michael@0: nsTArray > mRequests; michael@0: michael@0: // Everything related to the blobs and the status: michael@0: struct { michael@0: nsTArray > fileList; michael@0: nsresult status; michael@0: } mData; michael@0: michael@0: nsCString mEncoding; michael@0: }; michael@0: michael@0: END_FILE_NAMESPACE michael@0: michael@0: #endif // mozilla_dom_file_domarchivereader_h__