Reviewed by John.
authormjs <mjs@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 10 Dec 2003 04:09:52 +0000 (04:09 +0000)
committermjs <mjs@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 10 Dec 2003 04:09:52 +0000 (04:09 +0000)
<rdar://problem/3487195>: Implement responseXML property for XMLHttpRequest

        * khtml/ecma/xmlhttprequest.cpp:
        (KJS::XMLHttpRequest::getValueProperty): Implemented responseXML by parsing the
document and returning it.
        (KJS::XMLHttpRequest::XMLHttpRequest): Initialize new field
        * khtml/ecma/xmlhttprequest.h:

        * khtml/ecma/kjs_window.cpp:
(Windw::get): Forgot this in last commit; add XMLSerializer
constructor.
        * khtml/ecma/kjs_window.lut.h:
* khtml/ecma/Makefile.am: Forgot to include this in the last commit.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@5741 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebCore/ChangeLog-2005-08-23
WebCore/khtml/ecma/Makefile.am
WebCore/khtml/ecma/kjs_window.cpp
WebCore/khtml/ecma/kjs_window.h
WebCore/khtml/ecma/kjs_window.lut.h
WebCore/khtml/ecma/xmlhttprequest.cpp
WebCore/khtml/ecma/xmlhttprequest.h

index 9a16884dd8ec1bc17c906d754d0465c03d0fecb3..65199f4b480c6b3d564894ec28c5ebd86f0d0cc4 100644 (file)
@@ -1,3 +1,21 @@
+2003-12-09  Maciej Stachowiak  <mjs@apple.com>
+
+        Reviewed by John.
+
+       <rdar://problem/3487195>: Implement responseXML property for XMLHttpRequest
+        
+        * khtml/ecma/xmlhttprequest.cpp:
+        (KJS::XMLHttpRequest::getValueProperty): Implemented responseXML by parsing the
+       document and returning it.
+        (KJS::XMLHttpRequest::XMLHttpRequest): Initialize new field
+        * khtml/ecma/xmlhttprequest.h:
+
+        * khtml/ecma/kjs_window.cpp: 
+       (Windw::get): Forgot this in last commit; add XMLSerializer
+       constructor.
+        * khtml/ecma/kjs_window.lut.h:
+       * khtml/ecma/Makefile.am: Forgot to include this in the last commit.
+
 2003-12-09  Maciej Stachowiak  <mjs@apple.com>
 
         Reviewed by Richard.
index 6f00baf86270dd7b218af2a6182d6e35f6f9afb7..5eb9f2d852e9d8650ad54c86bbfb74628405f5ae 100644 (file)
@@ -11,6 +11,7 @@ LUT_FILES = \
        kjs_views.lut.h \
        kjs_window.lut.h \
        xmlhttprequest.lut.h \
+       xmlserializer.lut.h \
        $(NULL)
 
 CREATE_HASH_TABLE = $(top_srcdir)/JavaScriptCore/kjs/create_hash_table
index 574acfa8d9407ce2f3cd940ab1433d86a1680592..f365f4271896b34b77f9e6a26a9755f94ab589c3 100644 (file)
@@ -49,6 +49,7 @@
 #include "kjs_css.h"
 #include "kjs_events.h"
 #include "xmlhttprequest.h"
+#include "xmlserializer.h"
 
 #include "khtmlview.h"
 #include "khtml_part.h"
@@ -229,6 +230,7 @@ const ClassInfo Window::info = { "Window", 0, &WindowTable, 0 };
   Image                Window::Image           DontDelete|ReadOnly
   Option       Window::Option          DontDelete|ReadOnly
   XMLHttpRequest       Window::XMLHttpRequest  DontDelete|ReadOnly
+  XMLSerializer        Window::XMLSerializer   DontDelete|ReadOnly
   alert                Window::Alert           DontDelete|Function 1
   confirm      Window::Confirm         DontDelete|Function 1
   prompt       Window::Prompt          DontDelete|Function 2
@@ -545,6 +547,8 @@ Value Window::get(ExecState *exec, const Identifier &p) const
       return Value(new OptionConstructorImp(exec, m_part->document()));
     case XMLHttpRequest:
       return Value(new XMLHttpRequestConstructorImp(exec, m_part->document()));
+    case XMLSerializer:
+      return Value(new XMLSerializerConstructorImp(exec));
     case Alert:
     case Confirm:
     case Prompt:
