[GTK] webkit_dom_document_create_tree_walker impossible to use due to WebKitDOMNodeFilter
authorcarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 20 Jun 2014 06:44:16 +0000 (06:44 +0000)
committercarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 20 Jun 2014 06:44:16 +0000 (06:44 +0000)
https://bugs.webkit.org/show_bug.cgi?id=93002

Reviewed by Gustavo Noronha Silva.

Source/WebCore:
Add custom implementation of WebKitDOMNodeFilter to expose it as
an interface instead of a class.

* PlatformGTK.cmake: Add new files to compilation.
* bindings/gobject/GObjectNodeFilterCondition.cpp: Added.
(WebCore::GObjectNodeFilterCondition::~GObjectNodeFilterCondition):
Reset the NodeFilter WebCore object associated to the
WebKitDOMNodeFilter object.
(WebCore::GObjectNodeFilterCondition::acceptNode): Call webkit_dom_node_filter_accept_node().
* bindings/gobject/GObjectNodeFilterCondition.h: Added.
(WebCore::GObjectNodeFilterCondition::create): Create a new
GObjectNodeFilterCondition for the given WebKitDOMNodeFilter.
(WebCore::GObjectNodeFilterCondition::GObjectNodeFilterCondition):
* bindings/gobject/WebKitDOMNodeFilter.cpp: Added.
(webkit_dom_node_filter_default_init):
(webkit_dom_node_filter_accept_node):
(WebKit::nodeFilterMap): Map NodeFilter WebCore objects to
WebKitDOMNodeFilter objects.
(WebKit::nodeFilterObjectDestroyedCallback): Remove the node
filter form the map when the WebKitDOMNodeFilter objecrt is destroyed.
(WebKit::kit): Return the WebKitDOMNodeFilter object for the given
NodeFilter WebCore object.
(WebKit::core): Get or create a NodeFilter WebCore object
associated to the given WebKitDOMNodeFilter.
* bindings/gobject/WebKitDOMNodeFilter.h: Added.
* bindings/gobject/WebKitDOMNodeFilter.symbols: Added.
* bindings/gobject/WebKitDOMNodeFilterPrivate.h: Added.
* bindings/scripts/CodeGeneratorGObject.pm:
(GenerateFunction): Add exceptions for NodeFilter parameters since
the core method returns a PassRefPtr.

Tools:
Add unit tests to check WebKitDOMNodefilter API used from both
TreeWalker and NodeIterator.

* Scripts/webkitpy/style/checker.py: Add exceptions for GTK+
public headers and add WebKitDOMNodeFilter to the list of exceptions.
* TestWebKitAPI/Tests/WebKit2Gtk/CMakeLists.txt: Add new files to compilation.
* TestWebKitAPI/Tests/WebKit2Gtk/DOMNodeFilterTest.cpp: Added.
(webkitNodeFilterAcceptNode):
(webkitNodeFilterDOMNodeFilterIfaceInit):
(webkit_node_filter_init):
(webkit_node_filter_class_init):
(WebKitDOMNodeFilterTest::create):
(WebKitDOMNodeFilterTest::webPageFromArgs):
(WebKitDOMNodeFilterTest::testTreeWalker):
(WebKitDOMNodeFilterTest::testNodeIterator):
(WebKitDOMNodeFilterTest::runTest):
(registerTests):
* TestWebKitAPI/Tests/WebKit2Gtk/TestDOMNodeFilter.cpp: Added.
(runTest):
(testWebKitDOMNodeFilterTreeWalker):
(testWebKitDOMNodeFilterNodeIterator):
(beforeAll):
(afterAll):
* gtk/webkitdom.py:
(WebKitDOMDocGeneratorSections.__init__):
(WebKitDOMDocGeneratorSections._symbol_list):
(WebKitDOMDocGeneratorSections.write_section):

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

15 files changed:
Source/WebCore/ChangeLog
Source/WebCore/PlatformGTK.cmake
Source/WebCore/bindings/gobject/GObjectNodeFilterCondition.cpp [new file with mode: 0644]
Source/WebCore/bindings/gobject/GObjectNodeFilterCondition.h [new file with mode: 0644]
Source/WebCore/bindings/gobject/WebKitDOMNodeFilter.cpp [new file with mode: 0644]
Source/WebCore/bindings/gobject/WebKitDOMNodeFilter.h [new file with mode: 0644]
Source/WebCore/bindings/gobject/WebKitDOMNodeFilter.symbols [new file with mode: 0644]
Source/WebCore/bindings/gobject/WebKitDOMNodeFilterPrivate.h [new file with mode: 0644]
Source/WebCore/bindings/scripts/CodeGeneratorGObject.pm
Tools/ChangeLog
Tools/Scripts/webkitpy/style/checker.py
Tools/TestWebKitAPI/Tests/WebKit2Gtk/CMakeLists.txt
Tools/TestWebKitAPI/Tests/WebKit2Gtk/DOMNodeFilterTest.cpp [new file with mode: 0644]
Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestDOMNodeFilter.cpp [new file with mode: 0644]
Tools/gtk/webkitdom.py

index 4bc8e2c..14ae62c 100644 (file)
@@ -1,5 +1,43 @@
 2014-06-19  Carlos Garcia Campos  <cgarcia@igalia.com>
 
