SHARE
TWEET

Untitled

a guest Oct 25th, 2009 959 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function addDownload(from, to, title)
  2. {
  3.    var dm    = Components.classes["@mozilla.org/download-manager;1"].getService(Components.interfaces.nsIDownloadManager);
  4.  
  5.    var ioService  = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
  6.    var uri = ioService.newURI(from, null , null);
  7.    var url = uri.QueryInterface(Components.interfaces.nsIURL);
  8.  
  9.    var file = Components.classes['@mozilla.org/file/local;1'].createInstance(Components.interfaces.nsILocalFile);
  10.    file.initWithPath(to);
  11.    var fileURI = ioService.newFileURI(file);
  12.  
  13.    var nsIWBP = Components.interfaces.nsIWebBrowserPersist;
  14.    var persist = Components.classes['@mozilla.org/embedding/browser/nsWebBrowserPersist;1'].createInstance(Components.interfaces.nsIWebBrowserPersist);
  15.    var flags = nsIWBP.PERSIST_FLAGS_NO_CONVERSION |
  16.            nsIWBP.PERSIST_FLAGS_REPLACE_EXISTING_FILES |
  17.            nsIWBP.PERSIST_FLAGS_BYPASS_CACHE;
  18.          
  19.    persist.persistFlags = flags;
  20.  
  21.    
  22.    var download = dm.addDownload ( 0 , uri , fileURI , title || from, null , null , null , null, persist );
  23.    persist.progressListener = download;
  24.    persist.saveURI(uri, null, null, null, "", fileURI);
  25. }
  26.  
  27. function addDownload(from, to, title)
  28. {
  29.    var tr = Components.classes["@mozilla.org/transfer;1"].createInstance(Components.interfaces.nsITransfer);
  30.  
  31.    var ioService  = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
  32.    var uri = ioService.newURI(from, null , null);
  33.    var url = uri.QueryInterface(Components.interfaces.nsIURL);
  34.  
  35.    var file = Components.classes['@mozilla.org/file/local;1'].createInstance(Components.interfaces.nsILocalFile);
  36.    file.initWithPath(to);
  37.    var fileURI = ioService.newFileURI(file);
  38.  
  39.    var nsIWBP = Components.interfaces.nsIWebBrowserPersist;
  40.    var persist = Components.classes['@mozilla.org/embedding/browser/nsWebBrowserPersist;1'].createInstance(Components.interfaces.nsIWebBrowserPersist);
  41.    var flags = nsIWBP.PERSIST_FLAGS_NO_CONVERSION |
  42.         nsIWBP.PERSIST_FLAGS_REPLACE_EXISTING_FILES |
  43.         nsIWBP.PERSIST_FLAGS_BYPASS_CACHE;
  44.              
  45.    persist.persistFlags = flags;
  46.    
  47.    tr.init(uri , fileURI , title || from, null , null , null , null )
  48.    persist.progressListener = tr;
  49.    persist.saveURI(uri, null, null, null, "", fileURI);
  50.  
  51. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top