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

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, 3 months 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 9bafe5608cee455c06f8c1567d781bac88007b89..1aeab5354d21e762bb9057d3ec93c98c6a4ae2dc 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;
}
@@ -268,10 +267,13 @@ void ImageLoader::doUpdateFromElement(BypassMainWorldBehavior bypassBehavior, Up
crossSiteOrCSPViolationOccured(imageSourceURL);
else
clearFailedLoadURL();
- } else if (!imageSourceURL.isNull()) {
- // Fire an error event if the url string is not empty, but the KURL is.
- m_hasPendingErrorEvent = true;
- errorEventSender().dispatchEventSoon(this);
+ } else {
+ if (!imageSourceURL.isNull()) {
+ // Fire an error event if the url string is not empty, but the KURL is.
+ m_hasPendingErrorEvent = true;
+ errorEventSender().dispatchEventSoon(this);
+ }
+ noImageResourceToLoad();
}
ImageResource* oldImage = m_image.get();
@@ -316,7 +318,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();
@@ -334,7 +336,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;
}
@@ -358,14 +360,19 @@ KURL ImageLoader::imageSourceToKURL(AtomicString imageSourceURL) const
return url;
}
-bool ImageLoader::shouldLoadImmediately(const KURL& url, LoadType loadType) const
+bool ImageLoader::shouldLoadImmediately(const KURL& url) const
{
+ // We force failed image loads 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);
+ if (resource && !resource->errorOccurred())
+ return true;
+ }
return (m_loadingImageDocument
|| isHTMLObjectElement(m_element)
|| isHTMLEmbedElement(m_element)
- || url.protocolIsData()
- || memoryCache()->resourceForURL(url)
- || loadType == ForceLoadImmediately);
+ || url.protocolIsData());
}
void ImageLoader::notifyFinished(Resource* resource)

Powered by Google App Engine
This is Rietveld 408576698