Bug 1376971 - Part 4: query loadingprincipal in HTMLMediaElement. r=baku

Query loadingprincipal attribute on the media part.
This commit is contained in:
Yoshi Huang
2017-09-15 18:47:44 +08:00
parent 0b67670ad3
commit a0632ce656
2 changed files with 59 additions and 19 deletions

View File

@@ -1191,19 +1191,31 @@ public:
? nsIContentPolicy::TYPE_INTERNAL_AUDIO :
nsIContentPolicy::TYPE_INTERNAL_VIDEO;
// If aElement has 'loadingprincipal' attribute, we will use the value as
// loadingPrincipal for the channel, otherwise it will default to use
// aElement->NodePrincipal().
// This function returns true when aElement has 'loadingprincipal', so if
// setAttrs is true we will override the origin attributes on the channel
// later.
nsCOMPtr<nsIPrincipal> loadingPrincipal;
bool setAttrs = nsContentUtils::GetLoadingPrincipalForXULNode(aElement,
getter_AddRefs(loadingPrincipal));
nsCOMPtr<nsILoadGroup> loadGroup = aElement->GetDocumentLoadGroup();
nsCOMPtr<nsIChannel> channel;
nsresult rv = NS_NewChannel(getter_AddRefs(channel),
aElement->mLoadingSrc,
static_cast<Element*>(aElement),
securityFlags,
contentPolicyType,
loadGroup,
nullptr, // aCallbacks
nsICachingChannel::LOAD_BYPASS_LOCAL_CACHE_IF_BUSY |
nsIChannel::LOAD_MEDIA_SNIFFER_OVERRIDES_CONTENT_TYPE |
nsIChannel::LOAD_CLASSIFY_URI |
nsIChannel::LOAD_CALL_CONTENT_SNIFFERS);
nsresult rv =
NS_NewChannelWithTriggeringPrincipal(getter_AddRefs(channel),
aElement->mLoadingSrc,
static_cast<Element*>(aElement),
loadingPrincipal,
securityFlags,
contentPolicyType,
loadGroup,
nullptr, // aCallbacks
nsICachingChannel::LOAD_BYPASS_LOCAL_CACHE_IF_BUSY |
nsIChannel::LOAD_MEDIA_SNIFFER_OVERRIDES_CONTENT_TYPE |
nsIChannel::LOAD_CLASSIFY_URI |
nsIChannel::LOAD_CALL_CONTENT_SNIFFERS);
if (NS_FAILED(rv)) {
// Notify load error so the element will try next resource candidate.
@@ -1211,6 +1223,14 @@ public:
return;
}
if (setAttrs) {
nsCOMPtr<nsILoadInfo> loadInfo = channel->GetLoadInfo();
if (loadInfo) {
// The function simply returns NS_OK, so we ignore the return value.
Unused << loadInfo->SetOriginAttributes(loadingPrincipal->OriginAttributesRef());
}
}
nsCOMPtr<nsIClassOfService> cos(do_QueryInterface(channel));
if (cos) {
if (aElement->mUseUrgentStartForChannel) {