/*
    This file is part of the WebKit open source project.
    This file has been generated by generate-bindings.pl. DO NOT MODIFY!

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
    Boston, MA 02110-1301, USA.
*/

#include "config.h"
#include "JSClipboard.h"

#include "Clipboard.h"
#include "ExceptionCode.h"
#include "FileList.h"
#include "JSDOMBinding.h"
#include "JSElement.h"
#include "JSFileList.h"
#include "URL.h"
#include <runtime/Error.h>
#include <runtime/JSString.h>
#include <wtf/GetPtr.h>

#if ENABLE(DATA_TRANSFER_ITEMS)
#include "DataTransferItemList.h"
#include "JSDataTransferItemList.h"
#endif

using namespace JSC;

namespace WebCore {

/* Hash table */

static const HashTableValue JSClipboardTableValues[] =
{
    { "dropEffect", DontDelete, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsClipboardDropEffect), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSClipboardDropEffect) },
    { "effectAllowed", DontDelete, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsClipboardEffectAllowed), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSClipboardEffectAllowed) },
    { "types", DontDelete | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsClipboardTypes), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
    { "files", DontDelete | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsClipboardFiles), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
#if ENABLE(DATA_TRANSFER_ITEMS)
    { "items", DontDelete | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsClipboardItems), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
#endif
    { "constructor", DontEnum | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsClipboardConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
    { 0, 0, NoIntrinsic, 0, 0 }
};

static const HashTable JSClipboardTable = { 17, 15, true, JSClipboardTableValues, 0 };
/* Hash table for constructor */

static const HashTableValue JSClipboardConstructorTableValues[] =
{
    { 0, 0, NoIntrinsic, 0, 0 }
};

static const HashTable JSClipboardConstructorTable = { 1, 0, false, JSClipboardConstructorTableValues, 0 };
const ClassInfo JSClipboardConstructor::s_info = { "ClipboardConstructor", &Base::s_info, &JSClipboardConstructorTable, 0, CREATE_METHOD_TABLE(JSClipboardConstructor) };

JSClipboardConstructor::JSClipboardConstructor(Structure* structure, JSDOMGlobalObject* globalObject)
    : DOMConstructorObject(structure, globalObject)
{
}

void JSClipboardConstructor::finishCreation(VM& vm, JSDOMGlobalObject* globalObject)
{
    Base::finishCreation(vm);
    ASSERT(inherits(info()));
    putDirect(vm, vm.propertyNames->prototype, JSClipboardPrototype::self(vm, globalObject), DontDelete | ReadOnly);
    putDirect(vm, vm.propertyNames->length, jsNumber(0), ReadOnly | DontDelete | DontEnum);
}

bool JSClipboardConstructor::getOwnPropertySlot(JSObject* object, ExecState* exec, PropertyName propertyName, PropertySlot& slot)
{
    return getStaticValueSlot<JSClipboardConstructor, JSDOMWrapper>(exec, JSClipboardConstructorTable, jsCast<JSClipboardConstructor*>(object), propertyName, slot);
}

/* Hash table for prototype */

static const HashTableValue JSClipboardPrototypeTableValues[] =
{
    { "clearData", JSC::Function, NoIntrinsic, (intptr_t)static_cast<NativeFunction>(jsClipboardPrototypeFunctionClearData), (intptr_t) (0) },
    { "getData", JSC::Function, NoIntrinsic, (intptr_t)static_cast<NativeFunction>(jsClipboardPrototypeFunctionGetData), (intptr_t) (1) },
    { "setData", JSC::Function, NoIntrinsic, (intptr_t)static_cast<NativeFunction>(jsClipboardPrototypeFunctionSetData), (intptr_t) (2) },
    { "setDragImage", JSC::Function, NoIntrinsic, (intptr_t)static_cast<NativeFunction>(jsClipboardPrototypeFunctionSetDragImage), (intptr_t) (3) },
    { 0, 0, NoIntrinsic, 0, 0 }
};

