зеркало из https://github.com/mozilla/gecko-dev.git
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.
This commit is contained in:
Родитель
20febcb2bd
Коммит
b3e5ce4a2d
|
@ -1481,6 +1481,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;
|
||||
|
@ -1500,6 +1504,7 @@ var BookmarkingUI = {
|
|||
aExtraCSSClass);
|
||||
if (icon) {
|
||||
item.setAttribute("image", icon);
|
||||
item.setAttribute("loadingprincipal", loadingPrincipal);
|
||||
}
|
||||
item._placesNode = node;
|
||||
fragment.appendChild(item);
|
||||
|
|
|
@ -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"
|
||||
|
@ -9779,3 +9780,33 @@ nsContentUtils::AppendDocumentLevelNativeAnonymousContentTo(
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* 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);
|
||||
}
|
||||
|
|
|
@ -2743,6 +2743,16 @@ public:
|
|||
nsIDocument* aDocument,
|
||||
nsTArray<nsIContent*>& aElements);
|
||||
|
||||
/**
|
||||
* 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();
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
@ -311,9 +317,9 @@ nsMenuItemIconX::LoadIcon(nsIURI* aIconURI)
|
|||
|
||||
nsresult rv = loader->LoadImage(aIconURI, nullptr, nullptr,
|
||||
mozilla::net::RP_Unset,
|
||||
nullptr, loadGroup, this,
|
||||
nullptr, nullptr, nsIRequest::LOAD_NORMAL, nullptr,
|
||||
nsIContentPolicy::TYPE_INTERNAL_IMAGE, EmptyString(),
|
||||
mLoadingPrincipal, loadGroup, this,
|
||||
mContent, document, nsIRequest::LOAD_NORMAL, nullptr,
|
||||
mContentType, EmptyString(),
|
||||
getter_AddRefs(mIconRequest));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче