Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function addDownload(from, to, title)
- {
- var dm = Components.classes["@mozilla.org/download-manager;1"].getService(Components.interfaces.nsIDownloadManager);
- var ioService = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
- var uri = ioService.newURI(from, null , null);
- var url = uri.QueryInterface(Components.interfaces.nsIURL);
- var file = Components.classes['@mozilla.org/file/local;1'].createInstance(Components.interfaces.nsILocalFile);
- file.initWithPath(to);
- var fileURI = ioService.newFileURI(file);
- var nsIWBP = Components.interfaces.nsIWebBrowserPersist;
- var persist = Components.classes['@mozilla.org/embedding/browser/nsWebBrowserPersist;1'].createInstance(Components.interfaces.nsIWebBrowserPersist);
- var flags = nsIWBP.PERSIST_FLAGS_NO_CONVERSION |
- nsIWBP.PERSIST_FLAGS_REPLACE_EXISTING_FILES |
- nsIWBP.PERSIST_FLAGS_BYPASS_CACHE;
- persist.persistFlags = flags;
- var download = dm.addDownload ( 0 , uri , fileURI , title || from, null , null , null , null, persist );
- persist.progressListener = download;
- persist.saveURI(uri, null, null, null, "", fileURI);
- }
- function addDownload(from, to, title)
- {
- var tr = Components.classes["@mozilla.org/transfer;1"].createInstance(Components.interfaces.nsITransfer);
- var ioService = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
- var uri = ioService.newURI(from, null , null);
- var url = uri.QueryInterface(Components.interfaces.nsIURL);
- var file = Components.classes['@mozilla.org/file/local;1'].createInstance(Components.interfaces.nsILocalFile);
- file.initWithPath(to);
- var fileURI = ioService.newFileURI(file);
- var nsIWBP = Components.interfaces.nsIWebBrowserPersist;
- var persist = Components.classes['@mozilla.org/embedding/browser/nsWebBrowserPersist;1'].createInstance(Components.interfaces.nsIWebBrowserPersist);
- var flags = nsIWBP.PERSIST_FLAGS_NO_CONVERSION |
- nsIWBP.PERSIST_FLAGS_REPLACE_EXISTING_FILES |
- nsIWBP.PERSIST_FLAGS_BYPASS_CACHE;
- persist.persistFlags = flags;
- tr.init(uri , fileURI , title || from, null , null , null , null )
- persist.progressListener = tr;
- persist.saveURI(uri, null, null, null, "", fileURI);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement