Bug 1173320 - patch 6/8 - Make FileList clonable to workers if it doesn't contain Directories, r=smaug
☠☠ backed out by bd8284e36c7c ☠ ☠
authorAndrea Marchesini <amarchesini@mozilla.com>
Sat, 19 Mar 2016 14:34:35 +0100
changeset 289523 cd7e79d9a7507c6b33744428632dc684c2a82e10
parent 289522 56bbea4fe19990be2b05cd31371e76c01a252fc5
child 289524 db971ba7c26de1d0849afb6640dd5232b8d9a80f
push id19656
push usergwagner@mozilla.com
push dateMon, 04 Apr 2016 13:43:23 +0000
treeherderb2g-inbound@e99061fde28a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1173320
milestone48.0a1
Bug 1173320 - patch 6/8 - Make FileList clonable to workers if it doesn't contain Directories, r=smaug
dom/base/FileList.cpp
dom/base/FileList.h
dom/base/StructuredCloneHolder.cpp
dom/base/test/test_postMessages.html
--- a/dom/base/FileList.cpp
+++ b/dom/base/FileList.cpp
@@ -106,10 +106,22 @@ FileList::ToSequence(Sequence<OwningFile
     return;
   }
 
   for (uint32_t i = 0; i < mFilesOrDirectories.Length(); ++i) {
     aSequence[i] = mFilesOrDirectories[i];
   }
 }
 
+bool
+FileList::ClonableToDifferentThreadOrProcess() const
+{
+  for (uint32_t i = 0; i < mFilesOrDirectories.Length(); ++i) {
+    if (mFilesOrDirectories[i].IsDirectory()) {
+      return false;
+    }
+  }
+
+  return true;
+}
+
 } // namespace dom
 } // namespace mozilla
--- a/dom/base/FileList.h
+++ b/dom/base/FileList.h
@@ -92,16 +92,18 @@ public:
   uint32_t Length() const
   {
     return mFilesOrDirectories.Length();
   }
 
   void ToSequence(Sequence<OwningFileOrDirectory>& aSequence,
                   ErrorResult& aRv) const;
 
+  bool ClonableToDifferentThreadOrProcess() const;
+
 private:
   ~FileList() {}
 
   nsTArray<OwningFileOrDirectory> mFilesOrDirectories;
   nsCOMPtr<nsISupports> mParent;
 };
 
 } // namespace dom
--- a/dom/base/StructuredCloneHolder.cpp
+++ b/dom/base/StructuredCloneHolder.cpp
@@ -1003,17 +1003,16 @@ StructuredCloneHolder::CustomReadHandler
 {
   MOZ_ASSERT(mSupportsCloning);
 
   if (aTag == SCTAG_DOM_BLOB) {
     return ReadBlob(aCx, aIndex, this);
   }
 
   if (aTag == SCTAG_DOM_FILELIST) {
-    MOZ_ASSERT(mSupportedContext == SameProcessSameThread);
     return ReadFileList(aCx, aReader, aIndex, this);
   }
 
   if (aTag == SCTAG_DOM_FORMDATA) {
     return ReadFormData(aCx, aReader, aIndex, this);
   }
 
   if (aTag == SCTAG_DOM_IMAGEBITMAP) {
@@ -1044,19 +1043,21 @@ StructuredCloneHolder::CustomWriteHandle
   {
     Blob* blob = nullptr;
     if (NS_SUCCEEDED(UNWRAP_OBJECT(Blob, aObj, blob))) {
       return WriteBlob(aWriter, blob, this);
     }
   }
 
   // See if this is a FileList object.
-  if (mSupportedContext == SameProcessSameThread) {
+  {
     FileList* fileList = nullptr;
-    if (NS_SUCCEEDED(UNWRAP_OBJECT(FileList, aObj, fileList))) {
+    if (NS_SUCCEEDED(UNWRAP_OBJECT(FileList, aObj, fileList)) &&
+        (mSupportedContext == SameProcessSameThread ||
+         fileList->ClonableToDifferentThreadOrProcess())) {
       return WriteFileList(aWriter, fileList, this);
     }
   }
 
   // See if this is a FormData object.
   {
     FormData* formData = nullptr;
     if (NS_SUCCEEDED(UNWRAP_OBJECT(FormData, aObj, formData))) {
--- a/dom/base/test/test_postMessages.html
+++ b/dom/base/test/test_postMessages.html
@@ -79,17 +79,17 @@ function create_fileList() {
   function onOpened(message) {
     var fileList = document.getElementById('fileList');
     SpecialPowers.wrap(fileList).mozSetFileArray([message.file]);
 
     // Just a simple test
     var domFile = fileList.files[0];
     is(domFile.name, "prefs.js", "fileName should be prefs.js");
 
-    clonableObjects.push({ crossThreads: false, data: fileList.files });
+    clonableObjects.push({ crossThreads: true, data: fileList.files });
     script.destroy();
     next();
   }
 
   script.addMessageListener("file.opened", onOpened);
   script.sendAsyncMessage("file.open");
 }