xpcom/io/nsIFile.idl

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 #include "nsISupports.idl"
     8 %{C++
     9 struct PRFileDesc;
    10 struct PRLibrary;
    11 #include <stdio.h>
    12 %}
    14 [ptr] native PRFileDescStar(PRFileDesc);
    15 [ptr] native PRLibraryStar(PRLibrary);
    16 [ptr] native FILE(FILE);
    18 interface nsISimpleEnumerator;
    20 /**
    21  * An nsIFile is an abstract representation of a filename. It manages
    22  * filename encoding issues, pathname component separators ('/' vs. '\\'
    23  * vs. ':') and weird stuff like differing volumes with identical names, as
    24  * on pre-Darwin Macintoshes.
    25  *
    26  * This file has long introduced itself to new hackers with this opening
    27  * paragraph:
    28  *
    29  *    This is the only correct cross-platform way to specify a file.
    30  *    Strings are not such a way. If you grew up on windows or unix, you
    31  *    may think they are.  Welcome to reality.
    32  *
    33  * While taking the pose struck here to heart would be uncalled for, one
    34  * may safely conclude that writing cross-platform code is an embittering
    35  * experience.
    36  *
    37  * All methods with string parameters have two forms.  The preferred
    38  * form operates on UCS-2 encoded characters strings.  An alternate
    39  * form operates on characters strings encoded in the "native" charset.
    40  *
    41  * A string containing characters encoded in the native charset cannot
    42  * be safely passed to javascript via xpconnect.  Therefore, the "native
    43  * methods" are not scriptable.
    44  */
    45 [scriptable, uuid(a99a6a06-f90d-4659-8fce-c2f87feb1167), builtinclass]
    46 interface nsIFile : nsISupports
    47 {
    48     /**
    49      *  Create Types
    50      *
    51      *  NORMAL_FILE_TYPE - A normal file.
    52      *  DIRECTORY_TYPE   - A directory/folder.
    53      */
    54     const unsigned long NORMAL_FILE_TYPE = 0;
    55     const unsigned long DIRECTORY_TYPE   = 1;
    57     /**
    58      *  append[Native]
    59      *
    60      *  This function is used for constructing a descendent of the
    61      *  current nsIFile.
    62      *
    63      *   @param node
    64      *       A string which is intended to be a child node of the nsIFile.
    65      *       For the |appendNative| method, the node must be in the native
    66      *       filesystem charset.
    67      */
    68     void append(in AString node);
    69     [noscript] void appendNative(in ACString node);
    71     /**
    72      *  Normalize the pathName (e.g. removing .. and . components on Unix).
    73      */
    74     void normalize();
    76     /**
    77      *  create
    78      *
    79      *  This function will create a new file or directory in the
    80      *  file system. Any nodes that have not been created or
    81      *  resolved, will be.  If the file or directory already
    82      *  exists create() will return NS_ERROR_FILE_ALREADY_EXISTS.
    83      *
    84      *   @param type
    85      *       This specifies the type of file system object
    86      *       to be made.  The only two types at this time
    87      *       are file and directory which are defined above.
    88      *       If the type is unrecongnized, we will return an
    89      *       error (NS_ERROR_FILE_UNKNOWN_TYPE).
    90      *
    91      *   @param permissions
    92      *       The unix style octal permissions.  This may
    93      *       be ignored on systems that do not need to do
    94      *       permissions.
    95      */
    96     void create(in unsigned long type, in unsigned long permissions);
    98     /**
    99      *  Accessor to the leaf name of the file itself.      
   100      *  For the |nativeLeafName| method, the nativeLeafName must 
   101      *  be in the native filesystem charset.
   102      */
   103     attribute AString leafName;
   104     [noscript] attribute ACString nativeLeafName;
   106     /**
   107      *  copyTo[Native]
   108      *
   109      *  This will copy this file to the specified newParentDir.
   110      *  If a newName is specified, the file will be renamed.
   111      *  If 'this' is not created we will return an error
   112      *  (NS_ERROR_FILE_TARGET_DOES_NOT_EXIST).
   113      *
   114      *  copyTo may fail if the file already exists in the destination 
   115      *  directory.
   116      *
   117      *  copyTo will NOT resolve aliases/shortcuts during the copy.
   118      *
   119      *   @param newParentDir
   120      *       This param is the destination directory. If the
   121      *       newParentDir is null, copyTo() will use the parent
   122      *       directory of this file. If the newParentDir is not
   123      *       empty and is not a directory, an error will be
   124      *       returned (NS_ERROR_FILE_DESTINATION_NOT_DIR). For the 
   125      *       |CopyToNative| method, the newName must be in the 
   126      *       native filesystem charset.
   127      *
   128      *   @param newName
   129      *       This param allows you to specify a new name for
   130      *       the file to be copied. This param may be empty, in
   131      *       which case the current leaf name will be used.
   132      */
   133     void copyTo(in nsIFile newParentDir, in AString newName);
   134     [noscript] void CopyToNative(in nsIFile newParentDir, in ACString newName);
   136     /**
   137      *  copyToFollowingLinks[Native]
   138      *
   139      *  This function is identical to copyTo with the exception that,
   140      *  as the name implies, it follows symbolic links.  The XP_UNIX
   141      *  implementation always follow symbolic links when copying.  For 
   142      *  the |CopyToFollowingLinks| method, the newName must be in the 
   143      *  native filesystem charset.
   144      */
   145     void copyToFollowingLinks(in nsIFile newParentDir, in AString newName);
   146     [noscript] void copyToFollowingLinksNative(in nsIFile newParentDir, in ACString newName);
   148     /**
   149      *  moveTo[Native]
   150      *
   151      *  A method to move this file or directory to newParentDir.
   152      *  If a newName is specified, the file or directory will be renamed.
   153      *  If 'this' is not created we will return an error
   154      *  (NS_ERROR_FILE_TARGET_DOES_NOT_EXIST).
   155      *  If 'this' is a file, and the destination file already exists, moveTo
   156      *  will replace the old file.
   157      *  This object is updated to refer to the new file.
   158      *
   159      *  moveTo will NOT resolve aliases/shortcuts during the copy.
   160      *  moveTo will do the right thing and allow copies across volumes.
   161      *  moveTo will return an error (NS_ERROR_FILE_DIR_NOT_EMPTY) if 'this' is
   162      *  a directory and the destination directory is not empty.
   163      *  moveTo will return an error (NS_ERROR_FILE_ACCESS_DENIED) if 'this' is
   164      *  a directory and the destination directory is not writable.
   165      *
   166      *   @param newParentDir
   167      *       This param is the destination directory. If the
   168      *       newParentDir is empty, moveTo() will rename the file
   169      *       within its current directory. If the newParentDir is
   170      *       not empty and does not name a directory, an error will
   171      *       be returned (NS_ERROR_FILE_DESTINATION_NOT_DIR).  For 
   172      *       the |moveToNative| method, the newName must be in the 
   173      *       native filesystem charset.
   174      *
   175      *   @param newName
   176      *       This param allows you to specify a new name for
   177      *       the file to be moved. This param may be empty, in
   178      *       which case the current leaf name will be used.
   179      */
   180     void moveTo(in nsIFile newParentDir, in AString newName);
   181     [noscript] void moveToNative(in nsIFile newParentDir, in ACString newName);
   183     /**
   184      *  renameTo
   185      *
   186      *  This method is identical to moveTo except that if this file or directory
   187      *  is moved to a a different volume, it fails and returns an error
   188      *  (NS_ERROR_FILE_ACCESS_DENIED).
   189      *  This object will still point to the old location after renaming.
   190      */
   191     void renameTo(in nsIFile newParentDir, in AString newName);
   193     /**
   194      *  This will try to delete this file.  The 'recursive' flag
   195      *  must be PR_TRUE to delete directories which are not empty.
   196      *
   197      *  This will not resolve any symlinks.
   198      */
   199     void remove(in boolean recursive);
   201     /**
   202      *  Attributes of nsIFile.
   203      */
   205     attribute unsigned long permissions;
   206     attribute unsigned long permissionsOfLink;
   208     /**
   209      *  File Times are to be in milliseconds from
   210      *  midnight (00:00:00), January 1, 1970 Greenwich Mean
   211      *  Time (GMT).
   212      */
   213     attribute PRTime lastModifiedTime;
   214     attribute PRTime lastModifiedTimeOfLink;
   216     /**
   217      *  WARNING!  On the Mac, getting/setting the file size with nsIFile
   218      *  only deals with the size of the data fork.  If you need to
   219      *  know the size of the combined data and resource forks use the
   220      *  GetFileSizeWithResFork() method defined on nsILocalFileMac.
   221      */
   222     attribute int64_t fileSize;
   223     readonly attribute int64_t fileSizeOfLink;
   225     /**
   226      *  target & path
   227      *
   228      *  Accessor to the string path.  The native version of these
   229      *  strings are not guaranteed to be a usable path to pass to
   230      *  NSPR or the C stdlib.  There are problems that affect
   231      *  platforms on which a path does not fully specify a file
   232      *  because two volumes can have the same name (e.g., mac).
   233      *  This is solved by holding "private", native data in the
   234      *  nsIFile implementation.  This native data is lost when
   235      *  you convert to a string.
   236      *
   237      *      DO NOT PASS TO USE WITH NSPR OR STDLIB!
   238      *
   239      *  target
   240      *      Find out what the symlink points at.  Will give error
   241      *      (NS_ERROR_FILE_INVALID_PATH) if not a symlink.
   242      *
   243      *  path
   244      *      Find out what the nsIFile points at.
   245      *
   246      *  Note that the ACString attributes are returned in the 
   247      *  native filesystem charset.
   248      *
   249      */
   250     readonly attribute AString target;
   251     [noscript] readonly attribute ACString nativeTarget;
   252     readonly attribute AString path;
   253     [noscript] readonly attribute ACString nativePath;
   255     boolean exists();
   256     boolean isWritable();
   257     boolean isReadable();
   258     boolean isExecutable();
   259     boolean isHidden();
   260     boolean isDirectory();
   261     boolean isFile();
   262     boolean isSymlink();
   263     /**
   264      * Not a regular file, not a directory, not a symlink.
   265      */
   266     boolean isSpecial();
   268     /**
   269      *  createUnique
   270      *  
   271      *  This function will create a new file or directory in the
   272      *  file system. Any nodes that have not been created or
   273      *  resolved, will be.  If this file already exists, we try
   274      *  variations on the leaf name "suggestedName" until we find
   275      *  one that did not already exist.
   276      *
   277      *  If the search for nonexistent files takes too long
   278      *  (thousands of the variants already exist), we give up and
   279      *  return NS_ERROR_FILE_TOO_BIG.
   280      *
   281      *   @param type
   282      *       This specifies the type of file system object
   283      *       to be made.  The only two types at this time
   284      *       are file and directory which are defined above.
   285      *       If the type is unrecongnized, we will return an
   286      *       error (NS_ERROR_FILE_UNKNOWN_TYPE).
   287      *
   288      *   @param permissions
   289      *       The unix style octal permissions.  This may
   290      *       be ignored on systems that do not need to do
   291      *       permissions.
   292      */
   293     void createUnique(in unsigned long type, in unsigned long permissions);
   295     /**
   296       * clone()
   297       *
   298       * This function will allocate and initialize a nsIFile object to the
   299       * exact location of the |this| nsIFile.
   300       *
   301       *   @param file
   302       *          A nsIFile which this object will be initialize
   303       *          with.
   304       *
   305       */
   306     nsIFile clone();
   308     /**
   309      *  Will determine if the inFile equals this.
   310      */
   311     boolean equals(in nsIFile inFile);
   313     /**
   314      *  Will determine if inFile is a descendant of this file
   315      *  If |recur| is true, look in subdirectories too
   316      */
   317     boolean contains(in nsIFile inFile, in boolean recur);
   319     /**
   320      *  Parent will be null when this is at the top of the volume.
   321      */
   322     readonly attribute nsIFile parent;
   324     /**
   325      *  Returns an enumeration of the elements in a directory. Each
   326      *  element in the enumeration is an nsIFile.
   327      *
   328      *   @throws NS_ERROR_FILE_NOT_DIRECTORY if the current nsIFile does
   329      *           not specify a directory.
   330      */
   331     readonly attribute nsISimpleEnumerator directoryEntries;
   333     /**
   334      *  initWith[Native]Path
   335      *
   336      *  This function will initialize the nsIFile object.  Any
   337      *  internal state information will be reset.
   338      *
   339      *   @param filePath       
   340      *       A string which specifies a full file path to a 
   341      *       location.  Relative paths will be treated as an
   342      *       error (NS_ERROR_FILE_UNRECOGNIZED_PATH).  For 
   343      *       initWithNativePath, the filePath must be in the native
   344      *       filesystem charset.
   345      */
   346     void initWithPath(in AString filePath);
   347     [noscript] void initWithNativePath(in ACString filePath);
   349     /**
   350      *  initWithFile
   351      *
   352      *  Initialize this object with another file
   353      *
   354      *   @param aFile
   355      *       the file this becomes equivalent to
   356      */
   357     void initWithFile(in nsIFile aFile);
   359     /**
   360      *  followLinks
   361      *
   362      *  This attribute will determine if the nsLocalFile will auto
   363      *  resolve symbolic links.  By default, this value will be false
   364      *  on all non unix systems.  On unix, this attribute is effectively
   365      *  a noop.  
   366      */
   367     attribute boolean followLinks;  
   369     /**
   370      * Flag for openNSPRFileDesc(), to hint to the OS that the file will be
   371      * read sequentially with agressive readahead.
   372      */
   373     const unsigned long OS_READAHEAD = 0x40000000;
   375     /**
   376      * Flag for openNSPRFileDesc(). Deprecated and unreliable!
   377      * Instead use NS_OpenAnonymousTemporaryFile() to create a temporary
   378      * file which will be deleted upon close!
   379      */
   380     const unsigned long DELETE_ON_CLOSE = 0x80000000;
   382     /**
   383      * Return the result of PR_Open on the file.  The caller is
   384      * responsible for calling PR_Close on the result.
   385      *
   386      * @param flags the PR_Open flags from prio.h, plus optionally
   387      * OS_READAHEAD or DELETE_ON_CLOSE. OS_READAHEAD is a hint to the
   388      * OS that the file will be read sequentially with agressive
   389      * readahead. DELETE_ON_CLOSE is unreliable on Windows and is deprecated.
   390      * Instead use NS_OpenAnonymousTemporaryFile() to create a temporary
   391      * file which will be deleted upon close.
   392      */
   393     [noscript] PRFileDescStar openNSPRFileDesc(in long flags, in long mode);
   395     /**
   396      * Return the result of fopen on the file.  The caller is
   397      * responsible for calling fclose on the result.
   398      */
   399     [noscript] FILE           openANSIFileDesc(in string mode);
   401     /**
   402      * Return the result of PR_LoadLibrary on the file.  The caller is
   403      * responsible for calling PR_UnloadLibrary on the result.
   404      */
   405     [noscript] PRLibraryStar  load();
   407     // number of bytes available on disk to non-superuser
   408     readonly attribute int64_t diskSpaceAvailable;
   410     /**
   411      *  appendRelative[Native]Path
   412      *
   413      *  Append a relative path to the current path of the nsIFile object.
   414      *
   415      *   @param relativeFilePath
   416      *       relativeFilePath is a native relative path. For security reasons,
   417      *       this cannot contain .. or cannot start with a directory separator.
   418      *       For the |appendRelativeNativePath| method, the relativeFilePath 
   419      *       must be in the native filesystem charset.
   420      */
   421     void appendRelativePath(in AString relativeFilePath);
   422     [noscript] void appendRelativeNativePath(in ACString relativeFilePath);
   424     /**
   425      *  Accessor to a null terminated string which will specify
   426      *  the file in a persistent manner for disk storage.
   427      *
   428      *  The character set of this attribute is undefined.  DO NOT TRY TO
   429      *  INTERPRET IT AS HUMAN READABLE TEXT!
   430      */
   431     attribute ACString persistentDescriptor;
   433     /** 
   434      *  reveal
   435      *
   436      *  Ask the operating system to open the folder which contains
   437      *  this file or folder. This routine only works on platforms which 
   438      *  support the ability to open a folder and is run async on Windows.  
   439      *  This routine must be called on the main. 
   440      */
   441     void reveal();
   443     /** 
   444      *  launch
   445      *
   446      *  Ask the operating system to attempt to open the file. 
   447      *  this really just simulates "double clicking" the file on your platform.
   448      *  This routine only works on platforms which support this functionality
   449      *  and is run async on Windows.  This routine must be called on the 
   450      *  main thread. 
   451      */
   452     void launch();
   454     /**
   455      *  getRelativeDescriptor
   456      *
   457      *  Returns a relative file path in an opaque, XP format. It is therefore
   458      *  not a native path.
   459      *
   460      *  The character set of the string returned from this function is
   461      *  undefined.  DO NOT TRY TO INTERPRET IT AS HUMAN READABLE TEXT!
   462      *
   463      *   @param fromFile
   464      *       the file from which the descriptor is relative.
   465      *       There is no defined result if this param is null.
   466      */
   467     ACString getRelativeDescriptor(in nsIFile fromFile);
   469     /**
   470      *  setRelativeDescriptor
   471      *
   472      *  Initializes the file to the location relative to fromFile using
   473      *  a string returned by getRelativeDescriptor.
   474      *
   475      *   @param fromFile
   476      *       the file to which the descriptor is relative
   477      *   @param relative
   478      *       the relative descriptor obtained from getRelativeDescriptor
   479      */
   480     void setRelativeDescriptor(in nsIFile fromFile, in ACString relativeDesc);    
   481 };
   483 %{C++
   484 #ifdef MOZILLA_INTERNAL_API
   485 #include "nsDirectoryServiceUtils.h"
   486 #endif
   487 %}

mercurial