1
这是我使用addon-builder [builder.addons.mozilla.org/]开发的第一个Firefox扩展。通过Firefox扩展下载到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);
你能只给我从那里我应该得到最简便的下载功能是一个开始。