Bug 1835710 - Cancel off-thread JIT compilation before changing nursery allocation...
[gecko.git] / dom / base / nsNoDataProtocolContentPolicy.cpp
blob1911c613cf9c826f527d0e700884b00580399d8e
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 const nsACString& aMimeGuess,
26 int16_t* aDecision) {
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.
41 nsAutoCString scheme;
42 aContentLocation->GetScheme(scheme);
43 if (scheme.EqualsLiteral("http") || scheme.EqualsLiteral("https") ||
44 scheme.EqualsLiteral("ftp") || scheme.EqualsLiteral("file") ||
45 scheme.EqualsLiteral("chrome")) {
46 return NS_OK;
49 if (nsContentUtils::IsExternalProtocol(aContentLocation)) {
50 NS_SetRequestBlockingReason(
51 aLoadInfo,
52 nsILoadInfo::BLOCKING_REASON_CONTENT_POLICY_NO_DATA_PROTOCOL);
53 *aDecision = nsIContentPolicy::REJECT_REQUEST;
57 return NS_OK;
60 NS_IMETHODIMP
61 nsNoDataProtocolContentPolicy::ShouldProcess(nsIURI* aContentLocation,
62 nsILoadInfo* aLoadInfo,
63 const nsACString& aMimeGuess,
64 int16_t* aDecision) {
65 return ShouldLoad(aContentLocation, aLoadInfo, aMimeGuess, aDecision);