[tbb-commits] [tor-browser/tor-browser-52.1.0esr-7.0-2] Bug 1319908 - Load the menu icons for the bookmarks menu with the correct content type and principal on OSX; r=baku
gk at torproject.org
gk at torproject.org
Wed May 31 20:36:42 UTC 2017
commit ef0f9d150d4210bed5b517763cf8872e7f729649
Author: Ehsan Akhgari <ehsan at mozilla.com>
Date: Wed Dec 14 15:52:57 2016 -0500
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.
---
browser/base/content/browser-places.js | 5 +++++
dom/base/nsContentUtils.cpp | 31 +++++++++++++++++++++++++++++++
dom/base/nsContentUtils.h | 10 ++++++++++
layout/xul/nsImageBoxFrame.cpp | 28 +++++-----------------------
widget/cocoa/nsMenuItemIconX.h | 3 +++
widget/cocoa/nsMenuItemIconX.mm | 14 ++++++++++----
6 files changed, 64 insertions(+), 27 deletions(-)
diff --git a/browser/base/content/browser-places.js b/browser/base/content/browser-places.js
index 14e90cd..3998b5b 100644
--- a/browser/base/content/browser-places.js
+++ b/browser/base/content/browser-places.js
@@ -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);
diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp
index 539d189..48f7991 100644
--- a/dom/base/nsContentUtils.cpp
+++ b/dom/base/nsContentUtils.cpp
@@ -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);
+}
diff --git a/dom/base/nsContentUtils.h b/dom/base/nsContentUtils.h
index e991fb7..3c7d9eb 100644
--- a/dom/base/nsContentUtils.h
+++ b/dom/base/nsContentUtils.h
@@ -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();
diff --git a/layout/xul/nsImageBoxFrame.cpp b/layout/xul/nsImageBoxFrame.cpp
index fd7c7be..89b583c 100644
--- a/layout/xul/nsImageBoxFrame.cpp
+++ b/layout/xul/nsImageBoxFrame.cpp
@@ -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;
diff --git a/widget/cocoa/nsMenuItemIconX.h b/widget/cocoa/nsMenuItemIconX.h
index 7352a94..3bbe5d9 100644
--- a/widget/cocoa/nsMenuItemIconX.h
+++ b/widget/cocoa/nsMenuItemIconX.h
@@ -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;
diff --git a/widget/cocoa/nsMenuItemIconX.mm b/widget/cocoa/nsMenuItemIconX.mm
index 7589c27..261e63b 100644
--- a/widget/cocoa/nsMenuItemIconX.mm
+++ b/widget/cocoa/nsMenuItemIconX.mm
@@ -59,6 +59,8 @@ nsMenuItemIconX::nsMenuItemIconX(nsMenuObjectX* aMenuItem,
nsIContent* aContent,
NSMenuItem* aNativeMenuItem)
: mContent(aContent)
+, mLoadingPrincipal(aContent->NodePrincipal())
+, mContentType(nsIContentPolicy::TYPE_INTERNAL_IMAGE)
, mMenuObject(aMenuItem)
, mLoadedIcon(false)
, mSetIcon(false)
@@ -209,6 +211,10 @@ nsMenuItemIconX::GetIconURI(nsIURI** aIconURI)
rv = primitiveValue->GetStringValue(imageURIString);
if (NS_FAILED(rv)) return rv;
+ } else {
+ nsContentUtils::GetContentPolicyTypeForUIImageLoading(mContent,
+ getter_AddRefs(mLoadingPrincipal),
+ mContentType);
}
// Empty the mImageRegionRect initially as the image region CSS could
@@ -310,10 +316,10 @@ nsMenuItemIconX::LoadIcon(nsIURI* aIconURI)
}
nsresult rv = loader->LoadImage(aIconURI, nullptr, nullptr,
- mozilla::net::RP_Default,
- nullptr, loadGroup, this,
- nullptr, nullptr, nsIRequest::LOAD_NORMAL, nullptr,
- nsIContentPolicy::TYPE_INTERNAL_IMAGE, EmptyString(),
+ mozilla::net::RP_Unset,
+ mLoadingPrincipal, loadGroup, this,
+ mContent, document, nsIRequest::LOAD_NORMAL, nullptr,
+ mContentType, EmptyString(),
getter_AddRefs(mIconRequest));
if (NS_FAILED(rv)) return rv;
More information about the tbb-commits
mailing list