2 * Copyright (C) 2007, 2008, 2009 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 void JSDocument::markChildren(MarkStack& markStack)
53 JSNode::markChildren(markStack);
55 Document* document = impl();
56 JSGlobalData& globalData = *Heap::heap(this)->globalData();
58 markDOMNodesForDocument(markStack, document);
59 markActiveObjectsForContext(markStack, globalData, document);
60 markDOMObjectWrapper(markStack, globalData, document->implementation());
61 markDOMObjectWrapper(markStack, globalData, document->styleSheets());
62 document->markCachedNodeLists(markStack, globalData);
65 JSValue JSDocument::location(ExecState* exec) const
67 Frame* frame = static_cast<Document*>(impl())->frame();
71 Location* location = frame->domWindow()->location();
72 if (DOMObject* wrapper = getCachedDOMObjectWrapper(exec, location))
75 JSLocation* jsLocation = new (exec) JSLocation(getDOMStructure<JSLocation>(exec, globalObject()), globalObject(), location);
76 cacheDOMObjectWrapper(exec, location, jsLocation);
80 void JSDocument::setLocation(ExecState* exec, JSValue value)
82 Frame* frame = static_cast<Document*>(impl())->frame();
86 String str = ustringToString(value.toString(exec));
88 Frame* lexicalFrame = asJSDOMWindow(exec->lexicalGlobalObject())->impl()->frame();
90 // IE and Mozilla both resolve the URL relative to the source frame,
91 // not the target frame.
92 Frame* activeFrame = asJSDOMWindow(exec->dynamicGlobalObject())->impl()->frame();
93 str = activeFrame->document()->completeURL(str).string();
95 frame->navigationScheduler()->scheduleLocationChange(lexicalFrame->document()->securityOrigin(),
96 str, activeFrame->loader()->outgoingReferrer(), !activeFrame->script()->anyPageIsProcessingUserGesture(), false);
99 JSValue toJS(ExecState* exec, JSDOMGlobalObject* globalObject, Document* document)
104 DOMObject* wrapper = getCachedDOMNodeWrapper(exec, document, document);
108 if (document->isHTMLDocument())
109 wrapper = CREATE_DOM_NODE_WRAPPER(exec, globalObject, HTMLDocument, document);
111 else if (document->isSVGDocument())
112 wrapper = CREATE_DOM_NODE_WRAPPER(exec, globalObject, SVGDocument, document);
115 wrapper = CREATE_DOM_NODE_WRAPPER(exec, globalObject, Document, document);
117 // Make sure the document is kept around by the window object, and works right with the
118 // back/forward cache.
119 if (!document->frame()) {
120 size_t nodeCount = 0;
121 for (Node* n = document; n; n = n->traverseNextNode())
124 exec->heap()->reportExtraMemoryCost(nodeCount * sizeof(Node));
130 #if ENABLE(TOUCH_EVENTS)
131 JSValue JSDocument::createTouchList(ExecState* exec)
133 RefPtr<TouchList> touchList = TouchList::create();
135 for (int i = 0; i < exec->argumentCount(); i++)
136 touchList->append(toTouch(exec->argument(i)));
138 return toJS(exec, touchList.release());
142 } // namespace WebCore