Skip to content
Permalink
Browse files
[GTK] XPathNSResolver should be exposed as an interface instead of as…
… a class

https://bugs.webkit.org/show_bug.cgi?id=134028

Reviewed by Gustavo Noronha Silva.

Source/WebCore:
Add custom implementation of WebKitDOMXPathNSResolver to expose it
as an interface instead of a class. It also includes an internal
default implementation of the interface to support methods that
create a XPathNSResolver using the native implementation.

* PlatformGTK.cmake: Add new files to compilation.
* bindings/gobject/GObjectXPathNSResolver.cpp: Added.
(WebCore::GObjectXPathNSResolver::~GObjectXPathNSResolver):
(WebCore::GObjectXPathNSResolver::lookupNamespaceURI): Call
webkit_dom_xpath_ns_resolver_lookup_namespace_uri().
* bindings/gobject/GObjectXPathNSResolver.h: Added.
(WebCore::GObjectXPathNSResolver::create):
(WebCore::GObjectXPathNSResolver::GObjectXPathNSResolver): Create
a new GObjectXPathNSResolver for the given WebKitDOMXPathNSResolver.
* bindings/gobject/WebKitDOMXPathNSResolver.cpp: Added.
(webkit_dom_xpath_ns_resolver_default_init):
(webkit_dom_xpath_ns_resolver_lookup_namespace_uri):
(webkitDOMNativeXPathNSResolverFinalize):
(webkitDOMNativeXPathNSResolverConstructor):
(webkit_dom_native_xpath_ns_resolver_init):
(webkit_dom_native_xpath_ns_resolver_class_init):
(webkitDOMNativeXPathNSResolverLookupNamespaceURI):
(webkitDOMXPathNSResolverIfaceInit):
(WebKit::core): Return the native XPathNSResolver when using the
internal implementation or create a custom XPathNSResolver when
using a user provided WebKitDOMXPathNSResolver.
(WebKit::kit):
* bindings/gobject/WebKitDOMXPathNSResolver.h: Added.
* bindings/gobject/WebKitDOMXPathNSResolverPrivate.h: Added.
* bindings/scripts/CodeGeneratorGObject.pm:
(GenerateFunction): Add exceptions for XPathNSResolver since
the core method returns a PassRefPtr.

Tools:
Add unit tests to check WebKitDOMXPathNSResolver API when using the
native one and a user provided one.

* Scripts/webkitpy/style/checker.py: Add WebKitDOMXPathNSResolver
to the list of GTK+ public API exceptions.
* TestWebKitAPI/Tests/WebKit2Gtk/CMakeLists.txt: Add new files to compilation.
* TestWebKitAPI/Tests/WebKit2Gtk/DOMXPathNSResolverTest.cpp: Added.
(webkitXPathNSResolverLookupNamespaceURI):
(webkitXPathNSResolverDOMXPathNSResolverIfaceInit):
(webkit_xpath_ns_resolver_init):
(webkit_xpath_ns_resolver_class_init):
(WebKitDOMXPathNSResolverTest::create):
(WebKitDOMXPathNSResolverTest::webPageFromArgs):
(WebKitDOMXPathNSResolverTest::evaluateFooChildTextAndCheckResult):
(WebKitDOMXPathNSResolverTest::testXPathNSResolverNative):
(WebKitDOMXPathNSResolverTest::testXPathNSResolverCustom):
(WebKitDOMXPathNSResolverTest::runTest):
(registerTests):
* TestWebKitAPI/Tests/WebKit2Gtk/TestDOMXPathNSResolver.cpp: Added.
(runTest):
(testWebKitDOMXPathNSResolverNative):
(testWebKitDOMXPathNSResolverCustom):
(serverCallback):
(beforeAll):
(afterAll):
* gtk/webkitdom.py:
(WebKitDOMDocGeneratorSections.write_section): Add
WebKitDOMXPathNSResolver to the list of interfaces.

