Fix to make jar protocol not copy local files. Starting to get chrome to work with jars. Bug #18433

This commit is contained in:
warren%netscape.com 2000-06-02 23:39:45 +00:00
Родитель 57120eaa68
Коммит 870a7d208a
22 изменённых файлов: 150 добавлений и 107 удалений

Просмотреть файл

@ -325,9 +325,9 @@ nsDateTimeChannel::SetBufferMaxSize(PRUint32 aBufferMaxSize)
}
NS_IMETHODIMP
nsDateTimeChannel::GetShouldCache(PRBool *aShouldCache)
nsDateTimeChannel::GetLocalFile(nsIFile* *file)
{
*aShouldCache = PR_FALSE;
*file = nsnull;
return NS_OK;
}

Просмотреть файл

@ -361,9 +361,9 @@ nsFingerChannel::SetBufferMaxSize(PRUint32 aBufferMaxSize)
}
NS_IMETHODIMP
nsFingerChannel::GetShouldCache(PRBool *aShouldCache)
nsFingerChannel::GetLocalFile(nsIFile* *file)
{
*aShouldCache = PR_FALSE;
*file = nsnull;
return NS_OK;
}

Просмотреть файл

@ -506,9 +506,9 @@ nsMsgProtocol::SetBufferMaxSize(PRUint32 aBufferMaxSize)
}
NS_IMETHODIMP
nsMsgProtocol::GetShouldCache(PRBool *aShouldCache)
nsMsgProtocol::GetLocalFile(nsIFile* *file)
{
NS_NOTREACHED("GetShouldCache");
NS_NOTREACHED("GetLocalFile");
return NS_ERROR_NOT_IMPLEMENTED;
}

Просмотреть файл

@ -445,9 +445,9 @@ nsMailtoChannel::SetBufferMaxSize(PRUint32 aBufferMaxSize)
}
NS_IMETHODIMP
nsMailtoChannel::GetShouldCache(PRBool *aShouldCache)
nsMailtoChannel::GetLocalFile(nsIFile* *file)
{
NS_NOTREACHED("GetShouldCache");
NS_NOTREACHED("GetLocalFile");
return NS_ERROR_NOT_IMPLEMENTED;
}

Просмотреть файл

@ -6807,9 +6807,9 @@ nsImapMockChannel::SetBufferMaxSize(PRUint32 aBufferMaxSize)
}
NS_IMETHODIMP
nsImapMockChannel::GetShouldCache(PRBool *aShouldCache)
nsImapMockChannel::GetLocalFile(nsIFile* *file)
{
NS_NOTREACHED("GetShouldCache");
NS_NOTREACHED("GetLocalFile");
return NS_ERROR_NOT_IMPLEMENTED;
}

Просмотреть файл

