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: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #ifndef nsTransferable_h__ |
michael@0 | 7 | #define nsTransferable_h__ |
michael@0 | 8 | |
michael@0 | 9 | #include "nsIFormatConverter.h" |
michael@0 | 10 | #include "nsITransferable.h" |
michael@0 | 11 | #include "nsCOMPtr.h" |
michael@0 | 12 | #include "nsString.h" |
michael@0 | 13 | #include "nsTArray.h" |
michael@0 | 14 | |
michael@0 | 15 | class nsString; |
michael@0 | 16 | class nsDataObj; |
michael@0 | 17 | |
michael@0 | 18 | // |
michael@0 | 19 | // DataStruct |
michael@0 | 20 | // |
michael@0 | 21 | // Holds a flavor (a mime type) that describes the data and the associated data. |
michael@0 | 22 | // |
michael@0 | 23 | struct DataStruct |
michael@0 | 24 | { |
michael@0 | 25 | DataStruct ( const char* aFlavor ) |
michael@0 | 26 | : mDataLen(0), mFlavor(aFlavor), mCacheFileName(nullptr) { } |
michael@0 | 27 | ~DataStruct(); |
michael@0 | 28 | |
michael@0 | 29 | const nsCString& GetFlavor() const { return mFlavor; } |
michael@0 | 30 | void SetData( nsISupports* inData, uint32_t inDataLen ); |
michael@10 | 31 | void SetData( nsISupports* inData, uint32_t inDataLen, bool inPrivBrowse ); |
michael@0 | 32 | void GetData( nsISupports** outData, uint32_t *outDataLen ); |
michael@0 | 33 | already_AddRefed<nsIFile> GetFileSpec(const char* aFileName); |
michael@0 | 34 | bool IsDataAvailable() const { return (mData && mDataLen > 0) || (!mData && mCacheFileName); } |
michael@0 | 35 | |
michael@0 | 36 | protected: |
michael@0 | 37 | |
michael@0 | 38 | enum { |
michael@0 | 39 | // The size of data over which we write the data to disk rather than |
michael@0 | 40 | // keep it around in memory. |
michael@0 | 41 | kLargeDatasetSize = 1000000 // 1 million bytes |
michael@0 | 42 | }; |
michael@0 | 43 | |
michael@0 | 44 | nsresult WriteCache(nsISupports* aData, uint32_t aDataLen ); |
michael@0 | 45 | nsresult ReadCache(nsISupports** aData, uint32_t* aDataLen ); |
michael@0 | 46 | |
michael@0 | 47 | nsCOMPtr<nsISupports> mData; // OWNER - some varient of primitive wrapper |
michael@0 | 48 | uint32_t mDataLen; |
michael@0 | 49 | const nsCString mFlavor; |
michael@0 | 50 | char * mCacheFileName; |
michael@0 | 51 | |
michael@0 | 52 | }; |
michael@0 | 53 | |
michael@0 | 54 | /** |
michael@0 | 55 | * XP Transferable wrapper |
michael@0 | 56 | */ |
michael@0 | 57 | |
michael@0 | 58 | class nsTransferable : public nsITransferable |
michael@0 | 59 | { |
michael@0 | 60 | public: |
michael@0 | 61 | |
michael@0 | 62 | nsTransferable(); |
michael@0 | 63 | virtual ~nsTransferable(); |
michael@0 | 64 | |
michael@0 | 65 | // nsISupports |
michael@0 | 66 | NS_DECL_ISUPPORTS |
michael@0 | 67 | NS_DECL_NSITRANSFERABLE |
michael@0 | 68 | |
michael@0 | 69 | protected: |
michael@0 | 70 | |
michael@0 | 71 | // get flavors w/out converter |
michael@0 | 72 | nsresult GetTransferDataFlavors(nsISupportsArray** aDataFlavorList); |
michael@0 | 73 | |
michael@0 | 74 | nsTArray<DataStruct> mDataArray; |
michael@0 | 75 | nsCOMPtr<nsIFormatConverter> mFormatConv; |
michael@0 | 76 | bool mPrivateData; |
michael@0 | 77 | #if DEBUG |
michael@0 | 78 | bool mInitialized; |
michael@0 | 79 | #endif |
michael@0 | 80 | |
michael@0 | 81 | }; |
michael@0 | 82 | |
michael@0 | 83 | #endif // nsTransferable_h__ |