Bug 1277803 - Part 2: Make favicons loaded through XUL:image use the correct principal. r=Gijs, r=tnikkel
☠☠ backed out by 4fa317481105 ☠ ☠
authorTim Huang <tihuang@mozilla.com>
Tue, 04 Oct 2016 19:53:00 -0400
changeset 316903 1d88072cf36af970f3341b99f4eeada61875586a
parent 316902 d283c59402ce1c63bae3b89457abe9238fb75e1a
child 316904 d3a02bf398becc626a3069650fb74686c0205183
push id30787
push userryanvm@gmail.com
push dateFri, 07 Oct 2016 13:42:34 +0000
treeherdermozilla-central@ea8624a9b11e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGijs, tnikkel
bugs1277803
milestone52.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1277803 - Part 2: Make favicons loaded through XUL:image use the correct principal. r=Gijs, r=tnikkel
browser/base/content/tabbrowser.xml
dom/base/nsGkAtomList.h
layout/xul/nsImageBoxFrame.cpp
--- a/browser/base/content/tabbrowser.xml
+++ b/browser/base/content/tabbrowser.xml
@@ -6455,17 +6455,17 @@
                     class="tab-background-end"/>
         </xul:hbox>
         <xul:hbox xbl:inherits="pinned,selected=visuallyselected,titlechanged,attention"
                   class="tab-content" align="center">
           <xul:image xbl:inherits="fadein,pinned,busy,progress,selected=visuallyselected"
                      class="tab-throbber"
                      role="presentation"
                      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"
                      class="tab-icon-image"
                      validate="never"
                      role="presentation"/>
           <xul:image xbl:inherits="sharing,selected=visuallyselected"
                      anonid="sharing-icon"
                      class="tab-sharing-icon-overlay"
                      role="presentation"/>
--- a/dom/base/nsGkAtomList.h
+++ b/dom/base/nsGkAtomList.h
@@ -552,16 +552,17 @@ GK_ATOM(listcol, "listcol")
 GK_ATOM(listcols, "listcols")
 GK_ATOM(listener, "listener")
 GK_ATOM(listhead, "listhead")
 GK_ATOM(listheader, "listheader")
 GK_ATOM(listing, "listing")
 GK_ATOM(listitem, "listitem")
 GK_ATOM(listrows, "listrows")
 GK_ATOM(load, "load")
+GK_ATOM(loadingprincipal, "loadingprincipal")
 GK_ATOM(localedir, "localedir")
 GK_ATOM(localName, "local-name")
 GK_ATOM(longdesc, "longdesc")
 GK_ATOM(loop, "loop")
 GK_ATOM(low, "low")
 GK_ATOM(lowerFirst, "lower-first")
 GK_ATOM(lowest, "lowest")
 GK_ATOM(lowsrc, "lowsrc")
--- a/layout/xul/nsImageBoxFrame.cpp
+++ b/layout/xul/nsImageBoxFrame.cpp
@@ -43,16 +43,17 @@
 #include "nsIURI.h"
 #include "nsThreadUtils.h"
 #include "nsDisplayList.h"
 #include "ImageLayers.h"
 #include "ImageContainer.h"
 #include "nsIContent.h"
 
 #include "nsContentUtils.h"
+#include "nsSerializationHelper.h"
 
 #include "mozilla/BasicEvents.h"
 #include "mozilla/EventDispatcher.h"
 #include "mozilla/Maybe.h"
 
 #define ONLOAD_CALLED_TOO_EARLY 1
 
 using namespace mozilla;
@@ -221,27 +222,51 @@ nsImageBoxFrame::UpdateImage()
 
   // get the new image src
   nsAutoString src;
   mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::src, src);
   mUseSrcAttr = !src.IsEmpty();
   if (mUseSrcAttr) {
     nsIDocument* doc = mContent->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<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> uri;
       nsContentUtils::NewURIWithDocumentCharset(getter_AddRefs(uri),
                                                 src,
                                                 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,
                                                         mImageRequest,
                                                         &mRequestRegistered);
         }
       }
     }