Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Component returned failure code: 0x80004002 (NS_NOINTERFACE)

547 views
Skip to first unread message

Georg Maaß

unread,
Mar 16, 2008, 12:46:58 PM3/16/08
to
Hi,

I want to use the download manager in trunk 1.9, but I do something
wrong. I get an exception: NS_NOINTERFACE

Probably one of the arguments of my call to addDownload of the download
manager does not match what is expected, but I do not understand which
is wrong.

I want to use the download manager instead of the nsIDownloader, because
I need a download progress, which seems not to be provided by the
nsIDownloader.


My attempt is this:


// progress listener

var pl =
{
onDownloadStateChange:function(state,download){
dump('onDownloadStateChange'+state);}
, onProgressChange
:function(webProgress,request,curSelfProgres,maxSelfProgress
,curTotalProgres,maxTotalProgress,download){
dump('onProgressChange'+curSelfProgres+' of '+maxSelfProgres)}
, onSecurityChange:
function(webProgress,request,state,download){
dump('onSecurityChange'+state);}
, onStateChange:
function(webProgress,request,stateFlags,status,download){
dump('onStateChange'+state);}
}


// nsIURI
var src
=Components.classes["@mozilla.org/network/simple-uri;1"]
.createInstance(Components.interfaces.nsIURI);
src.spec='http://localhost/mei.zip';

// nsIURI
var dest
=Components.classes["@mozilla.org/network/simple-uri;1"]
.createInstance(Components.interfaces.nsIURI);
dest.spec='file:///Volumes/stick/mei.zip';

// nsICancelable
var cnc = {cancel:function(c){}};


// nsIDownloadManager
var dm =
Components.classes["@mozilla.org/download-manager;1"]
.createInstance(Components.interfaces.nsIDownloadManager);
dm.addListener(pl);

var dl = dm.addDownload(0,src,dest,'test Download', null, new
Date().getTime(),null, cnc);


This is, what I get:

Exception... "Component returned failure code: 0x80004002
(NS_NOINTERFACE) [nsIDownloadManager.addDownload]"


If I use the downloader instead of download manager, download succeeds,
but I don't get any download progress, which might cause impatient users
to abort.

Justin Wood (Callek)

unread,
Mar 16, 2008, 3:18:21 PM3/16/08
to
See: http://developer.mozilla.org/en/docs/nsIDownloadManager

Which has the addDownload method you mentioned, it returns an
nsIDownload: http://developer.mozilla.org/en/docs/nsIDownload

From there you can use the nsIDownloadManager to call addListener using
your own implementation of nsIDownloadProgressListener:
http://developer.mozilla.org/en/docs/nsIDownloadProgressListener

onProgressChange, and onDownloadStateChange are the two you probably
care the most about.

(See Also: http://developer.mozilla.org/en/docs/nsIWebProgressListener
which is used here as well)

--
~Justin Wood (Callek)

Shawn Wilsher

unread,
May 12, 2008, 11:48:00 PM5/12/08
to
On Mar 16, 12:46 pm, Georg Maaß <ge...@bioshop.de> wrote:
> Exception... "Component returned failure code: 0x80004002
> (NS_NOINTERFACE) [nsIDownloadManager.addDownload]"
You get this because you aren't passing an nsIFileURL to the method
for the target file. You can create one by using newFileURI instead
of newURI on the io service.

Cheers,

Shawn Wilsher

Neil

unread,
May 13, 2008, 7:19:14 AM5/13/08
to
Shawn Wilsher wrote:

The explanation is bogus; the original URI wasn't a file URI because the
IO service hadn't been used to create it.

--
Warning: May contain traces of nuts.

Neil

unread,
May 13, 2008, 7:20:06 AM5/13/08
to
Georg Maaß wrote:

> // nsIURI
> var src
> =Components.classes["@mozilla.org/network/simple-uri;1"]
> .createInstance(Components.interfaces.nsIURI);
> src.spec='http://localhost/mei.zip';
>
> // nsIURI
> var dest
> =Components.classes["@mozilla.org/network/simple-uri;1"]
> .createInstance(Components.interfaces.nsIURI);
> dest.spec='file:///Volumes/stick/mei.zip';

Only protocol handlers are allowed to do this. Everyone else MUST use
the IO service to create new URIs.

Boris Zbarsky

unread,
May 13, 2008, 10:11:32 AM5/13/08
to
Neil wrote:
> Only protocol handlers are allowed to do this. Everyone else MUST use
> the IO service to create new URIs.

See also
http://developer.mozilla.org/en/docs/Common_Pitfalls#How_to_create_a_URI_object

-Boris

0 new messages