[SCM] WebKit Debian packaging branch, debian/experimental, updated. upstream/1.3.3-9427-gc2be6fc

jianli at chromium.org jianli at chromium.org
Wed Dec 22 14:24:20 UTC 2010


The following commit has been merged in the debian/experimental branch:
commit 0bfeae985c322b193ca66782356a928dccfacf31
Author: jianli at chromium.org <jianli at chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Thu Oct 7 22:57:22 2010 +0000

    Support generating a FormData object based on the data in an existing <form>.
    https://bugs.webkit.org/show_bug.cgi?id=45929
    
    Reviewed by Adam Barth.
    
    WebCore:
    
    Test: http/tests/local/formdata/send-form-data-constructed-from-form.html
    
    * bindings/js/JSDOMFormDataCustom.cpp:
    (WebCore::toHTMLFormElement):
    (WebCore::JSDOMFormDataConstructor::constructJSDOMFormData):
    * bindings/v8/custom/V8DOMFormDataCustom.cpp:
    (WebCore::V8DOMFormData::constructorCallback):
    * html/DOMFormData.cpp:
    (WebCore::DOMFormData::DOMFormData):
    * html/DOMFormData.h:
    (WebCore::DOMFormData::create):
    * html/DOMFormData.idl:
    
    LayoutTests:
    
    Add a new test to test this functionality.
    
    * http/tests/local/formdata/resources/test.txt: Copied from LayoutTests/fast/files/resources/UTF8.txt.
    * http/tests/local/formdata/send-form-data-constructed-from-form-expected.txt: Added.
    * http/tests/local/formdata/send-form-data-constructed-from-form.html: Added.
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@69349 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog
index 462f98c..c3afb73 100644
--- a/LayoutTests/ChangeLog
+++ b/LayoutTests/ChangeLog
@@ -1,3 +1,16 @@
+2010-10-07  Jian Li  <jianli at chromium.org>
+
+        Reviewed by Adam Barth.
+
+        Support generating a FormData object based on the data in an existing <form>.
+        https://bugs.webkit.org/show_bug.cgi?id=45929
+
+        Add a new test to test this functionality.
+
+        * http/tests/local/formdata/resources/test.txt: Copied from LayoutTests/fast/files/resources/UTF8.txt.
+        * http/tests/local/formdata/send-form-data-constructed-from-form-expected.txt: Added.
+        * http/tests/local/formdata/send-form-data-constructed-from-form.html: Added.
+
 2010-10-07  Abhishek Arya  <inferno at chromium.org>
 
         Reviewed by Dave Hyatt.
