From 89402e216a4862ae6f7769d5bebd16c9d88008f3 Mon Sep 17 00:00:00 2001 From: "kaie%netscape.com" Date: Thu, 16 May 2002 03:39:59 +0000 Subject: [PATCH] b=144056 security state not reset after loading about:blank pages r=javi sr=rpotts git-svn-id: svn://10.0.0.236/trunk@121596 18797224-902f-48f8-a5cc-f745e15eee43 --- .../boot/src/nsSecureBrowserUIImpl.cpp | 116 ++++++++++++------ 1 file changed, 78 insertions(+), 38 deletions(-) diff --git a/mozilla/security/manager/boot/src/nsSecureBrowserUIImpl.cpp b/mozilla/security/manager/boot/src/nsSecureBrowserUIImpl.cpp index 8a3d4e01441..88a36926527 100644 --- a/mozilla/security/manager/boot/src/nsSecureBrowserUIImpl.cpp +++ b/mozilla/security/manager/boot/src/nsSecureBrowserUIImpl.cpp @@ -456,8 +456,6 @@ nsSecureBrowserUIImpl::OnStateChange(nsIWebProgress* aWebProgress, if (mIsViewSource) return NS_OK; - nsresult res = NS_OK; - if (!aRequest) { PR_LOG(gSecureDocLog, PR_LOG_DEBUG, @@ -474,33 +472,55 @@ nsSecureBrowserUIImpl::OnStateChange(nsIWebProgress* aWebProgress, // Get the channel from the request... // If the request is not network based, then ignore it. - nsCOMPtr channel(do_QueryInterface(aRequest, &res)); - if (NS_FAILED(res)) + nsCOMPtr channel(do_QueryInterface(aRequest)); + + PRUint32 loadFlags = 0; + aRequest->GetLoadFlags(&loadFlags); + +#ifdef PR_LOGGING + if (aProgressStateFlags & STATE_START + && + aProgressStateFlags & STATE_IS_REQUEST + && + isToplevelProgress + && + loadFlags & nsIChannel::LOAD_DOCUMENT_URI) { PR_LOG(gSecureDocLog, PR_LOG_DEBUG, - ("SecureUI:%p: OnStateChange: no channel\n", this)); - return NS_OK; + ("SecureUI:%p: OnStateChange: SOMETHING STARTS FOR TOPMOST DOCUMENT\n", this)); } + if (aProgressStateFlags & STATE_STOP + && + aProgressStateFlags & STATE_IS_REQUEST + && + isToplevelProgress + && + loadFlags & nsIChannel::LOAD_DOCUMENT_URI) + { + PR_LOG(gSecureDocLog, PR_LOG_DEBUG, + ("SecureUI:%p: OnStateChange: SOMETHING STOPS FOR TOPMOST DOCUMENT\n", this)); + } +#endif + + PRBool isSubDocumentRelevant = PR_TRUE; + // We are only interested in requests that load in the browser window... - nsCOMPtr httpRequest(do_QueryInterface(channel)); + nsCOMPtr httpRequest(do_QueryInterface(aRequest)); if (!httpRequest) { - nsCOMPtr fileRequest(do_QueryInterface(channel)); + nsCOMPtr fileRequest(do_QueryInterface(aRequest)); if (!fileRequest) { - nsCOMPtr wyciwygRequest(do_QueryInterface(channel)); + nsCOMPtr wyciwygRequest(do_QueryInterface(aRequest)); if (!wyciwygRequest) { - nsCOMPtr ftpRequest(do_QueryInterface(channel)); + nsCOMPtr ftpRequest(do_QueryInterface(aRequest)); if (!ftpRequest) { PR_LOG(gSecureDocLog, PR_LOG_DEBUG, - ("SecureUI:%p: OnStateChange: not a relevant request\n", this)); - return NS_OK; + ("SecureUI:%p: OnStateChange: not relevant for sub content\n", this)); + isSubDocumentRelevant = PR_FALSE; } } } } - - PRUint32 loadFlags = 0; - aRequest->GetLoadFlags(&loadFlags); #if defined(DEBUG) nsCString info2; @@ -611,7 +631,9 @@ nsSecureBrowserUIImpl::OnStateChange(nsIWebProgress* aWebProgress, ("SecureUI:%p: OnStateChange: %s %s -- %s\n", this, _status, info.get(), info2.get())); - if (aProgressStateFlags & STATE_STOP) + if (aProgressStateFlags & STATE_STOP + && + channel) { PR_LOG(gSecureDocLog, PR_LOG_DEBUG, ("SecureUI:%p: OnStateChange: seeing STOP with security state: %d\n", this, @@ -654,6 +676,9 @@ nsSecureBrowserUIImpl::OnStateChange(nsIWebProgress* aWebProgress, && aProgressStateFlags & STATE_IS_REQUEST) { + if (!isSubDocumentRelevant) + return NS_OK; + PR_LOG(gSecureDocLog, PR_LOG_DEBUG, ("SecureUI:%p: OnStateChange: ++mSubRequestsInProgress\n", this )); @@ -670,13 +695,18 @@ nsSecureBrowserUIImpl::OnStateChange(nsIWebProgress* aWebProgress, && loadFlags & nsIChannel::LOAD_DOCUMENT_URI) { - NS_ASSERTION(mDocumentRequestsInProgress > 0, "Oops? We see more STOPs than STARTs..."); + if (mDocumentRequestsInProgress <= 0) + { + // Ignore stop requests unless a document load is in progress + // Unfortunately on application start, see some stops without having seen any starts... + return NS_OK; + } PR_LOG(gSecureDocLog, PR_LOG_DEBUG, ("SecureUI:%p: OnStateChange: --mDocumentRequestsInProgress\n", this )); - if (!mToplevelEventSink) + if (!mToplevelEventSink && channel) { nsCOMPtr requestor; channel->GetNotificationCallbacks(getter_AddRefs(requestor)); @@ -689,26 +719,31 @@ nsSecureBrowserUIImpl::OnStateChange(nsIWebProgress* aWebProgress, // we are arriving at zero, all STOPs for toplevel documents // have been received - mNewToplevelSecurityState = GetSecurityStateFromChannel(channel); + if (channel) { + mNewToplevelSecurityState = GetSecurityStateFromChannel(channel); - PR_LOG(gSecureDocLog, PR_LOG_DEBUG, - ("SecureUI:%p: OnStateChange: remember mNewToplevelSecurityState => %x\n", this, - mNewToplevelSecurityState)); + 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)); + // 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; } if (!mSubRequestsInProgress) @@ -724,11 +759,16 @@ nsSecureBrowserUIImpl::OnStateChange(nsIWebProgress* aWebProgress, && aProgressStateFlags & STATE_IS_REQUEST) { + if (!isSubDocumentRelevant) + return NS_OK; + // if we arrive here, LOAD_DOCUMENT_URI is not set - NS_ASSERTION(mSubRequestsInProgress > 0, "Oops? We see more STOPs than STARTs..."); - - PRInt32 aState = GetSecurityStateFromChannel(channel); + PRInt32 aState = nsIWebProgressListener::STATE_IS_INSECURE; + + if (channel) { + aState = GetSecurityStateFromChannel(channel); + } if (aState & STATE_IS_SECURE) {