JSDOMWindowCustom.h [plain text]
#ifndef JSDOMWindowCustom_h
#define JSDOMWindowCustom_h
#include "JSDOMWindow.h"
#include "JSDOMWindowShell.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);
}
JSC::JSValuePtr nonCachingStaticCloseFunctionGetter(JSC::ExecState*, const JSC::Identifier&, const JSC::PropertySlot&);
JSC::JSValuePtr nonCachingStaticBlurFunctionGetter(JSC::ExecState*, const JSC::Identifier&, const JSC::PropertySlot&);
JSC::JSValuePtr nonCachingStaticFocusFunctionGetter(JSC::ExecState*, const JSC::Identifier&, const JSC::PropertySlot&);
JSC::JSValuePtr nonCachingStaticPostMessageFunctionGetter(JSC::ExecState*, const JSC::Identifier&, const JSC::PropertySlot&);
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, nonCachingStaticCloseFunctionGetter);
return true;
}
slot.setUndefined();
return true;
}
bool allowsAccess = allowsAccessFromNoErrorMessage(exec);
if (JSGlobalObject::getOwnPropertySlot(exec, propertyName, slot)) {
if (allowsAccess)
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, nonCachingStaticBlurFunctionGetter);
return true;
}
} else if (entry->function() == jsDOMWindowPrototypeFunctionClose) {
if (!allowsAccess) {
slot.setCustom(this, nonCachingStaticCloseFunctionGetter);
return true;
}
} else if (entry->function() == jsDOMWindowPrototypeFunctionFocus) {
if (!allowsAccess) {
slot.setCustom(this, nonCachingStaticFocusFunctionGetter);
return true;
}
} else if (entry->function() == jsDOMWindowPrototypeFunctionPostMessage) {
if (!allowsAccess) {
slot.setCustom(this, nonCachingStaticPostMessageFunctionGetter);
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::JSValuePtr 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;
if (!originWindow->impl()->document())
return true;
const SecurityOrigin* originSecurityOrigin = originWindow->impl()->securityOrigin();
const SecurityOrigin* targetSecurityOrigin = targetWindow->impl()->securityOrigin();
return originSecurityOrigin->canAccess(targetSecurityOrigin);
}
}
#endif // JSDOMWindowCustom_h