Bumping manifests a=b2g-bump
[gecko.git] / dom / archivereader / ArchiveReader.h
blob2187a54a0a4f912c46c787f24c2824ed0ad84510
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_archivereader_domarchivereader_h__
8 #define mozilla_dom_archivereader_domarchivereader_h__
10 #include "nsWrapperCache.h"
12 #include "ArchiveReaderCommon.h"
14 #include "nsCOMArray.h"
15 #include "nsIChannel.h"
16 #include "nsIDOMFile.h"
17 #include "mozilla/Attributes.h"
19 namespace mozilla {
20 namespace dom {
21 struct ArchiveReaderOptions;
22 class File;
23 class FileImpl;
24 class GlobalObject;
25 } // namespace dom
26 } // namespace mozilla
28 BEGIN_ARCHIVEREADER_NAMESPACE
30 class ArchiveRequest;
32 /**
33 * This is the ArchiveReader object
35 class ArchiveReader MOZ_FINAL : public nsISupports,
36 public nsWrapperCache
38 public:
39 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
40 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(ArchiveReader)
42 static already_AddRefed<ArchiveReader>
43 Constructor(const GlobalObject& aGlobal, File& aBlob,
44 const ArchiveReaderOptions& aOptions, ErrorResult& aError);
46 ArchiveReader(File& aBlob, nsPIDOMWindow* aWindow,
47 const nsACString& aEncoding);
49 nsIDOMWindow* GetParentObject() const
51 return mWindow;
54 virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
56 already_AddRefed<ArchiveRequest> GetFilenames();
57 already_AddRefed<ArchiveRequest> GetFile(const nsAString& filename);
58 already_AddRefed<ArchiveRequest> GetFiles();
60 nsresult GetInputStream(nsIInputStream** aInputStream);
61 nsresult GetSize(uint64_t* aSize);
63 public: // for the ArchiveRequest:
64 nsresult RegisterRequest(ArchiveRequest* aRequest);
66 public: // For events:
67 FileImpl* GetFileImpl() const
69 return mFileImpl;
72 void Ready(nsTArray<nsCOMPtr<nsIDOMFile> >& aFileList,
73 nsresult aStatus);
75 private:
76 ~ArchiveReader();
78 already_AddRefed<ArchiveRequest> GenerateArchiveRequest();
80 nsresult OpenArchive();
82 void RequestReady(ArchiveRequest* aRequest);
84 protected:
85 // The archive blob/file
86 nsRefPtr<FileImpl> mFileImpl;
88 // The window is needed by the requests
89 nsCOMPtr<nsPIDOMWindow> mWindow;
91 // Are we ready to return data?
92 enum {
93 NOT_STARTED = 0,
94 WORKING,
95 READY
96 } mStatus;
98 // State of the read:
99 enum {
100 Header, // We are collecting the header: 30bytes
101 Name, // The name length is contained in the header
102 Data, // The length of the data segment COULD be written in the header
103 Search // ... if the data length is unknown (== 0) we wait until we read a new header
104 } mReadStatus;
106 // List of requests to be processed
107 nsTArray<nsRefPtr<ArchiveRequest> > mRequests;
109 // Everything related to the blobs and the status:
110 struct {
111 nsTArray<nsCOMPtr<nsIDOMFile> > fileList;
112 nsresult status;
113 } mData;
115 nsCString mEncoding;
118 END_ARCHIVEREADER_NAMESPACE
120 #endif // mozilla_dom_archivereader_domarchivereader_h__