Bug 682360 - Merge nsILocalFile and nsIFile interfaces; r=bsmedberg
authorGeoff Lankow <geoff@darktrojan.net>
Wed, 04 Apr 2012 23:04:37 +1200
changeset 94312 82c7bdff95d4abc73c071f0dd901bde35b9b23f4
parent 94311 d8c5316f513afee907aabd5a04873bdf41fdebb7
child 94313 ba7f8495dd574a0d615898f15677d0cf1ddac663
push id886
push userlsblakk@mozilla.com
push dateMon, 04 Jun 2012 19:57:52 +0000
treeherdermozilla-beta@bbd8d5efd6d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbsmedberg
bugs682360
milestone14.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 682360 - Merge nsILocalFile and nsIFile interfaces; r=bsmedberg
xpcom/io/nsIFile.idl
xpcom/io/nsILocalFile.idl
xpcom/io/nsLocalFileCommon.cpp
xpcom/io/nsLocalFileUnix.cpp
xpcom/io/nsLocalFileWin.cpp
--- a/xpcom/io/nsIFile.idl
+++ b/xpcom/io/nsIFile.idl
@@ -36,32 +36,42 @@
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsISupports.idl"
 
+%{C++
+#include "prio.h"
+#include "prlink.h"
+#include <stdio.h>
+%}
+
+[ptr] native PRFileDescStar(PRFileDesc);
+[ptr] native PRLibraryStar(PRLibrary);
+[ptr] native FILE(FILE);
+
 interface nsISimpleEnumerator;
 
 /**
  * This is the only correct cross-platform way to specify a file.
  * Strings are not such a way. If you grew up on windows or unix, you
  * may think they are.  Welcome to reality.
  *
  * All methods with string parameters have two forms.  The preferred
  * form operates on UCS-2 encoded characters strings.  An alternate
  * form operates on characters strings encoded in the "native" charset.
  *
  * A string containing characters encoded in the native charset cannot
  * be safely passed to javascript via xpconnect.  Therefore, the "native
  * methods" are not scriptable. 
  */
