JSElementCustom.cpp [plain text]
#include "config.h"
#include "JSElement.h"
#include "Attr.h"
#include "Document.h"
#include "Element.h"
#include "ExceptionCode.h"
#include "HTMLFrameElement.h"
#include "HTMLIFrameElement.h"
#include "HTMLNames.h"
#include "PlatformString.h"
#include "kjs_binding.h"
#include "kjs_dom.h"
namespace WebCore {
using namespace HTMLNames;
static inline bool allowSettingSrcToJavascriptURL(KJS::ExecState* exec, Element* element, String name, String value)
{
if (element->hasTagName(iframeTag) && equalIgnoringCase(name, "src") && value.startsWith("javascript:", false)) {
HTMLIFrameElement* frame = static_cast<HTMLIFrameElement*>(element);
if (!checkNodeSecurity(exec, frame->contentDocument()))
return false;
}
if (element->hasTagName(frameTag) && equalIgnoringCase(name, "src") && value.startsWith("javascript:", false)) {
HTMLFrameElement* frame = static_cast<HTMLFrameElement*>(element);
if (!checkNodeSecurity(exec, frame->contentDocument()))
return false;
}
return true;
}
KJS::JSValue* JSElement::setAttribute(KJS::ExecState* exec, const KJS::List& args)
{
ExceptionCode ec = 0;
String name = args[0]->toString(exec);
String value = args[1]->toString(exec);
Element* imp = static_cast<Element*>(impl());
if (!allowSettingSrcToJavascriptURL(exec, imp, name, value))
return KJS::jsUndefined();
imp->setAttribute(name, value, ec);
KJS::setDOMException(exec, ec);
return KJS::jsUndefined();
}
KJS::JSValue* JSElement::setAttributeNode(KJS::ExecState* exec, const KJS::List& args)
{
ExceptionCode ec = 0;
bool newAttrOk;
Attr* newAttr = toAttr(args[0], newAttrOk);
if (!newAttrOk) {
setDOMException(exec, TYPE_MISMATCH_ERR);
return KJS::jsUndefined();
}
Element* imp = static_cast<Element*>(impl());
if (!allowSettingSrcToJavascriptURL(exec, imp, newAttr->name(), newAttr->value()))
return KJS::jsUndefined();
KJS::JSValue* result = toJS(exec, WTF::getPtr(imp->setAttributeNode(newAttr, ec)));
KJS::setDOMException(exec, ec);
return result;
}
KJS::JSValue* JSElement::setAttributeNS(KJS::ExecState* exec, const KJS::List& args)
{
ExceptionCode ec = 0;
String namespaceURI = valueToStringWithNullCheck(exec, args[0]);
String qualifiedName = args[1]->toString(exec);
String value = args[2]->toString(exec);
Element* imp = static_cast<Element*>(impl());
if (!allowSettingSrcToJavascriptURL(exec, imp, qualifiedName, value))
return KJS::jsUndefined();
imp->setAttributeNS(namespaceURI, qualifiedName, value, ec);
KJS::setDOMException(exec, ec);
return KJS::jsUndefined();
}
KJS::JSValue* JSElement::setAttributeNodeNS(KJS::ExecState* exec, const KJS::List& args)
{
ExceptionCode ec = 0;
bool newAttrOk;
Attr* newAttr = toAttr(args[0], newAttrOk);
if (!newAttrOk) {
KJS::setDOMException(exec, TYPE_MISMATCH_ERR);
return KJS::jsUndefined();
}
Element* imp = static_cast<Element*>(impl());
if (!allowSettingSrcToJavascriptURL(exec, imp, newAttr->name(), newAttr->value()))
return KJS::jsUndefined();
KJS::JSValue* result = toJS(exec, WTF::getPtr(imp->setAttributeNodeNS(newAttr, ec)));
KJS::setDOMException(exec, ec);
return result;
}
}