fixes bug 294535 "Prefetch Service should only follow redirects to http:// locations." r=biesi a=bsmedberg

This commit is contained in:
darin%meer.net 2005-06-29 20:57:34 +00:00
Родитель 0203abaec9
Коммит 2444b0a94f
2 изменённых файлов: 56 добавлений и 6 удалений

Просмотреть файл

@ -52,6 +52,7 @@
#include "nsString.h"
#include "nsXPIDLString.h"
#include "nsReadableUtils.h"
#include "nsAutoPtr.h"
#include "prtime.h"
#include "prlog.h"
#include "plstr.h"
@ -127,9 +128,11 @@ nsPrefetchListener::ConsumeSegments(nsIInputStream *aInputStream,
// nsPrefetchListener::nsISupports
//-----------------------------------------------------------------------------
NS_IMPL_ISUPPORTS2(nsPrefetchListener,
NS_IMPL_ISUPPORTS4(nsPrefetchListener,
nsIRequestObserver,
nsIStreamListener)
nsIStreamListener,
nsIInterfaceRequestor,
nsIChannelEventSink)
//-----------------------------------------------------------------------------
// nsPrefetchListener::nsIStreamListener
@ -197,6 +200,46 @@ nsPrefetchListener::OnStopRequest(nsIRequest *aRequest,
return NS_OK;
}
//-----------------------------------------------------------------------------
// nsPrefetchListener::nsIInterfaceRequestor
//-----------------------------------------------------------------------------
NS_IMETHODIMP
nsPrefetchListener::GetInterface(const nsIID &aIID, void **aResult)
{
if (aIID.Equals(NS_GET_IID(nsIChannelEventSink))) {
NS_ADDREF_THIS();
*aResult = NS_STATIC_CAST(nsIChannelEventSink *, this);
return NS_OK;
}
return NS_ERROR_NO_INTERFACE;
}
//-----------------------------------------------------------------------------
// nsPrefetchListener::nsIChannelEventSink
//-----------------------------------------------------------------------------
NS_IMETHODIMP
nsPrefetchListener::OnChannelRedirect(nsIChannel *aOldChannel,
nsIChannel *aNewChannel,
PRUint32 aFlags)
{
nsCOMPtr<nsIURI> newURI;
nsresult rv = aNewChannel->GetURI(getter_AddRefs(newURI));
if (NS_FAILED(rv))
return rv;
PRBool match;
rv = newURI->SchemeIs("http", &match);
if (NS_FAILED(rv) || !match) {
LOG(("rejected: URL is not of type http\n"));
return NS_ERROR_ABORT;
}
return NS_OK;
}
//-----------------------------------------------------------------------------
// nsPrefetchService <public>
//-----------------------------------------------------------------------------
@ -259,7 +302,7 @@ nsPrefetchService::ProcessNextURI()
mCurrentChannel = nsnull;
nsCOMPtr<nsIStreamListener> listener(new nsPrefetchListener(this));
nsRefPtr<nsPrefetchListener> listener(new nsPrefetchListener(this));
if (!listener) return;
do {
@ -278,7 +321,7 @@ nsPrefetchService::ProcessNextURI()
// if opening the channel fails, then just skip to the next uri
//
rv = NS_NewChannel(getter_AddRefs(mCurrentChannel), uri,
nsnull, nsnull, nsnull,
nsnull, nsnull, listener,
nsIRequest::LOAD_BACKGROUND |
nsICachingChannel::LOAD_ONLY_IF_MODIFIED);
if (NS_FAILED(rv)) continue;

Просмотреть файл

@ -41,6 +41,8 @@
#include "nsCPrefetchService.h"
#include "nsIGenericFactory.h"
#include "nsIObserver.h"
#include "nsIInterfaceRequestor.h"
#include "nsIChannelEventSink.h"
#include "nsIWebProgressListener.h"
#include "nsIStreamListener.h"
#include "nsIChannel.h"
@ -68,12 +70,12 @@ public:
NS_DECL_NSIOBSERVER
nsPrefetchService();
virtual ~nsPrefetchService();
nsresult Init();
void ProcessNextURI();
private:
~nsPrefetchService();
void AddProgressListener();
void RemoveProgressListener();
@ -95,16 +97,21 @@ private:
//-----------------------------------------------------------------------------
class nsPrefetchListener : public nsIStreamListener
, public nsIInterfaceRequestor
, public nsIChannelEventSink
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIREQUESTOBSERVER
NS_DECL_NSISTREAMLISTENER
NS_DECL_NSIINTERFACEREQUESTOR
NS_DECL_NSICHANNELEVENTSINK
nsPrefetchListener(nsPrefetchService *aPrefetchService);
virtual ~nsPrefetchListener();
private:
~nsPrefetchListener();
static NS_METHOD ConsumeSegments(nsIInputStream *, void *, const char *,
PRUint32, PRUint32, PRUint32 *);