Bug 1417869. P2 - abort the load algorithm early if media not allowed to load. draft
authorJW Wang <jwwang@mozilla.com>
Tue, 21 Nov 2017 14:02:13 +0800
changeset 701109 735b425df5148cf3cced3a242f421c1ebd0604f5
parent 701108 6de327c43ef42a63632531e7ee733713658e8944
child 741091 e9e1d8fcc44bba0cd374b14e867a55140d714fd3
push id90073
push userjwwang@mozilla.com
push dateTue, 21 Nov 2017 08:07:51 +0000
bugs1417869
milestone59.0a1
Bug 1417869. P2 - abort the load algorithm early if media not allowed to load. MozReview-Commit-ID: DUxyo4ywCPW
dom/html/HTMLMediaElement.cpp
--- 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(