Thu, 15 Jan 2015 15:59:08 +0100
Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* vim: set ts=2 et sw=2 tw=80: */ |
michael@0 | 3 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
michael@0 | 5 | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | #ifndef mozilla_dom_file_domarchivereader_h__ |
michael@0 | 8 | #define mozilla_dom_file_domarchivereader_h__ |
michael@0 | 9 | |
michael@0 | 10 | #include "nsWrapperCache.h" |
michael@0 | 11 | |
michael@0 | 12 | #include "FileCommon.h" |
michael@0 | 13 | |
michael@0 | 14 | #include "nsCOMArray.h" |
michael@0 | 15 | #include "nsIChannel.h" |
michael@0 | 16 | #include "nsIDOMFile.h" |
michael@0 | 17 | #include "mozilla/Attributes.h" |
michael@0 | 18 | |
michael@0 | 19 | namespace mozilla { |
michael@0 | 20 | namespace dom { |
michael@0 | 21 | class ArchiveReaderOptions; |
michael@0 | 22 | class GlobalObject; |
michael@0 | 23 | } // namespace dom |
michael@0 | 24 | } // namespace mozilla |
michael@0 | 25 | |
michael@0 | 26 | BEGIN_FILE_NAMESPACE |
michael@0 | 27 | |
michael@0 | 28 | class ArchiveRequest; |
michael@0 | 29 | |
michael@0 | 30 | /** |
michael@0 | 31 | * This is the ArchiveReader object |
michael@0 | 32 | */ |
michael@0 | 33 | class ArchiveReader MOZ_FINAL : public nsISupports, |
michael@0 | 34 | public nsWrapperCache |
michael@0 | 35 | { |
michael@0 | 36 | public: |
michael@0 | 37 | NS_DECL_CYCLE_COLLECTING_ISUPPORTS |
michael@0 | 38 | NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(ArchiveReader) |
michael@0 | 39 | |
michael@0 | 40 | static already_AddRefed<ArchiveReader> |
michael@0 | 41 | Constructor(const GlobalObject& aGlobal, nsIDOMBlob* aBlob, |
michael@0 | 42 | const ArchiveReaderOptions& aOptions, ErrorResult& aError); |
michael@0 | 43 | |
michael@0 | 44 | ArchiveReader(nsIDOMBlob* aBlob, nsPIDOMWindow* aWindow, |
michael@0 | 45 | const nsACString& aEncoding); |
michael@0 | 46 | |
michael@0 | 47 | nsIDOMWindow* GetParentObject() const |
michael@0 | 48 | { |
michael@0 | 49 | return mWindow; |
michael@0 | 50 | } |
michael@0 | 51 | virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE; |
michael@0 | 52 | |
michael@0 | 53 | already_AddRefed<ArchiveRequest> GetFilenames(); |
michael@0 | 54 | already_AddRefed<ArchiveRequest> GetFile(const nsAString& filename); |
michael@0 | 55 | already_AddRefed<ArchiveRequest> GetFiles(); |
michael@0 | 56 | |
michael@0 | 57 | nsresult GetInputStream(nsIInputStream** aInputStream); |
michael@0 | 58 | nsresult GetSize(uint64_t* aSize); |
michael@0 | 59 | |
michael@0 | 60 | public: // for the ArchiveRequest: |
michael@0 | 61 | nsresult RegisterRequest(ArchiveRequest* aRequest); |
michael@0 | 62 | |
michael@0 | 63 | public: // For events: |
michael@0 | 64 | void Ready(nsTArray<nsCOMPtr<nsIDOMFile> >& aFileList, |
michael@0 | 65 | nsresult aStatus); |
michael@0 | 66 | |
michael@0 | 67 | private: |
michael@0 | 68 | ~ArchiveReader(); |
michael@0 | 69 | |
michael@0 | 70 | already_AddRefed<ArchiveRequest> GenerateArchiveRequest(); |
michael@0 | 71 | |
michael@0 | 72 | nsresult OpenArchive(); |
michael@0 | 73 | |
michael@0 | 74 | void RequestReady(ArchiveRequest* aRequest); |
michael@0 | 75 | |
michael@0 | 76 | protected: |
michael@0 | 77 | // The archive blob/file |
michael@0 | 78 | nsCOMPtr<nsIDOMBlob> mBlob; |
michael@0 | 79 | |
michael@0 | 80 | // The window is needed by the requests |
michael@0 | 81 | nsCOMPtr<nsPIDOMWindow> mWindow; |
michael@0 | 82 | |
michael@0 | 83 | // Are we ready to return data? |
michael@0 | 84 | enum { |
michael@0 | 85 | NOT_STARTED = 0, |
michael@0 | 86 | WORKING, |
michael@0 | 87 | READY |
michael@0 | 88 | } mStatus; |
michael@0 | 89 | |
michael@0 | 90 | // State of the read: |
michael@0 | 91 | enum { |
michael@0 | 92 | Header, // We are collecting the header: 30bytes |
michael@0 | 93 | Name, // The name length is contained in the header |
michael@0 | 94 | Data, // The length of the data segment COULD be written in the header |
michael@0 | 95 | Search // ... if the data length is unknown (== 0) we wait until we read a new header |
michael@0 | 96 | } mReadStatus; |
michael@0 | 97 | |
michael@0 | 98 | // List of requests to be processed |
michael@0 | 99 | nsTArray<nsRefPtr<ArchiveRequest> > mRequests; |
michael@0 | 100 | |
michael@0 | 101 | // Everything related to the blobs and the status: |
michael@0 | 102 | struct { |
michael@0 | 103 | nsTArray<nsCOMPtr<nsIDOMFile> > fileList; |
michael@0 | 104 | nsresult status; |
michael@0 | 105 | } mData; |
michael@0 | 106 | |
michael@0 | 107 | nsCString mEncoding; |
michael@0 | 108 | }; |
michael@0 | 109 | |
michael@0 | 110 | END_FILE_NAMESPACE |
michael@0 | 111 | |
michael@0 | 112 | #endif // mozilla_dom_file_domarchivereader_h__ |