From 10ba1113a13d942d2e8cba5328790f51bd4ce5ed Mon Sep 17 00:00:00 2001 From: "darin%netscape.com" Date: Fri, 11 Oct 2002 04:22:54 +0000 Subject: [PATCH] fixes bug 151478 "https wyciwyg page is cached on disk" r=mstoltz sr=rpotts a=asa git-svn-id: svn://10.0.0.236/trunk@131775 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/content/base/src/nsDocument.cpp | 3 ++ mozilla/content/base/src/nsDocument.h | 1 + .../document/public/nsIWyciwygChannel.idl | 16 +++--- .../html/document/src/nsHTMLDocument.cpp | 7 +-- .../html/document/src/nsWyciwygChannel.cpp | 53 ++++++++++--------- .../html/document/src/nsWyciwygChannel.h | 1 - 6 files changed, 45 insertions(+), 36 deletions(-) diff --git a/mozilla/content/base/src/nsDocument.cpp b/mozilla/content/base/src/nsDocument.cpp index 9382b96545c..b54c5228068 100644 --- a/mozilla/content/base/src/nsDocument.cpp +++ b/mozilla/content/base/src/nsDocument.cpp @@ -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, diff --git a/mozilla/content/base/src/nsDocument.h b/mozilla/content/base/src/nsDocument.h index 59837e31a22..d7d54a9f953 100644 --- a/mozilla/content/base/src/nsDocument.h +++ b/mozilla/content/base/src/nsDocument.h @@ -616,6 +616,7 @@ protected: nsIURI* mDocumentURL; nsCOMPtr mDocumentBaseURL; nsCOMPtr mPrincipal; + PRUint32 mLoadFlags; // load flags of the document's channel nsWeakPtr mDocumentLoadGroup; nsWeakPtr mDocumentContainer; diff --git a/mozilla/content/html/document/public/nsIWyciwygChannel.idl b/mozilla/content/html/document/public/nsIWyciwygChannel.idl index 746b106a803..71069b58115 100644 --- a/mozilla/content/html/document/public/nsIWyciwygChannel.idl +++ b/mozilla/content/html/document/public/nsIWyciwygChannel.idl @@ -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(); - -}; \ No newline at end of file +}; diff --git a/mozilla/content/html/document/src/nsHTMLDocument.cpp b/mozilla/content/html/document/src/nsHTMLDocument.cpp index 1f64efdce16..d744c7a8d57 100644 --- a/mozilla/content/html/document/src/nsHTMLDocument.cpp +++ b/mozilla/content/html/document/src/nsHTMLDocument.cpp @@ -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 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 loadGroup; diff --git a/mozilla/content/html/document/src/nsWyciwygChannel.cpp b/mozilla/content/html/document/src/nsWyciwygChannel.cpp index 057a081b5ce..da54e2207c5 100644 --- a/mozilla/content/html/document/src/nsWyciwygChannel.cpp +++ b/mozilla/content/html/document/src/nsWyciwygChannel.cpp @@ -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 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; diff --git a/mozilla/content/html/document/src/nsWyciwygChannel.h b/mozilla/content/html/document/src/nsWyciwygChannel.h index d2a253ad3a7..4713940f9a3 100644 --- a/mozilla/content/html/document/src/nsWyciwygChannel.h +++ b/mozilla/content/html/document/src/nsWyciwygChannel.h @@ -93,7 +93,6 @@ protected: PRUint32 mStatus; PRUint32 mLoadFlags; PRPackedBool mIsPending; - }; #endif /* nsWyciwygChannel_h___ */