Bug 1341327 - Add assertions to be sure that FileBlobImpls are created on the parent process only, r=smaug

This commit is contained in:
Andrea Marchesini 2017-02-23 03:23:51 +01:00
parent 4d5f8afdc0
commit 68feb209f4
4 changed files with 13 additions and 3 deletions

View file

@ -13,6 +13,7 @@
#include "mozilla/dom/FileCreatorHelper.h"
#include "mozilla/dom/FileSystemUtils.h"
#include "mozilla/dom/Promise.h"
#include "nsXULAppAPI.h"
namespace mozilla {
namespace dom {
@ -60,6 +61,7 @@ File::CreateMemoryFile(nsISupports* aParent, void* aMemoryBuffer,
/* static */ already_AddRefed<File>
File::CreateFromFile(nsISupports* aParent, nsIFile* aFile)
{
MOZ_DIAGNOSTIC_ASSERT(XRE_IsParentProcess());
RefPtr<File> file = new File(aParent, new FileBlobImpl(aFile));
return file.forget();
}
@ -68,6 +70,7 @@ File::CreateFromFile(nsISupports* aParent, nsIFile* aFile)
File::CreateFromFile(nsISupports* aParent, nsIFile* aFile,
const nsAString& aName, const nsAString& aContentType)
{
MOZ_DIAGNOSTIC_ASSERT(XRE_IsParentProcess());
RefPtr<File> file = new File(aParent,
new FileBlobImpl(aFile, aName, aContentType));
return file.forget();
@ -166,8 +169,6 @@ File::CreateFromNsIFile(const GlobalObject& aGlobal,
SystemCallerGuarantee aGuarantee,
ErrorResult& aRv)
{
MOZ_ASSERT(NS_IsMainThread());
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(aGlobal.GetAsSupports());
RefPtr<Promise> promise =

View file

@ -28,6 +28,7 @@ FileBlobImpl::FileBlobImpl(nsIFile* aFile)
, mWholeFile(true)
{
MOZ_ASSERT(mFile, "must have file");
MOZ_ASSERT(XRE_IsParentProcess());
// Lazily get the content type and size
mContentType.SetIsVoid(true);
mFile->GetLeafName(mName);
@ -41,6 +42,7 @@ FileBlobImpl::FileBlobImpl(const nsAString& aName,
, mWholeFile(true)
{
MOZ_ASSERT(mFile, "must have file");
MOZ_ASSERT(XRE_IsParentProcess());
}
FileBlobImpl::FileBlobImpl(const nsAString& aName,
@ -52,6 +54,7 @@ FileBlobImpl::FileBlobImpl(const nsAString& aName,
, mWholeFile(true)
{
MOZ_ASSERT(mFile, "must have file");
MOZ_ASSERT(XRE_IsParentProcess());
}
FileBlobImpl::FileBlobImpl(nsIFile* aFile, const nsAString& aName,
@ -61,6 +64,7 @@ FileBlobImpl::FileBlobImpl(nsIFile* aFile, const nsAString& aName,
, mWholeFile(true)
{
MOZ_ASSERT(mFile, "must have file");
MOZ_ASSERT(XRE_IsParentProcess());
if (aContentType.IsEmpty()) {
// Lazily get the content type and size
mContentType.SetIsVoid(true);
@ -74,6 +78,7 @@ FileBlobImpl::FileBlobImpl(const FileBlobImpl* aOther, uint64_t aStart,
, mWholeFile(false)
{
MOZ_ASSERT(mFile, "must have file");
MOZ_ASSERT(XRE_IsParentProcess());
mImmutable = aOther->mImmutable;
}

View file

@ -31,7 +31,7 @@ FileCreatorHelper::CreateFile(nsIGlobalObject* aGlobalObject,
bool aIsFromNsIFile,
ErrorResult& aRv)
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_DIAGNOSTIC_ASSERT(NS_IsMainThread());
RefPtr<Promise> promise = Promise::Create(aGlobalObject, aRv);
if (NS_WARN_IF(aRv.Failed())) {

View file

@ -38,7 +38,11 @@ partial interface File {
[GetterThrows, ChromeOnly, NeedsCallerType]
readonly attribute DOMString mozFullPath;
};
// Mozilla extensions - main-thread only
[Exposed=(Window)]
partial interface File {
[ChromeOnly, Throws, NeedsCallerType]
static Promise<File> createFromNsIFile(nsIFile file,
optional ChromeFilePropertyBag options);