nsINetService *inet = 0; rv = nsServiceManager::GetService( kNetServiceCID, kINetServiceIID, (nsISupports**)&inet ); if (NS_OK == rv) { rv = inet->OpenStream(mUrl, this); nsServiceManager::ReleaseService(kNetServiceCID, inet); } else { if ( APP_DEBUG ) { printf( "Error getting Net Service, rv=0x%X\n", (int)rv ); } }
nsFileDownloadDialog::ConstructBeforeJavaScript(nsIWebShell *aWebShell) {    nsresult rv = NS_OK;    // Save web shell pointer.    mWebShell = nsDontQueryInterface<nsIWebShell>( aWebShell );    // Store instance information into dialog's DOM.    const char *loc = 0;    mUrl->GetSpec( &loc );    setAttribute( mWebShell, "data.location", "value", loc );    setAttribute( mWebShell, "data.contentType", "value", mContentType );    // If showing download progress, make target file name known.    if ( mMode == kProgress ) {        setAttribute( mWebShell, "data.fileName", "value", nsString((const char*)mFileName) );        // Load source stream into file.        nsINetService *inet = 0;        rv = nsServiceManager::GetService( kNetServiceCID,                                           kINetServiceIID,                                           (nsISupports**)&inet );        if (NS_OK == rv) {          rv = inet->OpenStream(mUrl, this);          nsServiceManager::ReleaseService(kNetServiceCID, inet);        } else {            if ( APP_DEBUG ) { printf( "Error getting Net Service, rv=0x%X\n", (int)rv ); }        }    }    // Add as observer of the xul document.    nsCOMPtr<nsIContentViewer> cv;    rv = mWebShell->GetContentViewer(getter_AddRefs(cv));    if ( cv ) {        // Up-cast.        nsCOMPtr<nsIDocumentViewer> docv(do_QueryInterface(cv));        if ( docv ) {            // Get the document from the doc viewer.            nsCOMPtr<nsIDocument> doc;            rv = docv->GetDocument(*getter_AddRefs(doc));            if ( doc ) {                doc->AddObserver( this );            } else {                if (APP_DEBUG) printf("GetDocument failed, rv=0x%X\n",(int)rv);            }        } else {            if (APP_DEBUG) printf("Upcast to nsIDocumentViewer failed\n");        }    } else {        if (APP_DEBUG) printf("GetContentViewer failed, rv=0x%X\n",(int)rv);    }    return rv;}