|
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/. */ |
|
6 |
|
7 #ifndef mozilla_dom_file_domarchivereader_h__ |
|
8 #define mozilla_dom_file_domarchivereader_h__ |
|
9 |
|
10 #include "nsWrapperCache.h" |
|
11 |
|
12 #include "FileCommon.h" |
|
13 |
|
14 #include "nsCOMArray.h" |
|
15 #include "nsIChannel.h" |
|
16 #include "nsIDOMFile.h" |
|
17 #include "mozilla/Attributes.h" |
|
18 |
|
19 namespace mozilla { |
|
20 namespace dom { |
|
21 class ArchiveReaderOptions; |
|
22 class GlobalObject; |
|
23 } // namespace dom |
|
24 } // namespace mozilla |
|
25 |
|
26 BEGIN_FILE_NAMESPACE |
|
27 |
|
28 class ArchiveRequest; |
|
29 |
|
30 /** |
|
31 * This is the ArchiveReader object |
|
32 */ |
|
33 class ArchiveReader MOZ_FINAL : public nsISupports, |
|
34 public nsWrapperCache |
|
35 { |
|
36 public: |
|
37 NS_DECL_CYCLE_COLLECTING_ISUPPORTS |
|
38 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(ArchiveReader) |
|
39 |
|
40 static already_AddRefed<ArchiveReader> |
|
41 Constructor(const GlobalObject& aGlobal, nsIDOMBlob* aBlob, |
|
42 const ArchiveReaderOptions& aOptions, ErrorResult& aError); |
|
43 |
|
44 ArchiveReader(nsIDOMBlob* aBlob, nsPIDOMWindow* aWindow, |
|
45 const nsACString& aEncoding); |
|
46 |
|
47 nsIDOMWindow* GetParentObject() const |
|
48 { |
|
49 return mWindow; |
|
50 } |
|
51 virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE; |
|
52 |
|
53 already_AddRefed<ArchiveRequest> GetFilenames(); |
|
54 already_AddRefed<ArchiveRequest> GetFile(const nsAString& filename); |
|
55 already_AddRefed<ArchiveRequest> GetFiles(); |
|
56 |
|
57 nsresult GetInputStream(nsIInputStream** aInputStream); |
|
58 nsresult GetSize(uint64_t* aSize); |
|
59 |
|
60 public: // for the ArchiveRequest: |
|
61 nsresult RegisterRequest(ArchiveRequest* aRequest); |
|
62 |
|
63 public: // For events: |
|
64 void Ready(nsTArray<nsCOMPtr<nsIDOMFile> >& aFileList, |
|
65 nsresult aStatus); |
|
66 |
|
67 private: |
|
68 ~ArchiveReader(); |
|
69 |
|
70 already_AddRefed<ArchiveRequest> GenerateArchiveRequest(); |
|
71 |
|
72 nsresult OpenArchive(); |
|
73 |
|
74 void RequestReady(ArchiveRequest* aRequest); |
|
75 |
|
76 protected: |
|
77 // The archive blob/file |
|
78 nsCOMPtr<nsIDOMBlob> mBlob; |
|
79 |
|
80 // The window is needed by the requests |
|
81 nsCOMPtr<nsPIDOMWindow> mWindow; |
|
82 |
|
83 // Are we ready to return data? |
|
84 enum { |
|
85 NOT_STARTED = 0, |
|
86 WORKING, |
|
87 READY |
|
88 } mStatus; |
|
89 |
|
90 // State of the read: |
|
91 enum { |
|
92 Header, // We are collecting the header: 30bytes |
|
93 Name, // The name length is contained in the header |
|
94 Data, // The length of the data segment COULD be written in the header |
|
95 Search // ... if the data length is unknown (== 0) we wait until we read a new header |
|
96 } mReadStatus; |
|
97 |
|
98 // List of requests to be processed |
|
99 nsTArray<nsRefPtr<ArchiveRequest> > mRequests; |
|
100 |
|
101 // Everything related to the blobs and the status: |
|
102 struct { |
|
103 nsTArray<nsCOMPtr<nsIDOMFile> > fileList; |
|
104 nsresult status; |
|
105 } mData; |
|
106 |
|
107 nsCString mEncoding; |
|
108 }; |
|
109 |
|
110 END_FILE_NAMESPACE |
|
111 |
|
112 #endif // mozilla_dom_file_domarchivereader_h__ |