Bug 1264529 - If an adoption of <img> is happening with the different source and destination document, we need to force it to reload; r=jdm
authorEdgar Chen <echen@mozilla.com>
Thu, 13 Oct 2016 18:03:10 +0800
changeset 409590 0f515e0bae0e90cb3fe772a5edf501fa0e6dfa7d
parent 409589 3b51e0c8b6cce5ccc6c81c3bbbeafaf5dcab8b30
child 409591 e676a13582cb320644c0467996a4aa804dab0255
push id7391
push usermtabara@mozilla.com
push dateMon, 12 Jun 2017 13:08:53 +0000
treeherdermozilla-beta@2191d7f87e2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdm
bugs1264529, 1307185, 1317901
milestone55.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 1264529 - If an adoption of <img> is happening with the different source and destination document, we need to force it to reload; r=jdm Do force update image when adoption happens, then we could remove the workaroud added in bug 1307185 and bug 1317901. MozReview-Commit-ID: Cbg3EHtyL8f
dom/html/HTMLImageElement.cpp
dom/html/HTMLImageElement.h
testing/web-platform/meta/html/semantics/embedded-content/the-img-element/document-adopt-base-url.html.ini
--- a/dom/html/HTMLImageElement.cpp
+++ b/dom/html/HTMLImageElement.cpp
@@ -658,17 +658,17 @@ HTMLImageElement::BindToTree(nsIDocument
     // script.
 
     // If loading is temporarily disabled, don't even launch MaybeLoadImage.
     // Otherwise MaybeLoadImage may run later when someone has reenabled
     // loading.
     if (LoadingEnabled() &&
         OwnerDoc()->IsCurrentActiveDocument()) {
       nsContentUtils::AddScriptRunner(
-          NewRunnableMethod(this, &HTMLImageElement::MaybeLoadImage));
+        NewRunnableMethod<bool>(this, &HTMLImageElement::MaybeLoadImage, false));
     }
   }
 
   return rv;
 }
 
 void
 HTMLImageElement::UnbindFromTree(bool aDeep, bool aNullParent)
@@ -685,18 +685,16 @@ HTMLImageElement::UnbindFromTree(bool aD
     nsIDocument* doc = GetOurOwnerDoc();
     MOZ_ASSERT(doc);
     if (doc) {
       doc->RemoveResponsiveContent(this);
       mInDocResponsiveContent = false;
     }
   }
 
-  mLastSelectedSource = nullptr;
-
   nsImageLoadingContent::UnbindFromTree(aDeep, aNullParent);
   nsGenericHTMLElement::UnbindFromTree(aDeep, aNullParent);
 }
 
 void
 HTMLImageElement::UpdateFormOwner()
 {
   if (!mForm) {
@@ -719,25 +717,25 @@ HTMLImageElement::UpdateFormOwner()
 
     if (!idVal.IsEmpty()) {
       mForm->AddImageElementToTable(this, idVal);
     }
   }
 }
 
 void
-HTMLImageElement::MaybeLoadImage()
+HTMLImageElement::MaybeLoadImage(bool aAlwaysForceLoad)
 {
   // Our base URI may have changed, or we may have had responsive parameters
   // change while not bound to the tree. Re-parse src/srcset and call LoadImage,
   // which is a no-op if it resolves to the same effective URI without aForce.
 
   // Note, check LoadingEnabled() after LoadImage call.
 
-  LoadSelectedImage(false, true, false);
+  LoadSelectedImage(aAlwaysForceLoad, /* aNotify */ true, aAlwaysForceLoad);
 
   if (!LoadingEnabled()) {
     CancelImageRequests(true);
   }
 }
 
 EventStates
 HTMLImageElement::IntrinsicState() const
@@ -745,18 +743,28 @@ HTMLImageElement::IntrinsicState() const
   return nsGenericHTMLElement::IntrinsicState() |
     nsImageLoadingContent::ImageState();
 }
 
 void
 HTMLImageElement::NodeInfoChanged(nsIDocument* aOldDoc)
 {
   nsGenericHTMLElement::NodeInfoChanged(aOldDoc);
-  // Resetting the last selected source if adoption steps are run.
-  mLastSelectedSource = nullptr;
+  // Force reload image if adoption steps are run.
+  // If loading is temporarily disabled, don't even launch script runner.
+  // Otherwise script runner may run later when someone has reenabled loading.
+  if (LoadingEnabled()) {
+    // Use script runner for the case the adopt is from appendChild.
+    // Bug 1076583 - We still behave synchronously in the non-responsive case
+    nsContentUtils::AddScriptRunner(
+      (InResponsiveMode())
+        ? NewRunnableMethod<bool>(this, &HTMLImageElement::QueueImageLoadTask, true)
+        : NewRunnableMethod<bool>(this, &HTMLImageElement::MaybeLoadImage, true)
+    );
+  }
 }
 
 // static
 already_AddRefed<HTMLImageElement>
 HTMLImageElement::Image(const GlobalObject& aGlobal,
                         const Optional<uint32_t>& aWidth,
                         const Optional<uint32_t>& aHeight,
                         ErrorResult& aError)
@@ -868,17 +876,17 @@ HTMLImageElement::CopyInnerTo(Element* a
     if (!dest->InResponsiveMode() &&
         dest->HasAttr(kNameSpaceID_None, nsGkAtoms::src) &&
         dest->OwnerDoc()->IsCurrentActiveDocument()) {
       // Mark channel as urgent-start before load image if the image load is
       // initaiated by a user interaction.
       mUseUrgentStartForChannel = EventStateManager::IsHandlingUserInput();
 
       nsContentUtils::AddScriptRunner(
-        NewRunnableMethod(dest, &HTMLImageElement::MaybeLoadImage));
+        NewRunnableMethod<bool>(dest, &HTMLImageElement::MaybeLoadImage, false));
     }
   }
 
   return NS_OK;
 }
 
 CORSMode
 HTMLImageElement::GetCORSMode()
--- a/dom/html/HTMLImageElement.h
+++ b/dom/html/HTMLImageElement.h
@@ -94,17 +94,17 @@ public:
   virtual EventStates IntrinsicState() const override;
   virtual nsresult Clone(mozilla::dom::NodeInfo *aNodeInfo, nsINode **aResult,
                          bool aPreallocateChildren) const override;
 
   virtual void NodeInfoChanged(nsIDocument* aOldDoc) override;
 
   nsresult CopyInnerTo(Element* aDest, bool aPreallocateChildren);
 
-  void MaybeLoadImage();
+  void MaybeLoadImage(bool aAlwaysForceLoad);
 
   bool IsMap()
   {
     return GetBoolAttr(nsGkAtoms::ismap);
   }
   void SetIsMap(bool aIsMap, ErrorResult& aError)
   {
     SetHTMLBoolAttr(nsGkAtoms::ismap, aIsMap, aError);
deleted file mode 100644
--- a/testing/web-platform/meta/html/semantics/embedded-content/the-img-element/document-adopt-base-url.html.ini
+++ /dev/null
@@ -1,3 +0,0 @@
-[document-adopt-base-url.html]
-  type: reftest
-  expected: FAIL