Bug 1036394 - Add support for getting the zip entry from the jar channel, r=jduell

This commit is contained in:
Michael Wu 2014-08-04 11:54:28 -04:00
parent f9d25b2e98
commit 2a5fa39618
4 changed files with 48 additions and 1 deletions

View File

@ -6,8 +6,9 @@
#include "nsIChannel.idl"
interface nsIFile;
interface nsIZipEntry;
[scriptable, builtinclass, uuid(5a4f8df0-3bd9-45c2-9db9-67e74c3dd47d)]
[scriptable, builtinclass, uuid(8cce289f-1671-452e-b9c3-3b7366ec8337)]
interface nsIJARChannel : nsIChannel
{
/**
@ -28,6 +29,12 @@ interface nsIJARChannel : nsIChannel
*/
readonly attribute nsIFile jarFile;
/**
* Returns the zip entry if the file is synchronously accessible.
* This will work even without opening the channel.
*/
readonly attribute nsIZipEntry zipEntry;
/**
* For child process, set this to make sure that a valid file descriptor of
* JAR file is always provided when calling NSPRFileDesc().

View File

@ -323,6 +323,9 @@ nsJARChannel::LookupFile()
{
LOG(("nsJARChannel::LookupFile [this=%x %s]\n", this, mSpec.get()));
if (mJarFile)
return NS_OK;
nsresult rv;
nsCOMPtr<nsIURI> uri;
@ -889,6 +892,24 @@ nsJARChannel::GetJarFile(nsIFile **aFile)
return NS_OK;
}
NS_IMETHODIMP
nsJARChannel::GetZipEntry(nsIZipEntry **aZipEntry)
{
nsresult rv = LookupFile();
if (NS_FAILED(rv))
return rv;
if (!mJarFile)
return NS_ERROR_NOT_AVAILABLE;
nsCOMPtr<nsIZipReader> reader;
rv = gJarHandler->JarCache()->GetZip(mJarFile, getter_AddRefs(reader));
if (NS_FAILED(rv))
return rv;
return reader->GetEntry(mJarEntry, aZipEntry);
}
NS_IMETHODIMP
nsJARChannel::EnsureChildFd()
{

View File

@ -87,6 +87,20 @@ add_test(testAsync);
// Run same test again so we test the codepath for a zipcache hit
add_test(testAsync);
/**
* Basic test for nsIZipReader.
* This relies on the jar cache to succeed in child processes.
*/
function testZipEntry() {
var uri = jarBase + "/inner40.zip";
var chan = ios.newChannel(uri, null, null).QueryInterface(Ci.nsIJARChannel);
var entry = chan.zipEntry;
do_check_true(entry.CRC32 == 0x8b635486);
do_check_true(entry.realSize == 184);
run_next_test();
}
add_test(testZipEntry);
// In e10s child processes we don't currently support
// 1) synchronously opening jar files on parent

View File

@ -127,6 +127,11 @@ NS_IMETHODIMP DummyChannel::GetJarFile(nsIFile* *aFile)
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP DummyChannel::GetZipEntry(nsIZipEntry* *aEntry)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP DummyChannel::EnsureChildFd()
{
return NS_ERROR_NOT_IMPLEMENTED;