no bug - Bumping Firefox l10n changesets r=release a=l10n-bump DONTBUILD CLOSED TREE
[gecko.git] / image / ImageBlocker.cpp
blobeee07589f74438746febdea7f9ce8233cc063270
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 if (!aContentLocation) {
24 // Bug 1720280: Ideally we should block the load, but to avoid a potential
25 // null pointer deref, we return early in this case. Please note that
26 // the ImageBlocker only applies about http/https loads anyway.
27 return NS_OK;
30 // we only want to check http, https
31 // for chrome:// and resources and others, no need to check.
32 nsAutoCString scheme;
33 aContentLocation->GetScheme(scheme);
34 if (!scheme.LowerCaseEqualsLiteral("http") &&
35 !scheme.LowerCaseEqualsLiteral("https")) {
36 return NS_OK;
39 // Block loading images depending on the permissions.default.image pref.
40 if ((contentType == ExtContentPolicy::TYPE_IMAGE ||
41 contentType == ExtContentPolicy::TYPE_IMAGESET) &&
42 StaticPrefs::permissions_default_image() ==
43 nsIPermissionManager::DENY_ACTION) {
44 NS_SetRequestBlockingReason(
45 aLoadInfo, nsILoadInfo::BLOCKING_REASON_CONTENT_POLICY_CONTENT_BLOCKED);
46 *aShouldLoad = nsIContentPolicy::REJECT_TYPE;
49 return NS_OK;
52 NS_IMETHODIMP
53 ImageBlocker::ShouldProcess(nsIURI* aContentLocation, nsILoadInfo* aLoadInfo,
54 const nsACString& aMimeGuess,
55 int16_t* aShouldProcess) {
56 // We block images at load level already, so those should not end up here.
57 *aShouldProcess = nsIContentPolicy::ACCEPT;
58 return NS_OK;