This source file includes following definitions.
- constructorCustom
- responseTextAttributeGetterCustom
- responseAttributeGetterCustom
- openMethodCustom
- isDocumentType
- sendMethodCustom
#include "config.h"
#include "V8XMLHttpRequest.h"
#include "V8Blob.h"
#include "V8Document.h"
#include "V8FormData.h"
#include "V8HTMLDocument.h"
#include "V8Stream.h"
#include "bindings/v8/ExceptionMessages.h"
#include "bindings/v8/ExceptionState.h"
#include "bindings/v8/V8Binding.h"
#include "bindings/v8/custom/V8ArrayBufferCustom.h"
#include "bindings/v8/custom/V8ArrayBufferViewCustom.h"
#include "core/dom/Document.h"
#include "core/fileapi/Stream.h"
#include "core/inspector/InspectorInstrumentation.h"
#include "core/workers/WorkerGlobalScope.h"
#include "core/xml/XMLHttpRequest.h"
#include "wtf/ArrayBuffer.h"
#include <v8.h>
namespace WebCore {
void V8XMLHttpRequest::constructorCustom(const v8::FunctionCallbackInfo<v8::Value>& info)
{
ExecutionContext* context = currentExecutionContext(info.GetIsolate());
RefPtr<SecurityOrigin> securityOrigin;
if (context->isDocument()) {
DOMWrapperWorld& world = DOMWrapperWorld::current(info.GetIsolate());
if (world.isIsolatedWorld())
securityOrigin = world.isolatedWorldSecurityOrigin();
}
RefPtrWillBeRawPtr<XMLHttpRequest> xmlHttpRequest = XMLHttpRequest::create(context, securityOrigin);
v8::Handle<v8::Object> wrapper = info.Holder();
V8DOMWrapper::associateObjectWithWrapper<V8XMLHttpRequest>(xmlHttpRequest.release(), &wrapperTypeInfo, wrapper, info.GetIsolate(), WrapperConfiguration::Dependent);
info.GetReturnValue().Set(wrapper);
}
void V8XMLHttpRequest::responseTextAttributeGetterCustom(const v8::PropertyCallbackInfo<v8::Value>& info)
{
XMLHttpRequest* xmlHttpRequest = V8XMLHttpRequest::toNative(info.Holder());
ExceptionState exceptionState(ExceptionState::GetterContext, "responseText", "XMLHttpRequest", info.Holder(), info.GetIsolate());
ScriptValue text = xmlHttpRequest->responseText(exceptionState);
if (exceptionState.throwIfNeeded())
return;
if (text.hasNoValue()) {
v8SetReturnValueString(info, emptyString(), info.GetIsolate());
return;
}
v8SetReturnValue(info, text.v8Value());
}
void V8XMLHttpRequest::responseAttributeGetterCustom(const v8::PropertyCallbackInfo<v8::Value>& info)
{
XMLHttpRequest* xmlHttpRequest = V8XMLHttpRequest::toNative(info.Holder());
switch (xmlHttpRequest->responseTypeCode()) {
case XMLHttpRequest::ResponseTypeDefault:
case XMLHttpRequest::ResponseTypeText:
responseTextAttributeGetterCustom(info);
return;
case XMLHttpRequest::ResponseTypeJSON:
{
v8::Isolate* isolate = info.GetIsolate();
ScriptString jsonSource = xmlHttpRequest->responseJSONSource();
if (jsonSource.hasNoValue() || !jsonSource.v8Value()->IsString()) {
v8SetReturnValue(info, v8::Null(isolate));
return;
}
v8::TryCatch exceptionCatcher;
v8::Handle<v8::Value> json = v8::JSON::Parse(jsonSource.v8Value().As<v8::String>());
if (exceptionCatcher.HasCaught() || json.IsEmpty())
v8SetReturnValue(info, v8::Null(isolate));
else
v8SetReturnValue(info, json);
return;
}
case XMLHttpRequest::ResponseTypeDocument:
{
ExceptionState exceptionState(ExceptionState::GetterContext, "response", "XMLHttpRequest", info.Holder(), info.GetIsolate());
Document* document = xmlHttpRequest->responseXML(exceptionState);
if (exceptionState.throwIfNeeded())
return;
v8SetReturnValueFast(info, document, xmlHttpRequest);
return;
}
case XMLHttpRequest::ResponseTypeBlob:
{
Blob* blob = xmlHttpRequest->responseBlob();
v8SetReturnValueFast(info, blob, xmlHttpRequest);
return;
}
case XMLHttpRequest::ResponseTypeStream:
{
Stream* stream = xmlHttpRequest->responseStream();
v8SetReturnValueFast(info, stream, xmlHttpRequest);
return;
}
case XMLHttpRequest::ResponseTypeArrayBuffer:
{
ArrayBuffer* arrayBuffer = xmlHttpRequest->responseArrayBuffer();
if (arrayBuffer) {
arrayBuffer->setDeallocationObserver(V8ArrayBufferDeallocationObserver::instanceTemplate());
}
v8SetReturnValueFast(info, arrayBuffer, xmlHttpRequest);
return;
}
}
}
void V8XMLHttpRequest::openMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& info)
{
ExceptionState exceptionState(ExceptionState::ExecutionContext, "open", "XMLHttpRequest", info.Holder(), info.GetIsolate());
if (info.Length() < 2) {
exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments(2, info.Length()));
exceptionState.throwIfNeeded();
return;
}
XMLHttpRequest* xmlHttpRequest = V8XMLHttpRequest::toNative(info.Holder());
V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, method, info[0]);
V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, urlstring, info[1]);
ExecutionContext* context = currentExecutionContext(info.GetIsolate());
KURL url = context->completeURL(urlstring);
if (info.Length() >= 3) {
bool async = info[2]->BooleanValue();
if (info.Length() >= 4 && !info[3]->IsUndefined()) {
V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<WithNullCheck>, user, info[3]);
if (info.Length() >= 5 && !info[4]->IsUndefined()) {
V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<WithNullCheck>, password, info[4]);
xmlHttpRequest->open(method, url, async, user, password, exceptionState);
} else {
xmlHttpRequest->open(method, url, async, user, exceptionState);
}
} else {
xmlHttpRequest->open(method, url, async, exceptionState);
}
} else {
xmlHttpRequest->open(method, url, exceptionState);
}
exceptionState.throwIfNeeded();
}
static bool isDocumentType(v8::Handle<v8::Value> value, v8::Isolate* isolate)
{
return V8Document::hasInstance(value, isolate) || V8HTMLDocument::hasInstance(value, isolate);
}
void V8XMLHttpRequest::sendMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& info)
{
XMLHttpRequest* xmlHttpRequest = V8XMLHttpRequest::toNative(info.Holder());
InspectorInstrumentation::willSendXMLHttpRequest(xmlHttpRequest->executionContext(), xmlHttpRequest->url());
ExceptionState exceptionState(ExceptionState::ExecutionContext, "send", "XMLHttpRequest", info.Holder(), info.GetIsolate());
if (info.Length() < 1)
xmlHttpRequest->send(exceptionState);
else {
v8::Handle<v8::Value> arg = info[0];
if (isUndefinedOrNull(arg)) {
xmlHttpRequest->send(exceptionState);
} else if (isDocumentType(arg, info.GetIsolate())) {
v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(arg);
Document* document = V8Document::toNative(object);
ASSERT(document);
xmlHttpRequest->send(document, exceptionState);
} else if (V8Blob::hasInstance(arg, info.GetIsolate())) {
v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(arg);
Blob* blob = V8Blob::toNative(object);
ASSERT(blob);
xmlHttpRequest->send(blob, exceptionState);
} else if (V8FormData::hasInstance(arg, info.GetIsolate())) {
v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(arg);
DOMFormData* domFormData = V8FormData::toNative(object);
ASSERT(domFormData);
xmlHttpRequest->send(domFormData, exceptionState);
} else if (V8ArrayBuffer::hasInstance(arg, info.GetIsolate())) {
v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(arg);
ArrayBuffer* arrayBuffer = V8ArrayBuffer::toNative(object);
ASSERT(arrayBuffer);
xmlHttpRequest->send(arrayBuffer, exceptionState);
} else if (V8ArrayBufferView::hasInstance(arg, info.GetIsolate())) {
v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(arg);
ArrayBufferView* arrayBufferView = V8ArrayBufferView::toNative(object);
ASSERT(arrayBufferView);
xmlHttpRequest->send(arrayBufferView, exceptionState);
} else {
V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<WithNullCheck>, argString, arg);
xmlHttpRequest->send(argString, exceptionState);
}
}
exceptionState.throwIfNeeded();
}
}