Exemplo n.º 1
0
nsresult
nsResProtocolHandler::Init(nsIFile *aOmniJar)
{
    nsresult rv;
    nsCOMPtr<nsIURI> uri;
    nsCAutoString omniJarSpec;
    NS_GetURLSpecFromActualFile(aOmniJar, omniJarSpec, mIOService);

    nsCAutoString urlStr("jar:");
    urlStr += omniJarSpec;
    urlStr += "!/";

    rv = mIOService->NewURI(urlStr, nsnull, nsnull, getter_AddRefs(uri));
    NS_ENSURE_SUCCESS(rv, rv);

    // these entries should be kept in sync with the normal Init function

    // resource:/// points to jar:omni.jar!/
    SetSubstitution(EmptyCString(), uri);

    // resource://gre/ points to jar:omni.jar!/
    SetSubstitution(kGRE, uri);

    urlStr += "chrome/toolkit/res/";
    rv = mIOService->NewURI(urlStr, nsnull, nsnull, getter_AddRefs(uri));
    NS_ENSURE_SUCCESS(rv, rv);

    // resource://gre-resources/ points to jar:omni.jar!/chrome/toolkit/res/
    SetSubstitution(kGRE_RESOURCES, uri);
    return NS_OK;
}
Exemplo n.º 2
0
nsresult
Omnijar::GetURIString(Type aType, nsACString& aResult)
{
  NS_ABORT_IF_FALSE(IsInitialized(), "Omnijar not initialized");

  aResult.Truncate();

  // Return an empty string for APP in the unified case.
  if ((aType == APP) && sIsUnified) {
    return NS_OK;
  }

  nsAutoCString omniJarSpec;
  if (sPath[aType]) {
    nsresult rv = NS_GetURLSpecFromActualFile(sPath[aType], omniJarSpec);
    if (NS_WARN_IF(NS_FAILED(rv))) {
      return rv;
    }

    aResult = "jar:";
    if (sIsNested[aType]) {
      aResult += "jar:";
    }
    aResult += omniJarSpec;
    aResult += "!";
    if (sIsNested[aType]) {
      aResult += "/" NS_STRINGIFY(OMNIJAR_NAME) "!";
    }
  } else {
    nsCOMPtr<nsIFile> dir;
    nsDirectoryService::gService->Get(SPROP(aType), NS_GET_IID(nsIFile),
                                      getter_AddRefs(dir));
    nsresult rv = NS_GetURLSpecFromActualFile(dir, aResult);
    if (NS_WARN_IF(NS_FAILED(rv))) {
      return rv;
    }
  }
  aResult += "/";
  return NS_OK;
}