From 3223deda983ee8d6023d1d047cade7543f8bbe44 Mon Sep 17 00:00:00 2001 From: "darin%meer.net" Date: Sat, 12 Feb 2005 01:01:02 +0000 Subject: [PATCH] fixes bug 277564 "update lock icon state in OnLocationChange for wyciwyg URLs" patch by jst, r=dveditz, sr=brendan, a=dveditz git-svn-id: svn://10.0.0.236/branches/AVIARY_1_0_1_20050124_BRANCH@169146 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/docshell/base/nsDocShell.cpp | 20 +- mozilla/docshell/base/nsDocShell.h | 2 + .../boot/src/nsSecureBrowserUIImpl.cpp | 192 +++++++++++------- .../manager/boot/src/nsSecureBrowserUIImpl.h | 3 + 4 files changed, 133 insertions(+), 84 deletions(-) diff --git a/mozilla/docshell/base/nsDocShell.cpp b/mozilla/docshell/base/nsDocShell.cpp index 9cd62b831cb..3e7e19ef93e 100644 --- a/mozilla/docshell/base/nsDocShell.cpp +++ b/mozilla/docshell/base/nsDocShell.cpp @@ -1362,13 +1362,21 @@ nsDocShell::SetParentURIContentListener(nsIURIContentListener * aParent) /* [noscript] void setCurrentURI (in nsIURI uri); */ NS_IMETHODIMP nsDocShell::SetCurrentURI(nsIURI *aURI) +{ + SetCurrentURI(aURI, nsnull); + + return NS_OK; +} + +void +nsDocShell::SetCurrentURI(nsIURI *aURI, nsIRequest *aRequest) { mCurrentURI = aURI; //This assignment addrefs PRBool isRoot = PR_FALSE; // Is this the root docshell PRBool isSubFrame = PR_FALSE; // Is this a subframe navigation? if (!mLoadCookie) - return NS_OK; + return; nsCOMPtr loader(do_GetInterface(mLoadCookie)); nsCOMPtr webProgress(do_QueryInterface(mLoadCookie)); @@ -1395,15 +1403,13 @@ nsDocShell::SetCurrentURI(nsIURI *aURI) * a subframe is being loaded for the first time, while * visiting a frameset page */ - return NS_OK; + return; } NS_ASSERTION(loader, "No document loader"); if (loader) { loader->FireOnLocationChange(webProgress, nsnull, aURI); } - - return NS_OK; } NS_IMETHODIMP @@ -4330,7 +4336,7 @@ nsDocShell::OnStateChange(nsIWebProgress * aProgress, nsIRequest * aRequest, // This is a document.write(). Get the made-up url // from the channel and store it in session history. rv = AddToSessionHistory(uri, wcwgChannel, getter_AddRefs(mLSHE)); - SetCurrentURI(uri); + SetCurrentURI(uri, aRequest); // Save history state of the previous page rv = PersistLayoutHistoryState(); if (mOSHE) @@ -4565,7 +4571,7 @@ nsDocShell::CreateAboutBlankContentViewer() Embed(viewer, "", 0); viewer->SetDOMDocument(domdoc); - SetCurrentURI(blankDoc->GetDocumentURI()); + SetCurrentURI(blankDoc->GetDocumentURI(), nsnull); rv = NS_OK; } } @@ -6238,7 +6244,7 @@ nsDocShell::OnNewURI(nsIURI * aURI, nsIChannel * aChannel, if (shInternal) shInternal->UpdateIndex(); } - SetCurrentURI(aURI); + SetCurrentURI(aURI, aChannel); // if there's a refresh header in the channel, this method // will set it up for us. SetupRefreshURI(aChannel); diff --git a/mozilla/docshell/base/nsDocShell.h b/mozilla/docshell/base/nsDocShell.h index 2777e9bf71d..3ca5284fa95 100644 --- a/mozilla/docshell/base/nsDocShell.h +++ b/mozilla/docshell/base/nsDocShell.h @@ -314,6 +314,8 @@ protected: nsresult CheckLoadingPermissions(); + void SetCurrentURI(nsIURI *aURI, nsIRequest *aRequest); + protected: nsString mName; nsString mTitle; diff --git a/mozilla/security/manager/boot/src/nsSecureBrowserUIImpl.cpp b/mozilla/security/manager/boot/src/nsSecureBrowserUIImpl.cpp index 7fa97bd57b0..2bfaf156b8f 100644 --- a/mozilla/security/manager/boot/src/nsSecureBrowserUIImpl.cpp +++ b/mozilla/security/manager/boot/src/nsSecureBrowserUIImpl.cpp @@ -374,6 +374,80 @@ void nsSecureBrowserUIImpl::ResetStateTracking() sizeof(RequestHashEntry), 16); } +nsresult +nsSecureBrowserUIImpl::EvaluateAndUpdateSecurityState(nsIRequest *aRequest) +{ + nsCOMPtr channel(do_QueryInterface(aRequest)); + + if (channel) { + mNewToplevelSecurityState = GetSecurityStateFromChannel(channel); + + PR_LOG(gSecureDocLog, PR_LOG_DEBUG, + ("SecureUI:%p: OnStateChange: remember mNewToplevelSecurityState => %x\n", this, + mNewToplevelSecurityState)); + + // Get SSL Status information if possible + nsCOMPtr info; + channel->GetSecurityInfo(getter_AddRefs(info)); + nsCOMPtr sp = do_QueryInterface(info); + if (sp) { + // Ignore result + sp->GetSSLStatus(getter_AddRefs(mSSLStatus)); + } + + if (info) { + nsCOMPtr secInfo(do_QueryInterface(info)); + if (secInfo) { + secInfo->GetShortSecurityDescription(getter_Copies(mInfoTooltip)); + } + } + } + else { + mNewToplevelSecurityState = nsIWebProgressListener::STATE_IS_INSECURE; + } + + // assume mNewToplevelSecurityState was set in this scope! + // see code that is directly above + + mNewToplevelSecurityStateKnown = PR_TRUE; + return UpdateSecurityState(aRequest); +} + +void +nsSecureBrowserUIImpl::UpdateSubrequestMembers(nsIRequest *aRequest) +{ + // For wyciwyg channels in subdocuments we only update our + // subrequest state members. + PRUint32 reqState = nsIWebProgressListener::STATE_IS_INSECURE; + nsCOMPtr channel(do_QueryInterface(aRequest)); + + if (channel) { + reqState = GetSecurityStateFromChannel(channel); + } + + if (reqState & STATE_IS_SECURE) { + if (reqState & STATE_SECURE_LOW || reqState & STATE_SECURE_MED) { + PR_LOG(gSecureDocLog, PR_LOG_DEBUG, + ("SecureUI:%p: OnStateChange: subreq LOW\n", this)); + ++mSubRequestsLowSecurity; + } else { + PR_LOG(gSecureDocLog, PR_LOG_DEBUG, + ("SecureUI:%p: OnStateChange: subreq HIGH\n", this)); + ++mSubRequestsHighSecurity; + } + } else if (reqState & STATE_IS_BROKEN) { + PR_LOG(gSecureDocLog, PR_LOG_DEBUG, + ("SecureUI:%p: OnStateChange: subreq BROKEN\n", this)); + ++mSubRequestsBrokenSecurity; + } else { + PR_LOG(gSecureDocLog, PR_LOG_DEBUG, + ("SecureUI:%p: OnStateChange: subreq INSECURE\n", this)); + ++mSubRequestsNoSecurity; + } +} + + + NS_IMETHODIMP nsSecureBrowserUIImpl::OnStateChange(nsIWebProgress* aWebProgress, nsIRequest* aRequest, @@ -787,50 +861,11 @@ nsSecureBrowserUIImpl::OnStateChange(nsIWebProgress* aWebProgress, --mDocumentRequestsInProgress; - { - PRBool MustEvaluate = PR_TRUE; + if (requestHasTransferedData) { + // Data has been transferred for the single toplevel + // request. Evaluate the security state. - if (!requestHasTransferedData) - { - // No data has been transfered for the single toplevel request. - MustEvaluate = PR_FALSE; - } - - if (MustEvaluate) - { - if (channel) { - mNewToplevelSecurityState = GetSecurityStateFromChannel(channel); - - PR_LOG(gSecureDocLog, PR_LOG_DEBUG, - ("SecureUI:%p: OnStateChange: remember mNewToplevelSecurityState => %x\n", this, - mNewToplevelSecurityState)); - - // Get SSL Status information if possible - nsCOMPtr info; - channel->GetSecurityInfo(getter_AddRefs(info)); - nsCOMPtr sp = do_QueryInterface(info); - if (sp) { - // Ignore result - sp->GetSSLStatus(getter_AddRefs(mSSLStatus)); - } - - if (info) { - nsCOMPtr secInfo(do_QueryInterface(info)); - if (secInfo) { - secInfo->GetShortSecurityDescription(getter_Copies(mInfoTooltip)); - } - } - } - else { - mNewToplevelSecurityState = nsIWebProgressListener::STATE_IS_INSECURE; - } - - // assume mNewToplevelSecurityState was set in this scope! - // see code that is directly above - - mNewToplevelSecurityStateKnown = PR_TRUE; - return UpdateSecurityState(aRequest); - } + return EvaluateAndUpdateSecurityState(aRequest); } return NS_OK; @@ -849,39 +884,7 @@ nsSecureBrowserUIImpl::OnStateChange(nsIWebProgress* aWebProgress, if (requestHasTransferedData) { - PRUint32 reqState = nsIWebProgressListener::STATE_IS_INSECURE; - - if (channel) { - reqState = GetSecurityStateFromChannel(channel); - } - - if (reqState & STATE_IS_SECURE) - { - if (reqState & STATE_SECURE_LOW || reqState & STATE_SECURE_MED) - { - PR_LOG(gSecureDocLog, PR_LOG_DEBUG, - ("SecureUI:%p: OnStateChange: subreq LOW\n", this)); - ++mSubRequestsLowSecurity; - } - else - { - PR_LOG(gSecureDocLog, PR_LOG_DEBUG, - ("SecureUI:%p: OnStateChange: subreq HIGH\n", this)); - ++mSubRequestsHighSecurity; - } - } - else if (reqState & STATE_IS_BROKEN) - { - PR_LOG(gSecureDocLog, PR_LOG_DEBUG, - ("SecureUI:%p: OnStateChange: subreq BROKEN\n", this)); - ++ mSubRequestsBrokenSecurity; - } - else - { - PR_LOG(gSecureDocLog, PR_LOG_DEBUG, - ("SecureUI:%p: OnStateChange: subreq INSECURE\n", this)); - ++mSubRequestsNoSecurity; - } + UpdateSubrequestMembers(aRequest); // Care for the following scenario: // A new top level document load might have already started, @@ -1116,11 +1119,16 @@ nsSecureBrowserUIImpl::OnLocationChange(nsIWebProgress* aWebProgress, nsIRequest* aRequest, nsIURI* aLocation) { + PRBool isWyciwyg = PR_FALSE; + if (aLocation) { + nsresult rv = aLocation->SchemeIs("wyciwyg", &isWyciwyg); + NS_ENSURE_SUCCESS(rv, rv); + PRBool vs; - nsresult rv = aLocation->SchemeIs("view-source", &vs); + rv = aLocation->SchemeIs("view-source", &vs); NS_ENSURE_SUCCESS(rv, rv); if (vs) { @@ -1133,6 +1141,36 @@ nsSecureBrowserUIImpl::OnLocationChange(nsIWebProgress* aWebProgress, mCurrentURI = aLocation; + if (isWyciwyg) { + nsCOMPtr windowForProgress; + aWebProgress->GetDOMWindow(getter_AddRefs(windowForProgress)); + + if (windowForProgress.get() == mWindow.get()) { + // For toplevel wyciwyg channels, upate the security state right + // away. + return EvaluateAndUpdateSecurityState(aRequest); + } + + // For wyciwyg channels in subdocuments we only update our + // subrequest state members. + UpdateSecurityState(aRequest); + + // Care for the following scenario: + + // A new top level document load might have already started, but + // the security state of the new top level document might not yet + // been known. + // + // At this point, we are learning about the security state of a + // sub-document. We must not update the security state based on + // the sub content, if the new top level state is not yet known. + // + // We skip updating the security state in this case. + + if (mNewToplevelSecurityStateKnown) + return UpdateSecurityState(aRequest); + } + return NS_OK; } diff --git a/mozilla/security/manager/boot/src/nsSecureBrowserUIImpl.h b/mozilla/security/manager/boot/src/nsSecureBrowserUIImpl.h index 3713ec0b742..b81fd1d4e81 100644 --- a/mozilla/security/manager/boot/src/nsSecureBrowserUIImpl.h +++ b/mozilla/security/manager/boot/src/nsSecureBrowserUIImpl.h @@ -109,6 +109,9 @@ protected: PRInt32 mSubRequestsNoSecurity; nsresult UpdateSecurityState(nsIRequest* aRequest); + nsresult EvaluateAndUpdateSecurityState(nsIRequest *aRequest); + void UpdateSubrequestMembers(nsIRequest *aRequest); + void ObtainEventSink(nsIChannel *channel); nsCOMPtr mSSLStatus;