WebCore/bindings/js/JSDocumentCustom.cpp
changeset 0 4f2f89ce4247
equal deleted inserted replaced
-1:000000000000 0:4f2f89ce4247
       
     1 /*
       
     2  * Copyright (C) 2007, 2008, 2009 Apple Inc. All rights reserved.
       
     3  *
       
     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.
       
     8  *
       
     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.
       
    13  *
       
    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.
       
    18  */
       
    19 
       
    20 #include "config.h"
       
    21 #include "JSDocument.h"
       
    22 
       
    23 #include "ExceptionCode.h"
       
    24 #include "Frame.h"
       
    25 #include "FrameLoader.h"
       
    26 #include "HTMLDocument.h"
       
    27 #include "JSCanvasRenderingContext2D.h"
       
    28 #if ENABLE(3D_CANVAS)
       
    29 #include "JSWebGLRenderingContext.h"
       
    30 #endif
       
    31 #include "JSDOMWindowCustom.h"
       
    32 #include "JSHTMLDocument.h"
       
    33 #include "JSLocation.h"
       
    34 #include "Location.h"
       
    35 #include "ScriptController.h"
       
    36 
       
    37 #if ENABLE(SVG)
       
    38 #include "JSSVGDocument.h"
       
    39 #include "SVGDocument.h"
       
    40 #endif
       
    41 
       
    42 #include <wtf/GetPtr.h>
       
    43 
       
    44 using namespace JSC;
       
    45 
       
    46 namespace WebCore {
       
    47 
       
    48 void JSDocument::markChildren(MarkStack& markStack)
       
    49 {
       
    50     JSNode::markChildren(markStack);
       
    51 
       
    52     Document* document = impl();
       
    53     JSGlobalData& globalData = *Heap::heap(this)->globalData();
       
    54 
       
    55     markDOMNodesForDocument(markStack, document);
       
    56     markActiveObjectsForContext(markStack, globalData, document);
       
    57     markDOMObjectWrapper(markStack, globalData, document->implementation());
       
    58     markDOMObjectWrapper(markStack, globalData, document->styleSheets());
       
    59     document->markCachedNodeLists(markStack, globalData);
       
    60 }
       
    61 
       
    62 JSValue JSDocument::location(ExecState* exec) const
       
    63 {
       
    64     Frame* frame = static_cast<Document*>(impl())->frame();
       
    65     if (!frame)
       
    66         return jsNull();
       
    67 
       
    68     Location* location = frame->domWindow()->location();
       
    69     if (DOMObject* wrapper = getCachedDOMObjectWrapper(exec, location))
       
    70         return wrapper;
       
    71 
       
    72     JSLocation* jsLocation = new (exec) JSLocation(getDOMStructure<JSLocation>(exec, globalObject()), globalObject(), location);
       
    73     cacheDOMObjectWrapper(exec, location, jsLocation);
       
    74     return jsLocation;
       
    75 }
       
    76 
       
    77 void JSDocument::setLocation(ExecState* exec, JSValue value)
       
    78 {
       
    79     Frame* frame = static_cast<Document*>(impl())->frame();
       
    80     if (!frame)
       
    81         return;
       
    82 
       
    83     String str = ustringToString(value.toString(exec));
       
    84 
       
    85     // IE and Mozilla both resolve the URL relative to the source frame,
       
    86     // not the target frame.
       
    87     Frame* activeFrame = asJSDOMWindow(exec->dynamicGlobalObject())->impl()->frame();
       
    88     if (activeFrame)
       
    89         str = activeFrame->document()->completeURL(str).string();
       
    90 
       
    91     bool userGesture = activeFrame->script()->processingUserGesture(currentWorld(exec));
       
    92     frame->redirectScheduler()->scheduleLocationChange(str, activeFrame->loader()->outgoingReferrer(), !activeFrame->script()->anyPageIsProcessingUserGesture(), false, userGesture);
       
    93 }
       
    94 
       
    95 JSValue toJS(ExecState* exec, JSDOMGlobalObject* globalObject, Document* document)
       
    96 {
       
    97     if (!document)
       
    98         return jsNull();
       
    99 
       
   100     DOMObject* wrapper = getCachedDOMNodeWrapper(exec, document, document);
       
   101     if (wrapper)
       
   102         return wrapper;
       
   103 
       
   104     if (document->isHTMLDocument())
       
   105         wrapper = CREATE_DOM_NODE_WRAPPER(exec, globalObject, HTMLDocument, document);
       
   106 #if ENABLE(SVG)
       
   107     else if (document->isSVGDocument())
       
   108         wrapper = CREATE_DOM_NODE_WRAPPER(exec, globalObject, SVGDocument, document);
       
   109 #endif
       
   110     else
       
   111         wrapper = CREATE_DOM_NODE_WRAPPER(exec, globalObject, Document, document);
       
   112 
       
   113     // Make sure the document is kept around by the window object, and works right with the
       
   114     // back/forward cache.
       
   115     if (!document->frame()) {
       
   116         size_t nodeCount = 0;
       
   117         for (Node* n = document; n; n = n->traverseNextNode())
       
   118             nodeCount++;
       
   119         
       
   120         exec->heap()->reportExtraMemoryCost(nodeCount * sizeof(Node));
       
   121     }
       
   122 
       
   123     return wrapper;
       
   124 }
       
   125 
       
   126 } // namespace WebCore