#ifndef V8DOMWrapper_h
#define V8DOMWrapper_h
#include "Document.h"
#include "Event.h"
#include "Node.h"
#include "NodeFilter.h"
#include "PlatformString.h" // for WebCore::String
#include "V8CustomBinding.h"
#include "V8CustomXPathNSResolver.h"
#include "V8DOMMap.h"
#include "V8Event.h"
#include "V8Index.h"
#include "V8Utilities.h"
#include "V8XPathNSResolver.h"
#include "XPathNSResolver.h"
#include <v8.h>
namespace WebCore {
class CSSRule;
class CSSRuleList;
class CSSStyleDeclaration;
class CSSValue;
class CSSValueList;
class ClientRectList;
class DOMImplementation;
class DOMWindow;
class Document;
class Element;
class Event;
class EventListener;
class EventTarget;
class Frame;
class HTMLCollection;
class HTMLDocument;
class HTMLElement;
class HTMLOptionsCollection;
class MediaList;
class MimeType;
class MimeTypeArray;
class NamedNodeMap;
class Navigator;
class Node;
class NodeFilter;
class NodeList;
class Plugin;
class PluginArray;
class SVGElement;
#if ENABLE(SVG)
class SVGElementInstance;
#endif
class Screen;
class ScriptExecutionContext;
#if ENABLE(DOM_STORAGE)
class Storage;
class StorageEvent;
#endif
class String;
class StyleSheet;
class StyleSheetList;
class V8EventListener;
class V8ObjectEventListener;
class V8Proxy;
#if ENABLE(WEB_SOCKETS)
class WebSocket;
#endif
class WorkerContext;
enum ListenerLookupType {
ListenerFindOnly,
ListenerFindOrCreate,
};
class V8DOMWrapper {
public:
#ifndef NDEBUG
static bool maybeDOMWrapper(v8::Handle<v8::Value>);
#endif
static void setDOMWrapper(v8::Handle<v8::Object> object, int type, void* cptr)
{
ASSERT(object->InternalFieldCount() >= 2);
object->SetPointerInInternalField(v8DOMWrapperObjectIndex, cptr);
object->SetInternalField(v8DOMWrapperTypeIndex, v8::Integer::New(type));
}
static v8::Handle<v8::Object> lookupDOMWrapper(V8ClassIndex::V8WrapperType type, v8::Handle<v8::Object> object)
{
return object.IsEmpty() ? object : object->FindInstanceInPrototypeChain(getTemplate(type));
}
template<typename T>
static v8::Handle<v8::Value> convertToV8Object(V8ClassIndex::V8WrapperType type, PassRefPtr<T> imp)
{
return convertToV8Object(type, imp.get());
}
static v8::Handle<v8::Value> convertToV8Object(V8ClassIndex::V8WrapperType, void*);
static v8::Handle<v8::Value> convertNodeToV8Object(PassRefPtr<Node> node)
{
return convertNodeToV8Object(node.get());
}
static v8::Handle<v8::Value> convertNodeToV8Object(Node*);
static v8::Handle<v8::Value> convertDocumentToV8Object(Document*);
static v8::Handle<v8::Value> convertNewNodeToV8Object(PassRefPtr<Node> node)
{
return convertNewNodeToV8Object(node.get());
}
static v8::Handle<v8::Value> convertNewNodeToV8Object(Node* node)
{
return convertNewNodeToV8Object(node, 0, getDOMNodeMap());
}
static v8::Handle<v8::Value> convertNewNodeToV8Object(Node*, V8Proxy*, DOMNodeMapping&);
static V8ClassIndex::V8WrapperType domWrapperType(v8::Handle<v8::Object>);
static v8::Handle<v8::Value> convertEventToV8Object(PassRefPtr<Event> event)
{
return convertEventToV8Object(event.get());
}
static v8::Handle<v8::Value> convertEventToV8Object(Event*);
static v8::Handle<v8::Value> convertEventTargetToV8Object(PassRefPtr<EventTarget> eventTarget)
{
return convertEventTargetToV8Object(eventTarget.get());
}
static v8::Handle<v8::Value> convertEventTargetToV8Object(EventTarget*);
static v8::Handle<v8::Value> convertEventListenerToV8Object(ScriptExecutionContext* context, PassRefPtr<EventListener> eventListener)
{
return convertEventListenerToV8Object(context, eventListener.get());
}
static v8::Handle<v8::Value> convertEventListenerToV8Object(ScriptExecutionContext*, EventListener*);
static PassRefPtr<EventListener> getEventListener(Node* node, v8::Local<v8::Value> value, bool isAttribute, ListenerLookupType lookup);
static PassRefPtr<EventListener> getEventListener(SVGElementInstance* element, v8::Local<v8::Value> value, bool isAttribute, ListenerLookupType lookup);
static PassRefPtr<EventListener> getEventListener(AbstractWorker* worker, v8::Local<v8::Value> value, bool isAttribute, ListenerLookupType lookup);
#if ENABLE(NOTIFICATIONS)
static PassRefPtr<EventListener> getEventListener(Notification* notification, v8::Local<v8::Value> value, bool isAttribute, ListenerLookupType lookup);
#endif
static PassRefPtr<EventListener> getEventListener(WorkerContext* workerContext, v8::Local<v8::Value> value, bool isAttribute, ListenerLookupType lookup);
static PassRefPtr<EventListener> getEventListener(XMLHttpRequestUpload* upload, v8::Local<v8::Value> value, bool isAttribute, ListenerLookupType lookup);
#if ENABLE(EVENTSOURCE)
static PassRefPtr<EventListener> getEventListener(EventSource* eventTarget, v8::Local<v8::Value> value, bool isAttribute, ListenerLookupType lookup);
#endif
static PassRefPtr<EventListener> getEventListener(EventTarget* eventTarget, v8::Local<v8::Value> value, bool isAttribute, ListenerLookupType lookup);
static PassRefPtr<EventListener> getEventListener(V8Proxy* proxy, v8::Local<v8::Value> value, bool isAttribute, ListenerLookupType lookup);
#if ENABLE(XPATH)
static RefPtr<XPathNSResolver> getXPathNSResolver(v8::Handle<v8::Value> value, V8Proxy* proxy = 0)
{
RefPtr<XPathNSResolver> resolver;
if (V8XPathNSResolver::HasInstance(value))
resolver = V8XPathNSResolver::toNative(v8::Handle<v8::Object>::Cast(value));
else if (value->IsObject())
resolver = V8CustomXPathNSResolver::create(proxy, value->ToObject());
return resolver;
}
#endif
static v8::Handle<v8::Value> convertDOMImplementationToV8Object(DOMImplementation*);
static PassRefPtr<NodeFilter> wrapNativeNodeFilter(v8::Handle<v8::Value>);
static v8::Persistent<v8::FunctionTemplate> getTemplate(V8ClassIndex::V8WrapperType);
static v8::Local<v8::Function> getConstructorForContext(V8ClassIndex::V8WrapperType, v8::Handle<v8::Context>);
static v8::Local<v8::Function> getConstructor(V8ClassIndex::V8WrapperType, v8::Handle<v8::Value> objectPrototype);
static v8::Local<v8::Function> getConstructor(V8ClassIndex::V8WrapperType, DOMWindow*);
static v8::Local<v8::Function> getConstructor(V8ClassIndex::V8WrapperType, WorkerContext*);
static void setJSWrapperForDOMObject(void*, v8::Persistent<v8::Object>);
static void setJSWrapperForActiveDOMObject(void*, v8::Persistent<v8::Object>);
static void setJSWrapperForDOMNode(Node*, v8::Persistent<v8::Object>);
static bool isWrapperOfType(v8::Handle<v8::Value>, V8ClassIndex::V8WrapperType);
static bool isDOMEventWrapper(v8::Handle<v8::Value>);
static v8::Handle<v8::Value> convertStyleSheetToV8Object(StyleSheet*);
static v8::Handle<v8::Value> convertCSSValueToV8Object(CSSValue*);
static v8::Handle<v8::Value> convertCSSRuleToV8Object(CSSRule*);
static v8::Handle<v8::Value> convertWindowToV8Object(DOMWindow*);
static v8::Handle<v8::Value> convertNamedNodeMapToV8Object(NamedNodeMap*);
#if ENABLE(SVG)
static v8::Handle<v8::Value> convertSVGElementInstanceToV8Object(SVGElementInstance*);
static v8::Handle<v8::Value> convertSVGObjectWithContextToV8Object(V8ClassIndex::V8WrapperType, void*);
#endif
#if ENABLE(3D_CANVAS)
static void setIndexedPropertiesToExternalArray(v8::Handle<v8::Object>,
int,
void*,
int);
#endif
private:
static void setHiddenWindowReference(Frame*, const int internalIndex, v8::Handle<v8::Object>);
static V8ClassIndex::V8WrapperType htmlElementType(HTMLElement*);
#if ENABLE(SVG)
static V8ClassIndex::V8WrapperType svgElementType(SVGElement*);
#endif
static v8::Local<v8::Object> instantiateV8Object(V8ClassIndex::V8WrapperType descType, V8ClassIndex::V8WrapperType cptrType, void* impl)
{
return instantiateV8Object(NULL, descType, cptrType, impl);
}
static v8::Local<v8::Object> instantiateV8Object(V8Proxy*, V8ClassIndex::V8WrapperType, V8ClassIndex::V8WrapperType, void*);
};
}
#endif // V8DOMWrapper_h