Bug 1324883 - part2: Once a MediaElement receive document unload event, remove all MediaElements in gElementTable with the same uri. r=jwwang
authorbechen@mozilla.com <bechen@mozilla.com>
Tue, 03 Oct 2017 12:07:13 +0800
changeset 427260 3e22200b7e839722b7b5090410d7769ed4fbea04
parent 427259 9d197f1860e6151f28d10cec5b543d8ad99b7a64
child 427261 3eb67a3d22b3030aa1280972c23dc76a57a8ec95
push id97
push userfmarier@mozilla.com
push dateSat, 14 Oct 2017 01:12:59 +0000
reviewersjwwang
bugs1324883
milestone58.0a1
Bug 1324883 - 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
@@ -3734,32 +3734,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 aFroceClearEntry)
 {
   if (!mDecoder || !mLoadingSrc || !gElementTable) {
     return;
   }
   MediaElementSetForURI* entry = gElementTable->GetEntry(mLoadingSrc);
   if (!entry) {
     return;
   }
-  entry->mElements.RemoveElement(this);
-  if (entry->mElements.IsEmpty()) {
+  if (aFroceClearEntry) {
     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)
 {
@@ -3878,16 +3882,17 @@ public:
     if ((aProgressStateFlags & STATE_IS_NETWORK) &&
         (aProgressStateFlags & STATE_START)) {
       // Query the LoadType to see if it's a ctrl+F5.
       nsCOMPtr<nsIDocShell> shell(do_QueryInterface(aWebProgress));
       if (shell) {
         uint32_t loadType;
         shell->GetLoadType(&loadType);
         if (LOAD_RELOAD_BYPASS_PROXY_AND_CACHE == loadType && mWeak->mDecoder) {
+          mWeak->RemoveMediaElementFromURITable(true);
           mWeak->ShutdownDecoder();
         }
       }
     }
     return NS_OK;
   }
 
   NS_IMETHODIMP
--- a/dom/html/HTMLMediaElement.h
+++ b/dom/html/HTMLMediaElement.h
@@ -982,17 +982,17 @@ protected:
 
   /**
    * Call this after setting up mLoadingSrc and mDecoder.
    */
   void AddMediaElementToURITable();
   /**
    * Call this before modifying mLoadingSrc.
    */
-  void RemoveMediaElementFromURITable();
+  void RemoveMediaElementFromURITable(bool aFroceClearEntry = 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.