+        [GTK] webkit_dom_document_create_tree_walker impossible to use due to WebKitDOMNodeFilter
+        https://bugs.webkit.org/show_bug.cgi?id=93002
+
+        Reviewed by Gustavo Noronha Silva.
+
+        Add custom implementation of WebKitDOMNodeFilter to expose it as
+        an interface instead of a class.
+
+        * PlatformGTK.cmake: Add new files to compilation.
+        * bindings/gobject/GObjectNodeFilterCondition.cpp: Added.
+        (WebCore::GObjectNodeFilterCondition::~GObjectNodeFilterCondition):
+        Reset the NodeFilter WebCore object associated to the
+        WebKitDOMNodeFilter object.
+        (WebCore::GObjectNodeFilterCondition::acceptNode): Call webkit_dom_node_filter_accept_node().
+        * bindings/gobject/GObjectNodeFilterCondition.h: Added.
+        (WebCore::GObjectNodeFilterCondition::create): Create a new
+        GObjectNodeFilterCondition for the given WebKitDOMNodeFilter.
+        (WebCore::GObjectNodeFilterCondition::GObjectNodeFilterCondition):
+        * bindings/gobject/WebKitDOMNodeFilter.cpp: Added.
+        (webkit_dom_node_filter_default_init):
+        (webkit_dom_node_filter_accept_node):
+        (WebKit::nodeFilterMap): Map NodeFilter WebCore objects to
+        WebKitDOMNodeFilter objects.
+        (WebKit::nodeFilterObjectDestroyedCallback): Remove the node
+        filter form the map when the WebKitDOMNodeFilter objecrt is destroyed.
+        (WebKit::kit): Return the WebKitDOMNodeFilter object for the given
+        NodeFilter WebCore object.
+        (WebKit::core): Get or create a NodeFilter WebCore object
+        associated to the given WebKitDOMNodeFilter.
+        * bindings/gobject/WebKitDOMNodeFilter.h: Added.
+        * bindings/gobject/WebKitDOMNodeFilter.symbols: Added.
+        * bindings/gobject/WebKitDOMNodeFilterPrivate.h: Added.
+        * bindings/scripts/CodeGeneratorGObject.pm:
+        (GenerateFunction): Add exceptions for NodeFilter parameters since
+        the core method returns a PassRefPtr.
+
+2014-06-19  Carlos Garcia Campos  <cgarcia@igalia.com>
+
         [GTK] Limit the amount of API exposed to GObject DOM bindings API
         https://bugs.webkit.org/show_bug.cgi?id=133726
 