@ -33,6 +33,12 @@
#include "nsIAggregatePrincipal.h"
#include "nsXPIDLString.h"
#ifdef NS_USE_CACHE_MANAGER_FOR_JAR
#include "nsINetDataCacheManager.h"
#include "nsICachedNetData.h"
#include "nsIStreamAsFile.h"
#endif
static NS_DEFINE_CID(kFileTransportServiceCID, NS_FILETRANSPORTSERVICE_CID);
static NS_DEFINE_CID(kMIMEServiceCID, NS_MIMESERVICE_CID);
static NS_DEFINE_CID(kZipReaderCID, NS_ZIPREADER_CID);
@ -379,6 +385,14 @@ nsJARChannel::EnsureJARFileAvailable(OnJARFileAvailableFun onJARFileAvailable,
nsCOMPtr<nsIChannel> jarCacheTransport;
nsCOMPtr<nsIInputStream> jarBaseIn;
#ifdef NS_USE_CACHE_MANAGER_FOR_JAR
nsCOMPtr<nsINetDataCacheManager> cacheMgr;
nsXPIDLCString jarBaseSpec;
nsCOMPtr<nsICachedNetData> cachedData;
nsCOMPtr<nsIStreamAsFile> streamAsFile;
nsCOMPtr<nsIFile> file;
#endif
#ifdef PR_LOGGING
nsXPIDLCString jarURLStr;
mURI->GetSpec(getter_Copies(jarURLStr));
@ -412,17 +426,45 @@ nsJARChannel::EnsureJARFileAvailable(OnJARFileAvailableFun onJARFileAvailable,
rv = mURI->GetJAREntry(&mJAREntry);
if (NS_FAILED(rv)) goto error;
#ifdef NS_USE_CACHE_MANAGER_FOR_JAR
cacheMgr = do_GetService(NS_NETWORK_CACHE_MANAGER_PROGID, &rv);
if (NS_FAILED(rv)) goto error;
rv = mJARBaseURI->GetSpec(getter_Copies(jarBaseSpec));
if (NS_FAILED(rv)) goto error;
rv = cacheMgr->GetCachedNetData(jarBaseSpec, nsnull, 0, nsINetDataCacheManager::CACHE_AS_FILE,
getter_AddRefs(cachedData));
if (NS_SUCCEEDED(rv)) {
streamAsFile = do_QueryInterface(cachedData, &rv);
if (NS_FAILED(rv)) goto error;
rv = streamAsFile->GetFile(getter_AddRefs(file));
if (NS_FAILED(rv)) goto error;
}
#endif
rv = NS_OpenURI(getter_AddRefs(jarBaseChannel), mJARBaseURI, nsnull);
if (NS_FAILED(rv)) goto error;
PRBool shouldCache;
rv = jarBaseChannel->GetShouldCache(&shouldCache);
if (NS_SUCCEEDED(rv) && !shouldCache) {
rv = jarBaseChannel->GetLocalFile(getter_AddRefs(jarCacheFile));
if (NS_SUCCEEDED(rv)) {
// Case 1: Local file
// we've already got a local jar file -- no need to download it
mJARBaseFile = do_QueryInterface(jarBaseChannel, &rv); // XXX fails for resource:
if (NS_FAILED(rv)) goto error;
rv = NS_NewLocalFileChannel(getter_AddRefs(mJARBaseFile),
jarCacheFile, PR_RDONLY, 0);
if (NS_FAILED(rv)) return rv;
rv = mJARBaseFile->SetBufferSegmentSize(mBufferSegmentSize);
if (NS_FAILED(rv)) return rv;
rv = mJARBaseFile->SetBufferMaxSize(mBufferMaxSize);
if (NS_FAILED(rv)) return rv;
rv = mJARBaseFile->SetLoadAttributes(mLoadAttributes);
if (NS_FAILED(rv)) return rv;
rv = mJARBaseFile->SetNotificationCallbacks(mCallbacks);
if (NS_FAILED(rv)) return rv;
PR_LOG(gJarProtocolLog, PR_LOG_DEBUG,
("nsJarProtocol: extracting local jar file %s", (const char*)jarURLStr));
rv = onJARFileAvailable(this, closure);
@ -747,12 +789,9 @@ nsJARChannel::SetBufferMaxSize(PRUint32 aBufferMaxSize)
}
NS_IMETHODIMP
nsJARChannel::GetShouldCache(PRBool *aShouldCache)
nsJARChannel::GetLocalFile(nsIFile* *file)
{
// Jar files report that you shouldn't cache them because this is really
// a question about the jar entry, and the jar entry is always in a jar
// file on disk.
*aShouldCache = PR_FALSE;
*file = nsnull;
return NS_OK;
}

Просмотреть файл

@ -182,14 +182,9 @@ interface nsIChannel : nsIRequest
attribute unsigned long bufferMaxSize;
/**
* Returns true if the data from this channel should be cached. Local files
* report false because they exist on the local disk and need not be cached.
* Input stream channels, data protocol, datetime protocol and finger
* protocol channels also should not be cached. Http and ftp on the other
* hand should. Note that the value of this attribute doesn't reflect any
* http headers that may specify that this channel should not be cached.
* Returns a local file to the channel's data if one exists, null otherwise.
*/
readonly attribute boolean shouldCache;
readonly attribute nsIFile localFile;
/**
* Setting pipeliningAllowed causes the load of a URL (issued via asyncOpen,

Просмотреть файл

@ -1032,9 +1032,16 @@ nsFileTransport::SetBufferMaxSize(PRUint32 aBufferMaxSize)
}
NS_IMETHODIMP
nsFileTransport::GetShouldCache(PRBool *aShouldCache)
nsFileTransport::GetLocalFile(nsIFile* *file)
{
*aShouldCache = PR_FALSE;
nsresult rv;
nsCOMPtr<nsIFileIO> fileIO = do_QueryInterface(mStreamIO, &rv);
if (NS_FAILED(rv)) return rv;
rv = fileIO->GetFile(file);
if (NS_FAILED(rv)) {
*file = nsnull;
}
return NS_OK;
}

Просмотреть файл

@ -530,9 +530,9 @@ nsStreamIOChannel::SetBufferMaxSize(PRUint32 aBufferMaxSize)
}
NS_IMETHODIMP
nsStreamIOChannel::GetShouldCache(PRBool *aShouldCache)
nsStreamIOChannel::GetLocalFile(nsIFile* *file)
{
*aShouldCache = PR_FALSE;
*file = nsnull;
return NS_OK;
}

Просмотреть файл

@ -2165,24 +2165,24 @@ nsSocketTransport::SetBufferMaxSize(PRUint32 aBufferMaxSize)
}
NS_IMETHODIMP
nsSocketTransport::GetShouldCache(PRBool *aShouldCache)
nsSocketTransport::GetLocalFile(nsIFile* *file)
{
*aShouldCache = PR_TRUE;
return NS_OK;
*file = nsnull;
return NS_OK;
}
NS_IMETHODIMP
nsSocketTransport::GetPipeliningAllowed(PRBool *aPipeliningAllowed)
{
*aPipeliningAllowed = PR_FALSE;
return NS_OK;
*aPipeliningAllowed = PR_FALSE;
return NS_OK;
}
NS_IMETHODIMP
nsSocketTransport::SetPipeliningAllowed(PRBool aPipeliningAllowed)
{
NS_NOTREACHED("SetPipeliningAllowed");
return NS_ERROR_NOT_IMPLEMENTED;
NS_NOTREACHED("SetPipeliningAllowed");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP

Просмотреть файл

@ -561,9 +561,10 @@ nsDiskCacheRecordChannel::SetBufferMaxSize(PRUint32 aBufferMaxSize)
}
NS_IMETHODIMP
nsDiskCacheRecordChannel::GetShouldCache(PRBool *aShouldCache)
nsDiskCacheRecordChannel::GetLocalFile(nsIFile* *file)
{
*aShouldCache = PR_FALSE;
*file = mSpec;
NS_ADDREF(*file);
return NS_OK;
}

2
netwerk/cache/filecache/nsNetDiskCache.cpp поставляемый
Просмотреть файл

@ -137,7 +137,7 @@ nsNetDiskCache::nsNetDiskCache() :
nsNetDiskCache::~nsNetDiskCache()
{
if ( mDB )
if ( mDB )
SetSizeEntry();
NS_IF_RELEASE(mDB) ;

Просмотреть файл

@ -539,9 +539,9 @@ nsMemCacheChannel::SetBufferMaxSize(PRUint32 aBufferMaxSize)
}
NS_IMETHODIMP
nsMemCacheChannel::GetShouldCache(PRBool *aShouldCache)
nsMemCacheChannel::GetLocalFile(nsIFile* *file)
{
*aShouldCache = PR_FALSE;
*file = nsnull;
return NS_OK;
}

58
netwerk/cache/mgr/nsCacheManager.cpp поставляемый
Просмотреть файл

@ -92,13 +92,13 @@ nsCacheManager::~nsCacheManager()
delete mActiveCacheRecords;
delete mMemSpaceManager;
delete mDiskSpaceManager;
nsresult rv;
NS_WITH_SERVICE(nsIPref, prefs, NS_PREF_PROGID, &rv);
if ( NS_SUCCEEDED (rv ) )
{
prefs->UnregisterCallback( CACHE_DISK_CAPACITY, diskCacheSizeChanged, this);
prefs->UnregisterCallback( CACHE_MEM_CAPACITY, memCacheSizeChanged, this);
}
nsresult rv;
NS_WITH_SERVICE(nsIPref, prefs, NS_PREF_PROGID, &rv);
if ( NS_SUCCEEDED (rv ) )
{
prefs->UnregisterCallback( CACHE_DISK_CAPACITY, diskCacheSizeChanged, this);
prefs->UnregisterCallback( CACHE_MEM_CAPACITY, memCacheSizeChanged, this);
}
}
@ -117,7 +117,7 @@ nsresult nsCacheManager::InitPrefs()
return rv;
// Init the prefs
diskCacheSizeChanged( CACHE_DISK_CAPACITY, this );
memCacheSizeChanged( CACHE_MEM_CAPACITY, this );
memCacheSizeChanged( CACHE_MEM_CAPACITY, this );
return rv;
}
@ -196,8 +196,8 @@ nsCacheManager::Init()
if (NS_FAILED(rv)) return rv;
}
InitPrefs();
return NS_OK;
InitPrefs();
return NS_OK;
}
nsresult nsCacheManager::GetCacheAndReplacementPolicy( PRUint32 aFlags, nsINetDataCache*& cache, nsReplacementPolicy *&spaceManager )
@ -206,25 +206,25 @@ nsresult nsCacheManager::GetCacheAndReplacementPolicy( PRUint32 aFlags, nsINetDa
if ( mDiskCache.get() )
mDiskCache->GetEnabled( &diskCacheEnabled );
if (aFlags & CACHE_AS_FILE) {
if ( diskCacheEnabled )
cache = mDiskCache;
if (aFlags & CACHE_AS_FILE) {
if ( diskCacheEnabled )
cache = mDiskCache;
else
cache = NULL;
spaceManager = mDiskSpaceManager;
return NS_ERROR_NOT_AVAILABLE;
spaceManager = mDiskSpaceManager;
// Ensure that cache is initialized
if (mDiskCacheCapacity == (PRUint32)-1)
return NS_ERROR_NOT_AVAILABLE;
// Ensure that cache is initialized
if (mDiskCacheCapacity == (PRUint32)-1)
return NS_ERROR_NOT_AVAILABLE;
} else if ((aFlags & BYPASS_PERSISTENT_CACHE) ||
( !mDiskCache && !mFlatCache) || !mDiskCacheCapacity || !diskCacheEnabled) {
cache = mMemCache;
spaceManager = mMemSpaceManager;
} else {
cache = mFlatCache ? mFlatCache : mDiskCache;
spaceManager = mDiskSpaceManager;
}
} else if ((aFlags & BYPASS_PERSISTENT_CACHE) ||
( !mDiskCache && !mFlatCache) || !mDiskCacheCapacity || !diskCacheEnabled) {
cache = mMemCache;
spaceManager = mMemSpaceManager;
} else {
cache = mFlatCache ? mFlatCache : mDiskCache;
spaceManager = mDiskSpaceManager;
}
return NS_OK;
}
@ -238,9 +238,9 @@ nsCacheManager::GetCachedNetData(const char *aUriSpec, const char *aSecondaryKey
nsINetDataCache *cache;
nsReplacementPolicy *spaceManager;
rv = GetCacheAndReplacementPolicy( aFlags, cache, spaceManager );
if ( NS_FAILED ( rv ) )
return rv;
rv = GetCacheAndReplacementPolicy( aFlags, cache, spaceManager );
if (NS_FAILED(rv))
return rv;
// Construct the cache key by appending the secondary key to the URI spec
nsCAutoString cacheKey(aUriSpec);

Просмотреть файл

@ -21,10 +21,10 @@
*/
#include "nsISupports.idl"
#include "nsINetDataCache.idl"
interface nsISimpleEnumerator;
interface nsICachedNetData;
interface nsINetDataCache;
interface nsINetDataDiskCache;
interface nsIURI;
@ -137,12 +137,12 @@ interface nsINetDataCacheManager : nsISupports
* even those in active use, will be deleted. Also, any global cache
* database files will be deleted.
*/
void RemoveAll();
void removeAll();
/**
* Clears the specified cache
*/
void Clear( in PRUint32 aCacheToClear );
void clear( in PRUint32 aCacheToClear );
/**
* The disk cache is made up of the file cache (for stream-as-file

6
netwerk/cache/public/nsIStreamAsFile.idl поставляемый
Просмотреть файл

@ -100,7 +100,7 @@ interface nsIStreamAsFileObserver : nsISupports
* as the cache manager will effectively relinquished ownership of the
* file.
*/
void ObserveStreamAsFile(in nsIStreamAsFile aStreamAsFile,
in PRUint32 aMessage,
in nsresult aError);
void observeStreamAsFile(in nsIStreamAsFile aStreamAsFile,
in PRUint32 aMessage,
in nsresult aError);
};

Просмотреть файл

@ -473,9 +473,9 @@ nsDataChannel::SetBufferMaxSize(PRUint32 aBufferMaxSize)
}
NS_IMETHODIMP
nsDataChannel::GetShouldCache(PRBool *aShouldCache)
nsDataChannel::GetLocalFile(nsIFile* *file)
{
*aShouldCache = PR_FALSE;
*file = nsnull;
return NS_OK;
}

Просмотреть файл

@ -325,9 +325,9 @@ nsDateTimeChannel::SetBufferMaxSize(PRUint32 aBufferMaxSize)
}
NS_IMETHODIMP
nsDateTimeChannel::GetShouldCache(PRBool *aShouldCache)
nsDateTimeChannel::GetLocalFile(nsIFile* *file)
{
*aShouldCache = PR_FALSE;
*file = nsnull;
return NS_OK;
}

