Bug 1298027 - Shut down CDMs when a containing document becomes inactive. r=cpearce
authorBryce Van Dyk <bvandyk@mozilla.com>
Mon, 14 Nov 2016 15:02:48 +1300
changeset 322398 0f22052f5c483b7085b19fc269cdd8b399bc3cec
parent 322397 f3930acd16b78469b247f33d054413aeb7db0ba0
child 322399 690c0cdddff7d0304b2a33051860fec67a40b5cc
push id30951
push usercbook@mozilla.com
push dateTue, 15 Nov 2016 11:25:40 +0000
treeherdermozilla-central@85a9d908e91a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpearce
bugs1298027
milestone52.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1298027 - Shut down CDMs when a containing document becomes inactive. r=cpearce The previous changeset against this bug relaxed the conditions under which the CDM and associated objects were shut down. This was to address moving a tab to a new window breaking EME videos. However, this had the unwanted side effect of not shutting down those objects early enough when pages are closed. This changeset introduces a new check to see if the containing document is currently active, if not we shutdown the CDM. This means CDMs are shutdown on time, while retaining the desired behaviour that CDMs should not be shut down on moving tabs to new windows. Shutdowns previously happened because we shut down if a page hide happened, which took place during a reparent. MozReview-Commit-ID: K5CD3ej43Y0
dom/html/HTMLMediaElement.cpp
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -5298,17 +5298,17 @@ void HTMLMediaElement::SuspendOrResumeEl
       // the CDM's decoder. This ensures the CDM gets reliable and prompt
       // shutdown notifications, as it may have book-keeping it needs
       // to do on shutdown.
       if (mMediaKeys) {
         nsAutoString keySystem;
         mMediaKeys->GetKeySystem(keySystem);
         // If we're using Primetime we need to shutdown the key system and
         // decoder to preserve secure stop like behavior, other CDMs don't
-        // implement this so we don't need to worry with them.
+        // implement this so we don't need to worry with them on a suspend.
         if (IsPrimetimeKeySystem(keySystem)) {
           mMediaKeys->Shutdown();
           mMediaKeys = nullptr;
           if (mDecoder) {
             ShutdownDecoder();
           }
         }
       }
@@ -5356,16 +5356,25 @@ void HTMLMediaElement::NotifyOwnerDocume
 
   if (mDecoder && !IsBeingDestroyed()) {
     mDecoder->NotifyOwnerActivityChanged(visible);
   }
 
   bool pauseElement = ShouldElementBePaused();
   SuspendOrResumeElement(pauseElement, !IsActive());
 
+  // If the owning document has become inactive we should shutdown the CDM.
+  if (!OwnerDoc()->IsCurrentActiveDocument() && mMediaKeys) {
+      mMediaKeys->Shutdown();
+      mMediaKeys = nullptr;
+      if (mDecoder) {
+        ShutdownDecoder();
+      }
+    }
+
   AddRemoveSelfReference();
 }
 
 void HTMLMediaElement::AddRemoveSelfReference()
 {
   // XXX we could release earlier here in many situations if we examined
   // which event listeners are attached. Right now we assume there is a
   // potential listener for every event. We would also have to keep the