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_filehelper_h__ |
michael@0 | 8 | #define mozilla_dom_file_filehelper_h__ |
michael@0 | 9 | |
michael@0 | 10 | #include "FileCommon.h" |
michael@0 | 11 | |
michael@0 | 12 | #include "nsIRequestObserver.h" |
michael@0 | 13 | |
michael@0 | 14 | class nsIFileStorage; |
michael@0 | 15 | |
michael@0 | 16 | BEGIN_FILE_NAMESPACE |
michael@0 | 17 | |
michael@0 | 18 | class FileHelper; |
michael@0 | 19 | class FileRequest; |
michael@0 | 20 | class FileOutputStreamWrapper; |
michael@0 | 21 | class LockedFile; |
michael@0 | 22 | |
michael@0 | 23 | class FileHelperListener |
michael@0 | 24 | { |
michael@0 | 25 | public: |
michael@0 | 26 | NS_IMETHOD_(MozExternalRefCountType) |
michael@0 | 27 | AddRef() = 0; |
michael@0 | 28 | |
michael@0 | 29 | NS_IMETHOD_(MozExternalRefCountType) |
michael@0 | 30 | Release() = 0; |
michael@0 | 31 | |
michael@0 | 32 | virtual void |
michael@0 | 33 | OnFileHelperComplete(FileHelper* aFileHelper) = 0; |
michael@0 | 34 | }; |
michael@0 | 35 | |
michael@0 | 36 | /** |
michael@0 | 37 | * Must be subclassed. The subclass must implement DoAsyncRun. It may then |
michael@0 | 38 | * choose to implement GetSuccessResult to properly set the result of the |
michael@0 | 39 | * success event. Call Enqueue to start the file operation. |
michael@0 | 40 | */ |
michael@0 | 41 | class FileHelper : public nsIRequestObserver |
michael@0 | 42 | { |
michael@0 | 43 | friend class FileRequest; |
michael@0 | 44 | friend class FileOutputStreamWrapper; |
michael@0 | 45 | |
michael@0 | 46 | public: |
michael@0 | 47 | NS_DECL_THREADSAFE_ISUPPORTS |
michael@0 | 48 | NS_DECL_NSIREQUESTOBSERVER |
michael@0 | 49 | |
michael@0 | 50 | nsresult |
michael@0 | 51 | Enqueue(); |
michael@0 | 52 | |
michael@0 | 53 | nsresult |
michael@0 | 54 | AsyncRun(FileHelperListener* aListener); |
michael@0 | 55 | |
michael@0 | 56 | void |
michael@0 | 57 | OnStreamProgress(uint64_t aProgress, uint64_t aProgressMax); |
michael@0 | 58 | |
michael@0 | 59 | void |
michael@0 | 60 | OnStreamClose(); |
michael@0 | 61 | |
michael@0 | 62 | void |
michael@0 | 63 | OnStreamDestroy(); |
michael@0 | 64 | |
michael@0 | 65 | static LockedFile* |
michael@0 | 66 | GetCurrentLockedFile(); |
michael@0 | 67 | |
michael@0 | 68 | protected: |
michael@0 | 69 | FileHelper(LockedFile* aLockedFile, FileRequest* aRequest); |
michael@0 | 70 | |
michael@0 | 71 | virtual ~FileHelper(); |
michael@0 | 72 | |
michael@0 | 73 | virtual nsresult |
michael@0 | 74 | DoAsyncRun(nsISupports* aStream) = 0; |
michael@0 | 75 | |
michael@0 | 76 | virtual nsresult |
michael@0 | 77 | GetSuccessResult(JSContext* aCx, JS::MutableHandle<JS::Value> aVal); |
michael@0 | 78 | |
michael@0 | 79 | virtual void |
michael@0 | 80 | ReleaseObjects(); |
michael@0 | 81 | |
michael@0 | 82 | void |
michael@0 | 83 | Finish(); |
michael@0 | 84 | |
michael@0 | 85 | nsCOMPtr<nsIFileStorage> mFileStorage; |
michael@0 | 86 | nsRefPtr<LockedFile> mLockedFile; |
michael@0 | 87 | nsRefPtr<FileRequest> mFileRequest; |
michael@0 | 88 | |
michael@0 | 89 | nsRefPtr<FileHelperListener> mListener; |
michael@0 | 90 | nsCOMPtr<nsIRequest> mRequest; |
michael@0 | 91 | |
michael@0 | 92 | private: |
michael@0 | 93 | nsresult mResultCode; |
michael@0 | 94 | bool mFinished; |
michael@0 | 95 | }; |
michael@0 | 96 | |
michael@0 | 97 | END_FILE_NAMESPACE |
michael@0 | 98 | |
michael@0 | 99 | #endif // mozilla_dom_file_filehelper_h__ |