Bug 1441136: Cleanup a bit the responsive image content setup. r?smaug draft
authorEmilio Cobos Álvarez <emilio@crisal.io>
Thu, 29 Mar 2018 18:46:34 +0200
changeset 774866 99d212f16c88a6db19a246b85f79a5a73a10ca14
parent 774815 e8407ca5e3923ae675ad07fee03f1bd889e08f1b
child 774867 a26cbc34d9aae9ca9a24da193b6dbbe6bf1dd440
child 775310 693a5cf33340bc4788d6e36bd63cc047f5639f6e
push id104537
push userbmo:emilio@crisal.io
push dateThu, 29 Mar 2018 18:09:21 +0000
reviewerssmaug
bugs1441136
milestone61.0a1
Bug 1441136: Cleanup a bit the responsive image content setup. r?smaug Also, clear it in DestroyElementMaps, as the rest of the code. MozReview-Commit-ID: A8D3pgQ8MxX
dom/base/nsDocument.cpp
dom/html/HTMLImageElement.cpp
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -8639,16 +8639,17 @@ nsIDocument::MutationEventDispatched(nsI
 void
 nsIDocument::DestroyElementMaps()
 {
 #ifdef DEBUG
   mStyledLinksCleared = true;
 #endif
   mStyledLinks.Clear();
   mIdentifierMap.Clear();
+  mResponsiveContent.Clear();
   IncrementExpandoGeneration(*this);
 }
 
 void
 nsIDocument::RefreshLinkHrefs()
 {
   // Get a list of all links we know about.  We will reset them, which will
   // remove them from the document, so we need a copy of what is in the
--- a/dom/html/HTMLImageElement.cpp
+++ b/dom/html/HTMLImageElement.cpp
@@ -627,22 +627,18 @@ HTMLImageElement::UnbindFromTree(bool aD
     if (aNullParent || !FindAncestorForm(mForm)) {
       ClearForm(true);
     } else {
       UnsetFlags(MAYBE_ORPHAN_FORM_ELEMENT);
     }
   }
 
   if (mInDocResponsiveContent) {
-    nsIDocument* doc = GetOurOwnerDoc();
-    MOZ_ASSERT(doc);
-    if (doc) {
-      doc->RemoveResponsiveContent(this);
-      mInDocResponsiveContent = false;
-    }
+    OwnerDoc()->RemoveResponsiveContent(this);
+    mInDocResponsiveContent = false;
   }
 
   nsImageLoadingContent::UnbindFromTree(aDeep, aNullParent);
   nsGenericHTMLElement::UnbindFromTree(aDeep, aNullParent);
 }
 
 void
 HTMLImageElement::UpdateFormOwner()
@@ -1045,21 +1041,18 @@ HTMLImageElement::PictureSourceSrcsetCha
       principal = mSrcsetTriggeringPrincipal;
     } else if (auto* source = HTMLSourceElement::FromNode(aSourceNode)) {
       principal = source->GetSrcsetTriggeringPrincipal();
     }
     mResponsiveSelector->SetCandidatesFromSourceSet(aNewValue, principal);
   }
 
   if (!mInDocResponsiveContent && IsInComposedDoc()) {
-    nsIDocument* doc = GetOurOwnerDoc();
-    if (doc) {
-      doc->AddResponsiveContent(this);
-      mInDocResponsiveContent = true;
-    }
+    OwnerDoc()->AddResponsiveContent(this);
+    mInDocResponsiveContent = true;
   }
 
   // This always triggers the image update steps per the spec, even if
   // we are not using this source.
   QueueImageLoadTask(true);
 }
 
 void