Canonical link: https://commits.webkit.org/152528@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@170700 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
carlosgcampos committed Jul 2, 2014
1 parent 2f7cbda commit ce6b9348ae5dae56386feac2f34d8edc349d9150
Show file tree
Hide file tree
Showing 14 changed files with 651 additions and 6 deletions.
@@ -1,3 +1,43 @@
2014-07-01 Carlos Garcia Campos <cgarcia@igalia.com>

[GTK] XPathNSResolver should be exposed as an interface instead of as a class
https://bugs.webkit.org/show_bug.cgi?id=134028

Reviewed by Gustavo Noronha Silva.

Add custom implementation of WebKitDOMXPathNSResolver to expose it
as an interface instead of a class. It also includes an internal
default implementation of the interface to support methods that
create a XPathNSResolver using the native implementation.

* PlatformGTK.cmake: Add new files to compilation.
* bindings/gobject/GObjectXPathNSResolver.cpp: Added.
(WebCore::GObjectXPathNSResolver::~GObjectXPathNSResolver):
(WebCore::GObjectXPathNSResolver::lookupNamespaceURI): Call
webkit_dom_xpath_ns_resolver_lookup_namespace_uri().
* bindings/gobject/GObjectXPathNSResolver.h: Added.
(WebCore::GObjectXPathNSResolver::create):
(WebCore::GObjectXPathNSResolver::GObjectXPathNSResolver): Create
a new GObjectXPathNSResolver for the given WebKitDOMXPathNSResolver.
* bindings/gobject/WebKitDOMXPathNSResolver.cpp: Added.
(webkit_dom_xpath_ns_resolver_default_init):
(webkit_dom_xpath_ns_resolver_lookup_namespace_uri):
(webkitDOMNativeXPathNSResolverFinalize):
(webkitDOMNativeXPathNSResolverConstructor):
(webkit_dom_native_xpath_ns_resolver_init):
(webkit_dom_native_xpath_ns_resolver_class_init):
(webkitDOMNativeXPathNSResolverLookupNamespaceURI):
(webkitDOMXPathNSResolverIfaceInit):
(WebKit::core): Return the native XPathNSResolver when using the
internal implementation or create a custom XPathNSResolver when
using a user provided WebKitDOMXPathNSResolver.
(WebKit::kit):
* bindings/gobject/WebKitDOMXPathNSResolver.h: Added.
* bindings/gobject/WebKitDOMXPathNSResolverPrivate.h: Added.
* bindings/scripts/CodeGeneratorGObject.pm:
(GenerateFunction): Add exceptions for XPathNSResolver since
the core method returns a PassRefPtr.

2014-07-01 Frédéric Wang <fred.wang@free.fr>

The OpenType MATH table is not read on Mac
@@ -436,12 +436,14 @@ list(APPEND GObjectDOMBindings_SOURCES
bindings/gobject/DOMObjectCache.cpp
bindings/gobject/GObjectEventListener.cpp
bindings/gobject/GObjectNodeFilterCondition.cpp
bindings/gobject/GObjectXPathNSResolver.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
bindings/gobject/WebKitDOMXPathNSResolver.cpp
${DERIVED_SOURCES_GOBJECT_DOM_BINDINGS_DIR}/webkitdomdefines.h
${DERIVED_SOURCES_GOBJECT_DOM_BINDINGS_DIR}/webkitdomdefines-unstable.h
${DERIVED_SOURCES_GOBJECT_DOM_BINDINGS_DIR}/webkitdom.h
@@ -547,7 +549,6 @@ list(APPEND GObjectDOMBindingsStable_IDL_FILES
page/DOMWindow.idl

xml/XPathExpression.idl
xml/XPathNSResolver.idl
xml/XPathResult.idl
)

@@ -649,14 +650,15 @@ if (ENABLE_QUOTA)
)
endif ()

