Bug 1333077 - Remove 'temporary' attribute in File, r=qdot
authorAndrea Marchesini <amarchesini@mozilla.com>
Tue, 24 Jan 2017 12:11:07 +0100
changeset 465655 00e55dbadab2cfcf363ab8a1d01aa07f96ca9318
parent 465654 42ae95a8b64b0cc97a227d1f4182ce5e52cecb60
child 465656 b7511085ca02618ca5fa5567d742930e4ed94ba4
push id42663
push usercykesiopka.bmo@gmail.com
push dateTue, 24 Jan 2017 16:29:25 +0000
reviewersqdot
bugs1333077
milestone54.0a1
Bug 1333077 - Remove 'temporary' attribute in File, r=qdot
dom/base/nsContentUtils.cpp
dom/base/test/chrome/chrome.ini
dom/base/test/chrome/test_fileconstructor_tempfile.xul
dom/file/File.cpp
dom/file/File.h
dom/file/MultipartBlobImpl.cpp
dom/webidl/File.webidl
--- a/dom/base/nsContentUtils.cpp
+++ b/dom/base/nsContentUtils.cpp
@@ -7821,17 +7821,17 @@ nsContentUtils::TransferableToIPCTransfe
 
                 Shmem dataAsShmem = ConvertToShmem(aChild, aParent, data);
                 item->data() = dataAsShmem;
               }
 
               continue;
             }
 
