extern "C" void RunChromeInstallOnThread(void *data) { nsresult rv;  NS_ASSERTION(data, "No nsInstallInfo passed to Chrome Install"); nsInstallInfo *info = (nsInstallInfo*)data; nsIXPIListener* listener = info->GetListener();  if (listener) listener->OnInstallStart(info->GetURL());   nsIXULChromeRegistry* reg = info->GetChromeRegistry(); #ifndef MOZ_XUL_APP nsCOMPtr<nsIChromeRegistrySea> cr = do_QueryInterface(reg); #endif if (reg) {  nsCString spec; spec.SetCapacity(200); spec = "jar:";  nsCAutoString localURL; rv = NS_GetURLSpecFromFile(info->GetFile(), localURL); if (NS_SUCCEEDED(rv)) { spec.Append(localURL); spec.Append("!/"); }   if (NS_SUCCEEDED(rv)) { PRBool isSkin    = (info->GetType() & CHROME_SKIN); PRBool isLocale  = (info->GetType() & CHROME_LOCALE); PRBool isContent = (info->GetType() & CHROME_CONTENT); PRBool selected  = (info->GetFlags() != 0);  if ( isContent ) { rv = reg->InstallPackage(spec.get(), PR_TRUE); }  if ( isSkin ) { PRBool installed = PR_FALSE;    static NS_DEFINE_IID(kIZipReaderIID, NS_IZIPREADER_IID); static NS_DEFINE_IID(kZipReaderCID,  NS_ZIPREADER_CID); nsresult rv; nsCOMPtr<nsIZipReader> hZip = do_CreateInstance(kZipReaderCID, &rv); if (hZip) rv = hZip->Init(info->GetFile()); if (NS_SUCCEEDED(rv)) { hZip->Open();  nsIExtensionManager* em = info->GetExtensionManager(); rv = hZip->Test("install.rdf"); if (NS_SUCCEEDED(rv) && em) { rv = em->InstallTheme(info->GetFile(), nsIExtensionManager::FLAG_INSTALL_PROFILE); if (NS_SUCCEEDED(rv)) installed = PR_TRUE; }  hZip->Close();   info->GetFile()->Remove(PR_FALSE); }      if (!installed) rv = reg->InstallSkin(spec.get(), PR_TRUE, PR_FALSE);  #ifndef MOZ_XUL_APP if (NS_SUCCEEDED(rv) && selected) { NS_ConvertUCS2toUTF8 utf8Args(info->GetArguments()); rv = reg->SelectSkin(utf8Args, PR_TRUE); } #endif }  if ( isLocale ) { rv = reg->InstallLocale(spec.get(), PR_TRUE);  #ifndef MOZ_XUL_APP if (NS_SUCCEEDED(rv) && selected) { NS_ConvertUCS2toUTF8 utf8Args(info->GetArguments()); rv = cr->SelectLocale(utf8Args, PR_TRUE); } #endif }   if ( isSkin && selected ) reg->RefreshSkins();  #ifdef RELOAD_CHROME_WORKS  if ( isContent || (isLocale && selected) ) reg->ReloadChrome(); #endif } }  if (listener) listener->OnInstallDone(info->GetURL(), nsInstall::SUCCESS);  delete info; }
extern "C" void RunInstallOnThread(void *data){    nsInstallInfo *installInfo = (nsInstallInfo*)data;    char        *scriptBuffer = nsnull;    PRUint32    scriptLength;    JSRuntime   *rt;    JSContext   *cx;    JSObject    *glob;    static NS_DEFINE_IID(kZipReaderCID,  NS_ZIPREADER_CID);    nsresult rv;    nsCOMPtr<nsIZipReader> hZip = do_CreateInstance(kZipReaderCID, &rv);    if (NS_FAILED(rv))        return;    // we will plan on sending a failure status back from here unless we    // find positive acknowledgement that the script sent the status    PRInt32     finalStatus;    nsCOMPtr<nsIXPIListener> listener;    // lets set up an eventQ so that our xpcom/proxies will not have to:    nsCOMPtr<nsIEventQueue> eventQ;    nsCOMPtr<nsIEventQueueService> eventQService =             do_GetService(kEventQueueServiceCID, &rv);    if (NS_SUCCEEDED(rv))    {        eventQService->CreateMonitoredThreadEventQueue();        eventQService->GetThreadEventQueue(NS_CURRENT_THREAD, getter_AddRefs(eventQ));    }    nsCOMPtr<nsISoftwareUpdate> softwareUpdate =             do_GetService(kSoftwareUpdateCID, &rv);    if (NS_FAILED(rv))    {        NS_WARNING("shouldn't have RunInstall() if we can't get SoftwareUpdate");        return;    }    softwareUpdate->SetActiveListener( installInfo->GetListener() );    softwareUpdate->GetMasterListener(getter_AddRefs(listener));    if(listener)        listener->OnInstallStart( installInfo->GetURL() );    nsCOMPtr<nsIFile> jarpath = installInfo->GetFile();    if (NS_SUCCEEDED(rv))    {        PRBool installed = PR_FALSE;        finalStatus = CanInstallFromExtensionManifest( hZip,                                                       jarpath,                                                       installInfo->mPrincipal);        if (NS_SUCCEEDED(finalStatus))         {            nsIExtensionManager* em = installInfo->GetExtensionManager();            if (em)             {                rv = em->InstallExtension(jarpath, nsIExtensionManager::FLAG_INSTALL_PROFILE);                if (NS_SUCCEEDED(rv))                    installed = PR_TRUE;            }        }                if (!installed)        {            finalStatus = GetInstallScriptFromJarfile( hZip,                                                       jarpath,                                                       installInfo->mPrincipal,                                                       &scriptBuffer,                                                       &scriptLength);            if ( finalStatus == NS_OK && scriptBuffer )            {                PRBool ownRuntime = PR_FALSE;                nsCOMPtr<nsIJSRuntimeService> rtsvc =                        do_GetService("@mozilla.org/js/xpc/RuntimeService;1", &rv);                if(NS_FAILED(rv) || NS_FAILED(rtsvc->GetRuntime(&rt)))                {                    // service not available (wizard context?)                    // create our own runtime                    ownRuntime = PR_TRUE;                    rt = JS_Init(4L * 1024L * 1024L);                }                rv = SetupInstallContext( hZip, jarpath,                                          installInfo->GetURL(),                                          installInfo->GetArguments(),                                          installInfo->GetFlags(),                                          installInfo->GetChromeRegistry(),                                          rt, &cx, &glob);                if (NS_SUCCEEDED(rv))                {                    // Go ahead and run!!                    jsval rval;                    jsval installedFiles;                    JS_BeginRequest(cx); //Increment JS thread counter associated                                        //with this context                    PRBool ok = JS_EvaluateScript(  cx,                                                    glob,                                                    scriptBuffer,                                                    scriptLength,                                                    nsnull,                                                    0,                                                    &rval);                    if(!ok)                    {                        // problem compiling or running script -- a true SCRIPT_ERROR                        if(JS_GetProperty(cx, glob, "_installedFiles", &installedFiles) &&                          JSVAL_TO_BOOLEAN(installedFiles))                        {                            nsInstall *a = (nsInstall*)JS_GetPrivate(cx, glob);                            a->InternalAbort(nsInstall::SCRIPT_ERROR);                        }                        finalStatus = nsInstall::SCRIPT_ERROR;                    }                    else                    {                        // check to make sure the script sent back a status -- if                        // not the install may have been syntactically correct but                        // left the init/(perform|cancel) transaction open                        if(JS_GetProperty(cx, glob, "_installedFiles", &installedFiles) &&                          JSVAL_TO_BOOLEAN(installedFiles))                        {                            // install items remain in queue, must clean up!                            nsInstall *a = (nsInstall*)JS_GetPrivate(cx, glob);                            a->InternalAbort(nsInstall::MALFORMED_INSTALL);                        }                        jsval sent;                        if ( JS_GetProperty( cx, glob, "_finalStatus", &sent ) )                            finalStatus = JSVAL_TO_INT(sent);                        else                            finalStatus = nsInstall::UNEXPECTED_ERROR;                    }                    JS_EndRequest(cx); //Decrement JS thread counter                    JS_DestroyContextMaybeGC(cx);                }                else                {                    // couldn't initialize install context                    finalStatus = nsInstall::UNEXPECTED_ERROR;                }                // clean up Runtime if we created it ourselves                if ( ownRuntime )                    JS_DestroyRuntime(rt);            }        // force zip archive closed before other cleanup        hZip = 0;    }    else    {        // no path to local jar archive        finalStatus = nsInstall::DOWNLOAD_ERROR;    }    if(listener)        listener->OnInstallDone( installInfo->GetURL(), finalStatus );    if (scriptBuffer) delete [] scriptBuffer;    softwareUpdate->SetActiveListener(0);    softwareUpdate->InstallJarCallBack();}//-----------------------------------------------------------------------------// RunChromeInstallOnThread//// Performs the guts of a chrome install on its own thread//// XXX: need to return errors/status somehow. What feedback will a user want?// How do we get it there? Maybe just alerts on errors, could also dump to// the new console service.//-----------------------------------------------------------------------------extern "C" void RunChromeInstallOnThread(void *data){    nsresult rv;    NS_ASSERTION(data, "No nsInstallInfo passed to Chrome Install");    nsInstallInfo *info = (nsInstallInfo*)data;    nsIXPIListener* listener = info->GetListener();    if (listener)        listener->OnInstallStart(info->GetURL());    // make sure we've got a chrome registry -- can't proceed if not    nsIXULChromeRegistry* reg = info->GetChromeRegistry();#ifndef MOZ_XUL_APP    nsCOMPtr<nsIChromeRegistrySea> cr = do_QueryInterface(reg);#endif    if (reg)    {        // build up jar: URL        nsCString spec;        spec.SetCapacity(200);        spec = "jar:";        nsCAutoString localURL;        rv = NS_GetURLSpecFromFile(info->GetFile(), localURL);        if (NS_SUCCEEDED(rv)) {            spec.Append(localURL);            spec.Append("!/");        }        // Now register the new chrome        if (NS_SUCCEEDED(rv))        {            PRBool isSkin    = (info->GetType() & CHROME_SKIN);            PRBool isLocale  = (info->GetType() & CHROME_LOCALE);            PRBool isContent = (info->GetType() & CHROME_CONTENT);            PRBool selected  = (info->GetFlags() != 0);            if ( isContent )            {                rv = reg->InstallPackage(spec.get(), PR_TRUE);            }            if ( isSkin )            {                PRBool installed = PR_FALSE;                // Look for a theme manifest                static NS_DEFINE_IID(kIZipReaderIID, NS_IZIPREADER_IID);                static NS_DEFINE_IID(kZipReaderCID,  NS_ZIPREADER_CID);                nsresult rv;                nsCOMPtr<nsIZipReader> hZip = do_CreateInstance(kZipReaderCID, &rv);                if (hZip)                    rv = hZip->Init(info->GetFile());                if (NS_SUCCEEDED(rv))                {                    hZip->Open();                    nsIExtensionManager* em = info->GetExtensionManager();                    rv = hZip->Test("install.rdf");                    if (NS_SUCCEEDED(rv) && em)                    {                        rv = em->InstallTheme(info->GetFile(), nsIExtensionManager::FLAG_INSTALL_PROFILE);                        if (NS_SUCCEEDED(rv))                            installed = PR_TRUE;                    }                        hZip->Close();                    // Extension Manager copies the theme .jar file to                     // a different location, so remove the temporary file.                    info->GetFile()->Remove(PR_FALSE);                }                                // We either have an old-style theme with no theme.rdf                 // manifest, OR we have a new style theme and InstallTheme                // returned an error (e.g. it's not implemented in Seamonkey,                 // or something else went wrong)                if (!installed)                    rv = reg->InstallSkin(spec.get(), PR_TRUE, PR_FALSE);                #ifndef MOZ_XUL_APP                if (NS_SUCCEEDED(rv) && selected)                {                    NS_ConvertUCS2toUTF8 utf8Args(info->GetArguments());                    rv = reg->SelectSkin(utf8Args, PR_TRUE);                }#endif            }            if ( isLocale )            {                rv = reg->InstallLocale(spec.get(), PR_TRUE);#ifndef MOZ_XUL_APP                if (NS_SUCCEEDED(rv) && selected)                {                    NS_ConvertUCS2toUTF8 utf8Args(info->GetArguments());                    rv = cr->SelectLocale(utf8Args, PR_TRUE);                }#endif            }            // now that all types are registered try to activate            if ( isSkin && selected )                reg->RefreshSkins();#ifdef RELOAD_CHROME_WORKS// XXX ReloadChrome() crashes right now            if ( isContent || (isLocale && selected) )                reg->ReloadChrome();#endif        }    }    if (listener)        listener->OnInstallDone(info->GetURL(), nsInstall::SUCCESS);    delete info;}