InitializeDataSource(nsAutoString(package), nsAutoString(provider), getter_AddRefs(dataSource));
nsString packageStr(package), providerStr(provider); InitializeDataSource(packageStr, providerStr, getter_AddRefs(dataSource));
nsChromeRegistry::ConvertChromeURL(nsIURI* aChromeURL){    nsresult rv = NS_OK;    NS_ASSERTION(aChromeURL, "null url!");    if (!aChromeURL)        return NS_ERROR_NULL_POINTER;#ifdef NS_DEBUG    //Ensure that we got a chrome url!    nsXPIDLCString scheme;    rv = aChromeURL->GetScheme(getter_Copies(scheme));    if (NS_FAILED(rv)) return rv;    NS_ASSERTION((0 == PL_strncmp(scheme, "chrome", 6)),         "Bad scheme URL in chrome URL conversion!");    if (0 != PL_strncmp(scheme, "chrome", 6))        return NS_ERROR_FAILURE;#endif    // Obtain the package, provider and remaining from the URL    nsXPIDLCString package, provider, remaining;#if 0 // This change happens when we switch to using chrome://skin@global/foo..    rv = aChromeURL->GetHost(getter_Copies(package));    if (NS_FAILED(rv)) return rv;    rv = aChromeURL->GetPreHost(getter_Copies(provider));    if (NS_FAILED(rv)) return rv;    rv = aChromeURL->GetPath(getter_Copies(remaining));    if (NS_FAILED(rv)) return rv;#else // For now however...    rv = aChromeURL->GetHost(getter_Copies(package));    if (NS_FAILED(rv)) return rv;    nsXPIDLCString tempPath;    rv = aChromeURL->GetPath(getter_Copies(tempPath));    if (NS_FAILED(rv)) return rv;    BreakProviderAndRemainingFromPath(        (const char*)tempPath,         getter_Copies(provider),         getter_Copies(remaining));#endif    // Construct the lookup string-    // which is basically chrome:// + package + provider        nsAutoString lookup("chrome://");    lookup += package; // no trailing slash here        NS_ASSERTION(*provider == '/', "No leading slash here!");        //definitely have a leading slash...    if (*provider != '/')        lookup += '/';    lookup += provider;         // end it on a slash if none is present    if (lookup.CharAt(lookup.Length()-1) != '/')        lookup += '/';    // Get the chromeResource from this lookup string    nsCOMPtr<nsIRDFResource> chromeResource;    if (NS_FAILED(rv = GetPackageTypeResource(lookup, getter_AddRefs(chromeResource)))) {        NS_ERROR("Unable to retrieve the resource corresponding to the chrome skin or content.");        return rv;    }        // Using this chrome resource get the three basic things of a chrome entry-    // base, name, main. and don't bail if they don't exist.    nsAutoString base, name, main;    nsCOMPtr<nsIRDFDataSource> dataSource;    InitializeDataSource(nsAutoString(package), nsAutoString(provider), getter_AddRefs(dataSource));    rv = GetChromeResource(dataSource, name, chromeResource, kCHROME_name);    if (NS_FAILED (rv)) {        if (PL_strcmp(provider,"/locale") == 0)          name = "en-US";        else          name = "default";    }    rv = GetChromeResource(dataSource, base, chromeResource, kCHROME_base);    if (NS_FAILED(rv))    {        // No base entry was found, default it to our cache.        base = "resource:/chrome/";        base += package;        if ((base.CharAt(base.Length()-1) != '/') && *provider != '/')            base += '/';        base += provider;        if (base.CharAt(base.Length()-1) != '/')             base += '/';        if (name.Length())            base += name;        if (base.CharAt(base.Length()-1) != '/')            base += '/';    }    NS_ASSERTION(base.CharAt(base.Length()-1) == '/', "Base doesn't end in a slash!");    if ('/' != base.CharAt(base.Length()-1))        base += '/';      // Now we construct our finalString    nsAutoString finalString(base);    if (!remaining || (0 == PL_strlen(remaining)))    {        rv = GetChromeResource(dataSource, main, chromeResource, kCHROME_main);        if (NS_FAILED(rv))        {            //we'd definitely need main for an empty remaining            //NS_ERROR("Unable to retrieve the main file registry entry for a chrome URL.");            //return rv;            main = package;            if (PL_strcmp(provider, "/skin") == 0)              main += ".css";            else if (PL_strcmp(provider, "/content") == 0)              main += ".xul";            else if (PL_strcmp(provider, "/locale") == 0)              main += ".dtd";        }        finalString += main;    }    else        finalString += remaining;    char* finalURI = finalString.ToNewCString();    aChromeURL->SetSpec(finalURI);    nsCRT::free(finalURI);    return NS_OK;}