fix autoreg components always get called on startup. bug#85770 r=ssu sr=alecf

This commit is contained in:
cathleen%netscape.com 2001-06-28 00:06:16 +00:00
Родитель 8d8886f4b0
Коммит e8ed84659e
7 изменённых файлов: 102 добавлений и 21 удалений

Просмотреть файл

@ -342,7 +342,7 @@ static void reginfo2Length( const REGINFO &in, PRUint32 &out ) {
| This code generates the implementation of the nsISupports member functions |
| for each class implemented in this file. |
------------------------------------------------------------------------------*/
NS_IMPL_ISUPPORTS1( nsRegistry, nsIRegistry )
NS_IMPL_THREADSAFE_ISUPPORTS1( nsRegistry, nsIRegistry )
NS_IMPL_ISUPPORTS2( nsRegSubtreeEnumerator, nsIEnumerator,
nsIRegistryEnumerator)
NS_IMPL_ISUPPORTS1( nsRegistryNode, nsIRegistryNode )

Просмотреть файл

@ -342,7 +342,7 @@ static void reginfo2Length( const REGINFO &in, PRUint32 &out ) {
| This code generates the implementation of the nsISupports member functions |
| for each class implemented in this file. |
------------------------------------------------------------------------------*/
NS_IMPL_ISUPPORTS1( nsRegistry, nsIRegistry )
NS_IMPL_THREADSAFE_ISUPPORTS1( nsRegistry, nsIRegistry )
NS_IMPL_ISUPPORTS2( nsRegSubtreeEnumerator, nsIEnumerator,
nsIRegistryEnumerator)
NS_IMPL_ISUPPORTS1( nsRegistryNode, nsIRegistryNode )

Просмотреть файл

@ -66,6 +66,7 @@
#include "nsProcess.h"
#include "InstallCleanupDefines.h"
#include "nsISoftwareUpdate.h"
// Interfaces Needed
#include "nsIXULWindow.h"
@ -1074,8 +1075,20 @@ static nsresult main1(int argc, char* argv[], nsISupports *nativeApp )
NS_ASSERTION(NS_SUCCEEDED(rv), "Initializing AppleEvents failed");
#endif
// XXX: This call will be replaced by a registry initialization...
NS_SetupRegistry_1( PR_TRUE );
// Ask XPInstall if we need to autoregister anything new.
PRBool needAutoReg = NS_SoftwareUpdateNeedsAutoReg();
#ifdef DEBUG
// _Always_ autoreg if we're in a debug build, under the assumption
// that people are busily modifying components and will be angry if
// their changes aren't noticed.
needAutoReg = PR_TRUE;
#endif
NS_SetupRegistry_1(needAutoReg);
if (needAutoReg) // XXX ...and autoreg was successful?
NS_SoftwareUpdateDidAutoReg();
// remove the nativeApp as an XPCOM autoreg observer
if (obsService)

Просмотреть файл

@ -37,6 +37,9 @@
#include "nsIGenericFactory.h"
#include "nsIDOMWindowInternal.h"
#include "nsIRegistry.h"
#include "nsIRegistryUtils.h"
#define NS_IXPINSTALLCOMPONENT_CONTRACTID NS_IAPPSHELLCOMPONENT_CONTRACTID "/xpinstall;1"
#define NS_IXPINSTALLCOMPONENT_CLASSNAME "Mozilla XPInstall Component"
@ -108,6 +111,85 @@ protected:
nsCOMPtr<nsIGenericFactory> mInstallVersionFactory;
};
#define XPI_ROOT_KEY "software/mozilla/xpinstall"
#define XPI_AUTOREG_VAL "Autoreg"
#define XPCOM_KEY "software/mozilla/XPCOM"
/**
* @return PR_TRUE if XPI has requested an autoreg be performed.
*/
inline PRBool
NS_SoftwareUpdateNeedsAutoReg()
{
nsresult rv;
// Conservatively assume that we'll need to autoreg.
PRBool needAutoReg = PR_TRUE;
nsCOMPtr<nsIRegistry> reg = do_GetService(NS_REGISTRY_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv)) {
rv = reg->OpenWellKnownRegistry(nsIRegistry::ApplicationComponentRegistry);
if (NS_SUCCEEDED(rv)) {
nsRegistryKey idKey = 0;
rv = reg->GetSubtree(nsIRegistry::Common, XPI_ROOT_KEY, &idKey);
if (NS_SUCCEEDED(rv)) {
char* autoRegVal = nsnull;
rv = reg->GetStringUTF8(idKey, XPI_AUTOREG_VAL, &autoRegVal);
// If the string exists and isn't yes'', then we can avoid
// autoreg; otherwise, be conservative and autoregister.
if (NS_SUCCEEDED(rv) && (PL_strcmp(autoRegVal, "yes") != 0))
needAutoReg = PR_FALSE;
if (autoRegVal)
nsMemory::Free(autoRegVal);
}
}
}
return needAutoReg;
}
/**
* Notify XPI that autoreg was performed successfully.
*/
inline void
NS_SoftwareUpdateDidAutoReg()
{
nsresult rv;
nsCOMPtr<nsIRegistry> reg = do_GetService(NS_REGISTRY_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv)) {
rv = reg->OpenWellKnownRegistry(nsIRegistry::ApplicationComponentRegistry);
if (NS_SUCCEEDED(rv)) {
nsRegistryKey idKey = 0;
rv = reg->AddSubtree(nsIRegistry::Common, XPI_ROOT_KEY, &idKey);
if (NS_SUCCEEDED(rv))
reg->SetStringUTF8(idKey, XPI_AUTOREG_VAL, "no");
}
}
}
/**
* Request that an autoreg be performed at next startup. (Used
* internally by XPI.)
*/
inline void
NS_SoftwareUpdateRequestAutoReg()
{
nsresult rv;
nsCOMPtr<nsIRegistry> reg = do_GetService(NS_REGISTRY_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv)) {
rv = reg->OpenWellKnownRegistry(nsIRegistry::ApplicationComponentRegistry);
if (NS_SUCCEEDED(rv)) {
nsRegistryKey idKey = 0;
rv = reg->AddSubtree(nsIRegistry::Common, XPI_ROOT_KEY, &idKey);
if (NS_SUCCEEDED(rv))
reg->SetStringUTF8(idKey, XPI_AUTOREG_VAL, "yes");
}
}
}
#endif // nsISoftwareUpdate_h__

