/platform/external/webkit/WebCore/bindings/js/JSDocumentCustom.cpp

https://github.com/aharish/totoro-gb-opensource-update2 · C++ · 125 lines · 80 code · 23 blank · 22 comment · 11 complexity · bb1287d240e6fd8de345eff893382e4d MD5 · raw file

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