static const HashTable JSClipboardPrototypeTable = { 8, 7, false, JSClipboardPrototypeTableValues, 0 };
const ClassInfo JSClipboardPrototype::s_info = { "ClipboardPrototype", &Base::s_info, &JSClipboardPrototypeTable, 0, CREATE_METHOD_TABLE(JSClipboardPrototype) };

JSObject* JSClipboardPrototype::self(VM& vm, JSGlobalObject* globalObject)
{
    return getDOMPrototype<JSClipboard>(vm, globalObject);
}

bool JSClipboardPrototype::getOwnPropertySlot(JSObject* object, ExecState* exec, PropertyName propertyName, PropertySlot& slot)
{
    JSClipboardPrototype* thisObject = jsCast<JSClipboardPrototype*>(object);
    return getStaticFunctionSlot<JSObject>(exec, JSClipboardPrototypeTable, thisObject, propertyName, slot);
}

const ClassInfo JSClipboard::s_info = { "Clipboard", &Base::s_info, &JSClipboardTable, 0 , CREATE_METHOD_TABLE(JSClipboard) };

JSClipboard::JSClipboard(Structure* structure, JSDOMGlobalObject* globalObject, PassRefPtr<Clipboard> impl)
    : JSDOMWrapper(structure, globalObject)
    , m_impl(impl.leakRef())
{
}

void JSClipboard::finishCreation(VM& vm)
{
    Base::finishCreation(vm);
    ASSERT(inherits(info()));
}

JSObject* JSClipboard::createPrototype(VM& vm, JSGlobalObject* globalObject)
{
    return JSClipboardPrototype::create(vm, globalObject, JSClipboardPrototype::createStructure(vm, globalObject, globalObject->objectPrototype()));
}

void JSClipboard::destroy(JSC::JSCell* cell)
{
    JSClipboard* thisObject = static_cast<JSClipboard*>(cell);
    thisObject->JSClipboard::~JSClipboard();
}

JSClipboard::~JSClipboard()
{
    releaseImplIfNotNull();
}

bool JSClipboard::getOwnPropertySlot(JSObject* object, ExecState* exec, PropertyName propertyName, PropertySlot& slot)
{
    JSClipboard* thisObject = jsCast<JSClipboard*>(object);
    ASSERT_GC_OBJECT_INHERITS(thisObject, info());
    return getStaticValueSlot<JSClipboard, Base>(exec, JSClipboardTable, thisObject, propertyName, slot);
}

EncodedJSValue jsClipboardDropEffect(ExecState* exec, EncodedJSValue slotBase, EncodedJSValue thisValue, PropertyName)
{
    JSClipboard* castedThis = jsDynamicCast<JSClipboard*>(JSValue::decode(thisValue));
    UNUSED_PARAM(slotBase);
    if (!castedThis)
        return throwVMTypeError(exec);
    UNUSED_PARAM(exec);
    Clipboard& impl = castedThis->impl();
    JSValue result = jsStringWithCache(exec, impl.dropEffect());
    return JSValue::encode(result);
}


EncodedJSValue jsClipboardEffectAllowed(ExecState* exec, EncodedJSValue slotBase, EncodedJSValue thisValue, PropertyName)
{
    JSClipboard* castedThis = jsDynamicCast<JSClipboard*>(JSValue::decode(thisValue));
    UNUSED_PARAM(slotBase);
    if (!castedThis)
        return throwVMTypeError(exec);
    UNUSED_PARAM(exec);
    Clipboard& impl = castedThis->impl();
    JSValue result = jsStringWithCache(exec, impl.effectAllowed());
    return JSValue::encode(result);
}


EncodedJSValue jsClipboardTypes(ExecState* exec, EncodedJSValue slotBase, EncodedJSValue thisValue, PropertyName)
{
    JSClipboard* castedThis = jsDynamicCast<JSClipboard*>(JSValue::decode(thisValue));
    UNUSED_PARAM(slotBase);
    if (!castedThis)
        return throwVMTypeError(exec);
    return JSValue::encode(castedThis->types(exec));
}


