delete []finalDecision; return NS_OK;
nsChromeRegistry::ConvertChromeURL(nsIURI* aChromeURL){    nsresult rv = NS_OK;        // Retrieve the resource for this chrome element.#ifdef NECKO    char* host;#else    const char* host;#endif    if (NS_FAILED(rv = aChromeURL->GetHost(&host))) {        NS_ERROR("Unable to retrieve the host for a chrome URL.");        return rv;    }    nsAutoString hostStr(host);#ifdef NECKO    nsCRT::free(host);    char* file;#else    const char* file;#endif    // Construct a chrome URL and use it to look up a resource.#ifndef NECKO    nsAutoString windowType = nsAutoString("chrome://") + hostStr + "/";#else    nsAutoString windowType = nsAutoString("chrome://") + hostStr ;#endif    // Stash any search part of the URL for later#ifdef NECKO    nsIURL* url = nsnull;    rv = aChromeURL->QueryInterface(nsIURL::GetIID(), (void**)&url);    if (NS_SUCCEEDED(rv)) {        rv = url->GetQuery(&file);		if (NS_FAILED(rv))			file = nsCRT::strdup("");        NS_RELEASE(url);    }#else    aChromeURL->GetSearch(&file);#endif    nsAutoString searchStr(file);    // Find out the package type of the URL#ifdef NECKO    aChromeURL->GetPath(&file);#else    aChromeURL->GetFile(&file);#endif    nsAutoString restOfURL(file);#ifdef NECKO    nsCRT::free(file);#endif //NECKO        // Find the second slash.    nsAutoString packageType("content");    nsAutoString path("");    PRInt32 slashIndex = -1;    if (restOfURL.Length() > 1)    {        // There is something to the right of that slash. A provider type must have        // been specified.        slashIndex = restOfURL.FindChar('/', PR_FALSE,1);        if (slashIndex == -1)		    slashIndex = restOfURL.Length();#ifndef NECKO        restOfURL.Mid(packageType, 1, slashIndex - 1);#else        restOfURL.Mid(packageType, 0, slashIndex);#endif        if (slashIndex < restOfURL.Length()-1)        {            // There are some extra subdirectories to remember.#ifndef NECKO            restOfURL.Right(path, restOfURL.Length()-slashIndex-1);#else            restOfURL.Right(path, restOfURL.Length()-slashIndex);#endif        }    }    windowType += packageType + "/";    // We have the resource URI that we wish to retrieve. Fetch it.    nsCOMPtr<nsIRDFResource> chromeResource;    if (NS_FAILED(rv = GetPackageTypeResource(windowType, getter_AddRefs(chromeResource)))) {        NS_ERROR("Unable to retrieve the resource corresponding to the chrome skin or content.");        return rv;    }    nsString chromeName;    if (NS_FAILED(rv = GetChromeResource(chromeName, chromeResource, kCHROME_name))) {        // No name entry was found. Don't use one.        chromeName = "";    }    nsString chromeBase;    if (NS_FAILED(rv = GetChromeResource(chromeBase, chromeResource, kCHROME_base))) {        // No base entry was found. Default to our cache.        chromeBase = "resource:/chrome/";        chromeBase += hostStr;#ifndef NECKO		chromeBase += "/";#endif        chromeBase += packageType + "/";        if (chromeName != "")          chromeBase += chromeName + "/";    }		// Make sure base ends in a slash	  PRInt32 length = chromeBase.Length();		if (length > 0)		{			PRUnichar c = chromeBase.CharAt(length-1);			if (c != '/')				chromeBase += "/"; // Ensure that a slash is present.		}    // Check to see if we should append the "main" entry in the registry.    // Only do this when the user doesn't have anything following "skin"    // or "content" in the specified URL.    if (path.IsEmpty())    {			  PRInt32 length = restOfURL.Length();				if (length > 0)				{					PRUnichar c = restOfURL.CharAt(length-1);					if (c != '/')						restOfURL += "/"; // Ensure that a slash is present.				}				          // Append the "main" entry.        nsString mainFile;        if (NS_FAILED(rv = GetChromeResource(mainFile, chromeResource, kCHROME_main))) {            NS_ERROR("Unable to retrieve the main file registry entry for a chrome URL.");            return rv;        }        chromeBase += mainFile;    }    else    {#ifdef NECKO        // if path starts in a slash, remove it.        if (path[0] == '/')          path.Cut(0, 1);#endif                // XXX Just append the rest of the URL to base to get the actual URL to look up.			  chromeBase += path;    }    char* finalDecision = chromeBase.ToNewCString();    char* search = searchStr.ToNewCString();    aChromeURL->SetSpec(finalDecision);    if (search && *search) {#ifdef NECKO        rv = aChromeURL->QueryInterface(nsIURL::GetIID(), (void**)&url);        if (NS_SUCCEEDED(rv)) {            (void)url->SetQuery(search);            NS_RELEASE(url);        }#else        aChromeURL->SetSearch(search);#endif        delete []search;    }    delete []finalDecision;    return NS_OK;}