|
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_domarchiverequest_h__ |
|
8 #define mozilla_dom_file_domarchiverequest_h__ |
|
9 |
|
10 #include "mozilla/Attributes.h" |
|
11 #include "ArchiveReader.h" |
|
12 #include "DOMRequest.h" |
|
13 |
|
14 #include "FileCommon.h" |
|
15 |
|
16 namespace mozilla { |
|
17 class EventChainPreVisitor; |
|
18 } // namespace mozilla |
|
19 |
|
20 BEGIN_FILE_NAMESPACE |
|
21 |
|
22 /** |
|
23 * This is the ArchiveRequest that handles any operation |
|
24 * related to ArchiveReader |
|
25 */ |
|
26 class ArchiveRequest : public mozilla::dom::DOMRequest |
|
27 { |
|
28 public: |
|
29 virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE; |
|
30 |
|
31 ArchiveReader* Reader() const; |
|
32 |
|
33 NS_DECL_ISUPPORTS_INHERITED |
|
34 |
|
35 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ArchiveRequest, DOMRequest) |
|
36 |
|
37 ArchiveRequest(nsPIDOMWindow* aWindow, |
|
38 ArchiveReader* aReader); |
|
39 |
|
40 // nsIDOMEventTarget |
|
41 virtual nsresult PreHandleEvent(EventChainPreVisitor& aVisitor) MOZ_OVERRIDE; |
|
42 |
|
43 public: |
|
44 // This is called by the DOMArchiveRequestEvent |
|
45 void Run(); |
|
46 |
|
47 // Set the types for this request |
|
48 void OpGetFilenames(); |
|
49 void OpGetFile(const nsAString& aFilename); |
|
50 void OpGetFiles(); |
|
51 |
|
52 nsresult ReaderReady(nsTArray<nsCOMPtr<nsIDOMFile> >& aFileList, |
|
53 nsresult aStatus); |
|
54 |
|
55 public: // static |
|
56 static already_AddRefed<ArchiveRequest> Create(nsPIDOMWindow* aOwner, |
|
57 ArchiveReader* aReader); |
|
58 |
|
59 private: |
|
60 ~ArchiveRequest(); |
|
61 |
|
62 nsresult GetFilenamesResult(JSContext* aCx, |
|
63 JS::Value* aValue, |
|
64 nsTArray<nsCOMPtr<nsIDOMFile> >& aFileList); |
|
65 nsresult GetFileResult(JSContext* aCx, |
|
66 JS::MutableHandle<JS::Value> aValue, |
|
67 nsTArray<nsCOMPtr<nsIDOMFile> >& aFileList); |
|
68 nsresult GetFilesResult(JSContext* aCx, |
|
69 JS::MutableHandle<JS::Value> aValue, |
|
70 nsTArray<nsCOMPtr<nsIDOMFile> >& aFileList); |
|
71 |
|
72 protected: |
|
73 // The reader: |
|
74 nsRefPtr<ArchiveReader> mArchiveReader; |
|
75 |
|
76 // The operation: |
|
77 enum { |
|
78 GetFilenames, |
|
79 GetFile, |
|
80 GetFiles |
|
81 } mOperation; |
|
82 |
|
83 // The filename (needed by GetFile): |
|
84 nsString mFilename; |
|
85 }; |
|
86 |
|
87 END_FILE_NAMESPACE |
|
88 |
|
89 #endif // mozilla_dom_file_domarchiverequest_h__ |