JSDOMWindowBase.cpp [plain text]
#include "config.h"
#include "JSDOMWindowBase.h"
#include "CString.h"
#include "Chrome.h"
#include "Console.h"
#include "DOMWindow.h"
#include "Frame.h"
#include "InspectorController.h"
#include "JSDOMWindowCustom.h"
#include "JSNode.h"
#include "Logging.h"
#include "Page.h"
#include "ScriptController.h"
#include "SecurityOrigin.h"
#include "Settings.h"
#include "ChromeClient.h"
using namespace JSC;
namespace WebCore {
const ClassInfo JSDOMWindowBase::s_info = { "Window", &JSDOMGlobalObject::s_info, 0, 0 };
JSDOMWindowBase::JSDOMWindowBaseData::JSDOMWindowBaseData(PassRefPtr<DOMWindow> window, JSDOMWindowShell* shell)
: JSDOMGlobalObjectData(shell->world(), destroyJSDOMWindowBaseData)
, impl(window)
, shell(shell)
{
}
JSDOMWindowBase::JSDOMWindowBase(NonNullPassRefPtr<Structure> structure, PassRefPtr<DOMWindow> window, JSDOMWindowShell* shell)
: JSDOMGlobalObject(structure, new JSDOMWindowBaseData(window, shell), shell)
{
GlobalPropertyInfo staticGlobals[] = {
GlobalPropertyInfo(Identifier(globalExec(), "document"), jsNull(), DontDelete | ReadOnly),
GlobalPropertyInfo(Identifier(globalExec(), "window"), d()->shell, DontDelete | ReadOnly)
};
addStaticGlobals(staticGlobals, sizeof(staticGlobals) / sizeof(GlobalPropertyInfo));
}
void JSDOMWindowBase::updateDocument()
{
ASSERT(d()->impl->document());
ExecState* exec = globalExec();
symbolTablePutWithAttributes(Identifier(exec, "document"), toJS(exec, this, d()->impl->document()), DontDelete | ReadOnly);
}
ScriptExecutionContext* JSDOMWindowBase::scriptExecutionContext() const
{
return d()->impl->document();
}
String JSDOMWindowBase::crossDomainAccessErrorMessage(const JSGlobalObject* other) const
{
KURL originURL = asJSDOMWindow(other)->impl()->url();
KURL targetURL = d()->shell->window()->impl()->url();
if (originURL.isNull() || targetURL.isNull())
return String();
return String::format("Unsafe JavaScript attempt to access frame with URL %s from frame with URL %s. Domains, protocols and ports must match.\n",
targetURL.string().utf8().data(), originURL.string().utf8().data());
}
void JSDOMWindowBase::printErrorMessage(const String& message) const
{
printErrorMessageForFrame(impl()->frame(), message);
}
ExecState* JSDOMWindowBase::globalExec()
{
if (Frame *frame = impl()->frame())
frame->keepAlive();
return Base::globalExec();
}
bool JSDOMWindowBase::supportsProfiling() const
{
#if !ENABLE(JAVASCRIPT_DEBUGGER) || !ENABLE(INSPECTOR)
return false;
#else
Frame* frame = impl()->frame();
if (!frame)
return false;
Page* page = frame->page();
if (!page)
return false;
#if ENABLE(INSPECTOR)
return page->inspectorController()->profilerEnabled();
#else
return false;
#endif // ENABLE(INSPECTOR)
#endif
}
bool JSDOMWindowBase::shouldInterruptScript() const
{
ASSERT(impl()->frame());
Page* page = impl()->frame()->page();
ASSERT(page);
if (!page)
return true;
return page->chrome()->shouldInterruptJavaScript();
}
bool JSDOMWindowBase::shouldInterruptScriptBeforeTimeout() const
{
if (impl()->frame() && impl()->frame()->page() && impl()->frame()->page()->chrome()->client()->isStopping())
return true;
return JSGlobalObject::shouldInterruptScriptBeforeTimeout();
}
void JSDOMWindowBase::willRemoveFromWindowShell()
{
setCurrentEvent(0);
}
JSObject* JSDOMWindowBase::toThisObject(ExecState*) const
{
return shell();
}
JSDOMWindowShell* JSDOMWindowBase::shell() const
{
return d()->shell;
}
JSGlobalData* JSDOMWindowBase::commonJSGlobalData()
{
ASSERT(isMainThread() || pthread_main_np());
static JSGlobalData* globalData = 0;
if (!globalData) {
globalData = JSGlobalData::createLeaked().releaseRef();
globalData->timeoutChecker.setTimeoutInterval(10000); #ifndef NDEBUG
globalData->mainThreadOnly = true;
#endif
globalData->clientData = new WebCoreJSClientData(globalData);
}
return globalData;
}
void JSDOMWindowBase::destroyJSDOMWindowBaseData(void* jsDOMWindowBaseData)
{
delete static_cast<JSDOMWindowBaseData*>(jsDOMWindowBaseData);
}
JSValue toJS(ExecState* exec, JSDOMGlobalObject*, DOMWindow* domWindow)
{
return toJS(exec, domWindow);
}
JSValue toJS(ExecState* exec, DOMWindow* domWindow)
{
if (!domWindow)
return jsNull();
Frame* frame = domWindow->frame();
if (!frame)
return jsNull();
return frame->script()->windowShell(currentWorld(exec));
}
JSDOMWindow* toJSDOMWindow(Frame* frame, DOMWrapperWorld* world)
{
if (!frame)
return 0;
return frame->script()->windowShell(world)->window();
}
JSDOMWindow* toJSDOMWindow(JSValue value)
{
if (!value.isObject())
return 0;
const ClassInfo* classInfo = asObject(value)->classInfo();
if (classInfo == &JSDOMWindow::s_info)
return static_cast<JSDOMWindow*>(asObject(value));
if (classInfo == &JSDOMWindowShell::s_info)
return static_cast<JSDOMWindowShell*>(asObject(value))->window();
return 0;
}
}