From 77428c0a83fe853fce7883deeca5559de511aaa6 Mon Sep 17 00:00:00 2001 From: Edgar Chen Date: Thu, 13 Oct 2016 18:03:10 +0800 Subject: [PATCH] Bug 1264529 - If an adoption of 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 | 24 ++++++++++++------- dom/html/HTMLImageElement.h | 2 +- .../document-adopt-base-url.html.ini | 3 --- 3 files changed, 17 insertions(+), 12 deletions(-) delete mode 100644 testing/web-platform/meta/html/semantics/embedded-content/the-img-element/document-adopt-base-url.html.ini diff --git a/dom/html/HTMLImageElement.cpp b/dom/html/HTMLImageElement.cpp index bf0d4f1e0fa6..10d289c0ce26 100644 --- a/dom/html/HTMLImageElement.cpp +++ b/dom/html/HTMLImageElement.cpp @@ -663,7 +663,7 @@ HTMLImageElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent, if (LoadingEnabled() && OwnerDoc()->IsCurrentActiveDocument()) { nsContentUtils::AddScriptRunner( - NewRunnableMethod(this, &HTMLImageElement::MaybeLoadImage)); + NewRunnableMethod(this, &HTMLImageElement::MaybeLoadImage, false)); } } @@ -690,8 +690,6 @@ HTMLImageElement::UnbindFromTree(bool aDeep, bool aNullParent) } } - mLastSelectedSource = nullptr; - nsImageLoadingContent::UnbindFromTree(aDeep, aNullParent); nsGenericHTMLElement::UnbindFromTree(aDeep, aNullParent); } @@ -724,7 +722,7 @@ HTMLImageElement::UpdateFormOwner() } 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, @@ -732,7 +730,7 @@ HTMLImageElement::MaybeLoadImage() // Note, check LoadingEnabled() after LoadImage call. - LoadSelectedImage(false, true, false); + LoadSelectedImage(aAlwaysForceLoad, /* aNotify */ true, aAlwaysForceLoad); if (!LoadingEnabled()) { CancelImageRequests(true); @@ -750,8 +748,18 @@ 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(this, &HTMLImageElement::QueueImageLoadTask, true) + : NewRunnableMethod(this, &HTMLImageElement::MaybeLoadImage, true) + ); + } } // static @@ -873,7 +881,7 @@ HTMLImageElement::CopyInnerTo(Element* aDest, bool aPreallocateChildren) mUseUrgentStartForChannel = EventStateManager::IsHandlingUserInput(); nsContentUtils::AddScriptRunner( - NewRunnableMethod(dest, &HTMLImageElement::MaybeLoadImage)); + NewRunnableMethod(dest, &HTMLImageElement::MaybeLoadImage, false)); } } diff --git a/dom/html/HTMLImageElement.h b/dom/html/HTMLImageElement.h index 5a34646745df..af7a36ff52dc 100644 --- a/dom/html/HTMLImageElement.h +++ b/dom/html/HTMLImageElement.h @@ -99,7 +99,7 @@ public: nsresult CopyInnerTo(Element* aDest, bool aPreallocateChildren); - void MaybeLoadImage(); + void MaybeLoadImage(bool aAlwaysForceLoad); bool IsMap() { diff --git a/testing/web-platform/meta/html/semantics/embedded-content/the-img-element/document-adopt-base-url.html.ini b/testing/web-platform/meta/html/semantics/embedded-content/the-img-element/document-adopt-base-url.html.ini deleted file mode 100644 index 55ced09ad2b8..000000000000 --- 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