Bug 912489 - Including the name of the directory picked by HTMLInputElement.openDirectoryPicker() in File.path. r=sicking
authorJonathan Watt <jwatt@jwatt.org>
Wed, 02 Oct 2013 00:26:40 +0100
changeset 149620 32c6282f3a29dba12f60ff30945d0d22bd7ea948
parent 149619 50400711c347b3aff4f179907ac153a46a3a76a4
child 149621 91690a35f26d72bb3aa34faa9fabf3577435fa20
push idunknown
push userunknown
push dateunknown
reviewerssicking
bugs912489
milestone27.0a1
Bug 912489 - Including the name of the directory picked by HTMLInputElement.openDirectoryPicker() in File.path. r=sicking
content/html/content/src/HTMLInputElement.cpp
--- a/content/html/content/src/HTMLInputElement.cpp
+++ b/content/html/content/src/HTMLInputElement.cpp
@@ -352,16 +352,22 @@ public:
 #ifdef DEBUG
     {
       bool isDir;
       aTopDir->IsDirectory(&isDir);
       MOZ_ASSERT(isDir);
     }
 #endif
 
+    if (NS_FAILED(aTopDir->GetParent(getter_AddRefs(mTopDirsParent)))) {
+      // This just means that the name of the picked directory won't be
+      // included in the File.path string.
+      mTopDirsParent = aTopDir;
+    }
+
     nsCOMPtr<nsISimpleEnumerator> entries;
     if (NS_SUCCEEDED(mTopDir->GetDirectoryEntries(getter_AddRefs(entries))) &&
         entries) {
       mDirEnumeratorStack.AppendElement(entries);
       LookupAndCacheNext();
     }
   }
 
@@ -372,17 +378,18 @@ public:
                "Walking the directory tree involves I/O, so using this "
                "enumerator can block a thread for a long time!");
 
     if (!mNextFile) {
       return NS_ERROR_FAILURE;
     }
     nsRefPtr<nsDOMFileFile> domFile = new nsDOMFileFile(mNextFile);
     nsCString relDescriptor;
-    nsresult rv = mNextFile->GetRelativeDescriptor(mTopDir, relDescriptor);
+    nsresult rv =
+      mNextFile->GetRelativeDescriptor(mTopDirsParent, relDescriptor);
     NS_ENSURE_SUCCESS(rv, rv);
     NS_ConvertUTF8toUTF16 path(relDescriptor);
     nsAutoString leafName;
     mNextFile->GetLeafName(leafName);
     MOZ_ASSERT(leafName.Length() <= path.Length());
     int32_t length = path.Length() - leafName.Length();
     MOZ_ASSERT(length >= 0);
     if (length > 0) {
@@ -458,16 +465,17 @@ private:
 
       mNextFile.swap(file);
       return;
     }
   }
 
 private:
   nsCOMPtr<nsIFile> mTopDir;
+  nsCOMPtr<nsIFile> mTopDirsParent; // May be mTopDir if no parent
   nsCOMPtr<nsIFile> mNextFile;
   nsTArray<nsCOMPtr<nsISimpleEnumerator> > mDirEnumeratorStack;
 };
 
 NS_IMPL_ISUPPORTS1(DirPickerRecursiveFileEnumerator, nsISimpleEnumerator)
 
 class DirPickerBuildFileListTask MOZ_FINAL
   : public nsRunnable