JSDocumentCustom.cpp [plain text]
#include "config.h"
#include "JSDocument.h"
#include "ExceptionCode.h"
#include "Frame.h"
#include "FrameLoader.h"
#include "HTMLDocument.h"
#include "JSCanvasRenderingContext2D.h"
#include "JSDOMWindowCustom.h"
#include "JSHTMLDocument.h"
#include "JSLocation.h"
#include "JSSVGDocument.h"
#include "Location.h"
#include "NodeTraversal.h"
#include "ScriptController.h"
#include "SVGDocument.h"
#include "TouchList.h"
#include <wtf/GetPtr.h>
#if ENABLE(WEBGL)
#include "JSWebGLRenderingContextBase.h"
#endif
#if ENABLE(TOUCH_EVENTS)
#include "JSTouch.h"
#include "JSTouchList.h"
#endif
using namespace JSC;
namespace WebCore {
JSValue JSDocument::location(ExecState* exec) const
{
RefPtr<Frame> frame = impl().frame();
if (!frame)
return jsNull();
RefPtr<Location> location = frame->document()->domWindow()->location();
if (JSObject* wrapper = getCachedWrapper(globalObject()->world(), location.get()))
return wrapper;
JSLocation* jsLocation = JSLocation::create(getDOMStructure<JSLocation>(exec->vm(), globalObject()), globalObject(), *location);
cacheWrapper(globalObject()->world(), location.get(), jsLocation);
return jsLocation;
}
void JSDocument::setLocation(ExecState* exec, JSValue value)
{
String locationString = value.toString(exec)->value(exec);
if (exec->hadException())
return;
RefPtr<Frame> frame = impl().frame();
if (!frame)
return;
if (RefPtr<Location> location = frame->document()->domWindow()->location())
location->setHref(locationString, activeDOMWindow(exec), firstDOMWindow(exec));
}
JSValue toJS(ExecState* exec, JSDOMGlobalObject* globalObject, Document* document)
{
if (!document)
return jsNull();
JSObject* wrapper = getCachedWrapper(globalObject->world(), document);
if (wrapper)
return wrapper;
if (DOMWindow* domWindow = document->domWindow()) {
globalObject = toJSDOMWindow(toJS(exec, domWindow));
wrapper = getCachedWrapper(globalObject->world(), document);
if (wrapper)
return wrapper;
}
if (document->isHTMLDocument())
wrapper = CREATE_DOM_WRAPPER(globalObject, HTMLDocument, document);
else if (document->isSVGDocument())
wrapper = CREATE_DOM_WRAPPER(globalObject, SVGDocument, document);
else
wrapper = CREATE_DOM_WRAPPER(globalObject, Document, document);
if (!document->frame()) {
size_t nodeCount = 0;
for (Node* n = document; n; n = NodeTraversal::next(*n))
nodeCount++;
exec->heap()->deprecatedReportExtraMemory(nodeCount * sizeof(Node));
}
return wrapper;
}
#if ENABLE(TOUCH_EVENTS)
JSValue JSDocument::createTouchList(ExecState* exec)
{
RefPtr<TouchList> touchList = TouchList::create();
for (size_t i = 0; i < exec->argumentCount(); i++)
touchList->append(JSTouch::toWrapped(exec->argument(i)));
return toJS(exec, globalObject(), touchList.release());
}
#endif
}