Bug 1417869. P2 - abort the load algorithm early if media not allowed to load. r=jya, a=Sylvestre
authorJW Wang <jwwang@mozilla.com>
Tue, 21 Nov 2017 14:02:13 +0800
changeset 444910 341dd6e739b885f7f73e1c2812cb51aa76dd083f
parent 444909 6c6c316f7254c08c5e110e5165fdf5624e2c1a44
child 444911 2c358715fab6851e4480b21dcb10f86b3a44a45a
push id1618
push userCallek@gmail.com
push dateThu, 11 Jan 2018 17:45:48 +0000
treeherdermozilla-release@882ca853e05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjya, Sylvestre
bugs1417869
milestone58.0
Bug 1417869. P2 - abort the load algorithm early if media not allowed to load. r=jya, a=Sylvestre MozReview-Commit-ID: DUxyo4ywCPW
dom/html/HTMLMediaElement.cpp
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -1962,16 +1962,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.
@@ -2510,22 +2517,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(