【发布时间】:2013-05-26 06:27:12
【问题描述】:
这是我正在使用 addon-builder [builder.addons.mozilla.org/] 开发的第一个 Firefox 扩展。
我的问题很简单,但是尝试了很多东西,很多天,我都无法得到结果。
我想知道:如何将文件下载添加到 Firefox 下载器??
我有一个类似的网址:http://example.com/file.zip 和一个类似的文件位置:D:\myFolder。 我想通过我的 Firefox 扩展添加这个下载。
我搜索过的东西是:
https://developer.mozilla.org/en-US/docs/Code_snippets/Downloading_Files
Components.utils.import("resource://gre/modules/PrivateBrowsingUtils.jsm");
const WebBrowserPersist = Components.Constructor("@mozilla.org/embedding/browser/nsWebBrowserPersist;1",
"nsIWebBrowserPersist");
var persist = WebBrowserPersist();
var targetFile = Services.dirsvc.get("Desk", Ci.nsIFile);
targetFile.append("file.bin");
// Obtain the privacy context of the browser window that the URL
// we are downloading comes from. If, and only if, the URL is not
// related to a window, null should be used instead.
var privacy = PrivateBrowsingUtils.privacyContextFromWindow(urlSourceWindow);
persist.persistFlags = persist.PERSIST_FLAGS_FROM_CACHE
| persist.PERSIST_FLAGS_REPLACE_EXISTING_FILES;
persist.saveURI(uriToSave, null, null, null, "", targetFile, privacy);
你能从我应该获得最简单的下载功能的地方开始吗?
【问题讨论】:
标签: firefox firefox-addon download