Bug 1517200 [wpt PR 14691] - Less restrictive internal column count limit., a=testonly
[gecko.git] / widget / nsTransferable.h
blobe7608b2107a983a5bb976e29af4b325a25ea8464
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"
11 #include "nsCOMPtr.h"
12 #include "nsString.h"
13 #include "nsTArray.h"
14 #include "nsIPrincipal.h"
15 #include "prio.h"
16 #include "mozilla/Maybe.h"
18 class nsIMutableArray;
21 // DataStruct
23 // Holds a flavor (a mime type) that describes the data and the associated data.
25 struct DataStruct {
26 explicit DataStruct(const char* aFlavor)
27 : mCacheFD(nullptr), mFlavor(aFlavor) {}
28 DataStruct(DataStruct&& aRHS);
29 ~DataStruct();
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; }
36 protected:
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
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
48 PRFileDesc* mCacheFD;
49 const nsCString mFlavor;
51 private:
52 DataStruct(const DataStruct&) = delete;
53 DataStruct& operator=(const DataStruct&) = delete;
56 /**
57 * XP Transferable wrapper
60 class nsTransferable : public nsITransferable {
61 public:
62 nsTransferable();
64 // nsISupports
65 NS_DECL_ISUPPORTS
66 NS_DECL_NSITRANSFERABLE
68 protected:
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;
79 bool mPrivateData;
80 nsCOMPtr<nsIPrincipal> mRequestingPrincipal;
81 nsContentPolicyType mContentPolicyType;
82 #if DEBUG
83 bool mInitialized;
84 #endif
87 #endif // nsTransferable_h__