/src/mozilla-central/widget/nsTransferable.h
Line | Count | Source (jump to first uncovered line) |
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 | | #include "nsIPrincipal.h" |
15 | | #include "prio.h" |
16 | | |
17 | | class nsIMutableArray; |
18 | | |
19 | | // |
20 | | // DataStruct |
21 | | // |
22 | | // Holds a flavor (a mime type) that describes the data and the associated data. |
23 | | // |
24 | | struct DataStruct |
25 | | { |
26 | | explicit DataStruct ( const char* aFlavor ) |
27 | 0 | : mDataLen(0), mCacheFD(nullptr), mFlavor(aFlavor) { } |
28 | | DataStruct(DataStruct&& aRHS); |
29 | | ~DataStruct(); |
30 | | |
31 | 0 | const nsCString& GetFlavor() const { return mFlavor; } |
32 | | void SetData( nsISupports* inData, uint32_t inDataLen, bool aIsPrivateData ); |
33 | | void GetData( nsISupports** outData, uint32_t *outDataLen ); |
34 | 0 | bool IsDataAvailable() const { return mData ? mDataLen > 0 : mCacheFD != nullptr; } |
35 | | |
36 | | protected: |
37 | | |
38 | | enum { |
39 | | // The size of data over which we write the data to disk rather than |
40 | | // keep it around in memory. |
41 | | kLargeDatasetSize = 1000000 // 1 million bytes |
42 | | }; |
43 | | |
44 | | nsresult WriteCache(nsISupports* aData, uint32_t aDataLen ); |
45 | | nsresult ReadCache(nsISupports** aData, uint32_t* aDataLen ); |
46 | | |
47 | | // mData + mDataLen OR mCacheFD should be used, not both. |
48 | | nsCOMPtr<nsISupports> mData; // OWNER - some varient of primitive wrapper |
49 | | uint32_t mDataLen; |
50 | | PRFileDesc* mCacheFD; |
51 | | const nsCString mFlavor; |
52 | | |
53 | | private: |
54 | | DataStruct(const DataStruct&) = delete; |
55 | | DataStruct& operator=(const DataStruct&) = delete; |
56 | | |
57 | | }; |
58 | | |
59 | | /** |
60 | | * XP Transferable wrapper |
61 | | */ |
62 | | |
63 | | class nsTransferable : public nsITransferable |
64 | | { |
65 | | public: |
66 | | |
67 | | nsTransferable(); |
68 | | |
69 | | // nsISupports |
70 | | NS_DECL_ISUPPORTS |
71 | | NS_DECL_NSITRANSFERABLE |
72 | | |
73 | | protected: |
74 | | virtual ~nsTransferable(); |
75 | | |
76 | | // get flavors w/out converter |
77 | | already_AddRefed<nsIMutableArray> GetTransferDataFlavors(); |
78 | | |
79 | | nsTArray<DataStruct> mDataArray; |
80 | | nsCOMPtr<nsIFormatConverter> mFormatConv; |
81 | | bool mPrivateData; |
82 | | nsCOMPtr<nsIPrincipal> mRequestingPrincipal; |
83 | | nsContentPolicyType mContentPolicyType; |
84 | | #if DEBUG |
85 | | bool mInitialized; |
86 | | #endif |
87 | | |
88 | | }; |
89 | | |
90 | | #endif // nsTransferable_h__ |