index cfa5104288fb274116eeefc0e38c002d52924a02..28195afbff216227dd8b6f95f71d95456bb786b1 100644 (file)
@@ -120,7 +120,7 @@ namespace KJS {
            ScrollTo, ScrollX, ScrollY, MoveBy, MoveTo, ResizeBy, ResizeTo, Self, _Window, Top, _Screen,
            Image, Option, Alert, Confirm, Prompt, Open, Print, SetTimeout, ClearTimeout,
            Focus, GetSelection, Blur, Close, SetInterval, ClearInterval, CaptureEvents, 
-           ReleaseEvents, AddEventListener, RemoveEventListener, XMLHttpRequest,
+           ReleaseEvents, AddEventListener, RemoveEventListener, XMLHttpRequest, XMLSerializer,
           Onabort, Onblur, Onchange, Onclick, Ondblclick, Ondragdrop, Onerror, 
           Onfocus, Onkeydown, Onkeypress, Onkeyup, Onload, Onmousedown, Onmousemove,
            Onmouseout, Onmouseover, Onmouseup, Onmove, Onreset, Onresize,
index 366630f909582bf51f61d61fad9a7659d072af97..6a41e1c3368f593448db870995280e324b88bac8 100644 (file)
@@ -53,7 +53,7 @@ const struct HashEntry WindowTableEntries[] = {
    { "onblur", Window::Onblur, DontDelete, 0, 0 },
    { "addEventListener", Window::AddEventListener, DontDelete|Function, 3, 0 },
    { "Node", Window::Node, DontDelete, 0, &WindowTableEntries[100] },
-   { 0, 0, 0, 0, 0 },
+   { "XMLSerializer", Window::XMLSerializer, DontDelete|ReadOnly, 0, 0 },
    { "scrollBy", Window::ScrollBy, DontDelete|Function, 2, 0 },
    { "Image", Window::Image, DontDelete|ReadOnly, 0, 0 },
    { "window", Window::_Window, DontDelete|ReadOnly, 0, 0 },
index 3b2e85db9182526403056e504ad502a267e9a7fe..2c3b5012648fd053162f804b75141f90dccc6edc 100644 (file)
@@ -23,6 +23,7 @@
 #include "kjs_window.h"
 #include "kjs_events.h"
 
+#include "dom/dom_doc.h"
 #include "dom/dom_exception.h"
 #include "dom/dom_string.h"
 #include "misc/loader.h"
@@ -122,7 +123,7 @@ Value XMLHttpRequest::tryGet(ExecState *exec, const Identifier &propertyName) co
   return DOMObjectLookupGetValue<XMLHttpRequest,DOMObject>(exec, propertyName, &XMLHttpRequestTable, this);
 }
 
-Value XMLHttpRequest::getValueProperty(ExecState *, int token) const
+Value XMLHttpRequest::getValueProperty(ExecState *exec, int token) const
 {
   switch (token) {
   case ReadyState:
@@ -130,7 +131,33 @@ Value XMLHttpRequest::getValueProperty(ExecState *, int token) const
   case ResponseText:
     return getStringOrNull(DOM::DOMString(response));
   case ResponseXML:
-    return Undefined();
+    if (state != Completed) {
+      return Undefined();
+    }
+    if (!createdDocument) {
+      QString mimeType = "text/xml";
+      
+      Value header = getResponseHeader("Content-Type");
+      if (header.type() != UndefinedType) {
+       mimeType = QStringList::split(";", header.toString(exec).qstring())[0].stripWhiteSpace();
+      }
+      
+      if (mimeType == "text/xml" || mimeType == "application/xml" || mimeType == "application/xhtml+xml") {
+       responseXML = DOM::Document(doc->implementation()->createDocument());
+      } else {
+       responseXML = DOM::Document(doc->implementation()->createHTMLDocument());
+      }
+
+      DOM::DocumentImpl *docImpl = static_cast<DOM::DocumentImpl *>(responseXML.handle());
+      
+      docImpl->open();
+      docImpl->write(response);
+      docImpl->finishParsing();
+      docImpl->close();
+      createdDocument = true;
+    }
+
+    return getDOMNode(exec,responseXML);
   case Status:
     return getStatus();
   case StatusText:
@@ -183,7 +210,8 @@ XMLHttpRequest::XMLHttpRequest(ExecState *exec, const DOM::Document &d)
     state(Uninitialized),
     onReadyStateChangeListener(0),
     onLoadListener(0),
-    decoder(0)
+    decoder(0),
+    createdDocument(false)
 {
 }
 
index 297dd3ccee65d4c35bcdb54e23bed0272f653d9d..635169945158301d8e5a05a631a62304c6965969 100644 (file)
@@ -104,9 +104,11 @@ namespace KJS {
 
     khtml::Decoder *decoder;
     QString encoding;
-    QString response;
-
     QString responseHeaders;
+
+    QString response;
+    mutable bool createdDocument;
+    mutable DOM::Document responseXML;
   };