#include "config.h"
#include "kjs_dom.h"
#include "Document.h"
#include "EventTarget.h"
#include "Frame.h"
#include "HTMLNames.h"
#include "HTMLPlugInElement.h"
#include "JSAttr.h"
#include "JSNode.h"
#include "XMLHttpRequest.h"
#include "kjs_events.h"
#include "kjs_window.h"
#if ENABLE(SVG)
#include "JSSVGElementInstance.h"
#endif
#if USE(JAVASCRIPTCORE_BINDINGS)
#include <bindings/runtime_object.h>
#endif
namespace WebCore {
using namespace KJS;
using namespace HTMLNames;
Attr* toAttr(JSValue* val, bool& ok)
{
if (!val || !val->isObject(&JSAttr::info)) {
ok = false;
return 0;
}
ok = true;
return static_cast<Attr*>(static_cast<JSNode*>(val)->impl());
}
bool checkNodeSecurity(ExecState* exec, Node* node)
{
return node && allowsAccessFromFrame(exec, node->document()->frame());
}
JSValue* toJS(ExecState* exec, EventTarget* target)
{
if (!target)
return jsNull();
#if ENABLE(SVG)
SVGElementInstance* instance = target->toSVGElementInstance();
if (instance)
return toJS(exec, instance);
#endif
Node* node = target->toNode();
if (node)
return toJS(exec, node);
if (XMLHttpRequest* xhr = target->toXMLHttpRequest())
return ScriptInterpreter::getDOMObject(xhr);
ASSERT(0);
return jsNull();
}
JSValue* getRuntimeObject(ExecState* exec, Node* n)
{
if (!n)
return 0;
#if USE(JAVASCRIPTCORE_BINDINGS)
if (n->hasTagName(objectTag) || n->hasTagName(embedTag) || n->hasTagName(appletTag)) {
HTMLPlugInElement* plugInElement = static_cast<HTMLPlugInElement*>(n);
if (plugInElement->getInstance() && plugInElement->getInstance()->rootObject())
return KJS::Bindings::Instance::createRuntimeObject(plugInElement->getInstance());
}
#endif
return 0;
}
}