index 1bf083f..c70aa8a 100644 (file)
@@ -435,9 +435,11 @@ list(APPEND GObjectDOMBindings_SOURCES
     bindings/gobject/ConvertToUTF8String.cpp
     bindings/gobject/DOMObjectCache.cpp
     bindings/gobject/GObjectEventListener.cpp
+    bindings/gobject/GObjectNodeFilterCondition.cpp
     bindings/gobject/WebKitDOMCustom.cpp
     bindings/gobject/WebKitDOMEventTarget.cpp
     bindings/gobject/WebKitDOMHTMLPrivate.cpp
+    bindings/gobject/WebKitDOMNodeFilter.cpp
     bindings/gobject/WebKitDOMObject.cpp
     bindings/gobject/WebKitDOMPrivate.cpp
     ${DERIVED_SOURCES_GOBJECT_DOM_BINDINGS_DIR}/webkitdomdefines.h
@@ -470,7 +472,6 @@ list(APPEND GObjectDOMBindingsStable_IDL_FILES
     dom/MouseEvent.idl
     dom/NamedNodeMap.idl
     dom/Node.idl
-    dom/NodeFilter.idl
     dom/NodeIterator.idl
     dom/NodeList.idl
     dom/ProcessingInstruction.idl
@@ -629,12 +630,13 @@ if (ENABLE_VIDEO OR ENABLE_WEB_AUDIO)
     )
 endif ()
 
-set(GObjectDOMBindingsStable_CLASS_LIST Custom EventTarget Object)
+set(GObjectDOMBindingsStable_CLASS_LIST Custom EventTarget NodeFilter Object)
 set(GObjectDOMBindingsStable_INSTALLED_HEADERS
      ${DERIVED_SOURCES_GOBJECT_DOM_BINDINGS_DIR}/webkitdomdefines.h
      ${DERIVED_SOURCES_GOBJECT_DOM_BINDINGS_DIR}/webkitdom.h
      ${WEBCORE_DIR}/bindings/gobject/WebKitDOMCustom.h
      ${WEBCORE_DIR}/bindings/gobject/WebKitDOMEventTarget.h
+     ${WEBCORE_DIR}/bindings/gobject/WebKitDOMNodeFilter.h
      ${WEBCORE_DIR}/bindings/gobject/WebKitDOMObject.h
 )
 
@@ -732,6 +734,7 @@ install(FILES ${GObjectDOMBindings_INSTALLED_HEADERS}
 set(GObjectDOMBindings_GIR_HEADERS ${GObjectDOMBindings_INSTALLED_HEADERS})
 list(REMOVE_ITEM GObjectDOMBindings_GIR_HEADERS
      bindings/gobject/WebKitDOMEventTarget.h
+     bindings/gobject/WebKitDOMNodeFilter.h
      bindings/gobject/WebKitDOMObject.h
 )
 
diff --git a/Source/WebCore/bindings/gobject/GObjectNodeFilterCondition.cpp b/Source/WebCore/bindings/gobject/GObjectNodeFilterCondition.cpp
new file mode 100644 (file)
index 0000000..adfd8c1
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ *  Copyright (C) 2014 Igalia S.L.
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include "config.h"
+#include "GObjectNodeFilterCondition.h"
+
+#include "NodeFilter.h"
+#include "WebKitDOMNodePrivate.h"
+
+namespace WebCore {
+
+GObjectNodeFilterCondition::~GObjectNodeFilterCondition()
+{
+    g_object_set_data(G_OBJECT(m_filter.get()), "webkit-core-node-filter", nullptr);
+}
+
+short GObjectNodeFilterCondition::acceptNode(JSC::ExecState*, Node* node) const
+{
+    if (!node)
+        return NodeFilter::FILTER_REJECT;
+    return webkit_dom_node_filter_accept_node(m_filter.get(), WebKit::kit(node));
+}
+
+} // namespace WebCore
diff --git a/Source/WebCore/bindings/gobject/GObjectNodeFilterCondition.h b/Source/WebCore/bindings/gobject/GObjectNodeFilterCondition.h
new file mode 100644 (file)
index 0000000..1d21bf7
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ *  Copyright (C) 2014 Igalia S.L.
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifndef GObjectNodeFilterCondition_h
+#define GObjectNodeFilterCondition_h
+
+#include "NodeFilterCondition.h"
+
+#include "WebKitDOMNodeFilter.h"
+#include <wtf/PassRefPtr.h>
+#include <wtf/RetainPtr.h>
+#include <wtf/gobject/GRefPtr.h>
+
+namespace WebCore {
+class Node;
+
+class GObjectNodeFilterCondition : public NodeFilterCondition {
+public:
+
+    static PassRefPtr<GObjectNodeFilterCondition> create(WebKitDOMNodeFilter* filter)
+    {
+        return adoptRef(new GObjectNodeFilterCondition(filter));
+    }
+
+    virtual short acceptNode(JSC::ExecState*, Node*) const;
+
+private:
+    GObjectNodeFilterCondition(WebKitDOMNodeFilter* filter)
+        : m_filter(filter)
+    {
+    }
+    ~GObjectNodeFilterCondition();
+
+    GRefPtr<WebKitDOMNodeFilter> m_filter;
+};
+
+} // namespace WebCore
+
+#endif // GObjectNodeFilterCondition_h
diff --git a/Source/WebCore/bindings/gobject/WebKitDOMNodeFilter.cpp b/Source/WebCore/bindings/gobject/WebKitDOMNodeFilter.cpp
new file mode 100644 (file)
index 0000000..79e8b6f
--- /dev/null
@@ -0,0 +1,83 @@
+/*
+ * Copyright (C) 2014 Igalia S.L.
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include "config.h"
+#include "WebKitDOMNodeFilter.h"
+
+#include "GObjectNodeFilterCondition.h"
+#include "NodeFilter.h"
+#include "WebKitDOMNode.h"
+#include "WebKitDOMNodeFilterPrivate.h"
+#include <wtf/HashMap.h>
+#include <wtf/NeverDestroyed.h>
+
+typedef WebKitDOMNodeFilterIface WebKitDOMNodeFilterInterface;
+
+G_DEFINE_INTERFACE(WebKitDOMNodeFilter, webkit_dom_node_filter, G_TYPE_OBJECT)
+
+static void webkit_dom_node_filter_default_init(WebKitDOMNodeFilterIface*)
+{
+}
+
+gshort webkit_dom_node_filter_accept_node(WebKitDOMNodeFilter* filter, WebKitDOMNode* node)
+{
+    g_return_val_if_fail(WEBKIT_DOM_IS_NODE_FILTER(filter), WEBKIT_DOM_NODE_FILTER_REJECT);
+    g_return_val_if_fail(WEBKIT_DOM_IS_NODE(node), WEBKIT_DOM_NODE_FILTER_REJECT);
+
+    return WEBKIT_DOM_NODE_FILTER_GET_IFACE(filter)->accept_node(filter, node);
+}
+
+namespace WebKit {
+
+static HashMap<WebCore::NodeFilter*, WebKitDOMNodeFilter*>& nodeFilterMap()
+{
+    static NeverDestroyed<HashMap<WebCore::NodeFilter*, WebKitDOMNodeFilter*>> nodeFilterMap;
+    return nodeFilterMap;
+}
+
+static void nodeFilterObjectDestroyedCallback(gpointer coreNodeFilter, GObject* nodeFilter)
+{
+    WebKitDOMNodeFilter* filter = nodeFilterMap().take(static_cast<WebCore::NodeFilter*>(coreNodeFilter));
+    UNUSED_PARAM(nodeFilter);
+    ASSERT_UNUSED(filter, filter == nodeFilter);
+}
+
+WebKitDOMNodeFilter* kit(WebCore::NodeFilter* coreNodeFilter)
+{
+    if (!coreNodeFilter)
+        return nullptr;
+
+    return nodeFilterMap().get(coreNodeFilter);
+}
+
+PassRefPtr<WebCore::NodeFilter> core(WebKitDOMNodeFilter* nodeFilter)
+{
+    if (!nodeFilter)
+        return nullptr;
+
+    RefPtr<WebCore::NodeFilter> coreNodeFilter = static_cast<WebCore::NodeFilter*>(g_object_get_data(G_OBJECT(nodeFilter), "webkit-core-node-filter"));
+    if (!coreNodeFilter) {
+        coreNodeFilter = WebCore::NodeFilter::create(WebCore::GObjectNodeFilterCondition::create(nodeFilter));
+        nodeFilterMap().add(coreNodeFilter.get(), nodeFilter);
+        g_object_weak_ref(G_OBJECT(nodeFilter), nodeFilterObjectDestroyedCallback, coreNodeFilter.get());
+        g_object_set_data(G_OBJECT(nodeFilter), "webkit-core-node-filter", coreNodeFilter.get());
+    }
+    return coreNodeFilter.release();
+}
+
+} // namespace WebKit
diff --git a/Source/WebCore/bindings/gobject/WebKitDOMNodeFilter.h b/Source/WebCore/bindings/gobject/WebKitDOMNodeFilter.h
new file mode 100644 (file)
index 0000000..8a98a61
--- /dev/null
@@ -0,0 +1,212 @@
+/*
+ *  Copyright (C) 2014 Igalia S.L.
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifndef WebKitDOMNodeFilter_h
+#define WebKitDOMNodeFilter_h
+
+#include <glib-object.h>
+#include <webkitdom/webkitdomdefines.h>
+
+G_BEGIN_DECLS
+
+#define WEBKIT_TYPE_DOM_NODE_FILTER            (webkit_dom_node_filter_get_type ())
+#define WEBKIT_DOM_NODE_FILTER(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), WEBKIT_TYPE_DOM_NODE_FILTER, WebKitDOMNodeFilter))
+#define WEBKIT_DOM_NODE_FILTER_CLASS(obj)      (G_TYPE_CHECK_CLASS_CAST ((obj), WEBKIT_TYPE_DOM_NODE_FILTER, WebKitDOMNodeFilterIface))
+#define WEBKIT_DOM_IS_NODE_FILTER(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), WEBKIT_TYPE_DOM_NODE_FILTER))
+#define WEBKIT_DOM_NODE_FILTER_GET_IFACE(obj)  (G_TYPE_INSTANCE_GET_INTERFACE ((obj), WEBKIT_TYPE_DOM_NODE_FILTER, WebKitDOMNodeFilterIface))
+
+/**
+ * WEBKIT_DOM_NODE_FILTER_ACCEPT:
+ *
+ * Accept the node. Use this macro as return value of webkit_dom_node_filter_accept_node()
+ * implementation to accept the given #WebKitDOMNode
+ *
+ * Since: 2.6
+ */
+#define WEBKIT_DOM_NODE_FILTER_ACCEPT 1
+
+/**
+ * WEBKIT_DOM_NODE_FILTER_REJECT:
+ *
+ * Reject the node. Use this macro as return value of webkit_dom_node_filter_accept_node()
+ * implementation to reject the given #WebKitDOMNode. The children of the given node will
+ * be rejected too.
+ *
+ * Since: 2.6
+ */
+#define WEBKIT_DOM_NODE_FILTER_REJECT 2
+
+/**
+ * WEBKIT_DOM_NODE_FILTER_SKIP:
+ *
+ * Skip the node. Use this macro as return value of webkit_dom_node_filter_accept_node()
+ * implementation to skip the given #WebKitDOMNode. The children of the given node will
+ * not be skipped.
+ *
+ * Since: 2.6
+ */
+#define WEBKIT_DOM_NODE_FILTER_SKIP   3
+
+/**
+ * WEBKIT_DOM_NODE_FILTER_SHOW_ALL:
+ *
+ * Show all nodes.
+ *
+ * Since: 2.6
+ */
+#define WEBKIT_DOM_NODE_FILTER_SHOW_ALL                    0xFFFFFFFF
+
+/**
+ * WEBKIT_DOM_NODE_FILTER_SHOW_ELEMENT:
+ *
+ * Show #WebKitDOMElement nodes.
+ *
+ * Since: 2.6
+ */
+#define WEBKIT_DOM_NODE_FILTER_SHOW_ELEMENT                0x00000001
+
+/**
+ * WEBKIT_DOM_NODE_FILTER_SHOW_ATTRIBUTE:
+ *
+ * Show #WebKitDOMAttr nodes.
+ *
+ * Since: 2.6
+ */
+#define WEBKIT_DOM_NODE_FILTER_SHOW_ATTRIBUTE              0x00000002
+
+/**
+ * WEBKIT_DOM_NODE_FILTER_SHOW_TEXT:
+ *
+ * Show #WebKitDOMText nodes.
+ *
+ * Since: 2.6
+ */
+#define WEBKIT_DOM_NODE_FILTER_SHOW_TEXT                   0x00000004
+
+/**
+ * WEBKIT_DOM_NODE_FILTER_SHOW_CDATA_SECTION:
+ *
+ * Show #WebKitDOMCDataSection nodes.
+ *
+ * Since: 2.6
+ */
+#define WEBKIT_DOM_NODE_FILTER_SHOW_CDATA_SECTION          0x00000008
+
+/**
+ * WEBKIT_DOM_NODE_FILTER_SHOW_ENTITY_REFERENCE:
+ *
+ * Show #WebKitDOMEntityReference nodes.
+ *
+ * Since: 2.6
+ */
+#define WEBKIT_DOM_NODE_FILTER_SHOW_ENTITY_REFERENCE       0x00000010
+
+/**
+ * WEBKIT_DOM_NODE_FILTER_SHOW_ENTITY:
+ *
+ * Show #WebKitDOMEntity nodes.
+ *
+ * Since: 2.6
+ */
+#define WEBKIT_DOM_NODE_FILTER_SHOW_ENTITY                 0x00000020
+
+/**
+ * WEBKIT_DOM_NODE_FILTER_SHOW_PROCESSING_INSTRUCTION:
+ *
+ * Show #WebKitDOMProcessingInstruction nodes.
+ *
+ * Since: 2.6
+ */
+#define WEBKIT_DOM_NODE_FILTER_SHOW_PROCESSING_INSTRUCTION 0x00000040
+
+/**
+ * WEBKIT_DOM_NODE_FILTER_SHOW_COMMENT:
+ *
+ * Show #WebKitDOMComment nodes.
+ *
+ * Since: 2.6
+ */
+#define WEBKIT_DOM_NODE_FILTER_SHOW_COMMENT                0x00000080
+
+/**
+ * WEBKIT_DOM_NODE_FILTER_SHOW_DOCUMENT:
+ *
+ * Show #WebKitDOMDocument nodes.
+ *
+ * Since: 2.6
+ */
+#define WEBKIT_DOM_NODE_FILTER_SHOW_DOCUMENT               0x00000100
+
+/**
+ * WEBKIT_DOM_NODE_FILTER_SHOW_DOCUMENT_TYPE:
+ *
+ * Show #WebKitDOMDocumentType nodes.
+ *
+ * Since: 2.6
+ */
+#define WEBKIT_DOM_NODE_FILTER_SHOW_DOCUMENT_TYPE          0x00000200
+
+/**
+ * WEBKIT_DOM_NODE_FILTER_SHOW_DOCUMENT_FRAGMENT:
+ *
+ * Show #WebKitDOMDocumentFragment nodes.
+ *
+ * Since: 2.6
+ */
+#define WEBKIT_DOM_NODE_FILTER_SHOW_DOCUMENT_FRAGMENT      0x00000400
+
+/**
+ * WEBKIT_DOM_NODE_FILTER_SHOW_NOTATION:
+ *
+ * Show #WebKitDOMNotation nodes.
+ *
+ * Since: 2.6
+ */
+#define WEBKIT_DOM_NODE_FILTER_SHOW_NOTATION               0x00000800
+
+typedef struct _WebKitDOMNodeFilterIface WebKitDOMNodeFilterIface;
+
+struct _WebKitDOMNodeFilterIface {
+    GTypeInterface gIface;
+
+    /* virtual table */
+    gshort (* accept_node)(WebKitDOMNodeFilter *filter,
+                           WebKitDOMNode       *node);
+
+    void (*_webkitdom_reserved0) (void);
+    void (*_webkitdom_reserved1) (void);
+    void (*_webkitdom_reserved2) (void);
+    void (*_webkitdom_reserved3) (void);
+};
+
+
+WEBKIT_API GType webkit_dom_node_filter_get_type(void) G_GNUC_CONST;
+
+/**
+ * webkit_dom_node_filter_accept_node:
+ * @filter: A #WebKitDOMNodeFilter
+ * @node: A #WebKitDOMNode
+ *
+ * Returns: a #gshort
+ */
+WEBKIT_API gshort webkit_dom_node_filter_accept_node(WebKitDOMNodeFilter *filter,
+                                                     WebKitDOMNode       *node);
+
+G_END_DECLS
+
+#endif /* WebKitDOMNodeFilter_h */
diff --git a/Source/WebCore/bindings/gobject/WebKitDOMNodeFilter.symbols b/Source/WebCore/bindings/gobject/WebKitDOMNodeFilter.symbols
new file mode 100644 (file)
index 0000000..39dd3f5
--- /dev/null
@@ -0,0 +1,18 @@
+GType webkit_dom_node_filter_get_type(void)
+WEBKIT_DOM_NODE_FILTER_ACCEPT
+WEBKIT_DOM_NODE_FILTER_REJECT
+WEBKIT_DOM_NODE_FILTER_SHOW_ALL
+WEBKIT_DOM_NODE_FILTER_SHOW_ATTRIBUTE
+WEBKIT_DOM_NODE_FILTER_SHOW_CDATA_SECTION
+WEBKIT_DOM_NODE_FILTER_SHOW_COMMENT
+WEBKIT_DOM_NODE_FILTER_SHOW_DOCUMENT
+WEBKIT_DOM_NODE_FILTER_SHOW_DOCUMENT_FRAGMENT
+WEBKIT_DOM_NODE_FILTER_SHOW_DOCUMENT_TYPE
+WEBKIT_DOM_NODE_FILTER_SHOW_ELEMENT
+WEBKIT_DOM_NODE_FILTER_SHOW_ENTITY
+WEBKIT_DOM_NODE_FILTER_SHOW_ENTITY_REFERENCE
+WEBKIT_DOM_NODE_FILTER_SHOW_NOTATION
+WEBKIT_DOM_NODE_FILTER_SHOW_PROCESSING_INSTRUCTION
+WEBKIT_DOM_NODE_FILTER_SHOW_TEXT
+WEBKIT_DOM_NODE_FILTER_SKIP
+gshort webkit_dom_node_filter_accept_node(WebKitDOMNodeFilter*, WebKitDOMNode*)
diff --git a/Source/WebCore/bindings/gobject/WebKitDOMNodeFilterPrivate.h b/Source/WebCore/bindings/gobject/WebKitDOMNodeFilterPrivate.h
new file mode 100644 (file)
index 0000000..7159c76
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2014 Igalia S.L.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef WebKitDOMNodeFilterPrivate_h
+#define WebKitDOMNodeFiltertPrivate_h
+
+#include <webkitdom/WebKitDOMNodeFilter.h>
+#include <wtf/PassRefPtr.h>
+
+namespace WebCore {
+class NodeFilter;
+}
+
+namespace WebKit {
+WebKitDOMNodeFilter* kit(WebCore::NodeFilter*);
+PassRefPtr<WebCore::NodeFilter> core(WebKitDOMNodeFilter*);
+} // namespace WebKit
+
+#endif /* WebKitDOMNodeFilterPrivate_h */
index 088712d..1e12605 100644 (file)
@@ -54,6 +54,8 @@ my $canBeNullParams = {
     'webkit_dom_document_create_attribute_ns' => ['namespaceURI'],
     'webkit_dom_document_create_element_ns' => ['namespaceURI'],
     'webkit_dom_document_create_entity_reference' => ['name'],
+    'webkit_dom_document_create_node_iterator' => ['filter'],
+    'webkit_dom_document_create_tree_walker' => ['filter'],
     'webkit_dom_document_evaluate' => ['inResult', 'resolver'],
     'webkit_dom_document_get_override_style' => ['pseudoElement'],
     'webkit_dom_dom_implementation_create_document' => ['namespaceURI', 'doctype'],
@@ -956,6 +958,9 @@ sub GenerateFunction {
         if ($paramIsGDOMType || ($paramIDLType eq "DOMString") || ($paramIDLType eq "CompareHow")) {
             $paramName = "converted" . $codeGenerator->WK_ucfirst($paramName);
         }
+        if ($paramIDLType eq "NodeFilter") {
+            $paramName = "WTF::getPtr(" . $paramName . ")";
+        }
         push(@callImplParams, $paramName);
     }
 
@@ -1057,6 +1062,8 @@ sub GenerateFunction {
             push(@cBody, "    WTF::String ${convertedParamName} = WTF::String::fromUTF8($paramName);\n");
         } elsif ($paramIDLType eq "CompareHow") {
             push(@cBody, "    WebCore::Range::CompareHow ${convertedParamName} = static_cast<WebCore::Range::CompareHow>($paramName);\n");
+        } elsif ($paramIDLType eq "NodeFilter") {
+            push(@cBody, "    RefPtr<WebCore::$paramIDLType> ${convertedParamName} = WebKit::core($paramName);\n");
         } elsif ($paramIsGDOMType) {
             push(@cBody, "    WebCore::${paramIDLType}* ${convertedParamName} = WebKit::core($paramName);\n");
         }
index 826cdff..e2617c0 100644 (file)
@@ -1,5 +1,40 @@
 2014-06-19  Carlos Garcia Campos  <cgarcia@igalia.com>
 
+        [GTK] webkit_dom_document_create_tree_walker impossible to use due to WebKitDOMNodeFilter
+        https://bugs.webkit.org/show_bug.cgi?id=93002
+
+        Reviewed by Gustavo Noronha Silva.
+
+        Add unit tests to check WebKitDOMNodefilter API used from both
+        TreeWalker and NodeIterator.
+
+        * Scripts/webkitpy/style/checker.py: Add exceptions for GTK+
+        public headers and add WebKitDOMNodeFilter to the list of exceptions.
+        * TestWebKitAPI/Tests/WebKit2Gtk/CMakeLists.txt: Add new files to compilation.
+        * TestWebKitAPI/Tests/WebKit2Gtk/DOMNodeFilterTest.cpp: Added.
+        (webkitNodeFilterAcceptNode):
+        (webkitNodeFilterDOMNodeFilterIfaceInit):
+        (webkit_node_filter_init):
+        (webkit_node_filter_class_init):
+        (WebKitDOMNodeFilterTest::create):
+        (WebKitDOMNodeFilterTest::webPageFromArgs):
+        (WebKitDOMNodeFilterTest::testTreeWalker):
+        (WebKitDOMNodeFilterTest::testNodeIterator):
+        (WebKitDOMNodeFilterTest::runTest):
+        (registerTests):
+        * TestWebKitAPI/Tests/WebKit2Gtk/TestDOMNodeFilter.cpp: Added.
+        (runTest):
+        (testWebKitDOMNodeFilterTreeWalker):
+        (testWebKitDOMNodeFilterNodeIterator):
+        (beforeAll):
+        (afterAll):
+        * gtk/webkitdom.py:
+        (WebKitDOMDocGeneratorSections.__init__):
+        (WebKitDOMDocGeneratorSections._symbol_list):
+        (WebKitDOMDocGeneratorSections.write_section):
+
+2014-06-19  Carlos Garcia Campos  <cgarcia@igalia.com>
+
         [GTK] Limit the amount of API exposed to GObject DOM bindings API
         https://bugs.webkit.org/show_bug.cgi?id=133726
 
index 330a349..6dae932 100644 (file)
@@ -153,6 +153,7 @@ _PATH_RULES_SPECIFIER = [
       "Source/WebCore/bindings/gobject/WebKitDOMCustom.h",
       "Source/WebCore/bindings/gobject/WebKitDOMDeprecated.h",
       "Source/WebCore/bindings/gobject/WebKitDOMEventTarget.h",
+      "Source/WebCore/bindings/gobject/WebKitDOMNodeFilter.h",
       "Source/WebCore/bindings/scripts/test/GObject",
       "Source/WebKit/gtk/webkit/",
       "Tools/DumpRenderTree/gtk/"],
@@ -160,6 +161,8 @@ _PATH_RULES_SPECIFIER = [
       "-readability/parameter_name",
       "-readability/null",
       "-readability/enum_casing",
+      "-whitespace/declaration",
+      "-whitespace/indent",
       "-whitespace/parens"]),
 
     ([# The GTK+ API use upper case, underscore separated, words in
@@ -221,6 +224,7 @@ _PATH_RULES_SPECIFIER = [
       "Source/WebCore/bindings/gobject/WebKitDOMCustom.cpp",
       "Source/WebCore/bindings/gobject/WebKitDOMDeprecated.cpp",
       "Source/WebCore/bindings/gobject/WebKitDOMEventTarget.cpp",
+      "Source/WebCore/bindings/gobject/WebKitDOMNodeFilter.cpp",
       "Source/WebCore/platform/graphics/gstreamer/VideoSinkGStreamer1.cpp",
       "Source/WebCore/platform/graphics/gstreamer/VideoSinkGStreamer.cpp",
       "Source/WebCore/platform/graphics/gstreamer/WebKitWebSourceGStreamer.cpp",
index 7a49bee..970853a 100644 (file)
@@ -82,7 +82,7 @@ macro(ADD_WK2_TEST test_name)
 endmacro()
 
 ADD_WK2_TEST_WEB_EXTENSION(WebExtensionTest WebExtensionTest.cpp)
-ADD_WK2_TEST_WEB_EXTENSION(WebProcessTest DOMNodeTest.cpp FrameTest.cpp WebProcessTest.cpp)
+ADD_WK2_TEST_WEB_EXTENSION(WebProcessTest DOMNodeTest.cpp DOMNodeFilterTest.cpp FrameTest.cpp WebProcessTest.cpp)
 
 ADD_WK2_TEST(InspectorTestServer InspectorTestServer.cpp)
 ADD_WK2_TEST(TestAuthentication TestAuthentication.cpp)
@@ -90,6 +90,7 @@ ADD_WK2_TEST(TestBackForwardList TestBackForwardList.cpp)
 ADD_WK2_TEST(TestContextMenu TestContextMenu.cpp)
 ADD_WK2_TEST(TestCookieManager TestCookieManager.cpp)
 ADD_WK2_TEST(TestDOMNode TestDOMNode.cpp)
+ADD_WK2_TEST(TestDOMNodeFilter TestDOMNodeFilter.cpp)
 ADD_WK2_TEST(TestDownloads TestDownloads.cpp)
 ADD_WK2_TEST(TestWebKitFaviconDatabase TestWebKitFaviconDatabase.cpp)
 ADD_WK2_TEST(TestWebKitFindController TestWebKitFindController.cpp)
diff --git a/Tools/TestWebKitAPI/Tests/WebKit2Gtk/DOMNodeFilterTest.cpp b/Tools/TestWebKitAPI/Tests/WebKit2Gtk/DOMNodeFilterTest.cpp
new file mode 100644 (file)
index 0000000..f2cf531
--- /dev/null
@@ -0,0 +1,208 @@
+/*
+ * Copyright (C) 2013 Igalia S.L.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+
+#include "WebProcessTest.h"
+#include <gio/gio.h>
+#include <webkit2/webkit-web-extension.h>
+#include <wtf/gobject/GUniquePtr.h>
+
+typedef struct _WebKitNodeFilter {
+    GObject parent;
+} WebKitNodeFilter;
+
+typedef struct _WebKitNodeFilterClass {
+    GObjectClass parentClass;
+} WebKitNodeFilterClass;
+
+static short webkitNodeFilterAcceptNode(WebKitDOMNodeFilter*, WebKitDOMNode* node)
+{
+    // Filter out input elements.
+    return WEBKIT_DOM_IS_HTML_INPUT_ELEMENT(node) ? WEBKIT_DOM_NODE_FILTER_REJECT : WEBKIT_DOM_NODE_FILTER_ACCEPT;
+}
+
+static void webkitNodeFilterDOMNodeFilterIfaceInit(WebKitDOMNodeFilterIface* iface)
+{
+    iface->accept_node = webkitNodeFilterAcceptNode;
+}
+
+G_DEFINE_TYPE_WITH_CODE(WebKitNodeFilter, webkit_node_filter, G_TYPE_OBJECT, G_IMPLEMENT_INTERFACE(WEBKIT_TYPE_DOM_NODE_FILTER, webkitNodeFilterDOMNodeFilterIfaceInit))
+
+static void webkit_node_filter_init(WebKitNodeFilter*)
+{
+}
+
+static void webkit_node_filter_class_init(WebKitNodeFilterClass*)
+{
+}
+
+static const char* expectedNodesAll[] = { "HTML", "HEAD", "TITLE", "#text", "BODY", "INPUT", "INPUT", "BR" };
+static const char* expectedNodesNoInput[] = { "HTML", "HEAD", "TITLE", "#text", "BODY", "BR" };
+static const char* expectedElementsNoInput[] = { "HTML", "HEAD", "TITLE", "BODY", "BR" };
+
+class WebKitDOMNodeFilterTest : public WebProcessTest {
+public:
+    static PassOwnPtr<WebProcessTest> create() { return adoptPtr(new WebKitDOMNodeFilterTest()); }
+
+private:
+    guint64 webPageFromArgs(GVariant* args)
+    {
+        GVariantIter iter;
+        g_variant_iter_init(&iter, args);
+
+        const char* key;
+        GVariant* value;
+        while (g_variant_iter_loop(&iter, "{&sv}", &key, &value)) {
+            if (!strcmp(key, "pageID") && g_variant_classify(value) == G_VARIANT_CLASS_UINT64)
+                return g_variant_get_uint64(value);
+        }
+
+        g_assert_not_reached();
+        return 0;
+    }
+
+    bool testTreeWalker(WebKitWebExtension* extension, GVariant* args)
+    {
+        WebKitWebPage* page = webkit_web_extension_get_page(extension, webPageFromArgs(args));
+        g_assert(WEBKIT_IS_WEB_PAGE(page));
+        WebKitDOMDocument* document = webkit_web_page_get_dom_document(page);
+        g_assert(WEBKIT_DOM_IS_DOCUMENT(document));
+
+        WebKitDOMElement* root = webkit_dom_document_get_element_by_id(document, "root");
+        g_assert(WEBKIT_DOM_IS_NODE(root));
+
+        // No filter.
+        WebKitDOMTreeWalker* walker = webkit_dom_document_create_tree_walker(document, WEBKIT_DOM_NODE(root), WEBKIT_DOM_NODE_FILTER_SHOW_ALL, nullptr, FALSE, nullptr);
+        g_assert(WEBKIT_DOM_IS_TREE_WALKER(walker));
+        g_assert(!webkit_dom_tree_walker_get_filter(walker));
+
+        unsigned i = 0;
+        for (WebKitDOMNode* node = WEBKIT_DOM_NODE(root); node; node = webkit_dom_tree_walker_next_node(walker), ++i) {
+            g_assert_cmpuint(i, <, G_N_ELEMENTS(expectedNodesAll));
+            GUniquePtr<char> nodeName(webkit_dom_node_get_node_name(node));
+            g_assert_cmpstr(nodeName.get(), ==, expectedNodesAll[i]);
+        }
+        g_assert_cmpuint(i, ==, G_N_ELEMENTS(expectedNodesAll));
+
+        // Input elements filter.
+        GRefPtr<WebKitDOMNodeFilter> filter = adoptGRef(static_cast<WebKitDOMNodeFilter*>(g_object_new(webkit_node_filter_get_type(), nullptr)));
+        walker = webkit_dom_document_create_tree_walker(document, WEBKIT_DOM_NODE(root), WEBKIT_DOM_NODE_FILTER_SHOW_ALL, filter.get(), FALSE, nullptr);
+        g_assert(WEBKIT_DOM_IS_TREE_WALKER(walker));
+        g_assert(webkit_dom_tree_walker_get_filter(walker) == filter.get());
+
+        i = 0;
+        for (WebKitDOMNode* node = WEBKIT_DOM_NODE(root); node; node = webkit_dom_tree_walker_next_node(walker), ++i) {
+            g_assert_cmpuint(i, <, G_N_ELEMENTS(expectedNodesNoInput));
+            GUniquePtr<char> nodeName(webkit_dom_node_get_node_name(node));
+            g_assert_cmpstr(nodeName.get(), ==, expectedNodesNoInput[i]);
+        }
+        g_assert_cmpuint(i, ==, G_N_ELEMENTS(expectedNodesNoInput));
+
+        // Show only elements, reusing the input filter.
+        walker = webkit_dom_document_create_tree_walker(document, WEBKIT_DOM_NODE(root), WEBKIT_DOM_NODE_FILTER_SHOW_ELEMENT, filter.get(), FALSE, nullptr);
+        g_assert(WEBKIT_DOM_IS_TREE_WALKER(walker));
+        g_assert(webkit_dom_tree_walker_get_filter(walker) == filter.get());
+
+        i = 0;
+        for (WebKitDOMNode* node = WEBKIT_DOM_NODE(root); node; node = webkit_dom_tree_walker_next_node(walker), ++i) {
+            g_assert_cmpuint(i, <, G_N_ELEMENTS(expectedElementsNoInput));
+            GUniquePtr<char> nodeName(webkit_dom_node_get_node_name(node));
+            g_assert_cmpstr(nodeName.get(), ==, expectedElementsNoInput[i]);
+        }
+        g_assert_cmpuint(i, ==, G_N_ELEMENTS(expectedElementsNoInput));
+
+        return true;
+    }
+
+    bool testNodeIterator(WebKitWebExtension* extension, GVariant* args)
+    {
+        WebKitWebPage* page = webkit_web_extension_get_page(extension, webPageFromArgs(args));
+        g_assert(WEBKIT_IS_WEB_PAGE(page));
+        WebKitDOMDocument* document = webkit_web_page_get_dom_document(page);
+        g_assert(WEBKIT_DOM_IS_DOCUMENT(document));
+
+        WebKitDOMElement* root = webkit_dom_document_get_element_by_id(document, "root");
+        g_assert(WEBKIT_DOM_IS_NODE(root));
+
+        // No filter.
+        WebKitDOMNodeIterator* iter = webkit_dom_document_create_node_iterator(document, WEBKIT_DOM_NODE(root), WEBKIT_DOM_NODE_FILTER_SHOW_ALL, nullptr, FALSE, nullptr);
+        g_assert(WEBKIT_DOM_IS_NODE_ITERATOR(iter));
+        g_assert(!webkit_dom_node_iterator_get_filter(iter));
+
+        unsigned i = 0;
+        while (WebKitDOMNode* node = webkit_dom_node_iterator_next_node(iter, nullptr)) {
+            g_assert_cmpuint(i, <, G_N_ELEMENTS(expectedNodesAll));
+            GUniquePtr<char> nodeName(webkit_dom_node_get_node_name(node));
+            g_assert_cmpstr(nodeName.get(), ==, expectedNodesAll[i]);
+            i++;
+        }
+        g_assert_cmpuint(i, ==, G_N_ELEMENTS(expectedNodesAll));
+
+        // Input elements filter.
+        GRefPtr<WebKitDOMNodeFilter> filter = adoptGRef(static_cast<WebKitDOMNodeFilter*>(g_object_new(webkit_node_filter_get_type(), nullptr)));
+        iter = webkit_dom_document_create_node_iterator(document, WEBKIT_DOM_NODE(root), WEBKIT_DOM_NODE_FILTER_SHOW_ALL, filter.get(), FALSE, nullptr);
+        g_assert(WEBKIT_DOM_IS_NODE_ITERATOR(iter));
+        g_assert(webkit_dom_node_iterator_get_filter(iter) == filter.get());
+
+        i = 0;
+        while (WebKitDOMNode* node = webkit_dom_node_iterator_next_node(iter, nullptr)) {
+            g_assert_cmpuint(i, <, G_N_ELEMENTS(expectedNodesNoInput));
+            GUniquePtr<char> nodeName(webkit_dom_node_get_node_name(node));
+            g_assert_cmpstr(nodeName.get(), ==, expectedNodesNoInput[i]);
+            i++;
+        }
+        g_assert_cmpuint(i, ==, G_N_ELEMENTS(expectedNodesNoInput));
+
+        // Show only elements, reusing the input filter.
+        iter = webkit_dom_document_create_node_iterator(document, WEBKIT_DOM_NODE(root), WEBKIT_DOM_NODE_FILTER_SHOW_ELEMENT, filter.get(), FALSE, nullptr);
+        g_assert(WEBKIT_DOM_IS_NODE_ITERATOR(iter));
+        g_assert(webkit_dom_node_iterator_get_filter(iter) == filter.get());
+
+        i = 0;
+        while (WebKitDOMNode* node = webkit_dom_node_iterator_next_node(iter, nullptr)) {
+            g_assert_cmpuint(i, <, G_N_ELEMENTS(expectedElementsNoInput));
+            GUniquePtr<char> nodeName(webkit_dom_node_get_node_name(node));
+            g_assert_cmpstr(nodeName.get(), ==, expectedElementsNoInput[i]);
+            i++;
+        }
+        g_assert_cmpuint(i, ==, G_N_ELEMENTS(expectedElementsNoInput));
+
+        return true;
+    }
+
+    virtual bool runTest(const char* testName, WebKitWebExtension* extension, GVariant* args)
+    {
+        if (!strcmp(testName, "tree-walker"))
+            return testTreeWalker(extension, args);
+        if (!strcmp(testName, "node-iterator"))
+            return testNodeIterator(extension, args);
+
+        g_assert_not_reached();
+        return false;
+    }
+};
+
+static void __attribute__((constructor)) registerTests()
+{
+    REGISTER_TEST(WebKitDOMNodeFilterTest, "WebKitDOMNodeFilter/tree-walker");
+    REGISTER_TEST(WebKitDOMNodeFilterTest, "WebKitDOMNodeFilter/node-iterator");
+}
+
+
diff --git a/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestDOMNodeFilter.cpp b/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestDOMNodeFilter.cpp
new file mode 100644 (file)
index 0000000..d036021
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2014 Igalia S.L.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2,1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+
+#include "WebProcessTestRunner.h"
+#include "WebViewTest.h"
+#include <gtk/gtk.h>
+#include <webkit2/webkit2.h>
+
+static WebProcessTestRunner* testRunner;
+
+static const char* testHTML = "<html id='root'><head><title>DOMNodeTreeWalker</title></head>"
+    "<body><input type='button' name='push' value='push'><input type='button' name='clear' value='clear'><br></body></html>";
+
+static void runTest(WebViewTest* test, const char* name)
+{
+    test->loadHtml(testHTML, nullptr);
+    test->waitUntilLoadFinished();
+
+    GVariantBuilder builder;
+    g_variant_builder_init(&builder, G_VARIANT_TYPE_VARDICT);
+    g_variant_builder_add(&builder, "{sv}", "pageID", g_variant_new_uint64(webkit_web_view_get_page_id(test->m_webView)));
+    g_assert(testRunner->runTest("WebKitDOMNodeFilter", name, g_variant_builder_end(&builder)));
+}
+
+static void testWebKitDOMNodeFilterTreeWalker(WebViewTest* test, gconstpointer)
+{
+    runTest(test, "tree-walker");
+}
+
+static void testWebKitDOMNodeFilterNodeIterator(WebViewTest* test, gconstpointer)
+{
+    runTest(test, "node-iterator");
+}
+
+void beforeAll()
+{
+    testRunner = new WebProcessTestRunner();
+    webkit_web_context_set_web_extensions_directory(webkit_web_context_get_default(), WEBKIT_TEST_WEB_EXTENSIONS_DIR);
+
+    WebViewTest::add("WebKitDOMNodeFilter", "tree-walker", testWebKitDOMNodeFilterTreeWalker);
+    WebViewTest::add("WebKitDOMNodeFilter", "node-iterator", testWebKitDOMNodeFilterNodeIterator);
+}
+
+void afterAll()
+{
+    delete testRunner;
+}
index 9f59307..e0561c2 100755 (executable)
@@ -92,6 +92,7 @@ class WebKitDOMDocGeneratorSections(WebKitDOMDocGenerator):
         self._second_decamelize_re = re.compile('([a-z0-9])([A-Z])')
         self._dom_class_re = re.compile('(^WebKitDOM)(.+)$')
         self._function_re = re.compile('^.+ (.+)\((.+)\)$')
+        self._constant_re = re.compile('^[A-Z_]+$')
 
     def _dom_class(self, class_name):
         return self._dom_class_re.sub(r'\2', class_name)
@@ -111,6 +112,11 @@ class WebKitDOMDocGeneratorSections(WebKitDOMDocGenerator):
         retval = []
         f = open(symbol_file, 'r')
         for line in f.readlines():
+            match = self._constant_re.match(line)
+            if match:
+                retval.append(line.strip('\n'))
+                continue
+
             match = self._function_re.match(line)
             if not match or match.group(1).endswith('get_type'):
                 continue
@@ -121,7 +127,7 @@ class WebKitDOMDocGeneratorSections(WebKitDOMDocGenerator):
     def write_section(self, symbol_file):
         class_name = os.path.basename(symbol_file).replace(".symbols", "")
         is_custom = class_name == 'WebKitDOMCustom'
-        is_interface = class_name == 'WebKitDOMEventTarget'
+        is_interface = class_name in ['WebKitDOMEventTarget', 'WebKitDOMNodeFilter']
         is_object = class_name == 'WebKitDOMObject'
         self.write('<SECTION>\n')
         self.write('<FILE>%s</FILE>\n<TITLE>%s</TITLE>\n' % (class_name, class_name))