Bug 685236 - Add nsIFile::DisplayPath. r?froydnj draft
authorMasatoshi Kimura <VYV03354@nifty.ne.jp>
Sat, 30 Dec 2017 23:32:27 +0900
changeset 715683 12009117d1d1bc3cc0eae1e3095ae4b332ff5565
parent 715682 3bf634d2d42d9970f9ea7d72432091c34281bd5b
child 715684 d5211b4aa5964a27b0ddb0dc4f2d5e80fb0e7f32
push id94228
push userVYV03354@nifty.ne.jp
push dateThu, 04 Jan 2018 11:56:10 +0000
reviewersfroydnj
bugs685236
milestone59.0a1
Bug 685236 - Add nsIFile::DisplayPath. r?froydnj This method is used to replace some GetNativePath usage for logging. MozReview-Commit-ID: 9nWf2r4oviA
xpcom/io/FileDescriptorFile.cpp
xpcom/io/nsIFile.idl
xpcom/io/nsLocalFileUnix.cpp
xpcom/io/nsLocalFileWin.cpp
--- a/xpcom/io/FileDescriptorFile.cpp
+++ b/xpcom/io/FileDescriptorFile.cpp
@@ -121,16 +121,22 @@ FileDescriptorFile::GetPath(nsAString& a
 }
 
 filesystem::Path::string_type
 FileDescriptorFile::NativePath()
 {
   return mFile->NativePath();
 }
 
+nsCString
+FileDescriptorFile::DisplayPath()
+{
+  return mFile->DisplayPath();
+}
+
 NS_IMETHODIMP
 FileDescriptorFile::Equals(nsIFile* aOther, bool* aRetVal)
 {
   return mFile->Equals(aOther, aRetVal);
 }
 
 NS_IMETHODIMP
 FileDescriptorFile::Contains(nsIFile* aOther, bool* aRetVal)
--- a/xpcom/io/nsIFile.idl
+++ b/xpcom/io/nsIFile.idl
@@ -11,16 +11,17 @@ struct PRLibrary;
 #include <stdio.h>
 #include "mozilla/Path.h"
 %}
 
 [ptr] native PRFileDescStar(PRFileDesc);
 [ptr] native PRLibraryStar(PRLibrary);
 [ptr] native FILE(FILE);
 native PathString(mozilla::filesystem::Path::string_type);
+native UTF8String(nsCString);
 
 interface nsISimpleEnumerator;
 
 /**
  * An nsIFile is an abstract representation of a filename. It manages
  * filename encoding issues, pathname component separators ('/' vs. '\\'
  * vs. ':') and weird stuff like differing volumes with identical names, as
  * on pre-Darwin Macintoshes.
@@ -248,20 +249,25 @@ interface nsIFile : nsISupports
      *
      *  Note that the ACString attributes are returned in the 
      *  native filesystem charset.
      *
      */
     readonly attribute AString target;
     [noscript] readonly attribute ACString nativeTarget;
     readonly attribute AString path;
-    [notxpcom,nostdcall] PathString nativePath();
+    [notxpcom,nostdcall,must_use] PathString nativePath();
 %{C++
     nsresult GetNativePath(nsACString& aPath);
 %}
+    /*
+     * Returns a human-readable path string.
+     * The result is deliberately quoted to prevent abuse.
+     */
+    [notxpcom,nostdcall,must_use] UTF8String displayPath();
 
     boolean exists();
     boolean isWritable();
     boolean isReadable();
     boolean isExecutable();
     boolean isHidden();
     boolean isDirectory();
     boolean isFile();
--- a/xpcom/io/nsLocalFileUnix.cpp
+++ b/xpcom/io/nsLocalFileUnix.cpp
@@ -603,16 +603,25 @@ nsLocalFile::NativePath()
 
 nsresult
 nsIFile::GetNativePath(nsACString& aResult)
 {
   aResult = NativePath();
   return NS_OK;
 }
 
+nsCString
+nsLocalFile::DisplayPath()
+{
+  nsAutoCString path('[');
+  path.Append(mPath);
+  path.Append(']');
+  return mPath;
+}
+
 nsresult
 nsLocalFile::GetNativeTargetPathName(nsIFile* aNewParent,
                                      const nsACString& aNewName,
                                      nsACString& aResult)
 {
   nsresult rv;
   nsCOMPtr<nsIFile> oldParent;
 
--- a/xpcom/io/nsLocalFileWin.cpp
+++ b/xpcom/io/nsLocalFileWin.cpp
@@ -3560,16 +3560,25 @@ nsLocalFile::NativePath()
 
 nsresult
 nsIFile::GetNativePath(nsACString& aResult)
 {
   //NS_WARNING("This API is lossy. Use GetPath !");
   return NS_CopyUnicodeToNative(NativePath(), aResult);
 }
 
+nsCString
+nsLocalFile::DisplayPath()
+{
+  nsAutoCString path('[');
+  AppendUTF16toUTF8(mWorkingPath, path);
+  path.Append(']');
+  return path;
+}
+
 
 NS_IMETHODIMP
 nsLocalFile::GetNativeCanonicalPath(nsACString& aResult)
 {
   NS_WARNING("This method is lossy. Use GetCanonicalPath !");
   EnsureShortPath();
   NS_CopyUnicodeToNative(mShortWorkingPath, aResult);
   return NS_OK;