2 * Copyright (C) 2007 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"
25 #include "FrameLoader.h"
26 #include "HTMLDocument.h"
27 #include "JSHTMLDocument.h"
28 #include "kjs_binding.h"
29 #include "kjs_window.h"
32 #include "JSSVGDocument.h"
33 #include "SVGDocument.h"
40 void JSDocument::mark()
43 ScriptInterpreter::markDOMNodesForDocument(static_cast<Document*>(impl()));
46 JSValue* JSDocument::location(ExecState* exec) const
48 Frame* frame = static_cast<Document*>(impl())->frame();
52 KJS::Window* win = KJS::Window::retrieveWindow(frame);
54 return win->location();
57 void JSDocument::setLocation(ExecState* exec, JSValue* value)
59 Frame* frame = static_cast<Document*>(impl())->frame();
63 String str = value->toString(exec);
65 // IE and Mozilla both resolve the URL relative to the source frame,
66 // not the target frame.
67 Frame* activeFrame = static_cast<ScriptInterpreter*>(exec->dynamicInterpreter())->frame();
69 str = activeFrame->document()->completeURL(str);
71 bool userGesture = static_cast<ScriptInterpreter*>(exec->dynamicInterpreter())->wasRunByUserGesture();
72 frame->loader()->scheduleLocationChange(str, activeFrame->loader()->outgoingReferrer(), false, userGesture);
75 JSValue* toJS(ExecState* exec, Document* doc)
80 ScriptInterpreter* interp = static_cast<ScriptInterpreter*>(exec->dynamicInterpreter());
81 JSDocument* ret = static_cast<JSDocument*>(interp->getDOMObject(doc));
85 if (doc->isHTMLDocument())
86 ret = new JSHTMLDocument(exec, static_cast<HTMLDocument*>(doc));
88 else if (doc->isSVGDocument())
89 ret = new JSSVGDocument(exec, static_cast<SVGDocument*>(doc));
92 ret = new JSDocument(exec, doc);
94 // Make sure the document is kept around by the window object, and works right with the
95 // back/forward cache.
97 KJS::Window::retrieveWindow(doc->frame())->putDirect("document", ret, DontDelete|ReadOnly);
100 for (Node* n = doc; n; n = n->traverseNextNode())
103 Collector::reportExtraMemoryCost(nodeCount * sizeof(Node));
106 interp->putDOMObject(doc, ret);
111 } // namespace WebCore