2 * Copyright (C) 2007, 2008, 2009, 2011 Apple Inc. All rights reserved.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
21 #include "JSDocument.h"
23 #include "ExceptionCode.h"
25 #include "FrameLoader.h"
26 #include "HTMLDocument.h"
27 #include "JSCanvasRenderingContext2D.h"
29 #include "JSWebGLRenderingContext.h"
31 #include "JSDOMWindowCustom.h"
32 #include "JSHTMLDocument.h"
33 #include "JSLocation.h"
35 #include "JSTouchList.h"
37 #include "ScriptController.h"
38 #include "TouchList.h"
41 #include "JSSVGDocument.h"
42 #include "SVGDocument.h"
45 #include <wtf/GetPtr.h>
51 JSValue JSDocument::location(ExecState* exec) const
53 Frame* frame = static_cast<Document*>(impl())->frame();
57 Location* location = frame->domWindow()->location();
58 if (JSDOMWrapper* wrapper = getCachedWrapper(currentWorld(exec), location))
61 JSLocation* jsLocation = JSLocation::create(getDOMStructure<JSLocation>(exec, globalObject()), globalObject(), location);
62 cacheWrapper(currentWorld(exec), location, jsLocation);
66 void JSDocument::setLocation(ExecState* exec, JSValue value)
68 Frame* frame = static_cast<Document*>(impl())->frame();
72 String str = ustringToString(value.toString(exec));
74 Frame* lexicalFrame = asJSDOMWindow(exec->lexicalGlobalObject())->impl()->frame();
76 // IE and Mozilla both resolve the URL relative to the source frame,
77 // not the target frame.
78 Frame* activeFrame = asJSDOMWindow(exec->dynamicGlobalObject())->impl()->frame();
79 str = activeFrame->document()->completeURL(str).string();
81 bool lockHistory = !ScriptController::processingUserGesture();
82 frame->navigationScheduler()->scheduleLocationChange(lexicalFrame->document()->securityOrigin(),
83 str, activeFrame->loader()->outgoingReferrer(), lockHistory, false);
86 JSValue toJS(ExecState* exec, JSDOMGlobalObject* globalObject, Document* document)
91 JSDOMWrapper* wrapper = getCachedWrapper(currentWorld(exec), document);
95 if (document->isHTMLDocument())
96 wrapper = CREATE_DOM_WRAPPER(exec, globalObject, HTMLDocument, document);
98 else if (document->isSVGDocument())
99 wrapper = CREATE_DOM_WRAPPER(exec, globalObject, SVGDocument, document);
102 wrapper = CREATE_DOM_WRAPPER(exec, globalObject, Document, document);
104 // Make sure the document is kept around by the window object, and works right with the
105 // back/forward cache.
106 if (!document->frame()) {
107 size_t nodeCount = 0;
108 for (Node* n = document; n; n = n->traverseNextNode())
111 exec->heap()->reportExtraMemoryCost(nodeCount * sizeof(Node));
117 #if ENABLE(TOUCH_EVENTS)
118 JSValue JSDocument::createTouchList(ExecState* exec)
120 RefPtr<TouchList> touchList = TouchList::create();
122 for (int i = 0; i < exec->argumentCount(); i++)
123 touchList->append(toTouch(exec->argument(i)));
125 return toJS(exec, globalObject(), touchList.release());
129 } // namespace WebCore