Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

nsIFileProtocolHandler

This interface provides methods to convert between nsIFile and nsIURI. It also provides access to Internet shortcuts stored on the host operating system's file system.
Inherits from: nsIProtocolHandler Last changed in Gecko 1.9.2 (Firefox 3.6 / Thunderbird 3.1 / Fennec 1.0)

Method overview

nsIFile getFileFromURLSpec(in AUTF8String url);
AUTF8String getURLSpecFromActualFile(in nsIFile file);
AUTF8String getURLSpecFromDir(in nsIFile file);
AUTF8String getURLSpecFromFile(in nsIFile file);
nsIURI newFileURI(in nsIFile aFile);
nsIURI readURLFile(in nsIFile file);

Methods

getFileFromURLSpec()

Converts the URL string into the corresponding nsIFile if possible. A local file will be created if the URL string begins with file://.

nsIFile getFileFromURLSpec(
  in AUTF8String url
);
Parameters
url
The url string to convert.
Return value

A reference to a new nsIFile object.

Requires Gecko 1.9.2 (Firefox 3.6 / Thunderbird 3.1 / Fennec 1.0)

getURLSpecFromActualFile()

Converts the nsIFile to the corresponding URL string. Should only be called on files which are not directories. Otherwise identical to getURLSpecFromFile(), but is usually more efficient.

Warning: This restriction may not be enforced at runtime!

AUTF8String getURLSpecFromActualFile(
  in nsIFile file
);
Parameters
file
The nsIFile to convert.
Return value

Corresponding url string. The resulting string may contain URL-escaped characters.

Requires Gecko 1.9.2 (Firefox 3.6 / Thunderbird 3.1 / Fennec 1.0)

getURLSpecFromDir()

Converts the nsIFile to the corresponding URL string. Should only be called on files which are directories. Otherwise identical to getURLSpecFromFile(), but is usually more efficient. WARNING: This restriction may not be enforced at runtime!

AUTF8String getURLSpecFromDir(
  in nsIFile file
);
Parameters
file
The nsIFile to convert.
Return value

Corresponding url string. The resulting string may contain URL-escaped characters.

getURLSpecFromFile()

Converts the nsIFile to the corresponding URL string. If the nsIFile is a local file, then the result will be a file:// URL string. The resulting string may contain URL-escaped characters.

Note: Under some platforms this is a lossy conversion.

Note: Callers should use getURLSpecFromActualFile() if possible, for performance reasons.

AUTF8String getURLSpecFromFile(
  in nsIFile file
);
Parameters
file
The nsIFile to convert.
Return value

Corresponding url string. The resulting string may contain URL-escaped characters.

newFileURI()

This method constructs a new file URI.

nsIURI newFileURI(
  in nsIFile aFile
);
Parameters
aFile
The nsIFile to convert.
Return value

A reference to a new nsIURI object.

Requires Gecko 1.8 (Firefox 1.5 / Thunderbird 1.5 / SeaMonkey 1.0)

readURLFile()

Takes a local file and tries to interpret it as an Internet shortcut (for example .url files on windows).

nsIURI readURLFile(
  in nsIFile file
);
Parameters
file
The nsIFile to read.
Return value

The nsIURI the file refers to.

Exceptions thrown
NS_ERROR_NOT_AVAILABLE
The OS does not support such files.
NS_ERROR_NOT_AVAILABLE
The file is not an Internet shortcut.

See also

Document Tags and Contributors

 Contributors to this page: Sheppy, trevorh, CrazyEyE, Wjjohnst
 Last updated by: Sheppy,