зеркало из https://github.com/mozilla/pjs.git
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:
Родитель
b1cd4b4e4d
Коммит
5ff58abb6b
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -269,6 +269,10 @@ if ("URI_NON_PERSISTABLE" in nsIProtocolHandler) {
|
|||
IRCProtocolHandler.prototype.protocolFlags |=
|
||||
nsIProtocolHandler.URI_NON_PERSISTABLE;
|
||||
}
|
||||
if ("URI_DOES_NOT_RETURN_DATA" in nsIProtocolHandler) {
|
||||
IRCProtocolHandler.prototype.protocolFlags |=
|
||||
nsIProtocolHandler.URI_DOES_NOT_RETURN_DATA;
|
||||
}
|
||||
|
||||
IRCProtocolHandler.prototype.allowPort =
|
||||
function ircph_allowPort(port, scheme)
|
||||
|
|
|
@ -306,7 +306,7 @@ nsSmtpService::AllowPort(PRInt32 port, const char *scheme, PRBool *_retval)
|
|||
NS_IMETHODIMP nsSmtpService::GetProtocolFlags(PRUint32 *result)
|
||||
{
|
||||
*result = URI_NORELATIVE | ALLOWS_PROXY | URI_LOADABLE_BY_ANYONE |
|
||||
URI_NON_PERSISTABLE;
|
||||
URI_NON_PERSISTABLE | URI_DOES_NOT_RETURN_DATA;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче