зеркало из https://github.com/mozilla/pjs.git
Fix to make jar protocol not copy local files. Starting to get chrome to work with jars. Bug #18433
This commit is contained in:
Родитель
870a7d208a
Коммит
ddce19c8d3
|
@ -380,10 +380,10 @@ nsCachedChromeChannel::SetBufferMaxSize(PRUint32 aBufferMaxSize)
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCachedChromeChannel::GetShouldCache(PRBool *aShouldCache)
|
||||
nsCachedChromeChannel::GetLocalFile(nsIFile* *file)
|
||||
{
|
||||
NS_NOTREACHED("GetShouldCache");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
*file = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
|
|
@ -451,7 +451,10 @@ nsChromeRegistry::ConvertChromeURL(nsIURI* aChromeURL, char** aResult)
|
|||
}
|
||||
|
||||
nsCAutoString finalURL;
|
||||
GetBaseURL(package, provider, finalURL);
|
||||
rv = GetBaseURL(package, provider, finalURL);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_WARNING("chrome: failed to get base url -- using wacky default");
|
||||
}
|
||||
if (finalURL.IsEmpty()) {
|
||||
// hard-coded fallback
|
||||
if (provider.Equals("skin")) {
|
||||
|
@ -529,11 +532,10 @@ nsChromeRegistry::GetBaseURL(const nsCString& aPackage, const nsCString& aProvid
|
|||
}
|
||||
|
||||
// From this resource, follow the "baseURL" arc.
|
||||
nsChromeRegistry::FollowArc(mChromeDataSource,
|
||||
aBaseURL,
|
||||
resource,
|
||||
mBaseURL);
|
||||
return NS_OK;
|
||||
return nsChromeRegistry::FollowArc(mChromeDataSource,
|
||||
aBaseURL,
|
||||
resource,
|
||||
mBaseURL);
|
||||
}
|
||||
|
||||
// locate
|
||||
|
|
|
@ -346,7 +346,7 @@ public:
|
|||
NS_IMETHOD SetBufferSegmentSize(PRUint32 aBufferSegmentSize) { NS_NOTREACHED("SetBufferSegmentSize"); return NS_ERROR_NOT_IMPLEMENTED; }
|
||||
NS_IMETHOD GetBufferMaxSize(PRUint32 *aBufferMaxSize) { NS_NOTREACHED("GetBufferMaxSize"); return NS_ERROR_NOT_IMPLEMENTED; }
|
||||
NS_IMETHOD SetBufferMaxSize(PRUint32 aBufferMaxSize) { NS_NOTREACHED("SetBufferMaxSize"); return NS_ERROR_NOT_IMPLEMENTED; }
|
||||
NS_IMETHOD GetShouldCache(PRBool *aShouldCache) { NS_NOTREACHED("GetShouldCache"); return NS_ERROR_NOT_IMPLEMENTED; }
|
||||
NS_IMETHOD GetLocalFile(nsIFile* *result) { NS_NOTREACHED("GetLocalFile"); return NS_ERROR_NOT_IMPLEMENTED; }
|
||||
NS_IMETHOD GetPipeliningAllowed(PRBool *aPipeliningAllowed) { *aPipeliningAllowed = PR_FALSE; return NS_OK; }
|
||||
NS_IMETHOD SetPipeliningAllowed(PRBool aPipeliningAllowed) { NS_NOTREACHED("SetPipeliningAllowed"); return NS_ERROR_NOT_IMPLEMENTED; }
|
||||
NS_IMETHOD GetOwner(nsISupports * *aOwner) { *aOwner = nsnull; return NS_OK; }
|
||||
|
|
|
@ -504,7 +504,10 @@ nsHTTPChannel::SetBufferMaxSize(PRUint32 aBufferMaxSize)
|
|||
NS_IMETHODIMP
|
||||
nsHTTPChannel::GetLocalFile(nsIFile* *file)
|
||||
{
|
||||
*file = nsnull; // XXX should we return the cache file here?
|
||||
nsresult rv;
|
||||
rv = GetFile(file);
|
||||
if (NS_FAILED(rv))
|
||||
*file = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -639,12 +639,30 @@ nsResChannel::SetBufferMaxSize(PRUint32 aBufferMaxSize)
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsResChannel::GetShouldCache(PRBool *aShouldCache)
|
||||
nsResChannel::GetLocalFile(nsIFile* *result)
|
||||
{
|
||||
if (mResolvedChannel) {
|
||||
mResolvedChannel->GetShouldCache(aShouldCache);
|
||||
}
|
||||
*aShouldCache = PR_TRUE;
|
||||
nsresult rv;
|
||||
rv = mSubstitutions.Init();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIFile> file;
|
||||
do {
|
||||
rv = EnsureNextResolvedChannel();
|
||||
if (NS_FAILED(rv)) break;
|
||||
|
||||
if (mResolvedChannel) {
|
||||
rv = mResolvedChannel->GetLocalFile(getter_AddRefs(file));
|
||||
PRBool exists;
|
||||
rv = file->Exists(&exists);
|
||||
if (NS_SUCCEEDED(rv) && exists) {
|
||||
*result = file;
|
||||
NS_ADDREF(*result);
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
} while (NS_FAILED(rv));
|
||||
|
||||
*result = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -380,10 +380,10 @@ nsCachedChromeChannel::SetBufferMaxSize(PRUint32 aBufferMaxSize)
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCachedChromeChannel::GetShouldCache(PRBool *aShouldCache)
|
||||
nsCachedChromeChannel::GetLocalFile(nsIFile* *file)
|
||||
{
|
||||
NS_NOTREACHED("GetShouldCache");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
*file = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
|
|
@ -451,7 +451,10 @@ nsChromeRegistry::ConvertChromeURL(nsIURI* aChromeURL, char** aResult)
|
|||
}
|
||||
|
||||
nsCAutoString finalURL;
|
||||
GetBaseURL(package, provider, finalURL);
|
||||
rv = GetBaseURL(package, provider, finalURL);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_WARNING("chrome: failed to get base url -- using wacky default");
|
||||
}
|
||||
if (finalURL.IsEmpty()) {
|
||||
// hard-coded fallback
|
||||
if (provider.Equals("skin")) {
|
||||
|
@ -529,11 +532,10 @@ nsChromeRegistry::GetBaseURL(const nsCString& aPackage, const nsCString& aProvid
|
|||
}
|
||||
|
||||
// From this resource, follow the "baseURL" arc.
|
||||
nsChromeRegistry::FollowArc(mChromeDataSource,
|
||||
aBaseURL,
|
||||
resource,
|
||||
mBaseURL);
|
||||
return NS_OK;
|
||||
return nsChromeRegistry::FollowArc(mChromeDataSource,
|
||||
aBaseURL,
|
||||
resource,
|
||||
mBaseURL);
|
||||
}
|
||||
|
||||
// locate
|
||||
|
|
|
@ -346,7 +346,7 @@ public:
|
|||
NS_IMETHOD SetBufferSegmentSize(PRUint32 aBufferSegmentSize) { NS_NOTREACHED("SetBufferSegmentSize"); return NS_ERROR_NOT_IMPLEMENTED; }
|
||||
NS_IMETHOD GetBufferMaxSize(PRUint32 *aBufferMaxSize) { NS_NOTREACHED("GetBufferMaxSize"); return NS_ERROR_NOT_IMPLEMENTED; }
|
||||
NS_IMETHOD SetBufferMaxSize(PRUint32 aBufferMaxSize) { NS_NOTREACHED("SetBufferMaxSize"); return NS_ERROR_NOT_IMPLEMENTED; }
|
||||
NS_IMETHOD GetShouldCache(PRBool *aShouldCache) { NS_NOTREACHED("GetShouldCache"); return NS_ERROR_NOT_IMPLEMENTED; }
|
||||
NS_IMETHOD GetLocalFile(nsIFile* *result) { NS_NOTREACHED("GetLocalFile"); return NS_ERROR_NOT_IMPLEMENTED; }
|
||||
NS_IMETHOD GetPipeliningAllowed(PRBool *aPipeliningAllowed) { *aPipeliningAllowed = PR_FALSE; return NS_OK; }
|
||||
NS_IMETHOD SetPipeliningAllowed(PRBool aPipeliningAllowed) { NS_NOTREACHED("SetPipeliningAllowed"); return NS_ERROR_NOT_IMPLEMENTED; }
|
||||
NS_IMETHOD GetOwner(nsISupports * *aOwner) { *aOwner = nsnull; return NS_OK; }
|
||||
|
|
Загрузка…
Ссылка в новой задаче