nsresult rv = NS_OK; NS_ASSERTION(aChromeURL, "null url!"); if (!aChromeURL) return NS_ERROR_NULL_POINTER;       nsCAutoString package, provider, remaining;  rv = SplitURL(aChromeURL, package, provider, remaining); if (NS_FAILED(rv)) return rv;    if (!mProfileInitialized) { rv = LoadProfileDataSource(); if (NS_FAILED(rv)) return rv; } if (!mInstallInitialized) { rv = LoadInstallDataSource(); if (NS_FAILED(rv)) return rv; }  nsCAutoString finalURL;  rv = GetOverrideURL(package, provider, remaining, finalURL); if (NS_SUCCEEDED(rv))
nsXPIDLCString spec; aChromeURL->GetSpec(getter_Copies(spec));  nsresult rv = NS_OK; NS_ASSERTION(aChromeURL, "null url!"); if (!aChromeURL) return NS_ERROR_NULL_POINTER;  #ifdef NS_DEBUG  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   nsXPIDLCString package, provider, remaining;  #if 0 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  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     nsString lookup("chrome:  lookup += package;  NS_ASSERTION(*provider == '/', "No leading slash here!");   if (*provider != '/') lookup += '/'; lookup += provider;   if (lookup.CharAt(lookup.Length()-1) != '/') lookup += '/';   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; }     nsString base, name, main;  rv = GetChromeResource(name, chromeResource, kCHROME_name); if (NS_FAILED (rv)) {  }  rv = GetChromeResource(base, chromeResource, kCHROME_base); if (NS_FAILED(rv)) {  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 += '/';   nsString finalString(base);  if (!remaining || (0 == PL_strlen(remaining))) { rv = GetChromeResource(main, chromeResource, kCHROME_main); if (NS_FAILED(rv)) {  NS_ERROR("Unable to retrieve the main file registry entry for a chrome URL."); return rv; } finalString += main; } else finalString += remaining;  char* finalURI = finalString.ToNewCString(); printf("FROM:%s\n",(const char*) spec); printf("TO:%s\n\n",finalURI); aChromeURL->SetSpec(finalURI); /* #ifndef NECKO  char* path; rv = aChromeURL->GetPath(&path); char* cleanPath = path; for (; '\0' != *path; ++path) { if (*path == '/' && *(path+1) == '/') ++path; *cleanPath++ = *path; } aChrome->SetRelativePath(path); nsCRT::free(path); #endif */ nsCRT::free(finalURI);
nsChromeRegistry::ConvertChromeURL(nsIURI* aChromeURL, nsACString& aResult){  nsresult rv = NS_OK;  NS_ASSERTION(aChromeURL, "null url!");  if (!aChromeURL)      return NS_ERROR_NULL_POINTER;  // No need to canonify as the SplitURL() that we  // do is the equivalent of canonification without modifying  // aChromeURL  // Obtain the package, provider and remaining from the URL  nsCAutoString package, provider, remaining;  rv = SplitURL(aChromeURL, package, provider, remaining);  if (NS_FAILED(rv)) return rv;  // Try for the profile data source first because it  // will load the install data source as well.  if (!mProfileInitialized) {    rv = LoadProfileDataSource();    if (NS_FAILED(rv)) return rv;  }  if (!mInstallInitialized) {    rv = LoadInstallDataSource();    if (NS_FAILED(rv)) return rv;  }  nsCAutoString finalURL;  rv = GetOverrideURL(package, provider, remaining, finalURL);  if (NS_SUCCEEDED(rv))    return NS_OK;    rv = GetBaseURL(package, provider, finalURL);#ifdef DEBUG  if (NS_FAILED(rv)) {    nsCAutoString msg("chrome: failed to get base url");    nsCAutoString url;    rv = aChromeURL->GetSpec(url);    if (NS_SUCCEEDED(rv)) {      msg += " for ";      msg += url.get();    }    msg += " -- using wacky default";    NS_WARNING(msg.get());  }#endif  if (finalURL.IsEmpty()) {    // hard-coded fallback    if (provider.Equals("skin")) {      finalURL = "resource:/chrome/skins/classic/";    }    else if (provider.Equals("locale")) {      finalURL = "resource:/chrome/locales/en-US/";    }    else if (package.Equals("aim")) {      finalURL = "resource:/chrome/packages/aim/";    }    else if (package.Equals("messenger")) {      finalURL = "resource:/chrome/packages/messenger/";    }    else if (package.Equals("global")) {      finalURL = "resource:/chrome/packages/widget-toolkit/";    }    else {      finalURL = "resource:/chrome/packages/core/";    }  }  aResult = finalURL + remaining;  return NS_OK;}