Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / dom / base / nsNoDataProtocolContentPolicy.cpp
blob0650b9ec9fdd2d573eaa702b88e6d3e4b3877931
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/. */
7 /*
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"
14 #include "nsString.h"
15 #include "nsIProtocolHandler.h"
16 #include "nsIURI.h"
17 #include "nsNetUtil.h"
18 #include "nsContentUtils.h"
20 NS_IMPL_ISUPPORTS(nsNoDataProtocolContentPolicy, nsIContentPolicy)
22 NS_IMETHODIMP
23 nsNoDataProtocolContentPolicy::ShouldLoad(nsIURI* aContentLocation,
24 nsILoadInfo* aLoadInfo,
25 int16_t* aDecision) {
26 ExtContentPolicyType contentType = aLoadInfo->GetExternalContentPolicyType();
28 *aDecision = nsIContentPolicy::ACCEPT;
30 // Don't block for TYPE_OBJECT since such URIs are sometimes loaded by the
31 // plugin, so they don't necessarily open external apps
32 // TYPE_WEBSOCKET loads can only go to ws:// or wss://, so we don't need to
33 // concern ourselves with them.
34 if (contentType != ExtContentPolicy::TYPE_DOCUMENT &&
35 contentType != ExtContentPolicy::TYPE_SUBDOCUMENT &&
36 contentType != ExtContentPolicy::TYPE_OBJECT &&
37 contentType != ExtContentPolicy::TYPE_WEBSOCKET) {
38 // The following are just quick-escapes for the most common cases
39 // where we would allow the content to be loaded anyway.
40 nsAutoCString scheme;
41 aContentLocation->GetScheme(scheme);
42 if (scheme.EqualsLiteral("http") || scheme.EqualsLiteral("https") ||
43 scheme.EqualsLiteral("file") || scheme.EqualsLiteral("chrome")) {
44 return NS_OK;
47 if (nsContentUtils::IsExternalProtocol(aContentLocation)) {
48 NS_SetRequestBlockingReason(
49 aLoadInfo,
50 nsILoadInfo::BLOCKING_REASON_CONTENT_POLICY_NO_DATA_PROTOCOL);
51 *aDecision = nsIContentPolicy::REJECT_REQUEST;
55 return NS_OK;
58 NS_IMETHODIMP
59 nsNoDataProtocolContentPolicy::ShouldProcess(nsIURI* aContentLocation,
60 nsILoadInfo* aLoadInfo,
61 int16_t* aDecision) {
62 return ShouldLoad(aContentLocation, aLoadInfo, aDecision);