JSDOMWindowCustom.cpp [plain text]
#include "config.h"
#include "JSDOMWindow.h"
#include "AtomicString.h"
#include "DOMWindow.h"
#include "Document.h"
#include "ExceptionCode.h"
#include "Frame.h"
#include "FrameLoader.h"
#include "FrameTree.h"
#include "kjs_window.h"
#include <kjs/object.h>
using namespace KJS;
namespace WebCore {
bool JSDOMWindow::customGetOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
{
const HashEntry* entry;
if (!impl()->frame()) {
entry = Lookup::findEntry(info.propHashTable, propertyName);
if (entry && !(entry->attr & Function) && entry->value.intValue == ClosedAttrNum) {
slot.setStaticEntry(this, entry, staticValueGetter<JSDOMWindow>);
return true;
}
entry = Lookup::findEntry(JSDOMWindowPrototype::info.propHashTable, propertyName);
if (entry && (entry->attr & Function) && entry->value.functionValue == jsDOMWindowPrototypeFunctionClose) {
slot.setStaticEntry(this, entry, nonCachingStaticFunctionGetter);
return true;
}
slot.setUndefined(this);
return true;
}
bool allowsAccess = allowsAccessFromNoErrorMessage(exec);
if (JSGlobalObject::getOwnPropertySlot(exec, propertyName, slot)) {
if (allowsAccess)
return true;
}
entry = Lookup::findEntry(JSDOMWindowPrototype::info.propHashTable, propertyName);
if (entry) {
if ((entry->attr & Function)
&& (entry->value.functionValue == jsDOMWindowPrototypeFunctionBlur
|| entry->value.functionValue == jsDOMWindowPrototypeFunctionClose
|| entry->value.functionValue == jsDOMWindowPrototypeFunctionFocus
#if ENABLE(CROSS_DOCUMENT_MESSAGING)
|| entry->value.functionValue == jsDOMWindowPrototypeFunctionPostMessage
#endif
)) {
if (!allowsAccess) {
slot.setStaticEntry(this, entry, nonCachingStaticFunctionGetter);
return true;
}
}
} else {
if (propertyName == exec->propertyNames().toString) {
if (!allowsAccess) {
slot.setCustom(this, objectToStringFunctionGetter);
return true;
}
}
}
return false;
}
bool JSDOMWindow::customPut(ExecState* exec, const Identifier& propertyName, JSValue* value, int attr)
{
if (!impl()->frame())
return true;
if (attr != None && attr != DontDelete) {
JSGlobalObject::put(exec, propertyName, value, attr);
return true;
}
PropertySlot slot;
if (JSGlobalObject::getOwnPropertySlot(exec, propertyName, slot)) {
if (allowsAccessFrom(exec))
JSGlobalObject::put(exec, propertyName, value, attr);
return true;
}
return false;
}
bool JSDOMWindow::deleteProperty(ExecState* exec, const Identifier& propertyName)
{
if (!allowsAccessFrom(exec))
return false;
return Base::deleteProperty(exec, propertyName);
}
bool JSDOMWindow::customGetPropertyNames(ExecState* exec, PropertyNameArray&)
{
if (!allowsAccessFrom(exec))
return true;
return false;
}
#if ENABLE(CROSS_DOCUMENT_MESSAGING)
JSValue* JSDOMWindow::postMessage(ExecState* exec, const List& args)
{
DOMWindow* window = impl();
DOMWindow* source = static_cast<JSDOMWindow*>(exec->dynamicGlobalObject())->impl();
String domain = source->frame()->loader()->url().host();
String uri = source->frame()->loader()->url().string();
String message = args[0]->toString(exec);
if (exec->hadException())
return jsUndefined();
window->postMessage(message, domain, uri, source);
return jsUndefined();
}
#endif
}