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 9a16884..65199f4 100644 (file)
@@ -1,5 +1,23 @@
 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.
 
        <rdar://problem/3504049>: XMLSerializer object and serializeToString method needed for XMLHttpRequest testing
index 6f00baf..5eb9f2d 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 574acfa..f365f42 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 cfa5104..28195af 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 366630f..6a41e1c 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 3b2e85d..2c3b501 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 297dd3c..6351699 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;
   };