Просмотреть файл

@ -526,9 +526,10 @@ nsFileChannel::SetBufferMaxSize(PRUint32 aBufferMaxSize)
}
NS_IMETHODIMP
nsFileChannel::GetShouldCache(PRBool *aShouldCache)
nsFileChannel::GetLocalFile(nsIFile* *file)
{
*aShouldCache = PR_FALSE;
*file = mFile;
NS_ADDREF(*file);
return NS_OK;
}

Просмотреть файл

@ -361,9 +361,9 @@ nsFingerChannel::SetBufferMaxSize(PRUint32 aBufferMaxSize)
}
NS_IMETHODIMP
nsFingerChannel::GetShouldCache(PRBool *aShouldCache)
nsFingerChannel::GetLocalFile(nsIFile* *file)
{
*aShouldCache = PR_FALSE;
*file = nsnull;
return NS_OK;
}

Просмотреть файл

@ -516,9 +516,9 @@ nsFTPChannel::SetBufferMaxSize(PRUint32 aBufferMaxSize)
}
NS_IMETHODIMP
nsFTPChannel::GetShouldCache(PRBool *aShouldCache)
nsFTPChannel::GetLocalFile(nsIFile* *file)
{
*aShouldCache = PR_TRUE;
*file = nsnull;
return NS_OK;
}