EncodedJSValue jsClipboardFiles(ExecState* exec, EncodedJSValue slotBase, EncodedJSValue thisValue, PropertyName)
{
    JSClipboard* castedThis = jsDynamicCast<JSClipboard*>(JSValue::decode(thisValue));
    UNUSED_PARAM(slotBase);
    if (!castedThis)
        return throwVMTypeError(exec);
    UNUSED_PARAM(exec);
    Clipboard& impl = castedThis->impl();
    JSValue result = toJS(exec, castedThis->globalObject(), WTF::getPtr(impl.files()));
    return JSValue::encode(result);
}


#if ENABLE(DATA_TRANSFER_ITEMS)
EncodedJSValue jsClipboardItems(ExecState* exec, EncodedJSValue slotBase, EncodedJSValue thisValue, PropertyName)
{
    JSClipboard* castedThis = jsDynamicCast<JSClipboard*>(JSValue::decode(thisValue));
    UNUSED_PARAM(slotBase);
    if (!castedThis)
        return throwVMTypeError(exec);
    UNUSED_PARAM(exec);
    Clipboard& impl = castedThis->impl();
    JSValue result = toJS(exec, castedThis->globalObject(), WTF::getPtr(impl.items()));
    return JSValue::encode(result);
}

#endif

EncodedJSValue jsClipboardConstructor(ExecState* exec, EncodedJSValue thisValue, EncodedJSValue, PropertyName)
{
    JSClipboard* domObject = jsDynamicCast<JSClipboard*>(JSValue::decode(thisValue));
    if (!domObject)
        return throwVMTypeError(exec);
    if (!domObject)
        return throwVMTypeError(exec);
    return JSValue::encode(JSClipboard::getConstructor(exec->vm(), domObject->globalObject()));
}

void setJSClipboardDropEffect(ExecState* exec, JSObject* /* baseObject */, EncodedJSValue thisValue, EncodedJSValue encodedValue)
{
    JSValue value = JSValue::decode(encodedValue);
    UNUSED_PARAM(exec);
    JSClipboard* castedThis = jsDynamicCast<JSClipboard*>(JSValue::decode(thisValue));
    if (!castedThis) {
        throwVMTypeError(exec);
        return;
    }
    Clipboard& impl = castedThis->impl();
    const String& nativeValue(value.isEmpty() ? String() : value.toString(exec)->value(exec));
    if (exec->hadException())
        return;
    impl.setDropEffect(nativeValue);
}


void setJSClipboardEffectAllowed(ExecState* exec, JSObject* /* baseObject */, EncodedJSValue thisValue, EncodedJSValue encodedValue)
{
    JSValue value = JSValue::decode(encodedValue);
    UNUSED_PARAM(exec);
    JSClipboard* castedThis = jsDynamicCast<JSClipboard*>(JSValue::decode(thisValue));
    if (!castedThis) {
        throwVMTypeError(exec);
        return;
    }
    Clipboard& impl = castedThis->impl();
    const String& nativeValue(value.isEmpty() ? String() : value.toString(exec)->value(exec));
    if (exec->hadException())
        return;
    impl.setEffectAllowed(nativeValue);
}


JSValue JSClipboard::getConstructor(VM& vm, JSGlobalObject* globalObject)
{
    return getDOMConstructor<JSClipboardConstructor>(vm, jsCast<JSDOMGlobalObject*>(globalObject));
}

EncodedJSValue JSC_HOST_CALL jsClipboardPrototypeFunctionClearData(ExecState* exec)
{
    JSValue thisValue = exec->hostThisValue();
    JSClipboard* castedThis = jsDynamicCast<JSClipboard*>(thisValue);
    if (!castedThis)
        return throwVMTypeError(exec);
    ASSERT_GC_OBJECT_INHERITS(castedThis, JSClipboard::info());
    Clipboard& impl = castedThis->impl();

    size_t argsCount = exec->argumentCount();
    if (argsCount <= 0) {
        impl.clearData();
        return JSValue::encode(jsUndefined());
    }

    const String& type(exec->argument(0).isEmpty() ? String() : exec->argument(0).toString(exec)->value(exec));
    if (exec->hadException())
        return JSValue::encode(jsUndefined());
    impl.clearData(type);
    return JSValue::encode(jsUndefined());
}

