Copying my response to the newsgroup...

-Darin


Darin Fisher wrote:

Mike Thompson wrote:

Hi, I'm in the same boat. I have a Firefox extension that allows a user

to


right-click on an image and send the image to an external application
(paint, etc). Thing is, I can't figure out how to extract the image out

of


the cache. Ideally, I want the extension to just send the original URL

and


have my win32 app extract the image from the cache itself. Barring that,

if


I could somehow extract the image myself (in firefox) and pass the local
path to the win32 app, it would work nicely too. I hope I explained this
clearly.


Any ideas?

Thanks,
Mike.

Perhaps you should use nsIDownloader. It gives you a nsIFile
referencing the downloaded file. If the file lives in the cache, then
you will get a pointer to the file in the cache (no extra work). If the
file is in the cache, but not stored as a separate file (i.e., as a
sequence of blocks in one of the _CACHE_00X_ files), then nsIDownloader
will copy the file out of the cache and give you a reference to a
temporary file on disk. Otherwise, it will go ahead and download the
file to a temporary location and give you a reference to that file.


You use it in conjunction with nsIChannel.  nsIDownloader is actually
just a subclass of nsIStreamListener, so once you configure your
nsIDownloader instance, you can pass it to nsIChannel::asyncOpen.
You'll want to configure a nsIChannel for your URL just as you would if
you were loading the URL normally.



http://lxr.mozilla.org/mozilla/source/netwerk/base/public/nsIDownloader.idl




See nsJARChannel.cpp for an example of nsIDownloader being used
internally by Mozilla.

-Darin


Thanks for the quick reply.

I looked at the idl, and it seems to be what I need.  However, I have no
idea how to actually *call* the function from outside of Firefox.

I see "[scriptable, uuid(44b3153e-a54e-4077-a527-b0325e40924e)]" but
honestly, I'm not sure what that tells me. I'm a straight "C" guy, and
recently have been doing .NET develpment.. In other words, I have no idea
what I'm looking at here. Can I call it from a DLL? ActiveX?


I looked all over Mozilla's site, but no dice. I just need to know how to
actually put this to work. C++ is no good, since I'll be ultimately calling
this function from VB.


Thanks,
Mike.





Inside your Firefox extensions, you can do the following:

(NOTE: I haven't verified that this code works, but it should modulo typos.)


// NOTE: nsIDownloader and nsIDownloadObserver are not frozen interfaces, // so we query them by UUID. const nsIDownloader = Components.interfacesByID["{fafe41a9-a531-4d6d-89bc-588a6522fb4e}"]; const nsIDownloadObserver = Components.interfacesByID["{44b3153e-a54e-4077-a527-b0325e40924e}"];

const nsISupports = Components.interfaces.nsISupports;
const nsIIOService = Components.interfaces.nsIIOService;

function MyDownloadObserver() {}

MyDownloadObserver.prototype.QueryInterface =
function(iid)
{
 if (!iid.equals(nsIDownloadObserver) &&
     !iid.equals(nsISupports))
   throw Components.results.NS_ERROR_NO_INTERFACE;

 return this;
}

MyDownloadObserver.prototype.onDownloadComplete =
function(downloader, request, ctxt, status, file)
{
 // ok, the resource is available at |file.path|, and i can use it
 // so long as i keep a reference to |downloader|.

 doStuff(file.path);
}

var ios = Components.classes["@mozilla.org/network/io-service;1"]
                   .getService(nsIIOService);
var channel = ios.newChannel("http://blah/blah";, null, null);

var downloader = Components.classes["@mozilla.org/network/downloader;1"]
                          .createInstance(nsIDownloader);

downloader.init(new MyDownloadObserver(), null);

channel.asyncOpen(downloader, null);


_______________________________________________ Mozilla-netlib mailing list [EMAIL PROTECTED] http://mail.mozilla.org/listinfo/mozilla-netlib

Reply via email to