-[scriptable, uuid(c8c0a080-0868-11d3-915f-d9d889d48e3c)]
+[scriptable, uuid(272a5020-64f5-485c-a8c4-44b2882ae0a2), builtinclass]
 interface nsIFile : nsISupports
 {
     /**
      *  Create Types
      *
      *  NORMAL_FILE_TYPE - A normal file.
      *  DIRECTORY_TYPE   - A directory/folder.
      */
@@ -328,15 +338,155 @@ interface nsIFile : nsISupports
     /**
      *  Returns an enumeration of the elements in a directory. Each
      *  element in the enumeration is an nsIFile.
      *
      *   @return NS_ERROR_FILE_NOT_DIRECTORY if the current nsIFile does
      *           not specify a directory.
      */
     readonly attribute nsISimpleEnumerator directoryEntries;
+
+    /**
+     *  initWith[Native]Path
+     *
+     *  This function will initialize the nsILocalFile object.  Any
+     *  internal state information will be reset.
+     *
+     *   @param filePath       
+     *       A string which specifies a full file path to a 
+     *       location.  Relative paths will be treated as an
+     *       error (NS_ERROR_FILE_UNRECOGNIZED_PATH).  For 
+     *       initWithNativePath, the filePath must be in the native
+     *       filesystem charset.
+     */
+    void initWithPath(in AString filePath);
+    [noscript] void initWithNativePath(in ACString filePath);
+    
+    /**
+     *  initWithFile
+     *
+     *  Initialize this object with another file
+     *
+     *   @param aFile
+     *       the file this becomes equivalent to
+     */
+    void initWithFile(in nsIFile aFile);
+    
+    /**
+     *  followLinks
+     *
+     *  This attribute will determine if the nsLocalFile will auto
+     *  resolve symbolic links.  By default, this value will be false
+     *  on all non unix systems.  On unix, this attribute is effectively
+     *  a noop.  
+     */
+    attribute boolean followLinks;  
+
+    const unsigned long OS_READAHEAD = 0x40000000;
+    const unsigned long DELETE_ON_CLOSE = 0x80000000;
+
+    /**
+     * Return the result of PR_Open on the file.  The caller is
+     * responsible for calling PR_Close on the result.
+     *
+     * @param flags the PR_Open flags from prio.h, plus optionally
+     * OS_READAHEAD or DELETE_ON_CLOSE. OS_READAHEAD is a hint to the
+     * OS that the file will be read sequentially with agressive
+     * readahead. DELETE_ON_CLOSE may be implemented by removing the
+     * file (by path name) immediately after opening it, so beware of
+     * possible races; the file should be exclusively owned by this
+     * process.
+     */
+    [noscript] PRFileDescStar openNSPRFileDesc(in long flags, in long mode);
+
+    /**
+     * Return the result of fopen on the file.  The caller is
+     * responsible for calling fclose on the result.
+     */
+    [noscript] FILE           openANSIFileDesc(in string mode);
+
+    /**
+     * Return the result of PR_LoadLibrary on the file.  The caller is
+     * responsible for calling PR_UnloadLibrary on the result.
+     */
+    [noscript] PRLibraryStar  load();
+
+    // number of bytes available on disk to non-superuser
+    readonly attribute PRInt64 diskSpaceAvailable;
+
+    /**
+     *  appendRelative[Native]Path
+     *
+     *  Append a relative path to the current path of the nsILocalFile object.
+     *
+     *   @param relativeFilePath
+     *       relativeFilePath is a native relative path. For security reasons,
+     *       this cannot contain .. or cannot start with a directory separator.
+     *       For the |appendRelativeNativePath| method, the relativeFilePath 
+     *       must be in the native filesystem charset.
+     */
+    void appendRelativePath(in AString relativeFilePath);
+    [noscript] void appendRelativeNativePath(in ACString relativeFilePath);
+    
+    /**
+     *  Accessor to a null terminated string which will specify
+     *  the file in a persistent manner for disk storage.
+     *
+     *  The character set of this attribute is undefined.  DO NOT TRY TO
+     *  INTERPRET IT AS HUMAN READABLE TEXT!
+     */
+    attribute ACString persistentDescriptor;
+
+    /** 
+     *  reveal
+     *
+     *  Ask the operating system to open the folder which contains
+     *  this file or folder. This routine only works on platforms which 
+     *  support the ability to open a folder and is run async on Windows.  
+     *  This routine must be called on the main. 
+     */
+    void reveal();
+    
+    /** 
+     *  launch
+     *
+     *  Ask the operating system to attempt to open the file. 
+     *  this really just simulates "double clicking" the file on your platform.
+     *  This routine only works on platforms which support this functionality
+     *  and is run async on Windows.  This routine must be called on the 
+     *  main thread. 
+     */
+    void launch();
+    
+    /**
+     *  getRelativeDescriptor
+     *
+     *  Returns a relative file path in an opaque, XP format. It is therefore
+     *  not a native path.
+     *
+     *  The character set of the string returned from this function is
+     *  undefined.  DO NOT TRY TO INTERPRET IT AS HUMAN READABLE TEXT!
+     *
+     *   @param fromFile
+     *       the file from which the descriptor is relative.
+     *       There is no defined result if this param is null.
+     */
+    ACString getRelativeDescriptor(in nsIFile fromFile);
+
+    /**
+     *  setRelativeDescriptor
+     *
+     *  Initializes the file to the location relative to fromFile using
+     *  a string returned by getRelativeDescriptor.
+     *
+     *   @param fromFile
+     *       the file to which the descriptor is relative
+     *   @param relative
+     *       the relative descriptor obtained from getRelativeDescriptor
+     */
+    void setRelativeDescriptor(in nsIFile fromFile, in ACString relativeDesc);    
 };
 
 %{C++
 #ifdef MOZILLA_INTERNAL_API
 #include "nsDirectoryServiceUtils.h"
 #endif
 %}
--- a/xpcom/io/nsILocalFile.idl
+++ b/xpcom/io/nsILocalFile.idl
@@ -35,168 +35,18 @@
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsIFile.idl"
 
-%{C++
-#include "prio.h"
-#include "prlink.h"
-#include <stdio.h>
-%}
-
-[ptr] native PRFileDescStar(PRFileDesc);
-[ptr] native PRLibraryStar(PRLibrary);
-[ptr] native FILE(FILE);
-
 /**
- * This interface adds methods to nsIFile that are particular to a file
- * that is accessible via the local file system.
+ * An empty interface to provide backwards compatibility for existing code.
  *
- * It follows the same string conventions as nsIFile.
+ * @see nsIFile
  */