set(GObjectDOMBindingsStable_CLASS_LIST Custom EventTarget NodeFilter Object)
set(GObjectDOMBindingsStable_CLASS_LIST Custom EventTarget NodeFilter Object XPathNSResolver)
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
${WEBCORE_DIR}/bindings/gobject/WebKitDOMXPathNSResolver.h
)

set(GObjectDOMBindingsUnstable_INSTALLED_HEADERS
@@ -755,6 +757,7 @@ list(REMOVE_ITEM GObjectDOMBindings_GIR_HEADERS
bindings/gobject/WebKitDOMEventTarget.h
bindings/gobject/WebKitDOMNodeFilter.h
bindings/gobject/WebKitDOMObject.h
bindings/gobject/WebKitDOMXPathNSResolver.h
)

# Propagate this variable to the parent scope, so that it can be used in other parts of the build.
@@ -0,0 +1,36 @@
/*
* 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 "GObjectXPathNSResolver.h"

#include <wtf/text/CString.h>
#include <wtf/text/WTFString.h>

namespace WebCore {

GObjectXPathNSResolver::~GObjectXPathNSResolver()
{
}

String GObjectXPathNSResolver::lookupNamespaceURI(const String& prefix)
{
return String::fromUTF8(webkit_dom_xpath_ns_resolver_lookup_namespace_uri(m_resolver.get(), prefix.utf8().data()));
}

} // namespace WebCore
@@ -0,0 +1,51 @@
/*
* 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 GObjectXPathNSResolver_h
#define GObjectXPathNSResolver_h

#include "WebKitDOMXPathNSResolver.h"
#include "XPathNSResolver.h"
#include <wtf/PassRefPtr.h>
#include <wtf/gobject/GRefPtr.h>

namespace WebCore {

class GObjectXPathNSResolver : public XPathNSResolver {
public:

static PassRefPtr<GObjectXPathNSResolver> create(WebKitDOMXPathNSResolver* resolver)
{
return adoptRef(new GObjectXPathNSResolver(resolver));
}

virtual ~GObjectXPathNSResolver();
virtual String lookupNamespaceURI(const String& prefix);

private:
GObjectXPathNSResolver(WebKitDOMXPathNSResolver* resolver)
: m_resolver(resolver)
{
}

GRefPtr<WebKitDOMXPathNSResolver> m_resolver;
};

} // namespace WebCore

#endif // GObjectXPathNSResolver_h
@@ -0,0 +1,140 @@
/*
* 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 "WebKitDOMXPathNSResolver.h"

#include "DOMObjectCache.h"
#include "GObjectXPathNSResolver.h"
#include "JSMainThreadExecState.h"
#include "WebKitDOMObject.h"
#include "WebKitDOMXPathNSResolverPrivate.h"
#include "gobject/ConvertToUTF8String.h"
#include <wtf/GetPtr.h>
#include <wtf/RefPtr.h>

typedef WebKitDOMXPathNSResolverIface WebKitDOMXPathNSResolverInterface;

G_DEFINE_INTERFACE(WebKitDOMXPathNSResolver, webkit_dom_xpath_ns_resolver, G_TYPE_OBJECT)

static void webkit_dom_xpath_ns_resolver_default_init(WebKitDOMXPathNSResolverIface*)
{
}

char* webkit_dom_xpath_ns_resolver_lookup_namespace_uri(WebKitDOMXPathNSResolver* resolver, const char* prefix)
{
g_return_val_if_fail(WEBKIT_DOM_IS_XPATH_NS_RESOLVER(resolver), nullptr);
g_return_val_if_fail(prefix, nullptr);

return WEBKIT_DOM_XPATH_NS_RESOLVER_GET_IFACE(resolver)->lookup_namespace_uri(resolver, prefix);
}

// WebKitDOMNativeXPathNSResolver.
struct _WebKitDOMNativeXPathNSResolver {
WebKitDOMObject parent;
};

struct _WebKitDOMNativeXPathNSResolverClass {
WebKitDOMObjectClass parentClass;
};

typedef struct _WebKitDOMNativeXPathNSResolverPrivate {
RefPtr<WebCore::XPathNSResolver> coreObject;
} WebKitDOMNativeXPathNSResolverPrivate;

#define WEBKIT_DOM_NATIVE_XPATH_NS_RESOLVER_GET_PRIVATE(obj) G_TYPE_INSTANCE_GET_PRIVATE(obj, WEBKIT_DOM_TYPE_NATIVE_XPATH_NS_RESOLVER, WebKitDOMNativeXPathNSResolverPrivate)

static void webkitDOMXPathNSResolverIfaceInit(WebKitDOMXPathNSResolverIface*);

G_DEFINE_TYPE_WITH_CODE(WebKitDOMNativeXPathNSResolver, webkit_dom_native_xpath_ns_resolver, WEBKIT_DOM_TYPE_OBJECT, G_IMPLEMENT_INTERFACE(WEBKIT_DOM_TYPE_XPATH_NS_RESOLVER, webkitDOMXPathNSResolverIfaceInit))

static void webkitDOMNativeXPathNSResolverFinalize(GObject* object)
{
WebKitDOMNativeXPathNSResolverPrivate* priv = WEBKIT_DOM_NATIVE_XPATH_NS_RESOLVER_GET_PRIVATE(object);
priv->~WebKitDOMNativeXPathNSResolverPrivate();
G_OBJECT_CLASS(webkit_dom_native_xpath_ns_resolver_parent_class)->finalize(object);
}

static GObject* webkitDOMNativeXPathNSResolverConstructor(GType type, guint constructPropertiesCount, GObjectConstructParam* constructProperties)
{
GObject* object = G_OBJECT_CLASS(webkit_dom_native_xpath_ns_resolver_parent_class)->constructor(type, constructPropertiesCount, constructProperties);
WebKitDOMNativeXPathNSResolverPrivate* priv = WEBKIT_DOM_NATIVE_XPATH_NS_RESOLVER_GET_PRIVATE(object);
priv->coreObject = static_cast<WebCore::XPathNSResolver*>(WEBKIT_DOM_OBJECT(object)->coreObject);
WebKit::DOMObjectCache::put(priv->coreObject.get(), object);
return object;
}

static void webkit_dom_native_xpath_ns_resolver_init(WebKitDOMNativeXPathNSResolver* resolver)
{
WebKitDOMNativeXPathNSResolverPrivate* priv = WEBKIT_DOM_NATIVE_XPATH_NS_RESOLVER_GET_PRIVATE(resolver);
new (priv) WebKitDOMNativeXPathNSResolverPrivate();
}

static void webkit_dom_native_xpath_ns_resolver_class_init(WebKitDOMNativeXPathNSResolverClass* klass)
{
GObjectClass* gobjectClass = G_OBJECT_CLASS(klass);
g_type_class_add_private(gobjectClass, sizeof(WebKitDOMNativeXPathNSResolverPrivate));
gobjectClass->constructor = webkitDOMNativeXPathNSResolverConstructor;
gobjectClass->finalize = webkitDOMNativeXPathNSResolverFinalize;
}

static char* webkitDOMNativeXPathNSResolverLookupNamespaceURI(WebKitDOMXPathNSResolver* resolver, const char* prefix)
{
WebCore::JSMainThreadNullState state;
g_return_val_if_fail(WEBKIT_DOM_IS_NATIVE_XPATH_NS_RESOLVER(resolver), nullptr);

return convertToUTF8String(WebKit::core(resolver)->lookupNamespaceURI(WTF::String::fromUTF8(prefix)));
}

static void webkitDOMXPathNSResolverIfaceInit(WebKitDOMXPathNSResolverIface* iface)
{
iface->lookup_namespace_uri = webkitDOMNativeXPathNSResolverLookupNamespaceURI;
}

namespace WebKit {

PassRefPtr<WebCore::XPathNSResolver> core(WebKitDOMXPathNSResolver* xPathNSResolver)
{
if (!xPathNSResolver)
return nullptr;

RefPtr<WebCore::XPathNSResolver> coreResolver;
if (WEBKIT_DOM_IS_NATIVE_XPATH_NS_RESOLVER(xPathNSResolver))
coreResolver = core(WEBKIT_DOM_NATIVE_XPATH_NS_RESOLVER(xPathNSResolver));
else
coreResolver = WebCore::GObjectXPathNSResolver::create(xPathNSResolver);
return coreResolver.release();
}

WebKitDOMXPathNSResolver* kit(WebCore::XPathNSResolver* coreXPathNSResolver)
{
if (!coreXPathNSResolver)
return nullptr;

if (gpointer ret = DOMObjectCache::get(coreXPathNSResolver))
return WEBKIT_DOM_XPATH_NS_RESOLVER(ret);

return WEBKIT_DOM_XPATH_NS_RESOLVER(g_object_new(WEBKIT_DOM_TYPE_NATIVE_XPATH_NS_RESOLVER, "core-object", coreXPathNSResolver, nullptr));
}

WebCore::XPathNSResolver* core(WebKitDOMNativeXPathNSResolver* xPathNSResolver)
{
return xPathNSResolver ? static_cast<WebCore::XPathNSResolver*>(WEBKIT_DOM_OBJECT(xPathNSResolver)->coreObject) : nullptr;
}

} // namespace WebKit
@@ -0,0 +1,63 @@
/*
* 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 WebKitDOMXPathNSResolver_h
#define WebKitDOMXPathNSResolver_h

#include <glib-object.h>
#include <webkitdom/webkitdomdefines.h>

G_BEGIN_DECLS

#define WEBKIT_DOM_TYPE_XPATH_NS_RESOLVER (webkit_dom_xpath_ns_resolver_get_type ())
#define WEBKIT_DOM_XPATH_NS_RESOLVER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), WEBKIT_DOM_TYPE_XPATH_NS_RESOLVER, WebKitDOMXPathNSResolver))
#define WEBKIT_DOM_XPATH_NS_RESOLVER_CLASS(obj) (G_TYPE_CHECK_CLASS_CAST ((obj), WEBKIT_DOM_TYPE_XPATH_NS_RESOLVER, WebKitDOMXPathNSResolverIface))
#define WEBKIT_DOM_IS_XPATH_NS_RESOLVER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), WEBKIT_DOM_TYPE_XPATH_NS_RESOLVER))
#define WEBKIT_DOM_XPATH_NS_RESOLVER_GET_IFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), WEBKIT_DOM_TYPE_XPATH_NS_RESOLVER, WebKitDOMXPathNSResolverIface))

typedef struct _WebKitDOMXPathNSResolverIface WebKitDOMXPathNSResolverIface;

struct _WebKitDOMXPathNSResolverIface {
GTypeInterface gIface;

/* virtual table */
gchar *(* lookup_namespace_uri)(WebKitDOMXPathNSResolver *resolver,
const gchar *prefix);

void (*_webkitdom_reserved0) (void);
void (*_webkitdom_reserved1) (void);
void (*_webkitdom_reserved2) (void);
void (*_webkitdom_reserved3) (void);
};


WEBKIT_API GType webkit_dom_xpath_ns_resolver_get_type(void) G_GNUC_CONST;

/**
* webkit_dom_xpath_ns_resolver_lookup_namespace_uri:
* @resolver: A #WebKitDOMXPathNSResolver
* @prefix: The prefix to lookup
*
* Returns: (transfer full): a #gchar
*/
WEBKIT_API gchar *webkit_dom_xpath_ns_resolver_lookup_namespace_uri(WebKitDOMXPathNSResolver *resolver,
const gchar *prefix);

G_END_DECLS

#endif /* WebKitDOMXPathNSResolver_h */

0 comments on commit ce6b934

Please sign in to comment.