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