-[scriptable, uuid(aa610f20-a889-11d3-8c81-000064657374)]
+[scriptable, uuid(ce4ef184-7660-445e-9e59-6731bdc65505)]
 interface nsILocalFile : nsIFile
 {
-    /**
-     *  initWith[Native]Path
-     *
-     *  This function will initialize the nsILocalFile object.  Any
-     *  internal state information will be reset.
-     *
-     *   @param filePath       
-     *       A string which specifies a full file path to a 
-     *       location.  Relative paths will be treated as an
-     *       error (NS_ERROR_FILE_UNRECOGNIZED_PATH).  For 
-     *       initWithNativePath, the filePath must be in the native
-     *       filesystem charset.
-     */
-    void initWithPath(in AString filePath);
-    [noscript] void initWithNativePath(in ACString filePath);
-    
-    /**
-     *  initWithFile
-     *
-     *  Initialize this object with another file
-     *
-     *   @param aFile
-     *       the file this becomes equivalent to
-     */
-    void initWithFile(in nsILocalFile aFile);
-    
-    /**
-     *  followLinks
-     *
-     *  This attribute will determine if the nsLocalFile will auto
-     *  resolve symbolic links.  By default, this value will be false
-     *  on all non unix systems.  On unix, this attribute is effectively
-     *  a noop.  
-     */
-    attribute boolean followLinks;  
-
-    const unsigned long OS_READAHEAD = 0x40000000;
-    const unsigned long DELETE_ON_CLOSE = 0x80000000;
-
-    /**
-     * Return the result of PR_Open on the file.  The caller is
-     * responsible for calling PR_Close on the result.
-     *
-     * @param flags the PR_Open flags from prio.h, plus optionally
-     * OS_READAHEAD or DELETE_ON_CLOSE. OS_READAHEAD is a hint to the
-     * OS that the file will be read sequentially with agressive
-     * readahead. DELETE_ON_CLOSE may be implemented by removing the
-     * file (by path name) immediately after opening it, so beware of
-     * possible races; the file should be exclusively owned by this
-     * process.
-     */
-    [noscript] PRFileDescStar openNSPRFileDesc(in long flags, in long mode);
-
-    /**
-     * Return the result of fopen on the file.  The caller is
-     * responsible for calling fclose on the result.
-     */
-    [noscript] FILE           openANSIFileDesc(in string mode);
-
-    /**
-     * Return the result of PR_LoadLibrary on the file.  The caller is
-     * responsible for calling PR_UnloadLibrary on the result.
-     */
-    [noscript] PRLibraryStar  load();
-
-    // number of bytes available on disk to non-superuser
-    readonly attribute PRInt64 diskSpaceAvailable;
-
-    /**
-     *  appendRelative[Native]Path
-     *
-     *  Append a relative path to the current path of the nsILocalFile object.
-     *
-     *   @param relativeFilePath
-     *       relativeFilePath is a native relative path. For security reasons,
-     *       this cannot contain .. or cannot start with a directory separator.
-     *       For the |appendRelativeNativePath| method, the relativeFilePath 
-     *       must be in the native filesystem charset.
-     */
-    void appendRelativePath(in AString relativeFilePath);
-    [noscript] void appendRelativeNativePath(in ACString relativeFilePath);
-    
-    /**
-     *  Accessor to a null terminated string which will specify
-     *  the file in a persistent manner for disk storage.
-     *
-     *  The character set of this attribute is undefined.  DO NOT TRY TO
-     *  INTERPRET IT AS HUMAN READABLE TEXT!
-     */
-    attribute ACString persistentDescriptor;
-
-    /** 
-     *  reveal
-     *
-     *  Ask the operating system to open the folder which contains
-     *  this file or folder. This routine only works on platforms which 
-     *  support the ability to open a folder and is run async on Windows.  
-     *  This routine must be called on the main. 
-     */
-    void reveal();
-    
-    /** 
-     *  launch
-     *
-     *  Ask the operating system to attempt to open the file. 
-     *  this really just simulates "double clicking" the file on your platform.
-     *  This routine only works on platforms which support this functionality
-     *  and is run async on Windows.  This routine must be called on the 
-     *  main thread. 
-     */
-    void launch();
-    
-    /**
-     *  getRelativeDescriptor
-     *
-     *  Returns a relative file path in an opaque, XP format. It is therefore
-     *  not a native path.
-     *
-     *  The character set of the string returned from this function is
-     *  undefined.  DO NOT TRY TO INTERPRET IT AS HUMAN READABLE TEXT!
-     *
-     *   @param fromFile
-     *       the file from which the descriptor is relative.
-     *       There is no defined result if this param is null.
-     */
-    ACString getRelativeDescriptor(in nsILocalFile fromFile);
-
-    /**
-     *  setRelativeDescriptor
-     *
-     *  Initializes the file to the location relative to fromFile using
-     *  a string returned by getRelativeDescriptor.
-     *
-     *   @param fromFile
-     *       the file to which the descriptor is relative
-     *   @param relative
-     *       the relative descriptor obtained from getRelativeDescriptor
-     */
-    void setRelativeDescriptor(in nsILocalFile fromFile, in ACString relativeDesc);    
 };
 
