From 91878c9769d02ab94d747e82851f2436a01eb8d3 Mon Sep 17 00:00:00 2001 From: Tim Huang Date: Wed, 12 Oct 2016 17:32:06 +0800 Subject: [PATCH] Bug 1277803 - Part 3 : Make the image library uses the correct originAttributes and triggering principal when opening a image channel for favicon loading. r=tnikkel --- image/imgLoader.cpp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/image/imgLoader.cpp b/image/imgLoader.cpp index 00b8ebd9ab3f..40f98e1ae902 100644 --- a/image/imgLoader.cpp +++ b/image/imgLoader.cpp @@ -743,14 +743,28 @@ NewImageChannel(nsIChannel** aResult, nullptr, // loadGroup callbacks, aLoadFlags); + + if (NS_FAILED(rv)) { + return rv; + } + + if (aPolicyType == nsIContentPolicy::TYPE_INTERNAL_IMAGE_FAVICON) { + // If this is a favicon loading, we will use the originAttributes from the + // loadingPrincipal as the channel's originAttributes. This allows the favicon + // loading from XUL will use the correct originAttributes. + NeckoOriginAttributes neckoAttrs; + neckoAttrs.InheritFromDocToNecko(BasePrincipal::Cast(aLoadingPrincipal)->OriginAttributesRef()); + + nsCOMPtr loadInfo = (*aResult)->GetLoadInfo(); + rv = loadInfo->SetOriginAttributes(neckoAttrs); + } } else { // either we are loading something inside a document, in which case // we should always have a requestingNode, or we are loading something // outside a document, in which case the loadingPrincipal and // triggeringPrincipal should always be the systemPrincipal. - // However, there are two exceptions: one is Notifications and the - // other one is Favicons which create a channel in the parent prcoess - // in which case we can't get a requestingNode. + // However, there are exceptions: one is Notifications which create a + // channel in the parent prcoess in which case we can't get a requestingNode. rv = NS_NewChannel(aResult, aURI, nsContentUtils::GetSystemPrincipal(),