This source file includes following definitions.
- m_lastTotalBytesToBeSent
- interfaceName
- executionContext
- dispatchProgressEvent
- dispatchEventAndLoadEnd
- handleRequestError
#include "config.h"
#include "core/xml/XMLHttpRequestUpload.h"
#include "core/events/Event.h"
#include "core/xml/XMLHttpRequestProgressEvent.h"
#include "wtf/Assertions.h"
#include "wtf/text/AtomicString.h"
namespace WebCore {
XMLHttpRequestUpload::XMLHttpRequestUpload(XMLHttpRequest* xmlHttpRequest)
: m_xmlHttpRequest(xmlHttpRequest)
, m_lastBytesSent(0)
, m_lastTotalBytesToBeSent(0)
{
ScriptWrappable::init(this);
}
const AtomicString& XMLHttpRequestUpload::interfaceName() const
{
return EventTargetNames::XMLHttpRequestUpload;
}
ExecutionContext* XMLHttpRequestUpload::executionContext() const
{
return m_xmlHttpRequest->executionContext();
}
void XMLHttpRequestUpload::dispatchProgressEvent(unsigned long long bytesSent, unsigned long long totalBytesToBeSent)
{
m_lastBytesSent = bytesSent;
m_lastTotalBytesToBeSent = totalBytesToBeSent;
dispatchEvent(XMLHttpRequestProgressEvent::create(EventTypeNames::progress, true, bytesSent, totalBytesToBeSent));
}
void XMLHttpRequestUpload::dispatchEventAndLoadEnd(const AtomicString& type, bool lengthComputable, unsigned long long bytesSent, unsigned long long total)
{
ASSERT(type == EventTypeNames::load || type == EventTypeNames::abort || type == EventTypeNames::error || type == EventTypeNames::timeout);
dispatchEvent(XMLHttpRequestProgressEvent::create(type, lengthComputable, bytesSent, total));
dispatchEvent(XMLHttpRequestProgressEvent::create(EventTypeNames::loadend, lengthComputable, bytesSent, total));
}
void XMLHttpRequestUpload::handleRequestError(const AtomicString& type)
{
bool lengthComputable = m_lastTotalBytesToBeSent > 0 && m_lastBytesSent <= m_lastTotalBytesToBeSent;
dispatchEvent(XMLHttpRequestProgressEvent::create(EventTypeNames::progress, lengthComputable, m_lastBytesSent, m_lastTotalBytesToBeSent));
dispatchEventAndLoadEnd(type, lengthComputable, m_lastBytesSent, m_lastTotalBytesToBeSent);
}
}