Bug 1297393 - Make passing of subject principals to webidl entry points explicit - part 2 - DataTransferItem, r=ehsan

This commit is contained in:
Andrea Marchesini 2016-09-29 08:55:20 +02:00
Родитель 47e3640d27
Коммит 995acd8d49
4 изменённых файлов: 24 добавлений и 29 удалений

Просмотреть файл

@ -238,21 +238,18 @@ DataTransferItem::FillInExternalData()
}
already_AddRefed<File>
DataTransferItem::GetAsFile(ErrorResult& aRv)
DataTransferItem::GetAsFile(const Maybe<nsIPrincipal*>& aSubjectPrincipal,
ErrorResult& aRv)
{
return GetAsFileWithPrincipal(nsContentUtils::SubjectPrincipal(), aRv);
}
MOZ_ASSERT(aSubjectPrincipal.isSome());
already_AddRefed<File>
DataTransferItem::GetAsFileWithPrincipal(nsIPrincipal* aPrincipal, ErrorResult& aRv)
{
if (mKind != KIND_FILE) {
return nullptr;
}
// This is done even if we have an mCachedFile, as it performs the necessary
// permissions checks to ensure that we are allowed to access this type.
nsCOMPtr<nsIVariant> data = Data(aPrincipal, aRv);
nsCOMPtr<nsIVariant> data = Data(aSubjectPrincipal.value(), aRv);
if (NS_WARN_IF(!data || aRv.Failed())) {
return nullptr;
}
@ -286,16 +283,12 @@ DataTransferItem::GetAsFileWithPrincipal(nsIPrincipal* aPrincipal, ErrorResult&
}
already_AddRefed<FileSystemEntry>
DataTransferItem::GetAsEntry(ErrorResult& aRv)
DataTransferItem::GetAsEntry(const Maybe<nsIPrincipal*>& aSubjectPrincipal,
ErrorResult& aRv)
{
return GetAsEntryWithPrincipal(nsContentUtils::SubjectPrincipal(), aRv);
}
MOZ_ASSERT(aSubjectPrincipal.isSome());
already_AddRefed<FileSystemEntry>
DataTransferItem::GetAsEntryWithPrincipal(nsIPrincipal* aPrincipal,
ErrorResult& aRv)
{
RefPtr<File> file = GetAsFileWithPrincipal(aPrincipal, aRv);
RefPtr<File> file = GetAsFile(aSubjectPrincipal, aRv);
if (NS_WARN_IF(aRv.Failed()) || !file) {
return nullptr;
}
@ -393,8 +386,11 @@ DataTransferItem::CreateFileFromInputStream(nsIInputStream* aStream)
void
DataTransferItem::GetAsString(FunctionStringCallback* aCallback,
const Maybe<nsIPrincipal*>& aSubjectPrincipal,
ErrorResult& aRv)
{
MOZ_ASSERT(aSubjectPrincipal.isSome());
if (!aCallback || mKind != KIND_STRING) {
return;
}
@ -402,7 +398,7 @@ DataTransferItem::GetAsString(FunctionStringCallback* aCallback,
// Theoretically this should be done inside of the runnable, as it might be an
// expensive operation on some systems, however we wouldn't get access to the
// NS_ERROR_DOM_SECURITY_ERROR messages which may be raised by this method.
nsCOMPtr<nsIVariant> data = Data(nsContentUtils::SubjectPrincipal(), aRv);
nsCOMPtr<nsIVariant> data = Data(aSubjectPrincipal.value(), aRv);
if (NS_WARN_IF(!data || aRv.Failed())) {
return;
}

Просмотреть файл

@ -50,7 +50,9 @@ public:
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
// NOTE: This accesses the subject principal, and should not be called from C++
void GetAsString(FunctionStringCallback* aCallback, ErrorResult& aRv);
void GetAsString(FunctionStringCallback* aCallback,
const Maybe<nsIPrincipal*>& aPrincipal,
ErrorResult& aRv);
void GetKind(nsAString& aKind) const
{
@ -82,15 +84,11 @@ public:
mKind = aKind;
}
// NOTE: This accesses the subject principal, and should not be called from C++
already_AddRefed<File> GetAsFile(ErrorResult& aRv);
already_AddRefed<File> GetAsFileWithPrincipal(nsIPrincipal* aPrincipal,
ErrorResult& aRv);
already_AddRefed<File>
GetAsFile(const Maybe<nsIPrincipal*>& aSubjectPrincipal, ErrorResult& aRv);
// NOTE: This accesses the subject principal, and should not be called from C++
already_AddRefed<FileSystemEntry> GetAsEntry(ErrorResult& aRv);
already_AddRefed<FileSystemEntry> GetAsEntryWithPrincipal(nsIPrincipal* aPrincipal,
ErrorResult& aRv);
already_AddRefed<FileSystemEntry>
GetAsEntry(const Maybe<nsIPrincipal*>& aSubjectPrincipal, ErrorResult& aRv);
DataTransfer* GetParentObject() const
{

Просмотреть файл

@ -557,7 +557,7 @@ DataTransferItemList::GenerateFiles(FileList* aFiles,
}
if (item->Kind() == DataTransferItem::KIND_FILE) {
RefPtr<File> file = item->GetAsFileWithPrincipal(aFilesPrincipal, rv);
RefPtr<File> file = item->GetAsFile(Some(aFilesPrincipal), rv);
if (NS_WARN_IF(rv.Failed() || !file)) {
continue;
}

Просмотреть файл

@ -10,15 +10,16 @@
interface DataTransferItem {
readonly attribute DOMString kind;
readonly attribute DOMString type;
[Throws]
[Throws, NeedsSubjectPrincipal]
void getAsString(FunctionStringCallback? _callback);
[Throws]
[Throws, NeedsSubjectPrincipal]
File? getAsFile();
};
callback FunctionStringCallback = void (DOMString data);
partial interface DataTransferItem {
[Pref="dom.webkitBlink.filesystem.enabled", BinaryName="getAsEntry", Throws]
[Pref="dom.webkitBlink.filesystem.enabled", BinaryName="getAsEntry", Throws,
NeedsSubjectPrincipal]
FileSystemEntry? webkitGetAsEntry();
};