JSDOMWindowCustom.h [plain text]
#ifndef JSDOMWindowCustom_h
#define JSDOMWindowCustom_h
#include "JSDOMWindow.h"
#include "JSDOMWindowShell.h"
#include <runtime/PrototypeFunction.h>
#include <wtf/AlwaysInline.h>
namespace WebCore {
inline JSDOMWindow* asJSDOMWindow(JSC::JSGlobalObject* globalObject)
{
return static_cast<JSDOMWindow*>(globalObject);
}
inline const JSDOMWindow* asJSDOMWindow(const JSC::JSGlobalObject* globalObject)
{
return static_cast<const JSDOMWindow*>(globalObject);
}
template<JSC::NativeFunction nativeFunction, int length>
JSC::JSValue nonCachingStaticFunctionGetter(JSC::ExecState* exec, const JSC::Identifier& propertyName, const JSC::PropertySlot&)
{
return new (exec) JSC::NativeFunctionWrapper(exec, exec->lexicalGlobalObject()->prototypeFunctionStructure(), length, propertyName, nativeFunction);
}
ALWAYS_INLINE bool JSDOMWindow::customGetOwnPropertySlot(JSC::ExecState* exec, const JSC::Identifier& propertyName, JSC::PropertySlot& slot)
{
const JSC::HashEntry* entry;
if (!impl()->frame()) {
entry = s_info.propHashTable(exec)->entry(exec, propertyName);
if (entry && !(entry->attributes() & JSC::Function) && entry->propertyGetter() == jsDOMWindowClosed) {
slot.setCustom(this, entry->propertyGetter());
return true;
}
entry = JSDOMWindowPrototype::s_info.propHashTable(exec)->entry(exec, propertyName);
if (entry && (entry->attributes() & JSC::Function) && entry->function() == jsDOMWindowPrototypeFunctionClose) {
slot.setCustom(this, nonCachingStaticFunctionGetter<jsDOMWindowPrototypeFunctionClose, 0>);
return true;
}
slot.setUndefined();
return true;
}
bool allowsAccess = allowsAccessFromNoErrorMessage(exec);
if (allowsAccess && JSGlobalObject::getOwnPropertySlot(exec, propertyName, slot))
return true;
entry = JSDOMWindowPrototype::s_info.propHashTable(exec)->entry(exec, propertyName);
if (entry) {
if (entry->attributes() & JSC::Function) {
if (entry->function() == jsDOMWindowPrototypeFunctionBlur) {
if (!allowsAccess) {
slot.setCustom(this, nonCachingStaticFunctionGetter<jsDOMWindowPrototypeFunctionBlur, 0>);
return true;
}
} else if (entry->function() == jsDOMWindowPrototypeFunctionClose) {
if (!allowsAccess) {
slot.setCustom(this, nonCachingStaticFunctionGetter<jsDOMWindowPrototypeFunctionClose, 0>);
return true;
}
} else if (entry->function() == jsDOMWindowPrototypeFunctionFocus) {
if (!allowsAccess) {
slot.setCustom(this, nonCachingStaticFunctionGetter<jsDOMWindowPrototypeFunctionFocus, 0>);
return true;
}
} else if (entry->function() == jsDOMWindowPrototypeFunctionPostMessage) {
if (!allowsAccess) {
slot.setCustom(this, nonCachingStaticFunctionGetter<jsDOMWindowPrototypeFunctionPostMessage, 2>);
return true;
}
} else if (entry->function() == jsDOMWindowPrototypeFunctionShowModalDialog) {
if (!DOMWindow::canShowModalDialog(impl()->frame())) {
slot.setUndefined();
return true;
}
}
}
} else {
if (propertyName == exec->propertyNames().toString) {
if (!allowsAccess) {
slot.setCustom(this, objectToStringFunctionGetter);
return true;
}
}
}
return false;
}
inline bool JSDOMWindow::customPut(JSC::ExecState* exec, const JSC::Identifier& propertyName, JSC::JSValue value, JSC::PutPropertySlot& slot)
{
if (!impl()->frame())
return true;
JSC::PropertySlot getSlot;
bool slotIsWriteable;
if (JSGlobalObject::getOwnPropertySlot(exec, propertyName, getSlot, slotIsWriteable)) {
if (allowsAccessFrom(exec)) {
if (slotIsWriteable) {
getSlot.putValue(value);
if (getSlot.isCacheable())
slot.setExistingProperty(this, getSlot.cachedOffset());
} else
JSGlobalObject::put(exec, propertyName, value, slot);
}
return true;
}
return false;
}
inline bool JSDOMWindowBase::allowsAccessFrom(const JSGlobalObject* other) const
{
if (allowsAccessFromPrivate(other))
return true;
printErrorMessage(crossDomainAccessErrorMessage(other));
return false;
}
inline bool JSDOMWindowBase::allowsAccessFrom(JSC::ExecState* exec) const
{
if (allowsAccessFromPrivate(exec->lexicalGlobalObject()))
return true;
printErrorMessage(crossDomainAccessErrorMessage(exec->lexicalGlobalObject()));
return false;
}
inline bool JSDOMWindowBase::allowsAccessFromNoErrorMessage(JSC::ExecState* exec) const
{
return allowsAccessFromPrivate(exec->lexicalGlobalObject());
}
inline bool JSDOMWindowBase::allowsAccessFrom(JSC::ExecState* exec, String& message) const
{
if (allowsAccessFromPrivate(exec->lexicalGlobalObject()))
return true;
message = crossDomainAccessErrorMessage(exec->lexicalGlobalObject());
return false;
}
ALWAYS_INLINE bool JSDOMWindowBase::allowsAccessFromPrivate(const JSGlobalObject* other) const
{
const JSDOMWindow* originWindow = asJSDOMWindow(other);
const JSDOMWindow* targetWindow = d()->shell->window();
if (originWindow == targetWindow)
return true;
const SecurityOrigin* originSecurityOrigin = originWindow->impl()->securityOrigin();
const SecurityOrigin* targetSecurityOrigin = targetWindow->impl()->securityOrigin();
return originSecurityOrigin->canAccess(targetSecurityOrigin);
}
}
#endif // JSDOMWindowCustom_h