diff --git a/LayoutTests/fast/files/resources/UTF8.txt b/LayoutTests/http/tests/local/formdata/resources/test.txt
similarity index 100%
copy from LayoutTests/fast/files/resources/UTF8.txt
copy to LayoutTests/http/tests/local/formdata/resources/test.txt
diff --git a/LayoutTests/http/tests/local/formdata/send-form-data-constructed-from-form-expected.txt b/LayoutTests/http/tests/local/formdata/send-form-data-constructed-from-form-expected.txt
new file mode 100644
index 0000000..1c49aa4
--- /dev/null
+++ b/LayoutTests/http/tests/local/formdata/send-form-data-constructed-from-form-expected.txt
@@ -0,0 +1,5 @@
+      
+Test that FormData constructor takes a HTML Form element.
+Response: submitted=true&checkbox=value2&radio=value3&text=value4&file=test.txt:text/plain:Hello
+DONE
+
diff --git a/LayoutTests/http/tests/local/formdata/send-form-data-constructed-from-form.html b/LayoutTests/http/tests/local/formdata/send-form-data-constructed-from-form.html
new file mode 100644
index 0000000..f976445
--- /dev/null
+++ b/LayoutTests/http/tests/local/formdata/send-form-data-constructed-from-form.html
@@ -0,0 +1,58 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<body>
+<form id=f>
+<input type=hidden name="submitted" value="true">
+<input type=button name="button" value="value1">
+<input type=checkbox name="checkbox" value="value2" checked>
+<input type=radio name="radio" value="value3" checked>
+<input type=text name="text" value="value4">
+<input type=text name="text2" value="value5" disabled>
+<input type=file id="file" name="file" onchange="onInputFileChange()">
+<input type=submit>
+</form>
+<pre id='console'></pre>
+
+<script>
+function log(message)
+{
+    document.getElementById('console').appendChild(document.createTextNode(message + "\n"));
+}
+
+function onInputFileChange()
+{
+    log("Test that FormData constructor takes a HTML Form element.");
+
+    var file = document.getElementById("file").files[0];
+    var xhr = new XMLHttpRequest();
+    xhr.open("POST", "http://127.0.0.1:8000/xmlhttprequest/resources/multipart-post-echo.php", false);
+    xhr.send(new FormData(document.getElementById("f")));
+    log("Response: " + xhr.responseText);
+
+    log("DONE");
+    if (layoutTestController.notifyDone)
+        layoutTestController.notifyDone();
+}
+
+function moveMouseToCenterOfElement(element)
+{
+    var centerX = element.offsetLeft + element.offsetWidth / 2;
+    var centerY = element.offsetTop + element.offsetHeight / 2;
+    eventSender.mouseMoveTo(centerX, centerY);
+}
+
+function runTests()
+{
+    eventSender.beginDragWithFiles(['resources/test.txt']);
+    moveMouseToCenterOfElement(document.getElementById("file"));
+    eventSender.mouseUp();
+}
+
+if (window.eventSender) {
+    layoutTestController.dumpAsText();
+    layoutTestController.waitUntilDone();
+    window.onload = runTests;
+}
+</script>
+</body>
+</html>
diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 2e48b8d..0eb8201 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,23 @@
+2010-10-07  Jian Li  <jianli at chromium.org>
+
+        Reviewed by Adam Barth.
+
+        Support generating a FormData object based on the data in an existing <form>.
+        https://bugs.webkit.org/show_bug.cgi?id=45929
+
+        Test: http/tests/local/formdata/send-form-data-constructed-from-form.html
+
+        * bindings/js/JSDOMFormDataCustom.cpp:
+        (WebCore::toHTMLFormElement):
+        (WebCore::JSDOMFormDataConstructor::constructJSDOMFormData):
+        * bindings/v8/custom/V8DOMFormDataCustom.cpp:
+        (WebCore::V8DOMFormData::constructorCallback):
+        * html/DOMFormData.cpp:
+        (WebCore::DOMFormData::DOMFormData):
+        * html/DOMFormData.h:
+        (WebCore::DOMFormData::create):
+        * html/DOMFormData.idl:
+
 2010-10-07  Abhishek Arya  <inferno at chromium.org>
 
         Reviewed by Dave Hyatt.
diff --git a/WebCore/bindings/js/JSDOMFormDataCustom.cpp b/WebCore/bindings/js/JSDOMFormDataCustom.cpp
index f207578..2559e96 100644
--- a/WebCore/bindings/js/JSDOMFormDataCustom.cpp
+++ b/WebCore/bindings/js/JSDOMFormDataCustom.cpp
@@ -32,13 +32,31 @@
 #include "JSDOMFormData.h"
 
 #include "DOMFormData.h"
+#include "HTMLFormElement.h"
 #include "JSBlob.h"
