зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1376971 - Part 2: add GetLoadingPrincipalForXULNode. r=baku
Refactor GetContentPolicyTypeForUIImageLoading to have another function called GetLoadingPrincipalForXULNode.
This commit is contained in:
Родитель
9e9be5b555
Коммит
58d0d5ec00
|
@ -10444,6 +10444,44 @@ nsContentUtils::AppendNativeAnonymousChildren(
|
|||
}
|
||||
}
|
||||
|
||||
/* static */ bool
|
||||
nsContentUtils::GetLoadingPrincipalForXULNode(nsIContent* aLoadingNode,
|
||||
nsIPrincipal** aLoadingPrincipal)
|
||||
{
|
||||
MOZ_ASSERT(aLoadingNode);
|
||||
MOZ_ASSERT(aLoadingPrincipal);
|
||||
|
||||
bool result = false;
|
||||
nsCOMPtr<nsIPrincipal> loadingPrincipal = aLoadingNode->NodePrincipal();
|
||||
nsAutoString loadingStr;
|
||||
aLoadingNode->GetAttr(kNameSpaceID_None, nsGkAtoms::loadingprincipal,
|
||||
loadingStr);
|
||||
if (loadingStr.IsEmpty()) {
|
||||
// Fall back to mContent's principal (SystemPrincipal) if 'loadingprincipal'
|
||||
// isn't specified.
|
||||
loadingPrincipal.forget(aLoadingPrincipal);
|
||||
return result;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsISupports> serializedPrincipal;
|
||||
NS_DeserializeObject(NS_ConvertUTF16toUTF8(loadingStr),
|
||||
getter_AddRefs(serializedPrincipal));
|
||||
loadingPrincipal = do_QueryInterface(serializedPrincipal);
|
||||
if (loadingPrincipal) {
|
||||
// We only allow specifying loadingprincipal attribute on a node loaded by
|
||||
// SystemPrincipal.
|
||||
MOZ_ASSERT(nsContentUtils::IsSystemPrincipal(aLoadingNode->NodePrincipal()),
|
||||
"aLoadingNode Should be loaded with SystemPrincipal");
|
||||
|
||||
result = true;
|
||||
} else {
|
||||
// Fallback if the deserialization is failed.
|
||||
loadingPrincipal = aLoadingNode->NodePrincipal();
|
||||
}
|
||||
|
||||
loadingPrincipal.forget(aLoadingPrincipal);
|
||||
return result;
|
||||
}
|
||||
|
||||
/* static */ void
|
||||
nsContentUtils::GetContentPolicyTypeForUIImageLoading(nsIContent* aLoadingNode,
|
||||
|
@ -10453,38 +10491,23 @@ nsContentUtils::GetContentPolicyTypeForUIImageLoading(nsIContent* aLoadingNode,
|
|||
{
|
||||
MOZ_ASSERT(aRequestContextID);
|
||||
|
||||
// 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);
|
||||
bool result = GetLoadingPrincipalForXULNode(aLoadingNode, aLoadingPrincipal);
|
||||
if (result) {
|
||||
// Set the content policy type to TYPE_INTERNAL_IMAGE_FAVICON for
|
||||
// indicating it's a favicon loading.
|
||||
aContentPolicyType = nsIContentPolicy::TYPE_INTERNAL_IMAGE_FAVICON;
|
||||
|
||||
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;
|
||||
|
||||
nsAutoString requestContextID;
|
||||
aLoadingNode->GetAttr(kNameSpaceID_None, nsGkAtoms::requestcontextid,
|
||||
requestContextID);
|
||||
nsresult rv;
|
||||
int64_t val = requestContextID.ToInteger64(&rv);
|
||||
*aRequestContextID = NS_SUCCEEDED(rv)
|
||||
? val
|
||||
: 0;
|
||||
} else {
|
||||
// Fallback if the deserialization is failed.
|
||||
loadingPrincipal = aLoadingNode->NodePrincipal();
|
||||
}
|
||||
nsAutoString requestContextID;
|
||||
aLoadingNode->GetAttr(kNameSpaceID_None, nsGkAtoms::requestcontextid,
|
||||
requestContextID);
|
||||
nsresult rv;
|
||||
int64_t val = requestContextID.ToInteger64(&rv);
|
||||
*aRequestContextID = NS_SUCCEEDED(rv)
|
||||
? val
|
||||
: 0;
|
||||
} else {
|
||||
aContentPolicyType = nsIContentPolicy::TYPE_INTERNAL_IMAGE;
|
||||
}
|
||||
loadingPrincipal.forget(aLoadingPrincipal);
|
||||
}
|
||||
|
||||
/* static */ nsresult
|
||||
|
|
|
@ -3038,6 +3038,19 @@ public:
|
|||
nsTArray<nsIContent*>& aKids,
|
||||
uint32_t aFlags);
|
||||
|
||||
/**
|
||||
* Query loadingPrincipal if it is specified as 'loadingprincipal' attribute on
|
||||
* aLoadingNode, otherwise the NodePrincipal of aLoadingNode is returned
|
||||
* (which is System Principal).
|
||||
*
|
||||
* Return true if aLoadingPrincipal has 'loadingprincipal' attributes, and
|
||||
* the value 'loadingprincipal' is also successfully deserialized, otherwise
|
||||
* return false.
|
||||
*/
|
||||
static bool
|
||||
GetLoadingPrincipalForXULNode(nsIContent* aLoadingNode,
|
||||
nsIPrincipal** aLoadingPrincipal);
|
||||
|
||||
/**
|
||||
* 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>,
|
||||
|
|
Загрузка…
Ссылка в новой задаче