nsIFileProtocolHandler 编辑

netwerk/protocol/file/nsIFileProtocolHandler.idlScriptable 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.

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.

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.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:56 次

字数:8131

最后编辑:7 年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文