Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
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@15 | 30 | void SetData( nsISupports* inData, uint32_t inDataLen, bool aIsPrivateData ); |
michael@0 | 31 | void GetData( nsISupports** outData, uint32_t *outDataLen ); |
michael@0 | 32 | already_AddRefed<nsIFile> GetFileSpec(const char* aFileName); |
michael@0 | 33 | bool IsDataAvailable() const { return (mData && mDataLen > 0) || (!mData && mCacheFileName); } |
michael@0 | 34 | |
michael@0 | 35 | protected: |
michael@0 | 36 | |
michael@0 | 37 | enum { |
michael@0 | 38 | // The size of data over which we write the data to disk rather than |
michael@0 | 39 | // keep it around in memory. |
michael@0 | 40 | kLargeDatasetSize = 1000000 // 1 million bytes |
michael@0 | 41 | }; |
michael@0 | 42 | |
michael@0 | 43 | nsresult WriteCache(nsISupports* aData, uint32_t aDataLen ); |
michael@0 | 44 | nsresult ReadCache(nsISupports** aData, uint32_t* aDataLen ); |
michael@0 | 45 | |
michael@0 | 46 | nsCOMPtr<nsISupports> mData; // OWNER - some varient of primitive wrapper |
michael@0 | 47 | uint32_t mDataLen; |
michael@0 | 48 | const nsCString mFlavor; |
michael@0 | 49 | char * mCacheFileName; |
michael@0 | 50 | |
michael@0 | 51 | }; |
michael@0 | 52 | |
michael@0 | 53 | /** |
michael@0 | 54 | * XP Transferable wrapper |
michael@0 | 55 | */ |
michael@0 | 56 | |
michael@0 | 57 | class nsTransferable : public nsITransferable |
michael@0 | 58 | { |
michael@0 | 59 | public: |
michael@0 | 60 | |
michael@0 | 61 | nsTransferable(); |
michael@0 | 62 | virtual ~nsTransferable(); |
michael@0 | 63 | |
michael@0 | 64 | // nsISupports |
michael@0 | 65 | NS_DECL_ISUPPORTS |
michael@0 | 66 | NS_DECL_NSITRANSFERABLE |
michael@0 | 67 | |
michael@0 | 68 | protected: |
michael@0 | 69 | |
michael@0 | 70 | // get flavors w/out converter |
michael@0 | 71 | nsresult GetTransferDataFlavors(nsISupportsArray** aDataFlavorList); |
michael@0 | 72 | |
michael@0 | 73 | nsTArray<DataStruct> mDataArray; |
michael@0 | 74 | nsCOMPtr<nsIFormatConverter> mFormatConv; |
michael@0 | 75 | bool mPrivateData; |
michael@0 | 76 | #if DEBUG |
michael@0 | 77 | bool mInitialized; |
michael@0 | 78 | #endif |
michael@0 | 79 | |
michael@0 | 80 | }; |
michael@0 | 81 | |
michael@0 | 82 | #endif // nsTransferable_h__ |