Bug 1887677: Correctly compute inClass predicate when validating unbound private...
[gecko.git] / widget / nsTransferable.h
blob02f2b0459c015293c50ff1aeeba69a92bdf3aee4
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 "nsICookieJarSettings.h"
10 #include "nsIFormatConverter.h"
11 #include "nsITransferable.h"
12 #include "nsCOMPtr.h"
13 #include "nsString.h"
14 #include "nsTArray.h"
15 #include "nsIPrincipal.h"
16 #include "nsIReferrerInfo.h"
17 #include "prio.h"
18 #include "mozilla/Maybe.h"
20 class nsIMutableArray;
23 // DataStruct
25 // Holds a flavor (a mime type) that describes the data and the associated data.
27 struct DataStruct {
28 explicit DataStruct(const char* aFlavor)
29 : mCacheFD(nullptr), mFlavor(aFlavor) {}
30 DataStruct(DataStruct&& aRHS);
31 ~DataStruct();
33 const nsCString& GetFlavor() const { return mFlavor; }
34 void SetData(nsISupports* aData, bool aIsPrivateData);
35 void GetData(nsISupports** aData);
36 void ClearData();
37 bool IsDataAvailable() const { return mData || mCacheFD; }
39 protected:
40 enum {
41 // The size of data over which we write the data to disk rather than
42 // keep it around in memory.
43 kLargeDatasetSize = 1000000 // 1 million bytes
46 nsresult WriteCache(void* aData, uint32_t aDataLen);
47 nsresult ReadCache(nsISupports** aData);
49 // mData OR mCacheFD should be used, not both.
50 nsCOMPtr<nsISupports> mData; // OWNER - some varient of primitive wrapper
51 PRFileDesc* mCacheFD;
52 const nsCString mFlavor;
54 private:
55 DataStruct(const DataStruct&) = delete;
56 DataStruct& operator=(const DataStruct&) = delete;
59 /**
60 * XP Transferable wrapper
63 class nsTransferable : public nsITransferable {
64 public:
65 nsTransferable();
67 // nsISupports
68 NS_DECL_ISUPPORTS
69 NS_DECL_NSITRANSFERABLE
71 protected:
72 virtual ~nsTransferable();
74 // Get flavors w/out converter
75 void GetTransferDataFlavors(nsTArray<nsCString>& aFlavors);
77 // Find index for data with the matching flavor in mDataArray.
78 mozilla::Maybe<size_t> FindDataFlavor(const char* aFlavor);
80 nsTArray<DataStruct> mDataArray;
81 nsCOMPtr<nsIFormatConverter> mFormatConv;
82 bool mPrivateData;
83 nsCOMPtr<nsIPrincipal> mRequestingPrincipal;
84 nsContentPolicyType mContentPolicyType;
85 nsCOMPtr<nsICookieJarSettings> mCookieJarSettings;
86 nsCOMPtr<nsIReferrerInfo> mReferrerInfo;
87 #if DEBUG
88 bool mInitialized;
89 #endif
92 #endif // nsTransferable_h__