From 929f8dc13e9a5cbe04ac190a4f82fafc91d901a5 Mon Sep 17 00:00:00 2001 From: John Schoenick Date: Tue, 19 Aug 2014 14:49:14 -0700 Subject: [PATCH] Bug 1055750 - Part 2 - nsContentUtils add optional content policy parameter to nsContentUtils::{Can,}LoadImage r=tanvi --- content/base/public/nsContentUtils.h | 18 +++++++++++++----- content/base/src/nsContentUtils.cpp | 8 +++++--- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/content/base/public/nsContentUtils.h b/content/base/public/nsContentUtils.h index 0ae1c1fdbc6..6bae90cf047 100644 --- a/content/base/public/nsContentUtils.h +++ b/content/base/public/nsContentUtils.h @@ -30,6 +30,7 @@ #include "mozilla/dom/AutocompleteInfoBinding.h" #include "mozilla/dom/ScriptSettings.h" #include "mozilla/FloatingPoint.h" +#include "nsIContentPolicy.h" #if defined(XP_WIN) // Undefine LoadImage to prevent naming conflict with Windows. @@ -591,6 +592,8 @@ public: * @param aContext the context the image is loaded in (eg an element) * @param aLoadingDocument the document we belong to * @param aLoadingPrincipal the principal doing the load + * @param [aContentPolicyType=nsIContentPolicy::TYPE_IMAGE] (Optional) + * The CP content type to use * @param aImageBlockingStatus the nsIContentPolicy blocking status for this * image. This will be set even if a security check fails for the * image, to some reasonable REJECT_* value. This out param will only @@ -601,10 +604,12 @@ public: * false is returned. */ static bool CanLoadImage(nsIURI* aURI, - nsISupports* aContext, - nsIDocument* aLoadingDocument, - nsIPrincipal* aLoadingPrincipal, - int16_t* aImageBlockingStatus = nullptr); + nsISupports* aContext, + nsIDocument* aLoadingDocument, + nsIPrincipal* aLoadingPrincipal, + int16_t* aImageBlockingStatus = nullptr, + uint32_t aContentPolicyType = nsIContentPolicy::TYPE_IMAGE); + /** * Method to start an image load. This does not do any security checks. * This method will attempt to make aURI immutable; a caller that wants to @@ -616,6 +621,8 @@ public: * @param aReferrer the referrer URI * @param aObserver the observer for the image load * @param aLoadFlags the load flags to use. See nsIRequest + * @param [aContentPolicyType=nsIContentPolicy::TYPE_IMAGE] (Optional) + * The CP content type to use * @return the imgIRequest for the image load */ static nsresult LoadImage(nsIURI* aURI, @@ -625,7 +632,8 @@ public: imgINotificationObserver* aObserver, int32_t aLoadFlags, const nsAString& initiatorType, - imgRequestProxy** aRequest); + imgRequestProxy** aRequest, + uint32_t aContentPolicyType = nsIContentPolicy::TYPE_IMAGE); /** * Obtain an image loader that respects the given document/channel's privacy status. diff --git a/content/base/src/nsContentUtils.cpp b/content/base/src/nsContentUtils.cpp index e347523d84a..427ddd97e95 100644 --- a/content/base/src/nsContentUtils.cpp +++ b/content/base/src/nsContentUtils.cpp @@ -2861,7 +2861,8 @@ bool nsContentUtils::CanLoadImage(nsIURI* aURI, nsISupports* aContext, nsIDocument* aLoadingDocument, nsIPrincipal* aLoadingPrincipal, - int16_t* aImageBlockingStatus) + int16_t* aImageBlockingStatus, + uint32_t aContentType) { NS_PRECONDITION(aURI, "Must have a URI"); NS_PRECONDITION(aLoadingDocument, "Must have a document"); @@ -2904,7 +2905,7 @@ nsContentUtils::CanLoadImage(nsIURI* aURI, nsISupports* aContext, int16_t decision = nsIContentPolicy::ACCEPT; - rv = NS_CheckContentLoadPolicy(nsIContentPolicy::TYPE_IMAGE, + rv = NS_CheckContentLoadPolicy(aContentType, aURI, aLoadingPrincipal, aContext, @@ -2985,7 +2986,8 @@ nsContentUtils::LoadImage(nsIURI* aURI, nsIDocument* aLoadingDocument, nsIPrincipal* aLoadingPrincipal, nsIURI* aReferrer, imgINotificationObserver* aObserver, int32_t aLoadFlags, const nsAString& initiatorType, - imgRequestProxy** aRequest) + imgRequestProxy** aRequest, + uint32_t aContentPolicyType) { NS_PRECONDITION(aURI, "Must have a URI"); NS_PRECONDITION(aLoadingDocument, "Must have a document");