EncodedJSValue JSC_HOST_CALL jsClipboardPrototypeFunctionGetData(ExecState* exec)
{
    JSValue thisValue = exec->hostThisValue();
    JSClipboard* castedThis = jsDynamicCast<JSClipboard*>(thisValue);
    if (!castedThis)
        return throwVMTypeError(exec);
    ASSERT_GC_OBJECT_INHERITS(castedThis, JSClipboard::info());
    Clipboard& impl = castedThis->impl();
    if (exec->argumentCount() < 1)
        return throwVMError(exec, createNotEnoughArgumentsError(exec));
    const String& type(exec->argument(0).isEmpty() ? String() : exec->argument(0).toString(exec)->value(exec));
    if (exec->hadException())
        return JSValue::encode(jsUndefined());

    JSC::JSValue result = jsStringWithCache(exec, impl.getData(type));
    return JSValue::encode(result);
}

EncodedJSValue JSC_HOST_CALL jsClipboardPrototypeFunctionSetData(ExecState* exec)
{
    JSValue thisValue = exec->hostThisValue();
    JSClipboard* castedThis = jsDynamicCast<JSClipboard*>(thisValue);
    if (!castedThis)
        return throwVMTypeError(exec);
    ASSERT_GC_OBJECT_INHERITS(castedThis, JSClipboard::info());
    Clipboard& impl = castedThis->impl();
    if (exec->argumentCount() < 2)
        return throwVMError(exec, createNotEnoughArgumentsError(exec));
    const String& type(exec->argument(0).isEmpty() ? String() : exec->argument(0).toString(exec)->value(exec));
    if (exec->hadException())
        return JSValue::encode(jsUndefined());
    const String& data(exec->argument(1).isEmpty() ? String() : exec->argument(1).toString(exec)->value(exec));
    if (exec->hadException())
        return JSValue::encode(jsUndefined());

    JSC::JSValue result = jsBoolean(impl.setData(type, data));
    return JSValue::encode(result);
}

EncodedJSValue JSC_HOST_CALL jsClipboardPrototypeFunctionSetDragImage(ExecState* exec)
{
    JSValue thisValue = exec->hostThisValue();
    JSClipboard* castedThis = jsDynamicCast<JSClipboard*>(thisValue);
    if (!castedThis)
        return throwVMTypeError(exec);
    ASSERT_GC_OBJECT_INHERITS(castedThis, JSClipboard::info());
    Clipboard& impl = castedThis->impl();
    if (exec->argumentCount() < 3)
        return throwVMError(exec, createNotEnoughArgumentsError(exec));
    Element* image(toElement(exec->argument(0)));
    if (exec->hadException())
        return JSValue::encode(jsUndefined());
    int x(toInt32(exec, exec->argument(1), NormalConversion));
    if (exec->hadException())
        return JSValue::encode(jsUndefined());
    int y(toInt32(exec, exec->argument(2), NormalConversion));
    if (exec->hadException())
        return JSValue::encode(jsUndefined());
    impl.setDragImage(image, x, y);
    return JSValue::encode(jsUndefined());
}

bool JSClipboardOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor)
{
    UNUSED_PARAM(handle);
    UNUSED_PARAM(visitor);
    return false;
}

void JSClipboardOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context)
{
    JSClipboard* jsClipboard = jsCast<JSClipboard*>(handle.get().asCell());
    DOMWrapperWorld& world = *static_cast<DOMWrapperWorld*>(context);
    uncacheWrapper(world, &jsClipboard->impl(), jsClipboard);
    jsClipboard->releaseImpl();
}

JSC::JSValue toJS(JSC::ExecState* exec, JSDOMGlobalObject* globalObject, Clipboard* impl)
{
    if (!impl)
        return jsNull();
    if (JSValue result = getExistingWrapper<JSClipboard>(exec, impl))
        return result;
    ReportMemoryCost<Clipboard>::reportMemoryCost(exec, impl);
    return createNewWrapper<JSClipboard>(exec, globalObject, impl);
}

Clipboard* toClipboard(JSC::JSValue value)
{
    return value.inherits(JSClipboard::info()) ? &jsCast<JSClipboard*>(value)->impl() : 0;
}

}
