2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2006-06-26 21:57:44 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Content policy implementation that prevents all loads of images,
|
|
|
|
* subframes, etc from protocols that don't return data but rather open
|
|
|
|
* applications (such as mailto).
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "nsNoDataProtocolContentPolicy.h"
|
|
|
|
#include "nsIDOMWindow.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsIProtocolHandler.h"
|
|
|
|
#include "nsIIOService.h"
|
|
|
|
#include "nsIExternalProtocolHandler.h"
|
2007-07-25 21:21:41 +04:00
|
|
|
#include "nsNetUtil.h"
|
2015-07-01 16:56:00 +03:00
|
|
|
#include "nsContentUtils.h"
|
2006-06-26 21:57:44 +04:00
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(nsNoDataProtocolContentPolicy, nsIContentPolicy)
|
2006-06-26 21:57:44 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsNoDataProtocolContentPolicy::ShouldLoad(uint32_t aContentType,
|
2006-06-26 21:57:44 +04:00
|
|
|
nsIURI *aContentLocation,
|
|
|
|
nsIURI *aRequestingLocation,
|
|
|
|
nsISupports *aRequestingContext,
|
|
|
|
const nsACString &aMimeGuess,
|
|
|
|
nsISupports *aExtra,
|
2012-07-03 03:16:11 +04:00
|
|
|
nsIPrincipal *aRequestPrincipal,
|
2012-08-22 19:56:38 +04:00
|
|
|
int16_t *aDecision)
|
2006-06-26 21:57:44 +04:00
|
|
|
{
|
2015-06-16 16:24:35 +03:00
|
|
|
MOZ_ASSERT(aContentType == nsContentUtils::InternalContentPolicyTypeToExternal(aContentType),
|
|
|
|
"We should only see external content policy types here.");
|
|
|
|
|
2006-06-26 21:57:44 +04:00
|
|
|
*aDecision = nsIContentPolicy::ACCEPT;
|
|
|
|
|
2006-07-28 03:43:48 +04:00
|
|
|
// Don't block for TYPE_OBJECT since such URIs are sometimes loaded by the
|
2009-01-11 11:46:35 +03:00
|
|
|
// plugin, so they don't necessarily open external apps
|
2011-12-08 03:19:43 +04:00
|
|
|
// TYPE_WEBSOCKET loads can only go to ws:// or wss://, so we don't need to
|
|
|
|
// concern ourselves with them.
|
2007-06-17 17:50:50 +04:00
|
|
|
if (aContentType != TYPE_DOCUMENT &&
|
|
|
|
aContentType != TYPE_SUBDOCUMENT &&
|
2011-12-08 03:19:43 +04:00
|
|
|
aContentType != TYPE_OBJECT &&
|
|
|
|
aContentType != TYPE_WEBSOCKET) {
|
2007-07-25 21:21:41 +04:00
|
|
|
|
|
|
|
// The following are just quick-escapes for the most common cases
|
|
|
|
// where we would allow the content to be loaded anyway.
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString scheme;
|
2006-06-26 21:57:44 +04:00
|
|
|
aContentLocation->GetScheme(scheme);
|
|
|
|
if (scheme.EqualsLiteral("http") ||
|
|
|
|
scheme.EqualsLiteral("https") ||
|
|
|
|
scheme.EqualsLiteral("ftp") ||
|
|
|
|
scheme.EqualsLiteral("file") ||
|
|
|
|
scheme.EqualsLiteral("chrome")) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool shouldBlock;
|
2007-07-25 21:21:41 +04:00
|
|
|
nsresult rv = NS_URIChainHasFlags(aContentLocation,
|
|
|
|
nsIProtocolHandler::URI_DOES_NOT_RETURN_DATA,
|
|
|
|
&shouldBlock);
|
|
|
|
if (NS_SUCCEEDED(rv) && shouldBlock) {
|
2006-12-19 18:32:46 +03:00
|
|
|
*aDecision = nsIContentPolicy::REJECT_REQUEST;
|
2006-06-26 21:57:44 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsNoDataProtocolContentPolicy::ShouldProcess(uint32_t aContentType,
|
2006-06-26 21:57:44 +04:00
|
|
|
nsIURI *aContentLocation,
|
|
|
|
nsIURI *aRequestingLocation,
|
|
|
|
nsISupports *aRequestingContext,
|
|
|
|
const nsACString &aMimeGuess,
|
|
|
|
nsISupports *aExtra,
|
2012-07-03 03:16:11 +04:00
|
|
|
nsIPrincipal *aRequestPrincipal,
|
2012-08-22 19:56:38 +04:00
|
|
|
int16_t *aDecision)
|
2006-06-26 21:57:44 +04:00
|
|
|
{
|
|
|
|
return ShouldLoad(aContentType, aContentLocation, aRequestingLocation,
|
2012-07-03 03:16:11 +04:00
|
|
|
aRequestingContext, aMimeGuess, aExtra, aRequestPrincipal,
|
|
|
|
aDecision);
|
2006-06-26 21:57:44 +04:00
|
|
|
}
|