Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Protected Attributes | Private Member Functions | Private Attributes
nsRegisterItem Class Reference

#include <nsRegisterItem.h>

Inheritance diagram for nsRegisterItem:
Inheritance graph
[legend]
Collaboration diagram for nsRegisterItem:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsRegisterItem (nsInstall *install, nsIFile *chrome, PRUint32 chromeType, const char *path)
virtual ~nsRegisterItem ()
PRInt32 Prepare ()
PRInt32 Complete ()
void Abort ()
char * toString ()
PRBool CanUninstall ()
PRBool RegisterPackageNode ()

Protected Attributes

nsInstallmInstall

Private Member Functions

nsresult GetURLFromIFile (nsIFile *aFile, char **aOutURL)
void LogError (const nsAString &aMessage, nsresult code)
void LogErrorWithFilename (const nsAString &aMessage, nsresult code, nsILocalFile *localFile)

Private Attributes

nsCString mURL
nsCOMPtr< nsIFilemChrome
PRUint32 mChromeType
nsCOMPtr< nsIFilemProgDir
nsCString mPath

Detailed Description

Definition at line 51 of file nsRegisterItem.h.


Constructor & Destructor Documentation

nsRegisterItem::nsRegisterItem ( nsInstall install,
nsIFile chrome,
PRUint32  chromeType,
const char *  path 
)

Definition at line 55 of file nsRegisterItem.cpp.

: nsInstallObject(inInstall), mChrome(chrome), mChromeType(chromeType), mPath(path)
{
    MOZ_COUNT_CTOR(nsRegisterItem);
}

Definition at line 65 of file nsRegisterItem.cpp.


Member Function Documentation

void nsRegisterItem::Abort ( ) [virtual]

Implements nsInstallObject.

Definition at line 495 of file nsRegisterItem.cpp.

{
    // nothing to undo
}

Implements nsInstallObject.

Definition at line 540 of file nsRegisterItem.cpp.

{
    return PR_FALSE;
}

Implements nsInstallObject.

Definition at line 273 of file nsRegisterItem.cpp.

{
    nsresult rv = NS_OK;
    PRInt32 result = nsInstall::SUCCESS;
    CHROMEREG_IFACE* reg = mInstall->GetChromeRegistry();
#ifndef MOZ_XUL_APP
    PRBool  isProfile = mChromeType & CHROME_PROFILE;
#endif

    if ( reg && !(mChromeType & CHROME_DELAYED) )
    {
#ifdef MOZ_XUL_APP
        nsCOMPtr<nsIURI> baseuri;
        rv = NS_NewURI(getter_AddRefs(baseuri), mURL);
        if (NS_FAILED(rv)) {
            LogError(NS_LITERAL_STRING("NS_NewURI failed."), rv);
        }
        else {
            nsCOMPtr<nsIURI> manifesturi;
            rv = NS_NewURI(getter_AddRefs(manifesturi),
                           NS_LITERAL_CSTRING("resource:///chrome/xpinstall.manifest"));
            if (NS_FAILED(rv)) {
                LogError(NS_LITERAL_STRING("NS_NewURI failed."), rv);
            }
            else {
                PRBool skinOnly = (mChromeType & CHROME_ALL) == CHROME_SKIN;
                rv = reg->ProcessContentsManifest(baseuri, manifesturi,
                                                  baseuri, PR_TRUE,
                                                  skinOnly);
                if (NS_FAILED(rv)) {
                    LogError(NS_LITERAL_STRING("ProcessContentsManifest failed."), rv);
                }
                reg->CheckForNewChrome();
            }
        }
#else
        // We can register right away
        if (mChromeType & CHROME_SKIN)
            rv = reg->InstallSkin(mURL.get(), isProfile, PR_TRUE);
        if (NS_FAILED(rv)) {
            LogError(NS_LITERAL_STRING("InstallSkin() failed."), rv);
        }

        if (NS_SUCCEEDED(rv) && (mChromeType & CHROME_LOCALE))
            rv = reg->InstallLocale(mURL.get(), isProfile);
        if (NS_FAILED(rv)) {
            LogError(NS_LITERAL_STRING("InstallLocale() failed."), rv);
        }

        if (NS_SUCCEEDED(rv) && (mChromeType & CHROME_CONTENT))
            rv = reg->InstallPackage(mURL.get(), isProfile);
        if (NS_FAILED(rv)) {
            LogError(NS_LITERAL_STRING("InstallPackage() failed."), rv);
        }
#endif
    }
    else
    {
        // Either script asked for delayed chrome or we can't find
        // the chrome registry to do it now.

        // construct a reference to the magic file
        PRFileDesc* fd = nsnull;
        nsCOMPtr<nsIFile> tmp;
        PRBool bExists = PR_FALSE;
        if (!nsSoftwareUpdate::GetProgramDirectory())  // not in the stub installer
        { 
            nsCOMPtr<nsIProperties> directoryService = 
                     do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID, &rv);
            if (NS_FAILED(rv)) {
                LogError(NS_LITERAL_STRING("failed to get directory service."), rv);
            }
            if (NS_SUCCEEDED(rv) && directoryService) 
            {
                rv = directoryService->Get(NS_APP_CHROME_DIR, 
                                       NS_GET_IID(nsIFile), 
                                       getter_AddRefs(tmp));
                if(NS_FAILED(rv))
                {
                    LogError(NS_LITERAL_STRING("failed get application chrome directory."), rv);
                    result = nsInstall::CHROME_REGISTRY_ERROR;
                    return result;
                }
            }
        }
        else
        {
            rv = nsSoftwareUpdate::GetProgramDirectory()->Clone(getter_AddRefs(tmp));

            if (NS_SUCCEEDED(rv))
            {
                tmp->AppendNative(INSTALL_CHROME_DIR);
            } else {
                LogError(NS_LITERAL_STRING("failed to clone program directory. (not critical)"), rv);
            }
        }
        nsCOMPtr<nsILocalFile> startupFile( do_QueryInterface(tmp, &rv) );

        if (NS_SUCCEEDED(rv))
        {
            rv = startupFile->Exists(&bExists);
            if(NS_FAILED(rv))
            {
                LogErrorWithFilename(NS_LITERAL_STRING("directory existance check failed."), rv, startupFile);
            }
            if (NS_SUCCEEDED(rv) && !bExists)
                rv = startupFile->Create(nsIFile::DIRECTORY_TYPE, 0755);
            if (NS_SUCCEEDED(rv))
            {
                rv = startupFile->AppendNative(NS_LITERAL_CSTRING("installed-chrome.txt"));
                if (NS_SUCCEEDED(rv))
                {
                    rv = startupFile->OpenNSPRFileDesc(
                                    PR_CREATE_FILE | PR_WRONLY,
                                    0744,
                                    &fd);
                    if(NS_FAILED(rv))
                    {
                        LogErrorWithFilename(NS_LITERAL_STRING("opening of installed-chrome.txt failed."), rv, startupFile);
                    }
                } else {
                    LogError(NS_LITERAL_STRING("String append failed."), rv);
                }
            } else {
                LogErrorWithFilename(NS_LITERAL_STRING("startup directory creation failed."), rv, startupFile);
            }
        }

        if ( NS_SUCCEEDED(rv) && fd )
        {
            PR_Seek(fd, 0, PR_SEEK_END);
            const char* location = (mChromeType & CHROME_PROFILE) ? "profile" : "install";

            if (NS_SUCCEEDED(rv)/* && path*/)
            {
                PRInt32 written, actual;
                char* installStr = nsnull;
       
                // this looks redundant, but a single registerChrome()
                // call can register all three types.
                if (mChromeType & CHROME_SKIN)
                {
                    installStr = PR_smprintf("skin,%s,url,%s\n",
                                             location, mURL.get());
                    if (installStr)
                    {
                        actual = strlen(installStr);
                        written = PR_Write(fd, installStr, actual);
                        if ( written != actual ) 
                        {
                            LogErrorWithFilename(NS_LITERAL_STRING("writing to installed-chrome.txt failed."), rv, startupFile);
                            result = nsInstall::CHROME_REGISTRY_ERROR;
                        }
                        PR_smprintf_free(installStr);
                    }
                    else 
                        result = nsInstall::OUT_OF_MEMORY;
                }

                if (mChromeType & CHROME_LOCALE)
                {
                    installStr = PR_smprintf("locale,%s,url,%s\n",
                                             location, mURL.get());
                    if (installStr)
                    {
                        actual = strlen(installStr);
                        written = PR_Write(fd, installStr, actual);
                        if ( written != actual ) 
                        {
                            LogErrorWithFilename(NS_LITERAL_STRING("writing to installed-chrome.txt failed."), rv, startupFile);
                            result = nsInstall::CHROME_REGISTRY_ERROR;
                        }
                        PR_smprintf_free(installStr);
                    }
                    else
                        result = nsInstall::OUT_OF_MEMORY;
                }

                if (mChromeType & CHROME_CONTENT)
                {
                    installStr = PR_smprintf("content,%s,url,%s\n",
                                             location, mURL.get());
                    if (installStr)
                    {
                        actual = strlen(installStr);
                        written = PR_Write(fd, installStr, actual);
                        if ( written != actual ) 
                        {
                            LogErrorWithFilename(NS_LITERAL_STRING("writing to installed-chrome.txt failed."), rv, startupFile);
                            result = nsInstall::CHROME_REGISTRY_ERROR;
                        }
                        PR_smprintf_free(installStr);
                    }
                    else
                        result = nsInstall::OUT_OF_MEMORY;
                }
            }
            PR_Close(fd);

#ifdef MOZ_XUL_APP
            // app-chrome.manifest is not regenerated if it exists
            rv = startupFile->SetNativeLeafName(NS_LITERAL_CSTRING("app-chrome.manifest"));
            if (NS_SUCCEEDED(rv))
                startupFile->Remove(PR_FALSE);
#endif
        }
        else
        {
            LogError(NS_LITERAL_STRING("opening of installed-chrome.txt failed."), rv);
            result = nsInstall::CHROME_REGISTRY_ERROR;
        }
    }

    if (NS_FAILED(rv))
    {
        LogError(NS_LITERAL_STRING("Failed to register chrome."), rv);
        result = nsInstall::CHROME_REGISTRY_ERROR;
    }

    return result;
}

Here is the call graph for this function:

nsresult nsRegisterItem::GetURLFromIFile ( nsIFile aFile,
char **  aOutURL 
) [private]

Definition at line 552 of file nsRegisterItem.cpp.

{
    if (!aFile || !aOutURL)
    {
        NS_WARNING("bogus arg passed to nsRegisterItem::GetURLFromIFile()");
        return NS_ERROR_NULL_POINTER;
    }
    *aOutURL = nsnull;

    // try to use Necko to create the URL; if that fails (as
    // it will for the install wizards which don't have Necko)
    // then use warren's local hack.

    nsCAutoString spec;
    nsresult rv = NS_GetURLSpecFromFile(aFile, spec);
    if (NS_FAILED(rv))
        rv = hack_nsIFile2URL(aFile, aOutURL);
    else {
        *aOutURL = ToNewCString(spec);
        if (!*aOutURL)
            rv = NS_ERROR_OUT_OF_MEMORY;
    }

    return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsRegisterItem::LogError ( const nsAString &  aMessage,
nsresult  code 
) [private]

Definition at line 155 of file nsRegisterItem.cpp.

{
    char resultString[12];

    PR_snprintf(resultString, 12, "0x%lx", code);
    mInstall->LogComment(aMessage + NS_LITERAL_STRING(" - nsresult code: ") +
                         NS_ConvertASCIItoUTF16(resultString));
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsRegisterItem::LogErrorWithFilename ( const nsAString &  aMessage,
nsresult  code,
nsILocalFile localFile 
) [private]

Definition at line 144 of file nsRegisterItem.cpp.

{
    nsCAutoString path;
    nsAutoString unipath;

    LogError(aMessage, code);
    localFile->GetNativePath(path);
    if(NS_SUCCEEDED(NS_CopyNativeToUnicode(path, unipath)))
        mInstall->LogComment(unipath);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Implements nsInstallObject.

Definition at line 164 of file nsRegisterItem.cpp.

{
    // The chrome must exist
    PRBool exists;
    nsresult rv = mChrome->Exists(&exists);
    if (NS_FAILED(rv))
        return nsInstall::UNEXPECTED_ERROR;
    if (!exists)
        return nsInstall::DOES_NOT_EXIST;


    // Are we dealing with a directory (flat chrome) or an archive?
    PRBool isDir;
    rv = mChrome->IsDirectory(&isDir);
    if (NS_FAILED(rv))
        return nsInstall::UNEXPECTED_ERROR;


    // Can we construct a resource: URL or do we need a file: URL instead?
    // find the xpcom directory and see if mChrome is a child
    PRBool isChild = PR_FALSE;
    mProgDir = nsSoftwareUpdate::GetProgramDirectory();
    if (!mProgDir)
    {
        // not in the wizard, so ask the directory service where it is
        nsCOMPtr<nsIProperties> dirService(
                do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID, &rv));
        if(NS_SUCCEEDED(rv))
        {
            NS_ASSERTION(dirService,"directory service lied to us");
            rv = dirService->Get(NS_XPCOM_CURRENT_PROCESS_DIR,
                        NS_GET_IID(nsIFile), getter_AddRefs(mProgDir));
        }
    }
    if (NS_SUCCEEDED(rv))
    {
        NS_ASSERTION(mProgDir,"NS_SUCCESS but no mProgDir");
        rv = mProgDir->Contains(mChrome, PR_TRUE, &isChild);
        if (NS_FAILED(rv)) 
            return nsInstall::UNEXPECTED_ERROR;
    }
    else
        return nsInstall::UNEXPECTED_ERROR;


    // Either way we need the file: URL to the chrome
    nsXPIDLCString localURL;
    rv = GetURLFromIFile( mChrome, getter_Copies(localURL) );
    if (NS_FAILED(rv))
        return nsInstall::UNEXPECTED_ERROR;

    // see what kind of URL we have to construct
    if (!isChild)
    {
        // Not relative so use the file:// URL we got above
        PRInt32 urlLen = strlen(localURL) + mPath.Length();

        if (isDir)
        {
            // "flat" chrome, urlLen is suffient
            mURL.SetCapacity( urlLen );
        }
        else
        {
            // archive, add room for jar: syntax (over by one, but harmless)
            mURL.SetCapacity( urlLen + sizeof("jar:") + sizeof('!') );
            mURL = "jar:";
        }
        mURL.Append(localURL);
    }
    else
    {
        // we can construct a resource: URL to chrome in a subdir
        nsXPIDLCString binURL;
        rv = GetURLFromIFile( mProgDir, getter_Copies(binURL) );
        if (NS_FAILED(rv))
            return nsInstall::UNEXPECTED_ERROR;

        PRInt32 binLen = strlen(binURL);
        const char *subURL = localURL + binLen;
        PRInt32 padding = sizeof("resource:/") + sizeof("jar:!/");

        mURL.SetCapacity( strlen(subURL) + mPath.Length() + padding );

        if (!isDir)
            mURL = "jar:";

        mURL.Append("resource:/");
        mURL.Append(subURL);
    }

        
    if (!isDir)
    {
        // need jar: URL closing bang-slash
        mURL.Append("!/");
    }
    else
    {
        // Necko should already slash-terminate directory file:// URLs
        NS_ASSERTION(mURL[mURL.Length()-1] == '/', "Necko changed the rules");
    }

    // add on "extra" subpath to new content.rdf
    mURL.Append(mPath);

    return nsInstall::SUCCESS;
}

Here is the call graph for this function:

Implements nsInstallObject.

Definition at line 546 of file nsRegisterItem.cpp.

{
    return PR_FALSE;
}
char * nsRegisterItem::toString ( ) [virtual]

Implements nsInstallObject.

Definition at line 500 of file nsRegisterItem.cpp.

{
    char* buffer = new char[1024];
    char* rsrcVal = nsnull;

    if (buffer == nsnull || !mInstall)
        return nsnull;

    buffer[0] = '\0';
    switch (mChromeType & CHROME_ALL)
    {
    case CHROME_SKIN:
        rsrcVal = mInstall->GetResourcedString(
                    NS_LITERAL_STRING("RegSkin"));
        break;
    case CHROME_LOCALE:
        rsrcVal = mInstall->GetResourcedString(
                    NS_LITERAL_STRING("RegLocale"));
        break;
    case CHROME_CONTENT:
        rsrcVal = mInstall->GetResourcedString(
                    NS_LITERAL_STRING("RegContent"));
        break;
    default:
        rsrcVal = mInstall->GetResourcedString(
                    NS_LITERAL_STRING("RegPackage"));
        break;
    }

    if (rsrcVal)
    {
        PR_snprintf(buffer, 1024, rsrcVal, mURL.get());
        nsCRT::free(rsrcVal);
    }

    return buffer;
}

Here is the call graph for this function:


Member Data Documentation

Definition at line 78 of file nsRegisterItem.h.

Definition at line 79 of file nsRegisterItem.h.

nsInstall* nsInstallObject::mInstall [protected, inherited]

Definition at line 69 of file nsInstallObject.h.

Definition at line 81 of file nsRegisterItem.h.

Definition at line 80 of file nsRegisterItem.h.

Definition at line 77 of file nsRegisterItem.h.


The documentation for this class was generated from the following files: