Bug 1277803 - Part 2 : Make favicons loaded through XUL:image use the correct principal. r=Gijs, tnikkel

This commit is contained in:
Tim Huang 2016-10-13 15:43:56 +08:00 коммит произвёл Jonathan Hao
Родитель 372ec56ff4
Коммит b05fe5b871
3 изменённых файлов: 29 добавлений и 3 удалений

Просмотреть файл

@ -6453,7 +6453,7 @@
class="tab-throbber" class="tab-throbber"
role="presentation" role="presentation"
layer="true" /> layer="true" />
<xul:image xbl:inherits="src=image,fadein,pinned,selected=visuallyselected,busy,crashed,sharing" <xul:image xbl:inherits="src=image,loadingprincipal=iconLoadingPrincipal,fadein,pinned,selected=visuallyselected,busy,crashed,sharing"
anonid="tab-icon-image" anonid="tab-icon-image"
class="tab-icon-image" class="tab-icon-image"
validate="never" validate="never"

Просмотреть файл

@ -557,6 +557,7 @@ GK_ATOM(listing, "listing")
GK_ATOM(listitem, "listitem") GK_ATOM(listitem, "listitem")
GK_ATOM(listrows, "listrows") GK_ATOM(listrows, "listrows")
GK_ATOM(load, "load") GK_ATOM(load, "load")
GK_ATOM(loadingprincipal, "loadingprincipal")
GK_ATOM(localedir, "localedir") GK_ATOM(localedir, "localedir")
GK_ATOM(localName, "local-name") GK_ATOM(localName, "local-name")
GK_ATOM(longdesc, "longdesc") GK_ATOM(longdesc, "longdesc")

Просмотреть файл

@ -48,6 +48,7 @@
#include "nsIContent.h" #include "nsIContent.h"
#include "nsContentUtils.h" #include "nsContentUtils.h"
#include "nsSerializationHelper.h"
#include "mozilla/BasicEvents.h" #include "mozilla/BasicEvents.h"
#include "mozilla/EventDispatcher.h" #include "mozilla/EventDispatcher.h"
@ -226,6 +227,29 @@ nsImageBoxFrame::UpdateImage()
if (mUseSrcAttr) { if (mUseSrcAttr) {
nsIDocument* doc = mContent->GetComposedDoc(); nsIDocument* doc = mContent->GetComposedDoc();
if (doc) { 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<nsIPrincipal> loadingPrincipal = mContent->NodePrincipal();
nsAutoString imageLoadingPrincipal;
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::loadingprincipal,
imageLoadingPrincipal);
if (!imageLoadingPrincipal.IsEmpty()) {
nsCOMPtr<nsISupports> 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<nsIURI> baseURI = mContent->GetBaseURI(); nsCOMPtr<nsIURI> baseURI = mContent->GetBaseURI();
nsCOMPtr<nsIURI> uri; nsCOMPtr<nsIURI> uri;
nsContentUtils::NewURIWithDocumentCharset(getter_AddRefs(uri), nsContentUtils::NewURIWithDocumentCharset(getter_AddRefs(uri),
@ -233,10 +257,11 @@ nsImageBoxFrame::UpdateImage()
doc, doc,
baseURI); baseURI);
if (uri) { if (uri) {
nsresult rv = nsContentUtils::LoadImage(uri, mContent, doc, mContent->NodePrincipal(), nsresult rv = nsContentUtils::LoadImage(uri, mContent, doc, loadingPrincipal,
doc->GetDocumentURI(), doc->GetReferrerPolicy(), doc->GetDocumentURI(), doc->GetReferrerPolicy(),
mListener, mLoadFlags, mListener, mLoadFlags,
EmptyString(), getter_AddRefs(mImageRequest)); EmptyString(), getter_AddRefs(mImageRequest),
contentPolicyType);
if (NS_SUCCEEDED(rv) && mImageRequest) { if (NS_SUCCEEDED(rv) && mImageRequest) {
nsLayoutUtils::RegisterImageRequestIfAnimated(presContext, nsLayoutUtils::RegisterImageRequestIfAnimated(presContext,