Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(569)

Unified Diff: Source/core/loader/ImageLoader.cpp

Issue 481753002: Use Shadow DOM to display fallback content for images (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Updated Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/core/loader/ImageLoader.cpp
diff --git a/Source/core/loader/ImageLoader.cpp b/Source/core/loader/ImageLoader.cpp
index 47a80b07d4e5eecccdf6f8616e676daee923dc85..3235914c8d6261747bab4a51791827a269282444 100644
--- a/Source/core/loader/ImageLoader.cpp
+++ b/Source/core/loader/ImageLoader.cpp
@@ -66,8 +66,7 @@ static ImageLoader::BypassMainWorldBehavior shouldBypassMainWorldCSP(ImageLoader
{
ASSERT(loader);
ASSERT(loader->element());
- ASSERT(loader->element()->document().frame());
- if (loader->element()->document().frame()->script().shouldBypassMainWorldCSP())
+ if (loader->element()->document().frame() && loader->element()->document().frame()->script().shouldBypassMainWorldCSP())
return ImageLoader::BypassMainWorldCSP;
return ImageLoader::DoNotBypassMainWorldCSP;
}
@@ -276,9 +275,12 @@ void ImageLoader::doUpdateFromElement(BypassMainWorldBehavior bypassBehavior, Up
} else {
clearFailedLoadURL();
}
- } else if (!imageSourceURL.isNull()) {
- // Fire an error event if the url string is not empty, but the KURL is.
- dispatchErrorEvent();
+ } else {
+ if (!imageSourceURL.isNull()) {
+ // Fire an error event if the url string is not empty, but the KURL is.
+ dispatchErrorEvent();
+ }
+ noImageResourceToLoad();
}
ImageResource* oldImage = m_image.get();
@@ -323,7 +325,7 @@ void ImageLoader::doUpdateFromElement(BypassMainWorldBehavior bypassBehavior, Up
updatedHasPendingEvent();
}
-void ImageLoader::updateFromElement(UpdateFromElementBehavior updateBehavior, LoadType loadType)
+void ImageLoader::updateFromElement(UpdateFromElementBehavior updateBehavior)
{
AtomicString imageSourceURL = m_element->imageSourceURL();
m_suppressErrorEvents = (updateBehavior == UpdateSizeChanged);
@@ -342,7 +344,7 @@ void ImageLoader::updateFromElement(UpdateFromElementBehavior updateBehavior, Lo
}
KURL url = imageSourceToKURL(imageSourceURL);
- if (imageSourceURL.isNull() || url.isNull() || shouldLoadImmediately(url, loadType)) {
+ if (shouldLoadImmediately(url)) {
doUpdateFromElement(DoNotBypassMainWorldCSP, updateBehavior);
return;
}
@@ -366,14 +368,16 @@ KURL ImageLoader::imageSourceToKURL(AtomicString imageSourceURL) const
return url;
}
-bool ImageLoader::shouldLoadImmediately(const KURL& url, LoadType loadType) const
+bool ImageLoader::shouldLoadImmediately(const KURL& url) const
{
- return (m_loadingImageDocument
- || isHTMLObjectElement(m_element)
- || isHTMLEmbedElement(m_element)
- || url.protocolIsData()
- || memoryCache()->resourceForURL(url, m_element->document().fetcher()->getCacheIdentifier())
- || loadType == ForceLoadImmediately);
+ // We force any image loads which might require alt content through the asynchronous path so that we can add the shadow DOM
+ // for the alt-text content when style recalc is over and DOM mutation is allowed again.
+ if (!url.isNull()) {
+ Resource* resource = memoryCache()->resourceForURL(url, m_element->document().fetcher()->getCacheIdentifier());
+ if (resource && !resource->errorOccurred())
+ return true;
+ }
+ return (m_loadingImageDocument || isHTMLObjectElement(m_element) || isHTMLEmbedElement(m_element) || url.protocolIsData());
}
void ImageLoader::notifyFinished(Resource* resource)
@@ -589,5 +593,4 @@ ImageLoader::ImageLoaderClientRemover::~ImageLoaderClientRemover()
m_loader.willRemoveClient(m_client);
}
#endif
-
}

Powered by Google App Engine
This is Rietveld 408576698