Bug 1341327 - Add assertions to be sure that FileBlobImpls are created on the parent process only, r=smaug
authorAndrea Marchesini <amarchesini@mozilla.com>
Thu, 23 Feb 2017 03:23:51 +0100
changeset 344446 a511e97862314dc1b90c531205489b972f5d50bd
parent 344445 06c838c29b6f619ffaebcf5093bd415c926eb477
child 344447 93f3dc64e9bf63f0f0244c488a721110a8295a3c
push id31408
push usercbook@mozilla.com
push dateThu, 23 Feb 2017 13:59:58 +0000
treeherdermozilla-central@c02dd6a7e9c1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1341327
milestone54.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1341327 - Add assertions to be sure that FileBlobImpls are created on the parent process only, r=smaug
dom/file/File.cpp
dom/file/FileBlobImpl.cpp
dom/file/FileCreatorHelper.cpp
dom/webidl/File.webidl
--- a/dom/file/File.cpp
+++ b/dom/file/File.cpp
@@ -8,16 +8,17 @@
 #include "FileBlobImpl.h"
 #include "MemoryBlobImpl.h"
 #include "MultipartBlobImpl.h"
 #include "mozilla/dom/BlobBinding.h"
 #include "mozilla/dom/FileBinding.h"
 #include "mozilla/dom/FileCreatorHelper.h"
 #include "mozilla/dom/FileSystemUtils.h"
 #include "mozilla/dom/Promise.h"
+#include "nsXULAppAPI.h"
 
 namespace mozilla {
 namespace dom {
 
 File::File(nsISupports* aParent, BlobImpl* aImpl)
   : Blob(aParent, aImpl)
 {
   MOZ_ASSERT(aImpl->IsFile());
@@ -55,24 +56,26 @@ File::CreateMemoryFile(nsISupports* aPar
     new MemoryBlobImpl(aMemoryBuffer, aLength, aName,
                        aContentType, aLastModifiedDate));
   return file.forget();
 }
 
 /* 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();
 }
 
 /* static */ already_AddRefed<File>
 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();
 }
 
 JSObject*
 File::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
 {
@@ -161,18 +164,16 @@ File::Constructor(const GlobalObject& aG
 
 /* static */ already_AddRefed<Promise>
 File::CreateFromNsIFile(const GlobalObject& aGlobal,
                         nsIFile* aData,
                         const ChromeFilePropertyBag& aBag,
                         SystemCallerGuarantee aGuarantee,
                         ErrorResult& aRv)
 {
-  MOZ_ASSERT(NS_IsMainThread());
-
   nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(aGlobal.GetAsSupports());
 
   RefPtr<Promise> promise =
     FileCreatorHelper::CreateFile(global, aData, aBag, true, aRv);
   return promise.forget();
 }
 
 /* static */ already_AddRefed<Promise>
--- a/dom/file/FileBlobImpl.cpp
+++ b/dom/file/FileBlobImpl.cpp
@@ -23,62 +23,67 @@ using namespace workers;
 NS_IMPL_ISUPPORTS_INHERITED0(FileBlobImpl, BlobImpl)
 
 FileBlobImpl::FileBlobImpl(nsIFile* aFile)
   : BaseBlobImpl(EmptyString(), EmptyString(), UINT64_MAX, INT64_MAX)
   , mFile(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);
 }
 
 FileBlobImpl::FileBlobImpl(const nsAString& aName,
                            const nsAString& aContentType,
                            uint64_t aLength, nsIFile* aFile)
   : BaseBlobImpl(aName, aContentType, aLength, UINT64_MAX)
   , mFile(aFile)
   , mWholeFile(true)
 {
   MOZ_ASSERT(mFile, "must have file");
+  MOZ_ASSERT(XRE_IsParentProcess());
 }
 
 FileBlobImpl::FileBlobImpl(const nsAString& aName,
                            const nsAString& aContentType,
                            uint64_t aLength, nsIFile* aFile,
                            int64_t aLastModificationDate)
   : BaseBlobImpl(aName, aContentType, aLength, aLastModificationDate)
   , mFile(aFile)
   , mWholeFile(true)
 {
   MOZ_ASSERT(mFile, "must have file");
+  MOZ_ASSERT(XRE_IsParentProcess());
 }
 
 FileBlobImpl::FileBlobImpl(nsIFile* aFile, const nsAString& aName,
                            const nsAString& aContentType)
   : BaseBlobImpl(aName, aContentType, UINT64_MAX, INT64_MAX)
   , mFile(aFile)
   , 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);
   }
 }
 
 FileBlobImpl::FileBlobImpl(const FileBlobImpl* aOther, uint64_t aStart,
                            uint64_t aLength, const nsAString& aContentType)
   : BaseBlobImpl(aContentType, aOther->mStart + aStart, aLength)
   , mFile(aOther->mFile)
   , mWholeFile(false)
 {
   MOZ_ASSERT(mFile, "must have file");
+  MOZ_ASSERT(XRE_IsParentProcess());
   mImmutable = aOther->mImmutable;
 }
 
 already_AddRefed<BlobImpl>
 FileBlobImpl::CreateSlice(uint64_t aStart, uint64_t aLength,
                           const nsAString& aContentType,
                           ErrorResult& aRv)
 {
--- a/dom/file/FileCreatorHelper.cpp
+++ b/dom/file/FileCreatorHelper.cpp
@@ -26,17 +26,17 @@ namespace dom {
 
 /* static */ already_AddRefed<Promise>
 FileCreatorHelper::CreateFile(nsIGlobalObject* aGlobalObject,
                               nsIFile* aFile,
                               const ChromeFilePropertyBag& aBag,
                               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())) {
     return nullptr;
   }
 
   nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(aGlobalObject);
 
--- a/dom/webidl/File.webidl
+++ b/dom/webidl/File.webidl
@@ -33,17 +33,21 @@ partial interface File {
   [GetterThrows, Deprecated="FileLastModifiedDate"]
   readonly attribute Date lastModifiedDate;
 
   [BinaryName="relativePath", Func="mozilla::dom::Directory::WebkitBlinkDirectoryPickerEnabled"]
   readonly attribute USVString webkitRelativePath;
 
   [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);
 
   [ChromeOnly, Throws, NeedsCallerType]
   static Promise<File> createFromFileName(USVString fileName,
                                           optional ChromeFilePropertyBag options);
 };