fixes bug 151478 "https wyciwyg page is cached on disk" r=mstoltz sr=rpotts a=asa

This commit is contained in:
darin%netscape.com 2002-10-11 04:22:54 +00:00
parent 5a6988bce7
commit f8645f610d
6 changed files with 45 additions and 36 deletions

View File

@ -567,6 +567,7 @@ nsDocument::~nsDocument()
}
mPrincipal = nsnull;
mLoadFlags = nsIRequest::LOAD_NORMAL; // XXX maybe not required
mDocumentLoadGroup = nsnull;
mParentDocument = nsnull;
@ -752,6 +753,7 @@ nsDocument::Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup)
aChannel->GetOwner(getter_AddRefs(owner));
if (owner)
mPrincipal = do_QueryInterface(owner);
aChannel->GetLoadFlags(&mLoadFlags);
}
return rv;
@ -766,6 +768,7 @@ nsDocument::ResetToURI(nsIURI *aURI, nsILoadGroup *aLoadGroup)
NS_IF_RELEASE(mDocumentURL);
mPrincipal = nsnull;
mLoadFlags = nsIRequest::LOAD_NORMAL;
mDocumentLoadGroup = nsnull;
// Delete references to sub-documents and kill the subdocument map,

View File

@ -616,6 +616,7 @@ protected:
nsIURI* mDocumentURL;
nsCOMPtr<nsIURI> mDocumentBaseURL;
nsCOMPtr<nsIPrincipal> mPrincipal;
PRUint32 mLoadFlags; // load flags of the document's channel
nsWeakPtr mDocumentLoadGroup;
nsWeakPtr mDocumentContainer;

View File

@ -48,13 +48,13 @@
[scriptable, uuid (c36730c0-a3b9-4732-9973-c5e7dbe0dabe)]
interface nsIWyciwygChannel : nsIChannel
{
/* Open a cache stream */
void createCacheEntry(in string cacheKey);
/**
* Append data to the cache entry; opens the cache entry if necessary.
*/
void writeToCacheEntry(in ACString aScript);
/* write to the cache stream */
void writeToCache(in string aScript);
/* Close a cache stream */
/**
* Close the cache entry; subsequent writes have undefined behavior.
*/
void closeCacheEntry();
};
};

View File

@ -2629,7 +2629,7 @@ nsHTMLDocument::WriteCommon(const nsAString& aText,
// Save the data in cache
if (mWyciwygChannel) {
mWyciwygChannel->WriteToCache(NS_ConvertUCS2toUTF8(text).get());
mWyciwygChannel->WriteToCacheEntry(NS_ConvertUCS2toUTF8(text));
}
rv = mParser->Parse(text ,
@ -3981,9 +3981,10 @@ nsHTMLDocument::CreateAndAddWyciwygChannel(void)
nsCOMPtr<nsIChannel> channel;
// Create a wyciwyg Channel
rv = NS_NewChannel(getter_AddRefs(channel), wcwgURI);
if (NS_SUCCEEDED(rv) && channel) {
if (NS_SUCCEEDED(rv) && channel) {
mWyciwygChannel = do_QueryInterface(channel);
mWyciwygChannel->CreateCacheEntry(url.get());
// inherit load flags from the original document's channel
channel->SetLoadFlags(mLoadFlags);
}
nsCOMPtr<nsILoadGroup> loadGroup;

View File

@ -345,32 +345,30 @@ nsWyciwygChannel::AsyncOpen(nsIStreamListener * aListener, nsISupports * aConte
//////////////////////////////////////////////////////////////////////////////
NS_IMETHODIMP
nsWyciwygChannel::CreateCacheEntry(const char * aCacheKey)
nsWyciwygChannel::WriteToCacheEntry(const nsACString &aScript)
{
return OpenCacheEntry(aCacheKey, nsICache::ACCESS_WRITE);
}
nsresult rv;
NS_IMETHODIMP
nsWyciwygChannel::WriteToCache(const char * aScript)
{
if (!mCacheEntry)
return NS_ERROR_FAILURE;
PRUint32 len = strlen(aScript);
nsresult rv = NS_ERROR_FAILURE;
PRUint32 out;
if (!mCacheTransport && !mCacheOutputStream) {
//Get the transport from cache
rv = mCacheEntry->GetTransport(getter_AddRefs(mCacheTransport));
// Get the outputstream from the transport.
if (mCacheTransport)
rv = mCacheTransport->OpenOutputStream(0, PRUint32(-1), 0, getter_AddRefs(mCacheOutputStream));
if (!mCacheEntry) {
nsCAutoString spec;
rv = mURI->GetAsciiSpec(spec);
if (NS_FAILED(rv)) return rv;
rv = OpenCacheEntry(spec.get(), nsICache::ACCESS_WRITE);
if (NS_FAILED(rv)) return rv;
}
if (mCacheOutputStream)
rv = mCacheOutputStream->Write(aScript, len, &out);
return rv;
if (!mCacheOutputStream) {
//Get the transport from cache
rv = mCacheEntry->GetTransport(getter_AddRefs(mCacheTransport));
if (NS_FAILED(rv)) return rv;
// Get the outputstream from the transport.
rv = mCacheTransport->OpenOutputStream(0, PRUint32(-1), 0, getter_AddRefs(mCacheOutputStream));
if (NS_FAILED(rv)) return rv;
}
PRUint32 out;
return mCacheOutputStream->Write(PromiseFlatCString(aScript).get(), aScript.Length(), &out);
}
@ -533,9 +531,16 @@ nsWyciwygChannel::OpenCacheEntry(const char * aCacheKey, nsCacheAccessMode aAcce
nsXPIDLCString spec;
nsAutoString newURIString;
nsCOMPtr<nsICacheSession> cacheSession;
// honor security settings
nsCacheStoragePolicy storagePolicy;
if (mLoadFlags & INHIBIT_PERSISTENT_CACHING)
storagePolicy = nsICache::STORE_IN_MEMORY;
else
storagePolicy = nsICache::STORE_ANYWHERE;
// Open a stream based cache session.
rv = cacheService->CreateSession("wyciwyg", nsICache::STORE_ANYWHERE, PR_TRUE, getter_AddRefs(cacheSession));
// Open a stream based cache session.
rv = cacheService->CreateSession("wyciwyg", storagePolicy, PR_TRUE, getter_AddRefs(cacheSession));
if (!cacheSession)
return NS_ERROR_FAILURE;

View File

@ -93,7 +93,6 @@ protected:
PRUint32 mStatus;
PRUint32 mLoadFlags;
PRPackedBool mIsPending;
};
#endif /* nsWyciwygChannel_h___ */