From 1dec47a5211299f1f917dfb89fbb62e0ddbed306 Mon Sep 17 00:00:00 2001 From: Ben Tian Date: Tue, 12 Jul 2016 10:56:42 +0800 Subject: [PATCH] Bug 1264769 - Part 2: Dispatch loadstart event for image loading. r=hsivonen --HG-- extra : rebase_source : 35df083492f43de8179c4ac50d82d20666ab9bf3 --- dom/base/nsImageLoadingContent.cpp | 15 ++++++++++++--- dom/base/nsImageLoadingContent.h | 4 +++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/dom/base/nsImageLoadingContent.cpp b/dom/base/nsImageLoadingContent.cpp index af61e7ed0337..3412eaf6c4cd 100644 --- a/dom/base/nsImageLoadingContent.cpp +++ b/dom/base/nsImageLoadingContent.cpp @@ -673,7 +673,7 @@ nsImageLoadingContent::ForceReload(const mozilla::dom::Optional& aNotify, ImageLoadType loadType = \ (mCurrentRequestFlags & REQUEST_IS_IMAGESET) ? eImageLoadType_Imageset : eImageLoadType_Normal; - nsresult rv = LoadImage(currentURI, true, notify, loadType, nullptr, + nsresult rv = LoadImage(currentURI, true, notify, loadType, true, nullptr, nsIRequest::VALIDATE_ALWAYS); if (NS_FAILED(rv)) { aError.Throw(rv); @@ -757,7 +757,10 @@ nsImageLoadingContent::LoadImage(const nsAString& aNewURI, return NS_OK; } - // Second, parse the URI string to get image URI + // Fire loadstart event + FireEvent(NS_LITERAL_STRING("loadstart")); + + // Parse the URI string to get image URI nsCOMPtr imageURI; nsresult rv = StringToURI(aNewURI, doc, getter_AddRefs(imageURI)); if (NS_FAILED(rv)) { @@ -788,7 +791,7 @@ nsImageLoadingContent::LoadImage(const nsAString& aNewURI, NS_TryToSetImmutable(imageURI); - return LoadImage(imageURI, aForce, aNotify, aImageLoadType, doc); + return LoadImage(imageURI, aForce, aNotify, aImageLoadType, false, doc); } nsresult @@ -796,9 +799,15 @@ nsImageLoadingContent::LoadImage(nsIURI* aNewURI, bool aForce, bool aNotify, ImageLoadType aImageLoadType, + bool aLoadStart, nsIDocument* aDocument, nsLoadFlags aLoadFlags) { + // Fire loadstart event if required + if (aLoadStart) { + FireEvent(NS_LITERAL_STRING("loadstart")); + } + if (!mLoadingEnabled) { // XXX Why fire an error here? seems like the callers to SetLoadingEnabled // don't want/need it. diff --git a/dom/base/nsImageLoadingContent.h b/dom/base/nsImageLoadingContent.h index 1b7b53750444..f2688141615b 100644 --- a/dom/base/nsImageLoadingContent.h +++ b/dom/base/nsImageLoadingContent.h @@ -133,13 +133,15 @@ protected: * @param aNotify If true, nsIDocumentObserver state change notifications * will be sent as needed. * @param aImageLoadType The ImageLoadType for this request + * @param aLoadStart If true, dispatch "loadstart" event. * @param aDocument Optional parameter giving the document this node is in. * This is purely a performance optimization. * @param aLoadFlags Optional parameter specifying load flags to use for * the image load */ nsresult LoadImage(nsIURI* aNewURI, bool aForce, bool aNotify, - ImageLoadType aImageLoadType, nsIDocument* aDocument = nullptr, + ImageLoadType aImageLoadType, bool aLoadStart = true, + nsIDocument* aDocument = nullptr, nsLoadFlags aLoadFlags = nsIRequest::LOAD_NORMAL); /**