From f0588159bd2c2d2c65b5bc7cb5b7e35f5432248a Mon Sep 17 00:00:00 2001 From: "jst%mozilla.jstenback.com" Date: Wed, 28 Jul 2004 04:06:40 +0000 Subject: [PATCH] Fixing bug 253121. Make wyciwyg channels and documents carry the source channels security info. r=darin@meer.net, sr=bzbarsky@mit.edu, a=roc@ocallahan.org git-svn-id: svn://10.0.0.236/branches/MOZILLA_1_7_BRANCH@159950 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/content/base/public/nsIDocument.h | 13 ++++++++ mozilla/content/base/src/nsDocument.cpp | 2 ++ .../document/public/nsIWyciwygChannel.idl | 5 +++ .../html/document/src/nsHTMLDocument.cpp | 31 ++++++++++++++++--- .../html/document/src/nsWyciwygChannel.cpp | 19 +++++++++++- .../html/document/src/nsWyciwygChannel.h | 2 ++ .../boot/src/nsSecureBrowserUIImpl.cpp | 16 ---------- 7 files changed, 66 insertions(+), 22 deletions(-) diff --git a/mozilla/content/base/public/nsIDocument.h b/mozilla/content/base/public/nsIDocument.h index 9d8abec4906..ee032b45d00 100644 --- a/mozilla/content/base/public/nsIDocument.h +++ b/mozilla/content/base/public/nsIDocument.h @@ -582,6 +582,16 @@ public: virtual PRBool IsScriptEnabled() = 0; + // Get the security info (i.e. SSL state etc) that the document got + // from the channel/document that created the content of the + // document. + // + // @see nsIChannel + nsISupports *GetSecurityInfo() + { + return mSecurityInfo; + } + protected: nsString mDocumentTitle; nsCOMPtr mDocumentURI; @@ -613,6 +623,9 @@ protected: nsXPIDLCString mContentLanguage; nsCString mContentType; + + // The document's security info + nsCOMPtr mSecurityInfo; }; diff --git a/mozilla/content/base/src/nsDocument.cpp b/mozilla/content/base/src/nsDocument.cpp index 3c1254e7546..de85173b5e5 100644 --- a/mozilla/content/base/src/nsDocument.cpp +++ b/mozilla/content/base/src/nsDocument.cpp @@ -708,6 +708,8 @@ nsDocument::ResetToURI(nsIURI *aURI, nsILoadGroup *aLoadGroup) mDocumentTitle.Truncate(); mPrincipal = nsnull; + mSecurityInfo = nsnull; + mDocumentLoadGroup = nsnull; // Delete references to sub-documents and kill the subdocument map, diff --git a/mozilla/content/html/document/public/nsIWyciwygChannel.idl b/mozilla/content/html/document/public/nsIWyciwygChannel.idl index c879483b124..0b2edf2aeb4 100644 --- a/mozilla/content/html/document/public/nsIWyciwygChannel.idl +++ b/mozilla/content/html/document/public/nsIWyciwygChannel.idl @@ -57,4 +57,9 @@ interface nsIWyciwygChannel : nsIChannel * Close the cache entry; subsequent writes have undefined behavior. */ void closeCacheEntry(in nsresult reason); + + /** + * Set the wyciwyg channels security info + */ + void setSecurityInfo(in nsISupports aSecurityInfo); }; diff --git a/mozilla/content/html/document/src/nsHTMLDocument.cpp b/mozilla/content/html/document/src/nsHTMLDocument.cpp index 66ed2ab56ba..dad6c0e2e4b 100644 --- a/mozilla/content/html/document/src/nsHTMLDocument.cpp +++ b/mozilla/content/html/document/src/nsHTMLDocument.cpp @@ -725,6 +725,9 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand, return rv; } + // Store the security info for future use with wyciwyg channels. + aChannel->GetSecurityInfo(getter_AddRefs(mSecurityInfo)); + // Stash away a pointer to our channel (we need this for cookies) mChannel = aChannel; @@ -2015,6 +2018,17 @@ nsHTMLDocument::OpenCommon(nsIURI* aSourceURI) return NS_OK; } + nsCOMPtr callingDoc = + do_QueryInterface(nsContentUtils::GetDocumentFromCaller()); + + // Grab a reference to the calling documents security info (if any) + // as it may be lost in the call to Reset(). + nsCOMPtr securityInfo; + + if (callingDoc) { + securityInfo = callingDoc->GetSecurityInfo(); + } + nsCOMPtr docshell = do_QueryReferent(mDocumentContainer); nsresult rv = NS_OK; @@ -2120,6 +2134,10 @@ nsHTMLDocument::OpenCommon(nsIURI* aSourceURI) mRootContent = root; } + // Store the security info of the caller now that we're done + // resetting the document. + mSecurityInfo = securityInfo; + mParser = do_CreateInstance(kCParserCID, &rv); mIsWriting = 1; @@ -3499,11 +3517,14 @@ nsHTMLDocument::CreateAndAddWyciwygChannel(void) nsCOMPtr channel; // Create a wyciwyg Channel rv = NS_NewChannel(getter_AddRefs(channel), wcwgURI); - if (NS_SUCCEEDED(rv) && channel) { - mWyciwygChannel = do_QueryInterface(channel); - // Inherit load flags from the original document's channel - channel->SetLoadFlags(mLoadFlags); - } + NS_ENSURE_SUCCESS(rv, rv); + + mWyciwygChannel = do_QueryInterface(channel); + + mWyciwygChannel->SetSecurityInfo(mSecurityInfo); + + // Inherit load flags from the original document's channel + channel->SetLoadFlags(mLoadFlags); nsCOMPtr loadGroup = GetDocumentLoadGroup(); diff --git a/mozilla/content/html/document/src/nsWyciwygChannel.cpp b/mozilla/content/html/document/src/nsWyciwygChannel.cpp index 76113cef733..b0a2c79f0c4 100644 --- a/mozilla/content/html/document/src/nsWyciwygChannel.cpp +++ b/mozilla/content/html/document/src/nsWyciwygChannel.cpp @@ -229,7 +229,9 @@ nsWyciwygChannel::SetNotificationCallbacks(nsIInterfaceRequestor* aNotificationC NS_IMETHODIMP nsWyciwygChannel::GetSecurityInfo(nsISupports * *aSecurityInfo) { - return NS_ERROR_NOT_IMPLEMENTED; + NS_IF_ADDREF(*aSecurityInfo = mSecurityInfo); + + return NS_OK; } NS_IMETHODIMP @@ -330,6 +332,10 @@ nsWyciwygChannel::WriteToCacheEntry(const nsACString &aScript) if (NS_FAILED(rv)) return rv; } + if (mSecurityInfo) { + mCacheEntry->SetSecurityInfo(mSecurityInfo); + } + if (!mCacheOutputStream) { // Get the outputstream from the cache entry. rv = mCacheEntry->OpenOutputStream(0, getter_AddRefs(mCacheOutputStream)); @@ -357,6 +363,14 @@ nsWyciwygChannel::CloseCacheEntry(nsresult reason) return NS_OK; } +NS_IMETHODIMP +nsWyciwygChannel::SetSecurityInfo(nsISupports *aSecurityInfo) +{ + mSecurityInfo = aSecurityInfo; + + return NS_OK; +} + ////////////////////////////////////////////////////////////////////////////// // nsICachelistener ////////////////////////////////////////////////////////////////////////////// @@ -525,6 +539,9 @@ nsWyciwygChannel::ReadFromCache() NS_ENSURE_TRUE(mCacheEntry, NS_ERROR_FAILURE); nsresult rv; + // Get the stored security info + mCacheEntry->GetSecurityInfo(getter_AddRefs(mSecurityInfo)); + // Get a transport to the cached data... rv = mCacheEntry->OpenInputStream(0, getter_AddRefs(mCacheInputStream)); if (NS_FAILED(rv)) diff --git a/mozilla/content/html/document/src/nsWyciwygChannel.h b/mozilla/content/html/document/src/nsWyciwygChannel.h index ea61ecad79f..cabe50eb0c3 100644 --- a/mozilla/content/html/document/src/nsWyciwygChannel.h +++ b/mozilla/content/html/document/src/nsWyciwygChannel.h @@ -90,6 +90,8 @@ protected: nsCOMPtr mCacheEntry; nsCOMPtr mCacheOutputStream; nsCOMPtr mCacheInputStream; + + nsCOMPtr mSecurityInfo; }; #endif /* nsWyciwygChannel_h___ */ diff --git a/mozilla/security/manager/boot/src/nsSecureBrowserUIImpl.cpp b/mozilla/security/manager/boot/src/nsSecureBrowserUIImpl.cpp index 58a41791406..b82a4613027 100644 --- a/mozilla/security/manager/boot/src/nsSecureBrowserUIImpl.cpp +++ b/mozilla/security/manager/boot/src/nsSecureBrowserUIImpl.cpp @@ -532,22 +532,6 @@ nsSecureBrowserUIImpl::OnStateChange(nsIWebProgress* aWebProgress, // If a document loading gets triggered, we will see more events. return NS_OK; } - - if (NS_SUCCEEDED(uri->SchemeIs("wyciwyg", &vs)) && vs) - { - // We ignore everything caused by wycywig == document.write/writeln - // and assume the same security status - // Unfortunately, this results in different lock icon states - // when using "back". - // 1) goto secure page => secure lock icon - // 2) trigger document.writeln() => still secure lock icon - // (because we not change lock icon) - // 3) go to a different insecure page => insecure lock icon - // 4) press "back" button => still insecure lock icon - // To fix this, we could try to remember the security state in the - // wyciwyg channel object. - return NS_OK; - } } }