diff --git a/browser/base/content/tabbrowser.xml b/browser/base/content/tabbrowser.xml index 8b896f77f8b5..58ae92f838cf 100644 --- a/browser/base/content/tabbrowser.xml +++ b/browser/base/content/tabbrowser.xml @@ -6453,7 +6453,7 @@ class="tab-throbber" role="presentation" layer="true" /> - GetComposedDoc(); if (doc) { + // Use the serialized loadingPrincipal from the image element. Fall back + // to mContent's principal (SystemPrincipal) if not available. + nsContentPolicyType contentPolicyType = nsIContentPolicy::TYPE_INTERNAL_IMAGE; + nsCOMPtr loadingPrincipal = mContent->NodePrincipal(); + nsAutoString imageLoadingPrincipal; + mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::loadingprincipal, + imageLoadingPrincipal); + if (!imageLoadingPrincipal.IsEmpty()) { + nsCOMPtr serializedPrincipal; + NS_DeserializeObject(NS_ConvertUTF16toUTF8(imageLoadingPrincipal), + getter_AddRefs(serializedPrincipal)); + loadingPrincipal = do_QueryInterface(serializedPrincipal); + + if (loadingPrincipal) { + // Set the content policy type to TYPE_INTERNAL_IMAGE_FAVICON for + // indicating it's a favicon loading. + contentPolicyType = nsIContentPolicy::TYPE_INTERNAL_IMAGE_FAVICON; + } else { + // Fallback if the deserialization is failed. + loadingPrincipal = mContent->NodePrincipal(); + } + } + nsCOMPtr baseURI = mContent->GetBaseURI(); nsCOMPtr uri; nsContentUtils::NewURIWithDocumentCharset(getter_AddRefs(uri), @@ -233,10 +257,11 @@ nsImageBoxFrame::UpdateImage() doc, baseURI); if (uri) { - nsresult rv = nsContentUtils::LoadImage(uri, mContent, doc, mContent->NodePrincipal(), + nsresult rv = nsContentUtils::LoadImage(uri, mContent, doc, loadingPrincipal, doc->GetDocumentURI(), doc->GetReferrerPolicy(), mListener, mLoadFlags, - EmptyString(), getter_AddRefs(mImageRequest)); + EmptyString(), getter_AddRefs(mImageRequest), + contentPolicyType); if (NS_SUCCEEDED(rv) && mImageRequest) { nsLayoutUtils::RegisterImageRequestIfAnimated(presContext,