Bug 1417869. P2 - abort the load algorithm early if media not allowed to load.
MozReview-Commit-ID: DUxyo4ywCPW
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -1961,16 +1961,23 @@ NS_IMETHODIMP HTMLMediaElement::Load()
mIsDoingExplicitLoad = true;
DoLoad();
return NS_OK;
}
void HTMLMediaElement::DoLoad()
{
+ // Check if media is allowed for the docshell.
+ nsCOMPtr<nsIDocShell> docShell = OwnerDoc()->GetDocShell();
+ if (docShell && !docShell->GetAllowMedia()) {
+ LOG(LogLevel::Debug, ("%p Media not allowed", this));
+ return;
+ }
+
if (mIsRunningLoadMethod) {
return;
}
// Detect if user has interacted with element so that play will not be
// blocked when initiated by a script. This enables sites to capture user
// intent to play by calling load() in the click handler of a "catalog
// view" of a gallery of videos.
@@ -2509,22 +2516,16 @@ HTMLMediaElement::LoadResource()
NS_ASSERTION(mDelayingLoadEvent,
"Should delay load event (if in document) during load");
if (mChannelLoader) {
mChannelLoader->Cancel();
mChannelLoader = nullptr;
}
- // Check if media is allowed for the docshell.
- nsCOMPtr<nsIDocShell> docShell = OwnerDoc()->GetDocShell();
- if (docShell && !docShell->GetAllowMedia()) {
- return MediaResult(NS_ERROR_FAILURE, "Media not allowed");
- }
-
// Set the media element's CORS mode only when loading a resource
mCORSMode = AttrValueToCORSMode(GetParsedAttr(nsGkAtoms::crossorigin));
HTMLMediaElement* other = LookupMediaElementURITable(mLoadingSrc);
if (other && other->mDecoder) {
// Clone it.
// TODO: remove the cast by storing ChannelMediaDecoder in the URI table.
nsresult rv = InitializeDecoderAsClone(