Commit ba262011 authored by Ehsan Akhgari's avatar Ehsan Akhgari Committed by Georg Koppen
Browse files

Bug 1319908 - Load the menu icons for the bookmarks menu with the correct...

Bug 1319908 - Load the menu icons for the bookmarks menu with the correct content type and principal on OSX; r=baku

This patch makes nsMenuItemIconX also participate in the setup
introduced in bug 1277803.
parent debfd98e
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -1509,6 +1509,10 @@ var BookmarkingUI = {
    options.maxResults = kMaxResults;
    let query = PlacesUtils.history.getNewQuery();

    let sh = Cc["@mozilla.org/network/serialization-helper;1"]
               .getService(Ci.nsISerializationHelper);
    let loadingPrincipal = sh.serializeToString(document.nodePrincipal);

    let fragment = document.createDocumentFragment();
    let root = PlacesUtils.history.executeQuery(query, options).root;
    root.containerOpen = true;
@@ -1528,6 +1532,7 @@ var BookmarkingUI = {
                                 aExtraCSSClass);
      if (icon) {
        item.setAttribute("image", icon);
        item.setAttribute("loadingprincipal", loadingPrincipal);
      }
      item._placesNode = node;
      fragment.appendChild(item);
+31 −0
Original line number Diff line number Diff line
@@ -189,6 +189,7 @@
#include "nsReferencedElement.h"
#include "nsSandboxFlags.h"
#include "nsScriptSecurityManager.h"
#include "nsSerializationHelper.h"
#include "nsStreamUtils.h"
#include "nsTextEditorState.h"
#include "nsTextFragment.h"
@@ -9870,3 +9871,33 @@ nsContentUtils::AttemptLargeAllocationLoad(nsIHttpChannel* aChannel)

  return reloadSucceeded;
}

/* static */ void
nsContentUtils::GetContentPolicyTypeForUIImageLoading(nsIContent* aLoadingNode,
                                                      nsIPrincipal** aLoadingPrincipal,
                                                      nsContentPolicyType& aContentPolicyType)
{
  // Use the serialized loadingPrincipal from the image element. Fall back
  // to mContent's principal (SystemPrincipal) if not available.
  aContentPolicyType = nsIContentPolicy::TYPE_INTERNAL_IMAGE;
  nsCOMPtr<nsIPrincipal> loadingPrincipal = aLoadingNode->NodePrincipal();
  nsAutoString imageLoadingPrincipal;
  aLoadingNode->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.
      aContentPolicyType = nsIContentPolicy::TYPE_INTERNAL_IMAGE_FAVICON;
    } else {
      // Fallback if the deserialization is failed.
      loadingPrincipal = aLoadingNode->NodePrincipal();
    }
  }
  loadingPrincipal.forget(aLoadingPrincipal);
}
+10 −0
Original line number Diff line number Diff line
@@ -2736,6 +2736,16 @@ public:

  static bool AttemptLargeAllocationLoad(nsIHttpChannel* aChannel);

  /**
   * Returns the content policy type that should be used for loading images
   * for displaying in the UI.  The sources of such images can be <xul:image>,
   * <xul:menuitem> on OSX where we load the image through nsMenuItemIconX, etc.
   */
  static void
  GetContentPolicyTypeForUIImageLoading(nsIContent* aLoadingNode,
                                        nsIPrincipal** aLoadingPrincipal,
                                        nsContentPolicyType& aContentPolicyType);

private:
  static bool InitializeEventTable();

+5 −23
Original line number Diff line number Diff line
@@ -48,7 +48,6 @@
#include "nsIContent.h"

#include "nsContentUtils.h"
#include "nsSerializationHelper.h"

#include "mozilla/BasicEvents.h"
#include "mozilla/EventDispatcher.h"
@@ -227,28 +226,11 @@ nsImageBoxFrame::UpdateImage()
  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();
        }
      }
      nsContentPolicyType contentPolicyType;
      nsCOMPtr<nsIPrincipal> loadingPrincipal;
      nsContentUtils::GetContentPolicyTypeForUIImageLoading(mContent,
                                                            getter_AddRefs(loadingPrincipal),
                                                            contentPolicyType);

      nsCOMPtr<nsIURI> baseURI = mContent->GetBaseURI();
      nsCOMPtr<nsIURI> uri;
+3 −0
Original line number Diff line number Diff line
@@ -13,6 +13,7 @@
#include "mozilla/RefPtr.h"
#include "nsCOMPtr.h"
#include "imgINotificationObserver.h"
#include "nsIContentPolicy.h"

class nsIURI;
class nsIContent;
@@ -55,6 +56,8 @@ protected:
  nsresult OnFrameComplete(imgIRequest* aRequest);

  nsCOMPtr<nsIContent>      mContent;
  nsCOMPtr<nsIPrincipal>    mLoadingPrincipal;
  nsContentPolicyType       mContentType;
  RefPtr<imgRequestProxy> mIconRequest;
  nsMenuObjectX*            mMenuObject; // [weak]
  nsIntRect                 mImageRegionRect;
Loading