HTMLImageLoader.cpp [plain text]
#include "config.h"
#include "HTMLImageLoader.h"
#include "CachedImage.h"
#include "Element.h"
#include "Event.h"
#include "EventNames.h"
#include "HTMLNames.h"
#include "HTMLObjectElement.h"
#include "HTMLParserIdioms.h"
#include "Settings.h"
#if USE(JSC)
#include "JSDOMWindowBase.h"
#include <runtime/JSLock.h>
#endif
namespace WebCore {
HTMLImageLoader::HTMLImageLoader(Element* node)
: ImageLoader(node)
{
}
HTMLImageLoader::~HTMLImageLoader()
{
}
void HTMLImageLoader::dispatchLoadEvent()
{
if (element()->hasTagName(HTMLNames::videoTag))
return;
bool errorOccurred = image()->errorOccurred();
if (!errorOccurred && image()->response().httpStatusCode() >= 400)
errorOccurred = element()->hasTagName(HTMLNames::objectTag); element()->dispatchEvent(Event::create(errorOccurred ? eventNames().errorEvent : eventNames().loadEvent, false, false));
}
String HTMLImageLoader::sourceURI(const AtomicString& attr) const
{
#if ENABLE(DASHBOARD_SUPPORT)
Settings* settings = element()->document()->settings();
if (settings && settings->usesDashboardBackwardCompatibilityMode() && attr.length() > 7 && attr.startsWith("url(\"") && attr.endsWith("\")"))
return attr.string().substring(5, attr.length() - 7);
#endif
return stripLeadingAndTrailingHTMLSpaces(attr);
}
void HTMLImageLoader::notifyFinished(CachedResource*)
{
CachedImage* cachedImage = image();
Element* elem = element();
ImageLoader::notifyFinished(cachedImage);
bool loadError = cachedImage->errorOccurred() || cachedImage->response().httpStatusCode() >= 400;
#if USE(JSC)
if (!loadError) {
if (!elem->inDocument()) {
JSC::JSLock lock(JSC::SilenceAssertionsOnly);
JSC::JSGlobalData* globalData = JSDOMWindowBase::commonJSGlobalData();
globalData->heap.reportExtraMemoryCost(cachedImage->encodedSize());
}
}
#endif
if (loadError && elem->hasTagName(HTMLNames::objectTag))
static_cast<HTMLObjectElement*>(elem)->renderFallbackContent();
}
}