1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 * Content policy implementation that prevents all loads of images,
9 * subframes, etc from protocols that don't return data but rather open
10 * applications (such as mailto).
13 #include "nsNoDataProtocolContentPolicy.h"
15 #include "nsIProtocolHandler.h"
17 #include "nsNetUtil.h"
18 #include "nsContentUtils.h"
20 NS_IMPL_ISUPPORTS(nsNoDataProtocolContentPolicy
, nsIContentPolicy
)
23 nsNoDataProtocolContentPolicy::ShouldLoad(nsIURI
* aContentLocation
,
24 nsILoadInfo
* aLoadInfo
,
25 const nsACString
& aMimeGuess
,
27 ExtContentPolicyType contentType
= aLoadInfo
->GetExternalContentPolicyType();
29 *aDecision
= nsIContentPolicy::ACCEPT
;
31 // Don't block for TYPE_OBJECT since such URIs are sometimes loaded by the
32 // plugin, so they don't necessarily open external apps
33 // TYPE_WEBSOCKET loads can only go to ws:// or wss://, so we don't need to
34 // concern ourselves with them.
35 if (contentType
!= ExtContentPolicy::TYPE_DOCUMENT
&&
36 contentType
!= ExtContentPolicy::TYPE_SUBDOCUMENT
&&
37 contentType
!= ExtContentPolicy::TYPE_OBJECT
&&
38 contentType
!= ExtContentPolicy::TYPE_WEBSOCKET
) {
39 // The following are just quick-escapes for the most common cases
40 // where we would allow the content to be loaded anyway.
42 aContentLocation
->GetScheme(scheme
);
43 if (scheme
.EqualsLiteral("http") || scheme
.EqualsLiteral("https") ||
44 scheme
.EqualsLiteral("ftp") || scheme
.EqualsLiteral("file") ||
45 scheme
.EqualsLiteral("chrome")) {
49 if (nsContentUtils::IsExternalProtocol(aContentLocation
)) {
50 NS_SetRequestBlockingReason(
52 nsILoadInfo::BLOCKING_REASON_CONTENT_POLICY_NO_DATA_PROTOCOL
);
53 *aDecision
= nsIContentPolicy::REJECT_REQUEST
;
61 nsNoDataProtocolContentPolicy::ShouldProcess(nsIURI
* aContentLocation
,
62 nsILoadInfo
* aLoadInfo
,
63 const nsACString
& aMimeGuess
,
65 return ShouldLoad(aContentLocation
, aLoadInfo
, aMimeGuess
, aDecision
);