HTMLImageLoader.cpp [plain text]
#include "config.h"
#include "HTMLImageLoader.h"
#include "CachedImage.h"
#include "CommonVM.h"
#include "DOMWindow.h"
#include "Element.h"
#include "Event.h"
#include "EventNames.h"
#include "HTMLNames.h"
#include "HTMLObjectElement.h"
#include "HTMLParserIdioms.h"
#include "HTMLVideoElement.h"
#include "Settings.h"
#include "JSDOMWindowBase.h"
#include <JavaScriptCore/JSCInlines.h>
#include <JavaScriptCore/JSLock.h>
namespace WebCore {
HTMLImageLoader::HTMLImageLoader(Element& element)
: ImageLoader(element)
{
}
HTMLImageLoader::~HTMLImageLoader() = default;
void HTMLImageLoader::dispatchLoadEvent()
{
#if ENABLE(VIDEO)
if (is<HTMLVideoElement>(element()))
return;
#endif
bool errorOccurred = image()->errorOccurred();
if (!errorOccurred && image()->response().httpStatusCode() >= 400)
errorOccurred = is<HTMLObjectElement>(element()); element().dispatchEvent(Event::create(errorOccurred ? eventNames().errorEvent : eventNames().loadEvent, Event::CanBubble::No, Event::IsCancelable::No));
}
String HTMLImageLoader::sourceURI(const AtomString& attr) const
{
return stripLeadingAndTrailingHTMLSpaces(attr);
}
void HTMLImageLoader::notifyFinished(CachedResource&)
{
ASSERT(image());
CachedImage& cachedImage = *image();
Ref<Element> protect(element());
ImageLoader::notifyFinished(cachedImage);
bool loadError = cachedImage.errorOccurred() || cachedImage.response().httpStatusCode() >= 400;
if (!loadError) {
if (!element().isConnected()) {
JSC::VM& vm = commonVM();
JSC::JSLockHolder lock(vm);
vm.heap.deprecatedReportExtraMemory(cachedImage.encodedSize());
}
}
if (loadError && is<HTMLObjectElement>(element()))
downcast<HTMLObjectElement>(element()).renderFallbackContent();
}
}