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

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, 1 month 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 1f3f7320a84b88d8d7039f8d583ab17c85f3d622..d85d6e6b20863ff97ecfc6acd48cc815fb8de775 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;
}
@@ -270,10 +269,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();
@@ -318,7 +320,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);
@@ -337,7 +339,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;
}
@@ -361,14 +363,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)
@@ -583,5 +587,4 @@ ImageLoader::ImageLoaderClientRemover::~ImageLoaderClientRemover()
m_loader.willRemoveClient(m_client);
}
#endif
-
}

Powered by Google App Engine
This is Rietveld 408576698