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/. */
6 #ifndef nsTransferable_h__
7 #define nsTransferable_h__
9 #include "nsIFormatConverter.h"
10 #include "nsITransferable.h"
14 #include "nsIPrincipal.h"
16 #include "mozilla/Maybe.h"
18 class nsIMutableArray
;
23 // Holds a flavor (a mime type) that describes the data and the associated data.
26 explicit DataStruct(const char* aFlavor
)
27 : mCacheFD(nullptr), mFlavor(aFlavor
) {}
28 DataStruct(DataStruct
&& aRHS
);
31 const nsCString
& GetFlavor() const { return mFlavor
; }
32 void SetData(nsISupports
* aData
, bool aIsPrivateData
);
33 void GetData(nsISupports
** aData
);
34 bool IsDataAvailable() const { return mData
|| mCacheFD
; }
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
43 nsresult
WriteCache(void* aData
, uint32_t aDataLen
);
44 nsresult
ReadCache(nsISupports
** aData
);
46 // mData OR mCacheFD should be used, not both.
47 nsCOMPtr
<nsISupports
> mData
; // OWNER - some varient of primitive wrapper
49 const nsCString mFlavor
;
52 DataStruct(const DataStruct
&) = delete;
53 DataStruct
& operator=(const DataStruct
&) = delete;
57 * XP Transferable wrapper
60 class nsTransferable
: public nsITransferable
{
66 NS_DECL_NSITRANSFERABLE
69 virtual ~nsTransferable();
71 // Get flavors w/out converter
72 void GetTransferDataFlavors(nsTArray
<nsCString
>& aFlavors
);
74 // Find index for data with the matching flavor in mDataArray.
75 mozilla::Maybe
<size_t> FindDataFlavor(const char* aFlavor
);
77 nsTArray
<DataStruct
> mDataArray
;
78 nsCOMPtr
<nsIFormatConverter
> mFormatConv
;
80 nsCOMPtr
<nsIPrincipal
> mRequestingPrincipal
;
81 nsContentPolicyType mContentPolicyType
;
87 #endif // nsTransferable_h__