+#include "JSHTMLFormElement.h"
 #include <runtime/Error.h>
 
 using namespace JSC;
 
 namespace WebCore {
 
+static HTMLFormElement* toHTMLFormElement(JSC::JSValue value)
+{
+    return value.inherits(&JSHTMLFormElement::s_info) ? static_cast<HTMLFormElement*>(static_cast<JSHTMLFormElement*>(asObject(value))->impl()) : 0;
+}
+
+EncodedJSValue JSC_HOST_CALL JSDOMFormDataConstructor::constructJSDOMFormData(ExecState* exec)
+{
+    JSDOMFormDataConstructor* jsConstructor = static_cast<JSDOMFormDataConstructor*>(exec->callee());
+
+    HTMLFormElement* form = 0;
+    if (exec->argumentCount() > 0)
+        form = toHTMLFormElement(exec->argument(0));
+    RefPtr<DOMFormData> domFormData = DOMFormData::create(form);
+    return JSValue::encode(asObject(toJS(exec, jsConstructor->globalObject(), domFormData.get())));
+}
+
 JSValue JSDOMFormData::append(ExecState* exec)
 {
     if (exec->argumentCount() >= 2) {
diff --git a/WebCore/bindings/v8/custom/V8DOMFormDataCustom.cpp b/WebCore/bindings/v8/custom/V8DOMFormDataCustom.cpp
index 8a39332..caf2e16 100644
--- a/WebCore/bindings/v8/custom/V8DOMFormDataCustom.cpp
+++ b/WebCore/bindings/v8/custom/V8DOMFormDataCustom.cpp
@@ -34,11 +34,28 @@
 #include "DOMFormData.h"
 #include "V8Binding.h"
 #include "V8Blob.h"
+#include "V8HTMLFormElement.h"
 #include "V8Proxy.h"
 #include "V8Utilities.h"
 
 namespace WebCore {
 
+v8::Handle<v8::Value> V8DOMFormData::constructorCallback(const v8::Arguments& args)
+{
+    INC_STATS("DOM.FormData.Constructor");
+
+    if (!args.IsConstructCall())
+        return throwError("DOM object constructor cannot be called as a function.", V8Proxy::SyntaxError);
+
+    HTMLFormElement* form = 0;
+    if (args.Length() > 0 && V8HTMLFormElement::HasInstance(args[0]))
+        form = V8HTMLFormElement::toNative(args[0]->ToObject());
+    RefPtr<DOMFormData> domFormData = DOMFormData::create(form);
+
+    V8DOMWrapper::setDOMWrapper(args.Holder(), &info, domFormData.get());
+    return toV8(domFormData.release(), args.Holder());
+}
+
 v8::Handle<v8::Value> V8DOMFormData::appendCallback(const v8::Arguments& args)
 {
     INC_STATS("DOM.FormData.append()");
diff --git a/WebCore/html/DOMFormData.cpp b/WebCore/html/DOMFormData.cpp
index f848898..0ece637 100644
--- a/WebCore/html/DOMFormData.cpp
+++ b/WebCore/html/DOMFormData.cpp
@@ -32,6 +32,8 @@
 #include "DOMFormData.h"
 
 #include "Blob.h"
+#include "HTMLFormControlElement.h"
+#include "HTMLFormElement.h"
 #include "PlatformString.h"
 #include "TextEncoding.h"
 
@@ -42,6 +44,19 @@ DOMFormData::DOMFormData(const TextEncoding& encoding)
 {
 }
 
+DOMFormData::DOMFormData(HTMLFormElement* form)
+    : FormDataList(UTF8Encoding())
+{
+    if (!form)
+        return;
+
+    for (unsigned i = 0; i < form->associatedElements().size(); ++i) {
+        HTMLFormControlElement* control = form->associatedElements()[i];
+        if (!control->disabled())
+            control->appendFormData(*this, true);
+    }
+}
+
 void DOMFormData::append(const String& name, const String& value)
 {
     if (!name.isEmpty())
diff --git a/WebCore/html/DOMFormData.h b/WebCore/html/DOMFormData.h
index 6c24858..967d64d 100644
--- a/WebCore/html/DOMFormData.h
+++ b/WebCore/html/DOMFormData.h
@@ -39,18 +39,20 @@
 namespace WebCore {
 
 class Blob;
+class HTMLFormElement;
 class TextEncoding;
 
 class DOMFormData : public FormDataList, public RefCounted<DOMFormData> {
 public:
-    static PassRefPtr<DOMFormData> create() { return adoptRef(new DOMFormData(UTF8Encoding())); }
+    static PassRefPtr<DOMFormData> create(HTMLFormElement* form) { return adoptRef(new DOMFormData(form)); }
     static PassRefPtr<DOMFormData> create(const TextEncoding& encoding) { return adoptRef(new DOMFormData(encoding)); }
 
     void append(const String& name, const String& value);
     void append(const String& name, Blob*);
 
 private:
-    DOMFormData(const TextEncoding&);
+    explicit DOMFormData(const TextEncoding&);
+    explicit DOMFormData(HTMLFormElement*);
 };
 
 } // namespace WebCore
diff --git a/WebCore/html/DOMFormData.idl b/WebCore/html/DOMFormData.idl
index c339381..4418428 100644
--- a/WebCore/html/DOMFormData.idl
+++ b/WebCore/html/DOMFormData.idl
@@ -32,6 +32,8 @@ module html {
 
     interface [
         CanBeConstructed,
+        CustomConstructFunction,
+        V8CustomConstructor,
         GenerateNativeConverter,
         GenerateToJS
     ] DOMFormData {

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list