-            blobImpl = new BlobImplFile(file, false);
+            blobImpl = new BlobImplFile(file);
             ErrorResult rv;
             // Ensure that file data is cached no that the content process
             // has this data available to it when passed over:
             blobImpl->GetSize(rv);
             blobImpl->GetLastModified(rv);
           } else {
             if (aInSyncMessage) {
               // Can't do anything.
--- a/dom/base/test/chrome/chrome.ini
+++ b/dom/base/test/chrome/chrome.ini
@@ -61,15 +61,14 @@ support-files = ../file_bug357450.js
 [test_bug1063837.xul]
 [test_bug1139964.xul]
 [test_bug1209621.xul]
 [test_cpows.xul]
 [test_registerElement_content.xul]
 [test_registerElement_ep.xul]
 [test_domparsing.xul]
 [test_fileconstructor.xul]
-[test_fileconstructor_tempfile.xul]
 [test_nsITextInputProcessor.xul]
 [test_range_getClientRectsAndTexts.html]
 [test_title.xul]
 [test_windowroot.xul]
 [test_swapFrameLoaders.xul]
 [test_groupedSHistory.xul]
deleted file mode 100644
--- a/dom/base/test/chrome/test_fileconstructor_tempfile.xul
+++ /dev/null
@@ -1,93 +0,0 @@
-<?xml version="1.0"?>
-<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
-<?xml-stylesheet
-  href="chrome://mochikit/content/tests/SimpleTest/test.css"
-  type="text/css"?>
-<!--
-https://bugzilla.mozilla.org/show_bug.cgi?id=982874
-
-Tests building a DOMFile with the "temporary" option and checks that
-the underlying file is removed when the DOMFile is gc'ed.
--->
-<window title="Mozilla Bug 982874"
-  xmlns:html="http://www.w3.org/1999/xhtml"
-  xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
-
-  <script type="application/javascript"
-    src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
-
-<body  xmlns="http://www.w3.org/1999/xhtml">
-<a target="_blank"
-   href="https://bugzilla.mozilla.org/show_bug.cgi?id=982874">
-   Mozilla Bug 982874</a>
-<p id="display"></p>
-<div id="content" style="display: none">
-
-</div>
-<pre id="test">
-</pre>
-</body>
-
-<script class="testbody" type="application/javascript">
-<![CDATA[
-
-/** Test for Bug 982874 **/
-var Cc = Components.classes;
-var Ci = Components.interfaces;
-var Cu = Components.utils;
-
-SimpleTest.waitForExplicitFinish();
-
-function cleanup(tmp) {
-  // Force cycle and garbage collection and check that we removed the file.
-  for (let i = 0; i < 10; i++) {
-    Cu.forceCC();
-    Cu.forceGC();
-  }
-  if (tmp.exists()) {
-    ok(false, "Failed to remove temporary file!");
-  } else {
-    ok(true, "Temporary file removed when gc-ing the DOMFile");
-  }
-  SimpleTest.finish();
-}
-
-try {
-  // Create a file in $TMPDIR/mozilla-temp-files
-  let tmp = Cc["@mozilla.org/file/directory_service;1"]
-              .getService(Ci.nsIProperties)
-              .get("TmpD", Ci.nsIFile);
-  tmp.append("mozilla-temp-files");
-  tmp.append("test.txt");
-  tmp.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0600);
-
-  // Add some content to the file.
-  let fileData = "I'm a temporary file!";
-  let outStream = Cc["@mozilla.org/network/file-output-stream;1"]
-                    .createInstance(Ci.nsIFileOutputStream);
-  outStream.init(tmp, 0x02 | 0x08 | 0x20, // write, create, truncate
-                 0666, 0);
-  outStream.write(fileData, fileData.length);
-  outStream.close();
-
-  // Create a scoped DOMFile so the gc will happily get rid of it.
-  {
-    let dirfile = File.createFromNsIFile(tmp, { temporary: true });
-    ok(true, "Temporary File() created");
-    let reader = new FileReader();
-    reader.readAsArrayBuffer(dirfile);
-    reader.onload = function(event) {
-      let buffer = event.target.result;
-      ok(buffer.byteLength > 0,
-         "Blob size should be > 0 : " + buffer.byteLength);
-      cleanup(tmp);
-    }
-  }
-} catch (e) {
-  ok(false, "Unable to create the File() object : " + e);
-  SimpleTest.finish();
-}
-]]>
-</script>
-
-</window>
--- a/dom/file/File.cpp
+++ b/dom/file/File.cpp
@@ -437,19 +437,19 @@ File::CreateMemoryFile(nsISupports* aPar
 {
   RefPtr<File> file = new File(aParent,
     new BlobImplMemory(aMemoryBuffer, aLength, aName,
                        aContentType, aLastModifiedDate));
   return file.forget();
 }
 
 /* static */ already_AddRefed<File>
-File::CreateFromFile(nsISupports* aParent, nsIFile* aFile, bool aTemporary)
+File::CreateFromFile(nsISupports* aParent, nsIFile* aFile)
 {
-  RefPtr<File> file = new File(aParent, new BlobImplFile(aFile, aTemporary));
+  RefPtr<File> file = new File(aParent, new BlobImplFile(aFile));
   return file.forget();
 }
 
 /* static */ already_AddRefed<File>
 File::CreateFromFile(nsISupports* aParent, nsIFile* aFile,
                      const nsAString& aName, const nsAString& aContentType)
 {
   RefPtr<File> file = new File(aParent,
--- a/dom/file/File.h
+++ b/dom/file/File.h
@@ -179,17 +179,17 @@ public:
 
   // This method creates a BlobFileImpl for the new File object. This is
   // thread-safe, cross-process, cross-thread as any other BlobImpl, but, when
   // GetType() is called, it must dispatch a runnable to the main-thread in
   // order to use nsIMIMEService.
   // Would be nice if we try to avoid to use this method outside the
   // main-thread to avoid extra runnables.
   static already_AddRefed<File>
-  CreateFromFile(nsISupports* aParent, nsIFile* aFile, bool aTemporary = false);
+  CreateFromFile(nsISupports* aParent, nsIFile* aFile);
 
   static already_AddRefed<File>
   CreateFromFile(nsISupports* aParent, nsIFile* aFile, const nsAString& aName,
                  const nsAString& aContentType);
 
   // WebIDL methods
 
   virtual JSObject* WrapObject(JSContext *cx,
@@ -671,57 +671,53 @@ private:
 };
 
 class BlobImplFile : public BlobImplBase
 {
 public:
   NS_DECL_ISUPPORTS_INHERITED
 
   // Create as a file
-  explicit BlobImplFile(nsIFile* aFile, bool aTemporary = false)
+  explicit BlobImplFile(nsIFile* aFile)
     : BlobImplBase(EmptyString(), EmptyString(), UINT64_MAX, INT64_MAX)
     , mFile(aFile)
     , mWholeFile(true)
-    , mIsTemporary(aTemporary)
   {
     MOZ_ASSERT(mFile, "must have file");
     // Lazily get the content type and size
     mContentType.SetIsVoid(true);
     mFile->GetLeafName(mName);
   }
 
   // Create as a file
   BlobImplFile(const nsAString& aName, const nsAString& aContentType,
                uint64_t aLength, nsIFile* aFile)
     : BlobImplBase(aName, aContentType, aLength, UINT64_MAX)
     , mFile(aFile)
     , mWholeFile(true)
-    , mIsTemporary(false)
   {
     MOZ_ASSERT(mFile, "must have file");
   }
 
   BlobImplFile(const nsAString& aName, const nsAString& aContentType,
                uint64_t aLength, nsIFile* aFile,
                int64_t aLastModificationDate)
     : BlobImplBase(aName, aContentType, aLength, aLastModificationDate)
     , mFile(aFile)
     , mWholeFile(true)
-    , mIsTemporary(false)
   {
     MOZ_ASSERT(mFile, "must have file");
   }
 
   // Create as a file with custom name
   BlobImplFile(nsIFile* aFile, const nsAString& aName,
                const nsAString& aContentType)
     : BlobImplBase(aName, aContentType, UINT64_MAX, INT64_MAX)
     , mFile(aFile)
     , mWholeFile(true)
-    , mIsTemporary(false)
   {
     MOZ_ASSERT(mFile, "must have file");
     if (aContentType.IsEmpty()) {
       // Lazily get the content type and size
       mContentType.SetIsVoid(true);
     }
   }
 
@@ -737,50 +733,36 @@ public:
 
   virtual bool IsDirectory() const override;
 
   // We always have size and date for this kind of blob.
   virtual bool IsSizeUnknown() const override { return false; }
   virtual bool IsDateUnknown() const override { return false; }
 
 protected:
-  virtual ~BlobImplFile() {
-    if (mFile && mIsTemporary) {
-      NS_WARNING("In temporary ~BlobImplFile");
-      // Ignore errors if any, not much we can do. Clean-up will be done by
-      // https://mxr.mozilla.org/mozilla-central/source/xpcom/io/nsAnonymousTemporaryFile.cpp?rev=6c1c7e45c902#127
-#ifdef DEBUG
-      nsresult rv =
-#endif
-      mFile->Remove(false);
-      NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
-                           "Failed to remove temporary DOMFile.");
-    }
-  }
+  virtual ~BlobImplFile() = default;
 
 private:
   // Create slice
   BlobImplFile(const BlobImplFile* aOther, uint64_t aStart,
                uint64_t aLength, const nsAString& aContentType)
     : BlobImplBase(aContentType, aOther->mStart + aStart, aLength)
     , mFile(aOther->mFile)
     , mWholeFile(false)
-    , mIsTemporary(false)
   {
     MOZ_ASSERT(mFile, "must have file");
     mImmutable = aOther->mImmutable;
   }
 
   virtual already_AddRefed<BlobImpl>
   CreateSlice(uint64_t aStart, uint64_t aLength,
               const nsAString& aContentType, ErrorResult& aRv) override;
 
   nsCOMPtr<nsIFile> mFile;
   bool mWholeFile;
-  bool mIsTemporary;
 };
 
 class EmptyBlobImpl final : public BlobImplBase
 {
 public:
   NS_DECL_ISUPPORTS_INHERITED
 
   explicit EmptyBlobImpl(const nsAString& aContentType)
--- a/dom/file/MultipartBlobImpl.cpp
+++ b/dom/file/MultipartBlobImpl.cpp
@@ -363,17 +363,17 @@ MultipartBlobImpl::InitializeChromeFile(
     aRv.Throw(NS_ERROR_FILE_IS_DIRECTORY);
     return;
   }
 
   if (mName.IsEmpty()) {
     aFile->GetLeafName(mName);
   }
 
-  RefPtr<File> blob = File::CreateFromFile(aWindow, aFile, aBag.mTemporary);
+  RefPtr<File> blob = File::CreateFromFile(aWindow, aFile);
 
   // Pre-cache size.
   blob->GetSize(aRv);
   if (NS_WARN_IF(aRv.Failed())) {
     return;
   }
 
   // Pre-cache modified date.
--- a/dom/webidl/File.webidl
+++ b/dom/webidl/File.webidl
@@ -21,17 +21,16 @@ interface File : Blob {
 
 dictionary FilePropertyBag {
   DOMString type = "";
   long long lastModified;
 };
 
 dictionary ChromeFilePropertyBag : FilePropertyBag {
   DOMString name = "";
-  boolean temporary = false;
 };
 
 // Mozilla extensions
 partial interface File {
   [GetterThrows, Deprecated="FileLastModifiedDate"]
   readonly attribute Date lastModifiedDate;
 
   [BinaryName="path", Func="mozilla::dom::Directory::WebkitBlinkDirectoryPickerEnabled"]