Line data Source code
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 "nsIContentPolicyBase.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 :
17 : class nsIMutableArray;
18 : class nsString;
19 :
20 : //
21 : // DataStruct
22 : //
23 : // Holds a flavor (a mime type) that describes the data and the associated data.
24 : //
25 0 : struct DataStruct
26 : {
27 0 : explicit DataStruct ( const char* aFlavor )
28 0 : : mDataLen(0), mFlavor(aFlavor), mCacheFileName(nullptr) { }
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 : already_AddRefed<nsIFile> GetFileSpec(const char* aFileName);
35 0 : bool IsDataAvailable() const { return (mData && mDataLen > 0) || (!mData && mCacheFileName); }
36 :
37 : protected:
38 :
39 : enum {
40 : // The size of data over which we write the data to disk rather than
41 : // keep it around in memory.
42 : kLargeDatasetSize = 1000000 // 1 million bytes
43 : };
44 :
45 : nsresult WriteCache(nsISupports* aData, uint32_t aDataLen );
46 : nsresult ReadCache(nsISupports** aData, uint32_t* aDataLen );
47 :
48 : nsCOMPtr<nsISupports> mData; // OWNER - some varient of primitive wrapper
49 : uint32_t mDataLen;
50 : const nsCString mFlavor;
51 : char * mCacheFileName;
52 :
53 : };
54 :
55 : /**
56 : * XP Transferable wrapper
57 : */
58 :
59 : class nsTransferable : public nsITransferable
60 : {
61 : public:
62 :
63 : nsTransferable();
64 :
65 : // nsISupports
66 : NS_DECL_ISUPPORTS
67 : NS_DECL_NSITRANSFERABLE
68 :
69 : protected:
70 : virtual ~nsTransferable();
71 :
72 : // get flavors w/out converter
73 : already_AddRefed<nsIMutableArray> GetTransferDataFlavors();
74 :
75 : nsTArray<DataStruct> mDataArray;
76 : nsCOMPtr<nsIFormatConverter> mFormatConv;
77 : bool mPrivateData;
78 : nsCOMPtr<nsIPrincipal> mRequestingPrincipal;
79 : nsContentPolicyType mContentPolicyType;
80 : #if DEBUG
81 : bool mInitialized;
82 : #endif
83 :
84 : };
85 :
86 : #endif // nsTransferable_h__
|