Просмотреть файл

@ -1,4 +1,4 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
@ -502,9 +502,9 @@ nsHTTPChannel::SetBufferMaxSize(PRUint32 aBufferMaxSize)
}
NS_IMETHODIMP
nsHTTPChannel::GetShouldCache(PRBool *aShouldCache)
nsHTTPChannel::GetLocalFile(nsIFile* *file)
{
*aShouldCache = PR_TRUE;
*file = nsnull; // XXX should we return the cache file here?
return NS_OK;
}
@ -880,25 +880,25 @@ nsHTTPChannel::CheckCache()
if (NS_FAILED(rv)) return rv;
NS_ASSERTION(mCacheEntry,
"Cache manager must always return cache entry");
"Cache manager must always return cache entry");
if (!mCacheEntry)
return NS_ERROR_FAILURE;
}
// Hook up stream as listener
nsCOMPtr<nsIStreamAsFile> streamAsFile( do_QueryInterface( mCacheEntry ) );
if ( streamAsFile )
{
nsCOMPtr< nsIStreamAsFileObserver> observer;
PRUint32 count = 0;
mStreamAsFileObserverArray->Count( & count );
for ( PRUint32 i=0; i< count; i++ )
{
mStreamAsFileObserverArray->GetElementAt( i, getter_AddRefs( observer ) );
streamAsFile->AddObserver( observer );
}
if ( streamAsFile )
{
nsCOMPtr< nsIStreamAsFileObserver> observer;
PRUint32 count = 0;
mStreamAsFileObserverArray->Count( & count );
for ( PRUint32 i=0; i< count; i++ )
{
mStreamAsFileObserverArray->GetElementAt( i, getter_AddRefs( observer ) );
streamAsFile->AddObserver( observer );
}
}
}
// Be pessimistic: Assume cache entry has no useful data
mCachedContentIsAvailable = mCachedContentIsValid = PR_FALSE;
@ -947,7 +947,7 @@ nsHTTPChannel::CheckCache()
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(mCachedResponse);
nsSubsumeCStr cachedHeadersCStr(NS_CONST_CAST(char*,
NS_STATIC_CAST(const char*, cachedHeaders)),
NS_STATIC_CAST(const char*, cachedHeaders)),
PR_FALSE);
rv = mCachedResponse->ParseHeaders(cachedHeadersCStr);
if (NS_FAILED(rv)) return rv;
@ -969,7 +969,7 @@ nsHTTPChannel::CheckCache()
PRBool mustRevalidate = PR_FALSE;
nsXPIDLCString header;
mCachedResponse->GetHeader(nsHTTPAtoms::Cache_Control,
getter_Copies(header));
getter_Copies(header));
if (header) {
PRInt32 offset;
@ -1024,7 +1024,7 @@ nsHTTPChannel::CheckCache()
// Add If-Modified-Since header
nsXPIDLCString lastModified;
mCachedResponse->GetHeader(nsHTTPAtoms::Last_Modified,
getter_Copies(lastModified));
getter_Copies(lastModified));
if (lastModified)
SetRequestHeader(nsHTTPAtoms::If_Modified_Since, lastModified);