From e620764ea9dba64470f1d73792d66fd54b6b1f72 Mon Sep 17 00:00:00 2001 From: Date: Sat, 16 Aug 2008 09:12:42 +0200 Subject: [PATCH] Bug 135007, Transfer mode of images should be relevant for shown lock icon state (mixed content) Based on ideas from Stuart Parmenter and experimental code from Kai Engert Patch contributed by Honza Bambas r=kaie, r=pavlov, sr=bz --- modules/libpr0n/src/imgRequest.cpp | 14 ++++ modules/libpr0n/src/imgRequest.h | 2 + modules/libpr0n/src/imgRequestProxy.cpp | 15 ++++- modules/libpr0n/src/imgRequestProxy.h | 4 +- netwerk/base/public/Makefile.in | 1 + .../base/public/nsISecurityInfoProvider.idl | 44 +++++++++++++ security/manager/boot/src/Makefile.in | 1 + .../boot/src/nsSecureBrowserUIImpl.cpp | 64 ++++++++++++++----- .../manager/boot/src/nsSecureBrowserUIImpl.h | 1 + 9 files changed, 127 insertions(+), 19 deletions(-) create mode 100644 netwerk/base/public/nsISecurityInfoProvider.idl diff --git a/modules/libpr0n/src/imgRequest.cpp b/modules/libpr0n/src/imgRequest.cpp index c0a62b75d85c..d46b39365de2 100644 --- a/modules/libpr0n/src/imgRequest.cpp +++ b/modules/libpr0n/src/imgRequest.cpp @@ -321,6 +321,16 @@ nsresult imgRequest::GetPrincipal(nsIPrincipal **aPrincipal) return NS_ERROR_FAILURE; } +nsresult imgRequest::GetSecurityInfo(nsISupports **aSecurityInfo) +{ + LOG_FUNC(gImgLog, "imgRequest::GetSecurityInfo"); + + // Missing security info means this is not a security load + // i.e. it is not an error when security info is missing + NS_IF_ADDREF(*aSecurityInfo = mSecurityInfo); + return NS_OK; +} + void imgRequest::RemoveFromCache() { LOG_SCOPE(gImgLog, "imgRequest::RemoveFromCache"); @@ -596,6 +606,10 @@ NS_IMETHODIMP imgRequest::OnStartRequest(nsIRequest *aRequest, nsISupports *ctxt mImageStatus = imgIRequest::STATUS_NONE; mState = onStartRequest; + nsCOMPtr channel(do_QueryInterface(aRequest)); + if (channel) + channel->GetSecurityInfo(getter_AddRefs(mSecurityInfo)); + /* set our loading flag to true */ mLoading = PR_TRUE; diff --git a/modules/libpr0n/src/imgRequest.h b/modules/libpr0n/src/imgRequest.h index d45de097def7..5a96e7a7ec96 100644 --- a/modules/libpr0n/src/imgRequest.h +++ b/modules/libpr0n/src/imgRequest.h @@ -123,6 +123,7 @@ private: void Cancel(nsresult aStatus); nsresult GetURI(nsIURI **aURI); nsresult GetPrincipal(nsIPrincipal **aPrincipal); + nsresult GetSecurityInfo(nsISupports **aSecurityInfo); void RemoveFromCache(); inline const char *GetMimeType() const { return mContentType.get(); @@ -157,6 +158,7 @@ private: nsCOMPtr mImage; nsCOMPtr mDecoder; nsCOMPtr mProperties; + nsCOMPtr mSecurityInfo; nsTObserverArray mObservers; diff --git a/modules/libpr0n/src/imgRequestProxy.cpp b/modules/libpr0n/src/imgRequestProxy.cpp index 0c6e07b70cd6..dfb29b63f8eb 100644 --- a/modules/libpr0n/src/imgRequestProxy.cpp +++ b/modules/libpr0n/src/imgRequestProxy.cpp @@ -55,8 +55,8 @@ #include "nspr.h" -NS_IMPL_ISUPPORTS3(imgRequestProxy, imgIRequest, nsIRequest, - nsISupportsPriority) +NS_IMPL_ISUPPORTS4(imgRequestProxy, imgIRequest, nsIRequest, + nsISupportsPriority, nsISecurityInfoProvider) imgRequestProxy::imgRequestProxy() : mOwner(nsnull), @@ -383,6 +383,17 @@ NS_IMETHODIMP imgRequestProxy::AdjustPriority(PRInt32 priority) return NS_OK; } +/** nsISecurityInfoProvider methods **/ + +NS_IMETHODIMP imgRequestProxy::GetSecurityInfo(nsISupports** retval) +{ + if (mOwner) + return mOwner->GetSecurityInfo(retval); + + *retval = nsnull; + return NS_OK; +} + /** imgIContainerObserver methods **/ void imgRequestProxy::FrameChanged(imgIContainer *container, gfxIImageFrame *newframe, nsIntRect * dirtyRect) diff --git a/modules/libpr0n/src/imgRequestProxy.h b/modules/libpr0n/src/imgRequestProxy.h index 83164e54cf6b..5f79e200bb45 100644 --- a/modules/libpr0n/src/imgRequestProxy.h +++ b/modules/libpr0n/src/imgRequestProxy.h @@ -39,6 +39,7 @@ #include "imgIRequest.h" #include "imgIDecoderObserver.h" +#include "nsISecurityInfoProvider.h" #include "imgIContainer.h" #include "imgIDecoder.h" @@ -59,13 +60,14 @@ {0x8f, 0x65, 0x9c, 0x46, 0x2e, 0xe2, 0xbc, 0x95} \ } -class imgRequestProxy : public imgIRequest, public nsISupportsPriority +class imgRequestProxy : public imgIRequest, public nsISupportsPriority, public nsISecurityInfoProvider { public: NS_DECL_ISUPPORTS NS_DECL_IMGIREQUEST NS_DECL_NSIREQUEST NS_DECL_NSISUPPORTSPRIORITY + NS_DECL_NSISECURITYINFOPROVIDER imgRequestProxy(); virtual ~imgRequestProxy(); diff --git a/netwerk/base/public/Makefile.in b/netwerk/base/public/Makefile.in index 7fe717374e33..991dc0a098ec 100644 --- a/netwerk/base/public/Makefile.in +++ b/netwerk/base/public/Makefile.in @@ -100,6 +100,7 @@ XPIDLSRCS = \ nsIServerSocket.idl \ nsIResumableChannel.idl \ nsIRequestObserverProxy.idl \ + nsISecurityInfoProvider.idl \ nsIStreamListenerTee.idl \ nsISimpleStreamListener.idl \ nsIStreamTransportService.idl \ diff --git a/netwerk/base/public/nsISecurityInfoProvider.idl b/netwerk/base/public/nsISecurityInfoProvider.idl new file mode 100644 index 000000000000..57d42bf1b98c --- /dev/null +++ b/netwerk/base/public/nsISecurityInfoProvider.idl @@ -0,0 +1,44 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is mozilla.org + * Portions created by the Initial Developer are Copyright (C) 2008 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Honza Bambas + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "nsISupports.idl" + +[scriptable, uuid(9E03B4C6-8B79-41a8-A3E5-C41F9E015598)] +interface nsISecurityInfoProvider : nsISupports +{ + readonly attribute nsISupports securityInfo; +}; diff --git a/security/manager/boot/src/Makefile.in b/security/manager/boot/src/Makefile.in index 9eda9b0d8252..24e9c03c8898 100644 --- a/security/manager/boot/src/Makefile.in +++ b/security/manager/boot/src/Makefile.in @@ -76,6 +76,7 @@ REQUIRES = nspr \ caps \ pref \ pipnss \ + imglib2 \ $(NULL) include $(topsrcdir)/config/rules.mk diff --git a/security/manager/boot/src/nsSecureBrowserUIImpl.cpp b/security/manager/boot/src/nsSecureBrowserUIImpl.cpp index 221c2e4a82ec..fec2083b0858 100644 --- a/security/manager/boot/src/nsSecureBrowserUIImpl.cpp +++ b/security/manager/boot/src/nsSecureBrowserUIImpl.cpp @@ -78,7 +78,9 @@ #include "nsIPrompt.h" #include "nsIFormSubmitObserver.h" #include "nsISecurityWarningDialogs.h" +#include "nsISecurityInfoProvider.h" #include "nsIProxyObjectManager.h" +#include "imgIRequest.h" #include "nsThreadUtils.h" #include "nsNetUtil.h" #include "nsCRT.h" @@ -271,6 +273,24 @@ nsSecureBrowserUIImpl::GetState(PRUint32* aState) return MapInternalToExternalState(aState, mNotifiedSecurityState, mNotifiedToplevelIsEV); } +// static +already_AddRefed +nsSecureBrowserUIImpl::ExtractSecurityInfo(nsIRequest* aRequest) +{ + nsISupports *retval = nsnull; + nsCOMPtr channel(do_QueryInterface(aRequest)); + if (channel) + channel->GetSecurityInfo(&retval); + + if (!retval) { + nsCOMPtr provider(do_QueryInterface(aRequest)); + if (provider) + provider->GetSecurityInfo(&retval); + } + + return retval; +} + nsresult nsSecureBrowserUIImpl::MapInternalToExternalState(PRUint32* aState, lockIconState lock, PRBool ev) { @@ -738,13 +758,11 @@ nsSecureBrowserUIImpl::OnStateChange(nsIWebProgress* aWebProgress, } #endif - nsCOMPtr securityInfo; - nsCOMPtr channel(do_QueryInterface(aRequest)); + nsCOMPtr securityInfo(ExtractSecurityInfo(aRequest)); + nsCOMPtr channel(do_QueryInterface(aRequest)); if (channel) { - channel->GetSecurityInfo(getter_AddRefs(securityInfo)); - nsCOMPtr uri; channel->GetURI(getter_AddRefs(uri)); if (uri) @@ -789,6 +807,7 @@ nsSecureBrowserUIImpl::OnStateChange(nsIWebProgress* aWebProgress, #endif PRBool isSubDocumentRelevant = PR_TRUE; + PRBool isImageRequest = PR_FALSE; // We are only interested in requests that load in the browser window... nsCOMPtr httpRequest(do_QueryInterface(aRequest)); @@ -799,9 +818,18 @@ nsSecureBrowserUIImpl::OnStateChange(nsIWebProgress* aWebProgress, if (!wyciwygRequest) { nsCOMPtr ftpRequest(do_QueryInterface(aRequest)); if (!ftpRequest) { - PR_LOG(gSecureDocLog, PR_LOG_DEBUG, - ("SecureUI:%p: OnStateChange: not relevant for sub content\n", this)); - isSubDocumentRelevant = PR_FALSE; + nsCOMPtr imgRequest(do_QueryInterface(aRequest)); + if (!imgRequest) { + PR_LOG(gSecureDocLog, PR_LOG_DEBUG, + ("SecureUI:%p: OnStateChange: not relevant for sub content\n", this)); + isSubDocumentRelevant = PR_FALSE; + } else { + // Remember this is an image request. Because image loads doesn't + // support any TRANSFERRING notifications but only START and + // STOP we must simply predict there were a content transferred. + // See bug 432685 for details. + isImageRequest = PR_TRUE; + } } } } @@ -951,14 +979,21 @@ nsSecureBrowserUIImpl::OnStateChange(nsIWebProgress* aWebProgress, && aProgressStateFlags & STATE_IS_REQUEST) { - nsAutoMonitor lock(mMonitor); - PLDHashEntryHdr *entry = PL_DHashTableOperate(&mTransferringRequests, aRequest, PL_DHASH_LOOKUP); - if (PL_DHASH_ENTRY_IS_BUSY(entry)) + if (isImageRequest) { - PL_DHashTableOperate(&mTransferringRequests, aRequest, PL_DHASH_REMOVE); - requestHasTransferedData = PR_TRUE; } + else + { + nsAutoMonitor lock(mMonitor); + PLDHashEntryHdr *entry = PL_DHashTableOperate(&mTransferringRequests, aRequest, PL_DHASH_LOOKUP); + if (PL_DHASH_ENTRY_IS_BUSY(entry)) + { + PL_DHashTableOperate(&mTransferringRequests, aRequest, PL_DHASH_REMOVE); + + requestHasTransferedData = PR_TRUE; + } + } } PRBool allowSecurityStateChange = PR_TRUE; @@ -1450,10 +1485,7 @@ nsSecureBrowserUIImpl::OnLocationChange(nsIWebProgress* aWebProgress, nsCOMPtr windowForProgress; aWebProgress->GetDOMWindow(getter_AddRefs(windowForProgress)); - nsCOMPtr securityInfo; - nsCOMPtr channel(do_QueryInterface(aRequest)); - if (channel) - channel->GetSecurityInfo(getter_AddRefs(securityInfo)); + nsCOMPtr securityInfo(ExtractSecurityInfo(aRequest)); if (windowForProgress.get() == window.get()) { // For toplevel channels, update the security state right away. diff --git a/security/manager/boot/src/nsSecureBrowserUIImpl.h b/security/manager/boot/src/nsSecureBrowserUIImpl.h index d3c4bb420780..891bee08b04e 100644 --- a/security/manager/boot/src/nsSecureBrowserUIImpl.h +++ b/security/manager/boot/src/nsSecureBrowserUIImpl.h @@ -126,6 +126,7 @@ protected: PRInt32 mSubRequestsBrokenSecurity; PRInt32 mSubRequestsNoSecurity; + static already_AddRefed ExtractSecurityInfo(nsIRequest* aRequest); static nsresult MapInternalToExternalState(PRUint32* aState, lockIconState lock, PRBool ev); nsresult UpdateSecurityState(nsIRequest* aRequest); void UpdateMyFlags(PRBool &showWarning, lockIconState &warnSecurityState);