2017-10-27 01:08:41 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2015-08-28 22:21:08 +03:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_dom_DataTransferItem_h
|
|
|
|
#define mozilla_dom_DataTransferItem_h
|
|
|
|
|
|
|
|
#include "mozilla/ErrorResult.h"
|
|
|
|
#include "mozilla/dom/DataTransfer.h"
|
|
|
|
#include "mozilla/dom/DOMString.h"
|
|
|
|
#include "mozilla/dom/File.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2016-08-18 10:17:25 +03:00
|
|
|
class FileSystemEntry;
|
2015-08-28 22:21:08 +03:00
|
|
|
class FunctionStringCallback;
|
|
|
|
|
|
|
|
class DataTransferItem final : public nsISupports, public nsWrapperCache {
|
|
|
|
public:
|
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(DataTransferItem);
|
|
|
|
|
|
|
|
public:
|
|
|
|
// The spec only talks about the "file" and "string" kinds. Due to the Moz*
|
|
|
|
// APIs, it is possible to attach any type to a DataTransferItem, meaning that
|
|
|
|
// we can have other kinds then just FILE and STRING. These others are simply
|
|
|
|
// marked as "other" and can only be produced throug the Moz* APIs.
|
|
|
|
enum eKind {
|
|
|
|
KIND_FILE,
|
|
|
|
KIND_STRING,
|
|
|
|
KIND_OTHER,
|
|
|
|
};
|
|
|
|
|
2016-10-11 04:07:47 +03:00
|
|
|
DataTransferItem(DataTransfer* aDataTransfer, const nsAString& aType,
|
|
|
|
eKind aKind = KIND_OTHER)
|
2016-08-18 01:39:15 +03:00
|
|
|
: mIndex(0),
|
|
|
|
mChromeOnly(false),
|
2016-10-11 04:07:47 +03:00
|
|
|
mKind(aKind),
|
2016-08-18 01:39:15 +03:00
|
|
|
mType(aType),
|
|
|
|
mDataTransfer(aDataTransfer) {
|
|
|
|
MOZ_ASSERT(mDataTransfer, "Must be associated with a DataTransfer");
|
|
|
|
}
|
2015-08-28 22:21:08 +03:00
|
|
|
|
2016-08-18 01:39:15 +03:00
|
|
|
already_AddRefed<DataTransferItem> Clone(DataTransfer* aDataTransfer) const;
|
2015-08-28 22:21:08 +03:00
|
|
|
|
|
|
|
virtual JSObject* WrapObject(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) override;
|
2016-08-23 18:29:48 +03:00
|
|
|
|
2016-09-29 09:55:20 +03:00
|
|
|
void GetAsString(FunctionStringCallback* aCallback,
|
2016-10-11 04:07:48 +03:00
|
|
|
nsIPrincipal& aSubjectPrincipal, ErrorResult& aRv);
|
2016-08-23 18:29:48 +03:00
|
|
|
|
2015-08-28 22:21:08 +03:00
|
|
|
void GetKind(nsAString& aKind) const {
|
|
|
|
switch (mKind) {
|
|
|
|
case KIND_FILE:
|
|
|
|
aKind = NS_LITERAL_STRING("file");
|
|
|
|
return;
|
|
|
|
case KIND_STRING:
|
|
|
|
aKind = NS_LITERAL_STRING("string");
|
|
|
|
return;
|
|
|
|
default:
|
|
|
|
aKind = NS_LITERAL_STRING("other");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-25 00:06:35 +03:00
|
|
|
void GetInternalType(nsAString& aType) const { aType = mType; }
|
2015-08-28 22:21:08 +03:00
|
|
|
|
2017-02-25 00:06:35 +03:00
|
|
|
void GetType(nsAString& aType);
|
|
|
|
|
2015-08-28 22:21:08 +03:00
|
|
|
eKind Kind() const { return mKind; }
|
|
|
|
|
2016-10-11 04:07:48 +03:00
|
|
|
already_AddRefed<File> GetAsFile(nsIPrincipal& aSubjectPrincipal,
|
|
|
|
ErrorResult& aRv);
|
2015-08-28 22:21:08 +03:00
|
|
|
|
2016-10-11 04:07:48 +03:00
|
|
|
already_AddRefed<FileSystemEntry> GetAsEntry(nsIPrincipal& aSubjectPrincipal,
|
|
|
|
ErrorResult& aRv);
|
2016-07-29 14:42:33 +03:00
|
|
|
|
2016-08-18 01:39:15 +03:00
|
|
|
DataTransfer* GetParentObject() const { return mDataTransfer; }
|
2015-08-28 22:21:08 +03:00
|
|
|
|
|
|
|
nsIPrincipal* Principal() const { return mPrincipal; }
|
|
|
|
void SetPrincipal(nsIPrincipal* aPrincipal) { mPrincipal = aPrincipal; }
|
|
|
|
|
2016-08-18 01:39:15 +03:00
|
|
|
already_AddRefed<nsIVariant> DataNoSecurityCheck();
|
2018-05-31 18:57:57 +03:00
|
|
|
// Data may return null if the clipboard state has changed since the type was
|
|
|
|
// detected.
|
2016-08-18 01:39:15 +03:00
|
|
|
already_AddRefed<nsIVariant> Data(nsIPrincipal* aPrincipal, ErrorResult& aRv);
|
2016-10-11 04:07:47 +03:00
|
|
|
|
|
|
|
// Note: This can modify the mKind. Callers of this method must let the
|
|
|
|
// relevant DataTransfer know, because its types list can change as a result.
|
2015-08-28 22:21:08 +03:00
|
|
|
void SetData(nsIVariant* aData);
|
|
|
|
|
|
|
|
uint32_t Index() const { return mIndex; }
|
|
|
|
void SetIndex(uint32_t aIndex) { mIndex = aIndex; }
|
|
|
|
void FillInExternalData();
|
|
|
|
|
2016-05-31 22:03:44 +03:00
|
|
|
bool ChromeOnly() const { return mChromeOnly; }
|
|
|
|
void SetChromeOnly(bool aChromeOnly) { mChromeOnly = aChromeOnly; }
|
|
|
|
|
2016-08-23 18:29:48 +03:00
|
|
|
static eKind KindFromData(nsIVariant* aData);
|
|
|
|
|
2015-08-28 22:21:08 +03:00
|
|
|
private:
|
|
|
|
~DataTransferItem() {}
|
2016-06-21 20:07:17 +03:00
|
|
|
already_AddRefed<File> CreateFileFromInputStream(nsIInputStream* aStream);
|
2015-08-28 22:21:08 +03:00
|
|
|
|
|
|
|
// The index in the 2d mIndexedItems array
|
|
|
|
uint32_t mIndex;
|
|
|
|
|
2016-05-31 22:03:44 +03:00
|
|
|
bool mChromeOnly;
|
2015-08-28 22:21:08 +03:00
|
|
|
eKind mKind;
|
2016-10-11 04:07:47 +03:00
|
|
|
const nsString mType;
|
2015-08-28 22:21:08 +03:00
|
|
|
nsCOMPtr<nsIVariant> mData;
|
|
|
|
nsCOMPtr<nsIPrincipal> mPrincipal;
|
2016-08-18 01:39:15 +03:00
|
|
|
RefPtr<DataTransfer> mDataTransfer;
|
2016-06-21 20:07:17 +03:00
|
|
|
|
|
|
|
// File cache for nsIFile application/x-moz-file entries.
|
|
|
|
RefPtr<File> mCachedFile;
|
2015-08-28 22:21:08 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif /* mozilla_dom_DataTransferItem_h */
|