Просмотреть файл

@ -860,17 +860,7 @@ nsInstall::FinalizeInstall(PRInt32* aReturn)
// XXX for now all successful installs will trigger an Autoreg.
// We eventually want to do this only when flagged.
HREG reg;
if ( REGERR_OK == NR_RegOpen("", &reg) )
{
RKEY xpiRoot;
REGERR err;
err = NR_RegAddKey(reg,ROOTKEY_COMMON,XPI_ROOT_KEY,&xpiRoot);
if ( err == REGERR_OK )
NR_RegSetEntryString(reg, xpiRoot, XPI_AUTOREG_VAL, "yes");
NR_RegClose(reg);
}
NS_SoftwareUpdateRequestAutoReg();
}
else
*aReturn = SaveError( result );

Просмотреть файл

@ -56,8 +56,8 @@ nsInstallProgressDialog::~nsInstallProgressDialog()
}
NS_IMPL_ADDREF( nsInstallProgressDialog );
NS_IMPL_RELEASE( nsInstallProgressDialog );
NS_IMPL_THREADSAFE_ADDREF( nsInstallProgressDialog );
NS_IMPL_THREADSAFE_RELEASE( nsInstallProgressDialog );
NS_IMETHODIMP
nsInstallProgressDialog::QueryInterface(REFNSIID aIID,void** aInstancePtr)

Просмотреть файл

@ -25,10 +25,6 @@ class nsInstallInfo;
#include "nsTopProgressNotifier.h"
#define XPI_ROOT_KEY "software/mozilla/xpinstall"
#define XPI_AUTOREG_VAL "Autoreg"
#define XPCOM_KEY "software/mozilla/XPCOM"
class nsSoftwareUpdate: public nsISoftwareUpdate,
public nsPIXPIStubHook,
public nsIObserver