summaryrefslogtreecommitdiff
path: root/Source/WebCore/loader/ImageLoader.cpp
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@nokia.com>2012-07-18 13:59:13 +0200
committerSimon Hausmann <simon.hausmann@nokia.com>2012-07-18 13:59:28 +0200
commit4d6084feccab99c0a7b3ecef26bb49c41dd50201 (patch)
treefd1195897f551eee6d5a15d07ff5733b15aa2a5c /Source/WebCore/loader/ImageLoader.cpp
parentae901828d4689ab9e89113f6b6ea8042b37a9fda (diff)
downloadqtwebkit-4d6084feccab99c0a7b3ecef26bb49c41dd50201.tar.gz
Imported WebKit commit ff52235a78888e5cb8e286a828a8698042200e67 (http://svn.webkit.org/repository/webkit/trunk@122948)
New snapshot that should fix the rendering issues recently introduced
Diffstat (limited to 'Source/WebCore/loader/ImageLoader.cpp')
-rw-r--r--Source/WebCore/loader/ImageLoader.cpp78
1 files changed, 42 insertions, 36 deletions
diff --git a/Source/WebCore/loader/ImageLoader.cpp b/Source/WebCore/loader/ImageLoader.cpp
index 0e3781cdb..f4d1209f0 100644
--- a/Source/WebCore/loader/ImageLoader.cpp
+++ b/Source/WebCore/loader/ImageLoader.cpp
@@ -27,11 +27,13 @@
#include "CrossOriginAccessControl.h"
#include "Document.h"
#include "Element.h"
+#include "ElementShadow.h"
#include "Event.h"
#include "EventSender.h"
#include "HTMLNames.h"
#include "HTMLObjectElement.h"
#include "HTMLParserIdioms.h"
+#include "ImageLoaderClient.h"
#include "RenderImage.h"
#include "ScriptCallStack.h"
#include "SecurityOrigin.h"
@@ -53,8 +55,8 @@ template<> struct ValueCheck<WebCore::ImageLoader*> {
{
if (!p)
return;
- ASSERT(p->element());
- ValueCheck<WebCore::Element*>::checkConsistency(p->element());
+ ASSERT(p->client()->imageElement());
+ ValueCheck<WebCore::Element*>::checkConsistency(p->client()->imageElement());
}
};
@@ -81,8 +83,8 @@ static ImageEventSender& errorEventSender()
return sender;
}
-ImageLoader::ImageLoader(Element* element)
- : m_element(element)
+ImageLoader::ImageLoader(ImageLoaderClient* client)
+ : m_client(client)
, m_image(0)
, m_hasPendingBeforeLoadEvent(false)
, m_hasPendingLoadEvent(false)
@@ -113,7 +115,12 @@ ImageLoader::~ImageLoader()
// If the ImageLoader is being destroyed but it is still protecting its image-loading Element,
// remove that protection here.
if (m_elementIsProtected)
- m_element->deref();
+ client()->derefSourceElement();
+}
+
+inline Document* ImageLoader::document()
+{
+ return client()->sourceElement()->document();
}
void ImageLoader::setImage(CachedImage* newImage)
@@ -153,11 +160,10 @@ void ImageLoader::updateFromElement()
{
// If we're not making renderers for the page, then don't load images. We don't want to slow
// down the raw HTML parsing case by loading images we don't intend to display.
- Document* document = m_element->document();
- if (!document->renderer())
+ if (!document()->renderer())
return;
- AtomicString attr = m_element->getAttribute(m_element->imageSourceAttributeName());
+ AtomicString attr = client()->sourceElement()->getAttribute(client()->sourceElement()->imageSourceAttributeName());
if (attr == m_failedLoadURL)
return;
@@ -166,24 +172,24 @@ void ImageLoader::updateFromElement()
// an empty string.
CachedResourceHandle<CachedImage> newImage = 0;
if (!attr.isNull() && !stripLeadingAndTrailingHTMLSpaces(attr).isEmpty()) {
- ResourceRequest request = ResourceRequest(document->completeURL(sourceURI(attr)));
+ ResourceRequest request = ResourceRequest(document()->completeURL(sourceURI(attr)));
- String crossOriginMode = m_element->fastGetAttribute(HTMLNames::crossoriginAttr);
+ String crossOriginMode = client()->sourceElement()->fastGetAttribute(HTMLNames::crossoriginAttr);
if (!crossOriginMode.isNull()) {
StoredCredentials allowCredentials = equalIgnoringCase(crossOriginMode, "use-credentials") ? AllowStoredCredentials : DoNotAllowStoredCredentials;
- updateRequestForAccessControl(request, document->securityOrigin(), allowCredentials);
+ updateRequestForAccessControl(request, document()->securityOrigin(), allowCredentials);
}
if (m_loadManually) {
- bool autoLoadOtherImages = document->cachedResourceLoader()->autoLoadImages();
- document->cachedResourceLoader()->setAutoLoadImages(false);
+ bool autoLoadOtherImages = document()->cachedResourceLoader()->autoLoadImages();
+ document()->cachedResourceLoader()->setAutoLoadImages(false);
newImage = new CachedImage(request);
newImage->setLoading(true);
- newImage->setOwningCachedResourceLoader(document->cachedResourceLoader());
- document->cachedResourceLoader()->m_documentResources.set(newImage->url(), newImage.get());
- document->cachedResourceLoader()->setAutoLoadImages(autoLoadOtherImages);
+ newImage->setOwningCachedResourceLoader(document()->cachedResourceLoader());
+ document()->cachedResourceLoader()->m_documentResources.set(newImage->url(), newImage.get());
+ document()->cachedResourceLoader()->setAutoLoadImages(autoLoadOtherImages);
} else
- newImage = document->cachedResourceLoader()->requestImage(request);
+ newImage = document()->cachedResourceLoader()->requestImage(request);
// If we do not have an image here, it means that a cross-site
// violation occurred.
@@ -191,7 +197,7 @@ void ImageLoader::updateFromElement()
} else if (!attr.isNull()) {
// Fire an error event if the url is empty.
// FIXME: Should we fire this event asynchronoulsy via errorEventSender()?
- m_element->dispatchEvent(Event::create(eventNames().errorEvent, false, false));
+ client()->imageElement()->dispatchEvent(Event::create(eventNames().errorEvent, false, false));
}
CachedImage* oldImage = m_image.get();
@@ -204,13 +210,13 @@ void ImageLoader::updateFromElement()
errorEventSender().cancelEvent(this);
m_image = newImage;
- m_hasPendingBeforeLoadEvent = !m_element->document()->isImageDocument() && newImage;
+ m_hasPendingBeforeLoadEvent = !document()->isImageDocument() && newImage;
m_hasPendingLoadEvent = newImage;
m_imageComplete = !newImage;
if (newImage) {
- if (!m_element->document()->isImageDocument()) {
- if (!m_element->document()->hasListenerType(Document::BEFORELOAD_LISTENER))
+ if (!document()->isImageDocument()) {
+ if (!document()->hasListenerType(Document::BEFORELOAD_LISTENER))
dispatchPendingBeforeLoadEvent();
else
beforeLoadEventSender().dispatchEventSoon(this);
@@ -253,9 +259,9 @@ void ImageLoader::notifyFinished(CachedResource* resource)
if (!m_hasPendingLoadEvent)
return;
- if (m_element->fastHasAttribute(HTMLNames::crossoriginAttr)
- && !m_element->document()->securityOrigin()->canRequest(image()->response().url())
- && !resource->passesAccessControlCheck(m_element->document()->securityOrigin())) {
+ if (client()->sourceElement()->fastHasAttribute(HTMLNames::crossoriginAttr)
+ && !document()->securityOrigin()->canRequest(image()->response().url())
+ && !resource->passesAccessControlCheck(document()->securityOrigin())) {
setImage(0);
@@ -263,7 +269,7 @@ void ImageLoader::notifyFinished(CachedResource* resource)
errorEventSender().dispatchEventSoon(this);
DEFINE_STATIC_LOCAL(String, consoleMessage, ("Cross-origin image load denied by Cross-Origin Resource Sharing policy."));
- m_element->document()->addConsoleMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, consoleMessage);
+ document()->addConsoleMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, consoleMessage);
ASSERT(!m_hasPendingLoadEvent);
return;
@@ -282,7 +288,7 @@ void ImageLoader::notifyFinished(CachedResource* resource)
RenderImageResource* ImageLoader::renderImageResource()
{
- RenderObject* renderer = m_element->renderer();
+ RenderObject* renderer = client()->imageElement()->renderer();
if (!renderer)
return 0;
@@ -333,9 +339,9 @@ void ImageLoader::updatedHasPendingLoadEvent()
m_elementIsProtected = m_hasPendingLoadEvent;
if (m_elementIsProtected)
- m_element->ref();
+ client()->refSourceElement();
else
- m_element->deref();
+ client()->derefSourceElement();
}
void ImageLoader::dispatchPendingEvent(ImageEventSender* eventSender)
@@ -356,10 +362,10 @@ void ImageLoader::dispatchPendingBeforeLoadEvent()
return;
if (!m_image)
return;
- if (!m_element->document()->attached())
+ if (!document()->attached())
return;
m_hasPendingBeforeLoadEvent = false;
- if (m_element->dispatchBeforeLoadEvent(m_image->url())) {
+ if (client()->sourceElement()->dispatchBeforeLoadEvent(m_image->url())) {
updateRenderer();
return;
}
@@ -370,9 +376,9 @@ void ImageLoader::dispatchPendingBeforeLoadEvent()
loadEventSender().cancelEvent(this);
m_hasPendingLoadEvent = false;
-
- if (m_element->hasTagName(HTMLNames::objectTag))
- static_cast<HTMLObjectElement*>(m_element)->renderFallbackContent();
+
+ if (client()->sourceElement()->hasTagName(HTMLNames::objectTag))
+ static_cast<HTMLObjectElement*>(client()->sourceElement())->renderFallbackContent();
// Only consider updating the protection ref-count of the Element immediately before returning
// from this function as doing so might result in the destruction of this ImageLoader.
@@ -385,7 +391,7 @@ void ImageLoader::dispatchPendingLoadEvent()
return;
if (!m_image)
return;
- if (!m_element->document()->attached())
+ if (!document()->attached())
return;
m_hasPendingLoadEvent = false;
dispatchLoadEvent();
@@ -399,10 +405,10 @@ void ImageLoader::dispatchPendingErrorEvent()
{
if (!m_hasPendingErrorEvent)
return;
- if (!m_element->document()->attached())
+ if (!document()->attached())
return;
m_hasPendingErrorEvent = false;
- m_element->dispatchEvent(Event::create(eventNames().errorEvent, false, false));
+ client()->imageElement()->dispatchEvent(Event::create(eventNames().errorEvent, false, false));
}
void ImageLoader::dispatchPendingBeforeLoadEvents()