Add a flag that allows protocol handlers to indicate that they don't return any

data.  Bug 379819, patch by Ryan Jones <sciguyryan@gmail.com>, r=me, sr=biesi
This commit is contained in:
bzbarsky@mit.edu 2007-07-25 10:21:41 -07:00
parent 10b3e425ee
commit 5fda0c5d00
3 changed files with 17 additions and 15 deletions

View File

@ -51,6 +51,7 @@
#include "nsIProtocolHandler.h"
#include "nsIIOService.h"
#include "nsIExternalProtocolHandler.h"
#include "nsNetUtil.h"
NS_IMPL_ISUPPORTS1(nsNoDataProtocolContentPolicy, nsIContentPolicy)
@ -70,9 +71,11 @@ nsNoDataProtocolContentPolicy::ShouldLoad(PRUint32 aContentType,
if (aContentType != TYPE_DOCUMENT &&
aContentType != TYPE_SUBDOCUMENT &&
aContentType != TYPE_OBJECT) {
// The following are just quick-escapes for the most common cases
// where we would allow the content to be loaded anyway.
nsCAutoString scheme;
aContentLocation->GetScheme(scheme);
// Fast-track for the common cases
if (scheme.EqualsLiteral("http") ||
scheme.EqualsLiteral("https") ||
scheme.EqualsLiteral("ftp") ||
@ -81,19 +84,11 @@ nsNoDataProtocolContentPolicy::ShouldLoad(PRUint32 aContentType,
return NS_OK;
}
nsIIOService* ios = nsContentUtils::GetIOService();
if (!ios) {
// default to accept, just in case
return NS_OK;
}
nsCOMPtr<nsIProtocolHandler> handler;
ios->GetProtocolHandler(scheme.get(), getter_AddRefs(handler));
nsCOMPtr<nsIExternalProtocolHandler> extHandler =
do_QueryInterface(handler);
if (extHandler) {
PRBool shouldBlock;
nsresult rv = NS_URIChainHasFlags(aContentLocation,
nsIProtocolHandler::URI_DOES_NOT_RETURN_DATA,
&shouldBlock);
if (NS_SUCCEEDED(rv) && shouldBlock) {
*aDecision = nsIContentPolicy::REJECT_REQUEST;
}
}

View File

@ -214,6 +214,13 @@ interface nsIProtocolHandler : nsISupports
* it unsuitable for saving to a local file.
*/
const unsigned long URI_NON_PERSISTABLE = (1<<10);
/**
* Channels using this protocol never call OnDataAvailable
* on the listener passed to AsyncOpen and they therefore
* do not return any data that we can use.
*/
const unsigned long URI_DOES_NOT_RETURN_DATA = (1<<11);
/**
* This protocol handler can be proxied via a proxy (socks or http)

View File

@ -565,7 +565,7 @@ NS_IMETHODIMP nsExternalProtocolHandler::GetProtocolFlags(PRUint32 *aUritype)
{
// Make it norelative since it is a simple uri
*aUritype = URI_NORELATIVE | URI_NOAUTH | URI_LOADABLE_BY_ANYONE |
URI_NON_PERSISTABLE;
URI_NON_PERSISTABLE | URI_DOES_NOT_RETURN_DATA;
return NS_OK;
}