Bug 1733130 [wpt PR 30935] - Fix ttwf-transform-translatex-001.html., a=testonly
[gecko.git] / image / ImageBlocker.cpp
blobb9684d99f27b6f4407afce62a37c9ebffcd4cb9e
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #include "ImageBlocker.h"
6 #include "nsIPermissionManager.h"
7 #include "nsContentUtils.h"
8 #include "mozilla/StaticPrefs_permissions.h"
9 #include "nsNetUtil.h"
11 using namespace mozilla;
12 using namespace mozilla::image;
14 NS_IMPL_ISUPPORTS(ImageBlocker, nsIContentPolicy)
16 NS_IMETHODIMP
17 ImageBlocker::ShouldLoad(nsIURI* aContentLocation, nsILoadInfo* aLoadInfo,
18 const nsACString& aMimeGuess, int16_t* aShouldLoad) {
19 ExtContentPolicyType contentType = aLoadInfo->GetExternalContentPolicyType();
21 *aShouldLoad = nsIContentPolicy::ACCEPT;
23 // we only want to check http, https, ftp
24 // for chrome:// and resources and others, no need to check.
25 nsAutoCString scheme;
26 aContentLocation->GetScheme(scheme);
27 if (!scheme.LowerCaseEqualsLiteral("ftp") &&
28 !scheme.LowerCaseEqualsLiteral("http") &&
29 !scheme.LowerCaseEqualsLiteral("https")) {
30 return NS_OK;
33 // Block loading images depending on the permissions.default.image pref.
34 if ((contentType == ExtContentPolicy::TYPE_IMAGE ||
35 contentType == ExtContentPolicy::TYPE_IMAGESET) &&
36 StaticPrefs::permissions_default_image() ==
37 nsIPermissionManager::DENY_ACTION) {
38 NS_SetRequestBlockingReason(
39 aLoadInfo, nsILoadInfo::BLOCKING_REASON_CONTENT_POLICY_CONTENT_BLOCKED);
40 *aShouldLoad = nsIContentPolicy::REJECT_TYPE;
43 return NS_OK;
46 NS_IMETHODIMP
47 ImageBlocker::ShouldProcess(nsIURI* aContentLocation, nsILoadInfo* aLoadInfo,
48 const nsACString& aMimeGuess,
49 int16_t* aShouldProcess) {
50 // We block images at load level already, so those should not end up here.
51 *aShouldProcess = nsIContentPolicy::ACCEPT;
52 return NS_OK;