--- a/xpcom/io/nsLocalFileCommon.cpp
+++ b/xpcom/io/nsLocalFileCommon.cpp
@@ -59,17 +59,17 @@ void NS_StartupLocalFile()
 
 void NS_ShutdownLocalFile()
 {
     nsLocalFile::GlobalShutdown();
 }
 
 #if !defined(MOZ_WIDGET_COCOA) && !defined(XP_WIN)
 NS_IMETHODIMP
-nsLocalFile::InitWithFile(nsILocalFile *aFile)
+nsLocalFile::InitWithFile(nsIFile *aFile)
 {
     NS_ENSURE_ARG(aFile);
     
     nsCAutoString path;
     aFile->GetNativePath(path);
     if (path.IsEmpty())
         return NS_ERROR_INVALID_ARG;
     return InitWithNativePath(path); 
@@ -215,17 +215,17 @@ static PRInt32 SplitPath(PRUnichar *path
         *nodePtr++ = cp;
       }
     }
     return nodePtr - nodeArray;
 }
 
  
 NS_IMETHODIMP
-nsLocalFile::GetRelativeDescriptor(nsILocalFile *fromFile, nsACString& _retval)
+nsLocalFile::GetRelativeDescriptor(nsIFile *fromFile, nsACString& _retval)
 {
     NS_ENSURE_ARG_POINTER(fromFile);
     const PRInt32 kMaxNodesInPath = 32;
 
     //
     // _retval will be UTF-8 encoded
     // 
         
@@ -271,17 +271,17 @@ nsLocalFile::GetRelativeDescriptor(nsILo
       if (nodeIndex + 1 < thisNodeCnt)
         _retval.Append('/');
     }
         
     return NS_OK;
 }
 
 NS_IMETHODIMP
-nsLocalFile::SetRelativeDescriptor(nsILocalFile *fromFile, const nsACString& relativeDesc)
+nsLocalFile::SetRelativeDescriptor(nsIFile *fromFile, const nsACString& relativeDesc)
 {
     NS_NAMED_LITERAL_CSTRING(kParentDirStr, "../");
  
     nsCOMPtr<nsIFile> targetFile;
     nsresult rv = fromFile->Clone(getter_AddRefs(targetFile));
     if (NS_FAILED(rv))
         return rv;
 
@@ -314,11 +314,10 @@ nsLocalFile::SetRelativeDescriptor(nsILo
     while (nodeEnd != strEnd) {
       FindCharInReadable('/', nodeEnd, strEnd);
       targetFile->Append(NS_ConvertUTF8toUTF16(Substring(nodeBegin, nodeEnd)));
       if (nodeEnd != strEnd) // If there's more left in the string, inc over the '/' nodeEnd is on.
         ++nodeEnd;
       nodeBegin = nodeEnd;
     }
 
-    nsCOMPtr<nsILocalFile> targetLocalFile(do_QueryInterface(targetFile));
-    return InitWithFile(targetLocalFile);
+    return InitWithFile(targetFile);
 }
--- a/xpcom/io/nsLocalFileUnix.cpp
+++ b/xpcom/io/nsLocalFileUnix.cpp
@@ -2435,17 +2435,17 @@ nsLocalFile::GetBundleIdentifier(nsACStr
       ::CFRelease(bundle);
     }
     ::CFRelease(urlRef);
   }
 
   return rv;
 }
 
-NS_IMETHODIMP nsLocalFile::InitWithFile(nsILocalFile *aFile)
+NS_IMETHODIMP nsLocalFile::InitWithFile(nsIFile *aFile)
 {
   NS_ENSURE_ARG(aFile);
 
   nsCAutoString nativePath;
   nsresult rv = aFile->GetNativePath(nativePath);
   if (NS_FAILED(rv))
     return rv;
 
--- a/xpcom/io/nsLocalFileWin.cpp
+++ b/xpcom/io/nsLocalFileWin.cpp
@@ -1083,17 +1083,17 @@ nsLocalFile::Clone(nsIFile **file)
       return NS_ERROR_OUT_OF_MEMORY;
 
     NS_ADDREF(*file);
     
     return NS_OK;
 }
 
 NS_IMETHODIMP
-nsLocalFile::InitWithFile(nsILocalFile *aFile)
+nsLocalFile::InitWithFile(nsIFile *aFile)
 {
     NS_ENSURE_ARG(aFile);
     
     nsAutoString path;
     aFile->GetPath(path);
     if (path.IsEmpty())
         return NS_ERROR_INVALID_ARG;
     return InitWithPath(path);