/work/obj-fuzz/dist/include/mozilla/dom/DataTransferItem.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #ifndef mozilla_dom_DataTransferItem_h |
8 | | #define mozilla_dom_DataTransferItem_h |
9 | | |
10 | | #include "mozilla/ErrorResult.h" |
11 | | #include "mozilla/dom/DataTransfer.h" |
12 | | #include "mozilla/dom/DOMString.h" |
13 | | #include "mozilla/dom/File.h" |
14 | | |
15 | | namespace mozilla { |
16 | | namespace dom { |
17 | | |
18 | | class FileSystemEntry; |
19 | | class FunctionStringCallback; |
20 | | |
21 | | class DataTransferItem final : public nsISupports |
22 | | , public nsWrapperCache |
23 | | { |
24 | | public: |
25 | | NS_DECL_CYCLE_COLLECTING_ISUPPORTS |
26 | | NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(DataTransferItem); |
27 | | |
28 | | public: |
29 | | // The spec only talks about the "file" and "string" kinds. Due to the Moz* |
30 | | // APIs, it is possible to attach any type to a DataTransferItem, meaning that |
31 | | // we can have other kinds then just FILE and STRING. These others are simply |
32 | | // marked as "other" and can only be produced throug the Moz* APIs. |
33 | | enum eKind { |
34 | | KIND_FILE, |
35 | | KIND_STRING, |
36 | | KIND_OTHER, |
37 | | }; |
38 | | |
39 | | DataTransferItem(DataTransfer* aDataTransfer, const nsAString& aType, |
40 | | eKind aKind = KIND_OTHER) |
41 | | : mIndex(0) |
42 | | , mChromeOnly(false) |
43 | | , mKind(aKind) |
44 | | , mType(aType) |
45 | | , mDataTransfer(aDataTransfer) |
46 | | { |
47 | | MOZ_ASSERT(mDataTransfer, "Must be associated with a DataTransfer"); |
48 | | } |
49 | | |
50 | | already_AddRefed<DataTransferItem> Clone(DataTransfer* aDataTransfer) const; |
51 | | |
52 | | virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override; |
53 | | |
54 | | void GetAsString(FunctionStringCallback* aCallback, |
55 | | nsIPrincipal& aSubjectPrincipal, |
56 | | ErrorResult& aRv); |
57 | | |
58 | | void GetKind(nsAString& aKind) const |
59 | 0 | { |
60 | 0 | switch (mKind) { |
61 | 0 | case KIND_FILE: |
62 | 0 | aKind = NS_LITERAL_STRING("file"); |
63 | 0 | return; |
64 | 0 | case KIND_STRING: |
65 | 0 | aKind = NS_LITERAL_STRING("string"); |
66 | 0 | return; |
67 | 0 | default: |
68 | 0 | aKind = NS_LITERAL_STRING("other"); |
69 | 0 | return; |
70 | 0 | } |
71 | 0 | } |
72 | | |
73 | | void GetInternalType(nsAString& aType) const |
74 | | { |
75 | | aType = mType; |
76 | | } |
77 | | |
78 | | void GetType(nsAString& aType); |
79 | | |
80 | | eKind Kind() const |
81 | | { |
82 | | return mKind; |
83 | | } |
84 | | |
85 | | already_AddRefed<File> |
86 | | GetAsFile(nsIPrincipal& aSubjectPrincipal, ErrorResult& aRv); |
87 | | |
88 | | already_AddRefed<FileSystemEntry> |
89 | | GetAsEntry(nsIPrincipal& aSubjectPrincipal, ErrorResult& aRv); |
90 | | |
91 | | DataTransfer* GetParentObject() const |
92 | 0 | { |
93 | 0 | return mDataTransfer; |
94 | 0 | } |
95 | | |
96 | | nsIPrincipal* Principal() const |
97 | | { |
98 | | return mPrincipal; |
99 | | } |
100 | | void SetPrincipal(nsIPrincipal* aPrincipal) |
101 | | { |
102 | | mPrincipal = aPrincipal; |
103 | | } |
104 | | |
105 | | already_AddRefed<nsIVariant> DataNoSecurityCheck(); |
106 | | // Data may return null if the clipboard state has changed since the type was detected. |
107 | | already_AddRefed<nsIVariant> Data(nsIPrincipal* aPrincipal, ErrorResult& aRv); |
108 | | |
109 | | // Note: This can modify the mKind. Callers of this method must let the |
110 | | // relevant DataTransfer know, because its types list can change as a result. |
111 | | void SetData(nsIVariant* aData); |
112 | | |
113 | | uint32_t Index() const |
114 | | { |
115 | | return mIndex; |
116 | | } |
117 | | void SetIndex(uint32_t aIndex) |
118 | | { |
119 | | mIndex = aIndex; |
120 | | } |
121 | | void FillInExternalData(); |
122 | | |
123 | | bool ChromeOnly() const |
124 | | { |
125 | | return mChromeOnly; |
126 | | } |
127 | | void SetChromeOnly(bool aChromeOnly) |
128 | | { |
129 | | mChromeOnly = aChromeOnly; |
130 | | } |
131 | | |
132 | | static eKind KindFromData(nsIVariant* aData); |
133 | | |
134 | | private: |
135 | | ~DataTransferItem() {} |
136 | | already_AddRefed<File> CreateFileFromInputStream(nsIInputStream* aStream); |
137 | | |
138 | | // The index in the 2d mIndexedItems array |
139 | | uint32_t mIndex; |
140 | | |
141 | | bool mChromeOnly; |
142 | | eKind mKind; |
143 | | const nsString mType; |
144 | | nsCOMPtr<nsIVariant> mData; |
145 | | nsCOMPtr<nsIPrincipal> mPrincipal; |
146 | | RefPtr<DataTransfer> mDataTransfer; |
147 | | |
148 | | // File cache for nsIFile application/x-moz-file entries. |
149 | | RefPtr<File> mCachedFile; |
150 | | }; |
151 | | |
152 | | } // namespace dom |
153 | | } // namespace mozilla |
154 | | |
155 | | #endif /* mozilla_dom_DataTransferItem_h */ |