Bug 1342883 - part2: Once a MediaElement receive document unload event, remove all MediaElements in gElementTable with the same uri. r=jwwang draft
authorbechen@mozilla.com <bechen@mozilla.com>
Mon, 25 Sep 2017 17:12:31 +0800
changeset 669716 f1c31bcddab4d2a11351b8992293e0babea88f18
parent 669715 70de598d426376345c88b75d94ec0c49b8ccb8bb
child 733029 5c8b862ca16947e8ead02786ba3ceb20795b5abd
push id81405
push userbmo:bechen@mozilla.com
push dateMon, 25 Sep 2017 09:12:47 +0000
reviewersjwwang
bugs1342883
milestone57.0a1
Bug 1342883 - part2: Once a MediaElement receive document unload event, remove all MediaElements in gElementTable with the same uri. r=jwwang MozReview-Commit-ID: 7Z0ouKsebp8
dom/html/HTMLMediaElement.cpp
dom/html/HTMLMediaElement.h
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -3704,32 +3704,36 @@ HTMLMediaElement::AddMediaElementToURITa
   }
   MediaElementSetForURI* entry = gElementTable->PutEntry(mLoadingSrc);
   entry->mElements.AppendElement(this);
   NS_ASSERTION(MediaElementTableCount(this, mLoadingSrc) == 1,
     "Should have a single entry for element in element table after addition");
 }
 
 void
-HTMLMediaElement::RemoveMediaElementFromURITable()
+HTMLMediaElement::RemoveMediaElementFromURITable(bool aRemoveSameURI)
 {
   if (!mDecoder || !mLoadingSrc || !gElementTable) {
     return;
   }
   MediaElementSetForURI* entry = gElementTable->GetEntry(mLoadingSrc);
   if (!entry) {
     return;
   }
-  entry->mElements.RemoveElement(this);
-  if (entry->mElements.IsEmpty()) {
+  if (aRemoveSameURI) {
     gElementTable->RemoveEntry(entry);
-    if (gElementTable->Count() == 0) {
-      delete gElementTable;
-      gElementTable = nullptr;
-    }
+  } else {
+    entry->mElements.RemoveElement(this);
+    if (entry->mElements.IsEmpty()) {
+      gElementTable->RemoveEntry(entry);
+    }
+  }
+  if (gElementTable->Count() == 0) {
+    delete gElementTable;
+    gElementTable = nullptr;
   }
   NS_ASSERTION(MediaElementTableCount(this, mLoadingSrc) == 0,
     "After remove, should no longer have an entry in element table");
 }
 
 HTMLMediaElement*
 HTMLMediaElement::LookupMediaElementURITable(nsIURI* aURI)
 {
@@ -6365,16 +6369,17 @@ void HTMLMediaElement::NotifyOwnerDocume
     mMediaKeys->Shutdown();
     mMediaKeys = nullptr;
     if (mDecoder) {
       ShutdownDecoder();
     }
   }
 
   if (aDocumentUnload && mDecoder) {
+    RemoveMediaElementFromURITable(true);
     ShutdownDecoder();
   }
 
   AddRemoveSelfReference();
 }
 
 void HTMLMediaElement::AddRemoveSelfReference()
 {
--- a/dom/html/HTMLMediaElement.h
+++ b/dom/html/HTMLMediaElement.h
@@ -981,17 +981,17 @@ protected:
 
   /**
    * Call this after setting up mLoadingSrc and mDecoder.
    */
   void AddMediaElementToURITable();
   /**
    * Call this before modifying mLoadingSrc.
    */
-  void RemoveMediaElementFromURITable();
+  void RemoveMediaElementFromURITable(bool aRemoveSameURI = false);
   /**
    * Call this to find a media element with the same NodePrincipal and mLoadingSrc
    * set to aURI, and with a decoder on which Load() has been called.
    */
   HTMLMediaElement* LookupMediaElementURITable(nsIURI* aURI);
 
   /**
    * Shutdown and clear mDecoder and maintain associated invariants.